Minor fix.
[nedit.git] / source / menu.c
blobeff35a549b5cd50e763065fc6efc2716649b9547
1 static const char CVSID[] = "$Id: menu.c,v 1.128 2005/05/27 16:49:04 edg Exp $";
2 /*******************************************************************************
3 * *
4 * menu.c -- Nirvana Editor menus *
5 * *
6 * Copyright (C) 1999 Mark Edel *
7 * *
8 * This is free software; you can redistribute it and/or modify it under the *
9 * terms of the GNU General Public License as published by the Free Software *
10 * Foundation; either version 2 of the License, or (at your option) any later *
11 * version. In addition, you may distribute versions of this program linked to *
12 * Motif or Open Motif. See README for details. *
13 * *
14 * This software is distributed in the hope that it will be useful, but WITHOUT *
15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
16 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
17 * for more details. *
18 * *
19 * You should have received a copy of the GNU General Public License along with *
20 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
21 * Place, Suite 330, Boston, MA 02111-1307 USA *
22 * *
23 * Nirvana Text Editor *
24 * May 10, 1991 *
25 * *
26 * Written by Mark Edel *
27 * *
28 *******************************************************************************/
30 #ifdef HAVE_CONFIG_H
31 #include "../config.h"
32 #endif
34 #include "menu.h"
35 #include "textBuf.h"
36 #include "text.h"
37 #include "nedit.h"
38 #include "file.h"
39 #include "window.h"
40 #include "search.h"
41 #include "selection.h"
42 #include "undo.h"
43 #include "shift.h"
44 #include "help.h"
45 #include "preferences.h"
46 #include "tags.h"
47 #include "userCmds.h"
48 #include "shell.h"
49 #include "macro.h"
50 #include "highlight.h"
51 #include "highlightData.h"
52 #include "interpret.h"
53 #include "smartIndent.h"
54 #include "windowTitle.h"
55 #include "../util/getfiles.h"
56 #include "../util/DialogF.h"
57 #include "../util/misc.h"
58 #include "../util/fileUtils.h"
59 #include "../util/utils.h"
60 #include "../Xlt/BubbleButton.h"
62 #include <stdlib.h>
63 #include <stdio.h>
64 #include <string.h>
65 #include <ctype.h>
66 #include <unistd.h>
67 #include <sys/types.h>
68 #ifdef VMS
69 #include "../util/VMSparam.h"
70 #else
71 #ifndef __MVS__
72 #include <sys/param.h>
73 #endif
74 #endif /*VMS*/
75 #include <X11/X.h>
76 #include <Xm/Xm.h>
77 #include <Xm/CascadeB.h>
78 #include <Xm/PushB.h>
79 #include <Xm/ToggleB.h>
80 #include <Xm/Separator.h>
81 #include <Xm/RowColumn.h>
82 #include <Xm/MenuShell.h>
84 #ifdef HAVE_DEBUG_H
85 #include "../debug.h"
86 #endif
88 #if XmVersion >= 1002
89 #define MENU_WIDGET(w) (XmGetPostedFromWidget(XtParent(w)))
90 #else
91 #define MENU_WIDGET(w) (w)
92 #endif
94 /* Menu modes for SGI_CUSTOM short-menus feature */
95 enum menuModes {FULL, SHORT};
97 typedef void (*menuCallbackProc)();
99 extern void _XmDismissTearOff(Widget, XtPointer, XtPointer);
101 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData);
102 static void doTabActionCB(Widget w, XtPointer clientData, XtPointer callData);
103 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData);
104 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData);
105 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData);
106 static void findCB(Widget w, XtPointer clientData, XtPointer callData);
107 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData);
108 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData);
109 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData);
110 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData);
111 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData);
112 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData);
113 static void markCB(Widget w, XtPointer clientData, XtPointer callData);
114 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData);
115 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData);
116 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData);
117 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData);
118 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData);
119 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData);
120 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData);
121 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData);
122 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData);
123 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData);
124 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData);
125 static void fontCB(Widget w, WindowInfo *window, caddr_t callData);
126 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
127 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData);
128 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
129 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
130 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
131 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
132 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
133 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
134 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
135 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
136 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
137 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData);
138 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
139 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
140 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
141 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData);
142 static void openInTabDefCB(Widget w, WindowInfo *window, caddr_t callData);
143 static void tabBarDefCB(Widget w, WindowInfo *window, caddr_t callData);
144 static void tabBarHideDefCB(Widget w, WindowInfo *window, caddr_t callData);
145 static void tabSortDefCB(Widget w, WindowInfo *window, caddr_t callData);
146 static void toolTipsDefCB(Widget w, WindowInfo *window, caddr_t callData);
147 static void tabNavigateDefCB(Widget w, WindowInfo *window, caddr_t callData);
148 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
149 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
150 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData);
151 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
152 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
153 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
154 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
155 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
156 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
157 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
158 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
159 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
160 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData);
161 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
162 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData);
163 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
164 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
165 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData);
166 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData);
167 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData);
168 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData);
169 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData);
170 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData);
171 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
172 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
173 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
174 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window,
175 caddr_t callData);
176 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData);
177 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData);
178 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData);
179 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
180 static void autoScrollDefCB(Widget w, WindowInfo *window, caddr_t callData);
181 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
182 static void modWarnRealDefCB(Widget w, WindowInfo *window, caddr_t callData);
183 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
184 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData);
185 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData);
186 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData);
187 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData);
188 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData);
189 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData);
190 #ifdef REPLACE_SCOPE
191 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData);
192 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData);
193 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData);
194 #endif
195 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData);
196 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData);
197 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData);
198 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData);
199 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData);
200 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData);
201 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData);
202 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData);
203 static void learnCB(Widget w, WindowInfo *window, caddr_t callData);
204 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData);
205 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData);
206 static void replayCB(Widget w, WindowInfo *window, caddr_t callData);
207 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData);
208 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData);
209 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window,
210 caddr_t callData);
211 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window,
212 caddr_t callData);
213 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
214 static void newOppositeAP(Widget w, XEvent *event, String *args,
215 Cardinal *nArgs);
216 static void newTabAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
217 static void openDialogAP(Widget w, XEvent *event, String *args,
218 Cardinal *nArgs);
219 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
220 static void openSelectedAP(Widget w, XEvent *event, String *args,
221 Cardinal *nArgs);
222 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
223 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
224 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
225 Cardinal *nArgs);
226 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
227 static void revertDialogAP(Widget w, XEvent *event, String *args,
228 Cardinal *nArgs);
229 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
230 static void includeDialogAP(Widget w, XEvent *event, String *args,
231 Cardinal *nArgs);
232 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
233 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
234 Cardinal *nArgs) ;
235 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
236 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
237 Cardinal *nArgs);
238 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
239 static void unloadTagsAP(Widget w, XEvent *event, String *args,
240 Cardinal *nArgs);
241 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
242 Cardinal *nArgs);
243 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
244 static void unloadTipsAP(Widget w, XEvent *event, String *args,
245 Cardinal *nArgs);
246 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
247 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
248 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
249 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
250 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
251 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
252 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
253 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
254 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
255 Cardinal *nArgs);
256 static void shiftRightAP(Widget w, XEvent *event, String *args,
257 Cardinal *nArgs);
258 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
259 Cardinal *nArgs);
260 static void findDialogAP(Widget w, XEvent *event, String *args,
261 Cardinal *nArgs);
262 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
263 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
264 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
265 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
266 static void startIncrFindAP(Widget w, XEvent *event, String *args,
267 Cardinal *nArgs);
268 static void replaceDialogAP(Widget w, XEvent *event, String *args,
269 Cardinal *nArgs);
270 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
271 static void replaceAllAP(Widget w, XEvent *event, String *args,
272 Cardinal *nArgs);
273 static void replaceInSelAP(Widget w, XEvent *event, String *args,
274 Cardinal *nArgs);
275 static void replaceSameAP(Widget w, XEvent *event, String *args,
276 Cardinal *nArgs);
277 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
278 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
279 Cardinal *nArgs);
280 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
281 static void gotoDialogAP(Widget w, XEvent *event, String *args,
282 Cardinal *nArgs);
283 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
284 Cardinal *nArgs);
285 static void repeatDialogAP(Widget w, XEvent *event, String *args,
286 Cardinal *nArgs);
287 static void repeatMacroAP(Widget w, XEvent *event, String *args,
288 Cardinal *nArgs);
289 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
290 static void markDialogAP(Widget w, XEvent *event, String *args,
291 Cardinal *nArgs);
292 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
293 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
294 Cardinal *nArgs);
295 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
296 Cardinal *nArgs);
297 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
298 Cardinal *nArgs);
299 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
300 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
301 static void splitPaneAP(Widget w, XEvent *event, String *args,
302 Cardinal *nArgs);
303 static void detachDocumentDialogAP(Widget w, XEvent *event, String *args,
304 Cardinal *nArgs);
305 static void detachDocumentAP(Widget w, XEvent *event, String *args,
306 Cardinal *nArgs);
307 static void moveDocumentDialogAP(Widget w, XEvent *event, String *args,
308 Cardinal *nArgs);
309 static void nextDocumentAP(Widget w, XEvent *event, String *args,
310 Cardinal *nArgs);
311 static void prevDocumentAP(Widget w, XEvent *event, String *args,
312 Cardinal *nArgs);
313 static void lastDocumentAP(Widget w, XEvent *event, String *args,
314 Cardinal *nArgs);
315 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
316 static void capitalizeAP(Widget w, XEvent *event, String *args,
317 Cardinal *nArgs);
318 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
319 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
320 static void controlDialogAP(Widget w, XEvent *event, String *args,
321 Cardinal *nArgs);
322 #ifndef VMS
323 static void filterDialogAP(Widget w, XEvent *event, String *args,
324 Cardinal *nArgs);
325 static void shellFilterAP(Widget w, XEvent *event, String *args,
326 Cardinal *nArgs);
327 static void execDialogAP(Widget w, XEvent *event, String *args,
328 Cardinal *nArgs);
329 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
330 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
331 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
332 #endif
333 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
334 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
335 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
336 Cardinal *nArgs);
337 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
338 Cardinal *nArgs);
339 static Widget createMenu(Widget parent, char *name, char *label,
340 char mnemonic, Widget *cascadeBtn, int mode);
341 static Widget createMenuItem(Widget parent, char *name, char *label,
342 char mnemonic, menuCallbackProc callback, void *cbArg, int mode);
343 static Widget createFakeMenuItem(Widget parent, char *name,
344 menuCallbackProc callback, void *cbArg);
345 static Widget createMenuToggle(Widget parent, char *name, char *label,
346 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
347 int mode);
348 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
349 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
350 int mode);
351 static Widget createMenuSeparator(Widget parent, char *name, int mode);
352 static void invalidatePrevOpenMenus(void);
353 static void updateWindowMenu(const WindowInfo *window);
354 static void updatePrevOpenMenu(WindowInfo *window);
355 static void updateTagsFileMenu(WindowInfo *window);
356 static void updateTipsFileMenu(WindowInfo *window);
357 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs);
358 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs);
359 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs);
360 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs);
361 static char **shiftKeyToDir(XtPointer callData);
362 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData);
363 static void openPrevCB(Widget w, char *name, caddr_t callData);
364 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData);
365 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData);
366 static int cmpStrPtr(const void *strA, const void *strB);
367 static void setWindowSizeDefault(int rows, int cols);
368 static void updateWindowSizeMenus(void);
369 static void updateWindowSizeMenu(WindowInfo *win);
370 static int strCaseCmp(const char *str1, const char *str2);
371 static int compareWindowNames(const void *windowA, const void *windowB);
372 static int compareWindowShell(const void *windowA, const void *windowB);
373 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
374 Cardinal *nArgs);
375 static void tabMenuPostAP(Widget w, XEvent *event, String *args,
376 Cardinal *nArgs);
377 static void raiseWindowAP(Widget w, XEvent *event, String *args,
378 Cardinal *nArgs);
379 static void focusPaneAP(Widget w, XEvent *event, String *args,
380 Cardinal *nArgs);
381 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
382 Cardinal *nArgs);
383 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
384 Cardinal *nArgs);
385 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
386 Cardinal *nArgs);
387 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
388 Cardinal *nArgs);
389 static void setWrapTextAP(Widget w, XEvent *event, String *args,
390 Cardinal *nArgs);
391 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
392 Cardinal *nArgs);
393 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
394 Cardinal *nArgs);
395 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
396 Cardinal *nArgs);
397 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
398 Cardinal *nArgs);
399 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
400 Cardinal *nArgs);
401 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
402 Cardinal *nArgs);
403 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
404 Cardinal *nArgs);
405 static void setLockedAP(Widget w, XEvent *event, String *args,
406 Cardinal *nArgs);
407 static void setUseTabsAP(Widget w, XEvent *event, String *args,
408 Cardinal *nArgs);
409 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
410 Cardinal *nArgs);
411 static void setTabDistAP(Widget w, XEvent *event, String *args,
412 Cardinal *nArgs);
413 static void setFontsAP(Widget w, XEvent *event, String *args,
414 Cardinal *nArgs);
415 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
416 Cardinal *nArgs);
417 #ifdef SGI_CUSTOM
418 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData);
419 static void addToToggleShortList(Widget w);
420 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName);
421 #endif
423 static HelpMenu * buildHelpMenu( Widget pane, HelpMenu * menu,
424 WindowInfo * window);
426 /* Application action table */
427 static XtActionsRec Actions[] = {
428 {"new", newAP},
429 {"new_opposite", newOppositeAP},
430 {"new_tab", newTabAP},
431 {"open", openAP},
432 {"open-dialog", openDialogAP},
433 {"open_dialog", openDialogAP},
434 {"open-selected", openSelectedAP},
435 {"open_selected", openSelectedAP},
436 {"close", closeAP},
437 {"save", saveAP},
438 {"save-as", saveAsAP},
439 {"save_as", saveAsAP},
440 {"save-as-dialog", saveAsDialogAP},
441 {"save_as_dialog", saveAsDialogAP},
442 {"revert-to-saved", revertAP},
443 {"revert_to_saved", revertAP},
444 {"revert_to_saved_dialog", revertDialogAP},
445 {"include-file", includeAP},
446 {"include_file", includeAP},
447 {"include-file-dialog", includeDialogAP},
448 {"include_file_dialog", includeDialogAP},
449 {"load-macro-file", loadMacroAP},
450 {"load_macro_file", loadMacroAP},
451 {"load-macro-file-dialog", loadMacroDialogAP},
452 {"load_macro_file_dialog", loadMacroDialogAP},
453 {"load-tags-file", loadTagsAP},
454 {"load_tags_file", loadTagsAP},
455 {"load-tags-file-dialog", loadTagsDialogAP},
456 {"load_tags_file_dialog", loadTagsDialogAP},
457 {"unload_tags_file", unloadTagsAP},
458 {"load_tips_file", loadTipsAP},
459 {"load_tips_file_dialog", loadTipsDialogAP},
460 {"unload_tips_file", unloadTipsAP},
461 {"print", printAP},
462 {"print-selection", printSelAP},
463 {"print_selection", printSelAP},
464 {"exit", exitAP},
465 {"undo", undoAP},
466 {"redo", redoAP},
467 {"delete", clearAP},
468 {"select-all", selAllAP},
469 {"select_all", selAllAP},
470 {"shift-left", shiftLeftAP},
471 {"shift_left", shiftLeftAP},
472 {"shift-left-by-tab", shiftLeftTabAP},
473 {"shift_left_by_tab", shiftLeftTabAP},
474 {"shift-right", shiftRightAP},
475 {"shift_right", shiftRightAP},
476 {"shift-right-by-tab", shiftRightTabAP},
477 {"shift_right_by_tab", shiftRightTabAP},
478 {"find", findAP},
479 {"find-dialog", findDialogAP},
480 {"find_dialog", findDialogAP},
481 {"find-again", findSameAP},
482 {"find_again", findSameAP},
483 {"find-selection", findSelAP},
484 {"find_selection", findSelAP},
485 {"find_incremental", findIncrAP},
486 {"start_incremental_find", startIncrFindAP},
487 {"replace", replaceAP},
488 {"replace-dialog", replaceDialogAP},
489 {"replace_dialog", replaceDialogAP},
490 {"replace-all", replaceAllAP},
491 {"replace_all", replaceAllAP},
492 {"replace-in-selection", replaceInSelAP},
493 {"replace_in_selection", replaceInSelAP},
494 {"replace-again", replaceSameAP},
495 {"replace_again", replaceSameAP},
496 {"replace_find", replaceFindAP},
497 {"replace_find_same", replaceFindSameAP},
498 {"replace_find_again", replaceFindSameAP},
499 {"goto-line-number", gotoAP},
500 {"goto_line_number", gotoAP},
501 {"goto-line-number-dialog", gotoDialogAP},
502 {"goto_line_number_dialog", gotoDialogAP},
503 {"goto-selected", gotoSelectedAP},
504 {"goto_selected", gotoSelectedAP},
505 {"mark", markAP},
506 {"mark-dialog", markDialogAP},
507 {"mark_dialog", markDialogAP},
508 {"goto-mark", gotoMarkAP},
509 {"goto_mark", gotoMarkAP},
510 {"goto-mark-dialog", gotoMarkDialogAP},
511 {"goto_mark_dialog", gotoMarkDialogAP},
512 {"match", selectToMatchingAP},
513 {"select_to_matching", selectToMatchingAP},
514 {"goto_matching", gotoMatchingAP},
515 {"find-definition", findDefAP},
516 {"find_definition", findDefAP},
517 {"show_tip", showTipAP},
518 {"split-pane", splitPaneAP},
519 {"split_pane", splitPaneAP},
520 {"close-pane", closePaneAP},
521 {"close_pane", closePaneAP},
522 {"detach_document", detachDocumentAP},
523 {"detach_document_dialog", detachDocumentDialogAP},
524 {"move_document_dialog", moveDocumentDialogAP},
525 {"next_document", nextDocumentAP},
526 {"previous_document", prevDocumentAP},
527 {"last_document", lastDocumentAP},
528 {"uppercase", capitalizeAP},
529 {"lowercase", lowercaseAP},
530 {"fill-paragraph", fillAP},
531 {"fill_paragraph", fillAP},
532 {"control-code-dialog", controlDialogAP},
533 {"control_code_dialog", controlDialogAP},
534 #ifndef VMS
535 {"filter-selection-dialog", filterDialogAP},
536 {"filter_selection_dialog", filterDialogAP},
537 {"filter-selection", shellFilterAP},
538 {"filter_selection", shellFilterAP},
539 {"execute-command", execAP},
540 {"execute_command", execAP},
541 {"execute-command-dialog", execDialogAP},
542 {"execute_command_dialog", execDialogAP},
543 {"execute-command-line", execLineAP},
544 {"execute_command_line", execLineAP},
545 {"shell-menu-command", shellMenuAP},
546 {"shell_menu_command", shellMenuAP},
547 #endif /*VMS*/
548 {"macro-menu-command", macroMenuAP},
549 {"macro_menu_command", macroMenuAP},
550 {"bg_menu_command", bgMenuAP},
551 {"post_window_bg_menu", bgMenuPostAP},
552 {"post_tab_context_menu", tabMenuPostAP},
553 {"beginning-of-selection", beginningOfSelectionAP},
554 {"beginning_of_selection", beginningOfSelectionAP},
555 {"end-of-selection", endOfSelectionAP},
556 {"end_of_selection", endOfSelectionAP},
557 {"repeat_macro", repeatMacroAP},
558 {"repeat_dialog", repeatDialogAP},
559 {"raise_window", raiseWindowAP},
560 {"focus_pane", focusPaneAP},
561 {"set_statistics_line", setStatisticsLineAP},
562 {"set_incremental_search_line", setIncrementalSearchLineAP},
563 {"set_show_line_numbers", setShowLineNumbersAP},
564 {"set_auto_indent", setAutoIndentAP},
565 {"set_wrap_text", setWrapTextAP},
566 {"set_wrap_margin", setWrapMarginAP},
567 {"set_highlight_syntax", setHighlightSyntaxAP},
568 #ifndef VMS
569 {"set_make_backup_copy", setMakeBackupCopyAP},
570 #endif
571 {"set_incremental_backup", setIncrementalBackupAP},
572 {"set_show_matching", setShowMatchingAP},
573 {"set_match_syntax_based", setMatchSyntaxBasedAP},
574 {"set_overtype_mode", setOvertypeModeAP},
575 {"set_locked", setLockedAP},
576 {"set_tab_dist", setTabDistAP},
577 {"set_em_tab_dist", setEmTabDistAP},
578 {"set_use_tabs", setUseTabsAP},
579 {"set_fonts", setFontsAP},
580 {"set_language_mode", setLanguageModeAP}
583 /* List of previously opened files for File menu */
584 static int NPrevOpen = 0;
585 static char **PrevOpen;
587 #ifdef SGI_CUSTOM
588 /* Window to receive items to be toggled on and off in short menus mode */
589 static WindowInfo *ShortMenuWindow;
590 #endif
592 void HidePointerOnKeyedEvent(Widget w, XEvent *event)
594 if (event && (event->type == KeyPress || event->type == KeyRelease)) {
595 ShowHidePointer((TextWidget)w, True);
600 ** Install actions for use in translation tables and macro recording, relating
601 ** to menu item commands
603 void InstallMenuActions(XtAppContext context)
605 XtAppAddActions(context, Actions, XtNumber(Actions));
609 ** Return the (statically allocated) action table for menu item actions.
611 XtActionsRec *GetMenuActions(int *nActions)
613 *nActions = XtNumber(Actions);
614 return Actions;
618 ** Create the menu bar
620 Widget CreateMenuBar(Widget parent, WindowInfo *window)
622 Widget menuBar, menuPane, btn, subPane, subSubPane, subSubSubPane, cascade;
625 ** cache user menus:
626 ** allocate user menu cache
628 window->userMenuCache = CreateUserMenuCache();
631 ** Create the menu bar (row column) widget
633 menuBar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
635 #ifdef SGI_CUSTOM
637 ** Short menu mode is a special feature for the SGI system distribution
638 ** version of NEdit.
640 ** To make toggling short-menus mode faster (re-creating the menus was
641 ** too slow), a list is kept in the window data structure of items to
642 ** be turned on and off. Initialize that list and give the menu creation
643 ** routines a pointer to the window on which this list is kept. This is
644 ** (unfortunately) a global variable to keep the interface simple for
645 ** the mainstream case.
647 ShortMenuWindow = window;
648 window->nToggleShortItems = 0;
649 #endif
652 ** "File" pull down menu.
654 menuPane = createMenu(menuBar, "fileMenu", "File", 0, NULL, SHORT);
655 createMenuItem(menuPane, "new", "New", 'N', doActionCB, "new", SHORT);
656 if ( GetPrefOpenInTab() )
657 window->newOppositeItem = createMenuItem(menuPane, "newOpposite",
658 "New Window", 'W', doActionCB, "new_opposite", SHORT);
659 else
660 window->newOppositeItem = createMenuItem(menuPane, "newOpposite",
661 "New Tab", 'T', doActionCB, "new_opposite", SHORT);
662 createMenuItem(menuPane, "open", "Open...", 'O', doActionCB, "open_dialog",
663 SHORT);
664 window->openSelItem=createMenuItem(menuPane, "openSelected", "Open Selected", 'd',
665 doActionCB, "open_selected", FULL);
666 if (GetPrefMaxPrevOpenFiles() != 0) {
667 window->prevOpenMenuPane = createMenu(menuPane, "openPrevious",
668 "Open Previous", 'v', &window->prevOpenMenuItem, SHORT);
669 XtSetSensitive(window->prevOpenMenuItem, NPrevOpen != 0);
670 XtAddCallback(window->prevOpenMenuItem, XmNcascadingCallback,
671 (XtCallbackProc)prevOpenMenuCB, window);
673 createMenuSeparator(menuPane, "sep1", SHORT);
674 window->closeItem = createMenuItem(menuPane, "close", "Close", 'C',
675 doActionCB, "close", SHORT);
676 createMenuItem(menuPane, "save", "Save", 'S', doActionCB, "save", SHORT);
677 createMenuItem(menuPane, "saveAs", "Save As...", 'A', doActionCB,
678 "save_as_dialog", SHORT);
679 createMenuItem(menuPane, "revertToSaved", "Revert to Saved", 'R',
680 doActionCB, "revert_to_saved_dialog", SHORT);
681 createMenuSeparator(menuPane, "sep2", SHORT);
682 createMenuItem(menuPane, "includeFile", "Include File...", 'I',
683 doActionCB, "include_file_dialog", SHORT);
684 createMenuItem(menuPane, "loadMacroFile", "Load Macro File...", 'M',
685 doActionCB, "load_macro_file_dialog", FULL);
686 createMenuItem(menuPane, "loadTagsFile", "Load Tags File...", 'g',
687 doActionCB, "load_tags_file_dialog", FULL);
688 window->unloadTagsMenuPane = createMenu(menuPane, "unloadTagsFiles",
689 "Unload Tags File", 'U', &window->unloadTagsMenuItem, FULL);
690 XtSetSensitive(window->unloadTagsMenuItem, TagsFileList != NULL);
691 XtAddCallback(window->unloadTagsMenuItem, XmNcascadingCallback,
692 (XtCallbackProc)unloadTagsFileMenuCB, window);
693 createMenuItem(menuPane, "loadTipsFile", "Load Calltips File...", 'F',
694 doActionCB, "load_tips_file_dialog", FULL);
695 window->unloadTipsMenuPane = createMenu(menuPane, "unloadTipsFiles",
696 "Unload Calltips File", 'e', &window->unloadTipsMenuItem, FULL);
697 XtSetSensitive(window->unloadTipsMenuItem, TipsFileList != NULL);
698 XtAddCallback(window->unloadTipsMenuItem, XmNcascadingCallback,
699 (XtCallbackProc)unloadTipsFileMenuCB, window);
700 createMenuSeparator(menuPane, "sep3", SHORT);
701 createMenuItem(menuPane, "print", "Print...", 'P', doActionCB, "print",
702 SHORT);
703 window->printSelItem = createMenuItem(menuPane, "printSelection",
704 "Print Selection...", 'l', doActionCB, "print_selection",
705 SHORT);
706 XtSetSensitive(window->printSelItem, window->wasSelected);
707 createMenuSeparator(menuPane, "sep4", SHORT);
708 createMenuItem(menuPane, "exit", "Exit", 'x', doActionCB, "exit", SHORT);
709 CheckCloseDim();
712 ** "Edit" pull down menu.
714 menuPane = createMenu(menuBar, "editMenu", "Edit", 0, NULL, SHORT);
715 window->undoItem = createMenuItem(menuPane, "undo", "Undo", 'U',
716 doActionCB, "undo", SHORT);
717 XtSetSensitive(window->undoItem, False);
718 window->redoItem = createMenuItem(menuPane, "redo", "Redo", 'R',
719 doActionCB, "redo", SHORT);
720 XtSetSensitive(window->redoItem, False);
721 createMenuSeparator(menuPane, "sep1", SHORT);
722 window->cutItem = createMenuItem(menuPane, "cut", "Cut", 't', doActionCB,
723 "cut_clipboard", SHORT);
724 XtSetSensitive(window->cutItem, window->wasSelected);
725 window->copyItem = createMenuItem(menuPane, "copy", "Copy", 'C', doActionCB,
726 "copy_clipboard", SHORT);
727 XtSetSensitive(window->copyItem, window->wasSelected);
728 createMenuItem(menuPane, "paste", "Paste", 'P', doActionCB,
729 "paste_clipboard", SHORT);
730 createMenuItem(menuPane, "pasteColumn", "Paste Column", 's', pasteColCB,
731 window, SHORT);
732 window->delItem=createMenuItem(menuPane, "delete", "Delete", 'D', doActionCB, "delete_selection",
733 SHORT);
734 XtSetSensitive(window->delItem, window->wasSelected);
735 createMenuItem(menuPane, "selectAll", "Select All", 'A', doActionCB,
736 "select_all", SHORT);
737 createMenuSeparator(menuPane, "sep2", SHORT);
738 createMenuItem(menuPane, "shiftLeft", "Shift Left", 'L',
739 shiftLeftCB, window, SHORT);
740 createFakeMenuItem(menuPane, "shiftLeftShift", shiftLeftCB, window);
741 createMenuItem(menuPane, "shiftRight", "Shift Right", 'g',
742 shiftRightCB, window, SHORT);
743 createFakeMenuItem(menuPane, "shiftRightShift", shiftRightCB, window);
744 window->lowerItem=createMenuItem(menuPane, "lowerCase", "Lower-case", 'w',
745 doActionCB, "lowercase", SHORT);
746 window->upperItem=createMenuItem(menuPane, "upperCase", "Upper-case", 'e',
747 doActionCB, "uppercase", SHORT);
748 createMenuItem(menuPane, "fillParagraph", "Fill Paragraph", 'F',
749 doActionCB, "fill_paragraph", SHORT);
750 createMenuSeparator(menuPane, "sep3", FULL);
751 createMenuItem(menuPane, "insertFormFeed", "Insert Form Feed", 'I',
752 formFeedCB, window, FULL);
753 createMenuItem(menuPane, "insertCtrlCode", "Insert Ctrl Code...", 'n',
754 doActionCB, "control_code_dialog", FULL);
755 #ifdef SGI_CUSTOM
756 createMenuSeparator(menuPane, "sep4", SHORT);
757 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
758 doActionCB, "set_overtype_mode", False, SHORT);
759 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
760 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
761 #endif
764 ** "Search" pull down menu.
766 menuPane = createMenu(menuBar, "searchMenu", "Search", 0, NULL, SHORT);
767 createMenuItem(menuPane, "find", "Find...", 'F', findCB, window, SHORT);
768 createFakeMenuItem(menuPane, "findShift", findCB, window);
769 window->findAgainItem=createMenuItem(menuPane, "findAgain", "Find Again", 'i', findSameCB, window,
770 SHORT);
771 XtSetSensitive(window->findAgainItem, NHist);
772 createFakeMenuItem(menuPane, "findAgainShift", findSameCB, window);
773 window->findSelItem=createMenuItem(menuPane, "findSelection", "Find Selection", 'S',
774 findSelCB, window, SHORT);
775 createFakeMenuItem(menuPane, "findSelectionShift", findSelCB, window);
776 createMenuItem(menuPane, "findIncremental", "Find Incremental", 'n',
777 findIncrCB, window, SHORT);
778 createFakeMenuItem(menuPane, "findIncrementalShift", findIncrCB, window);
779 createMenuItem(menuPane, "replace", "Replace...", 'R', replaceCB, window,
780 SHORT);
781 createFakeMenuItem(menuPane, "replaceShift", replaceCB, window);
782 window->replaceFindAgainItem=createMenuItem(menuPane, "replaceFindAgain", "Replace Find Again", 'A',
783 replaceFindSameCB, window, SHORT);
784 XtSetSensitive(window->replaceFindAgainItem, NHist);
785 createFakeMenuItem(menuPane, "replaceFindAgainShift", replaceFindSameCB, window);
786 window->replaceAgainItem=createMenuItem(menuPane, "replaceAgain", "Replace Again", 'p',
787 replaceSameCB, window, SHORT);
788 XtSetSensitive(window->replaceAgainItem, NHist);
789 createFakeMenuItem(menuPane, "replaceAgainShift", replaceSameCB, window);
790 createMenuSeparator(menuPane, "sep1", FULL);
791 createMenuItem(menuPane, "gotoLineNumber", "Goto Line Number...", 'L',
792 doActionCB, "goto_line_number_dialog", FULL);
793 window->gotoSelItem=createMenuItem(menuPane, "gotoSelected", "Goto Selected", 'G',
794 doActionCB, "goto_selected", FULL);
795 createMenuSeparator(menuPane, "sep2", FULL);
796 createMenuItem(menuPane, "mark", "Mark", 'k', markCB, window, FULL);
797 createMenuItem(menuPane, "gotoMark", "Goto Mark", 'o', gotoMarkCB, window,
798 FULL);
799 createFakeMenuItem(menuPane, "gotoMarkShift", gotoMarkCB, window);
800 createMenuSeparator(menuPane, "sep3", FULL);
801 createMenuItem(menuPane, "gotoMatching", "Goto Matching (..)", 'M',
802 gotoMatchingCB, window, FULL);
803 createFakeMenuItem(menuPane, "gotoMatchingShift", gotoMatchingCB, window);
804 window->findDefItem = createMenuItem(menuPane, "findDefinition",
805 "Find Definition", 'D', doActionCB, "find_definition", FULL);
806 XtSetSensitive(window->findDefItem, TagsFileList != NULL);
807 window->showTipItem = createMenuItem(menuPane, "showCalltip",
808 "Show Calltip", 'C', doActionCB, "show_tip", FULL);
809 XtSetSensitive(window->showTipItem, (TagsFileList != NULL ||
810 TipsFileList != NULL) );
813 ** Preferences menu, Default Settings sub menu
815 menuPane = createMenu(menuBar, "preferencesMenu", "Preferences", 0, NULL,
816 SHORT);
817 subPane = createMenu(menuPane, "defaultSettings", "Default Settings", 'D',
818 NULL, FULL);
819 createMenuItem(subPane, "languageModes", "Language Modes...", 'L',
820 languageDefCB, window, FULL);
822 /* Auto Indent sub menu */
823 subSubPane = createMenu(subPane, "autoIndent", "Auto Indent", 'A',
824 NULL, FULL);
825 window->autoIndentOffDefItem = createMenuRadioToggle(subSubPane, "off",
826 "Off", 'O', autoIndentOffDefCB, window,
827 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == NO_AUTO_INDENT, SHORT);
828 window->autoIndentDefItem = createMenuRadioToggle(subSubPane, "on",
829 "On", 'n', autoIndentDefCB, window,
830 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == AUTO_INDENT, SHORT);
831 window->smartIndentDefItem = createMenuRadioToggle(subSubPane, "smart",
832 "Smart", 'S', smartIndentDefCB, window,
833 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == SMART_INDENT, SHORT);
834 createMenuSeparator(subSubPane, "sep1", SHORT);
835 createMenuItem(subSubPane, "ProgramSmartIndent", "Program Smart Indent...",
836 'P', smartMacrosDefCB, window, FULL);
838 /* Wrap sub menu */
839 subSubPane = createMenu(subPane, "wrap", "Wrap", 'W', NULL, FULL);
840 window->noWrapDefItem = createMenuRadioToggle(subSubPane,
841 "none", "None", 'N', noWrapDefCB,
842 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NO_WRAP, SHORT);
843 window->newlineWrapDefItem = createMenuRadioToggle(subSubPane,
844 "autoNewline", "Auto Newline", 'A', newlineWrapDefCB,
845 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NEWLINE_WRAP, SHORT);
846 window->contWrapDefItem = createMenuRadioToggle(subSubPane, "continuous",
847 "Continuous", 'C', contWrapDefCB, window,
848 GetPrefWrap(PLAIN_LANGUAGE_MODE) == CONTINUOUS_WRAP, SHORT);
849 createMenuSeparator(subSubPane, "sep1", SHORT);
850 createMenuItem(subSubPane, "wrapMargin", "Wrap Margin...", 'W',
851 wrapMarginDefCB, window, SHORT);
853 /* Smart Tags sub menu */
854 subSubPane = createMenu(subPane, "smartTags", "Tag Collisions", 'l',
855 NULL, FULL);
856 window->allTagsDefItem = createMenuRadioToggle(subSubPane, "showall",
857 "Show All", 'A', showAllTagsDefCB, window, !GetPrefSmartTags(),
858 FULL);
859 window->smartTagsDefItem = createMenuRadioToggle(subSubPane, "smart",
860 "Smart", 'S', smartTagsDefCB, window, GetPrefSmartTags(), FULL);
862 createMenuItem(subPane, "tabDistance", "Tab Stops...", 'T', tabsDefCB, window,
863 SHORT);
864 createMenuItem(subPane, "textFont", "Text Fonts...", 'F', fontDefCB, window,
865 FULL);
866 createMenuItem(subPane, "colors", "Colors...", 'C', colorDefCB, window,
867 FULL);
869 /* Customize Menus sub menu */
870 subSubPane = createMenu(subPane, "customizeMenus", "Customize Menus",
871 'u', NULL, FULL);
872 #ifndef VMS
873 createMenuItem(subSubPane, "shellMenu", "Shell Menu...", 'S',
874 shellDefCB, window, FULL);
875 #endif
876 createMenuItem(subSubPane, "macroMenu", "Macro Menu...", 'M',
877 macroDefCB, window, FULL);
878 createMenuItem(subSubPane, "windowBackgroundMenu",
879 "Window Background Menu...", 'W', bgMenuDefCB, window, FULL);
880 createMenuSeparator(subSubPane, "sep1", SHORT);
881 window->pathInWindowsMenuDefItem = createMenuToggle(subSubPane, "pathInWindowsMenu",
882 "Show Path In Windows Menu", 'P', pathInWindowsMenuDefCB, window, GetPrefShowPathInWindowsMenu(),
883 SHORT);
884 createMenuItem(subPane, "custimizeTitle", "Customize Window Title...", 'd',
885 customizeTitleDefCB, window, FULL);
887 /* Search sub menu */
888 subSubPane = createMenu(subPane, "searching", "Searching",
889 'g', NULL, FULL);
890 window->searchDlogsDefItem = createMenuToggle(subSubPane, "verbose",
891 "Verbose", 'V', searchDlogsDefCB, window,
892 GetPrefSearchDlogs(), SHORT);
893 window->searchWrapsDefItem = createMenuToggle(subSubPane, "wrapAround",
894 "Wrap Around", 'W', searchWrapsDefCB, window,
895 GetPrefSearchWraps(), SHORT);
896 window->beepOnSearchWrapDefItem = createMenuToggle(subSubPane,
897 "beepOnSearchWrap", "Beep On Search Wrap", 'B',
898 beepOnSearchWrapDefCB, window, GetPrefBeepOnSearchWrap(), SHORT);
899 window->keepSearchDlogsDefItem = createMenuToggle(subSubPane,
900 "keepDialogsUp", "Keep Dialogs Up", 'K',
901 keepSearchDlogsDefCB, window, GetPrefKeepSearchDlogs(), SHORT);
902 subSubSubPane = createMenu(subSubPane, "defaultSearchStyle",
903 "Default Search Style", 'D', NULL, FULL);
904 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
905 window->searchLiteralDefItem = createMenuToggle(subSubSubPane, "literal",
906 "Literal", 'L', searchLiteralCB, window,
907 GetPrefSearch() == SEARCH_LITERAL, FULL);
908 window->searchCaseSenseDefItem = createMenuToggle(subSubSubPane,
909 "caseSensitive", "Literal, Case Sensitive", 'C', searchCaseSenseCB, window,
910 GetPrefSearch() == SEARCH_CASE_SENSE, FULL);
911 window->searchLiteralWordDefItem = createMenuToggle(subSubSubPane, "literalWord",
912 "Literal, Whole Word", 'W', searchLiteralWordCB, window,
913 GetPrefSearch() == SEARCH_LITERAL_WORD, FULL);
914 window->searchCaseSenseWordDefItem = createMenuToggle(subSubSubPane,
915 "caseSensitiveWord", "Literal, Case Sensitive, Whole Word", 't', searchCaseSenseWordCB, window,
916 GetPrefSearch() == SEARCH_CASE_SENSE_WORD, FULL);
917 window->searchRegexDefItem = createMenuToggle(subSubSubPane,
918 "regularExpression", "Regular Expression", 'R', searchRegexCB,
919 window, GetPrefSearch() == SEARCH_REGEX, FULL);
920 window->searchRegexNoCaseDefItem = createMenuToggle(subSubSubPane,
921 "regularExpressionNoCase", "Regular Expression, Case Insensitive", 'I', searchRegexNoCaseCB, window,
922 GetPrefSearch() == SEARCH_REGEX_NOCASE, FULL);
923 #ifdef REPLACE_SCOPE
924 subSubSubPane = createMenu(subSubPane, "defaultReplaceScope",
925 "Default Replace Scope", 'R', NULL, FULL);
926 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
927 window->replScopeWinDefItem = createMenuToggle(subSubSubPane, "window",
928 "In Window", 'W', replaceScopeWindowCB, window,
929 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_WINDOW, FULL);
930 window->replScopeSelDefItem = createMenuToggle(subSubSubPane, "selection",
931 "In Selection", 'S', replaceScopeSelectionCB, window,
932 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SELECTION, FULL);
933 window->replScopeSmartDefItem = createMenuToggle(subSubSubPane, "window",
934 "Smart", 'm', replaceScopeSmartCB, window,
935 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SMART, FULL);
936 #endif
938 /* Syntax Highlighting sub menu */
939 subSubPane = createMenu(subPane, "syntaxHighlighting","Syntax Highlighting",
940 'H', NULL, FULL);
941 window->highlightOffDefItem = createMenuRadioToggle(subSubPane, "off","Off",
942 'O', highlightOffDefCB, window, !GetPrefHighlightSyntax(), FULL);
943 window->highlightDefItem = createMenuRadioToggle(subSubPane, "on",
944 "On", 'n', highlightDefCB, window, GetPrefHighlightSyntax(), FULL);
945 createMenuSeparator(subSubPane, "sep1", SHORT);
946 createMenuItem(subSubPane, "recognitionPatterns", "Recognition Patterns...",
947 'R', highlightingDefCB, window, FULL);
948 createMenuItem(subSubPane, "textDrawingStyles", "Text Drawing Styles...", 'T',
949 stylesDefCB, window, FULL);
950 window->backlightCharsDefItem = createMenuToggle(subPane,
951 "backlightChars", "Apply Backlighting", 'g', backlightCharsDefCB,
952 window, GetPrefBacklightChars(), FULL);
954 /* tabbed editing sub menu */
955 subSubPane = createMenu(subPane, "tabbedEditMenu", "Tabbed Editing", 0,
956 &cascade, SHORT);
957 window->openInTabDefItem = createMenuToggle(subSubPane, "openAsTab",
958 "Open File In New Tab", 'T', openInTabDefCB, window,
959 GetPrefOpenInTab(), FULL);
960 window->tabBarDefItem = createMenuToggle(subSubPane, "showTabBar",
961 "Show Tab Bar", 'B', tabBarDefCB, window,
962 GetPrefTabBar(), FULL);
963 window->tabBarHideDefItem = createMenuToggle(subSubPane,
964 "hideTabBar", "Hide Tab Bar When Only One Document is Open", 'H',
965 tabBarHideDefCB, window, GetPrefTabBarHideOne(), FULL);
966 window->tabNavigateDefItem = createMenuToggle(subSubPane, "tabNavigateDef",
967 "Next/Prev Tabs Across Windows", 'W', tabNavigateDefCB, window,
968 GetPrefGlobalTabNavigate(), FULL);
969 window->tabSortDefItem = createMenuToggle(subSubPane, "tabSortDef",
970 "Sort Tabs Alphabetically", 'S', tabSortDefCB, window,
971 GetPrefSortTabs(), FULL);
973 window->toolTipsDefItem = createMenuToggle(subPane, "showTooltips",
974 "Show Tooltips", 0, toolTipsDefCB, window, GetPrefToolTips(),
975 FULL);
976 window->statsLineDefItem = createMenuToggle(subPane, "statisticsLine",
977 "Statistics Line", 'S', statsLineDefCB, window, GetPrefStatsLine(),
978 SHORT);
979 window->iSearchLineDefItem = createMenuToggle(subPane,
980 "incrementalSearchLine", "Incremental Search Line", 'i',
981 iSearchLineDefCB, window, GetPrefISearchLine(), FULL);
982 window->lineNumsDefItem = createMenuToggle(subPane, "showLineNumbers",
983 "Show Line Numbers", 'N', lineNumsDefCB, window, GetPrefLineNums(),
984 SHORT);
985 window->saveLastDefItem = createMenuToggle(subPane, "preserveLastVersion",
986 "Make Backup Copy (*.bck)", 'e', preserveDefCB, window,
987 GetPrefSaveOldVersion(), SHORT);
988 window->autoSaveDefItem = createMenuToggle(subPane, "incrementalBackup",
989 "Incremental Backup", 'B', autoSaveDefCB, window, GetPrefAutoSave(),
990 SHORT);
993 /* Show Matching sub menu */
994 subSubPane = createMenu(subPane, "showMatching", "Show Matching (..)", 'M',
995 NULL, FULL);
996 window->showMatchingOffDefItem = createMenuRadioToggle(subSubPane, "off",
997 "Off", 'O', showMatchingOffDefCB, window,
998 GetPrefShowMatching() == NO_FLASH, SHORT);
999 window->showMatchingDelimitDefItem = createMenuRadioToggle(subSubPane,
1000 "delimiter", "Delimiter", 'D', showMatchingDelimitDefCB, window,
1001 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
1002 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
1003 "range", "Range", 'R', showMatchingRangeDefCB, window,
1004 GetPrefShowMatching() == FLASH_RANGE, SHORT);
1005 createMenuSeparator(subSubPane, "sep", SHORT);
1006 window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
1007 "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
1008 GetPrefMatchSyntaxBased(), SHORT);
1010 /* Append LF at end of files on save */
1011 window->appendLFItem = createMenuToggle(subPane, "appendLFItem",
1012 "Terminate with Line Break on Save", 'v', appendLFCB, NULL,
1013 GetPrefAppendLF(), FULL);
1015 window->sortOpenPrevDefItem = createMenuToggle(subPane, "sortOpenPrevMenu",
1016 "Sort Open Prev. Menu", 'o', sortOpenPrevDefCB, window,
1017 GetPrefSortOpenPrevMenu(), FULL);
1018 window->reposDlogsDefItem = createMenuToggle(subPane, "popupsUnderPointer",
1019 "Popups Under Pointer", 'P', reposDlogsDefCB, window,
1020 GetPrefRepositionDialogs(), FULL);
1021 window->autoScrollDefItem = createMenuToggle(subPane, "autoScroll",
1022 "Auto Scroll Near Window Top/Bottom", 0, autoScrollDefCB, window,
1023 GetPrefAutoScroll(), FULL);
1024 subSubPane = createMenu(subPane, "warnings", "Warnings", 'r', NULL, FULL);
1025 window->modWarnDefItem = createMenuToggle(subSubPane,
1026 "filesModifiedExternally", "Files Modified Externally", 'F',
1027 modWarnDefCB, window, GetPrefWarnFileMods(), FULL);
1028 window->modWarnRealDefItem = createMenuToggle(subSubPane,
1029 "checkModifiedFileContents", "Check Modified File Contents", 'C',
1030 modWarnRealDefCB, window, GetPrefWarnRealFileMods(), FULL);
1031 XtSetSensitive(window->modWarnRealDefItem, GetPrefWarnFileMods());
1032 window->exitWarnDefItem = createMenuToggle(subSubPane, "onExit", "On Exit", 'O',
1033 exitWarnDefCB, window, GetPrefWarnExit(), FULL);
1035 /* Initial Window Size sub menu (simulates radioBehavior) */
1036 subSubPane = createMenu(subPane, "initialwindowSize",
1037 "Initial Window Size", 'z', NULL, FULL);
1038 /* XtVaSetValues(subSubPane, XmNradioBehavior, True, NULL); */
1039 window->size24x80DefItem = btn = createMenuToggle(subSubPane, "24X80",
1040 "24 x 80", '2', size24x80CB, window, False, SHORT);
1041 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1042 window->size40x80DefItem = btn = createMenuToggle(subSubPane, "40X80",
1043 "40 x 80", '4', size40x80CB, window, False, SHORT);
1044 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1045 window->size60x80DefItem = btn = createMenuToggle(subSubPane, "60X80",
1046 "60 x 80", '6', size60x80CB, window, False, SHORT);
1047 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1048 window->size80x80DefItem = btn = createMenuToggle(subSubPane, "80X80",
1049 "80 x 80", '8', size80x80CB, window, False, SHORT);
1050 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1051 window->sizeCustomDefItem = btn = createMenuToggle(subSubPane, "custom",
1052 "Custom...", 'C', sizeCustomCB, window, False, SHORT);
1053 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1054 updateWindowSizeMenu(window);
1057 ** Remainder of Preferences menu
1059 createMenuItem(menuPane, "saveDefaults", "Save Defaults...", 'v',
1060 savePrefCB, window, FULL);
1061 #ifdef SGI_CUSTOM
1062 window->shortMenusDefItem = createMenuToggle(menuPane,
1063 "shortMenus", "Short Menus", 'h', shortMenusCB, window,
1064 GetPrefShortMenus(), SHORT);
1065 #endif
1066 createMenuSeparator(menuPane, "sep1", SHORT);
1067 window->statsLineItem = createMenuToggle(menuPane, "statisticsLine", "Statistics Line", 'S',
1068 statsCB, window, GetPrefStatsLine(), SHORT);
1069 window->iSearchLineItem = createMenuToggle(menuPane, "incrementalSearchLine","Incremental Search Line",
1070 'I', doActionCB, "set_incremental_search_line", GetPrefISearchLine(), FULL);
1071 window->lineNumsItem = createMenuToggle(menuPane, "lineNumbers", "Show Line Numbers", 'N',
1072 doActionCB, "set_show_line_numbers", GetPrefLineNums(), SHORT);
1073 CreateLanguageModeSubMenu(window, menuPane, "languageMode",
1074 "Language Mode", 'L');
1075 subPane = createMenu(menuPane, "autoIndent", "Auto Indent",
1076 'A', NULL, FULL);
1077 window->autoIndentOffItem = createMenuRadioToggle(subPane, "off", "Off",
1078 'O', autoIndentOffCB, window, window->indentStyle == NO_AUTO_INDENT,
1079 SHORT);
1080 window->autoIndentItem = createMenuRadioToggle(subPane, "on", "On", 'n',
1081 autoIndentCB, window, window->indentStyle == AUTO_INDENT, SHORT);
1082 window->smartIndentItem = createMenuRadioToggle(subPane, "smart", "Smart",
1083 'S', smartIndentCB, window, window->indentStyle == SMART_INDENT,
1084 SHORT);
1085 subPane = createMenu(menuPane, "wrap", "Wrap",
1086 'W', NULL, FULL);
1087 window->noWrapItem = createMenuRadioToggle(subPane, "none",
1088 "None", 'N', noWrapCB, window,
1089 window->wrapMode==NO_WRAP, SHORT);
1090 window->newlineWrapItem = createMenuRadioToggle(subPane, "autoNewlineWrap",
1091 "Auto Newline", 'A', newlineWrapCB, window,
1092 window->wrapMode==NEWLINE_WRAP, SHORT);
1093 window->continuousWrapItem = createMenuRadioToggle(subPane,
1094 "continuousWrap", "Continuous", 'C', continuousWrapCB, window,
1095 window->wrapMode==CONTINUOUS_WRAP, SHORT);
1096 createMenuSeparator(subPane, "sep1", SHORT);
1097 createMenuItem(subPane, "wrapMargin", "Wrap Margin...", 'W',
1098 wrapMarginCB, window, SHORT);
1099 createMenuItem(menuPane, "tabs", "Tab Stops...", 'T', tabsCB, window, SHORT);
1100 createMenuItem(menuPane, "textFont", "Text Fonts...", 'F', fontCB, window,
1101 FULL);
1102 window->highlightItem = createMenuToggle(menuPane, "highlightSyntax",
1103 "Highlight Syntax", 'H', doActionCB, "set_highlight_syntax",
1104 GetPrefHighlightSyntax(), SHORT);
1105 window->backlightCharsItem = createMenuToggle(menuPane, "backlightChars",
1106 "Apply Backlighting", 'g', backlightCharsCB, window,
1107 window->backlightChars, FULL);
1108 #ifndef VMS
1109 window->saveLastItem = createMenuToggle(menuPane, "makeBackupCopy",
1110 "Make Backup Copy (*.bck)", 'e', preserveCB, window,
1111 window->saveOldVersion, SHORT);
1112 #endif
1113 window->autoSaveItem = createMenuToggle(menuPane, "incrementalBackup",
1114 "Incremental Backup", 'B', autoSaveCB, window, window->autoSave,
1115 SHORT);
1117 subPane = createMenu(menuPane, "showMatching", "Show Matching (..)",
1118 'M', NULL, FULL);
1119 window->showMatchingOffItem = createMenuRadioToggle(subPane, "off", "Off",
1120 'O', showMatchingOffCB, window, window->showMatchingStyle == NO_FLASH,
1121 SHORT);
1122 window->showMatchingDelimitItem = createMenuRadioToggle(subPane,
1123 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
1124 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
1125 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
1126 "Range", 'R', showMatchingRangeCB, window,
1127 window->showMatchingStyle == FLASH_RANGE, SHORT);
1128 createMenuSeparator(subPane, "sep", SHORT);
1129 window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
1130 "Syntax Based", 'S', matchSyntaxBasedCB, window,
1131 window->matchSyntaxBased, SHORT);
1133 #ifndef SGI_CUSTOM
1134 createMenuSeparator(menuPane, "sep2", SHORT);
1135 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
1136 doActionCB, "set_overtype_mode", False, SHORT);
1137 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
1138 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
1139 #endif
1141 #ifndef VMS
1143 ** Create the Shell menu
1145 menuPane = window->shellMenuPane =
1146 createMenu(menuBar, "shellMenu", "Shell", 0, &cascade, FULL);
1147 btn = createMenuItem(menuPane, "executeCommand", "Execute Command...",
1148 'E', doActionCB, "execute_command_dialog", SHORT);
1149 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1150 btn = createMenuItem(menuPane, "executeCommandLine", "Execute Command Line",
1151 'x', doActionCB, "execute_command_line", SHORT);
1152 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1153 window->filterItem = createMenuItem(menuPane, "filterSelection",
1154 "Filter Selection...", 'F', doActionCB, "filter_selection_dialog",
1155 SHORT);
1156 XtVaSetValues(window->filterItem, XmNuserData, PERMANENT_MENU_ITEM,
1157 XmNsensitive, window->wasSelected, NULL);
1158 window->cancelShellItem = createMenuItem(menuPane, "cancelShellCommand",
1159 "Cancel Shell Command", 'C', cancelShellCB, window, SHORT);
1160 XtVaSetValues(window->cancelShellItem, XmNuserData, PERMANENT_MENU_ITEM,
1161 XmNsensitive, False, NULL);
1162 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1163 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1164 #endif
1167 ** Create the Macro menu
1169 menuPane = window->macroMenuPane =
1170 createMenu(menuBar, "macroMenu", "Macro", 0, &cascade, FULL);
1171 window->learnItem = createMenuItem(menuPane, "learnKeystrokes",
1172 "Learn Keystrokes", 'L', learnCB, window, SHORT);
1173 XtVaSetValues(window->learnItem , XmNuserData, PERMANENT_MENU_ITEM, NULL);
1174 window->finishLearnItem = createMenuItem(menuPane, "finishLearn",
1175 "Finish Learn", 'F', finishLearnCB, window, SHORT);
1176 XtVaSetValues(window->finishLearnItem , XmNuserData, PERMANENT_MENU_ITEM,
1177 XmNsensitive, False, NULL);
1178 window->cancelMacroItem = createMenuItem(menuPane, "cancelLearn",
1179 "Cancel Learn", 'C', cancelLearnCB, window, SHORT);
1180 XtVaSetValues(window->cancelMacroItem, XmNuserData, PERMANENT_MENU_ITEM,
1181 XmNsensitive, False, NULL);
1182 window->replayItem = createMenuItem(menuPane, "replayKeystrokes",
1183 "Replay Keystrokes", 'K', replayCB, window, SHORT);
1184 XtVaSetValues(window->replayItem, XmNuserData, PERMANENT_MENU_ITEM,
1185 XmNsensitive, GetReplayMacro() != NULL, NULL);
1186 window->repeatItem = createMenuItem(menuPane, "repeat",
1187 "Repeat...", 'R', doActionCB, "repeat_dialog", SHORT);
1188 XtVaSetValues(window->repeatItem, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1189 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1190 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1193 ** Create the Windows menu
1195 menuPane = window->windowMenuPane = createMenu(menuBar, "windowsMenu",
1196 "Windows", 0, &cascade, FULL);
1197 XtAddCallback(cascade, XmNcascadingCallback, (XtCallbackProc)windowMenuCB,
1198 window);
1199 window->splitPaneItem = createMenuItem(menuPane, "splitPane",
1200 "Split Pane", 'S', doActionCB, "split_pane", SHORT);
1201 XtVaSetValues(window->splitPaneItem, XmNuserData, PERMANENT_MENU_ITEM,
1202 NULL);
1203 window->closePaneItem = createMenuItem(menuPane, "closePane",
1204 "Close Pane", 'C', doActionCB, "close_pane", SHORT);
1205 XtVaSetValues(window->closePaneItem, XmNuserData, PERMANENT_MENU_ITEM,NULL);
1206 XtSetSensitive(window->closePaneItem, False);
1208 btn = createMenuSeparator(menuPane, "sep01", SHORT);
1209 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1210 window->detachDocumentItem = createMenuItem(menuPane, "detachBuffer",
1211 "Detach Tab", 'D', doActionCB, "detach_document", SHORT);
1212 XtSetSensitive(window->detachDocumentItem, False);
1214 window->moveDocumentItem = createMenuItem(menuPane, "moveDocument",
1215 "Move Tab To...", 'M', doActionCB, "move_document_dialog", SHORT);
1216 XtSetSensitive(window->moveDocumentItem, False);
1217 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1218 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1221 ** Create "Help" pull down menu.
1223 menuPane = createMenu(menuBar, "helpMenu", "Help", 0, &cascade, SHORT);
1224 XtVaSetValues(menuBar, XmNmenuHelpWidget, cascade, NULL);
1225 buildHelpMenu( menuPane, &H_M[0], window );
1227 return menuBar;
1230 /*----------------------------------------------------------------------------*/
1232 static Widget makeHelpMenuItem(
1234 Widget parent,
1235 char *name, /* to be assigned to the child widget */
1236 char *label, /* text to be displayed in menu */
1237 char mnemonic, /* letter in label to be underlined */
1238 menuCallbackProc callback, /* activated when menu item selected */
1239 void *cbArg, /* passed to activated call back */
1240 int mode, /* SGI_CUSTOM menu option */
1241 enum HelpTopic topic /* associated with this menu item */
1244 Widget menuItem =
1245 createMenuItem( parent, name, label, mnemonic, callback, cbArg, mode );
1247 XtVaSetValues( menuItem, XmNuserData, topic, 0 );
1248 return menuItem;
1251 /*----------------------------------------------------------------------------*/
1253 static void helpCB( Widget menuItem, XtPointer clientData, XtPointer callData )
1255 enum HelpTopic topic;
1257 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(menuItem))->lastFocus,
1258 ((XmAnyCallbackStruct *)callData)->event);
1259 XtVaGetValues( menuItem, XmNuserData, &topic, 0 );
1261 Help(topic);
1264 /*----------------------------------------------------------------------------*/
1266 #define NON_MENU_HELP 9
1268 static HelpMenu * buildHelpMenu(
1270 Widget pane, /* Menu pane on which to place new menu items */
1271 HelpMenu * menu, /* Data to drive building the help menu */
1272 WindowInfo * window /* Main NEdit window information */
1275 #ifdef VMS
1276 int hideIt = 1; /* All menu items matching this will be inaccessible */
1277 #else
1278 int hideIt = -1; /* This value should make all menu items accessible */
1279 #endif
1281 if( menu != NULL )
1283 int crntLevel = menu->level;
1285 /*-------------------------
1286 * For each menu element ...
1287 *-------------------------*/
1288 while( menu != NULL && menu->level == crntLevel )
1290 /*----------------------------------------------
1291 * ... see if dealing with a separator or submenu
1292 *----------------------------------------------*/
1293 if( menu->topic == HELP_none )
1295 if( menu->mnemonic == '-' )
1297 createMenuSeparator(pane, menu->wgtName, SHORT);
1298 menu = menu->next;
1300 else
1302 /*-------------------------------------------------------
1303 * Do not show any of the submenu when it is to be hidden.
1304 *-------------------------------------------------------*/
1305 if( menu->hideIt == hideIt || menu->hideIt == NON_MENU_HELP )
1307 do { menu = menu->next;
1308 } while( menu != NULL && menu->level > crntLevel );
1311 else
1313 Widget subPane =
1314 createMenu( pane, menu->wgtName, menu->subTitle,
1315 menu->mnemonic, NULL, FULL);
1317 menu = buildHelpMenu( subPane, menu->next, window );
1322 else
1324 /*---------------------------------------
1325 * Show menu item if not going to hide it.
1326 * This is the easy way out of hiding
1327 * menu items. When entire submenus want
1328 * to be hidden, either the entire branch
1329 * will have to be marked, or this algorithm
1330 * will have to become a lot smarter.
1331 *---------------------------------------*/
1332 if( menu->hideIt != hideIt && menu->hideIt != NON_MENU_HELP )
1333 makeHelpMenuItem(
1334 pane, menu->wgtName, HelpTitles[menu->topic],
1335 menu->mnemonic, helpCB, window, SHORT, menu->topic );
1337 menu = menu->next;
1342 return menu;
1345 /*----------------------------------------------------------------------------*/
1348 ** handle actions called from the context menus of tabs.
1350 static void doTabActionCB(Widget w, XtPointer clientData, XtPointer callData)
1352 Widget menu = MENU_WIDGET(w);
1353 WindowInfo *win, *window = WidgetToWindow(menu);
1355 /* extract the window to be acted upon, see comment in
1356 tabMenuPostAP() for detail */
1357 XtVaGetValues(window->tabMenuPane, XmNuserData, &win, NULL);
1359 HidePointerOnKeyedEvent(win->lastFocus,
1360 ((XmAnyCallbackStruct *)callData)->event);
1361 XtCallActionProc(win->lastFocus, (char *)clientData,
1362 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1365 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData)
1367 Widget menu = MENU_WIDGET(w);
1369 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1370 ((XmAnyCallbackStruct *)callData)->event);
1371 XtCallActionProc(WidgetToWindow(menu)->lastFocus, (char *)clientData,
1372 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1375 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData)
1377 static char *params[1] = {"rect"};
1379 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1380 ((XmAnyCallbackStruct *)callData)->event);
1381 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "paste_clipboard",
1382 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1385 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData)
1387 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1388 ((XmAnyCallbackStruct *)callData)->event);
1389 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1390 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1391 ? "shift_left_by_tab" : "shift_left",
1392 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1395 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData)
1397 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1398 ((XmAnyCallbackStruct *)callData)->event);
1399 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1400 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1401 ? "shift_right_by_tab" : "shift_right",
1402 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1405 static void findCB(Widget w, XtPointer clientData, XtPointer callData)
1407 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1408 ((XmAnyCallbackStruct *)callData)->event);
1409 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_dialog",
1410 ((XmAnyCallbackStruct *)callData)->event,
1411 shiftKeyToDir(callData), 1);
1414 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData)
1416 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1417 ((XmAnyCallbackStruct *)callData)->event);
1418 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_again",
1419 ((XmAnyCallbackStruct *)callData)->event,
1420 shiftKeyToDir(callData), 1);
1423 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData)
1425 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1426 ((XmAnyCallbackStruct *)callData)->event);
1427 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_selection",
1428 ((XmAnyCallbackStruct *)callData)->event,
1429 shiftKeyToDir(callData), 1);
1432 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData)
1434 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1435 ((XmAnyCallbackStruct *)callData)->event);
1436 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1437 "start_incremental_find", ((XmAnyCallbackStruct *)callData)->event,
1438 shiftKeyToDir(callData), 1);
1441 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData)
1443 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1444 ((XmAnyCallbackStruct *)callData)->event);
1445 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_dialog",
1446 ((XmAnyCallbackStruct *)callData)->event,
1447 shiftKeyToDir(callData), 1);
1450 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData)
1452 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1453 ((XmAnyCallbackStruct *)callData)->event);
1454 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_again",
1455 ((XmAnyCallbackStruct *)callData)->event,
1456 shiftKeyToDir(callData), 1);
1459 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData)
1461 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1462 ((XmAnyCallbackStruct *)callData)->event);
1463 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_find_same",
1464 ((XmAnyCallbackStruct *)callData)->event,
1465 shiftKeyToDir(callData), 1);
1468 static void markCB(Widget w, XtPointer clientData, XtPointer callData)
1470 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1471 WindowInfo *window = WidgetToWindow(MENU_WIDGET(w));
1473 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1474 ((XmAnyCallbackStruct *)callData)->event);
1475 if (event->type == KeyPress || event->type == KeyRelease)
1476 BeginMarkCommand(window);
1477 else
1478 XtCallActionProc(window->lastFocus, "mark_dialog", event, NULL, 0);
1481 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData)
1483 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1484 WindowInfo *window = WidgetToWindow(MENU_WIDGET(w));
1485 int extend = event->xbutton.state & ShiftMask;
1486 static char *params[1] = {"extend"};
1488 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1489 ((XmAnyCallbackStruct *)callData)->event);
1490 if (event->type == KeyPress || event->type == KeyRelease)
1491 BeginGotoMarkCommand(window, extend);
1492 else
1493 XtCallActionProc(window->lastFocus, "goto_mark_dialog", event, params,
1494 extend ? 1 : 0);
1497 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData)
1499 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1500 ((XmAnyCallbackStruct *)callData)->event);
1501 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1502 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1503 ? "select_to_matching" : "goto_matching",
1504 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1507 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData)
1509 static char *params[1] = {"off"};
1510 Widget menu = MENU_WIDGET(w);
1512 window = WidgetToWindow(menu);
1514 #ifdef SGI_CUSTOM
1515 if (shortPrefAskDefault(window->shell, w, "Auto Indent Off")) {
1516 autoIndentOffDefCB(w, window, callData);
1517 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1519 #endif
1520 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1521 ((XmAnyCallbackStruct *)callData)->event);
1522 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1523 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1526 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1528 static char *params[1] = {"on"};
1529 Widget menu = MENU_WIDGET(w);
1531 window = WidgetToWindow(menu);
1533 #ifdef SGI_CUSTOM
1534 if (shortPrefAskDefault(window->shell, w, "Auto Indent")) {
1535 autoIndentDefCB(w, window, callData);
1536 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1538 #endif
1539 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1540 ((XmAnyCallbackStruct *)callData)->event);
1541 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1542 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1545 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1547 static char *params[1] = {"smart"};
1548 Widget menu = MENU_WIDGET(w);
1550 window = WidgetToWindow(menu);
1552 #ifdef SGI_CUSTOM
1553 if (shortPrefAskDefault(window->shell, w, "Smart Indent")) {
1554 smartIndentDefCB(w, window, callData);
1555 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1557 #endif
1558 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1559 ((XmAnyCallbackStruct *)callData)->event);
1560 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1561 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1564 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData)
1566 Widget menu = MENU_WIDGET(w);
1568 window = WidgetToWindow(menu);
1570 #ifdef SGI_CUSTOM
1571 if (shortPrefAskDefault(window->shell, w, "Incremental Backup")) {
1572 autoSaveDefCB(w, window, callData);
1573 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1575 #endif
1576 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1577 ((XmAnyCallbackStruct *)callData)->event);
1578 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_incremental_backup",
1579 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1582 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData)
1584 Widget menu = MENU_WIDGET(w);
1586 window = WidgetToWindow(menu);
1588 #ifdef SGI_CUSTOM
1589 if (shortPrefAskDefault(window->shell, w, "Make Backup Copy")) {
1590 preserveDefCB(w, window, callData);
1591 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1593 #endif
1594 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1595 ((XmAnyCallbackStruct *)callData)->event);
1596 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_make_backup_copy",
1597 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1600 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData)
1602 static char *params[1] = {NO_FLASH_STRING};
1603 Widget menu = MENU_WIDGET(w);
1605 window = WidgetToWindow(menu);
1607 #ifdef SGI_CUSTOM
1608 if (shortPrefAskDefault(window->shell, w, "Show Matching Off")) {
1609 showMatchingOffDefCB(w, window, callData);
1610 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1612 #endif
1613 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1614 ((XmAnyCallbackStruct *)callData)->event);
1615 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1616 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1619 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData)
1621 static char *params[1] = {FLASH_DELIMIT_STRING};
1622 Widget menu = MENU_WIDGET(w);
1624 window = WidgetToWindow(menu);
1626 #ifdef SGI_CUSTOM
1627 if (shortPrefAskDefault(window->shell, w, "Show Matching Delimiter")) {
1628 showMatchingDelimitDefCB(w, window, callData);
1629 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1631 #endif
1632 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1633 ((XmAnyCallbackStruct *)callData)->event);
1634 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1635 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1638 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData)
1640 static char *params[1] = {FLASH_RANGE_STRING};
1641 Widget menu = MENU_WIDGET(w);
1643 window = WidgetToWindow(menu);
1645 #ifdef SGI_CUSTOM
1646 if (shortPrefAskDefault(window->shell, w, "Show Matching Range")) {
1647 showMatchingRangeDefCB(w, window, callData);
1648 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1650 #endif
1651 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1652 ((XmAnyCallbackStruct *)callData)->event);
1653 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1654 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1657 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
1659 Widget menu = MENU_WIDGET(w);
1661 window = WidgetToWindow(menu);
1663 #ifdef SGI_CUSTOM
1664 if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
1665 matchSyntaxBasedDefCB(w, window, callData);
1666 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1668 #endif
1669 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1670 ((XmAnyCallbackStruct *)callData)->event);
1671 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
1672 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1675 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
1677 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), True);
1680 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1682 static char *params[1] = {"none"};
1683 Widget menu = MENU_WIDGET(w);
1685 window = WidgetToWindow(menu);
1687 #ifdef SGI_CUSTOM
1688 if (shortPrefAskDefault(window->shell, w, "No Wrap")) {
1689 noWrapDefCB(w, window, callData);
1690 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1692 #endif
1693 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1694 ((XmAnyCallbackStruct *)callData)->event);
1695 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1696 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1699 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1701 static char *params[1] = {"auto"};
1702 Widget menu = MENU_WIDGET(w);
1704 window = WidgetToWindow(menu);
1706 #ifdef SGI_CUSTOM
1707 if (shortPrefAskDefault(window->shell, w, "Auto Newline Wrap")) {
1708 newlineWrapDefCB(w, window, callData);
1709 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1711 #endif
1712 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1713 ((XmAnyCallbackStruct *)callData)->event);
1714 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1715 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1718 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1720 static char *params[1] = {"continuous"};
1721 Widget menu = MENU_WIDGET(w);
1723 window = WidgetToWindow(menu);
1725 #ifdef SGI_CUSTOM
1726 if (shortPrefAskDefault(window->shell, w, "Continuous Wrap")) {
1727 contWrapDefCB(w, window, callData);
1728 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1730 #endif
1731 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1732 ((XmAnyCallbackStruct *)callData)->event);
1733 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1734 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1737 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData)
1739 window = WidgetToWindow(MENU_WIDGET(w));
1741 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1742 ((XmAnyCallbackStruct *)callData)->event);
1743 WrapMarginDialog(window->shell, window);
1746 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData)
1748 int applyBacklight = XmToggleButtonGetState(w);
1749 window = WidgetToWindow(MENU_WIDGET(w));
1750 SetBacklightChars(window, applyBacklight?GetPrefBacklightCharTypes():NULL);
1753 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData)
1755 window = WidgetToWindow(MENU_WIDGET(w));
1757 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1758 ((XmAnyCallbackStruct *)callData)->event);
1759 TabsPrefDialog(window->shell, window);
1762 static void statsCB(Widget w, WindowInfo *window, caddr_t callData)
1764 Widget menu = MENU_WIDGET(w);
1766 window = WidgetToWindow(menu);
1768 #ifdef SGI_CUSTOM
1769 if (shortPrefAskDefault(window->shell, w, "Statistics Line")) {
1770 statsLineDefCB(w, window, callData);
1771 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1773 #endif
1774 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1775 ((XmAnyCallbackStruct *)callData)->event);
1776 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_statistics_line",
1777 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1780 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1782 WindowInfo *win;
1784 /* Set the preference and make the other windows' menus agree */
1785 SetPrefAutoIndent(NO_AUTO_INDENT);
1786 for (win=WindowList; win!=NULL; win=win->next) {
1787 if (!IsTopDocument(win))
1788 continue;
1789 XmToggleButtonSetState(win->autoIndentOffDefItem, True, False);
1790 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1791 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1795 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1797 WindowInfo *win;
1799 /* Set the preference and make the other windows' menus agree */
1800 SetPrefAutoIndent(AUTO_INDENT);
1801 for (win=WindowList; win!=NULL; win=win->next) {
1802 if (!IsTopDocument(win))
1803 continue;
1804 XmToggleButtonSetState(win->autoIndentDefItem, True, False);
1805 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1806 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1810 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1812 WindowInfo *win;
1814 /* Set the preference and make the other windows' menus agree */
1815 SetPrefAutoIndent(SMART_INDENT);
1816 for (win=WindowList; win!=NULL; win=win->next) {
1817 if (!IsTopDocument(win))
1818 continue;
1819 XmToggleButtonSetState(win->smartIndentDefItem, True, False);
1820 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1821 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1825 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1827 WindowInfo *win;
1828 int state = XmToggleButtonGetState(w);
1830 /* Set the preference and make the other windows' menus agree */
1831 SetPrefAutoSave(state);
1832 for (win=WindowList; win!=NULL; win=win->next) {
1833 if (IsTopDocument(win))
1834 XmToggleButtonSetState(win->autoSaveDefItem, state, False);
1838 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1840 WindowInfo *win;
1841 int state = XmToggleButtonGetState(w);
1843 /* Set the preference and make the other windows' menus agree */
1844 SetPrefSaveOldVersion(state);
1845 for (win=WindowList; win!=NULL; win=win->next) {
1846 if (IsTopDocument(win))
1847 XmToggleButtonSetState(win->saveLastDefItem, state, False);
1851 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData)
1853 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1854 ((XmAnyCallbackStruct *)callData)->event);
1855 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), False);
1858 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData)
1860 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1861 ((XmAnyCallbackStruct *)callData)->event);
1862 ChooseColors(WidgetToWindow(MENU_WIDGET(w)));
1865 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1867 WindowInfo *win;
1869 /* Set the preference and make the other windows' menus agree */
1870 SetPrefWrap(NO_WRAP);
1871 for (win=WindowList; win!=NULL; win=win->next) {
1872 if (!IsTopDocument(win))
1873 continue;
1874 XmToggleButtonSetState(win->noWrapDefItem, True, False);
1875 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1876 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1880 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1882 WindowInfo *win;
1884 /* Set the preference and make the other windows' menus agree */
1885 SetPrefWrap(NEWLINE_WRAP);
1886 for (win=WindowList; win!=NULL; win=win->next) {
1887 if (!IsTopDocument(win))
1888 continue;
1889 XmToggleButtonSetState(win->newlineWrapDefItem, True, False);
1890 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1891 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1895 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1897 WindowInfo *win;
1899 /* Set the preference and make the other windows' menus agree */
1900 SetPrefWrap(CONTINUOUS_WRAP);
1901 for (win=WindowList; win!=NULL; win=win->next) {
1902 if (!IsTopDocument(win))
1903 continue;
1904 XmToggleButtonSetState(win->contWrapDefItem, True, False);
1905 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1906 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1910 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData)
1912 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1913 ((XmAnyCallbackStruct *)callData)->event);
1914 WrapMarginDialog(WidgetToWindow(MENU_WIDGET(w))->shell, NULL);
1917 static void smartTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1919 WindowInfo *win;
1921 SetPrefSmartTags(True);
1922 for (win=WindowList; win!=NULL; win=win->next) {
1923 if (!IsTopDocument(win))
1924 continue;
1925 XmToggleButtonSetState(win->smartTagsDefItem, True, False);
1926 XmToggleButtonSetState(win->allTagsDefItem, False, False);
1930 static void showAllTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1932 WindowInfo *win;
1934 SetPrefSmartTags(False);
1935 for (win=WindowList; win!=NULL; win=win->next) {
1936 if (!IsTopDocument(win))
1937 continue;
1938 XmToggleButtonSetState(win->smartTagsDefItem, False, False);
1939 XmToggleButtonSetState(win->allTagsDefItem, True, False);
1943 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1945 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1946 ((XmAnyCallbackStruct *)callData)->event);
1947 TabsPrefDialog(WidgetToWindow(MENU_WIDGET(w))->shell, NULL);
1950 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1952 WindowInfo *win;
1954 /* Set the preference and make the other windows' menus agree */
1955 SetPrefShowMatching(NO_FLASH);
1956 for (win=WindowList; win!=NULL; win=win->next) {
1957 if (!IsTopDocument(win))
1958 continue;
1959 XmToggleButtonSetState(win->showMatchingOffDefItem, True, False);
1960 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1961 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1965 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData)
1967 WindowInfo *win;
1969 /* Set the preference and make the other windows' menus agree */
1970 SetPrefShowMatching(FLASH_DELIMIT);
1971 for (win=WindowList; win!=NULL; win=win->next) {
1972 if (!IsTopDocument(win))
1973 continue;
1974 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1975 XmToggleButtonSetState(win->showMatchingDelimitDefItem, True, False);
1976 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1980 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData)
1982 WindowInfo *win;
1984 /* Set the preference and make the other windows' menus agree */
1985 SetPrefShowMatching(FLASH_RANGE);
1986 for (win=WindowList; win!=NULL; win=win->next) {
1987 if (!IsTopDocument(win))
1988 continue;
1989 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1990 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1991 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
1995 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
1997 WindowInfo *win;
1999 int state = XmToggleButtonGetState(w);
2001 /* Set the preference and make the other windows' menus agree */
2002 SetPrefMatchSyntaxBased(state);
2003 for (win=WindowList; win!=NULL; win=win->next) {
2004 if (IsTopDocument(win))
2005 XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
2009 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2011 WindowInfo *win;
2012 int state = XmToggleButtonGetState(w);
2014 /* Set the preference and make the other windows' menus agree */
2015 SetPrefBacklightChars(state);
2016 for (win=WindowList; win!=NULL; win=win->next) {
2017 if (IsTopDocument(win))
2018 XmToggleButtonSetState(win->backlightCharsDefItem, state, False);
2022 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
2024 WindowInfo *win;
2026 /* Set the preference and make the other windows' menus agree */
2027 SetPrefHighlightSyntax(False);
2028 for (win=WindowList; win!=NULL; win=win->next) {
2029 if (!IsTopDocument(win))
2030 continue;
2031 XmToggleButtonSetState(win->highlightOffDefItem, True, False);
2032 XmToggleButtonSetState(win->highlightDefItem, False, False);
2036 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData)
2038 WindowInfo *win;
2040 /* Set the preference and make the other windows' menus agree */
2041 SetPrefHighlightSyntax(True);
2042 for (win=WindowList; win!=NULL; win=win->next) {
2043 if (!IsTopDocument(win))
2044 continue;
2045 XmToggleButtonSetState(win->highlightOffDefItem, False, False);
2046 XmToggleButtonSetState(win->highlightDefItem, True, False);
2050 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData)
2052 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2053 ((XmAnyCallbackStruct *)callData)->event);
2054 EditHighlightPatterns(WidgetToWindow(MENU_WIDGET(w)));
2057 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData)
2059 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2060 ((XmAnyCallbackStruct *)callData)->event);
2061 EditSmartIndentMacros(WidgetToWindow(MENU_WIDGET(w)));
2064 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData)
2066 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2067 ((XmAnyCallbackStruct *)callData)->event);
2068 EditHighlightStyles(NULL);
2071 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData)
2073 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2074 ((XmAnyCallbackStruct *)callData)->event);
2075 EditLanguageModes();
2078 #ifndef VMS
2079 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData)
2081 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2082 ((XmAnyCallbackStruct *)callData)->event);
2083 EditShellMenu(WidgetToWindow(MENU_WIDGET(w)));
2085 #endif /* VMS */
2087 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData)
2089 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2090 ((XmAnyCallbackStruct *)callData)->event);
2091 EditMacroMenu(WidgetToWindow(MENU_WIDGET(w)));
2094 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
2096 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2097 ((XmAnyCallbackStruct *)callData)->event);
2098 EditBGMenu(WidgetToWindow(MENU_WIDGET(w)));
2101 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData)
2103 window = WidgetToWindow(MENU_WIDGET(w));
2105 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2106 ((XmAnyCallbackStruct *)callData)->event);
2107 EditCustomTitleFormat(window);
2110 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2112 WindowInfo *win;
2113 int state = XmToggleButtonGetState(w);
2115 /* Set the preference and make the other windows' menus agree */
2116 SetPrefSearchDlogs(state);
2117 for (win=WindowList; win!=NULL; win=win->next) {
2118 if (IsTopDocument(win))
2119 XmToggleButtonSetState(win->searchDlogsDefItem, state, False);
2123 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
2125 WindowInfo *win;
2126 int state = XmToggleButtonGetState(w);
2128 /* Set the preference and make the other windows' menus agree */
2129 SetPrefBeepOnSearchWrap(state);
2130 for (win=WindowList; win!=NULL; win=win->next) {
2131 if (IsTopDocument(win))
2132 XmToggleButtonSetState(win->beepOnSearchWrapDefItem, state, False);
2136 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2138 WindowInfo *win;
2139 int state = XmToggleButtonGetState(w);
2141 /* Set the preference and make the other windows' menus agree */
2142 SetPrefKeepSearchDlogs(state);
2143 for (win=WindowList; win!=NULL; win=win->next) {
2144 if (IsTopDocument(win))
2145 XmToggleButtonSetState(win->keepSearchDlogsDefItem, state, False);
2149 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2151 WindowInfo *win;
2152 int state = XmToggleButtonGetState(w);
2154 /* Set the preference and make the other windows' menus agree */
2155 SetPrefSearchWraps(state);
2156 for (win=WindowList; win!=NULL; win=win->next) {
2157 if (IsTopDocument(win))
2158 XmToggleButtonSetState(win->searchWrapsDefItem, state, False);
2162 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData)
2164 WindowInfo *win;
2165 int state = XmToggleButtonGetState(w);
2167 SetPrefAppendLF(state);
2168 for (win = WindowList; win != NULL; win = win->next) {
2169 if (IsTopDocument(win))
2170 XmToggleButtonSetState(win->appendLFItem, state, False);
2174 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData)
2176 WindowInfo *win;
2177 int state = XmToggleButtonGetState(w);
2179 /* Set the preference, make the other windows' menus agree,
2180 and invalidate their Open Previous menus */
2181 SetPrefSortOpenPrevMenu(state);
2182 for (win=WindowList; win!=NULL; win=win->next) {
2183 win->prevOpenMenuValid = False;
2184 if (IsTopDocument(win))
2185 XmToggleButtonSetState(win->sortOpenPrevDefItem, state, False);
2189 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2191 WindowInfo *win;
2192 int state = XmToggleButtonGetState(w);
2194 /* Set the preference and make the other windows' menus agree */
2195 SetPrefRepositionDialogs(state);
2196 SetPointerCenteredDialogs(state);
2197 for (win=WindowList; win!=NULL; win=win->next) {
2198 if (IsTopDocument(win))
2199 XmToggleButtonSetState(win->reposDlogsDefItem, state, False);
2203 static void autoScrollDefCB(Widget w, WindowInfo *window, caddr_t callData)
2205 WindowInfo *win;
2206 int state = XmToggleButtonGetState(w);
2208 /* Set the preference and make the other windows' menus agree */
2209 SetPrefAutoScroll(state);
2210 /* XXX: Should we ensure auto-scroll now if needed? */
2211 for (win=WindowList; win!=NULL; win=win->next) {
2212 if (IsTopDocument(win))
2213 XmToggleButtonSetState(win->autoScrollDefItem, state, False);
2217 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
2219 WindowInfo *win;
2220 int state = XmToggleButtonGetState(w);
2222 /* Set the preference and make the other windows' menus agree */
2223 SetPrefWarnFileMods(state);
2224 for (win=WindowList; win!=NULL; win=win->next) {
2225 if (!IsTopDocument(win))
2226 continue;
2227 XmToggleButtonSetState(win->modWarnDefItem, state, False);
2228 XtSetSensitive(win->modWarnRealDefItem, state);
2232 static void modWarnRealDefCB(Widget w, WindowInfo *window, caddr_t callData)
2234 WindowInfo *win;
2235 int state = XmToggleButtonGetState(w);
2237 /* Set the preference and make the other windows' menus agree */
2238 SetPrefWarnRealFileMods(state);
2239 for (win=WindowList; win!=NULL; win=win->next) {
2240 if (IsTopDocument(win))
2241 XmToggleButtonSetState(win->modWarnRealDefItem, state, False);
2245 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
2247 WindowInfo *win;
2248 int state = XmToggleButtonGetState(w);
2250 /* Set the preference and make the other windows' menus agree */
2251 SetPrefWarnExit(state);
2252 for (win=WindowList; win!=NULL; win=win->next) {
2253 if (IsTopDocument(win))
2254 XmToggleButtonSetState(win->exitWarnDefItem, state, False);
2258 static void openInTabDefCB(Widget w, WindowInfo *window, caddr_t callData)
2260 WindowInfo *win;
2261 int state = XmToggleButtonGetState(w);
2263 /* Set the preference and make the other windows' menus agree */
2264 SetPrefOpenInTab(state);
2265 for (win=WindowList; win!=NULL; win=win->next)
2266 XmToggleButtonSetState(win->openInTabDefItem, state, False);
2269 static void tabBarDefCB(Widget w, WindowInfo *window, caddr_t callData)
2271 WindowInfo *win;
2272 int state = XmToggleButtonGetState(w);
2274 /* Set the preference and make the other windows' menus agree */
2275 SetPrefTabBar(state);
2276 for (win=WindowList; win!=NULL; win=win->next) {
2277 if (!IsTopDocument(win))
2278 continue;
2279 XmToggleButtonSetState(win->tabBarDefItem, state, False);
2280 ShowWindowTabBar(win);
2284 static void tabBarHideDefCB(Widget w, WindowInfo *window, caddr_t callData)
2286 WindowInfo *win;
2287 int state = XmToggleButtonGetState(w);
2289 /* Set the preference and make the other windows' menus agree */
2290 SetPrefTabBarHideOne(state);
2291 for (win=WindowList; win!=NULL; win=win->next) {
2292 if (!IsTopDocument(win))
2293 continue;
2294 XmToggleButtonSetState(win->tabBarHideDefItem, state, False);
2295 ShowWindowTabBar(win);
2299 static void toolTipsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2301 WindowInfo *win;
2302 int state = XmToggleButtonGetState(w);
2304 /* Set the preference and make the other windows' menus agree */
2305 SetPrefToolTips(state);
2306 for (win=WindowList; win!=NULL; win=win->next) {
2307 XtVaSetValues(win->tab, XltNshowBubble, GetPrefToolTips(), NULL);
2308 if (IsTopDocument(win))
2309 XmToggleButtonSetState(win->toolTipsDefItem, state, False);
2313 static void tabNavigateDefCB(Widget w, WindowInfo *window, caddr_t callData)
2315 WindowInfo *win;
2316 int state = XmToggleButtonGetState(w);
2318 /* Set the preference and make the other windows' menus agree */
2319 SetPrefGlobalTabNavigate(state);
2320 for (win=WindowList; win!=NULL; win=win->next) {
2321 if (IsTopDocument(win))
2322 XmToggleButtonSetState(win->tabNavigateDefItem, state, False);
2326 static void tabSortDefCB(Widget w, WindowInfo *window, caddr_t callData)
2328 WindowInfo *win;
2329 int state = XmToggleButtonGetState(w);
2331 /* Set the preference and make the other windows' menus agree */
2332 SetPrefSortTabs(state);
2333 for (win=WindowList; win!=NULL; win=win->next) {
2334 if (IsTopDocument(win))
2335 XmToggleButtonSetState(win->tabSortDefItem, state, False);
2338 /* If we just enabled sorting, sort all tabs. Note that this reorders
2339 the next pointers underneath us, which is scary, but SortTabBar never
2340 touches windows that are earlier in the WindowList so it's ok. */
2341 if (state) {
2342 Widget shell=(Widget)0;
2343 for (win=WindowList; win!=NULL; win=win->next) {
2344 if ( win->shell != shell ) {
2345 SortTabBar(win);
2346 shell = win->shell;
2352 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
2354 WindowInfo *win;
2355 int state = XmToggleButtonGetState(w);
2357 /* Set the preference and make the other windows' menus agree */
2358 SetPrefStatsLine(state);
2359 for (win=WindowList; win!=NULL; win=win->next) {
2360 if (IsTopDocument(win))
2361 XmToggleButtonSetState(win->statsLineDefItem, state, False);
2365 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
2367 WindowInfo *win;
2368 int state = XmToggleButtonGetState(w);
2370 /* Set the preference and make the other windows' menus agree */
2371 SetPrefISearchLine(state);
2372 for (win=WindowList; win!=NULL; win=win->next) {
2373 if (IsTopDocument(win))
2374 XmToggleButtonSetState(win->iSearchLineDefItem, state, False);
2378 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2380 WindowInfo *win;
2381 int state = XmToggleButtonGetState(w);
2383 /* Set the preference and make the other windows' menus agree */
2384 SetPrefLineNums(state);
2385 for (win=WindowList; win!=NULL; win=win->next) {
2386 if (IsTopDocument(win))
2387 XmToggleButtonSetState(win->lineNumsDefItem, state, False);
2391 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
2393 WindowInfo *win;
2394 int state = XmToggleButtonGetState(w);
2396 /* Set the preference and make the other windows' menus agree */
2397 SetPrefShowPathInWindowsMenu(state);
2398 for (win=WindowList; win!=NULL; win=win->next) {
2399 if (IsTopDocument(win))
2400 XmToggleButtonSetState(win->pathInWindowsMenuDefItem, state, False);
2402 InvalidateWindowMenus();
2405 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData)
2407 WindowInfo *win;
2409 /* Set the preference and make the other windows' menus agree */
2410 if (XmToggleButtonGetState(w)) {
2411 SetPrefSearch(SEARCH_LITERAL);
2412 for (win=WindowList; win!=NULL; win=win->next){
2413 if (!IsTopDocument(win))
2414 continue;
2415 XmToggleButtonSetState(win->searchLiteralDefItem, True, False);
2416 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2417 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2418 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2419 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2420 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2425 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData)
2427 WindowInfo *win;
2429 /* Set the preference and make the other windows' menus agree */
2430 if (XmToggleButtonGetState(w)) {
2431 SetPrefSearch(SEARCH_CASE_SENSE);
2432 for (win=WindowList; win!=NULL; win=win->next) {
2433 if (!IsTopDocument(win))
2434 continue;
2435 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2436 XmToggleButtonSetState(win->searchCaseSenseDefItem, True, False);
2437 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2438 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2439 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2440 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2445 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData)
2447 WindowInfo *win;
2449 /* Set the preference and make the other windows' menus agree */
2450 if (XmToggleButtonGetState(w)) {
2451 SetPrefSearch(SEARCH_LITERAL_WORD);
2452 for (win=WindowList; win!=NULL; win=win->next){
2453 if (!IsTopDocument(win))
2454 continue;
2455 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2456 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2457 XmToggleButtonSetState(win->searchLiteralWordDefItem, True, False);
2458 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2459 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2460 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2465 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData)
2467 WindowInfo *win;
2469 /* Set the preference and make the other windows' menus agree */
2470 if (XmToggleButtonGetState(w)) {
2471 SetPrefSearch(SEARCH_CASE_SENSE_WORD);
2472 for (win=WindowList; win!=NULL; win=win->next) {
2473 if (!IsTopDocument(win))
2474 continue;
2475 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2476 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2477 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2478 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, True, False);
2479 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2480 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2485 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData)
2487 WindowInfo *win;
2489 /* Set the preference and make the other windows' menus agree */
2490 if (XmToggleButtonGetState(w)) {
2491 SetPrefSearch(SEARCH_REGEX);
2492 for (win=WindowList; win!=NULL; win=win->next){
2493 if (!IsTopDocument(win))
2494 continue;
2495 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2496 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2497 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2498 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2499 XmToggleButtonSetState(win->searchRegexDefItem, True, False);
2500 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2505 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData)
2507 WindowInfo *win;
2509 /* Set the preference and make the other windows' menus agree */
2510 if (XmToggleButtonGetState(w)) {
2511 SetPrefSearch(SEARCH_REGEX_NOCASE);
2512 for (win=WindowList; win!=NULL; win=win->next){
2513 if (!IsTopDocument(win))
2514 continue;
2515 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2516 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2517 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2518 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2519 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2520 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, True, False);
2525 #ifdef REPLACE_SCOPE
2526 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData)
2528 WindowInfo *win;
2530 /* Set the preference and make the other windows' menus agree */
2531 if (XmToggleButtonGetState(w)) {
2532 SetPrefReplaceDefScope(REPL_DEF_SCOPE_WINDOW);
2533 for (win=WindowList; win!=NULL; win=win->next){
2534 if (!IsTopDocument(win))
2535 continue;
2536 XmToggleButtonSetState(win->replScopeWinDefItem, True, False);
2537 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2538 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2543 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData)
2545 WindowInfo *win;
2547 /* Set the preference and make the other windows' menus agree */
2548 if (XmToggleButtonGetState(w)) {
2549 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SELECTION);
2550 for (win=WindowList; win!=NULL; win=win->next){
2551 if (!IsTopDocument(win))
2552 continue;
2553 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2554 XmToggleButtonSetState(win->replScopeSelDefItem, True, False);
2555 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2560 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData)
2562 WindowInfo *win;
2564 /* Set the preference and make the other windows' menus agree */
2565 if (XmToggleButtonGetState(w)) {
2566 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SMART);
2567 for (win=WindowList; win!=NULL; win=win->next){
2568 if (!IsTopDocument(win))
2569 continue;
2570 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2571 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2572 XmToggleButtonSetState(win->replScopeSmartDefItem, True, False);
2576 #endif
2578 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData)
2580 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2581 ((XmAnyCallbackStruct *)callData)->event);
2582 setWindowSizeDefault(24, 80);
2585 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData)
2587 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2588 ((XmAnyCallbackStruct *)callData)->event);
2589 setWindowSizeDefault(40, 80);
2592 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData)
2594 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2595 ((XmAnyCallbackStruct *)callData)->event);
2596 setWindowSizeDefault(60, 80);
2599 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData)
2601 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2602 ((XmAnyCallbackStruct *)callData)->event);
2603 setWindowSizeDefault(80, 80);
2606 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData)
2608 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2609 ((XmAnyCallbackStruct *)callData)->event);
2610 RowColumnPrefDialog(WidgetToWindow(MENU_WIDGET(w))->shell);
2611 updateWindowSizeMenus();
2614 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData)
2616 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2617 ((XmAnyCallbackStruct *)callData)->event);
2618 SaveNEditPrefs(WidgetToWindow(MENU_WIDGET(w))->shell, False);
2621 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData)
2623 static char *params[1] = {"\f"};
2625 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2626 ((XmAnyCallbackStruct *)callData)->event);
2627 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "insert_string",
2628 ((XmAnyCallbackStruct *)callData)->event, params, 1);
2631 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData)
2633 #ifndef VMS
2634 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2635 ((XmAnyCallbackStruct *)callData)->event);
2636 AbortShellCommand(WidgetToWindow(MENU_WIDGET(w)));
2637 #endif
2640 static void learnCB(Widget w, WindowInfo *window, caddr_t callData)
2642 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2643 ((XmAnyCallbackStruct *)callData)->event);
2644 BeginLearn(WidgetToWindow(MENU_WIDGET(w)));
2647 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2649 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2650 ((XmAnyCallbackStruct *)callData)->event);
2651 FinishLearn();
2654 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2656 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2657 ((XmAnyCallbackStruct *)callData)->event);
2658 CancelMacroOrLearn(WidgetToWindow(MENU_WIDGET(w)));
2661 static void replayCB(Widget w, WindowInfo *window, caddr_t callData)
2663 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2664 ((XmAnyCallbackStruct *)callData)->event);
2665 Replay(WidgetToWindow(MENU_WIDGET(w)));
2668 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2670 window = WidgetToWindow(MENU_WIDGET(w));
2672 if (!window->windowMenuValid) {
2673 updateWindowMenu(window);
2674 window->windowMenuValid = True;
2678 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2680 window = WidgetToWindow(MENU_WIDGET(w));
2682 if (!window->prevOpenMenuValid) {
2683 updatePrevOpenMenu(window);
2684 window->prevOpenMenuValid = True;
2688 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2690 updateTagsFileMenu(WidgetToWindow(MENU_WIDGET(w)));
2693 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2695 updateTipsFileMenu(WidgetToWindow(MENU_WIDGET(w)));
2699 ** open a new tab or window.
2701 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2703 WindowInfo *window = WidgetToWindow(w);
2704 int openInTab = GetPrefOpenInTab();
2706 if (*nArgs > 0) {
2707 if (strcmp(args[0], "prefs") == 0) {
2708 /* accept default */;
2710 else if (strcmp(args[0], "tab") == 0) {
2711 openInTab = 1;
2713 else if (strcmp(args[0], "window") == 0) {
2714 openInTab = 0;
2716 else if (strcmp(args[0], "opposite") == 0) {
2717 openInTab = !openInTab;
2719 else {
2720 fprintf(stderr, "nedit: Unknown argument to action procedure \"new\": %s\n", args[0]);
2724 EditNewFile(openInTab? window : NULL, NULL, False, NULL, window->path);
2725 CheckCloseDim();
2729 ** These are just here because our techniques make it hard to bind a menu item
2730 ** to an action procedure that takes arguments. The user doesn't need to know
2731 ** about them -- they can use new( "opposite" ) or new( "tab" ).
2733 static void newOppositeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2735 WindowInfo *window = WidgetToWindow(w);
2737 EditNewFile(GetPrefOpenInTab()? NULL : window, NULL, False, NULL,
2738 window->path);
2739 CheckCloseDim();
2741 static void newTabAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2743 WindowInfo *window = WidgetToWindow(w);
2745 EditNewFile(window, NULL, False, NULL, window->path);
2746 CheckCloseDim();
2749 static void openDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2751 WindowInfo *window = WidgetToWindow(w);
2752 char fullname[MAXPATHLEN], *params[2];
2753 int response;
2754 int n=1;
2756 response = PromptForExistingFile(window, "Open File", fullname);
2757 if (response != GFN_OK)
2758 return;
2759 params[0] = fullname;
2761 if (*nArgs>0 && !strcmp(args[0], "1"))
2762 params[n++] = "1";
2764 XtCallActionProc(window->lastFocus, "open", event, params, n);
2765 CheckCloseDim();
2768 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2770 WindowInfo *window = WidgetToWindow(w);
2771 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
2773 if (*nArgs == 0) {
2774 fprintf(stderr, "nedit: open action requires file argument\n");
2775 return;
2777 if (0 != ParseFilename(args[0], filename, pathname)
2778 || strlen(filename) + strlen(pathname) > MAXPATHLEN - 1) {
2779 fprintf(stderr, "nedit: invalid file name for open action: %s\n",
2780 args[0]);
2781 return;
2783 EditExistingFile(window, filename, pathname, 0, NULL, False,
2784 NULL, GetPrefOpenInTab(), False);
2785 CheckCloseDim();
2788 static void openSelectedAP(Widget w, XEvent *event, String *args,
2789 Cardinal *nArgs)
2791 OpenSelectedFile(WidgetToWindow(w), event->xbutton.time);
2792 CheckCloseDim();
2795 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2797 int preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2799 if (*nArgs > 0) {
2800 if (strcmp(args[0], "prompt") == 0) {
2801 preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2803 else if (strcmp(args[0], "save") == 0) {
2804 preResponse = YES_SBC_DIALOG_RESPONSE;
2806 else if (strcmp(args[0], "nosave") == 0) {
2807 preResponse = NO_SBC_DIALOG_RESPONSE;
2810 CloseFileAndWindow(WidgetToWindow(w), preResponse);
2811 CheckCloseDim();
2814 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2816 WindowInfo *window = WidgetToWindow(w);
2818 if (CheckReadOnly(window))
2819 return;
2820 SaveWindow(window);
2823 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
2824 Cardinal *nArgs)
2826 WindowInfo *window = WidgetToWindow(w);
2827 int response, addWrap, fileFormat;
2828 char fullname[MAXPATHLEN], *params[2];
2830 response = PromptForNewFile(window, "Save File As", fullname,
2831 &fileFormat, &addWrap);
2832 if (response != GFN_OK)
2833 return;
2834 window->fileFormat = fileFormat;
2835 params[0] = fullname;
2836 params[1] = "wrapped";
2837 XtCallActionProc(window->lastFocus, "save_as", event, params, addWrap?2:1);
2840 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2842 if (*nArgs == 0) {
2843 fprintf(stderr, "nedit: save_as action requires file argument\n");
2844 return;
2846 SaveWindowAs(WidgetToWindow(w), args[0],
2847 *nArgs == 2 && !strCaseCmp(args[1], "wrapped"));
2850 static void revertDialogAP(Widget w, XEvent *event, String *args,
2851 Cardinal *nArgs)
2853 WindowInfo *window = WidgetToWindow(w);
2854 int b;
2856 /* re-reading file is irreversible, prompt the user first */
2857 if (window->fileChanged)
2859 b = DialogF(DF_QUES, window->shell, 2, "Discard Changes",
2860 "Discard changes to\n%s%s?", "OK", "Cancel", window->path,
2861 window->filename);
2862 } else
2864 b = DialogF(DF_QUES, window->shell, 2, "Reload File",
2865 "Re-load file\n%s%s?", "Re-read", "Cancel", window->path,
2866 window->filename);
2869 if (b != 1)
2871 return;
2873 XtCallActionProc(window->lastFocus, "revert_to_saved", event, NULL, 0);
2877 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2879 RevertToSaved(WidgetToWindow(w));
2882 static void includeDialogAP(Widget w, XEvent *event, String *args,
2883 Cardinal *nArgs)
2885 WindowInfo *window = WidgetToWindow(w);
2886 char filename[MAXPATHLEN], *params[1];
2887 int response;
2889 if (CheckReadOnly(window))
2890 return;
2891 response = PromptForExistingFile(window, "Include File", filename);
2892 if (response != GFN_OK)
2893 return;
2894 params[0] = filename;
2895 XtCallActionProc(window->lastFocus, "include_file", event, params, 1);
2898 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2900 WindowInfo *window = WidgetToWindow(w);
2902 if (CheckReadOnly(window))
2903 return;
2904 if (*nArgs == 0) {
2905 fprintf(stderr, "nedit: include action requires file argument\n");
2906 return;
2908 IncludeFile(WidgetToWindow(w), args[0]);
2911 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
2912 Cardinal *nArgs)
2914 WindowInfo *window = WidgetToWindow(w);
2915 char filename[MAXPATHLEN], *params[1];
2916 int response;
2918 response = PromptForExistingFile(window, "Load Macro File", filename);
2919 if (response != GFN_OK)
2920 return;
2921 params[0] = filename;
2922 XtCallActionProc(window->lastFocus, "load_macro_file", event, params, 1);
2925 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2927 if (*nArgs == 0) {
2928 fprintf(stderr,"nedit: load_macro_file action requires file argument\n");
2929 return;
2931 ReadMacroFile(WidgetToWindow(w), args[0], True);
2934 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
2935 Cardinal *nArgs)
2937 WindowInfo *window = WidgetToWindow(w);
2938 char filename[MAXPATHLEN], *params[1];
2939 int response;
2941 response = PromptForExistingFile(window, "Load Tags File", filename);
2942 if (response != GFN_OK)
2943 return;
2944 params[0] = filename;
2945 XtCallActionProc(window->lastFocus, "load_tags_file", event, params, 1);
2948 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2950 if (*nArgs == 0) {
2951 fprintf(stderr,"nedit: load_tags_file action requires file argument\n");
2952 return;
2955 if (!AddTagsFile(args[0], TAG))
2957 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1, "Error Reading File",
2958 "Error reading ctags file:\n'%s'\ntags not loaded", "OK",
2959 args[0]);
2963 static void unloadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2965 if (*nArgs == 0) {
2966 fprintf(stderr,
2967 "nedit: unload_tags_file action requires file argument\n");
2968 return;
2971 if (DeleteTagsFile(args[0], TAG, True)) {
2972 WindowInfo *win;
2974 /* refresh the "Unload Tags File" tear-offs after unloading, or
2975 close the tear-offs if all tags files have been unloaded */
2976 for (win=WindowList; win!=NULL; win=win->next) {
2977 if (IsTopDocument(win) &&
2978 !XmIsMenuShell(XtParent(win->unloadTagsMenuPane))) {
2979 if (XtIsSensitive(win->unloadTagsMenuItem))
2980 updateTagsFileMenu(win);
2981 else
2982 _XmDismissTearOff(XtParent(win->unloadTagsMenuPane),
2983 NULL, NULL);
2989 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
2990 Cardinal *nArgs)
2992 WindowInfo *window = WidgetToWindow(w);
2993 char filename[MAXPATHLEN], *params[1];
2994 int response;
2996 response = PromptForExistingFile(window, "Load Calltips File", filename);
2997 if (response != GFN_OK)
2998 return;
2999 params[0] = filename;
3000 XtCallActionProc(window->lastFocus, "load_tips_file", event, params, 1);
3003 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3005 if (*nArgs == 0) {
3006 fprintf(stderr,"nedit: load_tips_file action requires file argument\n");
3007 return;
3010 if (!AddTagsFile(args[0], TIP))
3012 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1, "Error Reading File",
3013 "Error reading tips file:\n'%s'\ntips not loaded", "OK",
3014 args[0]);
3018 static void unloadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3020 if (*nArgs == 0) {
3021 fprintf(stderr,
3022 "nedit: unload_tips_file action requires file argument\n");
3023 return;
3025 /* refresh the "Unload Calltips File" tear-offs after unloading, or
3026 close the tear-offs if all tips files have been unloaded */
3027 if (DeleteTagsFile(args[0], TIP, True)) {
3028 WindowInfo *win;
3030 for (win=WindowList; win!=NULL; win=win->next) {
3031 if (IsTopDocument(win) &&
3032 !XmIsMenuShell(XtParent(win->unloadTipsMenuPane))) {
3033 if (XtIsSensitive(win->unloadTipsMenuItem))
3034 updateTipsFileMenu(win);
3035 else
3036 _XmDismissTearOff(XtParent(win->unloadTipsMenuPane),
3037 NULL, NULL);
3043 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3045 PrintWindow(WidgetToWindow(w), False);
3048 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3050 PrintWindow(WidgetToWindow(w), True);
3053 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3055 WindowInfo *window = WidgetToWindow(w);
3057 if (!CheckPrefsChangesSaved(window->shell))
3058 return;
3060 /* If this is not the last window (more than one window is open),
3061 confirm with the user before exiting. */
3062 if (GetPrefWarnExit() && !(window == WindowList && window->next == NULL)) {
3063 int resp, titleLen, lineLen;
3064 char exitMsg[DF_MAX_MSG_LENGTH], *ptr, *title;
3065 char filename[MAXPATHLEN];
3066 WindowInfo *win;
3068 /* List the windows being edited and make sure the
3069 user really wants to exit */
3070 ptr = exitMsg;
3071 lineLen = 0;
3072 strcpy(ptr, "Editing: "); ptr += 9; lineLen += 9;
3073 for (win=WindowList; win!=NULL; win=win->next) {
3074 sprintf(filename, "%s%s", win->filename, win->fileChanged? "*": "");
3075 title = filename;
3076 titleLen = strlen(title);
3077 if (ptr - exitMsg + titleLen + 30 >= DF_MAX_MSG_LENGTH) {
3078 strcpy(ptr, "..."); ptr += 3;
3079 break;
3081 if (lineLen + titleLen + (win->next==NULL?5:2) > 50) {
3082 *ptr++ = '\n';
3083 lineLen = 0;
3085 if (win->next == NULL) {
3086 sprintf(ptr, "and %s.", title);
3087 ptr += 5 + titleLen;
3088 lineLen += 5 + titleLen;
3089 } else {
3090 sprintf(ptr, "%s, ", title);
3091 ptr += 2 + titleLen;
3092 lineLen += 2 + titleLen;
3095 sprintf(ptr, "\n\nExit NEdit?");
3096 resp = DialogF(DF_QUES, window->shell, 2, "Exit", "%s", "Exit",
3097 "Cancel", exitMsg);
3098 if (resp == 2)
3099 return;
3102 /* Close all files and exit when the last one is closed */
3103 if (CloseAllFilesAndWindows())
3104 exit(EXIT_SUCCESS);
3107 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3109 WindowInfo *window = WidgetToWindow(w);
3111 if (CheckReadOnly(window))
3112 return;
3113 Undo(window);
3116 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3118 WindowInfo *window = WidgetToWindow(w);
3120 if (CheckReadOnly(window))
3121 return;
3122 Redo(window);
3125 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3127 WindowInfo *window = WidgetToWindow(w);
3129 if (CheckReadOnly(window))
3130 return;
3131 BufRemoveSelected(window->buffer);
3134 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3136 WindowInfo *window = WidgetToWindow(w);
3138 BufSelect(window->buffer, 0, window->buffer->length);
3141 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3143 WindowInfo *window = WidgetToWindow(w);
3145 if (CheckReadOnly(window))
3146 return;
3147 ShiftSelection(window, SHIFT_LEFT, False);
3150 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
3151 Cardinal *nArgs)
3153 WindowInfo *window = WidgetToWindow(w);
3155 if (CheckReadOnly(window))
3156 return;
3157 ShiftSelection(window, SHIFT_LEFT, True);
3160 static void shiftRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3162 WindowInfo *window = WidgetToWindow(w);
3164 if (CheckReadOnly(window))
3165 return;
3166 ShiftSelection(window, SHIFT_RIGHT, False);
3169 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
3170 Cardinal *nArgs)
3172 WindowInfo *window = WidgetToWindow(w);
3174 if (CheckReadOnly(window))
3175 return;
3176 ShiftSelection(window, SHIFT_RIGHT, True);
3179 static void findDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3181 DoFindDlog(WidgetToWindow(w), searchDirection(0, args, nArgs),
3182 searchKeepDialogs(0, args, nArgs), searchType(0, args, nArgs),
3183 event->xbutton.time);
3186 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3188 if (*nArgs == 0) {
3189 fprintf(stderr, "nedit: find action requires search string argument\n");
3190 return;
3192 SearchAndSelect(WidgetToWindow(w), searchDirection(1, args, nArgs), args[0],
3193 searchType(1, args, nArgs), searchWrap(1, args, nArgs));
3196 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3198 SearchAndSelectSame(WidgetToWindow(w), searchDirection(0, args, nArgs),
3199 searchWrap(0, args, nArgs));
3202 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3204 SearchForSelected(WidgetToWindow(w), searchDirection(0, args, nArgs),
3205 searchType(0, args, nArgs), searchWrap(0, args, nArgs),
3206 event->xbutton.time);
3209 static void startIncrFindAP(Widget w, XEvent *event, String *args,
3210 Cardinal *nArgs)
3212 BeginISearch(WidgetToWindow(w), searchDirection(0, args, nArgs));
3215 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3217 int i, continued = FALSE;
3218 if (*nArgs == 0) {
3219 fprintf(stderr, "nedit: find action requires search string argument\n");
3220 return;
3222 for (i=1; i<(int)*nArgs; i++)
3223 if (!strCaseCmp(args[i], "continued"))
3224 continued = TRUE;
3225 SearchAndSelectIncremental(WidgetToWindow(w),
3226 searchDirection(1, args, nArgs), args[0],
3227 searchType(1, args, nArgs), searchWrap(1, args, nArgs), continued);
3230 static void replaceDialogAP(Widget w, XEvent *event, String *args,
3231 Cardinal *nArgs)
3233 WindowInfo *window = WidgetToWindow(w);
3235 if (CheckReadOnly(window))
3236 return;
3237 DoFindReplaceDlog(window, searchDirection(0, args, nArgs),
3238 searchKeepDialogs(0, args, nArgs), searchType(0, args, nArgs),
3239 event->xbutton.time);
3242 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3244 WindowInfo *window = WidgetToWindow(w);
3246 if (CheckReadOnly(window))
3247 return;
3248 if (*nArgs < 2) {
3249 fprintf(stderr,
3250 "nedit: replace action requires search and replace string arguments\n");
3251 return;
3253 SearchAndReplace(window, searchDirection(2, args, nArgs),
3254 args[0], args[1], searchType(2, args, nArgs), searchWrap(2, args, nArgs));
3257 static void replaceAllAP(Widget w, XEvent *event, String *args,
3258 Cardinal *nArgs)
3260 WindowInfo *window = WidgetToWindow(w);
3262 if (CheckReadOnly(window))
3263 return;
3264 if (*nArgs < 2) {
3265 fprintf(stderr,
3266 "nedit: replace_all action requires search and replace string arguments\n");
3267 return;
3269 ReplaceAll(window, args[0], args[1], searchType(2, args, nArgs));
3272 static void replaceInSelAP(Widget w, XEvent *event, String *args,
3273 Cardinal *nArgs)
3275 WindowInfo *window = WidgetToWindow(w);
3277 if (CheckReadOnly(window))
3278 return;
3279 if (*nArgs < 2) {
3280 fprintf(stderr,
3281 "nedit: replace_in_selection requires search and replace string arguments\n");
3282 return;
3284 ReplaceInSelection(window, args[0], args[1],
3285 searchType(2, args, nArgs));
3288 static void replaceSameAP(Widget w, XEvent *event, String *args,
3289 Cardinal *nArgs)
3291 WindowInfo *window = WidgetToWindow(w);
3293 if (CheckReadOnly(window))
3294 return;
3295 ReplaceSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
3298 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3300 WindowInfo *window = WidgetToWindow(w);
3302 if (CheckReadOnly(window))
3304 return;
3307 if (*nArgs < 2)
3309 DialogF(DF_WARN, window->shell, 1, "Error in replace_find",
3310 "replace_find action requires search and replace string arguments",
3311 "OK");
3312 return;
3315 ReplaceAndSearch(window, searchDirection(2, args, nArgs), args[0], args[1],
3316 searchType(2, args, nArgs), searchWrap(0, args, nArgs));
3319 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
3320 Cardinal *nArgs)
3322 WindowInfo *window = WidgetToWindow(w);
3324 if (CheckReadOnly(window))
3325 return;
3326 ReplaceFindSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
3329 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3331 int lineNum, column, position, curCol;
3333 /* Accept various formats:
3334 [line]:[column] (menu action)
3335 line (macro call)
3336 line, column (macro call) */
3337 if ( *nArgs == 0 ||
3338 *nArgs > 2 ||
3339 (*nArgs == 1 &&
3340 StringToLineAndCol( args[0], &lineNum, &column ) == -1) ||
3341 (*nArgs == 2 &&
3342 (!StringToNum(args[0], &lineNum) ||
3343 !StringToNum(args[1], &column)) ) ) {
3344 fprintf(stderr,"nedit: goto_line_number action requires line and/or column number\n");
3345 return;
3347 /* User specified column, but not line number */
3348 if ( lineNum == -1 ) {
3349 position = TextGetCursorPos(w);
3350 if (TextPosToLineAndCol(w, position, &lineNum,
3351 &curCol) == False) {
3352 return;
3355 /* User didn't specify a column */
3356 else if ( column == -1 ) {
3357 SelectNumberedLine(WidgetToWindow(w), lineNum);
3358 return;
3361 position = TextLineAndColToPos(w, lineNum, column );
3362 if ( position == -1 ) {
3363 return;
3365 TextSetCursorPos(w, position);
3366 return;
3369 static void gotoDialogAP(Widget w, XEvent *event, String *args,
3370 Cardinal *nArgs)
3372 GotoLineNumber(WidgetToWindow(w));
3375 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
3376 Cardinal *nArgs)
3378 GotoSelectedLineNumber(WidgetToWindow(w), event->xbutton.time);
3381 static void repeatDialogAP(Widget w, XEvent *event, String *args,
3382 Cardinal *nArgs)
3384 RepeatDialog(WidgetToWindow(w));
3387 static void repeatMacroAP(Widget w, XEvent *event, String *args,
3388 Cardinal *nArgs)
3390 int how;
3392 if (*nArgs != 2) {
3393 fprintf(stderr, "nedit: repeat_macro requires two arguments\n");
3394 return;
3396 if (!strcmp(args[0], "in_selection"))
3397 how = REPEAT_IN_SEL;
3398 else if (!strcmp(args[0], "to_end"))
3399 how = REPEAT_TO_END;
3400 else if (sscanf(args[0], "%d", &how) != 1) {
3401 fprintf(stderr, "nedit: repeat_macro requires method/count\n");
3402 return;
3404 RepeatMacro(WidgetToWindow(w), args[1], how);
3407 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3409 if (*nArgs == 0 || strlen(args[0]) != 1 ||
3410 !isalnum((unsigned char)args[0][0])) {
3411 fprintf(stderr,"nedit: mark action requires a single-letter label\n");
3412 return;
3414 AddMark(WidgetToWindow(w), w, args[0][0]);
3417 static void markDialogAP(Widget w, XEvent *event, String *args,
3418 Cardinal *nArgs)
3420 MarkDialog(WidgetToWindow(w));
3423 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3425 if (*nArgs == 0 || strlen(args[0]) != 1 ||
3426 !isalnum((unsigned char)args[0][0])) {
3427 fprintf(stderr,
3428 "nedit: goto_mark action requires a single-letter label\n");
3429 return;
3431 GotoMark(WidgetToWindow(w), w, args[0][0], *nArgs > 1 &&
3432 !strcmp(args[1], "extend"));
3435 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
3436 Cardinal *nArgs)
3438 GotoMarkDialog(WidgetToWindow(w), *nArgs!=0 && !strcmp(args[0], "extend"));
3441 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
3442 Cardinal *nArgs)
3444 SelectToMatchingCharacter(WidgetToWindow(w));
3447 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
3448 Cardinal *nArgs)
3450 GotoMatchingCharacter(WidgetToWindow(w));
3453 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3455 FindDefinition(WidgetToWindow(w), event->xbutton.time,
3456 *nArgs == 0 ? NULL : args[0]);
3459 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3461 FindDefCalltip(WidgetToWindow(w), event->xbutton.time,
3462 *nArgs == 0 ? NULL : args[0]);
3465 static void splitPaneAP(Widget w, XEvent *event, String *args,
3466 Cardinal *nArgs)
3468 WindowInfo *window = WidgetToWindow(w);
3470 SplitPane(window);
3471 if (IsTopDocument(window)) {
3472 XtSetSensitive(window->splitPaneItem, window->nPanes < MAX_PANES);
3473 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
3477 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3479 WindowInfo *window = WidgetToWindow(w);
3481 ClosePane(window);
3482 if (IsTopDocument(window)) {
3483 XtSetSensitive(window->splitPaneItem, window->nPanes < MAX_PANES);
3484 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
3488 static void detachDocumentDialogAP(Widget w, XEvent *event, String *args,
3489 Cardinal *nArgs)
3491 WindowInfo *window = WidgetToWindow(w);
3492 int resp;
3494 if (NDocuments(window) < 2)
3495 return;
3497 resp = DialogF(DF_QUES, window->shell, 2, "Detach %s?",
3498 "Detach", "Cancel", window->filename);
3500 if (resp == 1)
3501 DetachDocument(window);
3504 static void detachDocumentAP(Widget w, XEvent *event, String *args,
3505 Cardinal *nArgs)
3507 WindowInfo *window = WidgetToWindow(w);
3509 if (NDocuments(window) < 2)
3510 return;
3512 DetachDocument(window);
3515 static void moveDocumentDialogAP(Widget w, XEvent *event, String *args,
3516 Cardinal *nArgs)
3518 MoveDocumentDialog(WidgetToWindow(w));
3521 static void nextDocumentAP(Widget w, XEvent *event, String *args,
3522 Cardinal *nArgs)
3524 NextDocument(WidgetToWindow(w));
3527 static void prevDocumentAP(Widget w, XEvent *event, String *args,
3528 Cardinal *nArgs)
3530 PreviousDocument(WidgetToWindow(w));
3533 static void lastDocumentAP(Widget w, XEvent *event, String *args,
3534 Cardinal *nArgs)
3536 LastDocument(WidgetToWindow(w));
3539 static void capitalizeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3541 WindowInfo *window = WidgetToWindow(w);
3543 if (CheckReadOnly(window))
3544 return;
3545 UpcaseSelection(window);
3548 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3550 WindowInfo *window = WidgetToWindow(w);
3552 if (CheckReadOnly(window))
3553 return;
3554 DowncaseSelection(window);
3557 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3559 WindowInfo *window = WidgetToWindow(w);
3561 if (CheckReadOnly(window))
3562 return;
3563 FillSelection(window);
3566 static void controlDialogAP(Widget w, XEvent *event, String *args,
3567 Cardinal *nArgs)
3569 WindowInfo *window = WidgetToWindow(w);
3570 unsigned char charCodeString[2];
3571 char charCodeText[DF_MAX_PROMPT_LENGTH], dummy[DF_MAX_PROMPT_LENGTH];
3572 char *params[1];
3573 int charCode, nRead, response;
3575 if (CheckReadOnly(window))
3576 return;
3578 response = DialogF(DF_PROMPT, window->shell, 2, "Insert Ctrl Code",
3579 "ASCII Character Code:", charCodeText, "OK", "Cancel");
3581 if (response == 2)
3582 return;
3583 /* If we don't scan for a trailing string invalid input
3584 would be accepted sometimes. */
3585 nRead = sscanf(charCodeText, "%i%s", &charCode, dummy);
3586 if (nRead != 1 || charCode < 0 || charCode > 255) {
3587 XBell(TheDisplay, 0);
3588 return;
3590 charCodeString[0] = (unsigned char)charCode;
3591 charCodeString[1] = '\0';
3592 params[0] = (char *)charCodeString;
3594 if (!BufSubstituteNullChars((char *)charCodeString, 1, window->buffer))
3596 DialogF(DF_ERR, window->shell, 1, "Error", "Too much binary data",
3597 "OK");
3598 return;
3601 XtCallActionProc(w, "insert_string", event, params, 1);
3604 #ifndef VMS
3605 static void filterDialogAP(Widget w, XEvent *event, String *args,
3606 Cardinal *nArgs)
3608 WindowInfo *window = WidgetToWindow(w);
3609 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3610 int resp;
3611 static char **cmdHistory = NULL;
3612 static int nHistoryCmds = 0;
3614 if (CheckReadOnly(window))
3615 return;
3616 if (!window->buffer->primary.selected) {
3617 XBell(TheDisplay, 0);
3618 return;
3621 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3623 resp = DialogF(DF_PROMPT, window->shell, 2, "Filter Selection",
3624 "Shell command: (use up arrow key to recall previous)",
3625 cmdText, "OK", "Cancel");
3627 if (resp == 2)
3628 return;
3629 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3630 params[0] = cmdText;
3631 XtCallActionProc(w, "filter_selection", event, params, 1);
3634 static void shellFilterAP(Widget w, XEvent *event, String *args,
3635 Cardinal *nArgs)
3637 WindowInfo *window = WidgetToWindow(w);
3639 if (CheckReadOnly(window))
3640 return;
3641 if (*nArgs == 0) {
3642 fprintf(stderr,
3643 "nedit: filter_selection requires shell command argument\n");
3644 return;
3646 FilterSelection(window, args[0],
3647 event->xany.send_event == MACRO_EVENT_MARKER);
3650 static void execDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3652 WindowInfo *window = WidgetToWindow(w);
3653 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3654 int resp;
3655 static char **cmdHistory = NULL;
3656 static int nHistoryCmds = 0;
3658 if (CheckReadOnly(window))
3659 return;
3660 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3662 resp = DialogF(DF_PROMPT, window->shell, 2, "Execute Command",
3663 "Shell command: (use up arrow key to recall previous;\n"
3664 "%% expands to current filename, # to line number)", cmdText, "OK",
3665 "Cancel");
3667 if (resp == 2)
3668 return;
3669 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3670 params[0] = cmdText;
3671 XtCallActionProc(w, "execute_command", event, params, 1);;
3674 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3676 WindowInfo *window = WidgetToWindow(w);
3678 if (CheckReadOnly(window))
3679 return;
3680 if (*nArgs == 0) {
3681 fprintf(stderr,
3682 "nedit: execute_command requires shell command argument\n");
3683 return;
3685 ExecShellCommand(window, args[0],
3686 event->xany.send_event == MACRO_EVENT_MARKER);
3689 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3691 WindowInfo *window = WidgetToWindow(w);
3693 if (CheckReadOnly(window))
3694 return;
3695 ExecCursorLine(window, event->xany.send_event == MACRO_EVENT_MARKER);
3698 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3700 if (*nArgs == 0) {
3701 fprintf(stderr,
3702 "nedit: shell_menu_command requires item-name argument\n");
3703 return;
3705 HidePointerOnKeyedEvent(w, event);
3706 DoNamedShellMenuCmd(WidgetToWindow(w), args[0],
3707 event->xany.send_event == MACRO_EVENT_MARKER);
3709 #endif
3711 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3713 if (*nArgs == 0) {
3714 fprintf(stderr,
3715 "nedit: macro_menu_command requires item-name argument\n");
3716 return;
3718 /* Don't allow users to execute a macro command from the menu (or accel)
3719 if there's already a macro command executing, UNLESS the macro is
3720 directly called from another one. NEdit can't handle
3721 running multiple, independent uncoordinated, macros in the same
3722 window. Macros may invoke macro menu commands recursively via the
3723 macro_menu_command action proc, which is important for being able to
3724 repeat any operation, and to embed macros within eachother at any
3725 level, however, a call here with a macro running means that THE USER
3726 is explicitly invoking another macro via the menu or an accelerator,
3727 UNLESS the macro event marker is set */
3728 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3729 if (WidgetToWindow(w)->macroCmdData != NULL) {
3730 XBell(TheDisplay, 0);
3731 return;
3734 HidePointerOnKeyedEvent(w, event);
3735 DoNamedMacroMenuCmd(WidgetToWindow(w), args[0]);
3738 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3740 if (*nArgs == 0) {
3741 fprintf(stderr,
3742 "nedit: bg_menu_command requires item-name argument\n");
3743 return;
3745 /* Same remark as for macro menu commands (see above). */
3746 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3747 if (WidgetToWindow(w)->macroCmdData != NULL) {
3748 XBell(TheDisplay, 0);
3749 return;
3752 HidePointerOnKeyedEvent(w, event);
3753 DoNamedBGMenuCmd(WidgetToWindow(w), args[0]);
3756 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
3757 Cardinal *nArgs)
3759 textBuffer *buf = TextGetBuffer(w);
3760 int start, end, isRect, rectStart, rectEnd;
3762 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3763 return;
3764 if (!isRect)
3765 TextSetCursorPos(w, start);
3766 else
3767 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3768 BufStartOfLine(buf, start), rectStart));
3771 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
3772 Cardinal *nArgs)
3774 textBuffer *buf = TextGetBuffer(w);
3775 int start, end, isRect, rectStart, rectEnd;
3777 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3778 return;
3779 if (!isRect)
3780 TextSetCursorPos(w, end);
3781 else
3782 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3783 BufStartOfLine(buf, end), rectEnd));
3786 static void raiseWindowAP(Widget w, XEvent *event, String *args,
3787 Cardinal *nArgs)
3789 WindowInfo *window = WidgetToWindow(w);
3790 WindowInfo *nextWindow;
3791 WindowInfo *tmpWindow;
3792 int windowIndex;
3793 Boolean focus = GetPrefFocusOnRaise();
3795 if (*nArgs > 0) {
3796 if (strcmp(args[0], "last") == 0) {
3797 window = WindowList;
3799 else if (strcmp(args[0], "first") == 0) {
3800 window = WindowList;
3801 if (window != NULL) {
3802 nextWindow = window->next;
3803 while (nextWindow != NULL) {
3804 window = nextWindow;
3805 nextWindow = nextWindow->next;
3809 else if (strcmp(args[0], "previous") == 0) {
3810 tmpWindow = window;
3811 window = WindowList;
3812 if (window != NULL) {
3813 nextWindow = window->next;
3814 while (nextWindow != NULL && nextWindow != tmpWindow) {
3815 window = nextWindow;
3816 nextWindow = nextWindow->next;
3818 if (nextWindow == NULL && tmpWindow != WindowList) {
3819 window = NULL;
3823 else if (strcmp(args[0], "next") == 0) {
3824 if (window != NULL) {
3825 window = window->next;
3826 if (window == NULL) {
3827 window = WindowList;
3831 else {
3832 if (sscanf(args[0], "%d", &windowIndex) == 1) {
3833 if (windowIndex > 0) {
3834 for (window = WindowList; window != NULL && windowIndex > 1;
3835 --windowIndex) {
3836 window = window->next;
3839 else if (windowIndex < 0) {
3840 for (window = WindowList; window != NULL;
3841 window = window->next) {
3842 ++windowIndex;
3844 if (windowIndex >= 0) {
3845 for (window = WindowList; window != NULL &&
3846 windowIndex > 0; window = window->next) {
3847 --windowIndex;
3850 else {
3851 window = NULL;
3854 else {
3855 window = NULL;
3858 else {
3859 window = NULL;
3863 if (*nArgs > 1) {
3864 if (strcmp(args[1], "focus") == 0) {
3865 focus = True;
3867 else if (strcmp(args[1], "nofocus") == 0) {
3868 focus = False;
3872 if (window != NULL) {
3873 RaiseFocusDocumentWindow(window, focus);
3875 else {
3876 XBell(TheDisplay, 0);
3880 static void focusPaneAP(Widget w, XEvent *event, String *args,
3881 Cardinal *nArgs)
3883 WindowInfo *window = WidgetToWindow(w);
3884 Widget newFocusPane = NULL;
3885 int paneIndex;
3887 if (*nArgs > 0) {
3888 if (strcmp(args[0], "first") == 0) {
3889 paneIndex = 0;
3891 else if (strcmp(args[0], "last") == 0) {
3892 paneIndex = window->nPanes;
3894 else if (strcmp(args[0], "next") == 0) {
3895 paneIndex = WidgetToPaneIndex(window, window->lastFocus) + 1;
3896 if (paneIndex > window->nPanes) {
3897 paneIndex = 0;
3900 else if (strcmp(args[0], "previous") == 0) {
3901 paneIndex = WidgetToPaneIndex(window, window->lastFocus) - 1;
3902 if (paneIndex < 0) {
3903 paneIndex = window->nPanes;
3906 else {
3907 if (sscanf(args[0], "%d", &paneIndex) == 1) {
3908 if (paneIndex > 0) {
3909 paneIndex = paneIndex - 1;
3911 else if (paneIndex < 0) {
3912 paneIndex = window->nPanes + (paneIndex + 1);
3914 else {
3915 paneIndex = -1;
3919 if (paneIndex >= 0 && paneIndex <= window->nPanes) {
3920 newFocusPane = GetPaneByIndex(window, paneIndex);
3922 if (newFocusPane != NULL) {
3923 window->lastFocus = newFocusPane;
3924 XmProcessTraversal(window->lastFocus, XmTRAVERSE_CURRENT);
3926 else {
3927 XBell(TheDisplay, 0);
3930 else {
3931 fprintf(stderr, "nedit: focus_pane requires argument\n");
3935 #define ACTION_BOOL_PARAM_OR_TOGGLE(newState, numArgs, argvVal, oValue, actionName) \
3936 if ((numArgs) > 0) { \
3937 int intState; \
3939 if (sscanf(argvVal[0], "%d", &intState) == 1) { \
3940 (newState) = (intState != 0); \
3942 else { \
3943 fprintf(stderr, "nedit: %s requires 0 or 1 argument\n", actionName); \
3944 return; \
3947 else { \
3948 (newState) = !(oValue); \
3951 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
3952 Cardinal *nArgs)
3954 WindowInfo *window = WidgetToWindow(w);
3955 Boolean newState;
3957 /* stats line is a shell-level item, so we toggle the button
3958 state regardless of it's 'topness' */
3959 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->showStats,
3960 "set_statistics_line");
3961 XmToggleButtonSetState(window->statsLineItem, newState, False);
3962 ShowStatsLine(window, newState);
3965 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
3966 Cardinal *nArgs)
3968 WindowInfo *window = WidgetToWindow(w);
3969 Boolean newState;
3971 /* i-search line is a shell-level item, so we toggle the button
3972 state regardless of it's 'topness' */
3973 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args,
3974 window->showISearchLine, "set_incremental_search_line");
3975 XmToggleButtonSetState(window->iSearchLineItem, newState, False);
3976 ShowISearchLine(window, newState);
3979 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
3980 Cardinal *nArgs)
3982 WindowInfo *window = WidgetToWindow(w);
3983 Boolean newState;
3985 /* line numbers panel is a shell-level item, so we toggle the button
3986 state regardless of it's 'topness' */
3987 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args,
3988 window->showLineNumbers, "set_show_line_numbers");
3989 XmToggleButtonSetState(window->lineNumsItem, newState, False);
3990 ShowLineNumbers(window, newState);
3993 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
3994 Cardinal *nArgs)
3996 WindowInfo *window = WidgetToWindow(w);
3997 if (*nArgs > 0) {
3998 if (strcmp(args[0], "off") == 0) {
3999 SetAutoIndent(window, NO_AUTO_INDENT);
4001 else if (strcmp(args[0], "on") == 0) {
4002 SetAutoIndent(window, AUTO_INDENT);
4004 else if (strcmp(args[0], "smart") == 0) {
4005 SetAutoIndent(window, SMART_INDENT);
4007 else {
4008 fprintf(stderr, "nedit: set_auto_indent invalid argument\n");
4011 else {
4012 fprintf(stderr, "nedit: set_auto_indent requires argument\n");
4016 static void setWrapTextAP(Widget w, XEvent *event, String *args,
4017 Cardinal *nArgs)
4019 WindowInfo *window = WidgetToWindow(w);
4020 if (*nArgs > 0) {
4021 if (strcmp(args[0], "none") == 0) {
4022 SetAutoWrap(window, NO_WRAP);
4024 else if (strcmp(args[0], "auto") == 0) {
4025 SetAutoWrap(window, NEWLINE_WRAP);
4027 else if (strcmp(args[0], "continuous") == 0) {
4028 SetAutoWrap(window, CONTINUOUS_WRAP);
4030 else {
4031 fprintf(stderr, "nedit: set_wrap_text invalid argument\n");
4034 else {
4035 fprintf(stderr, "nedit: set_wrap_text requires argument\n");
4039 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
4040 Cardinal *nArgs)
4042 WindowInfo *window = WidgetToWindow(w);
4044 if (*nArgs > 0) {
4045 int newMargin = 0;
4046 if (sscanf(args[0], "%d", &newMargin) == 1 &&
4047 newMargin >= 0 &&
4048 newMargin < 1000) {
4049 int i;
4051 XtVaSetValues(window->textArea, textNwrapMargin, newMargin, NULL);
4052 for (i = 0; i < window->nPanes; ++i) {
4053 XtVaSetValues(window->textPanes[i], textNwrapMargin, newMargin, NULL);
4056 else {
4057 fprintf(stderr,
4058 "nedit: set_wrap_margin requires integer argument >= 0 and < 1000\n");
4061 else {
4062 fprintf(stderr, "nedit: set_wrap_margin requires argument\n");
4066 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
4067 Cardinal *nArgs)
4069 WindowInfo *window = WidgetToWindow(w);
4070 Boolean newState;
4072 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->highlightSyntax, "set_highlight_syntax");
4074 if (IsTopDocument(window))
4075 XmToggleButtonSetState(window->highlightItem, newState, False);
4076 window->highlightSyntax = newState;
4077 if (window->highlightSyntax) {
4078 StartHighlighting(window, True);
4079 } else {
4080 StopHighlighting(window);
4084 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
4085 Cardinal *nArgs)
4087 WindowInfo *window = WidgetToWindow(w);
4088 Boolean newState;
4090 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->saveOldVersion, "set_make_backup_copy");
4092 #ifndef VMS
4093 if (IsTopDocument(window))
4094 XmToggleButtonSetState(window->saveLastItem, newState, False);
4095 #endif
4096 window->saveOldVersion = newState;
4099 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
4100 Cardinal *nArgs)
4102 WindowInfo *window = WidgetToWindow(w);
4103 Boolean newState;
4105 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->autoSave, "set_incremental_backup");
4107 if (IsTopDocument(window))
4108 XmToggleButtonSetState(window->autoSaveItem, newState, False);
4109 window->autoSave = newState;
4112 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
4113 Cardinal *nArgs)
4115 WindowInfo *window = WidgetToWindow(w);
4116 if (*nArgs > 0) {
4117 if (strcmp(args[0], NO_FLASH_STRING) == 0) {
4118 SetShowMatching(window, NO_FLASH);
4120 else if (strcmp(args[0], FLASH_DELIMIT_STRING) == 0) {
4121 SetShowMatching(window, FLASH_DELIMIT);
4123 else if (strcmp(args[0], FLASH_RANGE_STRING) == 0) {
4124 SetShowMatching(window, FLASH_RANGE);
4126 /* For backward compatibility with pre-5.2 versions, we also
4127 accept 0 and 1 as aliases for NO_FLASH and FLASH_DELIMIT.
4128 It is quite unlikely, though, that anyone ever used this
4129 action procedure via the macro language or a key binding,
4130 so this can probably be left out safely. */
4131 else if (strcmp(args[0], "0") == 0) {
4132 SetShowMatching(window, NO_FLASH);
4134 else if (strcmp(args[0], "1") == 0) {
4135 SetShowMatching(window, FLASH_DELIMIT);
4137 else {
4138 fprintf(stderr, "nedit: Invalid argument for set_show_matching\n");
4141 else {
4142 fprintf(stderr, "nedit: set_show_matching requires argument\n");
4146 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
4147 Cardinal *nArgs)
4149 WindowInfo *window = WidgetToWindow(w);
4150 Boolean newState;
4152 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
4154 if (IsTopDocument(window))
4155 XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
4156 window->matchSyntaxBased = newState;
4159 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
4160 Cardinal *nArgs)
4162 WindowInfo *window = WidgetToWindow(w);
4163 Boolean newState;
4165 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->overstrike, "set_overtype_mode");
4167 if (IsTopDocument(window))
4168 XmToggleButtonSetState(window->overtypeModeItem, newState, False);
4169 SetOverstrike(window, newState);
4172 static void setLockedAP(Widget w, XEvent *event, String *args,
4173 Cardinal *nArgs)
4175 WindowInfo *window = WidgetToWindow(w);
4176 Boolean newState;
4178 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, IS_USER_LOCKED(window->lockReasons), "set_locked");
4180 SET_USER_LOCKED(window->lockReasons, newState);
4181 if (IsTopDocument(window))
4182 XmToggleButtonSetState(window->readOnlyItem, IS_ANY_LOCKED(window->lockReasons), False);
4183 UpdateWindowTitle(window);
4184 UpdateWindowReadOnly(window);
4187 static void setTabDistAP(Widget w, XEvent *event, String *args,
4188 Cardinal *nArgs)
4190 WindowInfo *window = WidgetToWindow(w);
4192 if (*nArgs > 0) {
4193 int newTabDist = 0;
4194 if (sscanf(args[0], "%d", &newTabDist) == 1 &&
4195 newTabDist > 0 &&
4196 newTabDist <= MAX_EXP_CHAR_LEN) {
4197 SetTabDist(window, newTabDist);
4199 else {
4200 fprintf(stderr,
4201 "nedit: set_tab_dist requires integer argument > 0 and <= %d\n",
4202 MAX_EXP_CHAR_LEN);
4205 else {
4206 fprintf(stderr, "nedit: set_tab_dist requires argument\n");
4210 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
4211 Cardinal *nArgs)
4213 WindowInfo *window = WidgetToWindow(w);
4215 if (*nArgs > 0) {
4216 int newEmTabDist = 0;
4217 if (sscanf(args[0], "%d", &newEmTabDist) == 1 &&
4218 newEmTabDist >= -1 &&
4219 newEmTabDist < 1000) {
4220 if (newEmTabDist < 0) {
4221 newEmTabDist = 0;
4223 SetEmTabDist(window, newEmTabDist);
4225 else {
4226 fprintf(stderr,
4227 "nedit: set_em_tab_dist requires integer argument >= -1 and < 1000\n");
4230 else {
4231 fprintf(stderr, "nedit: set_em_tab_dist requires argument\n");
4235 static void setUseTabsAP(Widget w, XEvent *event, String *args,
4236 Cardinal *nArgs)
4238 WindowInfo *window = WidgetToWindow(w);
4239 Boolean newState;
4241 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->buffer->useTabs, "set_use_tabs");
4243 window->buffer->useTabs = newState;
4246 static void setFontsAP(Widget w, XEvent *event, String *args,
4247 Cardinal *nArgs)
4249 WindowInfo *window = WidgetToWindow(w);
4250 if (*nArgs >= 4) {
4251 SetFonts(window, args[0], args[1], args[2], args[3]);
4253 else {
4254 fprintf(stderr, "nedit: set_fonts requires 4 arguments\n");
4258 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
4259 Cardinal *nArgs)
4261 WindowInfo *window = WidgetToWindow(w);
4263 if (*nArgs > 0) {
4264 SetLanguageMode(window, FindLanguageMode(args[0]), FALSE);
4266 else {
4267 fprintf(stderr, "nedit: set_language_mode requires argument\n");
4272 ** Same as AddSubMenu from libNUtil.a but 1) mnemonic is optional (NEdit
4273 ** users like to be able to re-arrange the mnemonics so they can set Alt
4274 ** key combinations as accelerators), 2) supports the short/full option
4275 ** of SGI_CUSTOM mode, 3) optionally returns the cascade button widget
4276 ** in "cascadeBtn" if "cascadeBtn" is non-NULL.
4278 static Widget createMenu(Widget parent, char *name, char *label,
4279 char mnemonic, Widget *cascadeBtn, int mode)
4281 Widget menu, cascade;
4282 XmString st1;
4284 menu = CreatePulldownMenu(parent, name, NULL, 0);
4285 cascade = XtVaCreateWidget(name, xmCascadeButtonWidgetClass, parent,
4286 XmNlabelString, st1=XmStringCreateSimple(label),
4287 XmNsubMenuId, menu, NULL);
4288 XmStringFree(st1);
4289 if (mnemonic != 0)
4290 XtVaSetValues(cascade, XmNmnemonic, mnemonic, NULL);
4291 #ifdef SGI_CUSTOM
4292 if (mode == SHORT || !GetPrefShortMenus())
4293 XtManageChild(cascade);
4294 if (mode == FULL)
4295 addToToggleShortList(cascade);
4296 #else
4297 XtManageChild(cascade);
4298 #endif
4299 if (cascadeBtn != NULL)
4300 *cascadeBtn = cascade;
4301 return menu;
4305 ** Same as AddMenuItem from libNUtil.a without setting the accelerator
4306 ** (these are set in the fallback app-defaults so users can change them),
4307 ** and with the short/full option required in SGI_CUSTOM mode.
4309 static Widget createMenuItem(Widget parent, char *name, char *label,
4310 char mnemonic, menuCallbackProc callback, void *cbArg, int mode)
4312 Widget button;
4313 XmString st1;
4316 button = XtVaCreateWidget(name, xmPushButtonWidgetClass, parent,
4317 XmNlabelString, st1=XmStringCreateSimple(label),
4318 XmNmnemonic, mnemonic, NULL);
4319 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
4320 XmStringFree(st1);
4321 #ifdef SGI_CUSTOM
4322 if (mode == SHORT || !GetPrefShortMenus())
4323 XtManageChild(button);
4324 if (mode == FULL)
4325 addToToggleShortList(button);
4326 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4327 #else
4328 XtManageChild(button);
4329 #endif
4330 return button;
4334 ** "fake" menu items allow accelerators to be attached, but don't show up
4335 ** in the menu. They are necessary to process the shifted menu items because
4336 ** Motif does not properly process the event descriptions in accelerator
4337 ** resources, and you can't specify "shift key is optional"
4339 static Widget createFakeMenuItem(Widget parent, char *name,
4340 menuCallbackProc callback, void *cbArg)
4342 Widget button;
4343 XmString st1;
4345 button = XtVaCreateManagedWidget(name, xmPushButtonWidgetClass, parent,
4346 XmNlabelString, st1=XmStringCreateSimple(""),
4347 XmNshadowThickness, 0,
4348 XmNmarginHeight, 0,
4349 XmNheight, 0, NULL);
4350 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
4351 XmStringFree(st1);
4352 XtVaSetValues(button, XmNtraversalOn, False, NULL);
4354 return button;
4358 ** Add a toggle button item to an already established pull-down or pop-up
4359 ** menu, including mnemonics, accelerators and callbacks.
4361 static Widget createMenuToggle(Widget parent, char *name, char *label,
4362 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
4363 int mode)
4365 Widget button;
4366 XmString st1;
4368 button = XtVaCreateWidget(name, xmToggleButtonWidgetClass, parent,
4369 XmNlabelString, st1=XmStringCreateSimple(label),
4370 XmNmnemonic, mnemonic,
4371 XmNset, set, NULL);
4372 XtAddCallback(button, XmNvalueChangedCallback, (XtCallbackProc)callback,
4373 cbArg);
4374 XmStringFree(st1);
4375 #ifdef SGI_CUSTOM
4376 if (mode == SHORT || !GetPrefShortMenus())
4377 XtManageChild(button);
4378 if (mode == FULL)
4379 addToToggleShortList(button);
4380 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4381 #else
4382 XtManageChild(button);
4383 #endif
4384 return button;
4388 ** Create a toggle button with a diamond (radio-style) appearance
4390 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
4391 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
4392 int mode)
4394 Widget button;
4395 button = createMenuToggle(parent, name, label, mnemonic, callback, cbArg,
4396 set, mode);
4397 XtVaSetValues(button, XmNindicatorType, XmONE_OF_MANY, NULL);
4398 return button;
4401 static Widget createMenuSeparator(Widget parent, char *name, int mode)
4403 Widget button;
4405 button = XmCreateSeparator(parent, name, NULL, 0);
4406 #ifdef SGI_CUSTOM
4407 if (mode == SHORT || !GetPrefShortMenus())
4408 XtManageChild(button);
4409 if (mode == FULL)
4410 addToToggleShortList(button);
4411 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4412 #else
4413 XtManageChild(button);
4414 #endif
4415 return button;
4419 ** Make sure the close menu item is dimmed appropriately for the current
4420 ** set of windows. It should be dim only for the last Untitled, unmodified,
4421 ** editor window, and sensitive otherwise.
4423 void CheckCloseDim(void)
4425 WindowInfo *window;
4427 if (WindowList == NULL)
4428 return;
4429 if (WindowList->next==NULL &&
4430 !WindowList->filenameSet && !WindowList->fileChanged) {
4431 XtSetSensitive(WindowList->closeItem, FALSE);
4432 return;
4435 for (window=WindowList; window!=NULL; window=window->next) {
4436 if (!IsTopDocument(window))
4437 continue;
4438 XtSetSensitive(window->closeItem, True);
4443 ** Invalidate the Window menus of all NEdit windows to but don't change
4444 ** the menus until they're needed (Originally, this was "UpdateWindowMenus",
4445 ** but creating and destroying manu items for every window every time a
4446 ** new window was created or something changed, made things move very
4447 ** slowly with more than 10 or so windows).
4449 void InvalidateWindowMenus(void)
4451 WindowInfo *w;
4453 /* Mark the window menus invalid (to be updated when the user pulls one
4454 down), unless the menu is torn off, meaning it is visible to the user
4455 and should be updated immediately */
4456 for (w=WindowList; w!=NULL; w=w->next) {
4457 if (!XmIsMenuShell(XtParent(w->windowMenuPane)))
4458 updateWindowMenu(w);
4459 else
4460 w->windowMenuValid = False;
4465 ** Mark the Previously Opened Files menus of all NEdit windows as invalid.
4466 ** Since actually changing the menus is slow, they're just marked and updated
4467 ** when the user pulls one down.
4469 static void invalidatePrevOpenMenus(void)
4471 WindowInfo *w;
4473 /* Mark the menus invalid (to be updated when the user pulls one
4474 down), unless the menu is torn off, meaning it is visible to the user
4475 and should be updated immediately */
4476 for (w=WindowList; w!=NULL; w=w->next) {
4477 if (!XmIsMenuShell(XtParent(w->prevOpenMenuPane)))
4478 updatePrevOpenMenu(w);
4479 else
4480 w->prevOpenMenuValid = False;
4485 ** Add a file to the list of previously opened files for display in the
4486 ** File menu.
4488 void AddToPrevOpenMenu(const char *filename)
4490 int i;
4491 char *nameCopy;
4492 WindowInfo *w;
4494 /* If the Open Previous command is disabled, just return */
4495 if (GetPrefMaxPrevOpenFiles() == 0)
4496 return;
4498 /* If the name is already in the list, move it to the start */
4499 for (i=0; i<NPrevOpen; i++) {
4500 if (!strcmp(filename, PrevOpen[i])) {
4501 nameCopy = PrevOpen[i];
4502 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * i);
4503 PrevOpen[0] = nameCopy;
4504 invalidatePrevOpenMenus();
4505 WriteNEditDB();
4506 return;
4510 /* If the list is already full, make room */
4511 if (NPrevOpen == GetPrefMaxPrevOpenFiles())
4512 XtFree(PrevOpen[--NPrevOpen]);
4514 /* Add it to the list */
4515 nameCopy = XtMalloc(strlen(filename) + 1);
4516 strcpy(nameCopy, filename);
4517 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * NPrevOpen);
4518 PrevOpen[0] = nameCopy;
4519 NPrevOpen++;
4521 /* Mark the Previously Opened Files menu as invalid in all windows */
4522 invalidatePrevOpenMenus();
4524 /* Undim the menu in all windows if it was previously empty */
4525 if (NPrevOpen == 1)
4526 for (w=WindowList; w!=NULL; w=w->next) {
4527 if (!IsTopDocument(w))
4528 continue;
4529 XtSetSensitive(w->prevOpenMenuItem, True);
4532 /* Write the menu contents to disk to restore in later sessions */
4533 WriteNEditDB();
4536 static char* getWindowsMenuEntry(const WindowInfo* window)
4538 static char fullTitle[MAXPATHLEN * 2 + 3+ 1];
4540 sprintf(fullTitle, "%s%s", window->filename,
4541 window->fileChanged? "*" : "");
4543 if (GetPrefShowPathInWindowsMenu() && window->filenameSet)
4545 strcat(fullTitle, " - ");
4546 strcat(fullTitle, window->path);
4549 return(fullTitle);
4553 ** Update the Window menu of a single window to reflect the current state of
4554 ** all NEdit windows as determined by the global WindowList.
4556 static void updateWindowMenu(const WindowInfo *window)
4558 WindowInfo *w;
4559 WidgetList items;
4560 Cardinal nItems;
4561 int i, n, nWindows, windowIndex;
4562 WindowInfo **windows;
4564 if (!IsTopDocument(window))
4565 return;
4567 /* Make a sorted list of windows */
4568 /* windows = MakeSortedWindowArray();*/
4569 for (w=WindowList, nWindows=0; w!=NULL; w=w->next, nWindows++);
4570 windows = (WindowInfo **)XtMalloc(sizeof(WindowInfo *) * nWindows);
4571 for (w=WindowList, i=0; w!=NULL; w=w->next, i++)
4572 windows[i] = w;
4573 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowNames);
4575 /* if the menu is torn off, unmanage the menu pane
4576 before updating it to prevent the tear-off menu
4577 from shrinking/expanding as the menu entries
4578 are added */
4579 if (!XmIsMenuShell(XtParent(window->windowMenuPane)))
4580 XtUnmanageChild(window->windowMenuPane);
4582 /* While it is not possible on some systems (ibm at least) to substitute
4583 a new menu pane, it is possible to substitute menu items, as long as
4584 at least one remains in the menu at all times. This routine assumes
4585 that the menu contains permanent items marked with the value
4586 PERMANENT_MENU_ITEM in the userData resource, and adds and removes items
4587 which it marks with the value TEMPORARY_MENU_ITEM */
4589 /* Go thru all of the items in the menu and rename them to
4590 match the window list. Delete any extras */
4591 XtVaGetValues(window->windowMenuPane, XmNchildren, &items,
4592 XmNnumChildren, &nItems, NULL);
4593 windowIndex = 0;
4594 nWindows = NWindows();
4595 for (n=0; n<(int)nItems; n++) {
4596 XtPointer userData;
4597 XtVaGetValues(items[n], XmNuserData, &userData, NULL);
4598 if (userData == TEMPORARY_MENU_ITEM) {
4599 if (windowIndex >= nWindows) {
4600 /* unmanaging before destroying stops parent from displaying */
4601 XtUnmanageChild(items[n]);
4602 XtDestroyWidget(items[n]);
4603 } else {
4604 XmString st1;
4605 char* title = getWindowsMenuEntry(windows[windowIndex]);
4606 XtVaSetValues(items[n], XmNlabelString,
4607 st1=XmStringCreateSimple(title), NULL);
4608 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4609 XtAddCallback(items[n], XmNactivateCallback,
4610 (XtCallbackProc)raiseCB, windows[windowIndex]);
4611 XmStringFree(st1);
4612 windowIndex++;
4617 /* Add new items for the titles of the remaining windows to the menu */
4618 for (; windowIndex<nWindows; windowIndex++) {
4619 XmString st1;
4620 char* title = getWindowsMenuEntry(windows[windowIndex]);
4621 Widget btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4622 window->windowMenuPane,
4623 XmNlabelString, st1=XmStringCreateSimple(title),
4624 XmNmarginHeight, 0,
4625 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4626 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)raiseCB,
4627 windows[windowIndex]);
4628 XmStringFree(st1);
4630 XtFree((char *)windows);
4632 /* if the menu is torn off, we need to manually adjust the
4633 dimension of the menuShell _before_ re-managing the menu
4634 pane, to either expose the hidden menu entries or remove
4635 the empty space */
4636 if (!XmIsMenuShell(XtParent(window->windowMenuPane))) {
4637 Dimension width, height;
4639 XtVaGetValues(window->windowMenuPane, XmNwidth, &width,
4640 XmNheight, &height, NULL);
4641 XtVaSetValues(XtParent(window->windowMenuPane), XmNwidth, width,
4642 XmNheight, height, NULL);
4643 XtManageChild(window->windowMenuPane);
4648 ** Update the Previously Opened Files menu of a single window to reflect the
4649 ** current state of the list as retrieved from FIXME.
4650 ** Thanks to Markus Schwarzenberg for the sorting part.
4652 static void updatePrevOpenMenu(WindowInfo *window)
4654 Widget btn;
4655 WidgetList items;
4656 Cardinal nItems;
4657 int n, index;
4658 XmString st1;
4659 char **prevOpenSorted;
4661 /* Sort the previously opened file list if requested */
4662 prevOpenSorted = (char **)XtMalloc(NPrevOpen * sizeof(char*));
4663 memcpy(prevOpenSorted, PrevOpen, NPrevOpen * sizeof(char*));
4664 if (GetPrefSortOpenPrevMenu())
4665 qsort(prevOpenSorted, NPrevOpen, sizeof(char*), cmpStrPtr);
4667 /* Go thru all of the items in the menu and rename them to match the file
4668 list. In older Motifs (particularly ibm), it was dangerous to replace
4669 a whole menu pane, which would be much simpler. However, since the
4670 code was already written for the Windows menu and is well tested, I'll
4671 stick with this weird method of re-naming the items */
4672 XtVaGetValues(window->prevOpenMenuPane, XmNchildren, &items,
4673 XmNnumChildren, &nItems, NULL);
4674 index = 0;
4675 for (n=0; n<(int)nItems; n++) {
4676 if (index >= NPrevOpen) {
4677 /* unmanaging before destroying stops parent from displaying */
4678 XtUnmanageChild(items[n]);
4679 XtDestroyWidget(items[n]);
4680 } else {
4681 XtVaSetValues(items[n], XmNlabelString,
4682 st1=XmStringCreateSimple(prevOpenSorted[index]), NULL);
4683 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4684 XtAddCallback(items[n], XmNactivateCallback,
4685 (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
4686 XmStringFree(st1);
4687 index++;
4691 /* Add new items for the remaining file names to the menu */
4692 for (; index<NPrevOpen; index++) {
4693 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4694 window->prevOpenMenuPane,
4695 XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
4696 XmNmarginHeight, 0,
4697 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4698 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)openPrevCB,
4699 prevOpenSorted[index]);
4700 XmStringFree(st1);
4703 XtFree((char*)prevOpenSorted);
4707 ** This function manages the display of the Tags File Menu, which is displayed
4708 ** when the user selects Un-load Tags File.
4710 static void updateTagsFileMenu(WindowInfo *window)
4712 tagFile *tf;
4713 Widget btn;
4714 WidgetList items;
4715 Cardinal nItems;
4716 int n;
4717 XmString st1;
4719 /* Go thru all of the items in the menu and rename them to match the file
4720 list. In older Motifs (particularly ibm), it was dangerous to replace
4721 a whole menu pane, which would be much simpler. However, since the
4722 code was already written for the Windows menu and is well tested, I'll
4723 stick with this weird method of re-naming the items */
4724 XtVaGetValues(window->unloadTagsMenuPane, XmNchildren, &items,
4725 XmNnumChildren, &nItems, NULL);
4726 tf = TagsFileList;
4727 for (n=0; n<(int)nItems; n++) {
4728 if (!tf) {
4729 /* unmanaging before destroying stops parent from displaying */
4730 XtUnmanageChild(items[n]);
4731 XtDestroyWidget(items[n]);
4732 } else {
4733 XtVaSetValues(items[n], XmNlabelString,
4734 st1=XmStringCreateSimple(tf->filename), NULL);
4735 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4736 XtAddCallback(items[n], XmNactivateCallback,
4737 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4738 XmStringFree(st1);
4739 tf = tf->next;
4743 /* Add new items for the remaining file names to the menu */
4744 while (tf) {
4745 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4746 window->unloadTagsMenuPane, XmNlabelString,
4747 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4748 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4749 XtAddCallback(btn, XmNactivateCallback,
4750 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4751 XmStringFree(st1);
4752 tf = tf->next;
4757 ** This function manages the display of the Tips File Menu, which is displayed
4758 ** when the user selects Un-load Calltips File.
4760 static void updateTipsFileMenu(WindowInfo *window)
4762 tagFile *tf;
4763 Widget btn;
4764 WidgetList items;
4765 Cardinal nItems;
4766 int n;
4767 XmString st1;
4769 /* Go thru all of the items in the menu and rename them to match the file
4770 list. In older Motifs (particularly ibm), it was dangerous to replace
4771 a whole menu pane, which would be much simpler. However, since the
4772 code was already written for the Windows menu and is well tested, I'll
4773 stick with this weird method of re-naming the items */
4774 XtVaGetValues(window->unloadTipsMenuPane, XmNchildren, &items,
4775 XmNnumChildren, &nItems, NULL);
4776 tf = TipsFileList;
4777 for (n=0; n<(int)nItems; n++) {
4778 if (!tf) {
4779 /* unmanaging before destroying stops parent from displaying */
4780 XtUnmanageChild(items[n]);
4781 XtDestroyWidget(items[n]);
4782 } else {
4783 XtVaSetValues(items[n], XmNlabelString,
4784 st1=XmStringCreateSimple(tf->filename), NULL);
4785 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4786 XtAddCallback(items[n], XmNactivateCallback,
4787 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4788 XmStringFree(st1);
4789 tf = tf->next;
4793 /* Add new items for the remaining file names to the menu */
4794 while (tf) {
4795 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4796 window->unloadTipsMenuPane, XmNlabelString,
4797 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4798 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4799 XtAddCallback(btn, XmNactivateCallback,
4800 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4801 XmStringFree(st1);
4802 tf = tf->next;
4807 ** Comparison function for sorting file names for the Open Previous submenu
4809 static int cmpStrPtr(const void *strA, const void *strB)
4811 return strcmp(*((char**)strA), *((char**)strB));
4814 #ifdef VMS
4815 static char neditDBBadFilenameChars[] = "\n\t*?(){}!@#%^&' ";
4816 #else
4817 static char neditDBBadFilenameChars[] = "\n";
4818 #endif
4821 ** Write dynamic database of file names for "Open Previous". Eventually,
4822 ** this may hold window positions, and possibly file marks, in which case,
4823 ** it should be moved to a different module, but for now it's just a list
4824 ** of previously opened files.
4826 void WriteNEditDB(void)
4828 const char* fullName = GetRCFileName(NEDIT_HISTORY);
4829 FILE *fp;
4830 int i;
4831 static char fileHeader[] =
4832 "# File name database for NEdit Open Previous command\n";
4834 if (fullName == NULL) {
4835 /* GetRCFileName() might return NULL if an error occurs during
4836 creation of the preference file directory. */
4837 return;
4840 /* If the Open Previous command is disabled, just return */
4841 if (GetPrefMaxPrevOpenFiles() == 0) {
4842 return;
4845 /* open the file */
4846 if ((fp = fopen(fullName, "w")) == NULL) {
4847 #ifdef VMS
4848 /* When the version number, ";1" is specified as part of the file
4849 name, fopen(fullName, "w"), will only open for writing if the
4850 file does not exist. Using, fopen(fullName, "r+"), opens an
4851 existing file for "update" - read/write pointer is placed at the
4852 beginning of file.
4853 By calling ftruncate(), we discard the old contents and avoid
4854 trailing garbage in the file if the new contents is shorter. */
4855 if ((fp = fopen(fullName, "r+")) == NULL) {
4856 return;
4858 if (ftruncate(fileno(fp), 0) != 0) {
4859 fclose(fp);
4860 return;
4862 #else
4863 return;
4864 #endif
4867 /* write the file header text to the file */
4868 fprintf(fp, "%s", fileHeader);
4870 /* Write the list of file names */
4871 for (i = 0; i < NPrevOpen; ++i) {
4872 size_t lineLen = strlen(PrevOpen[i]);
4874 if (lineLen > 0 && PrevOpen[i][0] != '#' &&
4875 strcspn(PrevOpen[i], neditDBBadFilenameChars) == lineLen) {
4876 fprintf(fp, "%s\n", PrevOpen[i]);
4880 fclose(fp);
4884 ** Read dynamic database of file names for "Open Previous". Eventually,
4885 ** this may hold window positions, and possibly file marks, in which case,
4886 ** it should be moved to a different module, but for now it's just a list
4887 ** of previously opened files. This routine should only be called once,
4888 ** at startup time, before any windows are open.
4890 void ReadNEditDB(void)
4892 const char *fullName = GetRCFileName(NEDIT_HISTORY);
4893 char line[MAXPATHLEN + 2];
4894 char *nameCopy;
4895 FILE *fp;
4896 size_t lineLen;
4898 /* If the Open Previous command is disabled, just return */
4899 if (GetPrefMaxPrevOpenFiles() == 0) {
4900 return;
4903 /* Initialize the files list and allocate a (permanent) block memory
4904 of the size prescribed by the maxPrevOpenFiles resource */
4905 PrevOpen = (char **)XtMalloc(sizeof(char *) * GetPrefMaxPrevOpenFiles());
4906 NPrevOpen = 0;
4908 /* Don't move this check ahead of the previous statements. PrevOpen
4909 must be initialized at all times. */
4910 if (fullName == NULL)
4912 /* GetRCFileName() might return NULL if an error occurs during
4913 creation of the preference file directory. */
4914 return;
4917 /* open the file */
4918 if ((fp = fopen(fullName, "r")) == NULL) {
4919 return;
4922 /* read lines of the file, lines beginning with # are considered to be
4923 comments and are thrown away. Lines are subject to cursory checking,
4924 then just copied to the Open Previous file menu list */
4925 while (True) {
4926 if (fgets(line, sizeof(line), fp) == NULL) {
4927 /* end of file */
4928 fclose(fp);
4929 return;
4931 if (line[0] == '#') {
4932 /* comment */
4933 continue;
4935 lineLen = strlen(line);
4936 if (lineLen == 0) {
4937 /* blank line */
4938 continue;
4940 if (line[lineLen - 1] != '\n') {
4941 /* no newline, probably truncated */
4942 fprintf(stderr, "nedit: Line too long in history file\n");
4943 while (fgets(line, sizeof(line), fp) != NULL) {
4944 lineLen = strlen(line);
4945 if (lineLen > 0 && line[lineLen - 1] == '\n') {
4946 break;
4949 continue;
4951 line[--lineLen] = '\0';
4952 if (strcspn(line, neditDBBadFilenameChars) != lineLen) {
4953 /* non-filename characters */
4954 fprintf(stderr, "nedit: History file may be corrupted\n");
4955 continue;
4957 nameCopy = XtMalloc(lineLen + 1);
4958 strcpy(nameCopy, line);
4959 PrevOpen[NPrevOpen++] = nameCopy;
4960 if (NPrevOpen >= GetPrefMaxPrevOpenFiles()) {
4961 /* too many entries */
4962 fclose(fp);
4963 return;
4968 static void setWindowSizeDefault(int rows, int cols)
4970 SetPrefRows(rows);
4971 SetPrefCols(cols);
4972 updateWindowSizeMenus();
4975 static void updateWindowSizeMenus(void)
4977 WindowInfo *win;
4979 for (win=WindowList; win!=NULL; win=win->next)
4980 updateWindowSizeMenu(win);
4983 static void updateWindowSizeMenu(WindowInfo *win)
4985 int rows = GetPrefRows(), cols = GetPrefCols();
4986 char title[50];
4987 XmString st1;
4989 if (!IsTopDocument(win))
4990 return;
4992 XmToggleButtonSetState(win->size24x80DefItem, rows==24&&cols==80,False);
4993 XmToggleButtonSetState(win->size40x80DefItem, rows==40&&cols==80,False);
4994 XmToggleButtonSetState(win->size60x80DefItem, rows==60&&cols==80,False);
4995 XmToggleButtonSetState(win->size80x80DefItem, rows==80&&cols==80,False);
4996 if ((rows!=24 && rows!=40 && rows!=60 && rows!=80) || cols!=80) {
4997 XmToggleButtonSetState(win->sizeCustomDefItem, True, False);
4998 sprintf(title, "Custom... (%d x %d)", rows, cols);
4999 XtVaSetValues(win->sizeCustomDefItem,
5000 XmNlabelString, st1=XmStringCreateSimple(title), NULL);
5001 XmStringFree(st1);
5002 } else {
5003 XmToggleButtonSetState(win->sizeCustomDefItem, False, False);
5004 XtVaSetValues(win->sizeCustomDefItem,
5005 XmNlabelString, st1=XmStringCreateSimple("Custom..."), NULL);
5006 XmStringFree(st1);
5011 ** Scans action argument list for arguments "forward" or "backward" to
5012 ** determine search direction for search and replace actions. "ignoreArgs"
5013 ** tells the routine how many required arguments there are to ignore before
5014 ** looking for keywords
5016 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs)
5018 int i;
5020 for (i=ignoreArgs; i<(int)*nArgs; i++) {
5021 if (!strCaseCmp(args[i], "forward"))
5022 return SEARCH_FORWARD;
5023 if (!strCaseCmp(args[i], "backward"))
5024 return SEARCH_BACKWARD;
5026 return SEARCH_FORWARD;
5030 ** Scans action argument list for arguments "keep" or "nokeep" to
5031 ** determine whether to keep dialogs up for search and replace. "ignoreArgs"
5032 ** tells the routine how many required arguments there are to ignore before
5033 ** looking for keywords
5035 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs)
5037 int i;
5039 for (i=ignoreArgs; i<(int)*nArgs; i++) {
5040 if (!strCaseCmp(args[i], "keep"))
5041 return TRUE;
5042 if (!strCaseCmp(args[i], "nokeep"))
5043 return FALSE;
5045 return GetPrefKeepSearchDlogs();
5049 ** Scans action argument list for arguments "wrap" or "nowrap" to
5050 ** determine search direction for search and replace actions. "ignoreArgs"
5051 ** tells the routine how many required arguments there are to ignore before
5052 ** looking for keywords
5054 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs)
5056 int i;
5058 for (i=ignoreArgs; i<(int)*nArgs; i++) {
5059 if (!strCaseCmp(args[i], "wrap"))
5060 return(TRUE);
5061 if (!strCaseCmp(args[i], "nowrap"))
5062 return(FALSE);
5064 return GetPrefSearchWraps();
5068 ** Scans action argument list for arguments "literal", "case" or "regex" to
5069 ** determine search type for search and replace actions. "ignoreArgs"
5070 ** tells the routine how many required arguments there are to ignore before
5071 ** looking for keywords
5073 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs)
5075 int i, tmpSearchType;
5077 for (i=ignoreArgs; i<(int)*nArgs; i++) {
5078 if (StringToSearchType(args[i], &tmpSearchType))
5079 return tmpSearchType;
5081 return GetPrefSearch();
5085 ** Return a pointer to the string describing search direction for search action
5086 ** routine parameters given a callback XmAnyCallbackStruct pointed to by
5087 ** "callData", by checking if the shift key is pressed (for search callbacks).
5089 static char **shiftKeyToDir(XtPointer callData)
5091 static char *backwardParam[1] = {"backward"};
5092 static char *forwardParam[1] = {"forward"};
5093 if (((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask)
5094 return backwardParam;
5095 return forwardParam;
5098 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData)
5100 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5101 ((XmAnyCallbackStruct *)callData)->event);
5102 RaiseFocusDocumentWindow(window, True /* always focus */);
5105 static void openPrevCB(Widget w, char *name, caddr_t callData)
5107 char *params[1];
5108 Widget menu = MENU_WIDGET(w);
5110 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5111 ((XmAnyCallbackStruct *)callData)->event);
5112 params[0] = name;
5113 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "open",
5114 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5115 CheckCloseDim();
5118 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData)
5120 char *params[1];
5121 Widget menu = MENU_WIDGET(w);
5123 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5124 ((XmAnyCallbackStruct *)callData)->event);
5125 params[0] = name;
5126 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tags_file",
5127 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5130 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData)
5132 char *params[1];
5133 #if XmVersion >= 1002
5134 Widget menu = XmGetPostedFromWidget(XtParent(w)); /* If menu is torn off */
5135 #else
5136 Widget menu = w;
5137 #endif
5139 params[0] = name;
5140 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tips_file",
5141 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5145 ** strCaseCmp compares its arguments and returns 0 if the two strings
5146 ** are equal IGNORING case differences. Otherwise returns 1.
5148 static int strCaseCmp(const char *str1, const char *str2)
5150 const char *c1, *c2;
5152 for (c1=str1, c2=str2; *c1!='\0' && *c2!='\0'; c1++, c2++)
5153 if (toupper((unsigned char)*c1) != toupper((unsigned char)*c2))
5154 return 1;
5155 if (*c1 == *c2) {
5156 return(0);
5158 else {
5159 return(1);
5164 ** Comparison function for sorting windows by title for the window menu.
5165 ** Windows are sorted by Untitled and then alphabetically by filename and
5166 ** then alphabetically by path.
5168 static int compareWindowNames(const void *windowA, const void *windowB)
5170 int rc;
5171 const WindowInfo *a = *((WindowInfo**)windowA);
5172 const WindowInfo *b = *((WindowInfo**)windowB);
5173 /* Untitled first */
5174 rc = a->filenameSet == b->filenameSet ? 0 :
5175 a->filenameSet && !b->filenameSet ? 1 : -1;
5176 if (rc != 0)
5177 return rc;
5178 rc = strcmp(a->filename, b->filename);
5179 if (rc != 0)
5180 return rc;
5181 rc = strcmp(a->path, b->path);
5182 return rc;
5185 static int compareWindowShell(const void *windowA, const void *windowB)
5187 const WindowInfo *a = *((WindowInfo**)windowA);
5188 const WindowInfo *b = *((WindowInfo**)windowB);
5190 return a->shell > b->shell;
5194 ** create & return a sorted list of windows
5195 ** Windows are first sort by their filename then,
5196 ** if windows are tabbed, grouped by their shell windows
5198 ** Note: caller must XtFree the returned window list.
5200 WindowInfo **MakeSortedWindowArray(void)
5202 WindowInfo *w, **windows;
5203 int i, nWindows;
5205 /* Make a sorted list of windows */
5206 for (w=WindowList, nWindows=0; w!=NULL; w=w->next, nWindows++);
5207 windows = (WindowInfo **)XtMalloc(sizeof(WindowInfo *) * nWindows);
5208 for (w=WindowList, i=0; w!=NULL; w=w->next, i++)
5209 windows[i] = w;
5210 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowNames);
5212 /* group the documents together by their shell window */
5213 if (GetPrefOpenInTab())
5214 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowShell);
5216 return windows;
5220 ** Create popup for right button programmable menu
5222 Widget CreateBGMenu(WindowInfo *window)
5224 Arg args[1];
5226 /* There is still some mystery here. It's important to get the XmNmenuPost
5227 resource set to the correct menu button, or the menu will not post
5228 properly, but there's also some danger that it will take over the entire
5229 button and interfere with text widget translations which use the button
5230 with modifiers. I don't entirely understand why it works properly now
5231 when it failed often in development, and certainly ignores the ~ syntax
5232 in translation event specifications. */
5233 XtSetArg(args[0], XmNmenuPost, GetPrefBGMenuBtn());
5234 return CreatePopupMenu(window->textArea, "bgMenu", args, 1);
5238 ** Create context popup menu for tabs & tab bar
5240 Widget CreateTabContextMenu(Widget parent, WindowInfo *window)
5242 Widget menu;
5243 Arg args[8];
5244 int n;
5246 n = 0;
5247 XtSetArg(args[n], XmNtearOffModel, XmTEAR_OFF_DISABLED); n++;
5248 menu = CreatePopupMenu(parent, "tabContext", args, n);
5250 createMenuItem(menu, "new", "New Tab", 0, doTabActionCB, "new_tab", SHORT);
5251 createMenuItem(menu, "close", "Close Tab", 0, doTabActionCB, "close", SHORT);
5252 createMenuSeparator(menu, "sep1", SHORT);
5253 window->contextDetachDocumentItem = createMenuItem(menu, "detach",
5254 "Detach Tab", 0, doTabActionCB, "detach_document", SHORT);
5255 XtSetSensitive(window->contextDetachDocumentItem, False);
5256 window->contextMoveDocumentItem = createMenuItem(menu, "attach",
5257 "Move Tab To...", 0, doTabActionCB, "move_document_dialog", SHORT);
5259 return menu;
5263 ** Add a translation to the text widget to trigger the background menu using
5264 ** the mouse-button + modifier combination specified in the resource:
5265 ** nedit.bgMenuBtn.
5267 void AddBGMenuAction(Widget widget)
5269 static XtTranslations table = NULL;
5271 if (table == NULL) {
5272 char translations[MAX_ACCEL_LEN + 25];
5273 sprintf(translations, "%s: post_window_bg_menu()\n",GetPrefBGMenuBtn());
5274 table = XtParseTranslationTable(translations);
5276 XtOverrideTranslations(widget, table);
5279 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
5280 Cardinal *nArgs)
5282 WindowInfo *window = WidgetToWindow(w);
5284 /* The Motif popup handling code BLOCKS events while the menu is posted,
5285 including the matching btn-up events which complete various dragging
5286 operations which it may interrupt. Cancel to head off problems */
5287 XtCallActionProc(window->lastFocus, "process_cancel", event, NULL, 0);
5289 /* Pop up the menu */
5290 XmMenuPosition(window->bgMenuPane, (XButtonPressedEvent *)event);
5291 XtManageChild(window->bgMenuPane);
5294 These statements have been here for a very long time, but seem
5295 unnecessary and are even dangerous: when any of the lock keys are on,
5296 Motif thinks it shouldn't display the background menu, but this
5297 callback is called anyway. When we then grab the focus and force the
5298 menu to be drawn, bad things can happen (like a total lockup of the X
5299 server).
5301 XtPopup(XtParent(window->bgMenuPane), XtGrabNonexclusive);
5302 XtMapWidget(XtParent(window->bgMenuPane));
5303 XtMapWidget(window->bgMenuPane);
5307 void AddTabContextMenuAction(Widget widget)
5309 static XtTranslations table = NULL;
5311 if (table == NULL) {
5312 char *translations = "<Btn3Down>: post_tab_context_menu()\n";
5313 table = XtParseTranslationTable(translations);
5315 XtOverrideTranslations(widget, table);
5319 ** action procedure for posting context menu of tabs
5321 static void tabMenuPostAP(Widget w, XEvent *event, String *args,
5322 Cardinal *nArgs)
5324 WindowInfo *window;
5325 XButtonPressedEvent *xbutton = (XButtonPressedEvent *)event;
5326 Widget wgt;
5328 /* Determine if the context menu was called from tabs or gutter,
5329 then stored the corresponding window info as userData of
5330 the popup menu pane, which will later be extracted by
5331 doTabActionCB() to act upon. When the context menu was called
5332 from the gutter, the active doc is assumed.
5334 Lesstif requires the action [to pupop the menu] to also be
5335 to the tabs, else nothing happed when right-click on tabs.
5336 Even so, the action procedure sometime appear to be called
5337 from the gutter even if users did right-click on the tabs.
5338 Here we try to cater for the uncertainty. */
5339 if (XtClass(w) == xrwsBubbleButtonWidgetClass)
5340 window = TabToWindow(w);
5341 else if (xbutton->subwindow) {
5342 wgt = XtWindowToWidget(XtDisplay(w), xbutton->subwindow);
5343 window = TabToWindow(wgt);
5345 else {
5346 window = WidgetToWindow(w);
5348 XtVaSetValues(window->tabMenuPane, XmNuserData, (XtPointer)window, NULL);
5350 /* The Motif popup handling code BLOCKS events while the menu is posted,
5351 including the matching btn-up events which complete various dragging
5352 operations which it may interrupt. Cancel to head off problems */
5353 XtCallActionProc(window->lastFocus, "process_cancel", event, NULL, 0);
5355 /* Pop up the menu */
5356 XmMenuPosition(window->tabMenuPane, (XButtonPressedEvent *)event);
5357 XtManageChild(window->tabMenuPane);
5361 ** Event handler for restoring the input hint of menu tearoffs
5362 ** previously disabled in ShowHiddenTearOff()
5364 static void tearoffMappedCB(Widget w, XtPointer clientData, XUnmapEvent *event)
5366 Widget shell = (Widget)clientData;
5367 XWMHints *wmHints;
5369 if (event->type != MapNotify)
5370 return;
5372 /* restore the input hint previously disabled in ShowHiddenTearOff() */
5373 wmHints = XGetWMHints(TheDisplay, XtWindow(shell));
5374 wmHints->input = True;
5375 wmHints->flags |= InputHint;
5376 XSetWMHints(TheDisplay, XtWindow(shell), wmHints);
5377 XFree(wmHints);
5379 /* we only need to do this only */
5380 XtRemoveEventHandler(shell, StructureNotifyMask, False,
5381 (XtEventHandler)tearoffMappedCB, shell);
5385 ** Redisplay (map) a hidden tearoff
5387 void ShowHiddenTearOff(Widget menuPane)
5389 Widget shell;
5391 if (!menuPane)
5392 return;
5394 shell = XtParent(menuPane);
5395 if (!XmIsMenuShell(shell)) {
5396 XWindowAttributes winAttr;
5398 XGetWindowAttributes(XtDisplay(shell), XtWindow(shell), &winAttr);
5399 if (winAttr.map_state == IsUnmapped) {
5400 XWMHints *wmHints;
5402 /* to workaround a problem where the remapped tearoffs
5403 always receive the input focus insteads of the text
5404 editing window, we disable the input hint of the
5405 tearoff shell temporarily. */
5406 wmHints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
5407 wmHints->input = False;
5408 wmHints->flags |= InputHint;
5409 XSetWMHints(XtDisplay(shell), XtWindow(shell), wmHints);
5410 XFree(wmHints);
5412 /* show the tearoff */
5413 XtMapWidget(shell);
5415 /* the input hint will be restored when the tearoff
5416 is mapped */
5417 XtAddEventHandler(shell, StructureNotifyMask, False,
5418 (XtEventHandler)tearoffMappedCB, shell);
5423 #ifdef SGI_CUSTOM
5424 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData)
5426 WindowInfo *win;
5427 int i, state = XmToggleButtonGetState(w);
5428 Widget parent;
5430 window = WidgetToWindow(w);
5432 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5433 ((XmAnyCallbackStruct *)callData)->event);
5434 /* Set the preference */
5435 SetPrefShortMenus(state);
5437 /* Re-create the menus for all windows */
5438 for (win=WindowList; win!=NULL; win=win->next) {
5439 for (i=0; i<win->nToggleShortItems; i++) {
5440 if (state)
5441 XtUnmanageChild(win->toggleShortItems[i]);
5442 else
5443 XtManageChild(win->toggleShortItems[i]);
5446 if (GetPrefShortMenus())
5447 SaveNEditPrefs(window->shell, True);
5450 static void addToToggleShortList(Widget w)
5452 if (ShortMenuWindow->nToggleShortItems >= MAX_SHORTENED_ITEMS) {
5453 fprintf(stderr,"nedit, internal error: increase MAX_SHORTENED_ITEMS\n");
5454 return;
5456 ShortMenuWindow->toggleShortItems[ShortMenuWindow->nToggleShortItems++] = w;
5460 ** Present the user a dialog for specifying whether or not a short
5461 ** menu mode preference should be applied toward the default setting.
5462 ** Return True if user requested to reset and save the default value.
5463 ** If operation was canceled, will return toggle widget "w" to it's
5464 ** original (opposite) state.
5466 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName)
5468 char msg[100] = "";
5470 if (!GetPrefShortMenus()) {
5471 return False;
5474 sprintf(msg, "%s: %s\nSave as default for future windows as well?",
5475 settingName, XmToggleButtonGetState(w) ? "On" : "Off");
5476 switch (DialogF (DF_QUES, parent, 3, "Save Default", msg, "Yes", "No",
5477 "Cancel"))
5479 case 1: /* yes */
5480 return True;
5481 case 2: /* no */
5482 return False;
5483 case 3: /* cancel */
5484 XmToggleButtonSetState(w, !XmToggleButtonGetState(w), False);
5485 return False;
5487 return False; /* not reached */
5489 #endif