praat_objectMenus.cpp 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729
  1. /* praat_objectMenus.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 <ctype.h>
  19. #include "praatP.h"
  20. #include "praat_script.h"
  21. #include "ScriptEditor.h"
  22. #include "ButtonEditor.h"
  23. #include "DataEditor.h"
  24. #include "site.h"
  25. #include "GraphicsP.h"
  26. //#include <string>
  27. #undef iam
  28. #define iam iam_LOOP
  29. #define EDITOR theCurrentPraatObjects -> list [IOBJECT]. editors
  30. /********** Callbacks of the fixed buttons. **********/
  31. DIRECT (PRAAT_Remove) {
  32. WHERE_DOWN (SELECTED)
  33. praat_removeObject (IOBJECT);
  34. praat_show ();
  35. END }
  36. FORM (MODIFY_Rename, U"Rename object", U"Rename...") {
  37. TEXTFIELD (newName, U"New name:", U"")
  38. OK
  39. WHERE (SELECTED) SET_STRING (newName, NAME)
  40. DO
  41. if (theCurrentPraatObjects -> totalSelection == 0)
  42. Melder_throw (U"Selection changed!\nNo object selected. Cannot rename.");
  43. if (theCurrentPraatObjects -> totalSelection > 1)
  44. Melder_throw (U"Selection changed!\nCannot rename more than one object at a time.");
  45. WHERE (SELECTED) break;
  46. static MelderString string;
  47. MelderString_copy (& string, newName);
  48. praat_cleanUpName (string.string);
  49. static MelderString fullName { };
  50. MelderString_copy (& fullName, Thing_className (OBJECT), U" ", string.string);
  51. if (! str32equ (fullName.string, FULL_NAME)) {
  52. theCurrentPraatObjects -> list [IOBJECT]. name = Melder_dup_f (fullName.string);
  53. autoMelderString listName;
  54. MelderString_append (& listName, ID, U". ", fullName.string);
  55. praat_list_renameAndSelect (IOBJECT, listName.string);
  56. for (int ieditor = 0; ieditor < praat_MAXNUM_EDITORS; ieditor ++)
  57. if (EDITOR [ieditor]) Thing_setName (EDITOR [ieditor], fullName.string);
  58. Thing_setName (OBJECT, string.string);
  59. }
  60. END }
  61. FORM (NEW1_Copy, U"Copy object", U"Copy...") {
  62. TEXTFIELD (newName, U"Name of new object:", U"")
  63. OK
  64. WHERE (SELECTED) SET_STRING (newName, NAME)
  65. DO
  66. if (theCurrentPraatObjects -> totalSelection == 0)
  67. Melder_throw (U"Selection changed!\nNo object selected. Cannot copy.");
  68. if (theCurrentPraatObjects -> totalSelection > 1)
  69. Melder_throw (U"Selection changed!\nCannot copy more than one object at a time.");
  70. WHERE (SELECTED) {
  71. praat_new (Data_copy ((Daata) OBJECT), newName);
  72. }
  73. END }
  74. DIRECT (INFO_Info) {
  75. if (theCurrentPraatObjects -> totalSelection == 0)
  76. Melder_throw (U"Selection changed!\nNo object selected. Cannot query.");
  77. if (theCurrentPraatObjects -> totalSelection > 1)
  78. Melder_throw (U"Selection changed!\nCannot query more than one object at a time.");
  79. WHERE (SELECTED) Thing_infoWithIdAndFile (OBJECT, ID, & theCurrentPraatObjects -> list [IOBJECT]. file);
  80. END }
  81. DIRECT (WINDOW_Inspect) {
  82. if (theCurrentPraatObjects -> totalSelection == 0)
  83. Melder_throw (U"Selection changed!\nNo object selected. Cannot inspect.");
  84. if (theCurrentPraatApplication -> batch) {
  85. Melder_throw (U"Cannot inspect data from batch.");
  86. } else {
  87. WHERE (SELECTED) {
  88. autoDataEditor editor = DataEditor_create (ID_AND_FULL_NAME, OBJECT);
  89. praat_installEditor (editor.get(), IOBJECT);
  90. editor.releaseToUser();
  91. }
  92. }
  93. END }
  94. /********** The fixed menus. **********/
  95. static GuiMenu praatMenu, editMenu, windowMenu, newMenu, readMenu, goodiesMenu, preferencesMenu, technicalMenu, applicationHelpMenu, helpMenu;
  96. GuiMenu praat_objects_resolveMenu (conststring32 menu) {
  97. return
  98. str32equ (menu, U"Praat") || str32equ (menu, U"Control") ? praatMenu :
  99. #if cocoa
  100. str32equ (menu, U"Edit") ? editMenu :
  101. str32equ (menu, U"Window") ? windowMenu :
  102. #endif
  103. str32equ (menu, U"New") || str32equ (menu, U"Create") ? newMenu :
  104. str32equ (menu, U"Open") || str32equ (menu, U"Read") ? readMenu :
  105. str32equ (menu, U"Help") ? helpMenu :
  106. str32equ (menu, U"Goodies") ? goodiesMenu :
  107. str32equ (menu, U"Preferences") ? preferencesMenu :
  108. str32equ (menu, U"Technical") ? technicalMenu :
  109. #ifdef macintosh
  110. str32equ (menu, U"ApplicationHelp") ? applicationHelpMenu :
  111. #else
  112. str32equ (menu, U"ApplicationHelp") ? helpMenu :
  113. #endif
  114. newMenu; // default
  115. }
  116. /********** Callbacks of the Praat menu. **********/
  117. DIRECT (WINDOW_About) {
  118. praat_showLogo (false);
  119. END }
  120. DIRECT (WINDOW_praat_newScript) {
  121. autoScriptEditor editor = ScriptEditor_createFromText (nullptr, nullptr);
  122. editor.releaseToUser();
  123. END }
  124. DIRECT (WINDOW_praat_openScript) {
  125. autoScriptEditor editor = ScriptEditor_createFromText (nullptr, nullptr);
  126. TextEditor_showOpen (editor.get());
  127. editor.releaseToUser();
  128. END }
  129. static ButtonEditor theReferenceToTheOnlyButtonEditor;
  130. static void cb_ButtonEditor_destruction (Editor /* editor */) {
  131. theReferenceToTheOnlyButtonEditor = nullptr;
  132. }
  133. DIRECT (WINDOW_praat_editButtons) {
  134. if (theReferenceToTheOnlyButtonEditor) {
  135. Editor_raise (theReferenceToTheOnlyButtonEditor);
  136. } else {
  137. autoButtonEditor editor = ButtonEditor_create ();
  138. Editor_setDestructionCallback (editor.get(), cb_ButtonEditor_destruction);
  139. theReferenceToTheOnlyButtonEditor = editor.get();
  140. editor.releaseToUser();
  141. }
  142. END }
  143. FORM (PRAAT_addMenuCommand, U"Add menu command", U"Add menu command...") {
  144. WORD (window, U"Window", U"Objects")
  145. WORD (menu, U"Menu", U"New")
  146. SENTENCE (command, U"Command", U"Hallo...")
  147. SENTENCE (afterCommand, U"After command", U"")
  148. INTEGER (depth, U"Depth", U"0")
  149. TEXTFIELD (script, U"Script file:", U"/u/miep/hallo.praat")
  150. OK
  151. DO
  152. praat_addMenuCommandScript (window, menu, command, afterCommand, depth, script);
  153. END }
  154. FORM (PRAAT_hideMenuCommand, U"Hide menu command", U"Hide menu command...") {
  155. WORD (window, U"Window", U"Objects")
  156. WORD (menu, U"Menu", U"New")
  157. SENTENCE (command, U"Command", U"Hallo...")
  158. OK
  159. DO
  160. praat_hideMenuCommand (window, menu, command);
  161. END }
  162. FORM (PRAAT_showMenuCommand, U"Show menu command", U"Show menu command...") {
  163. WORD (window, U"Window", U"Objects")
  164. WORD (menu, U"Menu", U"New")
  165. SENTENCE (command, U"Command", U"Hallo...")
  166. OK
  167. DO
  168. praat_showMenuCommand (window, menu, command);
  169. END }
  170. FORM (PRAAT_addAction, U"Add action command", U"Add action command...") {
  171. WORD (class1, U"Class 1", U"Sound")
  172. INTEGER (number1, U"Number 1", U"0")
  173. WORD (class2, U"Class 2", U"")
  174. INTEGER (number2, U"Number 2", U"0")
  175. WORD (class3, U"Class 3", U"")
  176. INTEGER (number3, U"Number 3", U"0")
  177. SENTENCE (command, U"Command", U"Play reverse")
  178. SENTENCE (afterCommand, U"After command", U"Play")
  179. INTEGER (depth, U"Depth", U"0")
  180. TEXTFIELD (script, U"Script file:", U"/u/miep/playReverse.praat")
  181. OK
  182. DO
  183. praat_addActionScript (class1, number1, class2, number2, class3, number3, command, afterCommand, depth, script);
  184. END }
  185. FORM (PRAAT_hideAction, U"Hide action command", U"Hide action command...") {
  186. WORD (class1, U"Class 1", U"Sound")
  187. WORD (class2, U"Class 2", U"")
  188. WORD (class3, U"Class 3", U"")
  189. SENTENCE (command, U"Command", U"Play")
  190. OK
  191. DO
  192. praat_hideAction_classNames (class1, class2, class3, command);
  193. END }
  194. FORM (PRAAT_showAction, U"Show action command", U"Show action command...") {
  195. WORD (class1, U"Class 1", U"Sound")
  196. WORD (class2, U"Class 2", U"")
  197. WORD (class3, U"Class 3", U"")
  198. SENTENCE (command, U"Command", U"Play")
  199. OK
  200. DO
  201. praat_showAction_classNames (class1, class2, class3, command);
  202. END }
  203. /********** Callbacks of the Preferences menu. **********/
  204. FORM (PREFS_TextInputEncodingSettings, U"Text reading preferences", U"Unicode") {
  205. RADIO_ENUM (kMelder_textInputEncoding, encodingOf8BitTextFiles,
  206. U"Encoding of 8-bit text files", kMelder_textInputEncoding::DEFAULT)
  207. OK
  208. SET_ENUM (encodingOf8BitTextFiles, kMelder_textInputEncoding, Melder_getInputEncoding ())
  209. DO
  210. Melder_setInputEncoding (encodingOf8BitTextFiles);
  211. END }
  212. FORM (PREFS_TextOutputEncodingSettings, U"Text writing preferences", U"Unicode") {
  213. RADIO_ENUM (kMelder_textOutputEncoding, outputEncoding,
  214. U"Output encoding", kMelder_textOutputEncoding::DEFAULT)
  215. OK
  216. SET_ENUM (outputEncoding, kMelder_textOutputEncoding, Melder_getOutputEncoding ())
  217. DO
  218. Melder_setOutputEncoding (outputEncoding);
  219. END }
  220. FORM (PREFS_GraphicsCjkFontStyleSettings, U"CJK font style preferences", nullptr) {
  221. OPTIONMENU_ENUM (kGraphics_cjkFontStyle, cjkFontStyle,
  222. U"CJK font style", kGraphics_cjkFontStyle::DEFAULT)
  223. OK
  224. SET_ENUM (cjkFontStyle, kGraphics_cjkFontStyle, theGraphicsCjkFontStyle)
  225. DO
  226. theGraphicsCjkFontStyle = cjkFontStyle;
  227. END }
  228. /********** Callbacks of the Goodies menu. **********/
  229. FORM (STRING_praat_calculator, U"Calculator", U"Calculator") {
  230. LABEL (U"Type any numeric formula or string formula:")
  231. TEXTFIELD (expression, nullptr, U"5*5")
  232. LABEL (U"Note that you can include many special functions in your formula,")
  233. LABEL (U"including statistical functions and acoustics-auditory conversions.")
  234. LABEL (U"For details, click Help.")
  235. OK
  236. DO
  237. Formula_Result result;
  238. if (! interpreter) {
  239. autoInterpreter tempInterpreter = Interpreter_create (nullptr, nullptr);
  240. Interpreter_anyExpression (tempInterpreter.get(), expression, & result);
  241. } else {
  242. Interpreter_anyExpression (interpreter, expression, & result);
  243. }
  244. switch (result. expressionType) {
  245. case kFormula_EXPRESSION_TYPE_NUMERIC: {
  246. Melder_information (result. numericResult);
  247. } break;
  248. case kFormula_EXPRESSION_TYPE_STRING: {
  249. Melder_information (result. stringResult.get());
  250. } break;
  251. case kFormula_EXPRESSION_TYPE_NUMERIC_VECTOR: {
  252. Melder_information (constVEC (result. numericVectorResult));
  253. } break;
  254. case kFormula_EXPRESSION_TYPE_NUMERIC_MATRIX: {
  255. Melder_information (constMAT (result. numericMatrixResult));
  256. }
  257. }
  258. END }
  259. FORM (INFO_reportDifferenceOfTwoProportions, U"Report difference of two proportions", U"Difference of two proportions") {
  260. INTEGER (a, U"left Row 1", U"71")
  261. INTEGER (b, U"right Row 1", U"39")
  262. INTEGER (c, U"left Row 2", U"93")
  263. INTEGER (d, U"right Row 2", U"27")
  264. OK
  265. DO
  266. double n = a + b + c + d;
  267. double aexp, bexp, cexp, dexp, crossDifference, x2;
  268. if (a < 0 || b < 0 || c < 0 || d < 0) Melder_throw (U"The numbers should not be negative.");
  269. if (a + b <= 0 || c + d <= 0) Melder_throw (U"The row totals should be positive.");
  270. if (a + c <= 0 || b + d <= 0) Melder_throw (U"The column totals should be positive.");
  271. MelderInfo_open ();
  272. MelderInfo_writeLine (U"Observed row 1 = ", Melder_iround (a), U" ", Melder_iround (b));
  273. MelderInfo_writeLine (U"Observed row 2 = ", Melder_iround (c), U" ", Melder_iround (d));
  274. aexp = (a + b) * (a + c) / n;
  275. bexp = (a + b) * (b + d) / n;
  276. cexp = (a + c) * (c + d) / n;
  277. dexp = (b + d) * (c + d) / n;
  278. MelderInfo_writeLine (U"");
  279. MelderInfo_writeLine (U"Expected row 1 = ", aexp, U" ", bexp);
  280. MelderInfo_writeLine (U"Expected row 2 = ", cexp, U" ", dexp);
  281. /*
  282. * Continuity correction:
  283. * bring the observed numbers closer to the expected numbers by 0.5 (if possible).
  284. */
  285. if (a < aexp) { a += 0.5; if (a > aexp) a = aexp; }
  286. else if (a > aexp) { a -= 0.5; if (a < aexp) a = aexp; }
  287. if (b < bexp) { b += 0.5; if (b > bexp) b = bexp; }
  288. else if (b > bexp) { b -= 0.5; if (b < bexp) b = bexp; }
  289. if (c < cexp) { c += 0.5; if (c > cexp) c = cexp; }
  290. else if (c > cexp) { c -= 0.5; if (c < cexp) c = cexp; }
  291. if (d < dexp) { d += 0.5; if (d > dexp) d = dexp; }
  292. else if (d > dexp) { d -= 0.5; if (d < dexp) d = dexp; }
  293. MelderInfo_writeLine (U"");
  294. MelderInfo_writeLine (U"Corrected observed row 1 = ", a, U" ", b);
  295. MelderInfo_writeLine (U"Corrected observed row 2 = ", c, U" ", d);
  296. n = a + b + c + d;
  297. crossDifference = a * d - b * c;
  298. x2 = n * crossDifference * crossDifference / (a + b) / (c + d) / (a + c) / (b + d);
  299. MelderInfo_writeLine (U"");
  300. MelderInfo_writeLine (U"Chi-square = ", x2);
  301. MelderInfo_writeLine (U"Two-tailed p = ", NUMchiSquareQ (x2, 1));
  302. MelderInfo_close ();
  303. END }
  304. /********** Callbacks of the Technical menu. **********/
  305. FORM (PRAAT_debug, U"Set debugging options", nullptr) {
  306. LABEL (U"If you switch Tracing on, Praat will write lots of detailed ")
  307. LABEL (U"information about what goes on in Praat")
  308. structMelderDir dir;
  309. Melder_getPrefDir (& dir);
  310. structMelderFile file;
  311. #ifdef UNIX
  312. MelderDir_getFile (& dir, U"tracing", & file);
  313. #else
  314. MelderDir_getFile (& dir, U"Tracing.txt", & file);
  315. #endif
  316. LABEL (Melder_cat (U"to ", Melder_fileToPath (& file), U"."))
  317. BOOLEAN (tracing, U"Tracing", false)
  318. LABEL (U"Setting the following to anything other than zero")
  319. LABEL (U"will alter the behaviour of Praat")
  320. LABEL (U"in unpredictable ways.")
  321. INTEGER (debugOption, U"Debug option", U"0")
  322. OK
  323. SET_BOOLEAN (tracing, Melder_isTracing)
  324. SET_INTEGER (debugOption, Melder_debug)
  325. DO
  326. Melder_setTracing (tracing);
  327. Melder_debug = debugOption;
  328. END }
  329. DIRECT (INFO_listReadableTypesOfObjects) {
  330. Thing_listReadableClasses ();
  331. END }
  332. FORM (INFO_praat_library_createC, U"PraatLib: Create C header or file", nullptr) {
  333. BOOLEAN (isInHeader, U"Is in header", true)
  334. BOOLEAN (includeCreateAPI, U"Include \"Create\" API", true)
  335. BOOLEAN (includeReadAPI, U"Include \"Read\" API", true)
  336. BOOLEAN (includeSaveAPI, U"Include \"Save\" API", true)
  337. BOOLEAN (includeQueryAPI, U"Include \"Query\" API", true)
  338. BOOLEAN (includeModifyAPI, U"Include \"Modify\" API", true)
  339. BOOLEAN (includeToAPI, U"Include \"To\" API", true)
  340. BOOLEAN (includeRecordAPI, U"Include \"Record\" API", true)
  341. BOOLEAN (includePlayAPI, U"Include \"Play\" API", true)
  342. BOOLEAN (includeDrawAPI, U"Include \"Draw\" API", true)
  343. BOOLEAN (includeHelpAPI, U"Include \"Help\" API", false)
  344. BOOLEAN (includeWindowAPI, U"Include \"Window\" API", false)
  345. BOOLEAN (includeDemoAPI, U"Include \"Demo\" API", false)
  346. OK
  347. DO
  348. praat_library_createC (isInHeader, includeCreateAPI, includeReadAPI, includeSaveAPI,
  349. includeQueryAPI, includeModifyAPI, includeToAPI, includeRecordAPI, includePlayAPI,
  350. includeDrawAPI, includeHelpAPI, includeWindowAPI, includeDemoAPI);
  351. END }
  352. DIRECT (INFO_reportSystemProperties) {
  353. praat_reportSystemProperties ();
  354. END }
  355. DIRECT (INFO_reportGraphicalProperties) {
  356. praat_reportGraphicalProperties ();
  357. END }
  358. DIRECT (INFO_reportIntegerProperties) {
  359. praat_reportIntegerProperties ();
  360. END }
  361. DIRECT (INFO_reportMemoryUse) {
  362. praat_reportMemoryUse ();
  363. END }
  364. DIRECT (INFO_reportTextProperties) {
  365. praat_reportTextProperties ();
  366. END }
  367. /********** Callbacks of the Open menu. **********/
  368. static void readFromFile (MelderFile file) {
  369. autoDaata object = Data_readFromFile (file);
  370. if (! object) return;
  371. if (Thing_isa (object.get(), classManPages) && ! Melder_batch) {
  372. ManPages manPages = (ManPages) object.get();
  373. ManPage firstPage = manPages -> pages.at [1];
  374. autoManual manual = Manual_create (firstPage -> title.get(), object.releaseToAmbiguousOwner(), true);
  375. if (manPages -> executable)
  376. Melder_warning (U"These manual pages contain links to executable scripts.\n"
  377. "Only navigate these pages if you trust their author!");
  378. manual.releaseToUser();
  379. return;
  380. }
  381. if (Thing_isa (object.get(), classScript) && ! Melder_batch) {
  382. autoScriptEditor editor = ScriptEditor_createFromScript_canBeNull (nullptr, (Script) object.get());
  383. if (! editor) {
  384. (void) 0; // the script was already open, and the user has been notified of that
  385. } else {
  386. editor.releaseToUser();
  387. }
  388. return;
  389. }
  390. praat_newWithFile (object.move(), file, MelderFile_name (file));
  391. praat_updateSelection ();
  392. }
  393. FORM_READ (READMANY_Data_readFromFile, U"Read Object(s) from file", 0, true) {
  394. readFromFile (file);
  395. END }
  396. /********** Callbacks of the Save menu. **********/
  397. FORM_SAVE (SAVE_Data_writeToTextFile, U"Save Object(s) as one text file", nullptr, nullptr) {
  398. if (theCurrentPraatObjects -> totalSelection == 1) {
  399. LOOP {
  400. iam (Daata);
  401. Data_writeToTextFile (me, file);
  402. }
  403. } else {
  404. autoCollection set = praat_getSelectedObjects ();
  405. Data_writeToTextFile (set.get(), file);
  406. }
  407. END }
  408. FORM_SAVE (SAVE_Data_writeToShortTextFile, U"Save Object(s) as one short text file", nullptr, nullptr) {
  409. if (theCurrentPraatObjects -> totalSelection == 1) {
  410. LOOP {
  411. iam (Daata);
  412. Data_writeToShortTextFile (me, file);
  413. }
  414. } else {
  415. autoCollection set = praat_getSelectedObjects ();
  416. Data_writeToShortTextFile (set.get(), file);
  417. }
  418. END }
  419. FORM_SAVE (SAVE_Data_writeToBinaryFile, U"Save Object(s) as one binary file", nullptr, nullptr) {
  420. if (theCurrentPraatObjects -> totalSelection == 1) {
  421. LOOP {
  422. iam (Daata);
  423. Data_writeToBinaryFile (me, file);
  424. }
  425. } else {
  426. autoCollection set = praat_getSelectedObjects ();
  427. Data_writeToBinaryFile (set.get(), file);
  428. }
  429. END }
  430. FORM (PRAAT_ManPages_saveToHtmlDirectory, U"Save all pages as HTML files", nullptr) {
  431. TEXTFIELD (directory, U"Directory:", U"")
  432. OK
  433. LOOP {
  434. iam (ManPages);
  435. SET_STRING (directory, Melder_dirToPath (& my rootDirectory))
  436. }
  437. DO
  438. LOOP {
  439. iam (ManPages);
  440. ManPages_writeAllToHtmlDir (me, directory);
  441. }
  442. END }
  443. DIRECT (WINDOW_ManPages_view) {
  444. LOOP {
  445. iam (ManPages);
  446. ManPage firstPage = my pages.at [1];
  447. autoManual manual = Manual_create (firstPage -> title.get(), me, false);
  448. if (my executable)
  449. Melder_warning (U"These manual pages contain links to executable scripts.\n"
  450. "Only navigate these pages if you trust their author!");
  451. praat_installEditor (manual.get(), IOBJECT);
  452. manual.releaseToUser();
  453. }
  454. END }
  455. /********** Callbacks of the Help menu. **********/
  456. FORM (HELP_SearchManual, U"Search manual", U"Manual") {
  457. TEXTFIELD (query, U"Search for strings (separate with spaces):", U"")
  458. OK
  459. DO
  460. if (theCurrentPraatApplication -> batch)
  461. Melder_throw (U"Cannot view a manual from batch.");
  462. autoManual manual = Manual_create (U"Intro", theCurrentPraatApplication -> manPages, false);
  463. Manual_search (manual.get(), query);
  464. manual.releaseToUser();
  465. END }
  466. FORM (HELP_GoToManualPage, U"Go to manual page", nullptr) {
  467. static conststring32vector pages;
  468. pages = ManPages_getTitles (theCurrentPraatApplication -> manPages);
  469. LIST (pageNumber, U"Page", pages, 1)
  470. OK
  471. DO
  472. if (theCurrentPraatApplication -> batch)
  473. Melder_throw (U"Cannot view a manual from batch.");
  474. autoManual manual = Manual_create (U"Intro", theCurrentPraatApplication -> manPages, false);
  475. HyperPage_goToPage_i (manual.get(), pageNumber);
  476. manual.releaseToUser();
  477. END }
  478. FORM (HELP_WriteManualToHtmlDirectory, U"Save all pages as HTML files", nullptr) {
  479. TEXTFIELD (directory, U"Directory:", U"")
  480. OK
  481. structMelderDir currentDirectory { };
  482. Melder_getDefaultDir (& currentDirectory);
  483. SET_STRING (directory, Melder_dirToPath (& currentDirectory))
  484. DO
  485. ManPages_writeAllToHtmlDir (theCurrentPraatApplication -> manPages, directory);
  486. END }
  487. /********** Menu descriptions. **********/
  488. void praat_show () {
  489. /*
  490. * (De)sensitivize the fixed buttons as appropriate for the current selection.
  491. */
  492. praat_sensitivizeFixedButtonCommand (U"Remove", theCurrentPraatObjects -> totalSelection != 0);
  493. praat_sensitivizeFixedButtonCommand (U"Rename...", theCurrentPraatObjects -> totalSelection == 1);
  494. praat_sensitivizeFixedButtonCommand (U"Copy...", theCurrentPraatObjects -> totalSelection == 1);
  495. praat_sensitivizeFixedButtonCommand (U"Info", theCurrentPraatObjects -> totalSelection == 1);
  496. praat_sensitivizeFixedButtonCommand (U"Inspect", theCurrentPraatObjects -> totalSelection != 0);
  497. praat_actions_show ();
  498. if (theCurrentPraatApplication == & theForegroundPraatApplication && theReferenceToTheOnlyButtonEditor)
  499. Editor_dataChanged (theReferenceToTheOnlyButtonEditor);
  500. }
  501. /********** Menu descriptions. **********/
  502. void praat_addFixedButtons (GuiWindow window) {
  503. praat_addFixedButtonCommand (window, U"Rename...", MODIFY_Rename, 8, 70);
  504. praat_addFixedButtonCommand (window, U"Copy...", NEW1_Copy, 98, 70);
  505. praat_addFixedButtonCommand (window, U"Inspect", WINDOW_Inspect, 8, 40);
  506. praat_addFixedButtonCommand (window, U"Info", INFO_Info, 98, 40);
  507. praat_addFixedButtonCommand (window, U"Remove", PRAAT_Remove, 8, 10);
  508. }
  509. static void searchProc () {
  510. HELP_SearchManual (nullptr, 0, nullptr, nullptr, nullptr, nullptr, false, nullptr);
  511. }
  512. static MelderString itemTitle_about { };
  513. static autoDaata scriptRecognizer (integer nread, const char *header, MelderFile file) {
  514. conststring32 name = MelderFile_name (file);
  515. if (nread < 2) return autoDaata ();
  516. if ((header [0] == '#' && header [1] == '!') || str32str (name, U".praat") == name + str32len (name) - 6
  517. || str32str (name, U".html") == name + str32len (name) - 5)
  518. {
  519. return Script_createFromFile (file);
  520. }
  521. return autoDaata ();
  522. }
  523. static void cb_openDocument (MelderFile file) {
  524. try {
  525. readFromFile (file);
  526. } catch (MelderError) {
  527. Melder_flushError ();
  528. }
  529. }
  530. #if cocoa
  531. DIRECT (PRAAT_cut) {
  532. [[[NSApp keyWindow] fieldEditor: YES forObject: nil] cut: nil];
  533. END }
  534. DIRECT (PRAAT_copy) {
  535. [[[NSApp keyWindow] fieldEditor: YES forObject: nil] copy: nil];
  536. END }
  537. DIRECT (PRAAT_paste) {
  538. [[[NSApp keyWindow] fieldEditor: YES forObject: nil] pasteAsPlainText: nil];
  539. END }
  540. DIRECT (PRAAT_minimize) {
  541. [[NSApp keyWindow] performMiniaturize: nil];
  542. END }
  543. DIRECT (PRAAT_zoom) {
  544. [[NSApp keyWindow] performZoom: nil];
  545. END }
  546. DIRECT (PRAAT_close) {
  547. [[NSApp keyWindow] performClose: nil];
  548. END }
  549. #endif
  550. void praat_addMenus (GuiWindow window) {
  551. Melder_setSearchProc (searchProc);
  552. Data_recognizeFileType (scriptRecognizer);
  553. /*
  554. * Create the menu titles in the bar.
  555. */
  556. if (! theCurrentPraatApplication -> batch) {
  557. #ifdef macintosh
  558. praatMenu = GuiMenu_createInWindow (nullptr, U"\024", 0);
  559. #if cocoa
  560. editMenu = GuiMenu_createInWindow (nullptr, U"Edit", 0);
  561. windowMenu = GuiMenu_createInWindow (nullptr, U"Window", 0);
  562. #endif
  563. #else
  564. praatMenu = GuiMenu_createInWindow (window, U"Praat", 0);
  565. #endif
  566. newMenu = GuiMenu_createInWindow (window, U"New", 0);
  567. readMenu = GuiMenu_createInWindow (window, U"Open", 0);
  568. praat_actions_createWriteMenu (window);
  569. #ifdef macintosh
  570. applicationHelpMenu = GuiMenu_createInWindow (nullptr, U"Help", 0);
  571. #endif
  572. helpMenu = GuiMenu_createInWindow (window, U"Help", 0);
  573. }
  574. MelderString_append (& itemTitle_about, U"About ", praatP.title.get(), U"...");
  575. #ifdef macintosh
  576. praat_addMenuCommand (U"Objects", U"Praat", itemTitle_about.string, nullptr, praat_UNHIDABLE, WINDOW_About);
  577. #if cocoa
  578. /*
  579. * HACK: give the following command weird names,
  580. * because otherwise they may be called from a script.
  581. * (we add three alt-spaces)
  582. */
  583. praat_addMenuCommand (U"Objects", U"Edit", U"Cut   ", nullptr, praat_UNHIDABLE | 'X' | praat_NO_API, PRAAT_cut);
  584. praat_addMenuCommand (U"Objects", U"Edit", U"Copy   ", nullptr, praat_UNHIDABLE | 'C' | praat_NO_API, PRAAT_copy);
  585. praat_addMenuCommand (U"Objects", U"Edit", U"Paste   ", nullptr, praat_UNHIDABLE | 'V' | praat_NO_API, PRAAT_paste);
  586. praat_addMenuCommand (U"Objects", U"Window", U"Minimize   ", nullptr, praat_UNHIDABLE | praat_NO_API, PRAAT_minimize);
  587. praat_addMenuCommand (U"Objects", U"Window", U"Zoom   ", nullptr, praat_UNHIDABLE | praat_NO_API, PRAAT_zoom);
  588. praat_addMenuCommand (U"Objects", U"Window", U"Close   ", nullptr, 'W' | praat_NO_API, PRAAT_close);
  589. #endif
  590. #endif
  591. #ifdef UNIX
  592. praat_addMenuCommand (U"Objects", U"Praat", itemTitle_about.string, nullptr, praat_UNHIDABLE, WINDOW_About);
  593. #endif
  594. praat_addMenuCommand (U"Objects", U"Praat", U"-- script --", nullptr, 0, nullptr);
  595. praat_addMenuCommand (U"Objects", U"Praat", U"New Praat script", nullptr, praat_NO_API, WINDOW_praat_newScript);
  596. praat_addMenuCommand (U"Objects", U"Praat", U"Open Praat script...", nullptr, praat_NO_API, WINDOW_praat_openScript);
  597. praat_addMenuCommand (U"Objects", U"Praat", U"-- buttons --", nullptr, 0, nullptr);
  598. praat_addMenuCommand (U"Objects", U"Praat", U"Add menu command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_addMenuCommand);
  599. praat_addMenuCommand (U"Objects", U"Praat", U"Hide menu command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_hideMenuCommand);
  600. praat_addMenuCommand (U"Objects", U"Praat", U"Show menu command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_showMenuCommand);
  601. praat_addMenuCommand (U"Objects", U"Praat", U"Add action command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_addAction);
  602. praat_addMenuCommand (U"Objects", U"Praat", U"Hide action command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_hideAction);
  603. praat_addMenuCommand (U"Objects", U"Praat", U"Show action command...", nullptr, praat_HIDDEN | praat_NO_API, PRAAT_showAction);
  604. GuiMenuItem menuItem = praat_addMenuCommand (U"Objects", U"Praat", U"Goodies", nullptr, praat_UNHIDABLE, nullptr);
  605. goodiesMenu = menuItem ? menuItem -> d_menu : nullptr;
  606. praat_addMenuCommand (U"Objects", U"Goodies", U"Calculator...", nullptr, 'U', STRING_praat_calculator);
  607. praat_addMenuCommand (U"Objects", U"Goodies", U"Report difference of two proportions...", nullptr, 0, INFO_reportDifferenceOfTwoProportions);
  608. menuItem = praat_addMenuCommand (U"Objects", U"Praat", U"Preferences", nullptr, praat_UNHIDABLE, nullptr);
  609. preferencesMenu = menuItem ? menuItem -> d_menu : nullptr;
  610. praat_addMenuCommand (U"Objects", U"Preferences", U"Buttons...", nullptr, praat_UNHIDABLE, WINDOW_praat_editButtons);
  611. praat_addMenuCommand (U"Objects", U"Preferences", U"-- encoding prefs --", nullptr, 0, nullptr);
  612. praat_addMenuCommand (U"Objects", U"Preferences", U"Text reading preferences...", nullptr, 0, PREFS_TextInputEncodingSettings);
  613. praat_addMenuCommand (U"Objects", U"Preferences", U"Text writing preferences...", nullptr, 0, PREFS_TextOutputEncodingSettings);
  614. praat_addMenuCommand (U"Objects", U"Preferences", U"CJK font style preferences...", nullptr, 0, PREFS_GraphicsCjkFontStyleSettings);
  615. menuItem = praat_addMenuCommand (U"Objects", U"Praat", U"Technical", nullptr, praat_UNHIDABLE, nullptr);
  616. technicalMenu = menuItem ? menuItem -> d_menu : nullptr;
  617. praat_addMenuCommand (U"Objects", U"Technical", U"Report memory use", nullptr, 0, INFO_reportMemoryUse);
  618. praat_addMenuCommand (U"Objects", U"Technical", U"Report integer properties", nullptr, 0, INFO_reportIntegerProperties);
  619. praat_addMenuCommand (U"Objects", U"Technical", U"Report text properties", nullptr, 0, INFO_reportTextProperties);
  620. praat_addMenuCommand (U"Objects", U"Technical", U"Report system properties", nullptr, 0, INFO_reportSystemProperties);
  621. praat_addMenuCommand (U"Objects", U"Technical", U"Report graphical properties", nullptr, 0, INFO_reportGraphicalProperties);
  622. praat_addMenuCommand (U"Objects", U"Technical", U"Debug...", nullptr, 0, PRAAT_debug);
  623. praat_addMenuCommand (U"Objects", U"Technical", U"-- api --", nullptr, 0, nullptr);
  624. praat_addMenuCommand (U"Objects", U"Technical", U"List readable types of objects", nullptr, 0, INFO_listReadableTypesOfObjects);
  625. praat_addMenuCommand (U"Objects", U"Technical", U"Create C interface...", nullptr, 0, INFO_praat_library_createC);
  626. praat_addMenuCommand (U"Objects", U"Open", U"Read from file...", nullptr, praat_ATTRACTIVE | 'O', READMANY_Data_readFromFile);
  627. praat_addAction1 (classDaata, 0, U"Save as text file...", nullptr, 0, SAVE_Data_writeToTextFile);
  628. praat_addAction1 (classDaata, 0, U"Write to text file...", nullptr, praat_DEPRECATED_2011, SAVE_Data_writeToTextFile);
  629. praat_addAction1 (classDaata, 0, U"Save as short text file...", nullptr, 0, SAVE_Data_writeToShortTextFile);
  630. praat_addAction1 (classDaata, 0, U"Write to short text file...", nullptr, praat_DEPRECATED_2011, SAVE_Data_writeToShortTextFile);
  631. praat_addAction1 (classDaata, 0, U"Save as binary file...", nullptr, 0, SAVE_Data_writeToBinaryFile);
  632. praat_addAction1 (classDaata, 0, U"Write to binary file...", nullptr, praat_DEPRECATED_2011, SAVE_Data_writeToBinaryFile);
  633. praat_addAction1 (classManPages, 1, U"Save to HTML directory...", nullptr, 0, PRAAT_ManPages_saveToHtmlDirectory);
  634. praat_addAction1 (classManPages, 1, U"View", nullptr, 0, WINDOW_ManPages_view);
  635. }
  636. void praat_addMenus2 () {
  637. praat_addMenuCommand (U"Objects", U"ApplicationHelp", U"-- manual --", nullptr, 0, nullptr);
  638. praat_addMenuCommand (U"Objects", U"ApplicationHelp", U"Go to manual page...", nullptr, 0, HELP_GoToManualPage);
  639. praat_addMenuCommand (U"Objects", U"ApplicationHelp", U"Write manual to HTML directory...", nullptr, praat_HIDDEN, HELP_WriteManualToHtmlDirectory);
  640. praat_addMenuCommand (U"Objects", U"ApplicationHelp",
  641. Melder_cat (U"Search ", praatP.title.get(), U" manual..."),
  642. nullptr, 'M' | praat_NO_API, HELP_SearchManual);
  643. #ifdef _WIN32
  644. praat_addMenuCommand (U"Objects", U"Help", U"-- about --", nullptr, 0, nullptr);
  645. praat_addMenuCommand (U"Objects", U"Help", itemTitle_about.string, nullptr, praat_UNHIDABLE, WINDOW_About);
  646. #endif
  647. #if defined (macintosh) || defined (_WIN32)
  648. Gui_setOpenDocumentCallback (cb_openDocument);
  649. #endif
  650. }
  651. /* End of file praat_objectMenus.cpp */