📄 usercmds.c
字号:
if (errorParent != NULL) { ParseError(errorParent, macro, stoppedAt, "macro", errMsg); XmTextSetInsertionPosition(errFocus, stoppedAt - macro); XmProcessTraversal(errFocus, XmTRAVERSE_CURRENT); } return False; } FreeProgram(prog); if (*stoppedAt != '\0') { if (errorParent != NULL) { ParseError(errorParent, macro, stoppedAt,"macro","syntax error"); XmTextSetInsertionPosition(errFocus, stoppedAt - macro); XmProcessTraversal(errFocus, XmTRAVERSE_CURRENT); } return False; } return True;}static int applyDialogChanges(userCmdDialog *ucd){ int i; /* Get the current contents of the dialog fields */ if (!UpdateManagedList(ucd->managedList, True)) return False; /* Test compile the macro */ if (ucd->dialogType == MACRO_CMDS) if (!checkMacro(ucd)) return False; /* Update the menu information */ if (ucd->dialogType == SHELL_CMDS) { for (i=0; i<NShellMenuItems; i++) freeMenuItemRec(ShellMenuItems[i]); for (i=0; i<ucd->nMenuItems; i++) ShellMenuItems[i] = copyMenuItemRec(ucd->menuItemsList[i]); NShellMenuItems = ucd->nMenuItems; } else if (ucd->dialogType == MACRO_CMDS) { for (i=0; i<NMacroMenuItems; i++) freeMenuItemRec(MacroMenuItems[i]); for (i=0; i<ucd->nMenuItems; i++) MacroMenuItems[i] = copyMenuItemRec(ucd->menuItemsList[i]); NMacroMenuItems = ucd->nMenuItems; } else { /* BG_MENU_CMDS */ for (i=0; i<NBGMenuItems; i++) freeMenuItemRec(BGMenuItems[i]); for (i=0; i<ucd->nMenuItems; i++) BGMenuItems[i] = copyMenuItemRec(ucd->menuItemsList[i]); NBGMenuItems = ucd->nMenuItems; } /* Update the menus themselves in all of the NEdit windows */ updateMenus(ucd->dialogType); /* Note that preferences have been changed */ MarkPrefsChanged(); return True;}static void pasteReplayCB(Widget w, XtPointer clientData, XtPointer callData){ userCmdDialog *ucd = (userCmdDialog *)clientData; if (GetReplayMacro() == NULL) return; XmTextInsert(ucd->cmdTextW, XmTextGetInsertionPosition(ucd->cmdTextW), GetReplayMacro());}static void destroyCB(Widget w, XtPointer clientData, XtPointer callData){ userCmdDialog *ucd = (userCmdDialog *)clientData; int i; for (i=0; i<ucd->nMenuItems; i++) freeMenuItemRec(ucd->menuItemsList[i]); XtFree((char *)ucd->menuItemsList); XtFree((char *)ucd);}static void accFocusCB(Widget w, XtPointer clientData, XtPointer callData){ userCmdDialog *ucd = (userCmdDialog *)clientData; RemoveDialogMnemonicHandler(XtParent(ucd->accTextW));}static void accLoseFocusCB(Widget w, XtPointer clientData, XtPointer callData){ userCmdDialog *ucd = (userCmdDialog *)clientData; AddDialogMnemonicHandler(XtParent(ucd->accTextW), FALSE);}static void accKeyCB(Widget w, XtPointer clientData, XKeyEvent *event){ userCmdDialog *ucd = (userCmdDialog *)clientData; KeySym keysym = XLookupKeysym(event, 0); char outStr[MAX_ACCEL_LEN]; /* Accept only real keys, not modifiers alone */ if (IsModifierKey(keysym)) return; /* Tab key means go to the next field, don't enter */ if (keysym == XK_Tab) return; /* Beep and return if the modifiers are buttons or ones we don't support */ if (event->state & ~(ShiftMask | LockMask | ControlMask | Mod1Mask | Mod2Mask | Mod3Mask | Mod4Mask | Mod5Mask)) { XBell(TheDisplay, 0); return; } /* Delete or backspace clears field */ if (keysym == XK_Delete || keysym == XK_BackSpace) { XmTextSetString(ucd->accTextW, ""); return; } /* generate the string to use in the dialog field */ generateAcceleratorString(outStr, event->state, keysym); /* Reject single character accelerators (a very simple way to eliminate un-modified letters and numbers) The goal is give users a clue that they're supposed to type the actual keys, not the name. This scheme is not rigorous and still allows accelerators like Comma. */ if (strlen(outStr) == 1) { XBell(TheDisplay, 0); return; } /* fill in the accelerator field in the dialog */ XmTextSetString(ucd->accTextW, outStr);}static void sameOutCB(Widget w, XtPointer clientData, XtPointer callData){ XtSetSensitive(((userCmdDialog *)clientData)->repInpBtn, XmToggleButtonGetState(w));}static void shellMenuCB(Widget w, WindowInfo *window, XtPointer callData) { XtArgVal userData; int index; char *params[1]; /* get the index of the shell command and verify that it's in range */ XtVaGetValues(w, XmNuserData, &userData, NULL); index = (int)userData - 10; if (index <0 || index >= NShellMenuItems) return; params[0] = ShellMenuItems[index]->name; XtCallActionProc(window->lastFocus, "shell_menu_command", ((XmAnyCallbackStruct *)callData)->event, params, 1);}static void macroMenuCB(Widget w, WindowInfo *window, XtPointer callData) { XtArgVal userData; int index; char *params[1]; /* Don't allow users to execute a macro command from the menu (or accel) if there's already a macro command executing. NEdit can't handle running multiple, independent uncoordinated, macros in the same window. Macros may invoke macro menu commands recursively via the macro_menu_command action proc, which is important for being able to repeat any operation, and to embed macros within eachother at any level, however, a call here with a macro running means that THE USER is explicitly invoking another macro via the menu or an accelerator. */ if (window->macroCmdData != NULL) { XBell(TheDisplay, 0); return; } /* get the index of the macro command and verify that it's in range */ XtVaGetValues(w, XmNuserData, &userData, NULL); index = (int)userData - 10; if (index <0 || index >= NMacroMenuItems) return; params[0] = MacroMenuItems[index]->name; XtCallActionProc(window->lastFocus, "macro_menu_command", ((XmAnyCallbackStruct *)callData)->event, params, 1);}static void bgMenuCB(Widget w, WindowInfo *window, XtPointer callData) { XtArgVal userData; int index; char *params[1]; /* Same remark as for macro menu commands (see above). */ if (window->macroCmdData != NULL) { XBell(TheDisplay, 0); return; } /* get the index of the macro command and verify that it's in range */ XtVaGetValues(w, XmNuserData, &userData, NULL); index = (int)userData - 10; if (index <0 || index >= NBGMenuItems) return; params[0] = BGMenuItems[index]->name; XtCallActionProc(window->lastFocus, "bg_menu_command", ((XmAnyCallbackStruct *)callData)->event, params, 1);}/*** Update the name, accelerator, mnemonic, and command fields in the shell** command or macro dialog to agree with the currently selected item in the** menu item list.*/static void updateDialogFields(menuItemRec *f, userCmdDialog *ucd){ char mneString[2], accString[MAX_ACCEL_LEN]; /* fill in the name, accelerator, mnemonic, and command fields of the dialog for the newly selected item, or blank them if "New" is selected */ if (f == NULL) { XmTextSetString(ucd->nameTextW, ""); XmTextSetString(ucd->cmdTextW, ""); XmTextSetString(ucd->accTextW, ""); XmTextSetString(ucd->mneTextW, ""); if (ucd->dialogType == SHELL_CMDS) { XmToggleButtonSetState(ucd->selInpBtn, True, True); XmToggleButtonSetState(ucd->sameOutBtn, True, True); XmToggleButtonSetState(ucd->repInpBtn, False, False); XtSetSensitive(ucd->repInpBtn, True); XmToggleButtonSetState(ucd->saveFirstBtn, False, False); XmToggleButtonSetState(ucd->loadAfterBtn, False, False); } } else { mneString[0] = f->mnemonic; mneString[1] = '\0'; generateAcceleratorString(accString, f->modifiers, f->keysym); XmTextSetString(ucd->nameTextW, f->name); XmTextSetString(ucd->cmdTextW, f->cmd); XmTextSetString(ucd->accTextW, accString); XmTextSetString(ucd->mneTextW, mneString); XmToggleButtonSetState(ucd->selInpBtn, f->input==FROM_SELECTION, False); if (ucd->dialogType == SHELL_CMDS) { XmToggleButtonSetState(ucd->winInpBtn, f->input == FROM_WINDOW, False); XmToggleButtonSetState(ucd->eitherInpBtn, f->input == FROM_EITHER, False); XmToggleButtonSetState(ucd->noInpBtn, f->input == FROM_NONE, False); XmToggleButtonSetState(ucd->sameOutBtn, f->output==TO_SAME_WINDOW, False); XmToggleButtonSetState(ucd->winOutBtn, f->output==TO_NEW_WINDOW, False); XmToggleButtonSetState(ucd->dlogOutBtn, f->output==TO_DIALOG, False); XmToggleButtonSetState(ucd->repInpBtn, f->repInput, False); XtSetSensitive(ucd->repInpBtn, f->output==TO_SAME_WINDOW); XmToggleButtonSetState(ucd->saveFirstBtn, f->saveFirst, False); XmToggleButtonSetState(ucd->loadAfterBtn, f->loadAfter, False); } }} /*** Read the name, accelerator, mnemonic, and command fields from the shell or** macro commands dialog into a newly allocated menuItemRec. Returns a** pointer to the new menuItemRec structure as the function value, or NULL on** failure.*/static menuItemRec *readDialogFields(userCmdDialog *ucd, int silent){ char *nameText, *cmdText, *mneText, *accText; menuItemRec *f; nameText = XmTextGetString(ucd->nameTextW); if (*nameText == '\0') { if (!silent) { DialogF(DF_WARN, ucd->dlogShell, 1, "Menu Entry", "Please specify a name\nfor the menu item", "Dismiss"); XmProcessTraversal(ucd->nameTextW, XmTRAVERSE_CURRENT); } XtFree(nameText); return NULL; } if (strchr(nameText, ':')) { if (!silent) { DialogF(DF_WARN, ucd->dlogShell, 1, "Menu Entry", "Menu item names may not\ncontain colon (:) characters", "Dismiss"); XmProcessTraversal(ucd->nameTextW, XmTRAVERSE_CURRENT); } XtFree(nameText); return NULL; } cmdText = XmTextGetString(ucd->cmdTextW); if (cmdText == NULL || *cmdText == '\0') { if (!silent) { DialogF(DF_WARN, ucd->dlogShell, 1, "Command to Execute", "Please specify %s to execute", "Dismiss", ucd->dialogType == SHELL_CMDS ? "shell command" : "macro command(s)"); XmProcessTraversal(ucd->cmdTextW, XmTRAVERSE_CURRENT); } XtFree(nameText); if (cmdText!=NULL) { XtFree(cmdText); } return NULL; } if (ucd->dialogType == MACRO_CMDS || ucd->dialogType == BG_MENU_CMDS) { addTerminatingNewline(&cmdText); if (!checkMacroText(cmdText, silent ? NULL : ucd->dlogShell, ucd->cmdTextW)) { XtFree(nameText); XtFree(cmdText); return NULL; } } f = (menuItemRec *)XtMalloc(sizeof(menuItemRec)); f->name = nameText; f->cmd = cmdText; if ((mneText = XmTextGetString(ucd->mneTextW)) != NULL) { f->mnemonic = mneText==NULL ? '\0' : mneText[0]; XtFree(mneText); if (f->mnemonic == ':') /* colons mess up string parsing */ f->mnemonic = '\0'; } if ((accText = XmTextGetString(ucd->accTextW)) != NULL) { parseAcceleratorString(accText, &f->modifiers, &f->keysym); XtFree(accText); } if (ucd->dialogType == SHELL_CMDS) { if (XmToggleButtonGetState(ucd->selInpBtn)) f->input = FROM_SELECTION; else if (XmToggleButtonGetState(ucd->winInpBtn)) f->input = FROM_WINDOW; else if (XmToggleButtonGetState(ucd->eitherInpBtn)) f->input = FROM_EITHER; else f->input = FROM_NONE; if (XmToggleButtonGetState(ucd->winOutBtn)) f->output = TO_NEW_WINDOW
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -