| 1 | /* praat_actions.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2018,2020-2024 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 2 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 "praatP.h"cxx . . $ `<file>/sys/praatP.h`/ |
| 20 | #include "praat_script.h"cxx . . $ `<file>/sys/praat_script.h`/ |
| 21 | #include "../kar/longchar.h"cxx . . $ `<file>/kar/longchar.h`/ |
| 22 | #include "machine.h"cxx . . $ `<file>/sys/machine.h`/ |
| 23 | #include "GuiP.h"cxx . . $ `<file>/sys/GuiP.h`/ |
| 24 | |
| 25 | #define BUTTON_LEFTcxx . . $ `sys/praat_actions.cpp:25:9`! -240 |
| 26 | #define BUTTON_RIGHTcxx . . $ `sys/praat_actions.cpp:26:9`! -5 |
| 27 | |
| 28 | static OrderedOfcxx . . $ OrderedOf# <structPraat_Commandcxx . . $ structPraat_Command#> theActionscxx . . $ theActions.; |
| 29 | void praat_actions_exit_optimizeByLeakingcxx . . $ praat_actions_exit_optimizeByLeaking(49f6e7a06ebc5aa8). () { theActionscxx . . $ theActions.. _ownItemscxx . . $ CollectionOf#_ownItems. = false; } |
| 30 | static GuiMenucxx . . $ GuiMenu# praat_writeMenucxx . . $ praat_writeMenu.; |
| 31 | static GuiMenuItemcxx . . $ GuiMenuItem# praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator.; |
| 32 | static GuiFormcxx . . $ GuiForm# praat_formcxx . . $ praat_form.; |
| 33 | static bool actionsInvisiblecxx . . $ actionsInvisible. = false; |
| 34 | |
| 35 | static void fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (ClassInfocxx . . $ ClassInfo# *class1, integercxx . . $ integer# *n1, ClassInfocxx . . $ ClassInfo# *class2, integercxx . . $ integer# *n2, ClassInfocxx . . $ ClassInfo# *class3, integercxx . . $ integer# *n3) { |
| 36 | /* |
| 37 | Function: |
| 38 | sort the specification pairs *class(i), *n(i) according to class name, with null classes at the end. |
| 39 | Postconditions: |
| 40 | if (*class2) !! *class1; |
| 41 | if (*class3) !! *class2; |
| 42 | (*class1) -> className <= (*class2) -> className <= (*class3) -> className; |
| 43 | Usage: |
| 44 | Called by praat_addAction () and praat_removeAction (). |
| 45 | */ |
| 46 | |
| 47 | /* |
| 48 | Fix unusual input bubblewise. |
| 49 | */ |
| 50 | if (! *class1 && *class2) { |
| 51 | *class1 = *class2; |
| 52 | *n1 = *n2; |
| 53 | *class2 = nullptr; |
| 54 | *n2 = 0; |
| 55 | } |
| 56 | if (! *class2 && *class3) { |
| 57 | *class2 = *class3; |
| 58 | *n2 = *n3; |
| 59 | *class3 = nullptr; |
| 60 | *n3 = 0; |
| 61 | if (! *class1 && *class2) { |
| 62 | *class1 = *class2; |
| 63 | *n1 = *n2; |
| 64 | *class2 = nullptr; |
| 65 | *n2 = 0; |
| 66 | } |
| 67 | } |
| 68 | |
| 69 | /* |
| 70 | Now: if *class3, then *class2, and if *class2, then *class1. |
| 71 | Bubble-sort the input by class name. |
| 72 | */ |
| 73 | if (*class2 && str32cmpcxx . . $ str32cmp(937dacc22d2a7919). ((*class1) -> classNamecxx . . $ structClassInfo#className., (*class2) -> classNamecxx . . $ structClassInfo#className.) > 0) { |
| 74 | ClassInfocxx . . $ ClassInfo# helpClass1 = *class1; *class1 = *class2; *class2 = helpClass1; |
| 75 | integercxx . . $ integer# helpN1 = *n1; *n1 = *n2; *n2 = helpN1; |
| 76 | } |
| 77 | if (*class3 && str32cmpcxx . . $ str32cmp(937dacc22d2a7919). ((*class2) -> classNamecxx . . $ structClassInfo#className., (*class3) -> classNamecxx . . $ structClassInfo#className.) > 0) { |
| 78 | ClassInfocxx . . $ ClassInfo# helpClass2 = *class2; *class2 = *class3; *class3 = helpClass2; |
| 79 | integercxx . . $ integer# helpN2 = *n2; *n2 = *n3; *n3 = helpN2; |
| 80 | if (str32cmpcxx . . $ str32cmp(937dacc22d2a7919). ((*class1) -> classNamecxx . . $ structClassInfo#className., (*class2) -> classNamecxx . . $ structClassInfo#className.) > 0) { |
| 81 | ClassInfocxx . . $ ClassInfo# helpClass1 = *class1; *class1 = *class2; *class2 = helpClass1; |
| 82 | integercxx . . $ integer# helpN1 = *n1; *n1 = *n2; *n2 = helpN1; |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | static integercxx . . $ integer# lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (ClassInfocxx . . $ ClassInfo# class1, ClassInfocxx . . $ ClassInfo# class2, ClassInfocxx . . $ ClassInfo# class3, ClassInfocxx . . $ ClassInfo# class4, conststring32cxx . . $ conststring32# title) { |
| 88 | /* |
| 89 | An action command is fully specified by its environment (the selected classes) and its title. |
| 90 | Precondition: |
| 91 | class1, class2, and class3 must be in sorted order. |
| 92 | */ |
| 93 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 94 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 95 | if (class1 == action -> class1cxx . . $ structPraat_Command#class1. && class2 == action -> class2cxx . . $ structPraat_Command#class2. && |
| 96 | class3 == action -> class3cxx . . $ structPraat_Command#class3. && class4 == action -> class4cxx . . $ structPraat_Command#class4. && |
| 97 | title && action -> titlecxx . . $ structPraat_Command#title. && str32equcxx . . $ `melder/melder_str32.h:122:9`! (action -> titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), title) |
| 98 | ) |
| 99 | return i; |
| 100 | } |
| 101 | return 0; // not found |
| 102 | } |
| 103 | |
| 104 | void praat_addAction1_cxx . . $ praat_addAction1_(a85663250716404b). (ClassInfocxx . . $ ClassInfo# class1, integercxx . . $ integer# n1, |
| 105 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, uint32cxx . . $ uint32# flags, UiCallbackcxx . . $ UiCallback# callback, conststring32cxx . . $ conststring32# nameOfCallback) |
| 106 | { praat_addAction4_cxx . . $ praat_addAction4_(62e0f6ea2fdde36d). (class1, n1, nullptr, 0, nullptr, 0, nullptr, 0, title, after, flags, callback, nameOfCallback); } |
| 107 | |
| 108 | void praat_addAction2_cxx . . $ praat_addAction2_(2445fc9969b00243). (ClassInfocxx . . $ ClassInfo# class1, integercxx . . $ integer# n1, ClassInfocxx . . $ ClassInfo# class2, integercxx . . $ integer# n2, |
| 109 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, uint32cxx . . $ uint32# flags, UiCallbackcxx . . $ UiCallback# callback, conststring32cxx . . $ conststring32# nameOfCallback) |
| 110 | { praat_addAction4_cxx . . $ praat_addAction4_(62e0f6ea2fdde36d). (class1, n1, class2, n2, nullptr, 0, nullptr, 0, title, after, flags, callback, nameOfCallback); } |
| 111 | |
| 112 | void praat_addAction3_cxx . . $ praat_addAction3_(cd8018cac012d365). (ClassInfocxx . . $ ClassInfo# class1, integercxx . . $ integer# n1, ClassInfocxx . . $ ClassInfo# class2, integercxx . . $ integer# n2, ClassInfocxx . . $ ClassInfo# class3, integercxx . . $ integer# n3, |
| 113 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, uint32cxx . . $ uint32# flags, UiCallbackcxx . . $ UiCallback# callback, conststring32cxx . . $ conststring32# nameOfCallback) |
| 114 | { praat_addAction4_cxx . . $ praat_addAction4_(62e0f6ea2fdde36d). (class1, n1, class2, n2, class3, n3, nullptr, 0, title, after, flags, callback, nameOfCallback); } |
| 115 | |
| 116 | static void praat_addAction4__cxx . . $ praat_addAction4__(62e0f6ea2fdde36d). (ClassInfocxx . . $ ClassInfo# class1, integercxx . . $ integer# n1, ClassInfocxx . . $ ClassInfo# class2, integercxx . . $ integer# n2, ClassInfocxx . . $ ClassInfo# class3, integercxx . . $ integer# n3, ClassInfocxx . . $ ClassInfo# class4, integercxx . . $ integer# n4, |
| 117 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, uint32cxx . . $ uint32# flags, UiCallbackcxx . . $ UiCallback# callback, conststring32cxx . . $ conststring32# nameOfCallback) |
| 118 | { |
| 119 | try { |
| 120 | uint32cxx . . $ uint32# depth = flags, key = 0; |
| 121 | bool unhidable = false, hidden = false, attractive = false; |
| 122 | uint32cxx . . $ uint32# guiFlags = 0; |
| 123 | if (flags > 7) { |
| 124 | depth = ((flags & GuiMenu_DEPTH_7cxx . . $ `sys/Gui.h:868:9`!) >> 16); |
| 125 | unhidable = (flags & GuiMenu_UNHIDABLEcxx . . $ `sys/Gui.h:870:9`!) != 0; |
| 126 | hidden = (flags & GuiMenu_HIDDENcxx . . $ `sys/Gui.h:869:9`!) != 0 && ! unhidable; |
| 127 | key = flags & 0x000000FF; |
| 128 | guiFlags = key ? flags & (0x000000FF | GuiMenu_SHIFTcxx . . $ `sys/Gui.h:811:9`! | GuiMenu_BUTTON_STATE_MASKcxx . . $ `sys/Gui.h:859:9`!) : flags & GuiMenu_BUTTON_STATE_MASKcxx . . $ `sys/Gui.h:859:9`!; |
| 129 | attractive = (guiFlags & GuiMenu_ATTRACTIVEcxx . . $ `sys/Gui.h:855:9`!) != 0; |
| 130 | } |
| 131 | fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (& class1, & n1, & class2, & n2, & class3, & n3); |
| 132 | |
| 133 | if (callback && ! title) |
| 134 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"An action command with callback has no title. Classes: ", |
| 135 | class1 ? class1 -> className : U"", U" ", |
| 136 | class2 ? class2 -> className : U"", U" ", |
| 137 | class3 ? class3 -> className : U"", U" ", |
| 138 | class4 ? class4 -> className : U"", U"." |
| 139 | ); |
| 140 | |
| 141 | if (! class1) |
| 142 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The action command \"", title, U"\" has no first class."); |
| 143 | |
| 144 | /* |
| 145 | Determine the position of the new command. |
| 146 | */ |
| 147 | integercxx . . $ integer# position; |
| 148 | if (after) { // search for existing command with same selection |
| 149 | const integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, class4, after); |
| 150 | if (found == 0) |
| 151 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The action command \"", title, U"\" cannot be put after \"", after, U"\",\n" |
| 152 | U"because the latter command does not exist."); |
| 153 | position = found + 1; // after 'after' |
| 154 | } else { |
| 155 | position = theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size. + 1; // at end |
| 156 | } |
| 157 | |
| 158 | /* |
| 159 | Make new command. |
| 160 | */ |
| 161 | autoPraat_Commandcxx . . $ autoPraat_Command# action = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Praat_Command); |
| 162 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class1cxx . . $ structPraat_Command#class1. = class1; |
| 163 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n1cxx . . $ structPraat_Command#n1. = n1; |
| 164 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class2cxx . . $ structPraat_Command#class2. = class2; |
| 165 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n2cxx . . $ structPraat_Command#n2. = n2; |
| 166 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class3cxx . . $ structPraat_Command#class3. = class3; |
| 167 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n3cxx . . $ structPraat_Command#n3. = n3; |
| 168 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class4cxx . . $ structPraat_Command#class4. = class4; |
| 169 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n4cxx . . $ structPraat_Command#n4. = n4; |
| 170 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). titlecxx . . $ structPraat_Command#title. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (title); |
| 171 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). depthcxx . . $ structPraat_Command#depth. = depth; |
| 172 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). callbackcxx . . $ structPraat_Command#callback. = callback; // null for a separator |
| 173 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback. = nameOfCallback; |
| 174 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). buttoncxx . . $ structPraat_Command#button. = nullptr; |
| 175 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). scriptcxx . . $ structPraat_Command#script. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(); |
| 176 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). hiddencxx . . $ structPraat_Command#hidden. = hidden; |
| 177 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). unhidablecxx . . $ structPraat_Command#unhidable. = unhidable; |
| 178 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). attractivecxx . . $ structPraat_Command#attractive. = attractive; |
| 179 | |
| 180 | /* |
| 181 | Insert new command. |
| 182 | */ |
| 183 | theActionscxx . . $ theActions.. addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (actioncxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), position); |
| 184 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 185 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 186 | } |
| 187 | } |
| 188 | void praat_addAction4_cxx . . $ praat_addAction4_(62e0f6ea2fdde36d). (ClassInfocxx . . $ ClassInfo# class1, integercxx . . $ integer# n1, ClassInfocxx . . $ ClassInfo# class2, integercxx . . $ integer# n2, ClassInfocxx . . $ ClassInfo# class3, integercxx . . $ integer# n3, ClassInfocxx . . $ ClassInfo# class4, integercxx . . $ integer# n4, |
| 189 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, uint32cxx . . $ uint32# flags, UiCallbackcxx . . $ UiCallback# callback, conststring32cxx . . $ conststring32# nameOfCallback) |
| 190 | { |
| 191 | const char32cxx . . $ char32# *pSeparator = str32strcxx . . $ str32str(2de17cd8f7c584a6). (title, U" || "); |
| 192 | if (! pSeparator) |
| 193 | return praat_addAction4__cxx . . $ praat_addAction4__(62e0f6ea2fdde36d). (class1, n1, class2, n2, class3, n3, class4, n4, |
| 194 | title, after, flags, callback, nameOfCallback); |
| 195 | if (flags < 8) |
| 196 | flags *= GuiMenu_DEPTH_1cxx . . $ `sys/Gui.h:862:9`!; // turn 1..7 into GuiMenu_DEPTH_1..GuiMenu_DEPTH_7, because the flags are ORed below |
| 197 | integercxx . . $ integer# positionOfSeparator = pSeparator - title; |
| 198 | static MelderStringcxx . . $ MelderString# string; |
| 199 | MelderString_copycxx . . $ MelderString_copy(65be51a793e0ff96). (& string, title); |
| 200 | char32cxx . . $ char32# *pTitle = & string.stringcxx . . $ MelderString#string. [0]; |
| 201 | do { |
| 202 | pTitle [positionOfSeparator] = U'\0'; |
| 203 | praat_addAction4__cxx . . $ praat_addAction4__(62e0f6ea2fdde36d). (class1, n1, class2, n2, class3, n3, class4, n4, |
| 204 | pTitle, after, flags, callback, nameOfCallback); |
| 205 | pTitle += positionOfSeparator + 4; // step past " || " |
| 206 | pSeparator = str32strcxx . . $ str32str(2de17cd8f7c584a6). (pTitle, U" || "); |
| 207 | if (pSeparator) |
| 208 | positionOfSeparator = pSeparator - pTitle; |
| 209 | flags |= GuiMenu_HIDDENcxx . . $ `sys/Gui.h:869:9`!; |
| 210 | } while (pSeparator); |
| 211 | praat_addAction4__cxx . . $ praat_addAction4__(62e0f6ea2fdde36d). (class1, n1, class2, n2, class3, n3, class4, n4, |
| 212 | pTitle, after, flags | GuiMenu_HIDDENcxx . . $ `sys/Gui.h:869:9`!, callback, nameOfCallback); |
| 213 | } |
| 214 | |
| 215 | static void deleteDynamicMenucxx . . $ deleteDynamicMenu(49f6e7a06ebc5aa8). () { |
| 216 | if (praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. != praat_HANDLING_EVENTScxx . . $ `sys/praatP.h:96:9`!) |
| 217 | return; |
| 218 | if (actionsInvisiblecxx . . $ actionsInvisible.) |
| 219 | return; |
| 220 | static integercxx . . $ integer# numberOfDeletions; |
| 221 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"deletion #", ++ numberOfDeletions); |
| 222 | #if motifcxx . . $ `sys/Gui.h:34:10`! |
| 223 | /* |
| 224 | Undangle the menu items. They can be destroyed by the removal of their pull-down menu. |
| 225 | */ |
| 226 | for (integer i = 1; i <= theActions.size; i ++) { |
| 227 | Praat_Command action = theActions.at [i]; |
| 228 | Melder_assert (action); |
| 229 | Melder_assert (Thing_isa (action, classPraat_Command)); |
| 230 | if (action -> button) { |
| 231 | Melder_assert (action -> button -> classInfo != classGuiMenu); |
| 232 | if (action -> button -> classInfo == classGuiMenuItem) |
| 233 | action -> button = nullptr; // prevent destruction; the menu will take care of that |
| 234 | } |
| 235 | } |
| 236 | #endif |
| 237 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 238 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 239 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (action); |
| 240 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (Thing_isa (action, classPraat_Command)); |
| 241 | if (action -> buttoncxx . . $ structPraat_Command#button.) { |
| 242 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"trying to destroy action ", i, U" of ", theActions.size, U", button ", Melder_pointer (action -> button), U": ", action -> title.get()); |
| 243 | #if gtkcxx . . $ `sys/Gui.h:33:10`! || cocoacxx . . $ `sys/Gui.h:35:10`! |
| 244 | if (action -> buttoncxx . . $ structPraat_Command#button. -> d_parentcxx . . $ structGuiThing#d_parent. == praat_formcxx . . $ praat_form.) { |
| 245 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroy a label or a push button or a cascade button"); |
| 246 | GuiObject_destroycxx . . $ GuiObject_destroy(5d22bdacc48458e8). (action -> buttoncxx . . $ structPraat_Command#button. -> d_widgetcxx . . $ structGuiThing#d_widget.); |
| 247 | } else if (praat_writeMenucxx . . $ praat_writeMenu. && action -> buttoncxx . . $ structPraat_Command#button. -> d_parentcxx . . $ structGuiThing#d_parent. == praat_writeMenucxx . . $ praat_writeMenu.) { |
| 248 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroying Save menu item"); |
| 249 | GuiObject_destroycxx . . $ GuiObject_destroy(5d22bdacc48458e8). (action -> buttoncxx . . $ structPraat_Command#button. -> d_widgetcxx . . $ structGuiThing#d_widget.); |
| 250 | } |
| 251 | #elif motif |
| 252 | //trace ((int) * (char *) action -> button); // try to access the memory |
| 253 | Melder_assert (action -> button -> classInfo); |
| 254 | //trace (2); |
| 255 | if (action -> button -> classInfo == classGuiButton) |
| 256 | Melder_assert (action -> button -> d_widget); |
| 257 | //trace (3); |
| 258 | if (action -> button -> classInfo == classGuiButton && action -> button -> d_widget -> subMenuId) { // a cascade button (not a direct child of the form)? |
| 259 | #define TRY_BARLESS 0 |
| 260 | #if TRY_BARLESS |
| 261 | GuiObject_destroy (action -> button -> d_widget); |
| 262 | GuiObject_destroy (action -> button -> d_widget -> subMenuId); |
| 263 | #else |
| 264 | /* |
| 265 | We check that the parent is a RowColumn with exactly two children: a cascade button and a pulldown menu |
| 266 | */ |
| 267 | GuiObject xmMenuBarRowColumn = action -> button -> d_widget -> parent; |
| 268 | Melder_assert (xmMenuBarRowColumn); |
| 269 | trace (U"destroy the xm menu bar (widget class ", xmMenuBarRowColumn -> widgetClass, U"); this also destroys the xm button and the xm menu"); |
| 270 | Melder_assert (xmMenuBarRowColumn -> widgetClass == xmRowColumnWidgetClass); |
| 271 | GuiObject xmCascadeButton = xmMenuBarRowColumn -> firstChild; |
| 272 | Melder_assert (xmCascadeButton); |
| 273 | Melder_assert (xmCascadeButton -> widgetClass == xmCascadeButtonWidgetClass); |
| 274 | Melder_assert (xmCascadeButton == action -> button -> d_widget); |
| 275 | GuiObject xmPulldownMenu = xmCascadeButton -> nextSibling; |
| 276 | Melder_assert (xmPulldownMenu); |
| 277 | Melder_assert (xmPulldownMenu -> widgetClass == xmPulldownMenuWidgetClass); |
| 278 | Melder_assert (! xmPulldownMenu -> nextSibling); |
| 279 | Melder_assert (xmCascadeButton -> subMenuId == xmPulldownMenu); |
| 280 | /* |
| 281 | Let's do some controlled destruction. |
| 282 | */ |
| 283 | //GuiObject_destroy (xmCascadeButton); Melder_assert (xmMenuBarRowColumn -> firstChild == xmPulldownMenu); |
| 284 | //GuiObject_destroy (xmPulldownMenu); Melder_assert (xmMenuBarRowColumn -> firstChild == nullptr); |
| 285 | GuiObject_destroy (xmMenuBarRowColumn); |
| 286 | //GuiObject_destroy (action -> button -> d_widget); // that would be only the cascade button |
| 287 | #endif |
| 288 | } else if (action -> button -> d_parent == praat_form) { |
| 289 | GuiObject xmLabelOrButton = action -> button -> d_widget; |
| 290 | Melder_assert (xmLabelOrButton); |
| 291 | Melder_assert (xmLabelOrButton -> widgetClass == xmLabelWidgetClass || xmLabelOrButton -> widgetClass == xmPushButtonWidgetClass); |
| 292 | trace (U"destroy a label or a push button"); |
| 293 | GuiObject_destroy (xmLabelOrButton); |
| 294 | } |
| 295 | #endif |
| 296 | action -> buttoncxx . . $ structPraat_Command#button. = nullptr; // undangle |
| 297 | } |
| 298 | } |
| 299 | if (praat_writeMenucxx . . $ praat_writeMenu.) { |
| 300 | #if gtkcxx . . $ `sys/Gui.h:33:10`! || cocoacxx . . $ `sys/Gui.h:35:10`! |
| 301 | if (praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator.) { |
| 302 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"destroy the Save menu separator"); |
| 303 | GuiObject_destroycxx . . $ GuiObject_destroy(5d22bdacc48458e8). (praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator. -> d_widgetcxx . . $ structGuiThing#d_widget.); |
| 304 | } |
| 305 | //praat_writeMenu -> f_empty (); |
| 306 | #elif motif |
| 307 | GuiObject_destroy (praat_writeMenu -> d_xmMenuTitle); |
| 308 | GuiObject_destroy (praat_writeMenu -> d_widget); |
| 309 | praat_writeMenu = GuiMenu_createInWindow (praatP.menuBar, U"Save", 0); |
| 310 | #endif |
| 311 | praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator. = nullptr; // undangle |
| 312 | } |
| 313 | actionsInvisiblecxx . . $ actionsInvisible. = true; |
| 314 | } |
| 315 | |
| 316 | static void updateDynamicMenucxx . . $ updateDynamicMenu(49f6e7a06ebc5aa8). () { |
| 317 | if (praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. != praat_HANDLING_EVENTScxx . . $ `sys/praatP.h:96:9`!) |
| 318 | return; |
| 319 | praat_sortActionscxx . . $ praat_sortActions(49f6e7a06ebc5aa8). (); |
| 320 | deleteDynamicMenucxx . . $ deleteDynamicMenu(49f6e7a06ebc5aa8). (); |
| 321 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 322 | } |
| 323 | |
| 324 | void praat_addActionScriptcxx . . $ praat_addActionScript(dcd860f3b50ce413). (conststring32cxx . . $ conststring32# className1, integercxx . . $ integer# n1, conststring32cxx . . $ conststring32# className2, integercxx . . $ integer# n2, conststring32cxx . . $ conststring32# className3, integercxx . . $ integer# n3, |
| 325 | conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# after, integercxx . . $ integer# depth, conststring32cxx . . $ conststring32# script) |
| 326 | { |
| 327 | try { |
| 328 | ClassInfocxx . . $ ClassInfo# class1 = nullptr, class2 = nullptr, class3 = nullptr; |
| 329 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (className1 && className2 && className3 && title && after && script); |
| 330 | if (className1 [0] != U'\0') |
| 331 | class1 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className1, nullptr); |
| 332 | if (className2 [0] != U'\0') |
| 333 | class2 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className2, nullptr); |
| 334 | if (className3 [0] != U'\0') |
| 335 | class3 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className3, nullptr); |
| 336 | fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (& class1, & n1, & class2, & n2, & class3, & n3); |
| 337 | |
| 338 | if (script [0] != U'\0' && title [0] == U'\0') |
| 339 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command with callback has no title. Classes: ", className1, U" ", className2, U" ", className3, U"."); |
| 340 | |
| 341 | if (className1 [0] == U'\0') |
| 342 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Command \"", title, U"\" has no first class."); |
| 343 | |
| 344 | /* |
| 345 | If the button already exists, remove it. |
| 346 | */ |
| 347 | {// scope |
| 348 | integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, nullptr, title); |
| 349 | if (found) |
| 350 | theActionscxx . . $ theActions.. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (found); |
| 351 | } |
| 352 | |
| 353 | /* |
| 354 | Determine the position of the new command. |
| 355 | */ |
| 356 | integercxx . . $ integer# position; |
| 357 | if (after [0] != U'\0') { // search for existing command with same selection |
| 358 | integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, nullptr, after); |
| 359 | if (found) |
| 360 | position = found + 1; // after 'after' |
| 361 | else |
| 362 | position = theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size. + 1; // at end |
| 363 | } else { |
| 364 | position = theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size. + 1; // at end |
| 365 | } |
| 366 | |
| 367 | /* |
| 368 | Create new command. |
| 369 | */ |
| 370 | autoPraat_Commandcxx . . $ autoPraat_Command# action = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Praat_Command); |
| 371 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class1cxx . . $ structPraat_Command#class1. = class1; |
| 372 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n1cxx . . $ structPraat_Command#n1. = n1; |
| 373 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class2cxx . . $ structPraat_Command#class2. = class2; |
| 374 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n2cxx . . $ structPraat_Command#n2. = n2; |
| 375 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). class3cxx . . $ structPraat_Command#class3. = class3; |
| 376 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). n3cxx . . $ structPraat_Command#n3. = n3; |
| 377 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). titlecxx . . $ structPraat_Command#title. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). title [0] != U'\0' ? Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (title) : autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(); // allow old-fashioned untitled separators |
| 378 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). depthcxx . . $ structPraat_Command#depth. = depth; |
| 379 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). callbackcxx . . $ structPraat_Command#callback. = ( script [0] != U'\0' ? DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c). : nullptr ); // null for a separator |
| 380 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). buttoncxx . . $ structPraat_Command#button. = nullptr; |
| 381 | if (script [0] == U'\0') { |
| 382 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). scriptcxx . . $ structPraat_Command#script. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).(); |
| 383 | } else { |
| 384 | structMelderFilecxx . . $ structMelderFile# file { }; |
| 385 | Melder_relativePathToFilecxx . . $ Melder_relativePathToFile(82691f2ee21fbb13). (script, & file); |
| 386 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). scriptcxx . . $ structPraat_Command#script. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (MelderFile_peekPathcxx . . $ MelderFile_peekPath(d9f043369fa9b55b). (& file)); |
| 387 | } |
| 388 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). aftercxx . . $ structPraat_Command#after. =cxx . . $ _autostring#`operator=`(f562943cbc4bcf37). ( after [0] != U'\0' ? Melder_dup_fcxx . . $ Melder_dup_f(87bf156b1f548402). (after) : autostring32cxx . . $ _autostring#_autostring(49f6e7a06ebc5aa8).() ); |
| 389 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). phasecxx . . $ structPraat_Command#phase. = praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase.; |
| 390 | if (praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. >= praat_READING_BUTTONScxx . . $ `sys/praatP.h:95:9`!) { |
| 391 | static integercxx . . $ integer# uniqueID = 0; |
| 392 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). uniqueIDcxx . . $ structPraat_Command#uniqueID. = ++ uniqueID; |
| 393 | } |
| 394 | action ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). addedcxx . . $ structPraat_Command#added. = true; |
| 395 | |
| 396 | /* |
| 397 | Insert new command. |
| 398 | */ |
| 399 | theActionscxx . . $ theActions.. addItemAtPosition_movecxx . . $ OrderedOf#addItemAtPosition_move(ca501a207ce7a6c1). (actioncxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f)..movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(), position); |
| 400 | updateDynamicMenucxx . . $ updateDynamicMenu(49f6e7a06ebc5aa8). (); |
| 401 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 402 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: script action not added."); |
| 403 | } |
| 404 | } |
| 405 | |
| 406 | void praat_removeActioncxx . . $ praat_removeAction(312e849c2af9bc10). (ClassInfocxx . . $ ClassInfo# class1, ClassInfocxx . . $ ClassInfo# class2, ClassInfocxx . . $ ClassInfo# class3, conststring32cxx . . $ conststring32# title) { |
| 407 | try { |
| 408 | integercxx . . $ integer# n1, n2, n3; |
| 409 | fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (& class1, & n1, & class2, & n2, & class3, & n3); |
| 410 | integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, nullptr, title); |
| 411 | if (! found) { |
| 412 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Action command \"", class1 -> className, |
| 413 | class2 ? U" & ": U"", class2 -> className, |
| 414 | class3 ? U" & ": U"", class3 -> className, |
| 415 | U": ", title, U"\" not found." |
| 416 | ); |
| 417 | } |
| 418 | theActionscxx . . $ theActions.. removeItemcxx . . $ CollectionOf#removeItem(1624ee8275b10bda). (found); |
| 419 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 420 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not removed."); |
| 421 | } |
| 422 | } |
| 423 | |
| 424 | void praat_removeAction_classNamescxx . . $ praat_removeAction_classNames(65c8e021e9cb4ed9). (conststring32cxx . . $ conststring32# className1, conststring32cxx . . $ conststring32# className2, |
| 425 | conststring32cxx . . $ conststring32# className3, conststring32cxx . . $ conststring32# title) |
| 426 | { |
| 427 | try { |
| 428 | ClassInfocxx . . $ ClassInfo# class1 = nullptr, class2 = nullptr, class3 = nullptr; |
| 429 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (className1 && className2 && className3 && title); |
| 430 | if (className1 [0] != U'\0') |
| 431 | class1 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className1, nullptr); |
| 432 | if (className2 [0] != U'\0') |
| 433 | class2 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className2, nullptr); |
| 434 | if (className3 [0] != U'\0') |
| 435 | class3 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className3, nullptr); |
| 436 | praat_removeActioncxx . . $ praat_removeAction(312e849c2af9bc10). (class1, class2, class3, title); |
| 437 | updateDynamicMenucxx . . $ updateDynamicMenu(49f6e7a06ebc5aa8). (); |
| 438 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 439 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not removed."); |
| 440 | } |
| 441 | } |
| 442 | |
| 443 | void praat_hideActioncxx . . $ praat_hideAction(312e849c2af9bc10). (ClassInfocxx . . $ ClassInfo# class1, ClassInfocxx . . $ ClassInfo# class2, ClassInfocxx . . $ ClassInfo# class3, conststring32cxx . . $ conststring32# title) { |
| 444 | try { |
| 445 | integercxx . . $ integer# n1, n2, n3; |
| 446 | fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (& class1, & n1, & class2, & n2, & class3, & n3); |
| 447 | integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, nullptr, title); |
| 448 | if (! found) { |
| 449 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action command \"", class1 ? class1 -> className : nullptr, |
| 450 | class2 ? U" & ": nullptr, class2 ? class2 -> className : nullptr, |
| 451 | class3 ? U" & ": nullptr, class3 ? class3 -> className : nullptr, |
| 452 | U": ", title, U"\" not found." |
| 453 | ); |
| 454 | } |
| 455 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).found]; |
| 456 | if (! action -> hiddencxx . . $ structPraat_Command#hidden.) { |
| 457 | action -> hiddencxx . . $ structPraat_Command#hidden. = true; |
| 458 | if (praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. >= praat_READING_BUTTONScxx . . $ `sys/praatP.h:95:9`!) |
| 459 | action -> toggledcxx . . $ structPraat_Command#toggled. = ! action -> toggledcxx . . $ structPraat_Command#toggled.; |
| 460 | updateDynamicMenucxx . . $ updateDynamicMenu(49f6e7a06ebc5aa8). (); |
| 461 | } |
| 462 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 463 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not hidden."); |
| 464 | } |
| 465 | } |
| 466 | |
| 467 | void praat_hideAction_classNamescxx . . $ praat_hideAction_classNames(65c8e021e9cb4ed9). (conststring32cxx . . $ conststring32# className1, conststring32cxx . . $ conststring32# className2, |
| 468 | conststring32cxx . . $ conststring32# className3, conststring32cxx . . $ conststring32# title) |
| 469 | { |
| 470 | try { |
| 471 | ClassInfocxx . . $ ClassInfo# class1 = nullptr, class2 = nullptr, class3 = nullptr; |
| 472 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (className1 && className2 && className3 && title); |
| 473 | if (className1 [0] != U'\0') |
| 474 | class1 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className1, nullptr); |
| 475 | if (className2 [0] != U'\0') |
| 476 | class2 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className2, nullptr); |
| 477 | if (className3 [0] != U'\0') |
| 478 | class3 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className3, nullptr); |
| 479 | praat_hideActioncxx . . $ praat_hideAction(312e849c2af9bc10). (class1, class2, class3, title); |
| 480 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 481 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not hidden."); |
| 482 | } |
| 483 | } |
| 484 | |
| 485 | void praat_showActioncxx . . $ praat_showAction(312e849c2af9bc10). (ClassInfocxx . . $ ClassInfo# class1, ClassInfocxx . . $ ClassInfo# class2, ClassInfocxx . . $ ClassInfo# class3, conststring32cxx . . $ conststring32# title) { |
| 486 | try { |
| 487 | integercxx . . $ integer# n1, n2, n3; |
| 488 | fixSelectionSpecificationcxx . . $ fixSelectionSpecification(78449c9d2f64cbfb). (& class1, & n1, & class2, & n2, & class3, & n3); |
| 489 | integercxx . . $ integer# found = lookUpMatchingActioncxx . . $ lookUpMatchingAction(c2ff18b2882baff4). (class1, class2, class3, nullptr, title); |
| 490 | if (! found) { |
| 491 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Action command \"", class1 ? class1 -> className : nullptr, |
| 492 | class2 ? U" & ": nullptr, class2 ? class2 -> className : nullptr, |
| 493 | class3 ? U" & ": nullptr, class3 ? class3 -> className : nullptr, |
| 494 | U": ", title, U"\" not found." |
| 495 | ); |
| 496 | } |
| 497 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).found]; |
| 498 | if (action -> hiddencxx . . $ structPraat_Command#hidden.) { |
| 499 | action -> hiddencxx . . $ structPraat_Command#hidden. = false; |
| 500 | if (praatPcxx . . $ praatP..phasecxx . . $ PraatP#phase. >= praat_READING_BUTTONScxx . . $ `sys/praatP.h:95:9`!) |
| 501 | action -> toggledcxx . . $ structPraat_Command#toggled. = ! action -> toggledcxx . . $ structPraat_Command#toggled.; |
| 502 | updateDynamicMenucxx . . $ updateDynamicMenu(49f6e7a06ebc5aa8). (); |
| 503 | } |
| 504 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 505 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not shown."); |
| 506 | } |
| 507 | } |
| 508 | |
| 509 | void praat_showAction_classNamescxx . . $ praat_showAction_classNames(65c8e021e9cb4ed9). (conststring32cxx . . $ conststring32# className1, conststring32cxx . . $ conststring32# className2, |
| 510 | conststring32cxx . . $ conststring32# className3, conststring32cxx . . $ conststring32# title) |
| 511 | { |
| 512 | try { |
| 513 | ClassInfocxx . . $ ClassInfo# class1 = nullptr, class2 = nullptr, class3 = nullptr; |
| 514 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (className1 && className2 && className3 && title); |
| 515 | if (className1 [0] != U'\0') |
| 516 | class1 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className1, nullptr); |
| 517 | if (className2 [0] != U'\0') |
| 518 | class2 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className2, nullptr); |
| 519 | if (className3 [0] != U'\0') |
| 520 | class3 = Thing_classFromClassNamecxx . . $ Thing_classFromClassName(8643cf72d5cb42e3). (className3, nullptr); |
| 521 | praat_showActioncxx . . $ praat_showAction(312e849c2af9bc10). (class1, class2, class3, title); |
| 522 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 523 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Praat: action not shown."); |
| 524 | } |
| 525 | } |
| 526 | |
| 527 | void praat_sortActionscxx . . $ praat_sortActions(49f6e7a06ebc5aa8). () { |
| 528 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 529 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 530 | action -> sortingTailcxx . . $ structPraat_Command#sortingTail. = i; |
| 531 | } |
| 532 | stdcxx . . $ std/::sortcxx . . $ std/sort(4d3091562df4e52e). (theActionscxx . . $ theActions..begincxx . . $ CollectionOf#begin(3871cfe815cb200).(), theActionscxx . . $ theActions..endcxx . . $ CollectionOf#end(3871cfe815cb200).(), |
| 533 | [] (Praat_Commandcxx . . $ Praat_Command# me, Praat_Commandcxx . . $ Praat_Command# thee) { |
| 534 | int compare = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1. -> classNamecxx . . $ structClassInfo#className., thycxx . . $ `melder/melder.h:45:9`! class1cxx . . $ structPraat_Command#class1. -> classNamecxx . . $ structClassInfo#className.); |
| 535 | if (compare != 0) |
| 536 | return mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1. == classDaatacxx . . $ classDaata. ? true : thycxx . . $ `melder/melder.h:45:9`! class1cxx . . $ structPraat_Command#class1. == classDaatacxx . . $ classDaata. ? false : ( compare < 0 ); |
| 537 | if (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2.) { |
| 538 | if (! thycxx . . $ `melder/melder.h:45:9`! class2cxx . . $ structPraat_Command#class2.) |
| 539 | return false; |
| 540 | compare = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. -> classNamecxx . . $ structClassInfo#className., thycxx . . $ `melder/melder.h:45:9`! class2cxx . . $ structPraat_Command#class2. -> classNamecxx . . $ structClassInfo#className.); |
| 541 | if (compare != 0) |
| 542 | return compare < 0; |
| 543 | } else if (thycxx . . $ `melder/melder.h:45:9`! class2cxx . . $ structPraat_Command#class2.) |
| 544 | return true; |
| 545 | if (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3.) { |
| 546 | if (! thycxx . . $ `melder/melder.h:45:9`! class3cxx . . $ structPraat_Command#class3.) |
| 547 | return false; |
| 548 | compare = str32cmpcxx . . $ str32cmp(937dacc22d2a7919). (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. -> classNamecxx . . $ structClassInfo#className., thycxx . . $ `melder/melder.h:45:9`! class3cxx . . $ structPraat_Command#class3. -> classNamecxx . . $ structClassInfo#className.); |
| 549 | if (compare != 0) |
| 550 | return compare < 0; |
| 551 | } else if (thycxx . . $ `melder/melder.h:45:9`! class3cxx . . $ structPraat_Command#class3.) |
| 552 | return true; |
| 553 | return mycxx . . $ `melder/melder.h:44:9`! sortingTailcxx . . $ structPraat_Command#sortingTail. < thycxx . . $ `melder/melder.h:45:9`! sortingTailcxx . . $ structPraat_Command#sortingTail.; |
| 554 | } |
| 555 | ); |
| 556 | } |
| 557 | |
| 558 | static conststring32cxx . . $ conststring32# numberStringcxx . . $ numberString(7b348ebc2004441d). (integercxx . . $ integer# number) { |
| 559 | return number == 1 ? U"one" : number == 2 ? U"two" : number == 3 ? U"three" : U"any number of"; |
| 560 | } |
| 561 | static conststring32cxx . . $ conststring32# classStringcxx . . $ classString(ceef492c470d0b3). (ClassInfocxx . . $ ClassInfo# klas) { |
| 562 | return klas == classDaatacxx . . $ classDaata. ? U"" : klas -> classNamecxx . . $ structClassInfo#className.; |
| 563 | } |
| 564 | static conststring32cxx . . $ conststring32# objectStringcxx . . $ objectString(7b348ebc2004441d). (integercxx . . $ integer# number) { |
| 565 | return number == 1 ? U"object" : U"objects"; |
| 566 | } |
| 567 | static bool allowExecutionHookcxx . . $ allowExecutionHook(db00c6a08f501612). (void *closure) { |
| 568 | UiCallbackcxx . . $ UiCallback# callback = (UiCallbackcxx . . $ UiCallback#) closure; |
| 569 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (sizeof (callback) == sizeof (void *)); |
| 570 | integercxx . . $ integer# numberOfMatchingCallbacks = 0, firstMatchingCallback = 0; |
| 571 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 572 | Praat_Commandcxx . . $ Praat_Command# me = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 573 | if (mycxx . . $ `melder/melder.h:44:9`! callbackcxx . . $ structPraat_Command#callback. == callback) { |
| 574 | integercxx . . $ integer# sel1, sel2 = 0, sel3 = 0, sel4 = 0; |
| 575 | if (! mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1.) |
| 576 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"No class1???"); |
| 577 | numberOfMatchingCallbacks += 1; |
| 578 | if (firstMatchingCallback == 0) |
| 579 | firstMatchingCallback = i; |
| 580 | sel1 = ( mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1. == classDaatacxx . . $ classDaata. ? theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. : praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1.) ); |
| 581 | if (sel1 == 0) |
| 582 | continue; |
| 583 | if (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. && (sel2 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2.)) == 0) |
| 584 | continue; |
| 585 | if (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. && (sel3 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3.)) == 0) |
| 586 | continue; |
| 587 | if (mycxx . . $ `melder/melder.h:44:9`! class4cxx . . $ structPraat_Command#class4. && (sel4 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (mycxx . . $ `melder/melder.h:44:9`! class4cxx . . $ structPraat_Command#class4.)) == 0) |
| 588 | continue; |
| 589 | if (sel1 + sel2 + sel3 + sel4 != theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection.) |
| 590 | continue; |
| 591 | if ((mycxx . . $ `melder/melder.h:44:9`! n1cxx . . $ structPraat_Command#n1. && sel1 != mycxx . . $ `melder/melder.h:44:9`! n1cxx . . $ structPraat_Command#n1.) || (mycxx . . $ `melder/melder.h:44:9`! n2cxx . . $ structPraat_Command#n2. && sel2 != mycxx . . $ `melder/melder.h:44:9`! n2cxx . . $ structPraat_Command#n2.) || (mycxx . . $ `melder/melder.h:44:9`! n3cxx . . $ structPraat_Command#n3. && sel3 != mycxx . . $ `melder/melder.h:44:9`! n3cxx . . $ structPraat_Command#n3.) || (mycxx . . $ `melder/melder.h:44:9`! n4cxx . . $ structPraat_Command#n4. && sel4 != mycxx . . $ `melder/melder.h:44:9`! n4cxx . . $ structPraat_Command#n4.)) |
| 592 | continue; |
| 593 | return true; // found a matching action |
| 594 | } |
| 595 | } |
| 596 | if (numberOfMatchingCallbacks == 1) { |
| 597 | Praat_Commandcxx . . $ Praat_Command# me = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).firstMatchingCallback]; |
| 598 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U"Selection changed! It should be:"); |
| 599 | if (mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1.) |
| 600 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U" ", numberStringcxx . . $ numberString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n1cxx . . $ structPraat_Command#n1.), U" ", classStringcxx . . $ classString(ceef492c470d0b3). (mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1.), U" ", objectStringcxx . . $ objectString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n1cxx . . $ structPraat_Command#n1.)); |
| 601 | if (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2.) |
| 602 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U" ", numberStringcxx . . $ numberString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n2cxx . . $ structPraat_Command#n2.), U" ", classStringcxx . . $ classString(ceef492c470d0b3). (mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2.), U" ", objectStringcxx . . $ objectString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n2cxx . . $ structPraat_Command#n2.)); |
| 603 | if (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3.) |
| 604 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U" ", numberStringcxx . . $ numberString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n3cxx . . $ structPraat_Command#n3.), U" ", classStringcxx . . $ classString(ceef492c470d0b3). (mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3.), U" ", objectStringcxx . . $ objectString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n3cxx . . $ structPraat_Command#n3.)); |
| 605 | if (mycxx . . $ `melder/melder.h:44:9`! class4cxx . . $ structPraat_Command#class4.) |
| 606 | Melder_appendErrorcxx . . $ Melder_appendError(6298c93241566110). (U" ", numberStringcxx . . $ numberString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n4cxx . . $ structPraat_Command#n4.), U" ", classStringcxx . . $ classString(ceef492c470d0b3). (mycxx . . $ `melder/melder.h:44:9`! class4cxx . . $ structPraat_Command#class4.), U" ", objectStringcxx . . $ objectString(7b348ebc2004441d). (mycxx . . $ `melder/melder.h:44:9`! n4cxx . . $ structPraat_Command#n4.)); |
| 607 | throw MelderErrorcxx . . $ MelderError# (); |
| 608 | } else { |
| 609 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Selection changed!"); |
| 610 | } |
| 611 | return false; |
| 612 | } |
| 613 | |
| 614 | static void do_menucxx . . $ do_menu(6ee09e51a76297e7). (Praat_Commandcxx . . $ Praat_Command# me, const bool isModified) { |
| 615 | if (mycxx . . $ `melder/melder.h:44:9`! callbackcxx . . $ structPraat_Command#callback. == DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c).) { |
| 616 | UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\nrunScript: "); |
| 617 | try { |
| 618 | DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c). (nullptr, 0, nullptr, mycxx . . $ `melder/melder.h:44:9`! scriptcxx . . $ structPraat_Command#script..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), nullptr, nullptr, false, nullptr, nullptr); |
| 619 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 620 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Command \"", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\" not executed."); |
| 621 | } |
| 622 | praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). (); return; |
| 623 | } else { |
| 624 | if (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title. && ! str32strcxx . . $ str32str(2de17cd8f7c584a6). (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"...")) { |
| 625 | UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (U"\n"); |
| 626 | UiHistory_writecxx . . $ UiHistory_write(ff00d524ab0355ec). (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 627 | } |
| 628 | Ui_setAllowExecutionHookcxx . . $ Ui_setAllowExecutionHook(1e9af8188bc9e75f). (allowExecutionHookcxx . . $ allowExecutionHook(db00c6a08f501612)., (void *) mycxx . . $ `melder/melder.h:44:9`! callbackcxx . . $ structPraat_Command#callback.); // BUG: one shouldn't assign a function pointer to a void pointer |
| 629 | try { |
| 630 | mycxx . . $ `melder/melder.h:44:9`! callbackcxx . . $ structPraat_Command#callback. (nullptr, 0, nullptr, nullptr, nullptr, mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), isModified, nullptr, nullptr); |
| 631 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 632 | Melder_flushErrorcxx . . $ Melder_flushError(6298c93241566110). (U"Command \"", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\" not executed."); |
| 633 | } |
| 634 | Ui_setAllowExecutionHookcxx . . $ Ui_setAllowExecutionHook(1e9af8188bc9e75f). (nullptr, nullptr); |
| 635 | praat_updateSelectioncxx . . $ praat_updateSelection(49f6e7a06ebc5aa8). (); return; |
| 636 | } |
| 637 | } |
| 638 | |
| 639 | static void cb_menucxx . . $ cb_menu(6d044108b20850e2). (Praat_Commandcxx . . $ Praat_Command# me, GuiMenuItemEventcxx . . $ GuiMenuItemEvent# event) { |
| 640 | const bool isModified = event -> shiftKeyPressedcxx . . $ structGuiMenuItemEvent#shiftKeyPressed. || event -> commandKeyPressedcxx . . $ structGuiMenuItemEvent#commandKeyPressed. || event -> optionKeyPressedcxx . . $ structGuiMenuItemEvent#optionKeyPressed.; |
| 641 | do_menucxx . . $ do_menu(6ee09e51a76297e7). (me, isModified); |
| 642 | } |
| 643 | |
| 644 | static void gui_button_cb_menucxx . . $ gui_button_cb_menu(914af3e9f2ef2bd2). (Praat_Commandcxx . . $ Praat_Command# me, GuiButtonEventcxx . . $ GuiButtonEvent# event) { |
| 645 | const bool isModified = event -> shiftKeyPressedcxx . . $ structGuiButtonEvent#shiftKeyPressed. || event -> commandKeyPressedcxx . . $ structGuiButtonEvent#commandKeyPressed. || event -> optionKeyPressedcxx . . $ structGuiButtonEvent#optionKeyPressed.; |
| 646 | do_menucxx . . $ do_menu(6ee09e51a76297e7). (me, isModified); |
| 647 | } |
| 648 | |
| 649 | void praat_actions_showcxx . . $ praat_actions_show(49f6e7a06ebc5aa8). () { |
| 650 | #if defined (macintosh) |
| 651 | const int BUTTON_VSPACING = 8; |
| 652 | #else |
| 653 | const int BUTTON_VSPACING = 5; |
| 654 | #endif |
| 655 | /* |
| 656 | The selection has changed; |
| 657 | kill the dynamic menu and the write menu. |
| 658 | */ |
| 659 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) { |
| 660 | deleteDynamicMenucxx . . $ deleteDynamicMenu(49f6e7a06ebc5aa8). (); |
| 661 | if (! Melder_backgroundingcxx . . $ Melder_backgrounding.) { |
| 662 | GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (praat_writeMenucxx . . $ praat_writeMenu., false); |
| 663 | if (praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator.) |
| 664 | GuiThing_hidecxx . . $ GuiThing_hide(20e88c25f0ba841). (praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator.); |
| 665 | } |
| 666 | |
| 667 | /* |
| 668 | Determine the visibility and sensitivity of all the actions. |
| 669 | */ |
| 670 | if (theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. != 0 && ! Melder_backgroundingcxx . . $ Melder_backgrounding.) |
| 671 | GuiThing_setSensitivecxx . . $ GuiThing_setSensitive(99178548e0926398). (praat_writeMenucxx . . $ praat_writeMenu., true); |
| 672 | } |
| 673 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 674 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 675 | integercxx . . $ integer# sel1 = 0, sel2 = 0, sel3 = 0, sel4 = 0; |
| 676 | const integercxx . . $ integer# n1 = action -> n1cxx . . $ structPraat_Command#n1., n2 = action -> n2cxx . . $ structPraat_Command#n2., n3 = action -> n3cxx . . $ structPraat_Command#n3., n4 = action -> n4cxx . . $ structPraat_Command#n4.; |
| 677 | |
| 678 | /* |
| 679 | Clean up from previous selection. |
| 680 | */ |
| 681 | action -> visiblecxx . . $ structPraat_Command#visible. = false; |
| 682 | action -> executablecxx . . $ structPraat_Command#executable. = false; |
| 683 | |
| 684 | /* |
| 685 | Match the actually selected classes with the selection required for this visibility. |
| 686 | */ |
| 687 | if (! action -> class1cxx . . $ structPraat_Command#class1.) |
| 688 | continue; // at least one class selected |
| 689 | sel1 = ( action -> class1cxx . . $ structPraat_Command#class1. == classDaatacxx . . $ classDaata. ? theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection. : praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (action -> class1cxx . . $ structPraat_Command#class1.) ); |
| 690 | if (sel1 == 0) |
| 691 | continue; |
| 692 | if (action -> class2cxx . . $ structPraat_Command#class2. && (sel2 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (action -> class2cxx . . $ structPraat_Command#class2.)) == 0) |
| 693 | continue; |
| 694 | if (action -> class3cxx . . $ structPraat_Command#class3. && (sel3 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (action -> class3cxx . . $ structPraat_Command#class3.)) == 0) |
| 695 | continue; |
| 696 | if (action -> class4cxx . . $ structPraat_Command#class4. && (sel4 = praat_numberOfSelectedcxx . . $ praat_numberOfSelected(33e8b4a553c0cc95). (action -> class4cxx . . $ structPraat_Command#class4.)) == 0) |
| 697 | continue; |
| 698 | if (sel1 + sel2 + sel3 + sel4 != theCurrentPraatObjectscxx . . $ theCurrentPraatObjects. -> totalSelectioncxx . . $ structPraatObjects#totalSelection.) |
| 699 | continue; // other classes selected? Do not show |
| 700 | action -> visiblecxx . . $ structPraat_Command#visible. = ! action -> hiddencxx . . $ structPraat_Command#hidden.; |
| 701 | |
| 702 | /* |
| 703 | Match the actually selected objects with the selection required for this action. |
| 704 | */ |
| 705 | if (! action -> callbackcxx . . $ structPraat_Command#callback.) |
| 706 | continue; // separators are not executable |
| 707 | if ((n1 && sel1 != n1) || (n2 && sel2 != n2) || (n3 && sel3 != n3) || (n4 && sel4 != n4)) |
| 708 | continue; |
| 709 | action -> executablecxx . . $ structPraat_Command#executable. = true; |
| 710 | } |
| 711 | |
| 712 | /* |
| 713 | Create a new column of buttons in the dynamic menu. |
| 714 | */ |
| 715 | if (! theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch. && ! Melder_backgroundingcxx . . $ Melder_backgrounding.) { |
| 716 | actionsInvisiblecxx . . $ actionsInvisible. = false; |
| 717 | GuiMenucxx . . $ GuiMenu# currentSubmenu1 = nullptr, currentSubmenu2 = nullptr; |
| 718 | bool writeMenuGoingToSeparate = false; |
| 719 | int y = Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). () + 10; |
| 720 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { // add buttons or make existing buttons sensitive (executable) |
| 721 | Praat_Commandcxx . . $ Praat_Command# me = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 722 | if (mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth. == 0) { |
| 723 | currentSubmenu1 = nullptr; |
| 724 | currentSubmenu2 = nullptr; // prevent attachment of later deep actions to earlier submenus after removal of label |
| 725 | } |
| 726 | if (mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth. == 1) |
| 727 | currentSubmenu2 = nullptr; // prevent attachment of later deep actions to earlier submenus after removal of label |
| 728 | if (! mycxx . . $ `melder/melder.h:44:9`! visiblecxx . . $ structPraat_Command#visible.) |
| 729 | continue; |
| 730 | if (mycxx . . $ `melder/melder.h:44:9`! callbackcxx . . $ structPraat_Command#callback.) { |
| 731 | /* |
| 732 | Apparently a true command: create a button in the dynamic menu. |
| 733 | If it is a subcommand (depth > 0), put it in the current submenu, |
| 734 | but only if this exists (umbrella against stray submenu specifications). |
| 735 | */ |
| 736 | GuiMenucxx . . $ GuiMenu# parentMenu = ( mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth. > 1 && currentSubmenu2 ? currentSubmenu2 : mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth. > 0 && currentSubmenu1 ? currentSubmenu1 : nullptr ); |
| 737 | |
| 738 | if (str32nequcxx . . $ `melder/melder_str32.h:123:9`! (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"Save ", 5) || str32nequcxx . . $ `melder/melder_str32.h:123:9`! (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"Write ", 6) || str32nequcxx . . $ `melder/melder_str32.h:123:9`! (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"Append to ", 10)) { |
| 739 | parentMenu = praat_writeMenucxx . . $ praat_writeMenu.; |
| 740 | if (! praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator.) { |
| 741 | if (writeMenuGoingToSeparate) |
| 742 | praat_writeMenuSeparatorcxx . . $ praat_writeMenuSeparator. = GuiMenu_addSeparatorcxx . . $ GuiMenu_addSeparator(d5bd5aafbfbb56aa). (parentMenu); |
| 743 | else if (str32equcxx . . $ `melder/melder_str32.h:122:9`! (mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"Save as binary file...")) |
| 744 | writeMenuGoingToSeparate = true; |
| 745 | } |
| 746 | } |
| 747 | if (parentMenu) { |
| 748 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = GuiMenu_addItemcxx . . $ GuiMenu_addItem(c4b605a971e4b555). (parentMenu, mycxx . . $ `melder/melder.h:44:9`! addedcxx . . $ structPraat_Command#added. ? Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"\u207A", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), |
| 749 | ( mycxx . . $ `melder/melder.h:44:9`! executablecxx . . $ structPraat_Command#executable. ? 0 : GuiMenu_INSENSITIVEcxx . . $ `sys/Gui.h:852:9`! ), |
| 750 | cb_menucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., me |
| 751 | ); |
| 752 | } else { |
| 753 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (praat_formcxx . . $ praat_form., |
| 754 | BUTTON_LEFTcxx . . $ `sys/praat_actions.cpp:25:9`!, BUTTON_RIGHTcxx . . $ `sys/praat_actions.cpp:26:9`!, y, y + Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, |
| 755 | mycxx . . $ `melder/melder.h:44:9`! addedcxx . . $ structPraat_Command#added. ? Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"\u207A", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), gui_button_cb_menucxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., |
| 756 | me, ( mycxx . . $ `melder/melder.h:44:9`! executablecxx . . $ structPraat_Command#executable. ? 0 : GuiButton_INSENSITIVEcxx . . $ `sys/Gui.h:469:9`! ) | ( mycxx . . $ `melder/melder.h:44:9`! attractivecxx . . $ structPraat_Command#attractive. ? GuiButton_ATTRACTIVEcxx . . $ `sys/Gui.h:470:9`! : 0 ) |
| 757 | ); |
| 758 | y += Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`! + BUTTON_VSPACING; |
| 759 | } |
| 760 | } else if (i == theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size. || theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i + 1] -> depthcxx . . $ structPraat_Command#depth. == 0) { |
| 761 | /* |
| 762 | Apparently a labelled separator. |
| 763 | */ |
| 764 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (praat_formcxx . . $ praat_form., BUTTON_LEFTcxx . . $ `sys/praat_actions.cpp:25:9`!, BUTTON_RIGHTcxx . . $ `sys/praat_actions.cpp:26:9`!, y, y + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, mycxx . . $ `melder/melder.h:44:9`! addedcxx . . $ structPraat_Command#added. ? Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"\u207A", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0); |
| 765 | y += Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`! + BUTTON_VSPACING; |
| 766 | } else if (! mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title. || mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title. [cxx . . $ _autostring#`operator[]`(b190d49faf30c5be).0] == U'-') { |
| 767 | /* |
| 768 | Apparently a separator in a submenu. |
| 769 | */ |
| 770 | if (currentSubmenu2 || currentSubmenu1) { // these separators are not shown in a flattened menu |
| 771 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = GuiMenu_addSeparatorcxx . . $ GuiMenu_addSeparator(d5bd5aafbfbb56aa). (currentSubmenu2 ? currentSubmenu2 : currentSubmenu1); |
| 772 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button.); |
| 773 | } |
| 774 | } else { |
| 775 | /* |
| 776 | Apparently a submenu. |
| 777 | */ |
| 778 | if (mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth. == 0 || ! currentSubmenu1) { |
| 779 | currentSubmenu1 = GuiMenu_createInFormcxx . . $ GuiMenu_createInForm(8f41118461509362). (praat_formcxx . . $ praat_form., |
| 780 | BUTTON_LEFTcxx . . $ `sys/praat_actions.cpp:25:9`!, BUTTON_RIGHTcxx . . $ `sys/praat_actions.cpp:26:9`!, y, y + Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, |
| 781 | mycxx . . $ `melder/melder.h:44:9`! addedcxx . . $ structPraat_Command#added. ? Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"\u207A", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0 |
| 782 | ); |
| 783 | y += Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`! + BUTTON_VSPACING; |
| 784 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = currentSubmenu1 -> d_cascadeButtoncxx . . $ structGuiMenu#d_cascadeButton..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); |
| 785 | } else { |
| 786 | currentSubmenu2 = GuiMenu_createInMenucxx . . $ GuiMenu_createInMenu(d27ae244131fab25). (currentSubmenu1, mycxx . . $ `melder/melder.h:44:9`! addedcxx . . $ structPraat_Command#added. ? Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (U"\u207A", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).()) : mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), 0); |
| 787 | mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button. = currentSubmenu2 -> d_menuItemcxx . . $ structGuiMenu#d_menuItem..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(); |
| 788 | } |
| 789 | GuiThing_showcxx . . $ GuiThing_show(20e88c25f0ba841). (mycxx . . $ `melder/melder.h:44:9`! buttoncxx . . $ structPraat_Command#button.); |
| 790 | } |
| 791 | } |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | void praat_actions_createWriteMenucxx . . $ praat_actions_createWriteMenu(20efc9fbfef198b1). (GuiWindowcxx . . $ GuiWindow# window) { |
| 796 | if (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) |
| 797 | return; |
| 798 | praat_writeMenucxx . . $ praat_writeMenu. = GuiMenu_createInWindowcxx . . $ GuiMenu_createInWindow(cfd6777f6dee287d). (window, U"Save", GuiMenu_INSENSITIVEcxx . . $ `sys/Gui.h:852:9`!); |
| 799 | #if gtkcxx . . $ `sys/Gui.h:33:10`! |
| 800 | GuiMenu_addSeparatorcxx . . $ GuiMenu_addSeparator(d5bd5aafbfbb56aa). (praat_writeMenucxx . . $ praat_writeMenu.); |
| 801 | #endif |
| 802 | } |
| 803 | |
| 804 | void praat_actions_createDynamicMenucxx . . $ praat_actions_createDynamicMenu(20efc9fbfef198b1). (GuiWindowcxx . . $ GuiWindow# window) { |
| 805 | if (theCurrentPraatApplicationcxx . . $ theCurrentPraatApplication. -> batchcxx . . $ structPraatApplication#batch.) |
| 806 | return; |
| 807 | praat_formcxx . . $ praat_form. = window; |
| 808 | } |
| 809 | |
| 810 | void praat_saveAddedActionscxx . . $ praat_saveAddedActions(93db1090f27e5462). (MelderStringcxx . . $ MelderString# *buffer) { |
| 811 | integercxx . . $ integer# maxID = 0; |
| 812 | for (integercxx . . $ integer# iaction = 1; iaction <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; iaction ++) { |
| 813 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iaction]; |
| 814 | if (action -> uniqueIDcxx . . $ structPraat_Command#uniqueID. > maxID) |
| 815 | maxID = action -> uniqueIDcxx . . $ structPraat_Command#uniqueID.; |
| 816 | } |
| 817 | for (integercxx . . $ integer# ident = 1; ident <= maxID; ident ++) |
| 818 | for (integercxx . . $ integer# iaction = 1; iaction <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; iaction ++) { |
| 819 | Praat_Commandcxx . . $ Praat_Command# me = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iaction]; |
| 820 | if (mycxx . . $ `melder/melder.h:44:9`! uniqueIDcxx . . $ structPraat_Command#uniqueID. == ident && ! mycxx . . $ `melder/melder.h:44:9`! hiddencxx . . $ structPraat_Command#hidden. && mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title.) { |
| 821 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, U"Add action command...", |
| 822 | U" ", mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1. -> classNamecxx . . $ structClassInfo#className., U" ", mycxx . . $ `melder/melder.h:44:9`! n1cxx . . $ structPraat_Command#n1., |
| 823 | U" ", ( mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. ? mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. -> classNamecxx . . $ structClassInfo#className. : U"\"\"" ), U" ", mycxx . . $ `melder/melder.h:44:9`! n2cxx . . $ structPraat_Command#n2., |
| 824 | U" ", ( mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. ? mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. -> classNamecxx . . $ structClassInfo#className. : U"\"\"" ), U" ", mycxx . . $ `melder/melder.h:44:9`! n3cxx . . $ structPraat_Command#n3., |
| 825 | U" \"", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\" \"", ( mycxx . . $ `melder/melder.h:44:9`! aftercxx . . $ structPraat_Command#after. ? mycxx . . $ `melder/melder.h:44:9`! aftercxx . . $ structPraat_Command#after..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() : U"" ), U"\" ", mycxx . . $ `melder/melder.h:44:9`! depthcxx . . $ structPraat_Command#depth.); |
| 826 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, U" ", mycxx . . $ `melder/melder.h:44:9`! scriptcxx . . $ structPraat_Command#script. ? mycxx . . $ `melder/melder.h:44:9`! scriptcxx . . $ structPraat_Command#script..getcxx . . $ _autostring#get(5a2a78a048fb49a8).() : U"", U"\n"); |
| 827 | break; |
| 828 | } |
| 829 | } |
| 830 | } |
| 831 | |
| 832 | void praat_saveToggledActionscxx . . $ praat_saveToggledActions(93db1090f27e5462). (MelderStringcxx . . $ MelderString# *buffer) { |
| 833 | for (integercxx . . $ integer# iaction = 1; iaction <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; iaction ++) { |
| 834 | Praat_Commandcxx . . $ Praat_Command# me = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).iaction]; |
| 835 | if (mycxx . . $ `melder/melder.h:44:9`! toggledcxx . . $ structPraat_Command#toggled. && mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title. && ! mycxx . . $ `melder/melder.h:44:9`! uniqueIDcxx . . $ structPraat_Command#uniqueID. && ! mycxx . . $ `melder/melder.h:44:9`! scriptcxx . . $ structPraat_Command#script.) { |
| 836 | MelderString_appendcxx . . $ MelderString_append(65be51a793e0ff96). (buffer, ( mycxx . . $ `melder/melder.h:44:9`! hiddencxx . . $ structPraat_Command#hidden. ? U"Hide" : U"Show" ), U" action command...", |
| 837 | U" ", mycxx . . $ `melder/melder.h:44:9`! class1cxx . . $ structPraat_Command#class1. -> classNamecxx . . $ structClassInfo#className., |
| 838 | U" ", ( mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. ? mycxx . . $ `melder/melder.h:44:9`! class2cxx . . $ structPraat_Command#class2. -> classNamecxx . . $ structClassInfo#className. : U"\"\"" ), |
| 839 | U" ", ( mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. ? mycxx . . $ `melder/melder.h:44:9`! class3cxx . . $ structPraat_Command#class3. -> classNamecxx . . $ structClassInfo#className. : U"\"\"" ), |
| 840 | U" ", mycxx . . $ `melder/melder.h:44:9`! titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\n" |
| 841 | ); |
| 842 | } |
| 843 | } |
| 844 | } |
| 845 | |
| 846 | int praat_doActioncxx . . $ praat_doAction(3dcbaa6862792959). (conststring32cxx . . $ conststring32# title, conststring32cxx . . $ conststring32# arguments, Interpretercxx . . $ Interpreter# interpreter) { |
| 847 | Praat_Commandcxx . . $ Praat_Command# actionFound = nullptr; |
| 848 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 849 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 850 | if (action -> executablecxx . . $ structPraat_Command#executable. && str32equcxx . . $ `melder/melder_str32.h:122:9`! (action -> titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), title)) { |
| 851 | actionFound = action; |
| 852 | break; |
| 853 | } |
| 854 | } |
| 855 | if (! actionFound) |
| 856 | return 0; |
| 857 | if (actionFound -> callbackcxx . . $ structPraat_Command#callback. == DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c).) { |
| 858 | const conststring32cxx . . $ conststring32# scriptPath = actionFound -> scriptcxx . . $ structPraat_Command#script..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 859 | const conststring32cxx . . $ conststring32# preferencesFolderPath = MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (Melder_preferencesFoldercxx . . $ Melder_preferencesFolder(3f0bf42ba8f9aa29).()); |
| 860 | const bool scriptIsInPlugin = Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (scriptPath, preferencesFolderPath); |
| 861 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! ( |
| 862 | U"From a script you cannot directly call a menu command that calls another script. Use instead: \nrunScript: ", |
| 863 | scriptIsInPlugin ? U"preferencesDirectory$ + " : U"", |
| 864 | U"\"", |
| 865 | scriptIsInPlugin ? scriptPath + Melder_length (preferencesFolderPath) : scriptPath, |
| 866 | U"\"", |
| 867 | arguments && arguments [0] ? U", " : U"", |
| 868 | arguments && arguments [0] ? arguments : U"", |
| 869 | U"\n" |
| 870 | ); |
| 871 | } |
| 872 | actionFound -> callbackcxx . . $ structPraat_Command#callback. (nullptr, 0, nullptr, arguments, interpreter, title, false, nullptr, nullptr); |
| 873 | return 1; |
| 874 | } |
| 875 | |
| 876 | int praat_doActioncxx . . $ praat_doAction(738317ad6fa3f573). (conststring32cxx . . $ conststring32# title, integercxx . . $ integer# narg, Stackelcxx . . $ Stackel# args, Interpretercxx . . $ Interpreter# interpreter) { |
| 877 | Praat_Commandcxx . . $ Praat_Command# actionFound = nullptr; |
| 878 | for (integercxx . . $ integer# i = 1; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 879 | Praat_Commandcxx . . $ Praat_Command# action = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 880 | if (action -> executablecxx . . $ structPraat_Command#executable. && str32equcxx . . $ `melder/melder_str32.h:122:9`! (action -> titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), title)) { |
| 881 | actionFound = action; |
| 882 | break; |
| 883 | } |
| 884 | } |
| 885 | if (! actionFound) |
| 886 | return 0; |
| 887 | if (actionFound -> callbackcxx . . $ structPraat_Command#callback. == DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c).) { |
| 888 | const conststring32cxx . . $ conststring32# scriptPath = actionFound -> scriptcxx . . $ structPraat_Command#script..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(); |
| 889 | const conststring32cxx . . $ conststring32# preferencesFolderPath = MelderFolder_peekPathcxx . . $ MelderFolder_peekPath(fbe3b4f4d15c56ee). (Melder_preferencesFoldercxx . . $ Melder_preferencesFolder(3f0bf42ba8f9aa29).()); |
| 890 | const bool scriptIsInPlugin = Melder_startsWithcxx . . $ Melder_startsWith(1652f10ed0f82783). (scriptPath, preferencesFolderPath); |
| 891 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! ( |
| 892 | U"From a script you cannot directly call a menu command that calls another script. Use instead: \nrunScript: ", |
| 893 | scriptIsInPlugin ? U"preferencesDirectory$ + " : U"", |
| 894 | U"\"", |
| 895 | scriptIsInPlugin ? scriptPath + Melder_length (preferencesFolderPath) : scriptPath, |
| 896 | U"\"", |
| 897 | narg > 0 ? U", ..." : U"", |
| 898 | U"\n" |
| 899 | ); |
| 900 | } |
| 901 | actionFound -> callbackcxx . . $ structPraat_Command#callback. (nullptr, narg, args, nullptr, interpreter, title, false, nullptr, nullptr); |
| 902 | return 1; |
| 903 | } |
| 904 | |
| 905 | integercxx . . $ integer# praat_getNumberOfActionscxx . . $ praat_getNumberOfActions(da6335ded91d79c2). () { return theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; } |
| 906 | |
| 907 | Praat_Commandcxx . . $ Praat_Command# praat_getActioncxx . . $ praat_getAction(ee05ff1469c8f4e9). (integercxx . . $ integer# i) |
| 908 | { return i < 0 || i > theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size. ? nullptr : theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; } |
| 909 | |
| 910 | void praat_backgroundcxx . . $ praat_background(49f6e7a06ebc5aa8). () { |
| 911 | if (Melder_batchcxx . . $ Melder_batch.) |
| 912 | return; |
| 913 | if (Melder_backgroundingcxx . . $ Melder_backgrounding.) |
| 914 | return; |
| 915 | deleteDynamicMenucxx . . $ deleteDynamicMenu(49f6e7a06ebc5aa8). (); |
| 916 | praat_list_backgroundcxx . . $ praat_list_background(49f6e7a06ebc5aa8). (); |
| 917 | Melder_backgroundingcxx . . $ Melder_backgrounding. = true; |
| 918 | } |
| 919 | |
| 920 | void praat_foregroundcxx . . $ praat_foreground(49f6e7a06ebc5aa8). () { |
| 921 | if (Melder_batchcxx . . $ Melder_batch.) |
| 922 | return; |
| 923 | if (! Melder_backgroundingcxx . . $ Melder_backgrounding.) |
| 924 | return; |
| 925 | Melder_backgroundingcxx . . $ Melder_backgrounding. = false; |
| 926 | praat_list_foregroundcxx . . $ praat_list_foreground(49f6e7a06ebc5aa8). (); |
| 927 | praat_showcxx . . $ praat_show(49f6e7a06ebc5aa8). (); |
| 928 | } |
| 929 | |
| 930 | static bool actionIsToBeIncludedcxx . . $ actionIsToBeIncluded(f2de3e1a1acc5bcb). (Praat_Commandcxx . . $ Praat_Command# command, bool deprecated, bool includeSaveAPI, |
| 931 | bool includeQueryAPI, bool includeModifyAPI, bool includeToAPI, |
| 932 | bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI) |
| 933 | { |
| 934 | const bool obsolete = ( deprecated && (command -> deprecationYearcxx . . $ structPraat_Command#deprecationYear. < Melder_appYearcxx . . $ Melder_appYear(da6335ded91d79c2).() - 10 || command -> deprecationYearcxx . . $ structPraat_Command#deprecationYear. < 2017) ); |
| 935 | const bool hiddenByDefault = ( command -> hiddencxx . . $ structPraat_Command#hidden. != command -> toggledcxx . . $ structPraat_Command#toggled. ); |
| 936 | const bool explicitlyHidden = hiddenByDefault && ! deprecated; |
| 937 | const bool hidden = explicitlyHidden || ! command -> callbackcxx . . $ structPraat_Command#callback. || command -> noApicxx . . $ structPraat_Command#noApi. || obsolete || |
| 938 | (! includeWindowAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"WINDOW_", 7)) || |
| 939 | (! includeHelpAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"HELP_", 5)) || |
| 940 | (! includeDrawAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"GRAPHICS_", 9)) || |
| 941 | (! includePlayAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"PLAY_", 5)) || |
| 942 | (! includeToAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"CONVERT_", 8)) || |
| 943 | (! includeModifyAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"MODIFY_", 7)) || |
| 944 | (! includeQueryAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"QUERY_", 6)) || |
| 945 | (! includeSaveAPI && Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"SAVE_", 5)); |
| 946 | return (command -> forceApicxx . . $ structPraat_Command#forceApi. || ! hidden) && command -> callbackcxx . . $ structPraat_Command#callback. != DO_RunTheScriptFromAnyAddedMenuCommandcxx . . $ DO_RunTheScriptFromAnyAddedMenuCommand(744a0abd3c8513c).; |
| 947 | } |
| 948 | |
| 949 | static bool actionHasFileNameArgumentcxx . . $ actionHasFileNameArgument(7a3a722a7704ae08). (Praat_Commandcxx . . $ Praat_Command# command) { |
| 950 | const bool hasFileNameArgument = |
| 951 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"READ_ONE__", 10) || |
| 952 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"SAVE_", 5) |
| 953 | ; |
| 954 | return hasFileNameArgument; |
| 955 | } |
| 956 | |
| 957 | static conststring32cxx . . $ conststring32# getReturnTypecxx . . $ getReturnType(152f281cc90b9344). (Praat_Commandcxx . . $ Praat_Command# command) { |
| 958 | const conststring32cxx . . $ conststring32# returnType = |
| 959 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"NEW1_", 5) ? U"PraatObject" : |
| 960 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"READ_ONE__", 10) ? U"PraatObject" : |
| 961 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"REAL_", 5) ? U"double" : |
| 962 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"INTEGER_", 8) ? U"int64_t" : |
| 963 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"STRING_", 7) ? U"char *" : |
| 964 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"REPORT_", 7) ? U"char *" : |
| 965 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"LIST_", 5) ? U"char *" : |
| 966 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"INFO_", 5) ? U"char *" : |
| 967 | Melder_nequcxx . . $ `melder/melder_str32.h:131:9`! (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U"HINT_", 5) ? U"char *" : |
| 968 | U"void"; |
| 969 | return returnType; |
| 970 | } |
| 971 | |
| 972 | void praat_actions_writeCcxx . . $ praat_actions_writeC(91b19ce1d42a4b6). (bool isInHeaderFile, bool includeSaveAPI, |
| 973 | bool includeQueryAPI, bool includeModifyAPI, bool includeToAPI, |
| 974 | bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI) |
| 975 | { |
| 976 | integercxx . . $ integer# i = 1; |
| 977 | try { |
| 978 | integercxx . . $ integer# numberOfApiActions = 0; |
| 979 | for (; i <= theActionscxx . . $ theActions..sizecxx . . $ CollectionOf#size.; i ++) { |
| 980 | //Melder_casual (i, U": ", theActions.at [i] -> class1 -> className, U": ", theActions.at [i] -> title.get()); |
| 981 | Praat_Commandcxx . . $ Praat_Command# command = theActionscxx . . $ theActions..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).i]; |
| 982 | const bool deprecated = ( command -> deprecationYearcxx . . $ structPraat_Command#deprecationYear. > 0 ); |
| 983 | if (! actionIsToBeIncludedcxx . . $ actionIsToBeIncluded(f2de3e1a1acc5bcb). (command, deprecated, includeSaveAPI, includeQueryAPI, includeModifyAPI, |
| 984 | includeToAPI, includePlayAPI, includeDrawAPI, includeHelpAPI, includeWindowAPI)) continue; |
| 985 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"\n/* Action command \"", command -> titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"\"", |
| 986 | deprecated ? U", deprecated " : U"", deprecated ? Melder_integercxx . . $ Melder_integer(7b348ebc2004441d). (command -> deprecationYearcxx . . $ structPraat_Command#deprecationYear.) : U"", |
| 987 | U" */"); |
| 988 | conststring32cxx . . $ conststring32# returnType = getReturnTypecxx . . $ getReturnType(152f281cc90b9344). (command); |
| 989 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (returnType, U" Praat", str32chrcxx . . $ str32chr(328a9ede0fba853a). (command -> nameOfCallbackcxx . . $ structPraat_Command#nameOfCallback., U'_'), U" ("); |
| 990 | const bool isDirect = ! str32strcxx . . $ str32str(2de17cd8f7c584a6). (command -> titlecxx . . $ structPraat_Command#title..getcxx . . $ _autostring#get(5a2a78a048fb49a8).(), U"..."); |
| 991 | if (isDirect) { |
| 992 | } else { |
| 993 | command -> callbackcxx . . $ structPraat_Command#callback. (nullptr, -1, nullptr, nullptr, nullptr, nullptr, false, nullptr, nullptr); |
| 994 | } |
| 995 | if (actionHasFileNameArgumentcxx . . $ actionHasFileNameArgument(7a3a722a7704ae08). (command)) |
| 996 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"\tconst char *fileName"); |
| 997 | MelderInfo_writecxx . . $ MelderInfo_write(3eb398314feba58b). (U")"); |
| 998 | if (isInHeaderFile) { |
| 999 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U";"); |
| 1000 | } else { |
| 1001 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U" {"); |
| 1002 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"}"); |
| 1003 | } |
| 1004 | numberOfApiActions += 1; |
| 1005 | } |
| 1006 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1007 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Action not written to C library: ", i, |
| 1008 | U": ", theActions.at [i] -> class1 ? theActions.at [i] -> class1 -> className : U"?? class ??", |
| 1009 | U": ", theActions.at [i] -> title.get() |
| 1010 | ); |
| 1011 | } |
| 1012 | } |
| 1013 | |
| 1014 | /* End of file praat_actions.cpp */ |