Debian Codegraph @

sys/ScriptEditor.cpp

raw symbols SCIP
1 /* ScriptEditor.cpp
2 *
3 * Copyright (C) 1997-2005,2007-2018,2020-2026 Paul Boersma
4 *
5 * This code is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "ScriptEditor.h"cxx . . $ `<file>/sys/ScriptEditor.h`/
20 #include "../kar/longchar.h"cxx . . $ `<file>/kar/longchar.h`/
21 #include "praatP.h"cxx . . $ `<file>/sys/praatP.h`/
22 #include "EditorM.h"cxx . . $ `<file>/sys/EditorM.h`/
23 #include "UiPause.h"cxx . . $ `<file>/sys/UiPause.h`/
24
25 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (ScriptEditor, TextEditor, 0);
26
27 CollectionOfcxx . . $ CollectionOf# <structScriptEditorcxx . . $ structScriptEditor#> theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors.;
28
29 bool ScriptEditors_dirtycxx . . $ ScriptEditors_dirty(c9857a73d68e59ba). () {
30 for (integercxx . . $ integer# i = 1; i <= theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..sizecxx . . $ CollectionOf#size.; i ++) {
31 const ScriptEditorcxx . . $ ScriptEditor# me = theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i];
32 if (mycxx . . $ `melder/melder.h:44:9`! dirtycxx . . $ structTextEditor#dirty.)
33 return true;
34 }
35 return false;
36 }
37
38 void structScriptEditorcxx . . $ structScriptEditor# :: v9_destroycxx . . $ structScriptEditor#v9_destroy(ced63f7c635d850d). () noexcept {
39 ourcxx . . $ `melder/melder.h:42:9`! argsDialogcxx . . $ structScriptEditor#argsDialog.. resetcxx . . $ autoSomeThing#reset(ced63f7c635d850d).(); // don't delay till delete
40 theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors.. undangleItemcxx . . $ CollectionOf#undangleItem(97cddd01752945f6). (this);
41 ScriptEditor_Parentcxx . . $ ScriptEditor_Parent# :: v9_destroycxx . . $ structTextEditor#v9_destroy(ced63f7c635d850d). ();
42 }
43
44 void structScriptEditorcxx . . $ structScriptEditor# :: v_nameChangedcxx . . $ structScriptEditor#v_nameChanged(49f6e7a06ebc5aa8). () {
45 /*
46 As TextEditor does, we totally ignore the name that our boss wants to give us.
47 Instead, we compose the window title from five ingredients, i.e. two more than TextEditor:
48
49 (1) whether we are already associated with a file or not;
50 (2) if so, the full file path;
51 (3) whether our text has been modified (i.e. whether we are "dirty");
52 (4) whether we have a boss, i.e. whether or not we were created from a data editor;
53 (5) if so, the name of our boss, i.e. of the data editor that we were created from.
54
55 (last checked 2023-02-25)
56 */
57 const bool dirtinessAlreadyShown = GuiWindow_setDirtycxx . . $ GuiWindow_setDirty(aed7644c12df6ab). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., ourcxx . . $ `melder/melder.h:42:9`! dirtycxx . . $ structTextEditor#dirty.); // (3) on the Mac (last checked 2023-02-25)
58 static MelderStringcxx . . $ MelderString# buffer;
59 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& buffer, MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structTextEditor#file.) ? U"untitled script" : U"Script"); // (1)
60 if (ourcxx . . $ `melder/melder.h:42:9`! wasCreatedInAnEditorcxx . . $ structScriptEditor#wasCreatedInAnEditor(3482b152b9333168).()) {
61 if (ourcxx . . $ `melder/melder.h:42:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor.)
62 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U" [editor “", Thing_getNamecxx . . $ Thing_getName(fbb3dc34e3ef688d). (ourcxx . . $ `melder/melder.h:42:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor.), U"”]"); // (4), (5)
63 else
64 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U" [closed ", ourcxx . . $ `melder/melder.h:42:9`! optionalOwningEditorClassNamecxx . . $ structScriptEditor#optionalOwningEditorClassName..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"]"); // (4)
65 }
66 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structTextEditor#file.))
67 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U" ", MelderFile_messageNamecxx . . $ MelderFile_messageName(d9f043369fa9b55b). (& ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structTextEditor#file.)); // (2)
68 if (ourcxx . . $ `melder/melder.h:42:9`! dirtycxx . . $ structTextEditor#dirty. && ! dirtinessAlreadyShown)
69 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& buffer, U" (modified)"); // (3) on Windows and Linux (last checked 2023-02-25)
70 GuiShell_setTitlecxx . . $ GuiShell_setTitle(3a9df304850abc11). (windowFormcxx . . $ structEditor#windowForm., buffer.stringcxx . . $ MelderString#string.);
71 /*
72 Finally, remember the name of this script.
73 */
74 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structTextEditor#file.)) {
75 autoScriptcxx . . $ autoScript# script = Script_createFromFilecxx . . $ Script_createFromFile(bd133301ef0e84d8). (& ourcxx . . $ `melder/melder.h:42:9`! filecxx . . $ structTextEditor#file.);
76 Script_rememberDuringThisAppSession_movecxx . . $ Script_rememberDuringThisAppSession_move(76c604abe5acc916). (scriptcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
77 }
78 }
79
80 static void common_args_okcxx . . $ common_args_ok(fb00952ff2296942). (UiFormcxx . . $ UiForm# sendingForm, void *void_me, Editorcxx . . $ Editor# optionalEditor, const bool fullTrust) {
81 iamcxx . . $ `melder/melder.h:50:9`! (ScriptEditor);
82 autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
83 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
84 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
85 Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text);
86
87 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditor == optionalEditor); // TODO: if never fires, then redundancy
88 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack);
89 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack -> interpreters [1]);
90 //Melder_assert (interpreter); // TODO: figure out why this is usually null
91 Interpreter_getArgumentsFromDialogcxx . . $ Interpreter_getArgumentsFromDialog(d4b141834b28b228). (mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1].getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), sendingForm);
92
93 autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).;
94 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
95 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
96 Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1].getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file., fullTrust); // right before running! (not at interpreter creation, because the name may change)
97 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (autoInterpretercxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false);
98 }
99 static void args_okcxx . . $ args_ok(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, conststring32cxx . . $ conststring32# /* sendingString */,
100 Interpretercxx . . $ Interpreter# /* interpreter */, conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *void_me, Editorcxx . . $ Editor# optionalEditor)
101 {
102 common_args_okcxx . . $ common_args_ok(fb00952ff2296942). (sendingForm, void_me, optionalEditor, false);
103 }
104 static void args_ok_FULL_TRUSTcxx . . $ args_ok_FULL_TRUST(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, conststring32cxx . . $ conststring32# /* sendingString */,
105 Interpretercxx . . $ Interpreter# /* interpreter */, conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *void_me, Editorcxx . . $ Editor# optionalEditor)
106 {
107 common_args_okcxx . . $ common_args_ok(fb00952ff2296942). (sendingForm, void_me, optionalEditor, true);
108 }
109
110 static void common_args_ok_selectionOnlycxx . . $ common_args_ok_selectionOnly(fb00952ff2296942). (UiFormcxx . . $ UiForm# sendingForm, void *void_me, Editorcxx . . $ Editor# optionalEditor, const bool fullTrust)
111 {
112 iamcxx . . $ `melder/melder.h:50:9`! (ScriptEditor);
113 autostring32cxx . . $ autostring32# text = GuiText_getSelectioncxx . . $ GuiText_getSelection(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
114 if (! text)
115 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No text is selected any longer.\nPlease reselect or click Cancel.");
116 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
117 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
118 Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text);
119
120 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditor == optionalEditor); // TODO: if never fires, then redundancy
121 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack);
122 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack -> interpreters [1]);
123 //Melder_assert (interpreter); // TODO: figure out why this is usually null
124 Interpreter_getArgumentsFromDialogcxx . . $ Interpreter_getArgumentsFromDialog(d4b141834b28b228). (mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1].getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), sendingForm);
125
126 autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).;
127 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
128 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
129 Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1].getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file., fullTrust);
130 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (autoInterpretercxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false);
131 }
132 static void args_ok_selectionOnlycxx . . $ args_ok_selectionOnly(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, conststring32cxx . . $ conststring32# /* sendingString */,
133 Interpretercxx . . $ Interpreter# /* interpreter */, conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *void_me, Editorcxx . . $ Editor# optionalEditor)
134 {
135 common_args_ok_selectionOnlycxx . . $ common_args_ok_selectionOnly(fb00952ff2296942). (sendingForm, void_me, optionalEditor, false);
136 }
137 static void args_ok_selectionOnly_FULL_TRUSTcxx . . $ args_ok_selectionOnly_FULL_TRUST(744a0abd3c8513c). (UiFormcxx . . $ UiForm# sendingForm, integercxx . . $ integer# /* narg */, Stackelcxx . . $ Stackel# /* args */, conststring32cxx . . $ conststring32# /* sendingString */,
138 Interpretercxx . . $ Interpreter# /* interpreter */, conststring32cxx . . $ conststring32# /* invokingButtonTitle */, bool /* modified */, void *void_me, Editorcxx . . $ Editor# optionalEditor)
139 {
140 common_args_ok_selectionOnlycxx . . $ common_args_ok_selectionOnly(fb00952ff2296942). (sendingForm, void_me, optionalEditor, true);
141 }
142
143 static void common_menu_cb_runcxx . . $ common_menu_cb_run(eae42598d331e92b). (ScriptEditorcxx . . $ ScriptEditor# me, const bool fullTrust) {
144 try {
145 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack);
146 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). ();
147 autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). (
148 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(),
149 mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor.,
150 & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.
151 );
152 autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
153 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
154 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.); // TODO: can be wrong
155 Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text);
156 const integercxx . . $ integer# npar = Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
157 if (npar != 0) {
158 /*
159 Pop up a dialog box for querying the arguments.
160 */
161 mycxx . . $ `melder/melder.h:44:9`! argsDialogcxx . . $ structScriptEditor#argsDialog. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Interpreter_createFormcxx . . $ Interpreter_createForm(cb75ceafc4a9bd55). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! windowFormcxx . . $ structEditor#windowForm., mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor., nullptr,
162 fullTrust ? args_ok_FULL_TRUSTcxx . . $ args_ok_FULL_TRUST(744a0abd3c8513c). : args_okcxx . . $ args_ok(744a0abd3c8513c)., me, false); // trust setting cannot be done earlier
163 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1] =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). interpreter.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
164 UiForm_docxx . . $ UiForm_do(c04b2c306b4dc6f4). (mycxx . . $ `melder/melder.h:44:9`! argsDialogcxx . . $ structScriptEditor#argsDialog..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false);
165 } else {
166 autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).;
167 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
168 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
169 Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file., fullTrust);
170 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreter -> owningInterpreterStack);
171 interpreter ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). owningInterpreterStackcxx . . $ structInterpreter#owningInterpreterStack. -> emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); // TODO: should we create a new InterpreterStack instead, owned by the script editor?
172 interpreter ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). owningInterpreterStackcxx . . $ structInterpreter#owningInterpreterStack. -> runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), textcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).(), false);
173 }
174 } catch (MelderErrorcxx . . $ MelderError#) {
175 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"The script didn’t run to its completion.");
176 }
177 }
178 static void menu_cb_runcxx . . $ menu_cb_run(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
179 common_menu_cb_runcxx . . $ common_menu_cb_run(eae42598d331e92b). (me, false);
180 }
181 static void menu_cb_runWithFullTrustcxx . . $ menu_cb_runWithFullTrust(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
182 common_menu_cb_runcxx . . $ common_menu_cb_run(eae42598d331e92b). (me, true);
183 }
184
185 static void common_menu_cb_runSelectioncxx . . $ common_menu_cb_runSelection(eae42598d331e92b). (ScriptEditorcxx . . $ ScriptEditor# me, const bool fullTrust) {
186 try {
187 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! interpreterStack);
188 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). ();
189 autoInterpretercxx . . $ autoInterpreter# interpreter = Interpreter_createFromEnvironmentcxx . . $ Interpreter_createFromEnvironment(2a446a9b6f15a803). (
190 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(),
191 mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor.,
192 & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.
193 );
194 autostring32cxx . . $ autostring32# selectedText = GuiText_getSelectioncxx . . $ GuiText_getSelection(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
195 if (! selectedText)
196 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No text selected.");
197 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
198 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
199 Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& selectedText);
200 const integercxx . . $ integer# npar = Interpreter_readParameterscxx . . $ Interpreter_readParameters(9dd4ed1655057857). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), selectedText.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
201 /*
202 TODO: check that no two procedures have the same name
203 */
204
205 /*
206 Add all the procedures to the selected text.
207 A procedure is counted as any text that honours the following conditions:
208 - it starts with a line starting with the text "procedure"
209 optionally preceded by whitespace and obligatorily followed by whitespace;
210 - it ends with a line starting with the text "endproc"
211 optionally preceded by whitespace and obligatorily followed by null or whitespace.
212 */
213 autoMelderStringcxx . . $ autoMelderString# textPlusProcedurescxx . . $ autoMelderString#autoMelderString(49f6e7a06ebc5aa8).;
214 MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& textPlusProcedures, selectedText.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
215 {// scope
216 autostring32cxx . . $ autostring32# wholeText = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
217 autoMelderReadTextcxx . . $ autoMelderReadText# textReader = MelderReadText_createFromTextcxx . . $ MelderReadText_createFromText(ec22451ee8ecfd96). (wholeTextcxx . . $ _autostring#_autostring(39021ecceedcc7d2)..movecxx . . $ _autostring#move(bd43c759570f178f).());
218 int procedureDepth = 0;
219 for (;;) {
220 const conststring32cxx . . $ conststring32# line = MelderReadText_readLinecxx . . $ MelderReadText_readLine(f4aa1d9b94177768). (textReader.getcxx . . $ std/unique_ptr#get(ea7391e9eeeaf20e).());
221 if (! line)
222 break;
223 const conststring32cxx . . $ conststring32# startOfCode = Melder_findEndOfHorizontalSpacecxx . . $ Melder_findEndOfHorizontalSpace(5553299aa8c4fee9). (line);
224 if (Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (startOfCode, U"procedure") && Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (startOfCode [9]))
225 procedureDepth += 1;
226 if (procedureDepth > 0)
227 MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (& textPlusProcedures, U"\n", line);
228 if (Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (startOfCode, U"endproc") && (startOfCode [7] == U'\0' || Melder_isHorizontalSpacecxx . . $ Melder_isHorizontalSpace(b8d0204ce8416907). (startOfCode [7])))
229 procedureDepth -= 1;
230 }
231 }
232
233 if (npar != 0) {
234 /*
235 Pop up a dialog box for querying the arguments.
236 */
237 mycxx . . $ `melder/melder.h:44:9`! argsDialogcxx . . $ structScriptEditor#argsDialog. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Interpreter_createFormcxx . . $ Interpreter_createForm(cb75ceafc4a9bd55). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! windowFormcxx . . $ structEditor#windowForm., mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor., nullptr, args_ok_selectionOnlycxx . . $ args_ok_selectionOnly(744a0abd3c8513c)., me, true);
238 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). interpreterscxx . . $ structInterpreterStack#interpreters. [1] =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). interpreter.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).();
239 UiForm_docxx . . $ UiForm_do(c04b2c306b4dc6f4). (mycxx . . $ `melder/melder.h:44:9`! argsDialogcxx . . $ structScriptEditor#argsDialog..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), false);
240 } else {
241 autoPraatBackgroundcxx . . $ autoPraatBackground# backgroundcxx . . $ autoPraatBackground#autoPraatBackground(49f6e7a06ebc5aa8).;
242 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
243 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
244 Interpreter_rememberScriptcxx . . $ Interpreter_rememberScript(a0c4c87353b136f2). (interpreter.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file., fullTrust);
245 Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (interpreter -> owningInterpreterStack);
246 interpreter ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). owningInterpreterStackcxx . . $ structInterpreter#owningInterpreterStack. -> emptyAllcxx . . $ structInterpreterStack#emptyAll(49f6e7a06ebc5aa8). (); // TODO: should we create a new InterpreterStack instead, owned by the script editor?
247 interpreter ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). owningInterpreterStackcxx . . $ structInterpreter#owningInterpreterStack. -> runDowncxx . . $ structInterpreterStack#runDown(f108da249e59f621). (interpretercxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (textPlusProcedures.stringcxx . . $ MelderString#string.), false);
248 }
249 } catch (MelderErrorcxx . . $ MelderError#) {
250 Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"The script selection didn’t run to its completion.");
251 }
252 }
253 static void menu_cb_runSelectioncxx . . $ menu_cb_runSelection(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
254 common_menu_cb_runSelectioncxx . . $ common_menu_cb_runSelection(eae42598d331e92b). (me, false);
255 }
256 static void menu_cb_runSelectionWithFullTrustcxx . . $ menu_cb_runSelectionWithFullTrust(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
257 common_menu_cb_runSelectioncxx . . $ common_menu_cb_runSelection(eae42598d331e92b). (me, true);
258 }
259
260 static void menu_cb_addToMenucxx . . $ menu_cb_addToMenu(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
261 EDITOR_FORMcxx . . $ `sys/EditorM.h:33:9`! (U"Add to menu", U"Add to fixed menu...")
262 WORDcxx . . $ `sys/EditorM.h:184:9`! (window, U"Window", U"?")
263 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (menu, U"Menu", U"File")
264 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (command, U"Command", U"Do it...")
265 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (afterCommand, U"After command", U"")
266 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (depth, U"Depth", U"0")
267 INFILEcxx . . $ `sys/EditorM.h:295:9`! (scriptFile, U"Script file", U"")
268 EDITOR_OKcxx . . $ `sys/EditorM.h:38:9`!
269 if (mycxx . . $ `melder/melder.h:44:9`! wasCreatedInAnEditorcxx . . $ structScriptEditor#wasCreatedInAnEditor(3482b152b9333168).())
270 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (window, mycxx . . $ `melder/melder.h:44:9`! optionalOwningEditorClassName.get())
271 if (MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
272 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, U"(please save your script first)")
273 else
274 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, MelderFile_peekPath (& mycxx . . $ `melder/melder.h:44:9`! file));
275 EDITOR_DOcxx . . $ `sys/EditorM.h:43:9`!
276 praat_addMenuCommandScriptcxx . . $ praat_addMenuCommandScript(ce2dc7cf61cce937). (window, menu, command, afterCommand, depth, scriptFile);
277 praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). ();
278 EDITOR_ENDcxx . . $ `sys/EditorM.h:80:9`!
279 }
280
281 static void menu_cb_addToFixedMenucxx . . $ menu_cb_addToFixedMenu(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
282 EDITOR_FORMcxx . . $ `sys/EditorM.h:33:9`! (U"Add to fixed menu", U"Add to fixed menu...");
283 CHOICESTRcxx . . $ `sys/EditorM.h:366:9`! (window, U"Window", 1)
284 OPTIONcxx . . $ `sys/EditorM.h:387:9`! (U"Objects")
285 OPTIONcxx . . $ `sys/EditorM.h:387:9`! (U"Picture")
286 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (menu, U"Menu", U"New")
287 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (command, U"Command", U"Do it...")
288 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (afterCommand, U"After command", U"")
289 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (depth, U"Depth", U"0")
290 INFILEcxx . . $ `sys/EditorM.h:295:9`! (scriptFile, U"Script file", U"")
291 EDITOR_OKcxx . . $ `sys/EditorM.h:38:9`!
292 if (MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
293 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, U"(please save your script first)")
294 else
295 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, MelderFile_peekPath (& mycxx . . $ `melder/melder.h:44:9`! file))
296 EDITOR_DOcxx . . $ `sys/EditorM.h:43:9`!
297 praat_addMenuCommandScriptcxx . . $ praat_addMenuCommandScript(ce2dc7cf61cce937). (window, menu, command, afterCommand, depth, scriptFile);
298 praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). ();
299 EDITOR_ENDcxx . . $ `sys/EditorM.h:80:9`!
300 }
301
302 static void menu_cb_addToDynamicMenucxx . . $ menu_cb_addToDynamicMenu(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
303 EDITOR_FORMcxx . . $ `sys/EditorM.h:33:9`! (U"Add to dynamic menu", U"Add to dynamic menu...")
304 WORDcxx . . $ `sys/EditorM.h:184:9`! (class1, U"Class 1", U"Sound")
305 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (number1, U"Number 1", U"0")
306 WORDcxx . . $ `sys/EditorM.h:184:9`! (class2, U"Class 2", U"")
307 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (number2, U"Number 2", U"0")
308 WORDcxx . . $ `sys/EditorM.h:184:9`! (class3, U"Class 3", U"")
309 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (number3, U"Number 3", U"0")
310 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (command, U"Command", U"Do it...")
311 SENTENCEcxx . . $ `sys/EditorM.h:195:9`! (afterCommand, U"After command", U"")
312 INTEGERcxx . . $ `sys/EditorM.h:139:9`! (depth, U"Depth", U"0")
313 INFILEcxx . . $ `sys/EditorM.h:295:9`! (scriptFile, U"Script file", U"")
314 EDITOR_OKcxx . . $ `sys/EditorM.h:38:9`!
315 if (MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
316 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, U"(please save your script first)")
317 else
318 SET_STRINGcxx . . $ `sys/EditorM.h:477:9`! (scriptFile, MelderFile_peekPath (& mycxx . . $ `melder/melder.h:44:9`! file))
319 EDITOR_DOcxx . . $ `sys/EditorM.h:43:9`!
320 praat_addActionScriptcxx . . $ praat_addActionScript(dcd860f3b50ce413). (class1, number1, class2, number2, class3, number3, command, afterCommand, depth, scriptFile);
321 praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). ();
322 EDITOR_ENDcxx . . $ `sys/EditorM.h:80:9`!
323 }
324
325 static void menu_cb_clearHistorycxx . . $ menu_cb_clearHistory(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# /* me */, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
326 UiHistory_clearcxx . . $ UiHistory_clear(49f6e7a06ebc5aa8). ();
327 }
328
329 static void menu_cb_pasteHistorycxx . . $ menu_cb_pasteHistory(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
330 char32cxx . . $ char32# *history = UiHistory_getcxx . . $ UiHistory_get(7f2d784185c6d30e). ();
331 if (! history || history [0] == U'\0')
332 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No history.");
333 integercxx . . $ integer# length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (history);
334 if (history [length - 1] != U'\n') {
335 UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\n");
336 history = UiHistory_getcxx . . $ UiHistory_get(7f2d784185c6d30e). ();
337 length = Melder_lengthcxx . . $ Melder_length(3fae411214b133ad). (history);
338 }
339 if (history [0] == U'\n') {
340 history ++;
341 length --;
342 }
343 integercxx . . $ integer# first = 0, last = 0;
344 autostring32cxx . . $ autostring32# text = GuiText_getStringAndSelectionPositioncxx . . $ GuiText_getStringAndSelectionPosition(2d4f5aac9640119d). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget., & first, & last);
345 GuiText_replacecxx . . $ GuiText_replace(27ef96c8abc2c4e2). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget., first, last, history);
346 GuiText_setSelectioncxx . . $ GuiText_setSelection(e06f404191ddd8ec). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget., first, first + length);
347 GuiText_scrollToSelectioncxx . . $ GuiText_scrollToSelection(9d8ddf5c89937cf2). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
348 }
349
350 static void menu_cb_expandIncludeFilescxx . . $ menu_cb_expandIncludeFiles(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor# me, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) {
351 autostring32cxx . . $ autostring32# text = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget.);
352 if (! MelderFile_isNullcxx . . $ MelderFile_isNull(8f92cdf95b27d908). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.))
353 MelderFile_setDefaultDircxx . . $ MelderFile_setDefaultDir(1145552d769d7b5d). (& mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
354 Melder_includeIncludeFilescxx . . $ Melder_includeIncludeFiles(2d5e149ff849c92b). (& text);
355 GuiText_setStringcxx . . $ GuiText_setString(d44acbd60ea2b9be). (mycxx . . $ `melder/melder.h:44:9`! textWidgetcxx . . $ structTextEditor#textWidget., text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
356 }
357
358 static void menu_cb_AboutScriptEditorcxx . . $ menu_cb_AboutScriptEditor(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"ScriptEditor"); }
359 static void menu_cb_ScriptingTutorialcxx . . $ menu_cb_ScriptingTutorial(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Scripting"); }
360 static void menu_cb_ScriptingExamplescxx . . $ menu_cb_ScriptingExamples(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Scripting examples"); }
361 static void menu_cb_PraatScriptcxx . . $ menu_cb_PraatScript(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Praat script"); }
362 static void menu_cb_FormulasTutorialcxx . . $ menu_cb_FormulasTutorial(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Formulas"); }
363 static void menu_cb_Functionscxx . . $ menu_cb_Functions(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Functions"); }
364 static void menu_cb_DemoWindowcxx . . $ menu_cb_DemoWindow(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Demo window"); }
365 static void menu_cb_TheHistoryMechanismcxx . . $ menu_cb_TheHistoryMechanism(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"History mechanism"); }
366 static void menu_cb_InitializationScriptscxx . . $ menu_cb_InitializationScripts(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Initialization script"); }
367 static void menu_cb_AddingToAFixedMenucxx . . $ menu_cb_AddingToAFixedMenu(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Add to fixed menu..."); }
368 static void menu_cb_AddingToADynamicMenucxx . . $ menu_cb_AddingToADynamicMenu(e69fecf946d2711b). (ScriptEditorcxx . . $ ScriptEditor#, EDITOR_ARGScxx . . $ `sys/EditorM.h:25:9`!) { Melder_helpcxx . . $ Melder_help(ff00d524ab0355ec). (U"Add to dynamic menu..."); }
369
370 void structScriptEditorcxx . . $ structScriptEditor# :: v_createMenuscxx . . $ structScriptEditor#v_createMenus(49f6e7a06ebc5aa8). () {
371 ScriptEditor_Parentcxx . . $ ScriptEditor_Parent# :: v_createMenuscxx . . $ structTextEditor#v_createMenus(49f6e7a06ebc5aa8). ();
372 if (ourcxx . . $ `melder/melder.h:42:9`! wasCreatedInAnEditorcxx . . $ structScriptEditor#wasCreatedInAnEditor(3482b152b9333168).()) {
373 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"File", U"Add to menu...", 0, menu_cb_addToMenucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
374 } else {
375 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"File", U"Add to fixed menu...", 0, menu_cb_addToFixedMenucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
376 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"File", U"Add to dynamic menu...", 0, menu_cb_addToDynamicMenucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
377 }
378 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"File", U"-- close --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
379 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Edit", U"-- history --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
380 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Edit", U"Clear history", 0, menu_cb_clearHistorycxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
381 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Edit", U"Paste history", 'H', menu_cb_pasteHistorycxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
382 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Convert", U"-- expand --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
383 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Convert", U"Expand include files", 0, menu_cb_expandIncludeFilescxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
384 Editor_addMenucxx . . $ Editor_addMenu(8b39ac34ca8e016f). (this, U"Run", 0);
385 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Run", U"Run", 'R', menu_cb_runcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
386 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Run", U"Run selection", 'T', menu_cb_runSelectioncxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
387 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Run", U"-- run with full trust --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
388 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Run", U"Run with FULL TRUST", 0, menu_cb_runWithFullTrustcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
389 Editor_addCommandcxx . . $ Editor_addCommand(d7f2c642863274c0). (this, U"Run", U"Run selection with FULL TRUST", 0, menu_cb_runSelectionWithFullTrustcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
390 }
391
392 void structScriptEditorcxx . . $ structScriptEditor# :: v_createMenuItems_helpcxx . . $ structScriptEditor#v_createMenuItems_help(6ea9c8c6ea2f58a9). (EditorMenucxx . . $ EditorMenu# menu) {
393 ScriptEditor_Parentcxx . . $ ScriptEditor_Parent# :: v_createMenuItems_helpcxx . . $ structDataGui#v_createMenuItems_help(6ea9c8c6ea2f58a9). (menu);
394 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"About ScriptEditor", '?', menu_cb_AboutScriptEditorcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
395 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Scripting tutorial", 0, menu_cb_ScriptingTutorialcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
396 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Scripting examples", 0, menu_cb_ScriptingExamplescxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
397 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Praat script", 0, menu_cb_PraatScriptcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
398 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Formulas tutorial", 0, menu_cb_FormulasTutorialcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
399 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Functions", 0, menu_cb_Functionscxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
400 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Demo window", 0, menu_cb_DemoWindowcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
401 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"-- help history --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
402 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"The History mechanism", 0, menu_cb_TheHistoryMechanismcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
403 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Initialization scripts", 0, menu_cb_InitializationScriptscxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
404 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"-- help add --", 0, nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112).);
405 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Adding to a fixed menu", 0, menu_cb_AddingToAFixedMenucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
406 EditorMenu_addCommandcxx . . $ EditorMenu_addCommand(b3c50ad5ffa1d58a). (menu, U"Adding to a dynamic menu", 0, menu_cb_AddingToADynamicMenucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97).);
407 }
408
409 void ScriptEditor_initcxx . . $ ScriptEditor_init(69f51ac727efc149). (ScriptEditorcxx . . $ ScriptEditor# me, Editorcxx . . $ Editor# optionalOwningEditor, conststring32cxx . . $ conststring32# initialText) {
410 if (optionalOwningEditor) {
411 mycxx . . $ `melder/melder.h:44:9`! optionalOwningEditorClassNamecxx . . $ structScriptEditor#optionalOwningEditorClassName. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dupcxx . . $ Melder_dup(87bf156b1f548402). (Thing_classNamecxx . . $ Thing_className(fbb3dc34e3ef688d). (optionalOwningEditor)); // BUG: no copying needed
412 mycxx . . $ `melder/melder.h:44:9`! optionalReferenceToOwningEditorcxx . . $ structScriptEditor#optionalReferenceToOwningEditor. = optionalOwningEditor;
413 }
414 TextEditor_initcxx . . $ TextEditor_init(9ba39b4797eb5880). (me, initialText);
415 mycxx . . $ `melder/melder.h:44:9`! interpreterStackcxx . . $ structScriptEditor#interpreterStack. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). InterpreterStack_createcxx . . $ InterpreterStack_create(91aa183261e4fa82). (optionalOwningEditor);
416 theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors.. addItem_refcxx . . $ CollectionOf#addItem_ref(ebd0a1552f8ce24f). (me);
417 }
418
419 autoScriptEditorcxx . . $ autoScriptEditor# ScriptEditor_createFromTextcxx . . $ ScriptEditor_createFromText(53cc301a35858397). (Editorcxx . . $ Editor# optionalOwningEditor, conststring32cxx . . $ conststring32# initialText) {
420 try {
421 autoScriptEditorcxx . . $ autoScriptEditor# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (ScriptEditor);
422 ScriptEditor_initcxx . . $ ScriptEditor_init(69f51ac727efc149). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), optionalOwningEditor, initialText);
423 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
424 } catch (MelderErrorcxx . . $ MelderError#) {
425 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script window not created.");
426 }
427 }
428
429 autoScriptEditorcxx . . $ autoScriptEditor# ScriptEditor_createFromScript_canBeNullcxx . . $ ScriptEditor_createFromScript_canBeNull(5fb1895a19deb5f9). (Editorcxx . . $ Editor# optionalOwningEditor, autoScriptcxx . . $ autoScript# script) {
430 try {
431 structMelderFilecxx . . $ structMelderFile# scriptFile { };
432 for (integercxx . . $ integer# ieditor = 1; ieditor <= theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..sizecxx . . $ CollectionOf#size.; ieditor ++) {
433 ScriptEditorcxx . . $ ScriptEditor# editor = theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ieditor];
434 if (Melder_equcxx . . $ `melder/melder_str32.h:124:9`! (script ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& editor -> filecxx . . $ structTextEditor#file.))) {
435 Editor_raisecxx . . $ Editor_raise(c0154a85f79216c7). (editor);
436 Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (script ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & scriptFile); // ensure correct messaging format
437 Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"The script ", & scriptFile, U" is already open and has been moved to the front.");
438 if (editor -> dirtycxx . . $ structTextEditor#dirty.)
439 Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"Choose “Reopen from disk” if you want to revert to the old version.");
440 Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). ();
441 return autoScriptEditorcxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(); // safe null, and `script` will be deleted
442 }
443 }
444 Melder_pathToFilecxx . . $ Melder_pathToFile(82691f2ee21fbb13). (script ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). stringcxx . . $ structSimpleString#string..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), & scriptFile);
445 autostring32cxx . . $ autostring32# text = MelderFile_readTextcxx . . $ MelderFile_readText(2312d39ae70aea26). (& scriptFile);
446 autoScriptEditorcxx . . $ autoScriptEditor# me = ScriptEditor_createFromTextcxx . . $ ScriptEditor_createFromText(53cc301a35858397). (optionalOwningEditor, text.getcxx . . $ _autostring#get(5a2a78a048fb49a8).());
447 MelderFile_copycxx . . $ MelderFile_copy(b298201f6d539a65). (& scriptFile, & mycxx . . $ `melder/melder.h:44:9`! filecxx . . $ structTextEditor#file.);
448 Script_rememberDuringThisAppSession_movecxx . . $ Script_rememberDuringThisAppSession_move(76c604abe5acc916). (scriptcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).());
449 Thing_setNamecxx . . $ Thing_setName(b5a42e5e01c267b5). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), nullptr);
450 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
451 } catch (MelderErrorcxx . . $ MelderError#) {
452 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Script window not created.");
453 }
454 }
455
456 void ScriptEditor_debug_printAllOpenScriptEditorscxx . . $ ScriptEditor_debug_printAllOpenScriptEditors(49f6e7a06ebc5aa8). () {
457 for (integercxx . . $ integer# ieditor = 1; ieditor <= theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..sizecxx . . $ CollectionOf#size.; ieditor ++) {
458 ScriptEditorcxx . . $ ScriptEditor# editor = theReferencesToAllOpenScriptEditorscxx . . $ theReferencesToAllOpenScriptEditors..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ieditor];
459 Melder_casualcxx . . $ Melder_casual(6298c93241566110). (U"Open script editor #", ieditor, U": <<", & editor -> filecxx . . $ structTextEditor#file., U">>");
460 }
461 }
462
463 /* End of file ScriptEditor.cpp */