⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usercmds.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
static const char CVSID[] = "$Id: userCmds.c,v 1.32 2003/05/02 19:19:02 edg Exp $";/********************************************************************************									       ** userCmds.c -- Nirvana Editor shell and macro command dialogs 		       **									       ** Copyright (C) 1999 Mark Edel						       **									       ** This is free software; you can redistribute it and/or modify it under the    ** terms of the GNU General Public License as published by the Free Software    ** Foundation; either version 2 of the License, or (at your option) any later   ** version.							               ** 									       ** This software is distributed in the hope that it will be useful, but WITHOUT ** ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or        ** FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License        ** for more details.							       ** 									       ** You should have received a copy of the GNU General Public License along with ** software; if not, write to the Free Software Foundation, Inc., 59 Temple     ** Place, Suite 330, Boston, MA  02111-1307 USA		                       **									       ** Nirvana Text Editor	    						       ** April, 1997								       **									       ** Written by Mark Edel							       **									       ********************************************************************************/#ifdef HAVE_CONFIG_H#include "../config.h"#endif#include "userCmds.h"#include "textBuf.h"#include "text.h"#include "nedit.h"#include "preferences.h"#include "window.h"#include "menu.h"#include "shell.h"#include "macro.h"#include "file.h"#include "interpret.h"#include "parse.h"#include "../util/DialogF.h"#include "../util/misc.h"#include "../util/managedList.h"#include <stdio.h>#include <stdlib.h>#include <string.h>#include <ctype.h>#ifdef VMS#include "../util/VMSparam.h"#else#ifndef __MVS__#include <sys/param.h>#endif#endif /*VMS*/#include <Xm/Xm.h>#include <X11/keysym.h>#include <Xm/Text.h>#include <Xm/Form.h>#include <Xm/List.h>#include <Xm/LabelG.h>#include <Xm/PushB.h>#include <Xm/ToggleB.h>#include <Xm/SelectioB.h>#include <Xm/RowColumn.h>#include <Xm/CascadeB.h>#ifdef HAVE_DEBUG_H#include "../debug.h"#endif/* max number of user programmable menu commands allowed per each of the   macro, shell, and bacground menus */#define MAX_ITEMS_PER_MENU 400/* major divisions (in position units) in User Commands dialogs */#define LEFT_MARGIN_POS 1#define RIGHT_MARGIN_POS 99#define LIST_RIGHT 45#define SHELL_CMD_TOP 70#define MACRO_CMD_TOP 40/* types of current dialog and/or menu */enum dialogTypes {SHELL_CMDS, MACRO_CMDS, BG_MENU_CMDS};/* Structure representing a menu item for both the shell and macro menus */typedef struct {    char *name;    unsigned int modifiers;    KeySym keysym;    char mnemonic;    char input;    char output;    char repInput;    char saveFirst;    char loadAfter;    char *cmd;} menuItemRec;/* Structure for widgets and flags associated with both shell command   and macro command editing dialogs */typedef struct {    int dialogType;    WindowInfo *window;    Widget nameTextW, accTextW, mneTextW, cmdTextW, saveFirstBtn;    Widget loadAfterBtn, selInpBtn, winInpBtn, eitherInpBtn, noInpBtn;    Widget repInpBtn, sameOutBtn, dlogOutBtn, winOutBtn, dlogShell;    Widget managedList;    menuItemRec **menuItemsList;    int nMenuItems;} userCmdDialog;/* Structure for keeping track of hierarchical sub-menus durring user-menu   creation */typedef struct {    char *name;    Widget menuPane;} menuTreeItem;/* Descriptions of the current user programmed menu items for re-generating   menus and processing shell, macro, and background menu selections */static menuItemRec *ShellMenuItems[MAX_ITEMS_PER_MENU];static int NShellMenuItems = 0;static menuItemRec *MacroMenuItems[MAX_ITEMS_PER_MENU];static int NMacroMenuItems = 0;static menuItemRec *BGMenuItems[MAX_ITEMS_PER_MENU];static int NBGMenuItems = 0;/* Top level shells of the user-defined menu editing dialogs */static Widget ShellCmdDialog = NULL;static Widget MacroCmdDialog = NULL;static Widget BGMenuCmdDialog = NULL;/* Paste learn/replay sequence buttons in user defined menu editing dialogs   (for dimming and undimming externally when replay macro is available) */static Widget MacroPasteReplayBtn = NULL;static Widget BGMenuPasteReplayBtn = NULL;static void editMacroOrBGMenu(WindowInfo *window, int dialogType);static void dimSelDepItemsInMenu(Widget menuPane, menuItemRec **menuList,	int nMenuItems, int sensitive);static void updateMenus(int menuType);static Widget findInMenuTree(menuTreeItem *menuTree, int nTreeEntries,                             const char *hierName);static char *copySubstring(const char *string, int length);static char *findStripLanguageMode(const char *menuItemName, int languageMode,	int *isDefaultLM);static Widget createUserMenuItem(Widget menuPane, char *name, menuItemRec *f,	int index, XtCallbackProc cbRtn, XtPointer cbArg);static Widget createUserSubMenu(Widget parent, char *label);static void removeMenuItems(Widget menuPane);static void updateMenu(WindowInfo *window, int menuType);static void okCB(Widget w, XtPointer clientData, XtPointer callData);static void applyCB(Widget w, XtPointer clientData, XtPointer callData);static void checkCB(Widget w, XtPointer clientData, XtPointer callData);static int checkMacro(userCmdDialog *ucd);static int checkMacroText(char *macro, Widget errorParent, Widget errFocus);static int applyDialogChanges(userCmdDialog *ucd);static void dismissCB(Widget w, XtPointer clientData, XtPointer callData);static void pasteReplayCB(Widget w, XtPointer clientData, XtPointer callData);static void destroyCB(Widget w, XtPointer clientData, XtPointer callData);static void accKeyCB(Widget w, XtPointer clientData, XKeyEvent *event);static void sameOutCB(Widget w, XtPointer clientData, XtPointer callData);static void shellMenuCB(Widget w, WindowInfo *window, XtPointer callData);static void macroMenuCB(Widget w, WindowInfo *window, XtPointer callData);static void bgMenuCB(Widget w, WindowInfo *window, XtPointer callData) ;static void accFocusCB(Widget w, XtPointer clientData, XtPointer callData);static void accLoseFocusCB(Widget w, XtPointer clientData,	XtPointer callData);static void updateDialogFields(menuItemRec *f, userCmdDialog *ucd);static menuItemRec *readDialogFields(userCmdDialog *ucd, int silent);static menuItemRec *copyMenuItemRec(menuItemRec *item);static void freeMenuItemRec(menuItemRec *item);static void *getDialogDataCB(void *oldItem, int explicitRequest, int *abort,    	void *cbArg);static void setDialogDataCB(void *item, void *cbArg);static void freeItemCB(void *item);static int dialogFieldsAreEmpty(userCmdDialog *ucd);static void disableTextW(Widget textW);static char *writeMenuItemString(menuItemRec **menuItems, int nItems,	int listType);static int loadMenuItemString(char *inString, menuItemRec **menuItems,	int *nItems, int listType);static void generateAcceleratorString(char *text, unsigned int modifiers,	KeySym keysym);static void genAccelEventName(char *text, unsigned int modifiers,	KeySym keysym);static int parseAcceleratorString(const char *string, unsigned int *modifiers,	KeySym *keysym);static int parseError(const char *message);static char *copyMacroToEnd(char **inPtr);static void addTerminatingNewline(char **string);/*** Present a dialog for editing the user specified commands in the shell menu*/void EditShellMenu(WindowInfo *window){    Widget form, accLabel, inpLabel, inpBox, outBox, outLabel;    Widget nameLabel, cmdLabel, okBtn, applyBtn, dismissBtn;    userCmdDialog *ucd;    XmString s1;    int ac, i;    Arg args[20];    /* if the dialog is already displayed, just pop it to the top and return */    if (ShellCmdDialog != NULL) {    	RaiseShellWindow(ShellCmdDialog);    	return;    }    /* Create a structure for keeping track of dialog state */    ucd = (userCmdDialog *)XtMalloc(sizeof(userCmdDialog));    ucd->window = window;        /* Set the dialog to operate on the Shell menu */    ucd->menuItemsList = (menuItemRec **)XtMalloc(sizeof(menuItemRec *) *    	    MAX_ITEMS_PER_MENU);    for (i=0; i<NShellMenuItems; i++)    	ucd->menuItemsList[i] = copyMenuItemRec(ShellMenuItems[i]);    ucd->nMenuItems = NShellMenuItems;    ucd->dialogType = SHELL_CMDS;        ac = 0;    XtSetArg(args[ac], XmNdeleteResponse, XmDO_NOTHING); ac++;    XtSetArg(args[ac], XmNiconName, "NEdit Shell Menu"); ac++;    XtSetArg(args[ac], XmNtitle, "Shell Menu"); ac++;    ucd->dlogShell = CreateShellWithBestVis(APP_NAME, APP_CLASS,	    applicationShellWidgetClass, TheDisplay, args, ac);    AddSmallIcon(ucd->dlogShell);    form = XtVaCreateManagedWidget("editShellCommands", xmFormWidgetClass,	    ucd->dlogShell, XmNautoUnmanage, False,	    XmNresizePolicy, XmRESIZE_NONE, NULL);    ShellCmdDialog = ucd->dlogShell;    XtAddCallback(form, XmNdestroyCallback, destroyCB, ucd);    AddMotifCloseCallback(ucd->dlogShell, dismissCB, ucd);     ac = 0;    XtSetArg(args[ac], XmNtopAttachment, XmATTACH_POSITION); ac++;    XtSetArg(args[ac], XmNtopPosition, 2); ac++;    XtSetArg(args[ac], XmNleftAttachment, XmATTACH_POSITION); ac++;    XtSetArg(args[ac], XmNleftPosition, LEFT_MARGIN_POS); ac++;    XtSetArg(args[ac], XmNrightAttachment, XmATTACH_POSITION); ac++;    XtSetArg(args[ac], XmNrightPosition, LIST_RIGHT-1); ac++;    XtSetArg(args[ac], XmNbottomAttachment, XmATTACH_POSITION); ac++;    XtSetArg(args[ac], XmNbottomPosition, SHELL_CMD_TOP); ac++;    ucd->managedList = CreateManagedList(form, "list", args, ac,    	    (void **)ucd->menuItemsList, &ucd->nMenuItems, MAX_ITEMS_PER_MENU,    	    20, getDialogDataCB, ucd, setDialogDataCB, ucd, freeItemCB);    ucd->loadAfterBtn = XtVaCreateManagedWidget("loadAfterBtn",    	    xmToggleButtonWidgetClass, form,    	    XmNlabelString, s1=MKSTRING("Re-load file after executing command"),    	    XmNmnemonic, 'R',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNset, False,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_POSITION,	    XmNbottomPosition, SHELL_CMD_TOP, NULL);    XmStringFree(s1);    ucd->saveFirstBtn = XtVaCreateManagedWidget("saveFirstBtn",    	    xmToggleButtonWidgetClass, form,    	    XmNlabelString, s1=MKSTRING("Save file before executing command"),    	    XmNmnemonic, 'f',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNset, False,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_WIDGET,	    XmNbottomWidget, ucd->loadAfterBtn, NULL);    XmStringFree(s1);    ucd->repInpBtn = XtVaCreateManagedWidget("repInpBtn",    	    xmToggleButtonWidgetClass, form,    	    XmNlabelString, s1=MKSTRING("Output replaces input"),    	    XmNmnemonic, 'f',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNset, False,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_WIDGET,	    XmNbottomWidget, ucd->saveFirstBtn, NULL);    XmStringFree(s1);    outBox = XtVaCreateManagedWidget("outBox", xmRowColumnWidgetClass, form,	    XmNpacking, XmPACK_TIGHT,	    XmNorientation, XmHORIZONTAL,	    XmNradioBehavior, True,	    XmNradioAlwaysOne, True,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT + 2,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_WIDGET,	    XmNbottomWidget, ucd->repInpBtn,	    XmNbottomOffset, 4, NULL);    ucd->sameOutBtn = XtVaCreateManagedWidget("sameOutBtn",    	    xmToggleButtonWidgetClass, outBox,    	    XmNlabelString, s1=MKSTRING("same window"),    	    XmNmnemonic, 'm',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNmarginHeight, 0,    	    XmNset, True, NULL);    XmStringFree(s1);    XtAddCallback(ucd->sameOutBtn, XmNvalueChangedCallback, sameOutCB, ucd);    ucd->dlogOutBtn = XtVaCreateManagedWidget("dlogOutBtn",    	    xmToggleButtonWidgetClass, outBox,    	    XmNlabelString, s1=MKSTRING("dialog"),    	    XmNmnemonic, 'g',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNmarginHeight, 0,    	    XmNset, False, NULL);    XmStringFree(s1);    ucd->winOutBtn = XtVaCreateManagedWidget("winOutBtn", xmToggleButtonWidgetClass,    	    outBox,    	    XmNlabelString, s1=MKSTRING("new window"),    	    XmNmnemonic, 'n',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNmarginHeight, 0,    	    XmNset, False, NULL);    XmStringFree(s1);    outLabel = XtVaCreateManagedWidget("outLabel", xmLabelGadgetClass, form,    	    XmNlabelString, s1=MKSTRING("Command Output:"),    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNmarginTop, 5,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_WIDGET,	    XmNbottomWidget, outBox, NULL);    XmStringFree(s1);    inpBox = XtVaCreateManagedWidget("inpBox", xmRowColumnWidgetClass, form,	    XmNpacking, XmPACK_TIGHT,	    XmNorientation, XmHORIZONTAL,	    XmNradioBehavior, True,	    XmNradioAlwaysOne, True,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, LIST_RIGHT + 2,	    XmNrightAttachment, XmATTACH_POSITION,	    XmNrightPosition, RIGHT_MARGIN_POS,	    XmNbottomAttachment, XmATTACH_WIDGET,	    XmNbottomWidget, outLabel, NULL);    ucd->selInpBtn = XtVaCreateManagedWidget("selInpBtn", xmToggleButtonWidgetClass,    	    inpBox,    	    XmNlabelString, s1=MKSTRING("selection"),    	    XmNmnemonic, 's',    	    XmNalignment, XmALIGNMENT_BEGINNING,    	    XmNmarginHeight, 0,    	    XmNset, True, NULL);    XmStringFree(s1);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -