static void menu_cb_pasteHistory (ScriptEditor me, EDITOR_ARGS_DIRECT) { char32 *history = UiHistory_get (); if (! history || history [0] == U'\0') Melder_throw (U"No history."); long length = str32len (history); if (history [length - 1] != U'\n') { UiHistory_write (U"\n"); history = UiHistory_get (); length = str32len (history); } if (history [0] == U'\n') { history ++; length --; } long first = 0, last = 0; char32 *text = GuiText_getStringAndSelectionPosition (my textWidget, & first, & last); Melder_free (text); GuiText_replace (my textWidget, first, last, history); GuiText_setSelection (my textWidget, first, first + length); GuiText_scrollToSelection (my textWidget); }
static void menu_cb_pasteHistory (EDITOR_ARGS) { EDITOR_IAM (ScriptEditor); wchar_t *history = UiHistory_get (); if (history == NULL || history [0] == '\0') Melder_throw ("No history."); long length = wcslen (history); if (history [length - 1] != '\n') { UiHistory_write (L"\n"); history = UiHistory_get (); length = wcslen (history); } if (history [0] == '\n') { history ++; length --; } long first = 0, last = 0; wchar_t *text = my textWidget -> f_getStringAndSelectionPosition (& first, & last); Melder_free (text); my textWidget -> f_replace (first, last, history); my textWidget -> f_setSelection (first, first + length); my textWidget -> f_scrollToSelection (); }
int structButtonEditor :: v_goToPage (const char32 *title) { if (! title || ! title [0]) return 0; if (str32equ (title, U"Buttons")) return 1; switch (title [0]) { case 'a': { // toggle visibility of action long i = Melder_atoi (& title [1]); Praat_Command action = praat_getAction (i); if (! action) return 0; if (action -> hidden) praat_showAction (action -> class1, action -> class2, action -> class3, action -> title); else praat_hideAction (action -> class1, action -> class2, action -> class3, action -> title); } break; case 'm': { // toggle visibility of menu command long i = Melder_atoi (& title [1]); Praat_Command menuCommand = praat_getMenuCommand (i); if (! menuCommand) return 0; if (menuCommand -> hidden) praat_showMenuCommand (menuCommand -> window, menuCommand -> menu, menuCommand -> title); else praat_hideMenuCommand (menuCommand -> window, menuCommand -> menu, menuCommand -> title); } break; case 'e': { // execute action long i = Melder_atoi (& title [1]); Praat_Command action = praat_getAction (i); if (! action || ! action -> callback) return 0; if (action -> title) { UiHistory_write (U"\n"); UiHistory_write_colonize (action -> title); } if (action -> script) { try { DO_RunTheScriptFromAnyAddedMenuCommand (nullptr, 0, nullptr, action -> script, nullptr, nullptr, false, nullptr); } catch (MelderError) { Melder_flushError (U"Command not executed."); } } else { try { action -> callback (nullptr, 0, nullptr, nullptr, nullptr, nullptr, false, nullptr); } catch (MelderError) { Melder_flushError (U"Command not executed."); } } praat_updateSelection (); } break; case 'p': { // perform menu command long i = Melder_atoi (& title [1]); Praat_Command menuCommand = praat_getMenuCommand (i); if (! menuCommand || ! menuCommand -> callback) return 0; if (menuCommand -> title) { UiHistory_write (U"\n"); UiHistory_write_colonize (menuCommand -> title); } if (menuCommand -> script) { try { DO_RunTheScriptFromAnyAddedMenuCommand (nullptr, 0, nullptr, menuCommand -> script, nullptr, nullptr, false, nullptr); } catch (MelderError) { Melder_flushError (U"Command not executed."); } } else { try { menuCommand -> callback (nullptr, 0, nullptr, nullptr, nullptr, nullptr, false, nullptr); } catch (MelderError) { Melder_flushError (U"Command not executed."); } } praat_updateSelection (); } break; default: break; } return 0; }