Beispiel #1
0
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;
}
Beispiel #2
0
int ButtonEditor::goToPage (const wchar_t *title) {
    if (! title || ! title [0]) return 0;
    if (wcsequ (title, L"Buttons")) return 1;
    switch (title [0]) {
    case 'a': {   /* Toggle visibility of action.*/
        long i = wcstol (& title [1], NULL, 10);
        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 = wcstol (& title [1], NULL, 10);
        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 = wcstol (& title [1], NULL, 10);
        praat_Command action = praat_getAction (i);
        if (! action || ! action -> callback) return 0;
        if (action -> title) {
            UiForm::history.write (L"\n");
            UiForm::history.write (action -> title);
        }
        if (action -> script) {
            if (! DO_RunTheScriptFromAnyAddedMenuCommand (NULL, action -> script, NULL, NULL, false, NULL)) Melder_flushError ("Command not executed.");
        } else {
            if (! action -> callback (NULL, NULL, NULL, NULL, false, NULL)) Melder_flushError ("Command not executed.");
        }
        praat_updateSelection ();
    }
    break;
    case 'p': {   /* Perform menu command. */
        long i = wcstol (& title [1], NULL, 10);
        praat_Command menuCommand = praat_getMenuCommand (i);
        if (! menuCommand || ! menuCommand -> callback) return 0;
        if (menuCommand -> title) {
            UiForm::history.write (L"\n");
            UiForm::history.write (menuCommand -> title);
        }
        if (menuCommand -> script) {
            if (! DO_RunTheScriptFromAnyAddedMenuCommand (NULL, menuCommand -> script, NULL, NULL, false, NULL)) Melder_flushError ("Command not executed.");
        } else {
            if (! menuCommand -> callback (NULL, NULL, NULL, NULL, false, NULL)) Melder_flushError ("Command not executed.");
        }
        praat_updateSelection ();
    }
    break;
    default:
        break;
    }
    return 0;
}