praat_menuCommands.cpp 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /* praat_menuCommands.cpp
  2. *
  3. * Copyright (C) 1992-2018 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. #include "praatP.h"
  19. #include "praat_script.h"
  20. #include "praat_version.h"
  21. #include "GuiP.h"
  22. static OrderedOf <structPraat_Command> theCommands;
  23. void praat_menuCommands_exit_optimizeByLeaking () { theCommands. _ownItems = false; }
  24. void praat_menuCommands_init () {
  25. }
  26. static int compareMenuCommands (const void *void_me, const void *void_thee) {
  27. Praat_Command me = * (Praat_Command *) void_me, thee = * (Praat_Command *) void_thee;
  28. if (my window) {
  29. if (! thy window) return 1;
  30. int compare = str32cmp (my window.get(), thy window.get());
  31. if (compare) return compare;
  32. } else if (thy window) return -1;
  33. if (my menu) {
  34. if (! thy menu) return 1;
  35. int compare = str32cmp (my menu.get(), thy menu.get());
  36. if (compare) return compare;
  37. } else if (thy menu) return -1;
  38. if (my sortingTail < thy sortingTail) return -1;
  39. return 1;
  40. }
  41. void praat_sortMenuCommands () {
  42. for (integer i = 1; i <= theCommands.size; i ++) {
  43. Praat_Command command = theCommands.at [i];
  44. command -> sortingTail = i;
  45. }
  46. qsort (& theCommands.at [1], theCommands.size, sizeof (Praat_Command), compareMenuCommands);
  47. }
  48. static integer lookUpMatchingMenuCommand (conststring32 window, conststring32 menu, conststring32 title) {
  49. /*
  50. * A menu command is fully specified by its environment (window + menu) and its title.
  51. */
  52. for (integer i = 1; i <= theCommands.size; i ++) {
  53. Praat_Command command = theCommands.at [i];
  54. conststring32 tryWindow = command -> window.get();
  55. conststring32 tryMenu = command -> menu.get();
  56. conststring32 tryTitle = command -> title.get();
  57. if ((window == tryWindow || (window && tryWindow && str32equ (window, tryWindow))) &&
  58. (menu == tryMenu || (menu && tryMenu && str32equ (menu, tryMenu))) &&
  59. (title == tryTitle || (title && tryTitle && str32equ (title, tryTitle)))) return i;
  60. }
  61. return 0; // not found
  62. }
  63. static void do_menu (Praat_Command me, uint32 modified) {
  64. if (my callback == DO_RunTheScriptFromAnyAddedMenuCommand) {
  65. UiHistory_write (U"\nrunScript: ");
  66. try {
  67. DO_RunTheScriptFromAnyAddedMenuCommand (nullptr, 0, nullptr, my script.get(), nullptr, nullptr, false, nullptr);
  68. } catch (MelderError) {
  69. Melder_flushError (U"Command \"", my title.get(), U"\" not executed.");
  70. }
  71. praat_updateSelection ();
  72. } else {
  73. if (my title && ! str32str (my title.get(), U"...")) {
  74. UiHistory_write (U"\n");
  75. UiHistory_write (my title.get());
  76. }
  77. try {
  78. my callback (nullptr, 0, nullptr, nullptr, nullptr, my title.get(), modified, nullptr);
  79. } catch (MelderError) {
  80. Melder_flushError (U"Command \"", my title.get(), U"\" not executed.");
  81. }
  82. praat_updateSelection ();
  83. }
  84. }
  85. static void gui_button_cb_menu (Praat_Command me, GuiButtonEvent event) {
  86. do_menu (me, event -> shiftKeyPressed | event -> commandKeyPressed | event -> optionKeyPressed | event -> extraControlKeyPressed);
  87. }
  88. static void gui_cb_menu (Praat_Command me, GuiMenuItemEvent event) {
  89. bool modified = event -> shiftKeyPressed || event -> commandKeyPressed || event -> optionKeyPressed || event -> extraControlKeyPressed;
  90. do_menu (me, modified);
  91. }
  92. static GuiMenu windowMenuToWidget (conststring32 window, conststring32 menu) {
  93. return
  94. str32equ (window, U"Picture") ? praat_picture_resolveMenu (menu) :
  95. str32equ (window, U"Objects") ? praat_objects_resolveMenu (menu) : nullptr;
  96. }
  97. GuiMenuItem praat_addMenuCommand_ (conststring32 window, conststring32 menu, conststring32 title /* cattable */,
  98. conststring32 after, uint32 flags, UiCallback callback, conststring32 nameOfCallback)
  99. {
  100. integer position;
  101. int depth = flags, key = 0;
  102. bool unhidable = false, hidden = false, noApi = false, forceApi = false;
  103. int deprecationYear = 0;
  104. uint32 guiFlags = 0;
  105. if (flags > 7) {
  106. depth = ((flags & praat_DEPTH_7) >> 16);
  107. unhidable = (flags & praat_UNHIDABLE) != 0;
  108. hidden = (flags & praat_HIDDEN) != 0 && ! unhidable;
  109. key = flags & 0x000000FF;
  110. noApi = (flags & praat_NO_API) != 0;
  111. forceApi = (flags & praat_FORCE_API) != 0;
  112. deprecationYear = (flags & praat_DEPRECATED) == praat_DEPRECATED ? 2000 + (flags >> 24) : 0;
  113. guiFlags = key ? flags & (0x000000FF | GuiMenu_SHIFT | GuiMenu_OPTION | GuiMenu_BUTTON_STATE_MASK) : flags & GuiMenu_BUTTON_STATE_MASK;
  114. }
  115. if (callback && ! title) {
  116. Melder_flushError (U"praat_addMenuCommand: command with callback has no title. Window \"", window, U"\", menu \"", menu, U"\".");
  117. return nullptr;
  118. }
  119. /*
  120. * Determine the position of the new command.
  121. */
  122. if (after && after [0] != U'*') { // search for existing command with same selection
  123. integer found = lookUpMatchingMenuCommand (window, menu, after);
  124. if (found) {
  125. position = found + 1; // after 'after'
  126. } else {
  127. Melder_flushError (U"praat_addMenuCommand: the command \"", title, U"\" cannot be put after \"", after, U"\",\n"
  128. U"in the menu \"", menu, U"\" in the window \"", window, U"\"\n"
  129. U"because the latter command does not exist.");
  130. return nullptr;
  131. }
  132. } else {
  133. position = theCommands.size + 1; // at end
  134. }
  135. /*
  136. * Make new command.
  137. */
  138. autoPraat_Command command = Thing_new (Praat_Command);
  139. command -> window = Melder_dup_f (window);
  140. command -> menu = Melder_dup_f (menu);
  141. command -> title = Melder_dup_f (title);
  142. trace (U"insert new command \"", title, U"\"");
  143. command -> depth = depth;
  144. command -> callback = callback; // null for a separator or cascade button
  145. command -> nameOfCallback = nameOfCallback;
  146. command -> executable = !! callback;
  147. command -> script = autostring32();
  148. command -> hidden = hidden;
  149. command -> unhidable = unhidable;
  150. command -> deprecationYear = deprecationYear;
  151. command -> noApi = noApi;
  152. command -> forceApi = forceApi;
  153. if (! theCurrentPraatApplication -> batch) {
  154. GuiMenu parentMenu = nullptr;
  155. /* WHERE TO PUT IT?
  156. * Determine parent menu widget.
  157. * This is not going to fail:
  158. * if 'depth' is inappropriate, the alleged subitem will be put in the top menu.
  159. */
  160. if (depth == 0) {
  161. /*
  162. * Put the new command in the window's top menu.
  163. */
  164. parentMenu = windowMenuToWidget (window, menu);
  165. } else {
  166. /*
  167. * Put the new command in a submenu.
  168. * The supermenu to put the new command in is the first menu that we find when going up.
  169. */
  170. for (integer parentPosition = position - 1; parentPosition > 0; parentPosition --) {
  171. Praat_Command parentCommand = theCommands.at [parentPosition];
  172. if (parentCommand -> depth == depth - 1) {
  173. /*
  174. * We found the supermenu.
  175. */
  176. if (! parentCommand -> callback && parentCommand -> title && parentCommand -> title [0] != U'-') {
  177. if (! parentCommand -> button)
  178. Melder_fatal (U"No button for ", window, U"/", menu, U"/", title, U".");
  179. Thing_cast (GuiMenuItem, parentButton_as_GuiMenuItem, parentCommand -> button);
  180. parentMenu = parentButton_as_GuiMenuItem -> d_menu;
  181. }
  182. break;
  183. }
  184. }
  185. if (! parentMenu) parentMenu = windowMenuToWidget (window, menu); // fallback: put the command in the window's top menu
  186. }
  187. if (! parentMenu) {
  188. trace (U"WARNING: no parent menu for ", window, U"/", menu, U"/", title, U".");
  189. return nullptr;
  190. }
  191. /*
  192. * WHAT TO PUT THERE?
  193. */
  194. if (! title || title [0] == U'-') {
  195. trace (U"insert the command as a separator");
  196. command -> button = GuiMenu_addSeparator (parentMenu);
  197. Melder_assert (command -> button);
  198. } else if (! callback) {
  199. trace (U"insert the command as a submenu");
  200. command -> button = GuiMenu_createInMenu (parentMenu, title, 0) -> d_menuItem.get();
  201. Melder_assert (command -> button);
  202. } else {
  203. trace (U"insert the command as a normal menu item");
  204. command -> button = GuiMenu_addItem (parentMenu, title, guiFlags, gui_cb_menu, command.get());
  205. Melder_assert (command -> button);
  206. }
  207. if (hidden) GuiThing_hide (command -> button);
  208. }
  209. Thing_cast (GuiMenuItem, button_as_GuiMenuItem, command -> button);
  210. theCommands. addItemAtPosition_move (command.move(), position);
  211. return button_as_GuiMenuItem;
  212. }
  213. void praat_addMenuCommandScript (conststring32 window, conststring32 menu, conststring32 title,
  214. conststring32 after, integer depth, conststring32 script)
  215. {
  216. try {
  217. Melder_assert (window && menu && title && after && script);
  218. if (script [0] != U'\0' && title [0] == U'\0')
  219. Melder_throw (U"Command with script has no title. Window \"", window, U"\", menu \"", menu, U"\".");
  220. /*
  221. * Determine the position of the new command.
  222. */
  223. integer position;
  224. if (str32len (after) && after [0] != U'*') { // search for existing command with same selection
  225. integer found = lookUpMatchingMenuCommand (window, menu, after);
  226. if (found) {
  227. position = found + 1; // after 'after'
  228. } else {
  229. /*Melder_throw (U"The menu command \"", title, U"\" cannot be put after \"", after, U"\",\n"
  230. U"in the menu \"", menu, "\" in the window \"", window, U"\"\n"
  231. U"because the latter command does not exist.");*/
  232. position = theCommands.size + 1; // default: at end
  233. }
  234. } else {
  235. position = theCommands.size + 1; // at end
  236. }
  237. /*
  238. * Make new command.
  239. */
  240. autoPraat_Command command = Thing_new (Praat_Command);
  241. command -> window = Melder_dup_f (window);
  242. command -> menu = Melder_dup_f (menu);
  243. command -> title = ( title [0] != U'\0' ? Melder_dup_f (title) : autostring32() ); // allow old-fashioned untitled separators
  244. command -> depth = depth;
  245. command -> callback = ( script [0] != U'\0' ? DO_RunTheScriptFromAnyAddedMenuCommand : nullptr ); // null for a separator or cascade button
  246. command -> executable = ( script [0] != U'\0' );
  247. command -> noApi = true;
  248. if (script [0] == U'\0') {
  249. command -> script = Melder_dup_f (U""); // empty string, which will be needed to signal origin
  250. } else {
  251. structMelderFile file { };
  252. Melder_relativePathToFile (script, & file);
  253. command -> script = Melder_dup_f (Melder_fileToPath (& file));
  254. }
  255. command -> after = ( after [0] != U'\0' ? Melder_dup_f (after) : autostring32() );
  256. if (praatP.phase >= praat_READING_BUTTONS) {
  257. static integer uniqueID = 0;
  258. command -> uniqueID = ++ uniqueID;
  259. }
  260. if (! theCurrentPraatApplication -> batch) {
  261. GuiMenu parentMenu = nullptr;
  262. /* WHERE TO PUT IT?
  263. * Determine parent menu widget.
  264. * This is not going to fail:
  265. * if 'depth' is inappropriate, the alleged subitem will be put in the top menu.
  266. */
  267. if (depth == 0) {
  268. parentMenu = windowMenuToWidget (window, menu); // not a subitem: in the top menu
  269. } else {
  270. for (integer parentPosition = position - 1; parentPosition > 0; parentPosition --) {
  271. Praat_Command parentCommand = theCommands.at [parentPosition];
  272. if (parentCommand -> depth == depth - 1) {
  273. if (! parentCommand -> callback && parentCommand -> title && parentCommand -> title [0] != U'-') {
  274. if (! parentCommand -> button)
  275. Melder_fatal (U"No button for ", window, U"/", menu, U"/", title, U".");
  276. Melder_assert (parentCommand -> button -> classInfo == classGuiMenuItem);
  277. parentMenu = (static_cast <GuiMenuItem> (parentCommand -> button)) -> d_menu;
  278. }
  279. break;
  280. }
  281. }
  282. if (! parentMenu) parentMenu = windowMenuToWidget (window, menu); // fallback: a subitem without a menu title
  283. }
  284. if (parentMenu) {
  285. /* WHAT TO PUT THERE?
  286. */
  287. if (title [0] == U'\0' || title [0] == U'-') {
  288. command -> button = GuiMenu_addSeparator (parentMenu);
  289. } else if (script [0] == '\0') {
  290. command -> button = GuiMenu_createInMenu (parentMenu, title, 0) -> d_menuItem.get();
  291. } else {
  292. command -> button = GuiMenu_addItem (parentMenu, title, 0, gui_cb_menu, command.get());
  293. }
  294. }
  295. }
  296. theCommands. addItemAtPosition_move (command.move(), position);
  297. if (praatP.phase >= praat_HANDLING_EVENTS) praat_sortMenuCommands ();
  298. } catch (MelderError) {
  299. Melder_throw (U"Script menu command not added.");
  300. }
  301. }
  302. void praat_hideMenuCommand (conststring32 window, conststring32 menu, conststring32 title) {
  303. if (theCurrentPraatApplication -> batch || ! window || ! menu || ! title) return;
  304. integer found = lookUpMatchingMenuCommand (window, menu, title);
  305. if (! found) return;
  306. Praat_Command command = theCommands.at [found];
  307. if (! command -> hidden && ! command -> unhidable) {
  308. command -> hidden = true;
  309. if (praatP.phase >= praat_READING_BUTTONS) command -> toggled = ! command -> toggled;
  310. if (command -> button) GuiThing_hide (command -> button);
  311. }
  312. }
  313. void praat_showMenuCommand (conststring32 window, conststring32 menu, conststring32 title) {
  314. if (theCurrentPraatApplication -> batch || ! window || ! menu || ! title) return;
  315. integer found = lookUpMatchingMenuCommand (window, menu, title);
  316. if (! found) return;
  317. Praat_Command command = theCommands.at [found];
  318. if (command -> hidden) {
  319. command -> hidden = false;
  320. if (praatP.phase >= praat_READING_BUTTONS) command -> toggled = ! command -> toggled;
  321. if (command -> button) GuiThing_show (command -> button);
  322. }
  323. }
  324. void praat_saveAddedMenuCommands (MelderString *buffer) {
  325. /*
  326. The procedure as it is now, runs in M*N time,
  327. where M is the number of added commands and N is the total number of commands.
  328. Sorting first instead runs in N log N time and will therefore be faster if M >> log N ≈ 10.
  329. */
  330. integer maxID = 0;
  331. for (integer i = 1; i <= theCommands.size; i ++) {
  332. Praat_Command command = theCommands.at [i];
  333. if (command -> uniqueID > maxID)
  334. maxID = command -> uniqueID;
  335. }
  336. for (integer id = 1; id <= maxID; id ++) // sorted
  337. for (integer i = 1; i <= theCommands.size; i ++) {
  338. Praat_Command me = theCommands.at [i];
  339. if (my uniqueID == id && ! my hidden && my window && my menu && my title) {
  340. MelderString_append (buffer, U"Add menu command... \"", my window.get(), U"\" \"", my menu.get(), U"\" \"", my title.get(), U"\" \"",
  341. ( my after ? my after.get() : U"" ), U"\" ", my depth, U" ", ( my script ? my script.get() : U"" ), U"\n");
  342. break;
  343. }
  344. }
  345. }
  346. void praat_saveToggledMenuCommands (MelderString *buffer) {
  347. for (integer i = 1; i <= theCommands.size; i ++) {
  348. Praat_Command me = theCommands.at [i];
  349. if (my toggled && my window && my menu && my title && ! my uniqueID && ! my script)
  350. MelderString_append (buffer, my hidden ? U"Hide" : U"Show", U" menu command... \"",
  351. my window.get(), U"\" \"", my menu.get(), U"\" ", my title.get(), U"\n");
  352. }
  353. }
  354. /***** FIXED BUTTONS *****/
  355. void praat_addFixedButtonCommand_ (GuiForm parent, conststring32 title, UiCallback callback, conststring32 nameOfCallback, int x, int y) {
  356. autoPraat_Command me = Thing_new (Praat_Command);
  357. my window = Melder_dup_f (U"Objects");
  358. my title = Melder_dup_f (title);
  359. my callback = callback;
  360. my nameOfCallback = nameOfCallback;
  361. my unhidable = true;
  362. my noApi = ( str32equ (title, U"Inspect") );
  363. if (theCurrentPraatApplication -> batch) {
  364. my button = nullptr;
  365. } else {
  366. GuiThing button = my button = GuiButton_create (parent, x, x + 82, -y - Gui_PUSHBUTTON_HEIGHT, -y,
  367. title, gui_button_cb_menu, me.get(), 0);
  368. GuiThing_setSensitive (button, false);
  369. GuiThing_show (button);
  370. }
  371. my executable = false;
  372. theCommands. addItemAtPosition_move (me.move(), 0);
  373. }
  374. void praat_sensitivizeFixedButtonCommand (conststring32 title, bool sensitive) {
  375. Praat_Command commandFound = nullptr;
  376. for (integer i = 1; i <= theCommands.size; i ++) {
  377. Praat_Command command = theCommands.at [i];
  378. if (str32equ (command -> title.get(), title)) {
  379. commandFound = command;
  380. break;
  381. }
  382. }
  383. if (! commandFound) Melder_fatal (U"Unkown fixed button <<", title, U">>");
  384. commandFound -> executable = sensitive;
  385. if (! theCurrentPraatApplication -> batch && ! Melder_backgrounding)
  386. GuiThing_setSensitive (commandFound -> button, sensitive);
  387. }
  388. int praat_doMenuCommand (conststring32 title, conststring32 arguments, Interpreter interpreter) {
  389. Praat_Command commandFound = nullptr;
  390. for (integer i = 1; i <= theCommands.size; i ++) {
  391. Praat_Command command = theCommands.at [i];
  392. if (command -> executable && str32equ (command -> title.get(), title) &&
  393. (str32equ (command -> window.get(), U"Objects") || str32equ (command -> window.get(), U"Picture")))
  394. {
  395. commandFound = command;
  396. break;
  397. }
  398. }
  399. if (! commandFound) return 0;
  400. commandFound -> callback (nullptr, 0, nullptr, arguments, interpreter, title, false, nullptr);
  401. return 1;
  402. }
  403. int praat_doMenuCommand (conststring32 title, integer narg, Stackel args, Interpreter interpreter) {
  404. Praat_Command commandFound = nullptr;
  405. for (integer i = 1; i <= theCommands.size; i ++) {
  406. Praat_Command command = theCommands.at [i];
  407. if (command -> executable && str32equ (command -> title.get(), title) &&
  408. (str32equ (command -> window.get(), U"Objects") || str32equ (command -> window.get(), U"Picture")))
  409. {
  410. commandFound = command;
  411. break;
  412. }
  413. }
  414. if (! commandFound) return 0;
  415. commandFound -> callback (nullptr, narg, args, nullptr, interpreter, title, false, nullptr);
  416. return 1;
  417. }
  418. integer praat_getNumberOfMenuCommands () { return theCommands.size; }
  419. Praat_Command praat_getMenuCommand (integer i)
  420. { return i < 1 || i > theCommands.size ? nullptr : theCommands.at [i]; }
  421. void praat_addCommandsToEditor (Editor me) {
  422. conststring32 windowName = my classInfo -> className;
  423. for (integer i = 1; i <= theCommands.size; i ++) {
  424. Praat_Command command = theCommands.at [i];
  425. if (str32equ (command -> window.get(), windowName)) {
  426. Editor_addCommandScript (me, command -> menu.get(), command -> title.get(), 0, command -> script.get());
  427. }
  428. }
  429. }
  430. static bool commandIsToBeIncluded (Praat_Command command, bool deprecated, bool includeCreateAPI, bool includeReadAPI,
  431. bool includeRecordAPI, bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI)
  432. {
  433. bool obsolete = ( deprecated && (command -> deprecationYear < PRAAT_YEAR - 10 || command -> deprecationYear < 2017) );
  434. bool hiddenByDefault = ( command -> hidden != command -> toggled );
  435. bool explicitlyHidden = hiddenByDefault && ! deprecated;
  436. bool hidden = explicitlyHidden || ! command -> callback || command -> noApi || obsolete ||
  437. (! includeWindowAPI && Melder_nequ (command -> nameOfCallback, U"WINDOW_", 7)) ||
  438. (! includeHelpAPI && Melder_nequ (command -> nameOfCallback, U"HELP_", 5)) ||
  439. (! includeDrawAPI && Melder_nequ (command -> nameOfCallback, U"GRAPHICS_", 9)) ||
  440. (! includePlayAPI && Melder_nequ (command -> nameOfCallback, U"PLAY_", 5)) ||
  441. (! includeRecordAPI && Melder_nequ (command -> nameOfCallback, U"RECORD_", 7)) ||
  442. (! includeReadAPI && Melder_nequ (command -> nameOfCallback, U"READ_", 5)) ||
  443. (! includeReadAPI && Melder_nequ (command -> nameOfCallback, U"READ1_", 6)) ||
  444. (! includeCreateAPI && Melder_nequ (command -> nameOfCallback, U"NEW1_", 5));
  445. return command -> forceApi || ! hidden;
  446. }
  447. static bool commandHasFileNameArgument (Praat_Command command) {
  448. bool hasFileNameArgument =
  449. Melder_nequ (command -> nameOfCallback, U"READ1_", 6) ||
  450. Melder_nequ (command -> nameOfCallback, U"SAVE_", 5)
  451. ;
  452. return hasFileNameArgument;
  453. }
  454. static conststring32 getReturnType (Praat_Command command) {
  455. const conststring32 returnType =
  456. Melder_nequ (command -> nameOfCallback, U"NEW1_", 5) ? U"PraatObject" :
  457. Melder_nequ (command -> nameOfCallback, U"READ1_", 6) ? U"PraatObject" :
  458. Melder_nequ (command -> nameOfCallback, U"REAL_", 5) ? U"double" :
  459. Melder_nequ (command -> nameOfCallback, U"INTEGER_", 8) ? U"int64_t" :
  460. Melder_nequ (command -> nameOfCallback, U"STRING_", 7) ? U"char *" :
  461. Melder_nequ (command -> nameOfCallback, U"REPORT_", 7) ? U"char *" :
  462. Melder_nequ (command -> nameOfCallback, U"LIST_", 5) ? U"char *" :
  463. Melder_nequ (command -> nameOfCallback, U"INFO_", 5) ? U"char *" :
  464. Melder_nequ (command -> nameOfCallback, U"HINT_", 5) ? U"char *" :
  465. U"void";
  466. return returnType;
  467. }
  468. void praat_menuCommands_writeC (bool isInHeaderFile, bool includeCreateAPI, bool includeReadAPI,
  469. bool includeRecordAPI, bool includePlayAPI, bool includeDrawAPI, bool includeHelpAPI, bool includeWindowAPI)
  470. {
  471. integer numberOfApiMenuCommands = 0;
  472. for (integer i = 1; i <= theCommands.size; i ++) {
  473. Praat_Command command = theCommands.at [i];
  474. bool deprecated = ( command -> deprecationYear > 0 );
  475. if (! commandIsToBeIncluded (command, deprecated, includeCreateAPI, includeReadAPI,
  476. includeRecordAPI, includePlayAPI, includeDrawAPI, includeHelpAPI, includeWindowAPI)) continue;
  477. MelderInfo_writeLine (U"\n/* Menu command \"", command -> title.get(), U"\"",
  478. deprecated ? U", deprecated " : U"", deprecated ? Melder_integer (command -> deprecationYear) : U"",
  479. U" */");
  480. conststring32 returnType = getReturnType (command);
  481. MelderInfo_writeLine (returnType, U" Praat", str32chr (command -> nameOfCallback, U'_'), U" (");
  482. bool isDirect = ! str32str (command -> title.get(), U"...");
  483. if (isDirect) {
  484. } else {
  485. command -> callback (nullptr, -1, nullptr, nullptr, nullptr, nullptr, false, nullptr);
  486. }
  487. if (commandHasFileNameArgument (command)) {
  488. MelderInfo_writeLine (U"\tconst char *fileName");
  489. }
  490. MelderInfo_write (U")");
  491. if (isInHeaderFile) {
  492. MelderInfo_writeLine (U";");
  493. } else {
  494. MelderInfo_writeLine (U" {");
  495. MelderInfo_writeLine (U"}");
  496. }
  497. numberOfApiMenuCommands += 1;
  498. }
  499. }
  500. /* End of file praat_menuCommands.cpp */