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

📄 smartindent.c

📁 nedit 是一款linux下的开发源码的功能强大的编辑器
💻 C
📖 第 1 页 / 共 5 页
字号:
	    XmTextSetString(SmartIndentDialog.initMacro, is->initMacro);	XmTextSetString(SmartIndentDialog.newlineMacro, is->newlineMacro);	if (is->modMacro == NULL)	    XmTextSetString(SmartIndentDialog.modMacro, "");	else	    XmTextSetString(SmartIndentDialog.modMacro, is->modMacro);    }}void EditCommonSmartIndentMacro(void){#define VERT_BORDER 4    Widget form, topLbl;    Widget okBtn, applyBtn, checkBtn;    Widget dismissBtn, restoreBtn;    XmString s1;    Arg args[20];    int n;    /* if the dialog is already displayed, just pop it to the top and return */    if (CommonDialog.shell != NULL) {    	RaiseShellWindow(CommonDialog.shell);    	return;    }    /* Create a form widget in an application shell */    n = 0;    XtSetArg(args[n], XmNdeleteResponse, XmDO_NOTHING); n++;    XtSetArg(args[n], XmNiconName, "NEdit Common Smart Indent Macros"); n++;    XtSetArg(args[n], XmNtitle, "Common Smart Indent Macros"); n++;    CommonDialog.shell = CreateShellWithBestVis(APP_NAME, APP_CLASS,	    applicationShellWidgetClass, TheDisplay, args, n);    AddSmallIcon(CommonDialog.shell);    form = XtVaCreateManagedWidget("editCommonSIMacros", xmFormWidgetClass,	    CommonDialog.shell, XmNautoUnmanage, False,	    XmNresizePolicy, XmRESIZE_NONE, NULL);    XtAddCallback(form, XmNdestroyCallback, comDestroyCB, NULL);    AddMotifCloseCallback(CommonDialog.shell, comDismissCB, NULL);        topLbl = XtVaCreateManagedWidget("topLbl", xmLabelGadgetClass, form,    	    XmNlabelString, s1=XmStringCreateSimple(	        "Common Definitions for Smart Indent Macros"),    	    XmNmnemonic, 'C',	    XmNtopAttachment, XmATTACH_FORM,	    XmNtopOffset, VERT_BORDER,	    XmNleftAttachment, XmATTACH_POSITION,	    XmNleftPosition, 1, NULL);    okBtn = XtVaCreateManagedWidget("ok", xmPushButtonWidgetClass, form,    	    XmNlabelString, s1=XmStringCreateSimple("OK"),    	    XmNleftAttachment, XmATTACH_POSITION,    	    XmNleftPosition, 6,    	    XmNrightAttachment, XmATTACH_POSITION,    	    XmNrightPosition, 18,    	    XmNbottomAttachment, XmATTACH_FORM,    	    XmNbottomOffset, VERT_BORDER, NULL);    XtAddCallback(okBtn, XmNactivateCallback, comOKCB, NULL);    XmStringFree(s1);        applyBtn = XtVaCreateManagedWidget("apply", xmPushButtonWidgetClass, form,    	    XmNlabelString, s1=XmStringCreateSimple("Apply"),    	    XmNmnemonic, 'y',    	    XmNleftAttachment, XmATTACH_POSITION,    	    XmNleftPosition, 22,    	    XmNrightAttachment, XmATTACH_POSITION,    	    XmNrightPosition, 35,    	    XmNbottomAttachment, XmATTACH_FORM,    	    XmNbottomOffset, VERT_BORDER, NULL);    XtAddCallback(applyBtn, XmNactivateCallback, comApplyCB, NULL);    XmStringFree(s1);        checkBtn = XtVaCreateManagedWidget("check", xmPushButtonWidgetClass, form,    	    XmNlabelString, s1=XmStringCreateSimple("Check"),    	    XmNmnemonic, 'k',    	    XmNleftAttachment, XmATTACH_POSITION,    	    XmNleftPosition, 39,    	    XmNrightAttachment, XmATTACH_POSITION,    	    XmNrightPosition, 52,    	    XmNbottomAttachment, XmATTACH_FORM,    	    XmNbottomOffset, VERT_BORDER, NULL);    XtAddCallback(checkBtn, XmNactivateCallback, comCheckCB, NULL);    XmStringFree(s1);        restoreBtn = XtVaCreateManagedWidget("restore", xmPushButtonWidgetClass,    form,    	    XmNlabelString, s1=XmStringCreateSimple("Restore Default"),    	    XmNmnemonic, 'f',    	    XmNleftAttachment, XmATTACH_POSITION,    	    XmNleftPosition, 56,    	    XmNrightAttachment, XmATTACH_POSITION,    	    XmNrightPosition, 77,    	    XmNbottomAttachment, XmATTACH_FORM,    	    XmNbottomOffset, VERT_BORDER, NULL);    XtAddCallback(restoreBtn, XmNactivateCallback, comRestoreCB, NULL);    XmStringFree(s1);        dismissBtn = XtVaCreateManagedWidget("dismiss", xmPushButtonWidgetClass,    	    form,    	    XmNlabelString, s1=XmStringCreateSimple("Dismiss"),    	    XmNleftAttachment, XmATTACH_POSITION,    	    XmNleftPosition, 81,    	    XmNrightAttachment, XmATTACH_POSITION,    	    XmNrightPosition, 94,    	    XmNbottomAttachment, XmATTACH_FORM,    	    XmNbottomOffset, VERT_BORDER, NULL);    XtAddCallback(dismissBtn, XmNactivateCallback, comDismissCB, NULL);    XmStringFree(s1);        n = 0;    XtSetArg(args[n], XmNeditMode, XmMULTI_LINE_EDIT); n++;    XtSetArg(args[n], XmNrows, 24); n++;    XtSetArg(args[n], XmNcolumns, 80); n++;    XtSetArg(args[n], XmNvalue, CommonMacros); n++;    XtSetArg(args[n], XmNtopAttachment, XmATTACH_WIDGET); n++;    XtSetArg(args[n], XmNtopWidget, topLbl); n++;    XtSetArg(args[n], XmNleftAttachment, XmATTACH_POSITION); n++;    XtSetArg(args[n], XmNleftPosition, 1); n++;    XtSetArg(args[n], XmNrightAttachment, XmATTACH_POSITION); n++;    XtSetArg(args[n], XmNrightPosition, 99); n++;    XtSetArg(args[n], XmNbottomAttachment, XmATTACH_WIDGET); n++;    XtSetArg(args[n], XmNbottomWidget, okBtn); n++;    XtSetArg(args[n], XmNbottomOffset, VERT_BORDER); n++;    CommonDialog.text = XmCreateScrolledText(form, "commonText", args, n);    AddMouseWheelSupport(CommonDialog.text);    XtManageChild(CommonDialog.text);    RemapDeleteKey(CommonDialog.text);    XtVaSetValues(topLbl, XmNuserData, CommonDialog.text, NULL);    /* Set initial default button */    XtVaSetValues(form, XmNdefaultButton, okBtn, NULL);    XtVaSetValues(form, XmNcancelButton, dismissBtn, NULL);        /* Handle mnemonic selection of buttons and focus to dialog */    AddDialogMnemonicHandler(form, FALSE);        /* Realize all of the widgets in the new dialog */    RealizeWithoutForcingPosition(CommonDialog.shell);}static void comDestroyCB(Widget w, XtPointer clientData, XtPointer callData){    CommonDialog.shell = NULL;}static void comOKCB(Widget w, XtPointer clientData, XtPointer callData){    /* change the macro */    if (!updateSmartIndentCommonData())    	return;        /* pop down and destroy the dialog */    XtDestroyWidget(CommonDialog.shell);}static void comApplyCB(Widget w, XtPointer clientData, XtPointer callData){    /* change the macro */    updateSmartIndentCommonData();}static void comCheckCB(Widget w, XtPointer clientData, XtPointer callData){    if (checkSmartIndentCommonDialogData())    {        DialogF(DF_INF, CommonDialog.shell, 1, "Macro compiled",                "Macros compiled without error", "Dismiss");    }}static void comRestoreCB(Widget w, XtPointer clientData, XtPointer callData){    if (DialogF(DF_WARN, CommonDialog.shell, 2, "Discard Changes",            "Are you sure you want to discard all\n"            "changes to common smart indent macros", "Discard", "Cancel") == 2)    {        return;    }        /* replace common macros with default */    if (CommonMacros != NULL)    	XtFree(CommonMacros);    CommonMacros = XtNewString(DefaultCommonMacros);       /* Update the dialog */    XmTextSetString(CommonDialog.text, CommonMacros);}static void comDismissCB(Widget w, XtPointer clientData, XtPointer callData){    /* pop down and destroy the dialog */    XtDestroyWidget(CommonDialog.shell);}/*** Update the smart indent macros being edited in the dialog** with the information that the dialog is currently displaying, and** apply changes to any window which is currently using the macros.*/static int updateSmartIndentCommonData(void){    WindowInfo *window;    	    /* Make sure the patterns are valid and compile */    if (!checkSmartIndentCommonDialogData())    	return False;        /* Get the current data */    CommonMacros = ensureNewline(XmTextGetString(CommonDialog.text));        /* Re-execute initialization macros (macros require a window to function,       since user could theoretically execute an action routine, but it       probably won't be referenced in a smart indent initialization) */    if (!ReadMacroString(WindowList, CommonMacros, "common macros"))    	return False;    /* Find windows that are currently using smart indent and       re-initialize the smart indent macros (in case they have initialization       data which depends on common data) */    for (window=WindowList; window!=NULL; window=window->next) {    	if (window->indentStyle == SMART_INDENT &&    		window->languageMode != PLAIN_LANGUAGE_MODE) {    	    EndSmartIndent(window);    	    BeginSmartIndent(window, False);    	}    }        /* Note that preferences have been changed */    MarkPrefsChanged();    return True;}static int checkSmartIndentCommonDialogData(void){    char *widgetText, *stoppedAt;        if (!TextWidgetIsBlank(CommonDialog.text)) {	widgetText = ensureNewline(XmTextGetString(CommonDialog.text));	if (!CheckMacroString(CommonDialog.shell, widgetText,		"macros", &stoppedAt)) {    	    XmTextSetInsertionPosition(CommonDialog.text, stoppedAt-widgetText);	    XmProcessTraversal(CommonDialog.text, XmTRAVERSE_CURRENT);	    XtFree(widgetText);	    return False;	}	XtFree(widgetText);    }    return True;}/*** Update the smart indent macros being edited in the dialog** with the information that the dialog is currently displaying, and** apply changes to any window which is currently using the macros.*/static int updateSmartIndentData(void){    smartIndentRec *newMacros;    WindowInfo *window;    char *lmName;    int i;    	    /* Make sure the patterns are valid and compile */    if (!checkSmartIndentDialogData())    	return False;        /* Get the current data */    newMacros = getSmartIndentDialogData();        /* Find the original macros */    for (i=0; i<NSmartIndentSpecs; i++)    	if (!strcmp(SmartIndentDialog.langModeName,SmartIndentSpecs[i]->lmName))	    break;        /* If it's a new language, add it at the end, otherwise free the       existing macros and replace it */    if (i == NSmartIndentSpecs) {    	SmartIndentSpecs[NSmartIndentSpecs++] = newMacros;    } else {	freeIndentSpec(SmartIndentSpecs[i]);	SmartIndentSpecs[i] = newMacros;    }        /* Find windows that are currently using this indent specification and       re-do the smart indent macros */    for (window=WindowList; window!=NULL; window=window->next) {    	lmName = LanguageModeName(window->languageMode);	if (lmName != NULL && !strcmp(lmName, newMacros->lmName)) {	    XtSetSensitive(window->smartIndentItem, True);    	    if (window->indentStyle == SMART_INDENT &&    		    window->languageMode != PLAIN_LANGUAGE_MODE) {    	    	EndSmartIndent(window);    	    	BeginSmartIndent(window, False);    	    }    	}    }        /* Note that preferences have been changed */    MarkPrefsChanged();    return True;}static int loadDefaultIndentSpec(char *lmName){    int i;        for (i=0; i<N_DEFAULT_INDENT_SPECS; i++) {    	if (!strcmp(lmName, DefaultIndentSpecs[i].lmName)) {    	    SmartIndentSpecs[NSmartIndentSpecs++] =		    copyIndentSpec(&DefaultIndentSpecs[i]);    	    return True;    	}    }    return False;}int LoadSmartIndentString(char *inString){   char *errMsg, *inPtr = inString;   smartIndentRec is, *isCopy;   int i;   for (;;) {   		/* skip over blank space */	inPtr += strspn(inPtr, " \t\n");		/* finished */	if (*inPtr == '\0')	    return True;	/* read language mode name */	is.lmName = ReadSymbolicField(&inPtr);	if (is.lmName == NULL)    	    return siParseError(inString, inPtr, "language mode name required");	if (!SkipDelimiter(&inPtr, &errMsg)) {    	    XtFree(is.lmName);    	    return siParseError(inString, inPtr, errMsg);    	}    		/* look for "Default" keyword, and if it's there, return the default	   smart indent macros */	if (!strncmp(inPtr, "Default", 7)) {    	    inPtr += 7;    	    if (!loadDefaultIndentSpec(is.lmName)) {    		XtFree(is.lmName);    		return siParseError(inString, inPtr,    	    		"no default smart indent macros");    	    }    	    XtFree(is.lmName);    	    continue;	}	/* read the initialization macro (arbitrary text terminated by the	   macro end boundary string) */	is.initMacro = readSIMacro(&inPtr);	if (is.initMacro == NULL) {    	    XtFree(is.lmName);    	    return siParseError(inString, inPtr,    	    	    "no end boundary to initialization macro");	}		/* read the newline macro */	is.newlineMacro = readSIMacro(&inPtr);	if (is.newlineMacro == NULL) {    	    XtFree(is.lmName);    	    XtFree(is.initMacro);   

⌨️ 快捷键说明

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