From cfa31b87f1c2a6597ed3cfb6a777126c58ace665 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Tue, 2 Aug 2022 16:28:18 -0400
Subject: Adjusted ScriptFields to have a rawScript, and updated ScrptingBoxes
 to create a scriptField even for scripts that don't compile.  Updated
 CurrentUserUtils setup functions for clicks.   Fixed TemplateMenu to work
 again.

---
 src/client/views/TemplateMenu.tsx | 98 ++++++++++++++++-----------------------
 1 file changed, 40 insertions(+), 58 deletions(-)

(limited to 'src/client/views/TemplateMenu.tsx')

diff --git a/src/client/views/TemplateMenu.tsx b/src/client/views/TemplateMenu.tsx
index 156513f47..863829a51 100644
--- a/src/client/views/TemplateMenu.tsx
+++ b/src/client/views/TemplateMenu.tsx
@@ -55,16 +55,12 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
     @observable private _hidden: boolean = true;
 
     toggleLayout = (e: React.ChangeEvent<HTMLInputElement>, layout: string): void => {
-        this.props.docViews.map(dv => dv.switchViews(e.target.checked, layout));
+        this.props.docViews.map(dv => dv.switchViews(e.target.checked, layout, undefined, true));
     };
     toggleDefault = (e: React.ChangeEvent<HTMLInputElement>): void => {
         this.props.docViews.map(dv => dv.switchViews(false, 'layout'));
     };
 
-    toggleAudio = (e: React.ChangeEvent<HTMLInputElement>): void => {
-        this.props.docViews.map(dv => (dv.props.Document._showAudio = e.target.checked));
-    };
-
     @undoBatch
     @action
     toggleTemplate = (event: React.ChangeEvent<HTMLInputElement>, template: string): void => {
@@ -76,12 +72,6 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
         this._hidden = !this._hidden;
     };
 
-    @undoBatch
-    @action
-    toggleChrome = (): void => {
-        this.props.docViews.map(dv => Doc.Layout(dv.layoutDoc)).forEach(layout => (layout._chromeHidden = !layout._chromeHidden));
-    };
-
     // todo: add brushes to brushMap to save with a style name
     onCustomKeypress = (e: React.KeyboardEvent) => {
         if (e.key === 'Enter') {
@@ -95,13 +85,9 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
             .map(key => runInAction(() => this._addedKeys.add(key.replace('layout_', ''))));
     }
 
-    return100 = () => 100;
+    return100 = () => 300;
     @computed get scriptField() {
-        const script = ScriptField.MakeScript(
-            'docs.map(d => switchView(d, this))',
-            { this: Doc.name, heading: 'string', checked: 'string', containingTreeView: Doc.name, firstDoc: Doc.name },
-            { docs: new List<Doc>(this.props.docViews.map(dv => dv.props.Document)) }
-        );
+        const script = ScriptField.MakeScript('docs.map(d => switchView(d, this))', { this: Doc.name }, { docs: this.props.docViews.map(dv => dv.props.Document) as any });
         return script ? () => script : undefined;
     }
     templateIsUsed = (selDoc: Doc, templateDoc: Doc) => {
@@ -113,13 +99,10 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
         const firstDoc = this.props.docViews[0].props.Document;
         const templateName = StrCast(firstDoc.layoutKey, 'layout').replace('layout_', '');
         const noteTypes = DocListCast(Cast(Doc.UserDoc()['template-notes'], Doc, null)?.data);
-        const addedTypes = Doc.noviceMode ? [] : DocListCast(Cast(Doc.UserDoc()['template-buttons'], Doc, null)?.data);
-        const layout = Doc.Layout(firstDoc);
+        const addedTypes = DocListCast(Cast(Doc.UserDoc()['template-clickFuncs'], Doc, null)?.data);
         const templateMenu: Array<JSX.Element> = [];
         this.props.templates?.forEach((checked, template) => templateMenu.push(<TemplateToggle key={template} template={template} checked={checked} toggle={this.toggleTemplate} />));
-        templateMenu.push(<OtherToggle key={'audio'} name={'Audio'} checked={firstDoc._showAudio ? true : false} toggle={this.toggleAudio} />);
         templateMenu.push(<OtherToggle key={'default'} name={'Default'} checked={templateName === 'layout'} toggle={this.toggleDefault} />);
-        !Doc.noviceMode && templateMenu.push(<OtherToggle key={'chrome'} name={'Chrome'} checked={!layout._chromeHidden} toggle={this.toggleChrome} />);
         addedTypes.concat(noteTypes).map(template => (template.treeViewChecked = this.templateIsUsed(firstDoc, template)));
         this._addedKeys &&
             Array.from(this._addedKeys)
@@ -129,43 +112,42 @@ export class TemplateMenu extends React.Component<TemplateMenuProps> {
             <ul className="template-list" style={{ display: 'block' }}>
                 {Doc.noviceMode ? null : <input placeholder="+ layout" ref={this._customRef} onKeyPress={this.onCustomKeypress} />}
                 {templateMenu}
-                {Doc.noviceMode ? null : (
-                    <CollectionTreeView
-                        Document={Doc.MyTemplates}
-                        CollectionView={undefined}
-                        ContainingCollectionDoc={undefined}
-                        ContainingCollectionView={undefined}
-                        styleProvider={DefaultStyleProvider}
-                        setHeight={returnFalse}
-                        docViewPath={returnEmptyDoclist}
-                        docFilters={returnEmptyFilter}
-                        docRangeFilters={returnEmptyFilter}
-                        searchFilterDocs={returnEmptyDoclist}
-                        rootSelected={returnFalse}
-                        onCheckedClick={this.scriptField}
-                        onChildClick={this.scriptField}
-                        dropAction={undefined}
-                        isAnyChildContentActive={returnFalse}
-                        isContentActive={returnTrue}
-                        bringToFront={emptyFunction}
-                        focus={emptyFunction}
-                        whenChildContentsActiveChanged={emptyFunction}
-                        ScreenToLocalTransform={Transform.Identity}
-                        isSelected={returnFalse}
-                        pinToPres={emptyFunction}
-                        select={emptyFunction}
-                        renderDepth={1}
-                        addDocTab={returnFalse}
-                        PanelWidth={this.return100}
-                        PanelHeight={this.return100}
-                        treeViewHideHeaderFields={true}
-                        dontRegisterView={true}
-                        fieldKey={'data'}
-                        moveDocument={returnFalse}
-                        removeDocument={returnFalse}
-                        addDocument={returnFalse}
-                    />
-                )}
+                <CollectionTreeView
+                    Document={Doc.MyTemplates}
+                    CollectionView={undefined}
+                    ContainingCollectionDoc={undefined}
+                    ContainingCollectionView={undefined}
+                    styleProvider={DefaultStyleProvider}
+                    setHeight={returnFalse}
+                    docViewPath={returnEmptyDoclist}
+                    docFilters={returnEmptyFilter}
+                    docRangeFilters={returnEmptyFilter}
+                    searchFilterDocs={returnEmptyDoclist}
+                    rootSelected={returnFalse}
+                    onCheckedClick={this.scriptField}
+                    onChildClick={this.scriptField}
+                    dropAction={undefined}
+                    isAnyChildContentActive={returnFalse}
+                    isContentActive={returnTrue}
+                    bringToFront={emptyFunction}
+                    focus={emptyFunction}
+                    whenChildContentsActiveChanged={emptyFunction}
+                    ScreenToLocalTransform={Transform.Identity}
+                    isSelected={returnFalse}
+                    pinToPres={emptyFunction}
+                    select={emptyFunction}
+                    renderDepth={1}
+                    addDocTab={returnFalse}
+                    PanelWidth={this.return100}
+                    PanelHeight={this.return100}
+                    treeViewHideHeaderFields={true}
+                    treeViewHideTitle={true}
+                    dontRegisterView={true}
+                    fieldKey={'data'}
+                    moveDocument={returnFalse}
+                    removeDocument={returnFalse}
+                    addDocument={returnFalse}
+                />
             </ul>
         );
     }
-- 
cgit v1.2.3-70-g09d2

