Support for Lynx, MacOS; better x86 reporting
[nedit.git] / source / menu.c
blob51ddf330fdbc3acf4bd6f2d7ba8b0c57e7c9e610
1 static const char CVSID[] = "$Id: menu.c,v 1.63 2002/07/26 21:39:10 n8gray 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. *
12 * *
13 * This software is distributed in the hope that it will be useful, but WITHOUT *
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License *
16 * for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License along with *
19 * software; if not, write to the Free Software Foundation, Inc., 59 Temple *
20 * Place, Suite 330, Boston, MA 02111-1307 USA *
21 * *
22 * Nirvana Text Editor *
23 * May 10, 1991 *
24 * *
25 * Written by Mark Edel *
26 * *
27 *******************************************************************************/
29 #ifdef HAVE_CONFIG_H
30 #include "../config.h"
31 #endif
33 #include "menu.h"
34 #include "textBuf.h"
35 #include "text.h"
36 #include "nedit.h"
37 #include "file.h"
38 #include "window.h"
39 #include "search.h"
40 #include "selection.h"
41 #include "undo.h"
42 #include "shift.h"
43 #include "help.h"
44 #include "preferences.h"
45 #include "tags.h"
46 #include "userCmds.h"
47 #include "shell.h"
48 #include "macro.h"
49 #include "highlight.h"
50 #include "highlightData.h"
51 #include "interpret.h"
52 #include "smartIndent.h"
53 #include "windowTitle.h"
54 #include "../util/getfiles.h"
55 #include "../util/DialogF.h"
56 #include "../util/misc.h"
57 #include "../util/fileUtils.h"
58 #include "../util/utils.h"
60 #include <stdlib.h>
61 #include <stdio.h>
62 #include <string.h>
63 #include <ctype.h>
64 #ifdef VMS
65 #include "../util/VMSparam.h"
66 #else
67 #ifndef __MVS__
68 #include <sys/param.h>
69 #endif
70 #endif /*VMS*/
71 #include <X11/X.h>
72 #include <Xm/Xm.h>
73 #include <Xm/CascadeB.h>
74 #include <Xm/PushB.h>
75 #include <Xm/ToggleB.h>
76 #include <Xm/RowColumn.h>
77 #include <Xm/Separator.h>
78 #include <Xm/MenuShell.h>
80 #ifdef HAVE_DEBUG_H
81 #include "../debug.h"
82 #endif
84 #if XmVersion >= 1002
85 #define MENU_WIDGET(w) (XmGetPostedFromWidget(XtParent(w)))
86 #else
87 #define MENU_WIDGET(w) (w)
88 #endif
90 /* Menu modes for SGI_CUSTOM short-menus feature */
91 enum menuModes {FULL, SHORT};
93 typedef void (*menuCallbackProc)();
95 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData);
96 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData);
97 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData);
98 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData);
99 static void findCB(Widget w, XtPointer clientData, XtPointer callData);
100 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData);
101 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData);
102 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData);
103 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData);
104 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData);
105 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData);
106 static void markCB(Widget w, XtPointer clientData, XtPointer callData);
107 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData);
108 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData);
109 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData);
110 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData);
111 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData);
112 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData);
113 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData);
114 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData);
115 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData);
116 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData);
117 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData);
118 static void fontCB(Widget w, WindowInfo *window, caddr_t callData);
119 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
120 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
121 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
122 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
123 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
124 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
125 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
126 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
127 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
128 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
129 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData);
130 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
131 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
132 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
133 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData);
134 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
135 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
136 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData);
137 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
138 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
139 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
140 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
141 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
142 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
143 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
144 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
145 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
146 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
147 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
148 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
149 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData);
150 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData);
151 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData);
152 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData);
153 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData);
154 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData);
155 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
156 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
157 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
158 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window,
159 caddr_t callData);
160 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData);
161 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData);
162 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData);
163 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
164 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
165 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
166 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData);
167 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData);
168 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData);
169 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData);
170 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData);
171 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData);
172 #ifdef REPLACE_SCOPE
173 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData);
174 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData);
175 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData);
176 #endif
177 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData);
178 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData);
179 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData);
180 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData);
181 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData);
182 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData);
183 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData);
184 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData);
185 static void learnCB(Widget w, WindowInfo *window, caddr_t callData);
186 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData);
187 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData);
188 static void replayCB(Widget w, WindowInfo *window, caddr_t callData);
189 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData);
190 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData);
191 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window,
192 caddr_t callData);
193 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window,
194 caddr_t callData);
195 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
196 static void openDialogAP(Widget w, XEvent *event, String *args,
197 Cardinal *nArgs);
198 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
199 static void openSelectedAP(Widget w, XEvent *event, String *args,
200 Cardinal *nArgs);
201 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
202 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
203 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
204 Cardinal *nArgs);
205 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
206 static void revertDialogAP(Widget w, XEvent *event, String *args,
207 Cardinal *nArgs);
208 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
209 static void includeDialogAP(Widget w, XEvent *event, String *args,
210 Cardinal *nArgs);
211 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
212 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
213 Cardinal *nArgs) ;
214 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
215 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
216 Cardinal *nArgs);
217 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
218 static void unloadTagsAP(Widget w, XEvent *event, String *args,
219 Cardinal *nArgs);
220 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
221 Cardinal *nArgs);
222 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
223 static void unloadTipsAP(Widget w, XEvent *event, String *args,
224 Cardinal *nArgs);
225 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
226 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
227 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
228 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
229 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
230 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
231 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
232 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
233 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
234 Cardinal *nArgs);
235 static void shiftRightAP(Widget w, XEvent *event, String *args,
236 Cardinal *nArgs);
237 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
238 Cardinal *nArgs);
239 static void findDialogAP(Widget w, XEvent *event, String *args,
240 Cardinal *nArgs);
241 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
242 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
243 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
244 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
245 static void startIncrFindAP(Widget w, XEvent *event, String *args,
246 Cardinal *nArgs);
247 static void replaceDialogAP(Widget w, XEvent *event, String *args,
248 Cardinal *nArgs);
249 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
250 static void replaceAllAP(Widget w, XEvent *event, String *args,
251 Cardinal *nArgs);
252 static void replaceInSelAP(Widget w, XEvent *event, String *args,
253 Cardinal *nArgs);
254 static void replaceSameAP(Widget w, XEvent *event, String *args,
255 Cardinal *nArgs);
256 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
257 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
258 Cardinal *nArgs);
259 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
260 static void gotoDialogAP(Widget w, XEvent *event, String *args,
261 Cardinal *nArgs);
262 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
263 Cardinal *nArgs);
264 static void repeatDialogAP(Widget w, XEvent *event, String *args,
265 Cardinal *nArgs);
266 static void repeatMacroAP(Widget w, XEvent *event, String *args,
267 Cardinal *nArgs);
268 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
269 static void markDialogAP(Widget w, XEvent *event, String *args,
270 Cardinal *nArgs);
271 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
272 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
273 Cardinal *nArgs);
274 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
275 Cardinal *nArgs);
276 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
277 Cardinal *nArgs);
278 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
279 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
280 static void splitWindowAP(Widget w, XEvent *event, String *args,
281 Cardinal *nArgs);
282 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
283 static void capitalizeAP(Widget w, XEvent *event, String *args,
284 Cardinal *nArgs);
285 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
286 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
287 static void controlDialogAP(Widget w, XEvent *event, String *args,
288 Cardinal *nArgs);
289 #ifndef VMS
290 static void filterDialogAP(Widget w, XEvent *event, String *args,
291 Cardinal *nArgs);
292 static void shellFilterAP(Widget w, XEvent *event, String *args,
293 Cardinal *nArgs);
294 static void execDialogAP(Widget w, XEvent *event, String *args,
295 Cardinal *nArgs);
296 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
297 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
298 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
299 #endif
300 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
301 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
302 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
303 Cardinal *nArgs);
304 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
305 Cardinal *nArgs);
306 static Widget createMenu(Widget parent, char *name, char *label,
307 char mnemonic, Widget *cascadeBtn, int mode);
308 static Widget createMenuItem(Widget parent, char *name, char *label,
309 char mnemonic, menuCallbackProc callback, void *cbArg, int mode);
310 static Widget createFakeMenuItem(Widget parent, char *name,
311 menuCallbackProc callback, void *cbArg);
312 static Widget createMenuToggle(Widget parent, char *name, char *label,
313 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
314 int mode);
315 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
316 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
317 int mode);
318 static Widget createMenuSeparator(Widget parent, char *name, int mode);
319 static void invalidatePrevOpenMenus(void);
320 static void updateWindowMenu(const WindowInfo *window);
321 static void updatePrevOpenMenu(WindowInfo *window);
322 static void updateTagsFileMenu(WindowInfo *window);
323 static void updateTipsFileMenu(WindowInfo *window);
324 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs);
325 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs);
326 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs);
327 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs);
328 static char **shiftKeyToDir(XtPointer callData);
329 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData);
330 static void openPrevCB(Widget w, char *name, caddr_t callData);
331 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData);
332 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData);
333 static int cmpStrPtr(const void *strA, const void *strB);
334 static void setWindowSizeDefault(int rows, int cols);
335 static void updateWindowSizeMenus(void);
336 static void updateWindowSizeMenu(WindowInfo *win);
337 static int strCaseCmp(const char *str1, const char *str2);
338 static int compareWindowNames(const void *windowA, const void *windowB);
339 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
340 Cardinal *nArgs);
341 static void raiseWindowAP(Widget w, XEvent *event, String *args,
342 Cardinal *nArgs);
343 static void focusPaneAP(Widget w, XEvent *event, String *args,
344 Cardinal *nArgs);
345 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
346 Cardinal *nArgs);
347 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
348 Cardinal *nArgs);
349 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
350 Cardinal *nArgs);
351 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
352 Cardinal *nArgs);
353 static void setWrapTextAP(Widget w, XEvent *event, String *args,
354 Cardinal *nArgs);
355 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
356 Cardinal *nArgs);
357 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
358 Cardinal *nArgs);
359 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
360 Cardinal *nArgs);
361 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
362 Cardinal *nArgs);
363 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
364 Cardinal *nArgs);
365 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
366 Cardinal *nArgs);
367 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
368 Cardinal *nArgs);
369 static void setLockedAP(Widget w, XEvent *event, String *args,
370 Cardinal *nArgs);
371 static void setUseTabsAP(Widget w, XEvent *event, String *args,
372 Cardinal *nArgs);
373 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
374 Cardinal *nArgs);
375 static void setTabDistAP(Widget w, XEvent *event, String *args,
376 Cardinal *nArgs);
377 static void setFontsAP(Widget w, XEvent *event, String *args,
378 Cardinal *nArgs);
379 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
380 Cardinal *nArgs);
381 #ifdef SGI_CUSTOM
382 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData);
383 static void addToToggleShortList(Widget w);
384 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName);
385 #endif
387 static HelpMenu * buildHelpMenu( Widget pane, HelpMenu * menu,
388 WindowInfo * window);
390 /* Application action table */
391 static XtActionsRec Actions[] = {
392 {"new", newAP},
393 {"open", openAP},
394 {"open-dialog", openDialogAP},
395 {"open_dialog", openDialogAP},
396 {"open-selected", openSelectedAP},
397 {"open_selected", openSelectedAP},
398 {"close", closeAP},
399 {"save", saveAP},
400 {"save-as", saveAsAP},
401 {"save_as", saveAsAP},
402 {"save-as-dialog", saveAsDialogAP},
403 {"save_as_dialog", saveAsDialogAP},
404 {"revert-to-saved", revertAP},
405 {"revert_to_saved", revertAP},
406 {"revert_to_saved_dialog", revertDialogAP},
407 {"include-file", includeAP},
408 {"include_file", includeAP},
409 {"include-file-dialog", includeDialogAP},
410 {"include_file_dialog", includeDialogAP},
411 {"load-macro-file", loadMacroAP},
412 {"load_macro_file", loadMacroAP},
413 {"load-macro-file-dialog", loadMacroDialogAP},
414 {"load_macro_file_dialog", loadMacroDialogAP},
415 {"load-tags-file", loadTagsAP},
416 {"load_tags_file", loadTagsAP},
417 {"load-tags-file-dialog", loadTagsDialogAP},
418 {"load_tags_file_dialog", loadTagsDialogAP},
419 {"unload_tags_file", unloadTagsAP},
420 {"load_tips_file", loadTipsAP},
421 {"load_tips_file_dialog", loadTipsDialogAP},
422 {"unload_tips_file", unloadTipsAP},
423 {"print", printAP},
424 {"print-selection", printSelAP},
425 {"print_selection", printSelAP},
426 {"exit", exitAP},
427 {"undo", undoAP},
428 {"redo", redoAP},
429 {"delete", clearAP},
430 {"select-all", selAllAP},
431 {"select_all", selAllAP},
432 {"shift-left", shiftLeftAP},
433 {"shift_left", shiftLeftAP},
434 {"shift-left-by-tab", shiftLeftTabAP},
435 {"shift_left_by_tab", shiftLeftTabAP},
436 {"shift-right", shiftRightAP},
437 {"shift_right", shiftRightAP},
438 {"shift-right-by-tab", shiftRightTabAP},
439 {"shift_right_by_tab", shiftRightTabAP},
440 {"find", findAP},
441 {"find-dialog", findDialogAP},
442 {"find_dialog", findDialogAP},
443 {"find-again", findSameAP},
444 {"find_again", findSameAP},
445 {"find-selection", findSelAP},
446 {"find_selection", findSelAP},
447 {"find_incremental", findIncrAP},
448 {"start_incremental_find", startIncrFindAP},
449 {"replace", replaceAP},
450 {"replace-dialog", replaceDialogAP},
451 {"replace_dialog", replaceDialogAP},
452 {"replace-all", replaceAllAP},
453 {"replace_all", replaceAllAP},
454 {"replace-in-selection", replaceInSelAP},
455 {"replace_in_selection", replaceInSelAP},
456 {"replace-again", replaceSameAP},
457 {"replace_again", replaceSameAP},
458 {"replace_find", replaceFindAP},
459 {"replace_find_same", replaceFindSameAP},
460 {"replace_find_again", replaceFindSameAP},
461 {"goto-line-number", gotoAP},
462 {"goto_line_number", gotoAP},
463 {"goto-line-number-dialog", gotoDialogAP},
464 {"goto_line_number_dialog", gotoDialogAP},
465 {"goto-selected", gotoSelectedAP},
466 {"goto_selected", gotoSelectedAP},
467 {"mark", markAP},
468 {"mark-dialog", markDialogAP},
469 {"mark_dialog", markDialogAP},
470 {"goto-mark", gotoMarkAP},
471 {"goto_mark", gotoMarkAP},
472 {"goto-mark-dialog", gotoMarkDialogAP},
473 {"goto_mark_dialog", gotoMarkDialogAP},
474 {"match", selectToMatchingAP},
475 {"select_to_matching", selectToMatchingAP},
476 {"goto_matching", gotoMatchingAP},
477 {"find-definition", findDefAP},
478 {"find_definition", findDefAP},
479 {"show_tip", showTipAP},
480 {"split-window", splitWindowAP},
481 {"split_window", splitWindowAP},
482 {"close-pane", closePaneAP},
483 {"close_pane", closePaneAP},
484 {"uppercase", capitalizeAP},
485 {"lowercase", lowercaseAP},
486 {"fill-paragraph", fillAP},
487 {"fill_paragraph", fillAP},
488 {"control-code-dialog", controlDialogAP},
489 {"control_code_dialog", controlDialogAP},
490 #ifndef VMS
491 {"filter-selection-dialog", filterDialogAP},
492 {"filter_selection_dialog", filterDialogAP},
493 {"filter-selection", shellFilterAP},
494 {"filter_selection", shellFilterAP},
495 {"execute-command", execAP},
496 {"execute_command", execAP},
497 {"execute-command-dialog", execDialogAP},
498 {"execute_command_dialog", execDialogAP},
499 {"execute-command-line", execLineAP},
500 {"execute_command_line", execLineAP},
501 {"shell-menu-command", shellMenuAP},
502 {"shell_menu_command", shellMenuAP},
503 #endif /*VMS*/
504 {"macro-menu-command", macroMenuAP},
505 {"macro_menu_command", macroMenuAP},
506 {"bg_menu_command", bgMenuAP},
507 {"post_window_bg_menu", bgMenuPostAP},
508 {"beginning-of-selection", beginningOfSelectionAP},
509 {"beginning_of_selection", beginningOfSelectionAP},
510 {"end-of-selection", endOfSelectionAP},
511 {"end_of_selection", endOfSelectionAP},
512 {"repeat_macro", repeatMacroAP},
513 {"repeat_dialog", repeatDialogAP},
514 {"raise_window", raiseWindowAP},
515 {"focus_pane", focusPaneAP},
516 {"set_statistics_line", setStatisticsLineAP},
517 {"set_incremental_search_line", setIncrementalSearchLineAP},
518 {"set_show_line_numbers", setShowLineNumbersAP},
519 {"set_auto_indent", setAutoIndentAP},
520 {"set_wrap_text", setWrapTextAP},
521 {"set_wrap_margin", setWrapMarginAP},
522 {"set_highlight_syntax", setHighlightSyntaxAP},
523 #ifndef VMS
524 {"set_make_backup_copy", setMakeBackupCopyAP},
525 #endif
526 {"set_incremental_backup", setIncrementalBackupAP},
527 {"set_show_matching", setShowMatchingAP},
528 {"set_match_syntax_based", setMatchSyntaxBasedAP},
529 {"set_overtype_mode", setOvertypeModeAP},
530 {"set_locked", setLockedAP},
531 {"set_tab_dist", setTabDistAP},
532 {"set_em_tab_dist", setEmTabDistAP},
533 {"set_use_tabs", setUseTabsAP},
534 {"set_fonts", setFontsAP},
535 {"set_language_mode", setLanguageModeAP}
538 /* List of previously opened files for File menu */
539 static int NPrevOpen = 0;
540 static char **PrevOpen;
542 #ifdef SGI_CUSTOM
543 /* Window to receive items to be toggled on and off in short menus mode */
544 static WindowInfo *ShortMenuWindow;
545 #endif
547 void HidePointerOnKeyedEvent(Widget w, XEvent *event)
549 if (event && (event->type == KeyPress || event->type == KeyRelease)) {
550 ShowHidePointer((TextWidget)w, True);
555 ** Install actions for use in translation tables and macro recording, relating
556 ** to menu item commands
558 void InstallMenuActions(XtAppContext context)
560 XtAppAddActions(context, Actions, XtNumber(Actions));
564 ** Return the (statically allocated) action table for menu item actions.
566 XtActionsRec *GetMenuActions(int *nActions)
568 *nActions = XtNumber(Actions);
569 return Actions;
573 ** Create the menu bar
575 Widget CreateMenuBar(Widget parent, WindowInfo *window)
577 Widget menuBar, menuPane, btn, subPane, subSubPane, subSubSubPane, cascade;
580 ** Create the menu bar (row column) widget
582 menuBar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
584 #ifdef SGI_CUSTOM
586 ** Short menu mode is a special feature for the SGI system distribution
587 ** version of NEdit.
589 ** To make toggling short-menus mode faster (re-creating the menus was
590 ** too slow), a list is kept in the window data structure of items to
591 ** be turned on and off. Initialize that list and give the menu creation
592 ** routines a pointer to the window on which this list is kept. This is
593 ** (unfortunately) a global variable to keep the interface simple for
594 ** the mainstream case.
596 ShortMenuWindow = window;
597 window->nToggleShortItems = 0;
598 #endif
601 ** "File" pull down menu.
603 menuPane = createMenu(menuBar, "fileMenu", "File", 0, NULL, SHORT);
604 createMenuItem(menuPane, "new", "New", 'N', doActionCB, "new", SHORT);
605 createMenuItem(menuPane, "open", "Open...", 'O', doActionCB, "open_dialog",
606 SHORT);
607 window->openSelItem=createMenuItem(menuPane, "openSelected", "Open Selected", 'd',
608 doActionCB, "open_selected", FULL);
609 if (GetPrefMaxPrevOpenFiles() != 0) {
610 window->prevOpenMenuPane = createMenu(menuPane, "openPrevious",
611 "Open Previous", 'v', &window->prevOpenMenuItem, SHORT);
612 XtSetSensitive(window->prevOpenMenuItem, NPrevOpen != 0);
613 XtAddCallback(window->prevOpenMenuItem, XmNcascadingCallback,
614 (XtCallbackProc)prevOpenMenuCB, window);
616 createMenuSeparator(menuPane, "sep1", SHORT);
617 window->closeItem = createMenuItem(menuPane, "close", "Close", 'C',
618 doActionCB, "close", SHORT);
619 createMenuItem(menuPane, "save", "Save", 'S', doActionCB, "save", SHORT);
620 createMenuItem(menuPane, "saveAs", "Save As...", 'A', doActionCB,
621 "save_as_dialog", SHORT);
622 createMenuItem(menuPane, "revertToSaved", "Revert to Saved", 'R',
623 doActionCB, "revert_to_saved_dialog", SHORT);
624 createMenuSeparator(menuPane, "sep2", SHORT);
625 createMenuItem(menuPane, "includeFile", "Include File...", 'I',
626 doActionCB, "include_file_dialog", SHORT);
627 createMenuItem(menuPane, "loadMacroFile", "Load Macro File...", 'M',
628 doActionCB, "load_macro_file_dialog", FULL);
629 createMenuItem(menuPane, "loadTagsFile", "Load Tags File...", 'T',
630 doActionCB, "load_tags_file_dialog", FULL);
631 window->unloadTagsMenuPane = createMenu(menuPane, "unloadTagsFiles",
632 "Unload Tags File", 'U', &window->unloadTagsMenuItem, FULL);
633 XtSetSensitive(window->unloadTagsMenuItem, TagsFileList != NULL);
634 XtAddCallback(window->unloadTagsMenuItem, XmNcascadingCallback,
635 (XtCallbackProc)unloadTagsFileMenuCB, window);
636 createMenuItem(menuPane, "loadTipsFile", "Load Calltips File...", 'F',
637 doActionCB, "load_tips_file_dialog", FULL);
638 window->unloadTipsMenuPane = createMenu(menuPane, "unloadTipsFiles",
639 "Unload Calltips File", 'e', &window->unloadTipsMenuItem, FULL);
640 XtSetSensitive(window->unloadTipsMenuItem, TipsFileList != NULL);
641 XtAddCallback(window->unloadTipsMenuItem, XmNcascadingCallback,
642 (XtCallbackProc)unloadTipsFileMenuCB, window);
643 createMenuSeparator(menuPane, "sep3", SHORT);
644 createMenuItem(menuPane, "print", "Print...", 'P', doActionCB, "print",
645 SHORT);
646 window->printSelItem = createMenuItem(menuPane, "printSelection",
647 "Print Selection...", 'l', doActionCB, "print_selection",
648 SHORT);
649 XtSetSensitive(window->printSelItem, window->wasSelected);
650 createMenuSeparator(menuPane, "sep4", SHORT);
651 createMenuItem(menuPane, "exit", "Exit", 'x', doActionCB, "exit", SHORT);
652 CheckCloseDim();
655 ** "Edit" pull down menu.
657 menuPane = createMenu(menuBar, "editMenu", "Edit", 0, NULL, SHORT);
658 window->undoItem = createMenuItem(menuPane, "undo", "Undo", 'U',
659 doActionCB, "undo", SHORT);
660 XtSetSensitive(window->undoItem, False);
661 window->redoItem = createMenuItem(menuPane, "redo", "Redo", 'R',
662 doActionCB, "redo", SHORT);
663 XtSetSensitive(window->redoItem, False);
664 createMenuSeparator(menuPane, "sep1", SHORT);
665 window->cutItem = createMenuItem(menuPane, "cut", "Cut", 't', doActionCB,
666 "cut_clipboard", SHORT);
667 XtSetSensitive(window->cutItem, window->wasSelected);
668 window->copyItem = createMenuItem(menuPane, "copy", "Copy", 'C', doActionCB,
669 "copy_clipboard", SHORT);
670 XtSetSensitive(window->copyItem, window->wasSelected);
671 createMenuItem(menuPane, "paste", "Paste", 'P', doActionCB,
672 "paste_clipboard", SHORT);
673 createMenuItem(menuPane, "pasteColumn", "Paste Column", 's', pasteColCB,
674 window, SHORT);
675 window->delItem=createMenuItem(menuPane, "delete", "Delete", 'D', doActionCB, "delete_selection",
676 SHORT);
677 XtSetSensitive(window->delItem, window->wasSelected);
678 createMenuItem(menuPane, "selectAll", "Select All", 'A', doActionCB,
679 "select_all", SHORT);
680 createMenuSeparator(menuPane, "sep2", SHORT);
681 createMenuItem(menuPane, "shiftLeft", "Shift Left", 'L',
682 shiftLeftCB, window, SHORT);
683 createFakeMenuItem(menuPane, "shiftLeftShift", shiftLeftCB, window);
684 createMenuItem(menuPane, "shiftRight", "Shift Right", 'g',
685 shiftRightCB, window, SHORT);
686 createFakeMenuItem(menuPane, "shiftRightShift", shiftRightCB, window);
687 window->lowerItem=createMenuItem(menuPane, "lowerCase", "Lower-case", 'w',
688 doActionCB, "lowercase", SHORT);
689 window->upperItem=createMenuItem(menuPane, "upperCase", "Upper-case", 'e',
690 doActionCB, "uppercase", SHORT);
691 createMenuItem(menuPane, "fillParagraph", "Fill Paragraph", 'F',
692 doActionCB, "fill_paragraph", SHORT);
693 createMenuSeparator(menuPane, "sep3", FULL);
694 createMenuItem(menuPane, "insertFormFeed", "Insert Form Feed", 'I',
695 formFeedCB, window, FULL);
696 createMenuItem(menuPane, "insertCtrlCode", "Insert Ctrl Code...", 'n',
697 doActionCB, "control_code_dialog", FULL);
698 #ifdef SGI_CUSTOM
699 createMenuSeparator(menuPane, "sep4", SHORT);
700 createMenuToggle(menuPane, "overtype", "Overtype", 'O',
701 doActionCB, "set_overtype_mode", False, SHORT);
702 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
703 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
704 #endif
707 ** "Search" pull down menu.
709 menuPane = createMenu(menuBar, "searchMenu", "Search", 0, NULL, SHORT);
710 createMenuItem(menuPane, "find", "Find...", 'F', findCB, window, SHORT);
711 createFakeMenuItem(menuPane, "findShift", findCB, window);
712 window->findAgainItem=createMenuItem(menuPane, "findAgain", "Find Again", 'i', findSameCB, window,
713 SHORT);
714 XtSetSensitive(window->findAgainItem, NHist);
715 createFakeMenuItem(menuPane, "findAgainShift", findSameCB, window);
716 window->findSelItem=createMenuItem(menuPane, "findSelection", "Find Selection", 'S',
717 findSelCB, window, SHORT);
718 createFakeMenuItem(menuPane, "findSelectionShift", findSelCB, window);
719 createMenuItem(menuPane, "findIncremental", "Find Incremental", 'n',
720 findIncrCB, window, SHORT);
721 createFakeMenuItem(menuPane, "findIncrementalShift", findIncrCB, window);
722 createMenuItem(menuPane, "replace", "Replace...", 'R', replaceCB, window,
723 SHORT);
724 createFakeMenuItem(menuPane, "replaceShift", replaceCB, window);
725 window->replaceFindAgainItem=createMenuItem(menuPane, "replaceFindAgain", "Replace Find Again", 'A',
726 replaceFindSameCB, window, SHORT);
727 XtSetSensitive(window->replaceFindAgainItem, NHist);
728 createFakeMenuItem(menuPane, "replaceFindAgainShift", replaceFindSameCB, window);
729 window->replaceAgainItem=createMenuItem(menuPane, "replaceAgain", "Replace Again", 'p',
730 replaceSameCB, window, SHORT);
731 XtSetSensitive(window->replaceAgainItem, NHist);
732 createFakeMenuItem(menuPane, "replaceAgainShift", replaceSameCB, window);
733 createMenuSeparator(menuPane, "sep1", FULL);
734 createMenuItem(menuPane, "gotoLineNumber", "Goto Line Number...", 'L',
735 doActionCB, "goto_line_number_dialog", FULL);
736 window->gotoSelItem=createMenuItem(menuPane, "gotoSelected", "Goto Selected", 'G',
737 doActionCB, "goto_selected", FULL);
738 createMenuSeparator(menuPane, "sep2", FULL);
739 createMenuItem(menuPane, "mark", "Mark", 'k', markCB, window, FULL);
740 createMenuItem(menuPane, "gotoMark", "Goto Mark", 'o', gotoMarkCB, window,
741 FULL);
742 createFakeMenuItem(menuPane, "gotoMarkShift", gotoMarkCB, window);
743 createMenuSeparator(menuPane, "sep3", FULL);
744 createMenuItem(menuPane, "gotoMatching", "Goto Matching (..)", 'M',
745 gotoMatchingCB, window, FULL);
746 createFakeMenuItem(menuPane, "gotoMatchingShift", gotoMatchingCB, window);
747 window->findDefItem = createMenuItem(menuPane, "findDefinition",
748 "Find Definition", 'D', doActionCB, "find_definition", FULL);
749 XtSetSensitive(window->findDefItem, TagsFileList != NULL);
750 window->showTipItem = createMenuItem(menuPane, "showCalltip",
751 "Show Calltip", 'C', doActionCB, "show_tip", FULL);
752 XtSetSensitive(window->showTipItem, (TagsFileList != NULL ||
753 TipsFileList != NULL) );
756 ** Preferences menu, Default Settings sub menu
758 menuPane = createMenu(menuBar, "preferencesMenu", "Preferences", 0, NULL,
759 SHORT);
760 subPane = createMenu(menuPane, "defaultSettings", "Default Settings", 'D',
761 NULL, FULL);
762 createMenuItem(subPane, "languageModes", "Language Modes...", 'L',
763 languageDefCB, window, FULL);
765 /* Auto Indent sub menu */
766 subSubPane = createMenu(subPane, "autoIndent", "Auto Indent", 'A',
767 NULL, FULL);
768 window->autoIndentOffDefItem = createMenuRadioToggle(subSubPane, "off",
769 "Off", 'O', autoIndentOffDefCB, window,
770 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == NO_AUTO_INDENT, SHORT);
771 window->autoIndentDefItem = createMenuRadioToggle(subSubPane, "on",
772 "On", 'n', autoIndentDefCB, window,
773 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == AUTO_INDENT, SHORT);
774 window->smartIndentDefItem = createMenuRadioToggle(subSubPane, "smart",
775 "Smart", 'S', smartIndentDefCB, window,
776 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == SMART_INDENT, SHORT);
777 createMenuSeparator(subSubPane, "sep1", SHORT);
778 createMenuItem(subSubPane, "ProgramSmartIndent", "Program Smart Indent...",
779 'P', smartMacrosDefCB, window, FULL);
781 /* Wrap sub menu */
782 subSubPane = createMenu(subPane, "wrap", "Wrap", 'W', NULL, FULL);
783 window->noWrapDefItem = createMenuRadioToggle(subSubPane,
784 "none", "None", 'N', noWrapDefCB,
785 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NO_WRAP, SHORT);
786 window->newlineWrapDefItem = createMenuRadioToggle(subSubPane,
787 "autoNewline", "Auto Newline", 'A', newlineWrapDefCB,
788 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NEWLINE_WRAP, SHORT);
789 window->contWrapDefItem = createMenuRadioToggle(subSubPane, "continuous",
790 "Continuous", 'C', contWrapDefCB, window,
791 GetPrefWrap(PLAIN_LANGUAGE_MODE) == CONTINUOUS_WRAP, SHORT);
792 createMenuSeparator(subSubPane, "sep1", SHORT);
793 createMenuItem(subSubPane, "wrapMargin", "Wrap Margin...", 'W',
794 wrapMarginDefCB, window, SHORT);
796 /* Smart Tags sub menu */
797 subSubPane = createMenu(subPane, "smartTags", "Tag Collisions", 'C',
798 NULL, FULL);
799 window->allTagsDefItem = createMenuRadioToggle(subSubPane, "showall",
800 "Show All", 'A', showAllTagsDefCB, window, !GetPrefSmartTags(),
801 FULL);
802 window->smartTagsDefItem = createMenuRadioToggle(subSubPane, "smart",
803 "Smart", 'S', smartTagsDefCB, window, GetPrefSmartTags(), FULL);
805 createMenuItem(subPane, "tabDistance", "Tabs...", 'T', tabsDefCB, window,
806 SHORT);
807 createMenuItem(subPane, "textFont", "Text Font...", 'F', fontDefCB, window,
808 FULL);
810 /* Customize Menus sub menu */
811 subSubPane = createMenu(subPane, "customizeMenus", "Customize Menus",
812 'u', NULL, FULL);
813 #ifndef VMS
814 createMenuItem(subSubPane, "shellMenu", "Shell Menu...", 'S',
815 shellDefCB, window, FULL);
816 #endif
817 createMenuItem(subSubPane, "macroMenu", "Macro Menu...", 'M',
818 macroDefCB, window, FULL);
819 createMenuItem(subSubPane, "windowBackgroundMenu",
820 "Window Background Menu...", 'W', bgMenuDefCB, window, FULL);
821 createMenuSeparator(subSubPane, "sep1", SHORT);
822 window->pathInWindowsMenuDefItem = createMenuToggle(subSubPane, "pathInWindowsMenu",
823 "Show Path In Windows Menu", 'P', pathInWindowsMenuDefCB, window, GetPrefShowPathInWindowsMenu(),
824 SHORT);
825 createMenuItem(subPane, "custimizeTitle", "Customize Window Title...", 'd',
826 customizeTitleDefCB, window, FULL);
828 /* Search sub menu */
829 subSubPane = createMenu(subPane, "searching", "Searching",
830 'g', NULL, FULL);
831 window->searchDlogsDefItem = createMenuToggle(subSubPane, "verbose",
832 "Verbose", 'V', searchDlogsDefCB, window,
833 GetPrefSearchDlogs(), SHORT);
834 window->searchWrapsDefItem = createMenuToggle(subSubPane, "wrapAround",
835 "Wrap Around", 'W', searchWrapsDefCB, window,
836 GetPrefSearchWraps(), SHORT);
837 window->beepOnSearchWrapDefItem = createMenuToggle(subSubPane,
838 "beepOnSearchWrap", "Beep On Search Wrap", 'B',
839 beepOnSearchWrapDefCB, window, GetPrefBeepOnSearchWrap(), SHORT);
840 window->keepSearchDlogsDefItem = createMenuToggle(subSubPane,
841 "keepDialogsUp", "Keep Dialogs Up", 'K',
842 keepSearchDlogsDefCB, window, GetPrefKeepSearchDlogs(), SHORT);
843 subSubSubPane = createMenu(subSubPane, "defaultSearchStyle",
844 "Default Search Style", 'D', NULL, FULL);
845 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
846 window->searchLiteralDefItem = createMenuToggle(subSubSubPane, "literal",
847 "Literal", 'L', searchLiteralCB, window,
848 GetPrefSearch() == SEARCH_LITERAL, FULL);
849 window->searchCaseSenseDefItem = createMenuToggle(subSubSubPane,
850 "caseSensitive", "Literal, Case Sensitive", 'C', searchCaseSenseCB, window,
851 GetPrefSearch() == SEARCH_CASE_SENSE, FULL);
852 window->searchLiteralWordDefItem = createMenuToggle(subSubSubPane, "literalWord",
853 "Literal, Whole Word", 'W', searchLiteralWordCB, window,
854 GetPrefSearch() == SEARCH_LITERAL_WORD, FULL);
855 window->searchCaseSenseWordDefItem = createMenuToggle(subSubSubPane,
856 "caseSensitiveWord", "Literal, Case Sensitive, Whole Word", 't', searchCaseSenseWordCB, window,
857 GetPrefSearch() == SEARCH_CASE_SENSE_WORD, FULL);
858 window->searchRegexDefItem = createMenuToggle(subSubSubPane,
859 "regularExpression", "Regular Expression", 'R', searchRegexCB,
860 window, GetPrefSearch() == SEARCH_REGEX, FULL);
861 window->searchRegexNoCaseDefItem = createMenuToggle(subSubSubPane,
862 "regularExpressionNoCase", "Regular Expression, Case Insensitive", 'I', searchRegexNoCaseCB, window,
863 GetPrefSearch() == SEARCH_REGEX_NOCASE, FULL);
864 #ifdef REPLACE_SCOPE
865 subSubSubPane = createMenu(subSubPane, "defaultReplaceScope",
866 "Default Replace Scope", 'R', NULL, FULL);
867 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
868 window->replScopeWinDefItem = createMenuToggle(subSubSubPane, "window",
869 "In Window", 'W', replaceScopeWindowCB, window,
870 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_WINDOW, FULL);
871 window->replScopeSelDefItem = createMenuToggle(subSubSubPane, "selection",
872 "In Selection", 'S', replaceScopeSelectionCB, window,
873 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SELECTION, FULL);
874 window->replScopeSmartDefItem = createMenuToggle(subSubSubPane, "window",
875 "Smart", 'm', replaceScopeSmartCB, window,
876 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SMART, FULL);
877 #endif
879 /* Syntax Highlighting sub menu */
880 subSubPane = createMenu(subPane, "syntaxHighlighting","Syntax Highlighting",
881 'H', NULL, FULL);
882 window->highlightOffDefItem = createMenuRadioToggle(subSubPane, "off","Off",
883 'O', highlightOffDefCB, window, !GetPrefHighlightSyntax(), FULL);
884 window->highlightDefItem = createMenuRadioToggle(subSubPane, "on",
885 "On", 'n', highlightDefCB, window, GetPrefHighlightSyntax(), FULL);
886 createMenuSeparator(subSubPane, "sep1", SHORT);
887 createMenuItem(subSubPane, "recognitionPatterns", "Recognition Patterns...",
888 'R', highlightingDefCB, window, FULL);
889 createMenuItem(subSubPane, "textDrawingStyles", "Text Drawing Styles...", 'T',
890 stylesDefCB, window, FULL);
892 window->statsLineDefItem = createMenuToggle(subPane, "statisticsLine",
893 "Statistics Line", 'S', statsLineDefCB, window, GetPrefStatsLine(),
894 SHORT);
895 window->iSearchLineDefItem = createMenuToggle(subPane,
896 "incrementalSearchLine", "Incremental Search Line", 'i',
897 iSearchLineDefCB, window, GetPrefISearchLine(), FULL);
898 window->lineNumsDefItem = createMenuToggle(subPane, "showLineNumbers",
899 "Show Line Numbers", 'N', lineNumsDefCB, window, GetPrefLineNums(),
900 SHORT);
901 window->saveLastDefItem = createMenuToggle(subPane, "preserveLastVersion",
902 "Make Backup Copy (*.bck)", 'e', preserveDefCB, window,
903 GetPrefSaveOldVersion(), SHORT);
904 window->autoSaveDefItem = createMenuToggle(subPane, "incrementalBackup",
905 "Incremental Backup", 'B', autoSaveDefCB, window, GetPrefAutoSave(),
906 SHORT);
908 /* Show Matching sub menu */
909 subSubPane = createMenu(subPane, "showMatching", "Show Matching (..)", 'M',
910 NULL, FULL);
911 window->showMatchingOffDefItem = createMenuRadioToggle(subSubPane, "off",
912 "Off", 'O', showMatchingOffDefCB, window,
913 GetPrefShowMatching() == NO_FLASH, SHORT);
914 window->showMatchingDelimitDefItem = createMenuRadioToggle(subSubPane,
915 "delimiter", "Delimiter", 'D', showMatchingDelimitDefCB, window,
916 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
917 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
918 "range", "Range", 'R', showMatchingRangeDefCB, window,
919 GetPrefShowMatching() == FLASH_RANGE, SHORT);
920 createMenuSeparator(subSubPane, "sep", SHORT);
921 window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
922 "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
923 GetPrefMatchSyntaxBased(), SHORT);
925 /* Append LF at end of files on save */
926 window->appendLFItem = createMenuToggle(subPane, "appendLFItem",
927 "Append Line Feed on Save", 'v', appendLFCB, NULL,
928 GetPrefAppendLF(), FULL);
930 window->sortOpenPrevDefItem = createMenuToggle(subPane, "sortOpenPrevMenu",
931 "Sort Open Prev. Menu", 'o', sortOpenPrevDefCB, window,
932 GetPrefSortOpenPrevMenu(), FULL);
933 window->reposDlogsDefItem = createMenuToggle(subPane, "popupsUnderPointer",
934 "Popups Under Pointer", 'P', reposDlogsDefCB, window,
935 GetPrefRepositionDialogs(), FULL);
936 subSubPane = createMenu(subPane, "warnings", "Warnings", 'r', NULL, FULL);
937 window->modWarnDefItem = createMenuToggle(subSubPane,
938 "filesModifiedExternally", "Files Modified Externally", 'F',
939 modWarnDefCB, window, GetPrefWarnFileMods(), FULL);
940 window->exitWarnDefItem = createMenuToggle(subSubPane, "onExit", "On Exit", 'O',
941 exitWarnDefCB, window, GetPrefWarnExit(), FULL);
943 /* Initial Window Size sub menu (simulates radioBehavior) */
944 subSubPane = createMenu(subPane, "initialwindowSize",
945 "Initial Window Size", 'z', NULL, FULL);
946 /* XtVaSetValues(subSubPane, XmNradioBehavior, True, NULL); */
947 window->size24x80DefItem = btn = createMenuToggle(subSubPane, "24X80",
948 "24 x 80", '2', size24x80CB, window, False, SHORT);
949 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
950 window->size40x80DefItem = btn = createMenuToggle(subSubPane, "40X80",
951 "40 x 80", '4', size40x80CB, window, False, SHORT);
952 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
953 window->size60x80DefItem = btn = createMenuToggle(subSubPane, "60X80",
954 "60 x 80", '6', size60x80CB, window, False, SHORT);
955 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
956 window->size80x80DefItem = btn = createMenuToggle(subSubPane, "80X80",
957 "80 x 80", '8', size80x80CB, window, False, SHORT);
958 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
959 window->sizeCustomDefItem = btn = createMenuToggle(subSubPane, "custom",
960 "Custom...", 'C', sizeCustomCB, window, False, SHORT);
961 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
962 updateWindowSizeMenu(window);
965 ** Remainder of Preferences menu
967 createMenuItem(menuPane, "saveDefaults", "Save Defaults...", 'v',
968 savePrefCB, window, FULL);
969 #ifdef SGI_CUSTOM
970 window->shortMenusDefItem = createMenuToggle(menuPane,
971 "shortMenus", "Short Menus", 'h', shortMenusCB, window,
972 GetPrefShortMenus(), SHORT);
973 #endif
974 createMenuSeparator(menuPane, "sep1", SHORT);
975 window->statsLineItem = createMenuToggle(menuPane, "statisticsLine", "Statistics Line", 'S',
976 statsCB, window, GetPrefStatsLine(), SHORT);
977 window->iSearchLineItem = createMenuToggle(menuPane, "incremntalSearchLine","Incremental Search Line",
978 'I', doActionCB, "set_incremental_search_line", GetPrefISearchLine(), FULL);
979 window->lineNumsItem = createMenuToggle(menuPane, "lineNumbers", "Show Line Numbers", 'N',
980 doActionCB, "set_show_line_numbers", GetPrefLineNums(), SHORT);
981 CreateLanguageModeSubMenu(window, menuPane, "languageMode",
982 "Language Mode", 'L');
983 subPane = createMenu(menuPane, "autoIndent", "Auto Indent",
984 'A', NULL, FULL);
985 window->autoIndentOffItem = createMenuRadioToggle(subPane, "off", "Off",
986 'O', autoIndentOffCB, window, window->indentStyle == NO_AUTO_INDENT,
987 SHORT);
988 window->autoIndentItem = createMenuRadioToggle(subPane, "on", "On", 'n',
989 autoIndentCB, window, window->indentStyle == AUTO_INDENT, SHORT);
990 window->smartIndentItem = createMenuRadioToggle(subPane, "smart", "Smart",
991 'S', smartIndentCB, window, window->indentStyle == SMART_INDENT,
992 SHORT);
993 subPane = createMenu(menuPane, "wrap", "Wrap",
994 'W', NULL, FULL);
995 window->noWrapItem = createMenuRadioToggle(subPane, "none",
996 "None", 'N', noWrapCB, window,
997 window->wrapMode==NO_WRAP, SHORT);
998 window->newlineWrapItem = createMenuRadioToggle(subPane, "autoNewlineWrap",
999 "Auto Newline", 'A', newlineWrapCB, window,
1000 window->wrapMode==NEWLINE_WRAP, SHORT);
1001 window->continuousWrapItem = createMenuRadioToggle(subPane,
1002 "continuousWrap", "Continuous", 'C', continuousWrapCB, window,
1003 window->wrapMode==CONTINUOUS_WRAP, SHORT);
1004 createMenuSeparator(subPane, "sep1", SHORT);
1005 createMenuItem(subPane, "wrapMargin", "Wrap Margin...", 'W',
1006 wrapMarginCB, window, SHORT);
1007 createMenuItem(menuPane, "tabs", "Tabs...", 'T', tabsCB, window, SHORT);
1008 createMenuItem(menuPane, "textFont", "Text Font...", 'F', fontCB, window,
1009 FULL);
1010 window->highlightItem = createMenuToggle(menuPane, "highlightSyntax",
1011 "Highlight Syntax", 'H', doActionCB, "set_highlight_syntax",
1012 GetPrefHighlightSyntax(), SHORT);
1013 #ifndef VMS
1014 window->saveLastItem = createMenuToggle(menuPane, "makeBackupCopy",
1015 "Make Backup Copy (*.bck)", 'e', preserveCB, window,
1016 window->saveOldVersion, SHORT);
1017 #endif
1018 window->autoSaveItem = createMenuToggle(menuPane, "incrementalBackup",
1019 "Incremental Backup", 'B', autoSaveCB, window, window->autoSave,
1020 SHORT);
1022 subPane = createMenu(menuPane, "showMatching", "Show Matching (..)",
1023 'M', NULL, FULL);
1024 window->showMatchingOffItem = createMenuRadioToggle(subPane, "off", "Off",
1025 'O', showMatchingOffCB, window, window->showMatchingStyle == NO_FLASH,
1026 SHORT);
1027 window->showMatchingDelimitItem = createMenuRadioToggle(subPane,
1028 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
1029 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
1030 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
1031 "Range", 'R', showMatchingRangeCB, window,
1032 window->showMatchingStyle == FLASH_RANGE, SHORT);
1033 createMenuSeparator(subPane, "sep", SHORT);
1034 window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
1035 "Syntax Based", 'S', matchSyntaxBasedCB, window,
1036 window->matchSyntaxBased, SHORT);
1038 #ifndef SGI_CUSTOM
1039 createMenuSeparator(menuPane, "sep2", SHORT);
1040 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
1041 doActionCB, "set_overtype_mode", False, SHORT);
1042 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
1043 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
1044 #endif
1046 #ifndef VMS
1048 ** Create the Shell menu
1050 menuPane = window->shellMenuPane =
1051 createMenu(menuBar, "shellMenu", "Shell", 0, NULL, FULL);
1052 btn = createMenuItem(menuPane, "executeCommand", "Execute Command...",
1053 'E', doActionCB, "execute_command_dialog", SHORT);
1054 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1055 btn = createMenuItem(menuPane, "executeCommandLine", "Execute Command Line",
1056 'x', doActionCB, "execute_command_line", SHORT);
1057 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1058 window->filterItem = createMenuItem(menuPane, "filterSelection",
1059 "Filter Selection...", 'F', doActionCB, "filter_selection_dialog",
1060 SHORT);
1061 XtVaSetValues(window->filterItem, XmNuserData, PERMANENT_MENU_ITEM,
1062 XmNsensitive, window->wasSelected, NULL);
1063 window->cancelShellItem = createMenuItem(menuPane, "cancelShellCommand",
1064 "Cancel Shell Command", 'C', cancelShellCB, window, SHORT);
1065 XtVaSetValues(window->cancelShellItem, XmNuserData, PERMANENT_MENU_ITEM,
1066 XmNsensitive, False, NULL);
1067 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1068 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1069 /* UpdateShellMenu(window) now done in DetermineLanguageMode */
1070 #endif
1073 ** Create the Macro menu
1075 menuPane = window->macroMenuPane =
1076 createMenu(menuBar, "macroMenu", "Macro", 0, NULL, FULL);
1077 window->learnItem = createMenuItem(menuPane, "learnKeystrokes",
1078 "Learn Keystrokes", 'L', learnCB, window, SHORT);
1079 XtVaSetValues(window->learnItem , XmNuserData, PERMANENT_MENU_ITEM, NULL);
1080 window->finishLearnItem = createMenuItem(menuPane, "finishLearn",
1081 "Finish Learn", 'F', finishLearnCB, window, SHORT);
1082 XtVaSetValues(window->finishLearnItem , XmNuserData, PERMANENT_MENU_ITEM,
1083 XmNsensitive, False, NULL);
1084 window->cancelMacroItem = createMenuItem(menuPane, "cancelLearn",
1085 "Cancel Learn", 'C', cancelLearnCB, window, SHORT);
1086 XtVaSetValues(window->cancelMacroItem, XmNuserData, PERMANENT_MENU_ITEM,
1087 XmNsensitive, False, NULL);
1088 window->replayItem = createMenuItem(menuPane, "replayKeystrokes",
1089 "Replay Keystrokes", 'K', replayCB, window, SHORT);
1090 XtVaSetValues(window->replayItem, XmNuserData, PERMANENT_MENU_ITEM,
1091 XmNsensitive, GetReplayMacro() != NULL, NULL);
1092 window->repeatItem = createMenuItem(menuPane, "repeat",
1093 "Repeat...", 'R', doActionCB, "repeat_dialog", SHORT);
1094 XtVaSetValues(window->repeatItem, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1095 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1096 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1097 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1098 /* UpdateMacroMenu(window) now done in DetermineLanguageMode */
1101 ** Create the Windows menu
1103 menuPane = window->windowMenuPane = createMenu(menuBar, "windowsMenu",
1104 "Windows", 0, &cascade, FULL);
1105 XtAddCallback(cascade, XmNcascadingCallback, (XtCallbackProc)windowMenuCB,
1106 window);
1107 window->splitWindowItem = createMenuItem(menuPane, "splitWindow",
1108 "Split Window", 'S', doActionCB, "split_window", SHORT);
1109 XtVaSetValues(window->splitWindowItem, XmNuserData, PERMANENT_MENU_ITEM,
1110 NULL);
1111 window->closePaneItem = createMenuItem(menuPane, "closePane",
1112 "Close Pane", 'C', doActionCB, "close_pane", SHORT);
1113 XtVaSetValues(window->closePaneItem, XmNuserData, PERMANENT_MENU_ITEM,NULL);
1114 XtSetSensitive(window->closePaneItem, False);
1115 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1116 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1119 ** Create "Help" pull down menu.
1121 menuPane = createMenu(menuBar, "helpMenu", "Help", 0, &cascade, SHORT);
1122 XtVaSetValues(menuBar, XmNmenuHelpWidget, cascade, NULL);
1123 buildHelpMenu( menuPane, &H_M[0], window );
1125 return menuBar;
1128 /*----------------------------------------------------------------------------*/
1130 static Widget makeHelpMenuItem(
1132 Widget parent,
1133 char *name, /* to be assigned to the child widget */
1134 char *label, /* text to be displayed in menu */
1135 char mnemonic, /* letter in label to be underlined */
1136 menuCallbackProc callback, /* activated when menu item selected */
1137 void *cbArg, /* passed to activated call back */
1138 int mode, /* SGI_CUSTOM menu option */
1139 enum HelpTopic topic /* associated with this menu item */
1142 Widget menuItem =
1143 createMenuItem( parent, name, label, mnemonic, callback, cbArg, mode );
1145 XtVaSetValues( menuItem, XmNuserData, topic, 0 );
1146 return menuItem;
1149 /*----------------------------------------------------------------------------*/
1151 static void helpCB( Widget menuItem, XtPointer clientData, XtPointer callData )
1153 WindowInfo *window = (WindowInfo*) clientData;
1154 enum HelpTopic topic;
1156 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(menuItem))->lastFocus,
1157 ((XmAnyCallbackStruct *)callData)->event);
1158 XtVaGetValues( menuItem, XmNuserData, &topic, 0 );
1160 Help( window->shell, topic );
1163 /*----------------------------------------------------------------------------*/
1165 #define NON_MENU_HELP 9
1167 static HelpMenu * buildHelpMenu(
1169 Widget pane, /* Menu pane on which to place new menu items */
1170 HelpMenu * menu, /* Data to drive building the help menu */
1171 WindowInfo * window /* Main NEdit window information */
1174 #ifdef VMS
1175 int hideIt = 1; /* All menu items matching this will be inaccessible */
1176 #else
1177 int hideIt = -1; /* This value should make all menu items accessible */
1178 #endif
1180 if( menu != NULL )
1182 int crntLevel = menu->level;
1184 /*-------------------------
1185 * For each menu element ...
1186 *-------------------------*/
1187 while( menu != NULL && menu->level == crntLevel )
1189 /*----------------------------------------------
1190 * ... see if dealing with a separator or submenu
1191 *----------------------------------------------*/
1192 if( menu->topic == HELP_none )
1194 if( menu->mnemonic == '-' )
1196 createMenuSeparator(pane, menu->wgtName, SHORT);
1197 menu = menu->next;
1199 else
1201 /*-------------------------------------------------------
1202 * Do not show any of the submenu when it is to be hidden.
1203 *-------------------------------------------------------*/
1204 if( menu->hideIt == hideIt || menu->hideIt == NON_MENU_HELP )
1206 do { menu = menu->next;
1207 } while( menu != NULL && menu->level > crntLevel );
1210 else
1212 Widget subPane =
1213 createMenu( pane, menu->wgtName, menu->subTitle,
1214 menu->mnemonic, NULL, FULL);
1216 menu = buildHelpMenu( subPane, menu->next, window );
1221 else
1223 /*---------------------------------------
1224 * Show menu item if not going to hide it.
1225 * This is the easy way out of hiding
1226 * menu items. When entire submenus want
1227 * to be hidden, either the entire branch
1228 * will have to be marked, or this algorithm
1229 * will have to become a lot smarter.
1230 *---------------------------------------*/
1231 if( menu->hideIt != hideIt && menu->hideIt != NON_MENU_HELP )
1232 makeHelpMenuItem(
1233 pane, menu->wgtName, HelpTitles[menu->topic],
1234 menu->mnemonic, helpCB, window, SHORT, menu->topic );
1236 menu = menu->next;
1241 return menu;
1244 /*----------------------------------------------------------------------------*/
1246 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData)
1248 Widget menu = MENU_WIDGET(w);
1250 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1251 ((XmAnyCallbackStruct *)callData)->event);
1252 XtCallActionProc(WidgetToWindow(menu)->lastFocus, (char *)clientData,
1253 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1256 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData)
1258 static char *params[1] = {"rect"};
1260 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1261 ((XmAnyCallbackStruct *)callData)->event);
1262 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "paste_clipboard",
1263 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1266 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData)
1268 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1269 ((XmAnyCallbackStruct *)callData)->event);
1270 XtCallActionProc(((WindowInfo *)clientData)->lastFocus,
1271 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1272 ? "shift_left_by_tab" : "shift_left",
1273 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1276 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData)
1278 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1279 ((XmAnyCallbackStruct *)callData)->event);
1280 XtCallActionProc(((WindowInfo *)clientData)->lastFocus,
1281 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1282 ? "shift_right_by_tab" : "shift_right",
1283 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1286 static void findCB(Widget w, XtPointer clientData, XtPointer callData)
1288 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1289 ((XmAnyCallbackStruct *)callData)->event);
1290 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "find_dialog",
1291 ((XmAnyCallbackStruct *)callData)->event,
1292 shiftKeyToDir(callData), 1);
1295 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData)
1297 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1298 ((XmAnyCallbackStruct *)callData)->event);
1299 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "find_again",
1300 ((XmAnyCallbackStruct *)callData)->event,
1301 shiftKeyToDir(callData), 1);
1304 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData)
1306 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1307 ((XmAnyCallbackStruct *)callData)->event);
1308 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "find_selection",
1309 ((XmAnyCallbackStruct *)callData)->event,
1310 shiftKeyToDir(callData), 1);
1313 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData)
1315 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1316 ((XmAnyCallbackStruct *)callData)->event);
1317 XtCallActionProc(((WindowInfo *)clientData)->lastFocus,
1318 "start_incremental_find", ((XmAnyCallbackStruct *)callData)->event,
1319 shiftKeyToDir(callData), 1);
1322 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData)
1324 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1325 ((XmAnyCallbackStruct *)callData)->event);
1326 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "replace_dialog",
1327 ((XmAnyCallbackStruct *)callData)->event,
1328 shiftKeyToDir(callData), 1);
1331 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData)
1333 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1334 ((XmAnyCallbackStruct *)callData)->event);
1335 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "replace_again",
1336 ((XmAnyCallbackStruct *)callData)->event,
1337 shiftKeyToDir(callData), 1);
1340 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData)
1342 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1343 ((XmAnyCallbackStruct *)callData)->event);
1344 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "replace_find_same",
1345 ((XmAnyCallbackStruct *)callData)->event,
1346 shiftKeyToDir(callData), 1);
1349 static void markCB(Widget w, XtPointer clientData, XtPointer callData)
1351 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1352 WindowInfo *window = (WindowInfo *)clientData;
1354 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1355 ((XmAnyCallbackStruct *)callData)->event);
1356 if (event->type == KeyPress || event->type == KeyRelease)
1357 BeginMarkCommand(window);
1358 else
1359 XtCallActionProc(window->lastFocus, "mark_dialog", event, NULL, 0);
1362 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData)
1364 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1365 WindowInfo *window = (WindowInfo *)clientData;
1366 int extend = event->xbutton.state & ShiftMask;
1367 static char *params[1] = {"extend"};
1369 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1370 ((XmAnyCallbackStruct *)callData)->event);
1371 if (event->type == KeyPress || event->type == KeyRelease)
1372 BeginGotoMarkCommand(window, extend);
1373 else
1374 XtCallActionProc(window->lastFocus, "goto_mark_dialog", event, params,
1375 extend ? 1 : 0);
1378 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData)
1380 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1381 ((XmAnyCallbackStruct *)callData)->event);
1382 XtCallActionProc(((WindowInfo *)clientData)->lastFocus,
1383 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1384 ? "select_to_matching" : "goto_matching",
1385 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1388 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData)
1390 static char *params[1] = {"off"};
1391 Widget menu = MENU_WIDGET(w);
1392 #ifdef SGI_CUSTOM
1393 if (shortPrefAskDefault(window->shell, w, "Auto Indent Off")) {
1394 autoIndentOffDefCB(w, window, callData);
1395 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1397 #endif
1398 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1399 ((XmAnyCallbackStruct *)callData)->event);
1400 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1401 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1404 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1406 static char *params[1] = {"on"};
1407 Widget menu = MENU_WIDGET(w);
1408 #ifdef SGI_CUSTOM
1409 if (shortPrefAskDefault(window->shell, w, "Auto Indent")) {
1410 autoIndentDefCB(w, window, callData);
1411 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1413 #endif
1414 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1415 ((XmAnyCallbackStruct *)callData)->event);
1416 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1417 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1420 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1422 static char *params[1] = {"smart"};
1423 Widget menu = MENU_WIDGET(w);
1424 #ifdef SGI_CUSTOM
1425 if (shortPrefAskDefault(window->shell, w, "Smart Indent")) {
1426 smartIndentDefCB(w, window, callData);
1427 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1429 #endif
1430 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1431 ((XmAnyCallbackStruct *)callData)->event);
1432 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1433 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1436 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData)
1438 Widget menu = MENU_WIDGET(w);
1439 #ifdef SGI_CUSTOM
1440 if (shortPrefAskDefault(window->shell, w, "Incremental Backup")) {
1441 autoSaveDefCB(w, window, callData);
1442 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1444 #endif
1445 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1446 ((XmAnyCallbackStruct *)callData)->event);
1447 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_incremental_backup",
1448 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1451 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData)
1453 Widget menu = MENU_WIDGET(w);
1454 #ifdef SGI_CUSTOM
1455 if (shortPrefAskDefault(window->shell, w, "Make Backup Copy")) {
1456 preserveDefCB(w, window, callData);
1457 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1459 #endif
1460 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1461 ((XmAnyCallbackStruct *)callData)->event);
1462 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_make_backup_copy",
1463 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1466 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData)
1468 static char *params[1] = {NO_FLASH_STRING};
1469 Widget menu = MENU_WIDGET(w);
1470 #ifdef SGI_CUSTOM
1471 if (shortPrefAskDefault(window->shell, w, "Show Matching Off")) {
1472 showMatchingOffDefCB(w, window, callData);
1473 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1475 #endif
1476 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1477 ((XmAnyCallbackStruct *)callData)->event);
1478 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1479 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1482 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData)
1484 static char *params[1] = {FLASH_DELIMIT_STRING};
1485 Widget menu = MENU_WIDGET(w);
1486 #ifdef SGI_CUSTOM
1487 if (shortPrefAskDefault(window->shell, w, "Show Matching Delimiter")) {
1488 showMatchingDelimitDefCB(w, window, callData);
1489 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1491 #endif
1492 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1493 ((XmAnyCallbackStruct *)callData)->event);
1494 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1495 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1498 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData)
1500 static char *params[1] = {FLASH_RANGE_STRING};
1501 Widget menu = MENU_WIDGET(w);
1502 #ifdef SGI_CUSTOM
1503 if (shortPrefAskDefault(window->shell, w, "Show Matching Range")) {
1504 showMatchingRangeDefCB(w, window, callData);
1505 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1507 #endif
1508 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1509 ((XmAnyCallbackStruct *)callData)->event);
1510 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1511 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1514 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
1516 Widget menu = MENU_WIDGET(w);
1517 #ifdef SGI_CUSTOM
1518 if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
1519 matchSyntaxBasedDefCB(w, window, callData);
1520 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1522 #endif
1523 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1524 ((XmAnyCallbackStruct *)callData)->event);
1525 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
1526 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1529 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
1531 ChooseFonts(window, True);
1534 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1536 static char *params[1] = {"none"};
1537 Widget menu = MENU_WIDGET(w);
1538 #ifdef SGI_CUSTOM
1539 if (shortPrefAskDefault(window->shell, w, "No Wrap")) {
1540 noWrapDefCB(w, window, callData);
1541 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1543 #endif
1544 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1545 ((XmAnyCallbackStruct *)callData)->event);
1546 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1547 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1550 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1552 static char *params[1] = {"auto"};
1553 Widget menu = MENU_WIDGET(w);
1554 #ifdef SGI_CUSTOM
1555 if (shortPrefAskDefault(window->shell, w, "Auto Newline Wrap")) {
1556 newlineWrapDefCB(w, window, callData);
1557 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1559 #endif
1560 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1561 ((XmAnyCallbackStruct *)callData)->event);
1562 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1563 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1566 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1568 static char *params[1] = {"continuous"};
1569 Widget menu = MENU_WIDGET(w);
1570 #ifdef SGI_CUSTOM
1571 if (shortPrefAskDefault(window->shell, w, "Continuous Wrap")) {
1572 contWrapDefCB(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_wrap_text",
1579 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1582 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData)
1584 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1585 ((XmAnyCallbackStruct *)callData)->event);
1586 WrapMarginDialog(window->shell, window);
1589 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData)
1591 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1592 ((XmAnyCallbackStruct *)callData)->event);
1593 TabsPrefDialog(window->shell, window);
1596 static void statsCB(Widget w, WindowInfo *window, caddr_t callData)
1598 Widget menu = MENU_WIDGET(w);
1599 #ifdef SGI_CUSTOM
1600 if (shortPrefAskDefault(window->shell, w, "Statistics Line")) {
1601 statsLineDefCB(w, window, callData);
1602 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1604 #endif
1605 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1606 ((XmAnyCallbackStruct *)callData)->event);
1607 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_statistics_line",
1608 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1611 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1613 WindowInfo *win;
1615 /* Set the preference and make the other windows' menus agree */
1616 SetPrefAutoIndent(NO_AUTO_INDENT);
1617 for (win=WindowList; win!=NULL; win=win->next) {
1618 XmToggleButtonSetState(win->autoIndentOffDefItem, True, False);
1619 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1620 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1624 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1626 WindowInfo *win;
1628 /* Set the preference and make the other windows' menus agree */
1629 SetPrefAutoIndent(AUTO_INDENT);
1630 for (win=WindowList; win!=NULL; win=win->next) {
1631 XmToggleButtonSetState(win->autoIndentDefItem, True, False);
1632 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1633 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1637 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1639 WindowInfo *win;
1641 /* Set the preference and make the other windows' menus agree */
1642 SetPrefAutoIndent(SMART_INDENT);
1643 for (win=WindowList; win!=NULL; win=win->next) {
1644 XmToggleButtonSetState(win->smartIndentDefItem, True, False);
1645 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1646 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1650 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1652 WindowInfo *win;
1653 int state = XmToggleButtonGetState(w);
1655 /* Set the preference and make the other windows' menus agree */
1656 SetPrefAutoSave(state);
1657 for (win=WindowList; win!=NULL; win=win->next)
1658 XmToggleButtonSetState(win->autoSaveDefItem, state, False);
1661 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1663 WindowInfo *win;
1664 int state = XmToggleButtonGetState(w);
1666 /* Set the preference and make the other windows' menus agree */
1667 SetPrefSaveOldVersion(state);
1668 for (win=WindowList; win!=NULL; win=win->next)
1669 XmToggleButtonSetState(win->saveLastDefItem, state, False);
1672 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData)
1674 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1675 ((XmAnyCallbackStruct *)callData)->event);
1676 ChooseFonts(window, False);
1679 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1681 WindowInfo *win;
1683 /* Set the preference and make the other windows' menus agree */
1684 SetPrefWrap(NO_WRAP);
1685 for (win=WindowList; win!=NULL; win=win->next) {
1686 XmToggleButtonSetState(win->noWrapDefItem, True, False);
1687 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1688 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1692 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1694 WindowInfo *win;
1696 /* Set the preference and make the other windows' menus agree */
1697 SetPrefWrap(NEWLINE_WRAP);
1698 for (win=WindowList; win!=NULL; win=win->next) {
1699 XmToggleButtonSetState(win->newlineWrapDefItem, True, False);
1700 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1701 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1705 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1707 WindowInfo *win;
1709 /* Set the preference and make the other windows' menus agree */
1710 SetPrefWrap(CONTINUOUS_WRAP);
1711 for (win=WindowList; win!=NULL; win=win->next) {
1712 XmToggleButtonSetState(win->contWrapDefItem, True, False);
1713 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1714 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1718 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData)
1720 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1721 ((XmAnyCallbackStruct *)callData)->event);
1722 WrapMarginDialog(window->shell, NULL);
1725 static void smartTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1727 WindowInfo *win;
1729 SetPrefSmartTags(True);
1730 for (win=WindowList; win!=NULL; win=win->next) {
1731 XmToggleButtonSetState(win->smartTagsDefItem, True, False);
1732 XmToggleButtonSetState(win->allTagsDefItem, False, False);
1736 static void showAllTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1738 WindowInfo *win;
1740 SetPrefSmartTags(False);
1741 for (win=WindowList; win!=NULL; win=win->next) {
1742 XmToggleButtonSetState(win->smartTagsDefItem, False, False);
1743 XmToggleButtonSetState(win->allTagsDefItem, True, False);
1747 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1749 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1750 ((XmAnyCallbackStruct *)callData)->event);
1751 TabsPrefDialog(window->shell, NULL);
1754 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1756 WindowInfo *win;
1758 /* Set the preference and make the other windows' menus agree */
1759 SetPrefShowMatching(NO_FLASH);
1760 for (win=WindowList; win!=NULL; win=win->next) {
1761 XmToggleButtonSetState(win->showMatchingOffDefItem, True, False);
1762 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1763 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1767 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData)
1769 WindowInfo *win;
1771 /* Set the preference and make the other windows' menus agree */
1772 SetPrefShowMatching(FLASH_DELIMIT);
1773 for (win=WindowList; win!=NULL; win=win->next) {
1774 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1775 XmToggleButtonSetState(win->showMatchingDelimitDefItem, True, False);
1776 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1780 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData)
1782 WindowInfo *win;
1784 /* Set the preference and make the other windows' menus agree */
1785 SetPrefShowMatching(FLASH_RANGE);
1786 for (win=WindowList; win!=NULL; win=win->next) {
1787 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1788 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1789 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
1793 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
1795 WindowInfo *win;
1797 int state = XmToggleButtonGetState(w);
1799 /* Set the preference and make the other windows' menus agree */
1800 SetPrefMatchSyntaxBased(state);
1801 for (win=WindowList; win!=NULL; win=win->next) {
1802 XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
1806 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1808 WindowInfo *win;
1810 /* Set the preference and make the other windows' menus agree */
1811 SetPrefHighlightSyntax(False);
1812 for (win=WindowList; win!=NULL; win=win->next) {
1813 XmToggleButtonSetState(win->highlightOffDefItem, True, False);
1814 XmToggleButtonSetState(win->highlightDefItem, False, False);
1818 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData)
1820 WindowInfo *win;
1822 /* Set the preference and make the other windows' menus agree */
1823 SetPrefHighlightSyntax(True);
1824 for (win=WindowList; win!=NULL; win=win->next) {
1825 XmToggleButtonSetState(win->highlightOffDefItem, False, False);
1826 XmToggleButtonSetState(win->highlightDefItem, True, False);
1830 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData)
1832 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1833 ((XmAnyCallbackStruct *)callData)->event);
1834 EditHighlightPatterns(window);
1837 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData)
1839 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1840 ((XmAnyCallbackStruct *)callData)->event);
1841 EditSmartIndentMacros(window);
1844 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData)
1846 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1847 ((XmAnyCallbackStruct *)callData)->event);
1848 EditHighlightStyles(window->shell, NULL);
1851 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData)
1853 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1854 ((XmAnyCallbackStruct *)callData)->event);
1855 EditLanguageModes(window->shell);
1858 #ifndef VMS
1859 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData)
1861 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1862 ((XmAnyCallbackStruct *)callData)->event);
1863 EditShellMenu(window);
1865 #endif /* VMS */
1867 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData)
1869 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1870 ((XmAnyCallbackStruct *)callData)->event);
1871 EditMacroMenu(window);
1874 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
1876 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1877 ((XmAnyCallbackStruct *)callData)->event);
1878 EditBGMenu(window);
1881 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData)
1883 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1884 ((XmAnyCallbackStruct *)callData)->event);
1885 EditCustomTitleFormat(window->shell, window);
1888 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1890 WindowInfo *win;
1891 int state = XmToggleButtonGetState(w);
1893 /* Set the preference and make the other windows' menus agree */
1894 SetPrefSearchDlogs(state);
1895 for (win=WindowList; win!=NULL; win=win->next)
1896 XmToggleButtonSetState(win->searchDlogsDefItem, state, False);
1899 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1901 WindowInfo *win;
1902 int state = XmToggleButtonGetState(w);
1904 /* Set the preference and make the other windows' menus agree */
1905 SetPrefBeepOnSearchWrap(state);
1906 for (win=WindowList; win!=NULL; win=win->next)
1907 XmToggleButtonSetState(win->beepOnSearchWrapDefItem, state, False);
1910 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1912 WindowInfo *win;
1913 int state = XmToggleButtonGetState(w);
1915 /* Set the preference and make the other windows' menus agree */
1916 SetPrefKeepSearchDlogs(state);
1917 for (win=WindowList; win!=NULL; win=win->next)
1918 XmToggleButtonSetState(win->keepSearchDlogsDefItem, state, False);
1921 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1923 WindowInfo *win;
1924 int state = XmToggleButtonGetState(w);
1926 /* Set the preference and make the other windows' menus agree */
1927 SetPrefSearchWraps(state);
1928 for (win=WindowList; win!=NULL; win=win->next)
1929 XmToggleButtonSetState(win->searchWrapsDefItem, state, False);
1932 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData)
1934 WindowInfo *win;
1935 int state = XmToggleButtonGetState(w);
1937 SetPrefAppendLF(state);
1938 for (win = WindowList; win != NULL; win = win->next)
1940 XmToggleButtonSetState(win->appendLFItem, state, False);
1944 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData)
1946 WindowInfo *win;
1947 int state = XmToggleButtonGetState(w);
1949 /* Set the preference, make the other windows' menus agree,
1950 and invalidate their Open Previous menus */
1951 SetPrefSortOpenPrevMenu(state);
1952 for (win=WindowList; win!=NULL; win=win->next) {
1953 win->prevOpenMenuValid = False;
1954 XmToggleButtonSetState(win->sortOpenPrevDefItem, state, False);
1958 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1960 WindowInfo *win;
1961 int state = XmToggleButtonGetState(w);
1963 /* Set the preference and make the other windows' menus agree */
1964 SetPrefRepositionDialogs(state);
1965 SetPointerCenteredDialogs(state);
1966 for (win=WindowList; win!=NULL; win=win->next)
1967 XmToggleButtonSetState(win->reposDlogsDefItem, state, False);
1970 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
1972 WindowInfo *win;
1973 int state = XmToggleButtonGetState(w);
1975 /* Set the preference and make the other windows' menus agree */
1976 SetPrefWarnFileMods(state);
1977 for (win=WindowList; win!=NULL; win=win->next)
1978 XmToggleButtonSetState(win->modWarnDefItem, state, False);
1981 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
1983 WindowInfo *win;
1984 int state = XmToggleButtonGetState(w);
1986 /* Set the preference and make the other windows' menus agree */
1987 SetPrefWarnExit(state);
1988 for (win=WindowList; win!=NULL; win=win->next)
1989 XmToggleButtonSetState(win->exitWarnDefItem, state, False);
1992 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
1994 WindowInfo *win;
1995 int state = XmToggleButtonGetState(w);
1997 /* Set the preference and make the other windows' menus agree */
1998 SetPrefStatsLine(state);
1999 for (win=WindowList; win!=NULL; win=win->next)
2000 XmToggleButtonSetState(win->statsLineDefItem, state, False);
2003 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
2005 WindowInfo *win;
2006 int state = XmToggleButtonGetState(w);
2008 /* Set the preference and make the other windows' menus agree */
2009 SetPrefISearchLine(state);
2010 for (win=WindowList; win!=NULL; win=win->next)
2011 XmToggleButtonSetState(win->iSearchLineDefItem, state, False);
2014 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2016 WindowInfo *win;
2017 int state = XmToggleButtonGetState(w);
2019 /* Set the preference and make the other windows' menus agree */
2020 SetPrefLineNums(state);
2021 for (win=WindowList; win!=NULL; win=win->next)
2022 XmToggleButtonSetState(win->lineNumsDefItem, state, False);
2025 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
2027 WindowInfo *win;
2028 int state = XmToggleButtonGetState(w);
2030 /* Set the preference and make the other windows' menus agree */
2031 SetPrefShowPathInWindowsMenu(state);
2032 for (win=WindowList; win!=NULL; win=win->next)
2033 XmToggleButtonSetState(win->pathInWindowsMenuDefItem, state, False);
2036 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData)
2038 WindowInfo *win;
2040 /* Set the preference and make the other windows' menus agree */
2041 if (XmToggleButtonGetState(w)) {
2042 SetPrefSearch(SEARCH_LITERAL);
2043 for (win=WindowList; win!=NULL; win=win->next){
2044 XmToggleButtonSetState(win->searchLiteralDefItem, True, False);
2045 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2046 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2047 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2048 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2049 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2054 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData)
2056 WindowInfo *win;
2058 /* Set the preference and make the other windows' menus agree */
2059 if (XmToggleButtonGetState(w)) {
2060 SetPrefSearch(SEARCH_CASE_SENSE);
2061 for (win=WindowList; win!=NULL; win=win->next) {
2062 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2063 XmToggleButtonSetState(win->searchCaseSenseDefItem, True, False);
2064 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2065 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2066 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2067 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2072 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData)
2074 WindowInfo *win;
2076 /* Set the preference and make the other windows' menus agree */
2077 if (XmToggleButtonGetState(w)) {
2078 SetPrefSearch(SEARCH_LITERAL_WORD);
2079 for (win=WindowList; win!=NULL; win=win->next){
2080 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2081 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2082 XmToggleButtonSetState(win->searchLiteralWordDefItem, True, False);
2083 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2084 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2085 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2090 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData)
2092 WindowInfo *win;
2094 /* Set the preference and make the other windows' menus agree */
2095 if (XmToggleButtonGetState(w)) {
2096 SetPrefSearch(SEARCH_CASE_SENSE_WORD);
2097 for (win=WindowList; win!=NULL; win=win->next) {
2098 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2099 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2100 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2101 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, True, False);
2102 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2103 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2108 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData)
2110 WindowInfo *win;
2112 /* Set the preference and make the other windows' menus agree */
2113 if (XmToggleButtonGetState(w)) {
2114 SetPrefSearch(SEARCH_REGEX);
2115 for (win=WindowList; win!=NULL; win=win->next){
2116 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2117 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2118 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2119 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2120 XmToggleButtonSetState(win->searchRegexDefItem, True, False);
2121 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2126 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData)
2128 WindowInfo *win;
2130 /* Set the preference and make the other windows' menus agree */
2131 if (XmToggleButtonGetState(w)) {
2132 SetPrefSearch(SEARCH_REGEX_NOCASE);
2133 for (win=WindowList; win!=NULL; win=win->next){
2134 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2135 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2136 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2137 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2138 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2139 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, True, False);
2144 #ifdef REPLACE_SCOPE
2145 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData)
2147 WindowInfo *win;
2149 /* Set the preference and make the other windows' menus agree */
2150 if (XmToggleButtonGetState(w)) {
2151 SetPrefReplaceDefScope(REPL_DEF_SCOPE_WINDOW);
2152 for (win=WindowList; win!=NULL; win=win->next){
2153 XmToggleButtonSetState(win->replScopeWinDefItem, True, False);
2154 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2155 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2160 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData)
2162 WindowInfo *win;
2164 /* Set the preference and make the other windows' menus agree */
2165 if (XmToggleButtonGetState(w)) {
2166 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SELECTION);
2167 for (win=WindowList; win!=NULL; win=win->next){
2168 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2169 XmToggleButtonSetState(win->replScopeSelDefItem, True, False);
2170 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2175 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData)
2177 WindowInfo *win;
2179 /* Set the preference and make the other windows' menus agree */
2180 if (XmToggleButtonGetState(w)) {
2181 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SMART);
2182 for (win=WindowList; win!=NULL; win=win->next){
2183 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2184 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2185 XmToggleButtonSetState(win->replScopeSmartDefItem, True, False);
2189 #endif
2191 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData)
2193 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2194 ((XmAnyCallbackStruct *)callData)->event);
2195 setWindowSizeDefault(24, 80);
2198 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData)
2200 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2201 ((XmAnyCallbackStruct *)callData)->event);
2202 setWindowSizeDefault(40, 80);
2205 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData)
2207 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2208 ((XmAnyCallbackStruct *)callData)->event);
2209 setWindowSizeDefault(60, 80);
2212 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData)
2214 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2215 ((XmAnyCallbackStruct *)callData)->event);
2216 setWindowSizeDefault(80, 80);
2219 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData)
2221 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2222 ((XmAnyCallbackStruct *)callData)->event);
2223 RowColumnPrefDialog(window->shell);
2224 updateWindowSizeMenus();
2227 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData)
2229 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2230 ((XmAnyCallbackStruct *)callData)->event);
2231 SaveNEditPrefs(window->shell, False);
2234 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData)
2236 static char *params[1] = {"\f"};
2238 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2239 ((XmAnyCallbackStruct *)callData)->event);
2240 XtCallActionProc(((WindowInfo *)clientData)->lastFocus, "insert_string",
2241 ((XmAnyCallbackStruct *)callData)->event, params, 1);
2244 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData)
2246 #ifndef VMS
2247 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2248 ((XmAnyCallbackStruct *)callData)->event);
2249 AbortShellCommand(window);
2250 #endif
2253 static void learnCB(Widget w, WindowInfo *window, caddr_t callData)
2255 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2256 ((XmAnyCallbackStruct *)callData)->event);
2257 BeginLearn(window);
2260 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2262 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2263 ((XmAnyCallbackStruct *)callData)->event);
2264 FinishLearn();
2267 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2269 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2270 ((XmAnyCallbackStruct *)callData)->event);
2271 CancelMacroOrLearn(window);
2274 static void replayCB(Widget w, WindowInfo *window, caddr_t callData)
2276 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2277 ((XmAnyCallbackStruct *)callData)->event);
2278 Replay(window);
2281 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2283 if (!window->windowMenuValid) {
2284 updateWindowMenu(window);
2285 window->windowMenuValid = True;
2289 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2291 if (!window->prevOpenMenuValid) {
2292 updatePrevOpenMenu(window);
2293 window->prevOpenMenuValid = True;
2297 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2299 updateTagsFileMenu(window);
2302 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2304 updateTipsFileMenu(window);
2308 ** Action Procedures for menu item commands
2310 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2312 EditNewFile(NULL, False, NULL, WidgetToWindow(w)->path);
2313 CheckCloseDim();
2316 static void openDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2318 WindowInfo *window = WidgetToWindow(w);
2319 char fullname[MAXPATHLEN], *params[1];
2320 int response;
2322 response = PromptForExistingFile(window, "File to Edit", fullname);
2323 if (response != GFN_OK)
2324 return;
2325 params[0] = fullname;
2326 XtCallActionProc(window->lastFocus, "open", event, params, 1);
2327 CheckCloseDim();
2330 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2332 WindowInfo *window = WidgetToWindow(w);
2333 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
2335 if (*nArgs == 0) {
2336 fprintf(stderr, "NEdit: open action requires file argument\n");
2337 return;
2339 if (ParseFilename(args[0], filename, pathname) != 0) {
2340 fprintf(stderr, "NEdit: invalid file name for open action: %s\n",
2341 args[0]);
2342 return;
2344 EditExistingFile(window, filename, pathname, 0, NULL, False, NULL);
2345 CheckCloseDim();
2348 static void openSelectedAP(Widget w, XEvent *event, String *args,
2349 Cardinal *nArgs)
2351 OpenSelectedFile(WidgetToWindow(w), event->xbutton.time);
2352 CheckCloseDim();
2355 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2357 int preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2359 if (*nArgs > 0) {
2360 if (strcmp(args[0], "prompt") == 0) {
2361 preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2363 else if (strcmp(args[0], "save") == 0) {
2364 preResponse = YES_SBC_DIALOG_RESPONSE;
2366 else if (strcmp(args[0], "nosave") == 0) {
2367 preResponse = NO_SBC_DIALOG_RESPONSE;
2370 CloseFileAndWindow(WidgetToWindow(w), preResponse);
2371 CheckCloseDim();
2374 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2376 WindowInfo *window = WidgetToWindow(w);
2378 if (CheckReadOnly(window))
2379 return;
2380 SaveWindow(window);
2383 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
2384 Cardinal *nArgs)
2386 WindowInfo *window = WidgetToWindow(w);
2387 int response, addWrap, fileFormat;
2388 char fullname[MAXPATHLEN], *params[2];
2390 response = PromptForNewFile(window, "Save File As", fullname,
2391 &fileFormat, &addWrap);
2392 if (response != GFN_OK)
2393 return;
2394 window->fileFormat = fileFormat;
2395 params[0] = fullname;
2396 params[1] = "wrapped";
2397 XtCallActionProc(window->lastFocus, "save_as", event, params, addWrap?2:1);
2400 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2402 if (*nArgs == 0) {
2403 fprintf(stderr, "NEdit: save_as action requires file argument\n");
2404 return;
2406 SaveWindowAs(WidgetToWindow(w), args[0],
2407 *nArgs == 2 && !strCaseCmp(args[1], "wrapped"));
2410 static void revertDialogAP(Widget w, XEvent *event, String *args,
2411 Cardinal *nArgs)
2413 WindowInfo *window = WidgetToWindow(w);
2414 int b;
2416 /* re-reading file is irreversible, prompt the user first */
2417 if (window->fileChanged)
2418 b = DialogF(DF_QUES, window->shell, 2, "Discard changes to\n%s%s?",
2419 "OK", "Cancel", window->path, window->filename);
2420 else
2421 b = DialogF(DF_QUES, window->shell, 2, "Re-load file\n%s%s?",
2422 "Re-read", "Cancel", window->path, window->filename);
2423 if (b != 1)
2424 return;
2425 XtCallActionProc(window->lastFocus, "revert_to_saved", event, NULL, 0);
2429 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2431 RevertToSaved(WidgetToWindow(w));
2434 static void includeDialogAP(Widget w, XEvent *event, String *args,
2435 Cardinal *nArgs)
2437 WindowInfo *window = WidgetToWindow(w);
2438 char filename[MAXPATHLEN], *params[1];
2439 int response;
2441 if (CheckReadOnly(window))
2442 return;
2443 response = PromptForExistingFile(window, "File to Include", filename);
2444 if (response != GFN_OK)
2445 return;
2446 params[0] = filename;
2447 XtCallActionProc(window->lastFocus, "include_file", event, params, 1);
2450 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2452 WindowInfo *window = WidgetToWindow(w);
2454 if (CheckReadOnly(window))
2455 return;
2456 if (*nArgs == 0) {
2457 fprintf(stderr, "NEdit: include action requires file argument\n");
2458 return;
2460 IncludeFile(WidgetToWindow(w), args[0]);
2463 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
2464 Cardinal *nArgs)
2466 WindowInfo *window = WidgetToWindow(w);
2467 char filename[MAXPATHLEN], *params[1];
2468 int response;
2470 response = PromptForExistingFile(window, "NEdit Macro File", filename);
2471 if (response != GFN_OK)
2472 return;
2473 params[0] = filename;
2474 XtCallActionProc(window->lastFocus, "load_macro_file", event, params, 1);
2477 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2479 if (*nArgs == 0) {
2480 fprintf(stderr,"NEdit: load_macro_file action requires file argument\n");
2481 return;
2483 ReadMacroFile(WidgetToWindow(w), args[0], True);
2486 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
2487 Cardinal *nArgs)
2489 WindowInfo *window = WidgetToWindow(w);
2490 char filename[MAXPATHLEN], *params[1];
2491 int response;
2493 response = PromptForExistingFile(window, "ctags File", filename);
2494 if (response != GFN_OK)
2495 return;
2496 params[0] = filename;
2497 XtCallActionProc(window->lastFocus, "load_tags_file", event, params, 1);
2500 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2502 if (*nArgs == 0) {
2503 fprintf(stderr,"NEdit: load_tags_file action requires file argument\n");
2504 return;
2506 if (!AddTagsFile(args[0], TAG)) {
2507 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1,
2508 "Error reading ctags file:\n'%s'\ntags not loaded", "Dismiss",
2509 args[0]);
2513 static void unloadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2515 if (*nArgs == 0) {
2516 fprintf(stderr,
2517 "NEdit: unload_tags_file action requires file argument\n");
2518 return;
2520 DeleteTagsFile(args[0], TAG);
2523 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
2524 Cardinal *nArgs)
2526 WindowInfo *window = WidgetToWindow(w);
2527 char filename[MAXPATHLEN], *params[1];
2528 int response;
2530 response = PromptForExistingFile(window, "Calltips File", filename);
2531 if (response != GFN_OK)
2532 return;
2533 params[0] = filename;
2534 XtCallActionProc(window->lastFocus, "load_tips_file", event, params, 1);
2537 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2539 if (*nArgs == 0) {
2540 fprintf(stderr,"NEdit: load_tips_file action requires file argument\n");
2541 return;
2543 if (!AddTagsFile(args[0], TIP)) {
2544 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1,
2545 "Error reading tips file:\n'%s'\ntips not loaded", "Dismiss",
2546 args[0]);
2550 static void unloadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2552 if (*nArgs == 0) {
2553 fprintf(stderr,
2554 "NEdit: unload_tips_file action requires file argument\n");
2555 return;
2557 DeleteTagsFile(args[0], TIP);
2560 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2562 PrintWindow(WidgetToWindow(w), False);
2565 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2567 PrintWindow(WidgetToWindow(w), True);
2570 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2572 WindowInfo *window = WidgetToWindow(w);
2574 if (!CheckPrefsChangesSaved(window->shell))
2575 return;
2577 /* If this is not the last window (more than one window is open),
2578 confirm with the user before exiting. */
2579 if (GetPrefWarnExit() && !(window == WindowList && window->next == NULL)) {
2580 int resp, titleLen, lineLen;
2581 char exitMsg[DF_MAX_MSG_LENGTH], *ptr, *title;
2582 WindowInfo *win;
2584 /* List the windows being edited and make sure the
2585 user really wants to exit */
2586 ptr = exitMsg;
2587 lineLen = 0;
2588 strcpy(ptr, "Editing: "); ptr += 9; lineLen += 9;
2589 for (win=WindowList; win!=NULL; win=win->next) {
2590 XtVaGetValues(win->shell, XmNiconName, &title, NULL);
2591 titleLen = strlen(title);
2592 if (ptr - exitMsg + titleLen + 30 >= DF_MAX_MSG_LENGTH) {
2593 strcpy(ptr, "..."); ptr += 3;
2594 break;
2596 if (lineLen + titleLen + (win->next==NULL?5:2) > 50) {
2597 *ptr++ = '\n';
2598 lineLen = 0;
2600 if (win->next == NULL) {
2601 sprintf(ptr, "and %s.", title);
2602 ptr += 5 + titleLen;
2603 lineLen += 5 + titleLen;
2604 } else {
2605 sprintf(ptr, "%s, ", title);
2606 ptr += 2 + titleLen;
2607 lineLen += 2 + titleLen;
2610 sprintf(ptr, "\n\nExit NEdit?");
2611 resp = DialogF(DF_QUES, window->shell, 2, "%s", "Exit", "Cancel", exitMsg);
2612 if (resp == 2)
2613 return;
2616 /* Close all files and exit when the last one is closed */
2617 if (CloseAllFilesAndWindows())
2618 exit(EXIT_SUCCESS);
2621 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2623 WindowInfo *window = WidgetToWindow(w);
2625 if (CheckReadOnly(window))
2626 return;
2627 Undo(window);
2630 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2632 WindowInfo *window = WidgetToWindow(w);
2634 if (CheckReadOnly(window))
2635 return;
2636 Redo(window);
2639 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2641 WindowInfo *window = WidgetToWindow(w);
2643 if (CheckReadOnly(window))
2644 return;
2645 BufRemoveSelected(window->buffer);
2648 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2650 WindowInfo *window = WidgetToWindow(w);
2652 BufSelect(window->buffer, 0, window->buffer->length);
2655 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2657 WindowInfo *window = WidgetToWindow(w);
2659 if (CheckReadOnly(window))
2660 return;
2661 ShiftSelection(window, SHIFT_LEFT, False);
2664 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
2665 Cardinal *nArgs)
2667 WindowInfo *window = WidgetToWindow(w);
2669 if (CheckReadOnly(window))
2670 return;
2671 ShiftSelection(window, SHIFT_LEFT, True);
2674 static void shiftRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2676 WindowInfo *window = WidgetToWindow(w);
2678 if (CheckReadOnly(window))
2679 return;
2680 ShiftSelection(window, SHIFT_RIGHT, False);
2683 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
2684 Cardinal *nArgs)
2686 WindowInfo *window = WidgetToWindow(w);
2688 if (CheckReadOnly(window))
2689 return;
2690 ShiftSelection(window, SHIFT_RIGHT, True);
2693 static void findDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2695 DoFindDlog(WidgetToWindow(w), searchDirection(0, args, nArgs),
2696 searchType(0, args, nArgs), searchKeepDialogs(0, args, nArgs),
2697 event->xbutton.time);
2700 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2702 if (*nArgs == 0) {
2703 fprintf(stderr, "NEdit: find action requires search string argument\n");
2704 return;
2706 SearchAndSelect(WidgetToWindow(w), searchDirection(1, args, nArgs), args[0],
2707 searchType(1, args, nArgs), searchWrap(1, args, nArgs));
2710 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2712 SearchAndSelectSame(WidgetToWindow(w), searchDirection(0, args, nArgs),
2713 searchWrap(0, args, nArgs));
2716 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2718 SearchForSelected(WidgetToWindow(w), searchDirection(0, args, nArgs),
2719 searchType(0, args, nArgs), searchWrap(0, args, nArgs),
2720 event->xbutton.time);
2723 static void startIncrFindAP(Widget w, XEvent *event, String *args,
2724 Cardinal *nArgs)
2726 BeginISearch(WidgetToWindow(w), searchDirection(0, args, nArgs));
2729 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2731 int i, continued = FALSE;
2732 if (*nArgs == 0) {
2733 fprintf(stderr, "NEdit: find action requires search string argument\n");
2734 return;
2736 for (i=1; i<(int)*nArgs; i++)
2737 if (!strCaseCmp(args[i], "continued"))
2738 continued = TRUE;
2739 SearchAndSelectIncremental(WidgetToWindow(w),
2740 searchDirection(1, args, nArgs), args[0],
2741 searchType(1, args, nArgs), searchWrap(1, args, nArgs), continued);
2744 static void replaceDialogAP(Widget w, XEvent *event, String *args,
2745 Cardinal *nArgs)
2747 WindowInfo *window = WidgetToWindow(w);
2749 if (CheckReadOnly(window))
2750 return;
2751 DoFindReplaceDlog(window, searchDirection(0, args, nArgs),
2752 searchType(0, args, nArgs), searchKeepDialogs(0, args, nArgs),
2753 event->xbutton.time);
2756 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2758 WindowInfo *window = WidgetToWindow(w);
2760 if (CheckReadOnly(window))
2761 return;
2762 if (*nArgs < 2) {
2763 fprintf(stderr,
2764 "NEdit: replace action requires search and replace string arguments\n");
2765 return;
2767 SearchAndReplace(window, searchDirection(2, args, nArgs),
2768 args[0], args[1], searchType(2, args, nArgs), searchWrap(2, args, nArgs));
2771 static void replaceAllAP(Widget w, XEvent *event, String *args,
2772 Cardinal *nArgs)
2774 WindowInfo *window = WidgetToWindow(w);
2776 if (CheckReadOnly(window))
2777 return;
2778 if (*nArgs < 2) {
2779 fprintf(stderr,
2780 "NEdit: replace_all action requires search and replace string arguments\n");
2781 return;
2783 ReplaceAll(window, args[0], args[1], searchType(2, args, nArgs));
2786 static void replaceInSelAP(Widget w, XEvent *event, String *args,
2787 Cardinal *nArgs)
2789 WindowInfo *window = WidgetToWindow(w);
2791 if (CheckReadOnly(window))
2792 return;
2793 if (*nArgs < 2) {
2794 fprintf(stderr,
2795 "NEdit: replace_in_selection requires search and replace string arguments\n");
2796 return;
2798 ReplaceInSelection(window, args[0], args[1],
2799 searchType(2, args, nArgs));
2802 static void replaceSameAP(Widget w, XEvent *event, String *args,
2803 Cardinal *nArgs)
2805 WindowInfo *window = WidgetToWindow(w);
2807 if (CheckReadOnly(window))
2808 return;
2809 ReplaceSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
2812 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2814 WindowInfo *window = WidgetToWindow(w);
2816 if (CheckReadOnly(window))
2817 return;
2818 if (*nArgs < 2) {
2819 DialogF(DF_WARN, window->shell, 1, "replace_find action requires search and replace string arguments", "OK");
2820 return;
2822 ReplaceAndSearch(window, searchDirection(2, args, nArgs),
2823 args[0], args[1], searchType(2, args, nArgs),
2824 searchWrap(0, args, nArgs));
2827 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
2828 Cardinal *nArgs)
2830 WindowInfo *window = WidgetToWindow(w);
2832 if (CheckReadOnly(window))
2833 return;
2834 ReplaceFindSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
2837 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2839 int lineNum, column, position, curCol;
2841 if (*nArgs == 0 || StringToLineAndCol( args[0], &lineNum, &column ) == -1) {
2842 fprintf(stderr,"NEdit: goto_line_number action requires line and/or column number\n");
2843 return;
2845 /* User specified column, but not line number */
2846 if ( lineNum == -1 ) {
2847 position = TextGetCursorPos(w);
2848 if (TextPosToLineAndCol(w, position, &lineNum,
2849 &curCol) == False) {
2850 return;
2853 /* User didn't specify a column */
2854 else if ( column == -1 ) {
2855 SelectNumberedLine(WidgetToWindow(w), lineNum);
2856 return;
2859 position = TextLineAndColToPos(w, lineNum, column );
2860 if ( position == -1 ) {
2861 return;
2863 TextSetCursorPos(w, position);
2864 return;
2867 static void gotoDialogAP(Widget w, XEvent *event, String *args,
2868 Cardinal *nArgs)
2870 GotoLineNumber(WidgetToWindow(w));
2873 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
2874 Cardinal *nArgs)
2876 GotoSelectedLineNumber(WidgetToWindow(w), event->xbutton.time);
2879 static void repeatDialogAP(Widget w, XEvent *event, String *args,
2880 Cardinal *nArgs)
2882 RepeatDialog(WidgetToWindow(w));
2885 static void repeatMacroAP(Widget w, XEvent *event, String *args,
2886 Cardinal *nArgs)
2888 int how;
2890 if (*nArgs != 2) {
2891 fprintf(stderr, "NEdit: repeat_macro requires two arguments\n");
2892 return;
2894 if (!strcmp(args[0], "in_selection"))
2895 how = REPEAT_IN_SEL;
2896 else if (!strcmp(args[0], "to_end"))
2897 how = REPEAT_TO_END;
2898 else if (sscanf(args[0], "%d", &how) != 1) {
2899 fprintf(stderr, "NEdit: repeat_macro requires method/count\n");
2900 return;
2902 RepeatMacro(WidgetToWindow(w), args[1], how);
2905 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2907 if (*nArgs == 0 || strlen(args[0]) != 1 ||
2908 !isalnum((unsigned char)args[0][0])) {
2909 fprintf(stderr,"NEdit: mark action requires a single-letter label\n");
2910 return;
2912 AddMark(WidgetToWindow(w), w, args[0][0]);
2915 static void markDialogAP(Widget w, XEvent *event, String *args,
2916 Cardinal *nArgs)
2918 MarkDialog(WidgetToWindow(w));
2921 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2923 if (*nArgs == 0 || strlen(args[0]) != 1 ||
2924 !isalnum((unsigned char)args[0][0])) {
2925 fprintf(stderr,
2926 "NEdit: goto_mark action requires a single-letter label\n");
2927 return;
2929 GotoMark(WidgetToWindow(w), w, args[0][0], *nArgs > 1 &&
2930 !strcmp(args[1], "extend"));
2933 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
2934 Cardinal *nArgs)
2936 GotoMarkDialog(WidgetToWindow(w), *nArgs!=0 && !strcmp(args[0], "extend"));
2939 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
2940 Cardinal *nArgs)
2942 SelectToMatchingCharacter(WidgetToWindow(w));
2945 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
2946 Cardinal *nArgs)
2948 GotoMatchingCharacter(WidgetToWindow(w));
2951 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2953 FindDefinition(WidgetToWindow(w), event->xbutton.time,
2954 *nArgs == 0 ? NULL : args[0]);
2957 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2959 FindDefCalltip(WidgetToWindow(w), event->xbutton.time,
2960 *nArgs == 0 ? NULL : args[0]);
2963 static void splitWindowAP(Widget w, XEvent *event, String *args,
2964 Cardinal *nArgs)
2966 WindowInfo *window = WidgetToWindow(w);
2968 SplitWindow(window);
2969 XtSetSensitive(window->splitWindowItem, window->nPanes < MAX_PANES);
2970 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
2973 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2975 WindowInfo *window = WidgetToWindow(w);
2977 ClosePane(window);
2978 XtSetSensitive(window->splitWindowItem, window->nPanes < MAX_PANES);
2979 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
2982 static void capitalizeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2984 WindowInfo *window = WidgetToWindow(w);
2986 if (CheckReadOnly(window))
2987 return;
2988 UpcaseSelection(window);
2991 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2993 WindowInfo *window = WidgetToWindow(w);
2995 if (CheckReadOnly(window))
2996 return;
2997 DowncaseSelection(window);
3000 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3002 WindowInfo *window = WidgetToWindow(w);
3004 if (CheckReadOnly(window))
3005 return;
3006 FillSelection(window);
3009 static void controlDialogAP(Widget w, XEvent *event, String *args,
3010 Cardinal *nArgs)
3012 WindowInfo *window = WidgetToWindow(w);
3013 unsigned char charCodeString[2];
3014 char charCodeText[DF_MAX_PROMPT_LENGTH], dummy[DF_MAX_PROMPT_LENGTH];
3015 char *params[1];
3016 int charCode, nRead, response;
3018 if (CheckReadOnly(window))
3019 return;
3020 response = DialogF(DF_PROMPT, window->shell, 2,
3021 "ASCII Character Code:", charCodeText, "OK", "Cancel");
3022 if (response == 2)
3023 return;
3024 /* If we don't scan for a trailing string invalid input
3025 would be accepted sometimes. */
3026 nRead = sscanf(charCodeText, "%i%s", &charCode, dummy);
3027 if (nRead != 1 || charCode < 0 || charCode > 255) {
3028 XBell(TheDisplay, 0);
3029 return;
3031 charCodeString[0] = (unsigned char)charCode;
3032 charCodeString[1] = '\0';
3033 params[0] = (char *)charCodeString;
3034 if (!BufSubstituteNullChars((char *)charCodeString, 1, window->buffer)) {
3035 DialogF(DF_ERR, window->shell, 1, "Too much binary data","Dismiss");
3036 return;
3038 XtCallActionProc(w, "insert_string", event, params, 1);
3041 #ifndef VMS
3042 static void filterDialogAP(Widget w, XEvent *event, String *args,
3043 Cardinal *nArgs)
3045 WindowInfo *window = WidgetToWindow(w);
3046 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3047 int resp;
3048 static char **cmdHistory = NULL;
3049 static int nHistoryCmds = 0;
3051 if (CheckReadOnly(window))
3052 return;
3053 if (!window->buffer->primary.selected) {
3054 XBell(TheDisplay, 0);
3055 return;
3058 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3059 resp = DialogF(DF_PROMPT, window->shell, 2,
3060 "Shell command: (use up arrow key to recall previous)",
3061 cmdText, "OK", "Cancel");
3062 if (resp == 2)
3063 return;
3064 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3065 params[0] = cmdText;
3066 XtCallActionProc(w, "filter_selection", event, params, 1);
3069 static void shellFilterAP(Widget w, XEvent *event, String *args,
3070 Cardinal *nArgs)
3072 WindowInfo *window = WidgetToWindow(w);
3074 if (CheckReadOnly(window))
3075 return;
3076 if (*nArgs == 0) {
3077 fprintf(stderr,
3078 "NEdit: filter_selection requires shell command argument\n");
3079 return;
3081 FilterSelection(window, args[0],
3082 event->xany.send_event == MACRO_EVENT_MARKER);
3085 static void execDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3087 WindowInfo *window = WidgetToWindow(w);
3088 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3089 int resp;
3090 static char **cmdHistory = NULL;
3091 static int nHistoryCmds = 0;
3093 if (CheckReadOnly(window))
3094 return;
3095 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3096 resp = DialogF(DF_PROMPT, window->shell, 2,
3097 "Shell command: (use up arrow key to recall previous;\n" \
3098 "%% expands to current filename, # to line number)",
3099 cmdText, "OK", "Cancel");
3100 if (resp == 2)
3101 return;
3102 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3103 params[0] = cmdText;
3104 XtCallActionProc(w, "execute_command", event, params, 1);;
3107 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3109 WindowInfo *window = WidgetToWindow(w);
3111 if (CheckReadOnly(window))
3112 return;
3113 if (*nArgs == 0) {
3114 fprintf(stderr,
3115 "NEdit: execute_command requires shell command argument\n");
3116 return;
3118 ExecShellCommand(window, args[0],
3119 event->xany.send_event == MACRO_EVENT_MARKER);
3122 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3124 WindowInfo *window = WidgetToWindow(w);
3126 if (CheckReadOnly(window))
3127 return;
3128 ExecCursorLine(window, event->xany.send_event == MACRO_EVENT_MARKER);
3131 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3133 if (*nArgs == 0) {
3134 fprintf(stderr,
3135 "NEdit: shell_menu_command requires item-name argument\n");
3136 return;
3138 HidePointerOnKeyedEvent(w, event);
3139 DoNamedShellMenuCmd(WidgetToWindow(w), args[0],
3140 event->xany.send_event == MACRO_EVENT_MARKER);
3142 #endif
3144 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3146 if (*nArgs == 0) {
3147 fprintf(stderr,
3148 "NEdit: macro_menu_command requires item-name argument\n");
3149 return;
3151 /* Don't allow users to execute a macro command from the menu (or accel)
3152 if there's already a macro command executing, UNLESS the macro is
3153 directly called from another one. NEdit can't handle
3154 running multiple, independent uncoordinated, macros in the same
3155 window. Macros may invoke macro menu commands recursively via the
3156 macro_menu_command action proc, which is important for being able to
3157 repeat any operation, and to embed macros within eachother at any
3158 level, however, a call here with a macro running means that THE USER
3159 is explicitly invoking another macro via the menu or an accelerator,
3160 UNLESS the macro event marker is set */
3161 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3162 if (WidgetToWindow(w)->macroCmdData != NULL) {
3163 XBell(TheDisplay, 0);
3164 return;
3167 HidePointerOnKeyedEvent(w, event);
3168 DoNamedMacroMenuCmd(WidgetToWindow(w), args[0]);
3171 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3173 if (*nArgs == 0) {
3174 fprintf(stderr,
3175 "NEdit: bg_menu_command requires item-name argument\n");
3176 return;
3178 /* Same remark as for macro menu commands (see above). */
3179 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3180 if (WidgetToWindow(w)->macroCmdData != NULL) {
3181 XBell(TheDisplay, 0);
3182 return;
3185 HidePointerOnKeyedEvent(w, event);
3186 DoNamedBGMenuCmd(WidgetToWindow(w), args[0]);
3189 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
3190 Cardinal *nArgs)
3192 textBuffer *buf = TextGetBuffer(w);
3193 int start, end, isRect, rectStart, rectEnd;
3195 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3196 return;
3197 if (!isRect)
3198 TextSetCursorPos(w, start);
3199 else
3200 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3201 BufStartOfLine(buf, start), rectStart));
3204 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
3205 Cardinal *nArgs)
3207 textBuffer *buf = TextGetBuffer(w);
3208 int start, end, isRect, rectStart, rectEnd;
3210 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3211 return;
3212 if (!isRect)
3213 TextSetCursorPos(w, end);
3214 else
3215 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3216 BufStartOfLine(buf, end), rectEnd));
3219 static void raiseWindowAP(Widget w, XEvent *event, String *args,
3220 Cardinal *nArgs)
3222 WindowInfo *window = WidgetToWindow(w);
3223 WindowInfo *nextWindow;
3224 WindowInfo *tmpWindow;
3225 int windowIndex;
3227 if (*nArgs > 0) {
3228 if (strcmp(args[0], "last") == 0) {
3229 window = WindowList;
3231 else if (strcmp(args[0], "first") == 0) {
3232 window = WindowList;
3233 if (window != NULL) {
3234 nextWindow = window->next;
3235 while (nextWindow != NULL) {
3236 window = nextWindow;
3237 nextWindow = nextWindow->next;
3241 else if (strcmp(args[0], "previous") == 0) {
3242 tmpWindow = window;
3243 window = WindowList;
3244 if (window != NULL) {
3245 nextWindow = window->next;
3246 while (nextWindow != NULL && nextWindow != tmpWindow) {
3247 window = nextWindow;
3248 nextWindow = nextWindow->next;
3250 if (nextWindow == NULL && tmpWindow != WindowList) {
3251 window = NULL;
3255 else if (strcmp(args[0], "next") == 0) {
3256 if (window != NULL) {
3257 window = window->next;
3258 if (window == NULL) {
3259 window = WindowList;
3263 else {
3264 if (sscanf(args[0], "%d", &windowIndex) == 1) {
3265 if (windowIndex > 0) {
3266 for (window = WindowList; window != NULL && windowIndex > 1;
3267 --windowIndex) {
3268 window = window->next;
3271 else if (windowIndex < 0) {
3272 for (window = WindowList; window != NULL;
3273 window = window->next) {
3274 ++windowIndex;
3276 if (windowIndex >= 0) {
3277 for (window = WindowList; window != NULL &&
3278 windowIndex > 0; window = window->next) {
3279 --windowIndex;
3282 else {
3283 window = NULL;
3286 else {
3287 window = NULL;
3290 else {
3291 window = NULL;
3295 if (window != NULL) {
3296 RaiseShellWindow(window->shell);
3298 else {
3299 XBell(TheDisplay, 0);
3303 static void focusPaneAP(Widget w, XEvent *event, String *args,
3304 Cardinal *nArgs)
3306 WindowInfo *window = WidgetToWindow(w);
3307 Widget newFocusPane = NULL;
3308 int paneIndex;
3310 if (*nArgs > 0) {
3311 if (strcmp(args[0], "first") == 0) {
3312 paneIndex = 0;
3314 else if (strcmp(args[0], "last") == 0) {
3315 paneIndex = window->nPanes;
3317 else if (strcmp(args[0], "next") == 0) {
3318 paneIndex = WidgetToPaneIndex(window, window->lastFocus) + 1;
3319 if (paneIndex > window->nPanes) {
3320 paneIndex = 0;
3323 else if (strcmp(args[0], "previous") == 0) {
3324 paneIndex = WidgetToPaneIndex(window, window->lastFocus) - 1;
3325 if (paneIndex < 0) {
3326 paneIndex = window->nPanes;
3329 else {
3330 if (sscanf(args[0], "%d", &paneIndex) == 1) {
3331 if (paneIndex > 0) {
3332 paneIndex = paneIndex - 1;
3334 else if (paneIndex < 0) {
3335 paneIndex = window->nPanes + (paneIndex + 1);
3337 else {
3338 paneIndex = -1;
3342 if (paneIndex >= 0 && paneIndex <= window->nPanes) {
3343 newFocusPane = GetPaneByIndex(window, paneIndex);
3345 if (newFocusPane != NULL) {
3346 window->lastFocus = newFocusPane;
3347 XmProcessTraversal(window->lastFocus, XmTRAVERSE_CURRENT);
3349 else {
3350 XBell(TheDisplay, 0);
3353 else {
3354 fprintf(stderr, "NEdit: focus_pane requires argument\n");
3358 #define ACTION_BOOL_PARAM_OR_TOGGLE(newState, numArgs, argvVal, oValue, actionName) \
3359 if ((numArgs) > 0) { \
3360 int intState; \
3362 if (sscanf(argvVal[0], "%d", &intState) == 1) { \
3363 (newState) = (intState != 0); \
3365 else { \
3366 fprintf(stderr, "NEdit: %s requires 0 or 1 argument\n", actionName); \
3367 return; \
3370 else { \
3371 (newState) = !(oValue); \
3374 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
3375 Cardinal *nArgs)
3377 WindowInfo *window = WidgetToWindow(w);
3378 Boolean newState;
3380 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->showStats, "set_statistics_line");
3382 XmToggleButtonSetState(window->statsLineItem, newState, False);
3383 ShowStatsLine(window, newState);
3386 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
3387 Cardinal *nArgs)
3389 WindowInfo *window = WidgetToWindow(w);
3390 Boolean newState;
3392 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->showISearchLine, "set_incremental_search_line");
3394 XmToggleButtonSetState(window->iSearchLineItem, newState, False);
3395 ShowISearchLine(window, newState);
3398 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
3399 Cardinal *nArgs)
3401 WindowInfo *window = WidgetToWindow(w);
3402 Boolean newState;
3404 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->showLineNumbers, "set_show_line_numbers");
3406 XmToggleButtonSetState(window->lineNumsItem, newState, False);
3407 ShowLineNumbers(window, newState);
3410 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
3411 Cardinal *nArgs)
3413 WindowInfo *window = WidgetToWindow(w);
3414 if (*nArgs > 0) {
3415 if (strcmp(args[0], "off") == 0) {
3416 SetAutoIndent(window, NO_AUTO_INDENT);
3418 else if (strcmp(args[0], "on") == 0) {
3419 SetAutoIndent(window, AUTO_INDENT);
3421 else if (strcmp(args[0], "smart") == 0) {
3422 SetAutoIndent(window, SMART_INDENT);
3424 else {
3425 fprintf(stderr, "NEdit: set_auto_indent invalid argument\n");
3428 else {
3429 fprintf(stderr, "NEdit: set_auto_indent requires argument\n");
3433 static void setWrapTextAP(Widget w, XEvent *event, String *args,
3434 Cardinal *nArgs)
3436 WindowInfo *window = WidgetToWindow(w);
3437 if (*nArgs > 0) {
3438 if (strcmp(args[0], "none") == 0) {
3439 SetAutoWrap(window, NO_WRAP);
3441 else if (strcmp(args[0], "auto") == 0) {
3442 SetAutoWrap(window, NEWLINE_WRAP);
3444 else if (strcmp(args[0], "continuous") == 0) {
3445 SetAutoWrap(window, CONTINUOUS_WRAP);
3447 else {
3448 fprintf(stderr, "NEdit: set_wrap_text invalid argument\n");
3451 else {
3452 fprintf(stderr, "NEdit: set_wrap_text requires argument\n");
3456 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
3457 Cardinal *nArgs)
3459 WindowInfo *window = WidgetToWindow(w);
3461 if (*nArgs > 0) {
3462 int newMargin = 0;
3463 if (sscanf(args[0], "%d", &newMargin) == 1 &&
3464 newMargin >= 0 &&
3465 newMargin < 1000) {
3466 int i;
3468 XtVaSetValues(window->textArea, textNwrapMargin, newMargin, NULL);
3469 for (i = 0; i < window->nPanes; ++i) {
3470 XtVaSetValues(window->textPanes[i], textNwrapMargin, newMargin, NULL);
3473 else {
3474 fprintf(stderr,
3475 "NEdit: set_wrap_margin requires integer argument >= 0 and < 1000\n");
3478 else {
3479 fprintf(stderr, "NEdit: set_wrap_margin requires argument\n");
3483 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
3484 Cardinal *nArgs)
3486 WindowInfo *window = WidgetToWindow(w);
3487 Boolean newState;
3489 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->highlightSyntax, "set_highlight_syntax");
3491 XmToggleButtonSetState(window->highlightItem, newState, False);
3492 window->highlightSyntax = newState;
3493 if (window->highlightSyntax) {
3494 StartHighlighting(window, True);
3495 } else {
3496 StopHighlighting(window);
3500 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
3501 Cardinal *nArgs)
3503 WindowInfo *window = WidgetToWindow(w);
3504 Boolean newState;
3506 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->saveOldVersion, "set_make_backup_copy");
3508 XmToggleButtonSetState(window->saveLastItem, newState, False);
3509 window->saveOldVersion = newState;
3512 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
3513 Cardinal *nArgs)
3515 WindowInfo *window = WidgetToWindow(w);
3516 Boolean newState;
3518 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->autoSave, "set_incremental_backup");
3520 XmToggleButtonSetState(window->autoSaveItem, newState, False);
3521 window->autoSave = newState;
3524 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
3525 Cardinal *nArgs)
3527 WindowInfo *window = WidgetToWindow(w);
3528 if (*nArgs > 0) {
3529 if (strcmp(args[0], NO_FLASH_STRING) == 0) {
3530 SetShowMatching(window, NO_FLASH);
3532 else if (strcmp(args[0], FLASH_DELIMIT_STRING) == 0) {
3533 SetShowMatching(window, FLASH_DELIMIT);
3535 else if (strcmp(args[0], FLASH_RANGE_STRING) == 0) {
3536 SetShowMatching(window, FLASH_RANGE);
3538 /* For backward compatibility with pre-5.2 versions, we also
3539 accept 0 and 1 as aliases for NO_FLASH and FLASH_DELIMIT.
3540 It is quite unlikely, though, that anyone ever used this
3541 action procedure via the macro language or a key binding,
3542 so this can probably be left out safely. */
3543 else if (strcmp(args[0], "0") == 0) {
3544 SetShowMatching(window, NO_FLASH);
3546 else if (strcmp(args[0], "1") == 0) {
3547 SetShowMatching(window, FLASH_DELIMIT);
3549 else {
3550 fprintf(stderr, "NEdit: Invalid argument for set_show_matching\n");
3553 else {
3554 fprintf(stderr, "NEdit: set_show_matching requires argument\n");
3558 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
3559 Cardinal *nArgs)
3561 WindowInfo *window = WidgetToWindow(w);
3562 Boolean newState;
3564 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
3566 XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
3567 window->matchSyntaxBased = newState;
3570 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
3571 Cardinal *nArgs)
3573 WindowInfo *window = WidgetToWindow(w);
3574 Boolean newState;
3576 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->overstrike, "set_overtype_mode");
3578 XmToggleButtonSetState(window->overtypeModeItem, newState, False);
3579 SetOverstrike(window, newState);
3582 static void setLockedAP(Widget w, XEvent *event, String *args,
3583 Cardinal *nArgs)
3585 WindowInfo *window = WidgetToWindow(w);
3586 Boolean newState;
3588 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, IS_USER_LOCKED(window->lockReasons), "set_locked");
3590 SET_USER_LOCKED(window->lockReasons, newState);
3591 XmToggleButtonSetState(window->readOnlyItem, IS_ANY_LOCKED(window->lockReasons), False);
3592 UpdateWindowTitle(window);
3593 UpdateWindowReadOnly(window);
3596 static void setTabDistAP(Widget w, XEvent *event, String *args,
3597 Cardinal *nArgs)
3599 WindowInfo *window = WidgetToWindow(w);
3601 if (*nArgs > 0) {
3602 int newTabDist = 0;
3603 if (sscanf(args[0], "%d", &newTabDist) == 1 &&
3604 newTabDist > 0 &&
3605 newTabDist <= MAX_EXP_CHAR_LEN) {
3606 SetTabDist(window, newTabDist);
3608 else {
3609 fprintf(stderr,
3610 "NEdit: set_tab_dist requires integer argument > 0 and <= %d\n",
3611 MAX_EXP_CHAR_LEN);
3614 else {
3615 fprintf(stderr, "NEdit: set_tab_dist requires argument\n");
3619 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
3620 Cardinal *nArgs)
3622 WindowInfo *window = WidgetToWindow(w);
3624 if (*nArgs > 0) {
3625 int newEmTabDist = 0;
3626 if (sscanf(args[0], "%d", &newEmTabDist) == 1 &&
3627 newEmTabDist >= -1 &&
3628 newEmTabDist < 1000) {
3629 if (newEmTabDist < 0) {
3630 newEmTabDist = 0;
3632 SetEmTabDist(window, newEmTabDist);
3634 else {
3635 fprintf(stderr,
3636 "NEdit: set_em_tab_dist requires integer argument >= -1 and < 1000\n");
3639 else {
3640 fprintf(stderr, "NEdit: set_em_tab_dist requires argument\n");
3644 static void setUseTabsAP(Widget w, XEvent *event, String *args,
3645 Cardinal *nArgs)
3647 WindowInfo *window = WidgetToWindow(w);
3648 Boolean newState;
3650 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->buffer->useTabs, "set_use_tabs");
3652 window->buffer->useTabs = newState;
3655 static void setFontsAP(Widget w, XEvent *event, String *args,
3656 Cardinal *nArgs)
3658 WindowInfo *window = WidgetToWindow(w);
3659 if (*nArgs >= 4) {
3660 SetFonts(window, args[0], args[1], args[2], args[3]);
3662 else {
3663 fprintf(stderr, "NEdit: set_fonts requires 4 arguments\n");
3667 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
3668 Cardinal *nArgs)
3670 WindowInfo *window = WidgetToWindow(w);
3672 if (*nArgs > 0) {
3673 SetLanguageMode(window, FindLanguageMode(args[0]), FALSE);
3675 else {
3676 fprintf(stderr, "NEdit: set_language_mode requires argument\n");
3681 ** Same as AddSubMenu from libNUtil.a but 1) mnemonic is optional (NEdit
3682 ** users like to be able to re-arrange the mnemonics so they can set Alt
3683 ** key combinations as accelerators), 2) supports the short/full option
3684 ** of SGI_CUSTOM mode, 3) optionally returns the cascade button widget
3685 ** in "cascadeBtn" if "cascadeBtn" is non-NULL.
3687 static Widget createMenu(Widget parent, char *name, char *label,
3688 char mnemonic, Widget *cascadeBtn, int mode)
3690 Widget menu, cascade;
3691 XmString st1;
3693 menu = CreatePulldownMenu(parent, name, NULL, 0);
3694 cascade = XtVaCreateWidget(name, xmCascadeButtonWidgetClass, parent,
3695 XmNlabelString, st1=XmStringCreateSimple(label),
3696 XmNsubMenuId, menu, NULL);
3697 XmStringFree(st1);
3698 if (mnemonic != 0)
3699 XtVaSetValues(cascade, XmNmnemonic, mnemonic, NULL);
3700 #ifdef SGI_CUSTOM
3701 if (mode == SHORT || !GetPrefShortMenus())
3702 XtManageChild(cascade);
3703 if (mode == FULL)
3704 addToToggleShortList(cascade);
3705 #else
3706 XtManageChild(cascade);
3707 #endif
3708 if (cascadeBtn != NULL)
3709 *cascadeBtn = cascade;
3710 return menu;
3714 ** Same as AddMenuItem from libNUtil.a without setting the accelerator
3715 ** (these are set in the fallback app-defaults so users can change them),
3716 ** and with the short/full option required in SGI_CUSTOM mode.
3718 static Widget createMenuItem(Widget parent, char *name, char *label,
3719 char mnemonic, menuCallbackProc callback, void *cbArg, int mode)
3721 Widget button;
3722 XmString st1;
3725 button = XtVaCreateWidget(name, xmPushButtonWidgetClass, parent,
3726 XmNlabelString, st1=XmStringCreateSimple(label),
3727 XmNmnemonic, mnemonic, NULL);
3728 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
3729 XmStringFree(st1);
3730 #ifdef SGI_CUSTOM
3731 if (mode == SHORT || !GetPrefShortMenus())
3732 XtManageChild(button);
3733 if (mode == FULL)
3734 addToToggleShortList(button);
3735 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
3736 #else
3737 XtManageChild(button);
3738 #endif
3739 return button;
3743 ** "fake" menu items allow accelerators to be attached, but don't show up
3744 ** in the menu. They are necessary to process the shifted menu items because
3745 ** Motif does not properly process the event descriptions in accelerator
3746 ** resources, and you can't specify "shift key is optional"
3748 static Widget createFakeMenuItem(Widget parent, char *name,
3749 menuCallbackProc callback, void *cbArg)
3751 Widget button;
3752 XmString st1;
3754 button = XtVaCreateManagedWidget(name, xmPushButtonWidgetClass, parent,
3755 XmNlabelString, st1=XmStringCreateSimple(""),
3756 XmNshadowThickness, 0,
3757 XmNmarginHeight, 0,
3758 XmNheight, 0, NULL);
3759 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
3760 XmStringFree(st1);
3761 XtVaSetValues(button, XmNtraversalOn, False, NULL);
3763 return button;
3767 ** Add a toggle button item to an already established pull-down or pop-up
3768 ** menu, including mnemonics, accelerators and callbacks.
3770 static Widget createMenuToggle(Widget parent, char *name, char *label,
3771 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
3772 int mode)
3774 Widget button;
3775 XmString st1;
3777 button = XtVaCreateWidget(name, xmToggleButtonWidgetClass, parent,
3778 XmNlabelString, st1=XmStringCreateSimple(label),
3779 XmNmnemonic, mnemonic,
3780 XmNset, set, NULL);
3781 XtAddCallback(button, XmNvalueChangedCallback, (XtCallbackProc)callback,
3782 cbArg);
3783 XmStringFree(st1);
3784 #ifdef SGI_CUSTOM
3785 if (mode == SHORT || !GetPrefShortMenus())
3786 XtManageChild(button);
3787 if (mode == FULL)
3788 addToToggleShortList(button);
3789 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
3790 #else
3791 XtManageChild(button);
3792 #endif
3793 return button;
3797 ** Create a toggle button with a diamond (radio-style) appearance
3799 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
3800 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
3801 int mode)
3803 Widget button;
3804 button = createMenuToggle(parent, name, label, mnemonic, callback, cbArg,
3805 set, mode);
3806 XtVaSetValues(button, XmNindicatorType, XmONE_OF_MANY, NULL);
3807 return button;
3810 static Widget createMenuSeparator(Widget parent, char *name, int mode)
3812 Widget button;
3814 button = XmCreateSeparator(parent, name, NULL, 0);
3815 #ifdef SGI_CUSTOM
3816 if (mode == SHORT || !GetPrefShortMenus())
3817 XtManageChild(button);
3818 if (mode == FULL)
3819 addToToggleShortList(button);
3820 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
3821 #else
3822 XtManageChild(button);
3823 #endif
3824 return button;
3828 ** Make sure the close menu item is dimmed appropriately for the current
3829 ** set of windows. It should be dim only for the last Untitled, unmodified,
3830 ** editor window, and sensitive otherwise.
3832 void CheckCloseDim(void)
3834 WindowInfo *window;
3836 if (WindowList == NULL)
3837 return;
3838 if (WindowList->next==NULL &&
3839 !WindowList->filenameSet && !WindowList->fileChanged) {
3840 XtSetSensitive(WindowList->closeItem, FALSE);
3841 return;
3844 for (window=WindowList; window!=NULL; window=window->next)
3845 XtSetSensitive(window->closeItem, True);
3849 ** Invalidate the Window menus of all NEdit windows to but don't change
3850 ** the menus until they're needed (Originally, this was "UpdateWindowMenus",
3851 ** but creating and destroying manu items for every window every time a
3852 ** new window was created or something changed, made things move very
3853 ** slowly with more than 10 or so windows).
3855 void InvalidateWindowMenus(void)
3857 WindowInfo *w;
3859 /* Mark the window menus invalid (to be updated when the user pulls one
3860 down), unless the menu is torn off, meaning it is visible to the user
3861 and should be updated immediately */
3862 for (w=WindowList; w!=NULL; w=w->next) {
3863 if (!XmIsMenuShell(XtParent(w->windowMenuPane)))
3864 updateWindowMenu(w);
3865 else
3866 w->windowMenuValid = False;
3871 ** Mark the Previously Opened Files menus of all NEdit windows as invalid.
3872 ** Since actually changing the menus is slow, they're just marked and updated
3873 ** when the user pulls one down.
3875 static void invalidatePrevOpenMenus(void)
3877 WindowInfo *w;
3879 /* Mark the menus invalid (to be updated when the user pulls one
3880 down), unless the menu is torn off, meaning it is visible to the user
3881 and should be updated immediately */
3882 for (w=WindowList; w!=NULL; w=w->next) {
3883 if (!XmIsMenuShell(XtParent(w->prevOpenMenuPane)))
3884 updatePrevOpenMenu(w);
3885 else
3886 w->prevOpenMenuValid = False;
3891 ** Add a file to the list of previously opened files for display in the
3892 ** File menu.
3894 void AddToPrevOpenMenu(const char *filename)
3896 int i;
3897 char *nameCopy;
3898 WindowInfo *w;
3900 /* If the Open Previous command is disabled, just return */
3901 if (GetPrefMaxPrevOpenFiles() == 0)
3902 return;
3904 /* If the name is already in the list, move it to the start */
3905 for (i=0; i<NPrevOpen; i++) {
3906 if (!strcmp(filename, PrevOpen[i])) {
3907 nameCopy = PrevOpen[i];
3908 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * i);
3909 PrevOpen[0] = nameCopy;
3910 invalidatePrevOpenMenus();
3911 WriteNEditDB();
3912 return;
3916 /* If the list is already full, make room */
3917 if (NPrevOpen == GetPrefMaxPrevOpenFiles())
3918 XtFree(PrevOpen[--NPrevOpen]);
3920 /* Add it to the list */
3921 nameCopy = XtMalloc(strlen(filename) + 1);
3922 strcpy(nameCopy, filename);
3923 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * NPrevOpen);
3924 PrevOpen[0] = nameCopy;
3925 NPrevOpen++;
3927 /* Mark the Previously Opened Files menu as invalid in all windows */
3928 invalidatePrevOpenMenus();
3930 /* Undim the menu in all windows if it was previously empty */
3931 if (NPrevOpen == 1)
3932 for (w=WindowList; w!=NULL; w=w->next)
3933 XtSetSensitive(w->prevOpenMenuItem, True);
3935 /* Write the menu contents to disk to restore in later sessions */
3936 WriteNEditDB();
3939 static char* getWindowsMenuEntry(const WindowInfo* thisWindow, const WindowInfo* window)
3941 static char fullTitle[MAXPATHLEN * 2 + 3+ 1];
3942 const char *title;
3944 XtVaGetValues(window->shell, XmNiconName, &title, NULL);
3945 #ifdef SGI_CUSTOM
3946 title = title + SGI_WINDOW_TITLE_LEN;
3947 #endif
3948 strcpy(fullTitle, title);
3949 if (thisWindow->showPathInWindowsMenu && window->filenameSet)
3951 strcat(fullTitle, " - ");
3952 strcat(fullTitle, window->path);
3955 return(fullTitle);
3959 ** Update the Window menu of a single window to reflect the current state of
3960 ** all NEdit windows as determined by the global WindowList.
3962 static void updateWindowMenu(const WindowInfo *window)
3964 WindowInfo *w;
3965 WidgetList items;
3966 Cardinal nItems;
3967 int i, n, nWindows, windowIndex;
3968 WindowInfo **windows;
3970 /* Make a sorted list of windows */
3971 for (w=WindowList, nWindows=0; w!=NULL; w=w->next, nWindows++);
3972 windows = (WindowInfo **)XtMalloc(sizeof(WindowInfo *) * nWindows);
3973 for (w=WindowList, i=0; w!=NULL; w=w->next, i++)
3974 windows[i] = w;
3975 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowNames);
3977 /* While it is not possible on some systems (ibm at least) to substitute
3978 a new menu pane, it is possible to substitute menu items, as long as
3979 at least one remains in the menu at all times. This routine assumes
3980 that the menu contains permanent items marked with the value
3981 PERMANENT_MENU_ITEM in the userData resource, and adds and removes items
3982 which it marks with the value TEMPORARY_MENU_ITEM */
3984 /* Go thru all of the items in the menu and rename them to
3985 match the window list. Delete any extras */
3986 XtVaGetValues(window->windowMenuPane, XmNchildren, &items,
3987 XmNnumChildren, &nItems, NULL);
3988 windowIndex = 0;
3989 for (n=0; n<(int)nItems; n++) {
3990 XtPointer userData;
3991 XtVaGetValues(items[n], XmNuserData, &userData, NULL);
3992 if (userData == TEMPORARY_MENU_ITEM) {
3993 if (windowIndex >= nWindows) {
3994 /* unmanaging before destroying stops parent from displaying */
3995 XtUnmanageChild(items[n]);
3996 XtDestroyWidget(items[n]);
3997 } else {
3998 XmString st1;
3999 char* title = getWindowsMenuEntry(window, windows[windowIndex]);
4000 XtVaSetValues(items[n], XmNlabelString,
4001 st1=XmStringCreateSimple(title), NULL);
4002 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4003 XtAddCallback(items[n], XmNactivateCallback,
4004 (XtCallbackProc)raiseCB, windows[windowIndex]);
4005 XmStringFree(st1);
4006 windowIndex++;
4011 /* Add new items for the titles of the remaining windows to the menu */
4012 for (; windowIndex<nWindows; windowIndex++) {
4013 XmString st1;
4014 char* title = getWindowsMenuEntry(window, windows[windowIndex]);
4015 Widget btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4016 window->windowMenuPane,
4017 XmNlabelString, st1=XmStringCreateSimple(title),
4018 XmNmarginHeight, 0,
4019 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4020 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)raiseCB,
4021 windows[windowIndex]);
4022 XmStringFree(st1);
4024 XtFree((char *)windows);
4028 ** Update the Previously Opened Files menu of a single window to reflect the
4029 ** current state of the list as retrieved from GetPrevOpenFiles.
4030 ** Thanks to Markus Schwarzenberg for the sorting part.
4032 static void updatePrevOpenMenu(WindowInfo *window)
4034 Widget btn;
4035 WidgetList items;
4036 Cardinal nItems;
4037 int n, index;
4038 XmString st1;
4039 char **prevOpenSorted;
4041 /* Sort the previously opened file list if requested */
4042 prevOpenSorted = (char **)XtMalloc(NPrevOpen * sizeof(char*));
4043 memcpy(prevOpenSorted, PrevOpen, NPrevOpen * sizeof(char*));
4044 if (GetPrefSortOpenPrevMenu())
4045 qsort(prevOpenSorted, NPrevOpen, sizeof(char*), cmpStrPtr);
4047 /* Go thru all of the items in the menu and rename them to match the file
4048 list. In older Motifs (particularly ibm), it was dangerous to replace
4049 a whole menu pane, which would be much simpler. However, since the
4050 code was already written for the Windows menu and is well tested, I'll
4051 stick with this weird method of re-naming the items */
4052 XtVaGetValues(window->prevOpenMenuPane, XmNchildren, &items,
4053 XmNnumChildren, &nItems, NULL);
4054 index = 0;
4055 for (n=0; n<(int)nItems; n++) {
4056 if (index >= NPrevOpen) {
4057 /* unmanaging before destroying stops parent from displaying */
4058 XtUnmanageChild(items[n]);
4059 XtDestroyWidget(items[n]);
4060 } else {
4061 XtVaSetValues(items[n], XmNlabelString,
4062 st1=XmStringCreateSimple(prevOpenSorted[index]), NULL);
4063 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4064 XtAddCallback(items[n], XmNactivateCallback,
4065 (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
4066 XmStringFree(st1);
4067 index++;
4071 /* Add new items for the remaining file names to the menu */
4072 for (; index<NPrevOpen; index++) {
4073 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4074 window->prevOpenMenuPane,
4075 XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
4076 XmNmarginHeight, 0,
4077 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4078 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)openPrevCB,
4079 prevOpenSorted[index]);
4080 XmStringFree(st1);
4083 XtFree((char*)prevOpenSorted);
4087 ** This function manages the display of the Tags File Menu, which is displayed
4088 ** when the user selects Un-load Tags File.
4090 static void updateTagsFileMenu(WindowInfo *window)
4092 tagFile *tf;
4093 Widget btn;
4094 WidgetList items;
4095 Cardinal nItems;
4096 int n;
4097 XmString st1;
4099 /* Go thru all of the items in the menu and rename them to match the file
4100 list. In older Motifs (particularly ibm), it was dangerous to replace
4101 a whole menu pane, which would be much simpler. However, since the
4102 code was already written for the Windows menu and is well tested, I'll
4103 stick with this weird method of re-naming the items */
4104 XtVaGetValues(window->unloadTagsMenuPane, XmNchildren, &items,
4105 XmNnumChildren, &nItems, NULL);
4106 tf = TagsFileList;
4107 for (n=0; n<(int)nItems; n++) {
4108 if (!tf) {
4109 /* unmanaging before destroying stops parent from displaying */
4110 XtUnmanageChild(items[n]);
4111 XtDestroyWidget(items[n]);
4112 } else {
4113 XtVaSetValues(items[n], XmNlabelString,
4114 st1=XmStringCreateSimple(tf->filename), NULL);
4115 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4116 XtAddCallback(items[n], XmNactivateCallback,
4117 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4118 XmStringFree(st1);
4119 tf = tf->next;
4123 /* Add new items for the remaining file names to the menu */
4124 while (tf) {
4125 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4126 window->unloadTagsMenuPane, XmNlabelString,
4127 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4128 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4129 XtAddCallback(btn, XmNactivateCallback,
4130 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4131 XmStringFree(st1);
4132 tf = tf->next;
4137 ** This function manages the display of the Tips File Menu, which is displayed
4138 ** when the user selects Un-load Calltips File.
4140 static void updateTipsFileMenu(WindowInfo *window)
4142 tagFile *tf;
4143 Widget btn;
4144 WidgetList items;
4145 Cardinal nItems;
4146 int n;
4147 XmString st1;
4149 /* Go thru all of the items in the menu and rename them to match the file
4150 list. In older Motifs (particularly ibm), it was dangerous to replace
4151 a whole menu pane, which would be much simpler. However, since the
4152 code was already written for the Windows menu and is well tested, I'll
4153 stick with this weird method of re-naming the items */
4154 XtVaGetValues(window->unloadTipsMenuPane, XmNchildren, &items,
4155 XmNnumChildren, &nItems, NULL);
4156 tf = TipsFileList;
4157 for (n=0; n<(int)nItems; n++) {
4158 if (!tf) {
4159 /* unmanaging before destroying stops parent from displaying */
4160 XtUnmanageChild(items[n]);
4161 XtDestroyWidget(items[n]);
4162 } else {
4163 XtVaSetValues(items[n], XmNlabelString,
4164 st1=XmStringCreateSimple(tf->filename), NULL);
4165 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4166 XtAddCallback(items[n], XmNactivateCallback,
4167 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4168 XmStringFree(st1);
4169 tf = tf->next;
4173 /* Add new items for the remaining file names to the menu */
4174 while (tf) {
4175 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4176 window->unloadTipsMenuPane, XmNlabelString,
4177 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4178 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4179 XtAddCallback(btn, XmNactivateCallback,
4180 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4181 XmStringFree(st1);
4182 tf = tf->next;
4187 ** Comparison function for sorting file names for the Open Previous submenu
4189 static int cmpStrPtr(const void *strA, const void *strB)
4191 return strcmp(*((char**)strA), *((char**)strB));
4195 ** Write dynamic database of file names for "Open Previous". Eventually,
4196 ** this may hold window positions, and possibly file marks, in which case,
4197 ** it should be moved to a different module, but for now it's just a list
4198 ** of previously opened files.
4200 void WriteNEditDB(void)
4202 const char* fullName = GetRCFileName(NEDIT_HISTORY);
4203 FILE *fp;
4204 int i;
4205 static char fileHeader[] =
4206 "# File name database for NEdit Open Previous command\n";
4208 /* If the Open Previous command is disabled, just return */
4209 if (GetPrefMaxPrevOpenFiles() == 0)
4210 return;
4212 /* open the file */
4213 if ((fp = fopen(fullName, "w")) == NULL)
4214 return;
4216 /* write the file header text to the file */
4217 fprintf(fp, "%s", fileHeader);
4219 /* Write the list of file names */
4220 for (i=0; i<NPrevOpen; i++)
4221 fprintf(fp, "%s\n", PrevOpen[i]);
4223 /* Close the file */
4224 fclose(fp);
4228 ** Read dynamic database of file names for "Open Previous". Eventually,
4229 ** this may hold window positions, and possibly file marks, in which case,
4230 ** it should be moved to a different module, but for now it's just a list
4231 ** of previously opened files. This routine should only be called once,
4232 ** at startup time, before any windows are open.
4234 void ReadNEditDB(void)
4236 const char* fullName = GetRCFileName(NEDIT_HISTORY);
4237 char line[MAXPATHLEN];
4238 char *nameCopy;
4239 FILE *fp;
4240 int lineLen;
4241 #ifdef VMS
4242 static char badFilenameChars[] = "\n\t*?()[]{}!@#%^&:;' ";
4243 #else
4244 static char badFilenameChars[] = "\n\t*?()[]{}";
4245 #endif
4247 /* If the Open Previous command is disabled, just return */
4248 if (GetPrefMaxPrevOpenFiles() == 0)
4249 return;
4251 /* Initialize the files list and allocate a (permanent) block memory
4252 of the size prescribed by the maxPrevOpenFiles resource */
4253 PrevOpen = (char **)XtMalloc(sizeof(char *) * GetPrefMaxPrevOpenFiles());
4254 NPrevOpen = 0;
4256 /* open the file */
4257 if ((fp = fopen(fullName, "r")) == NULL)
4258 return;
4260 /* read lines of the file, lines beginning with # are considered to be
4261 comments and are thrown away. Lines are subject to cursory checking,
4262 then just copied to the Open Previous file menu list */
4263 while (True) {
4264 if (fgets(line, (int)MAXPATHLEN, fp) == NULL) {
4265 fclose(fp);
4266 return; /* end of file */
4268 if (line[0] == '#')
4269 continue;
4270 lineLen = strlen(line); /* comment */
4271 if (line[lineLen-1] != '\n') {
4272 fprintf(stderr, ".neditdb line too long\n");
4273 fclose(fp);
4274 return; /* no newline, probably truncated */
4276 line[--lineLen] = '\0';
4277 if (lineLen == 0)
4278 continue; /* blank line */
4279 if ((int)strcspn(line, badFilenameChars) != lineLen) {
4280 fprintf(stderr, ".neditdb file is corrupted\n");
4281 fclose(fp);
4282 return; /* non-filename characters */
4284 nameCopy = XtMalloc(lineLen+1);
4285 strcpy(nameCopy, line);
4286 PrevOpen[NPrevOpen++] = nameCopy;
4287 if (NPrevOpen >= GetPrefMaxPrevOpenFiles()) {
4288 fclose(fp);
4289 return; /* too many entries */
4294 static void setWindowSizeDefault(int rows, int cols)
4296 SetPrefRows(rows);
4297 SetPrefCols(cols);
4298 updateWindowSizeMenus();
4301 static void updateWindowSizeMenus(void)
4303 WindowInfo *win;
4305 for (win=WindowList; win!=NULL; win=win->next)
4306 updateWindowSizeMenu(win);
4309 static void updateWindowSizeMenu(WindowInfo *win)
4311 int rows = GetPrefRows(), cols = GetPrefCols();
4312 char title[50];
4313 XmString st1;
4315 XmToggleButtonSetState(win->size24x80DefItem, rows==24&&cols==80,False);
4316 XmToggleButtonSetState(win->size40x80DefItem, rows==40&&cols==80,False);
4317 XmToggleButtonSetState(win->size60x80DefItem, rows==60&&cols==80,False);
4318 XmToggleButtonSetState(win->size80x80DefItem, rows==80&&cols==80,False);
4319 if ((rows!=24 && rows!=40 && rows!=60 && rows!=80) || cols!=80) {
4320 XmToggleButtonSetState(win->sizeCustomDefItem, True, False);
4321 sprintf(title, "Custom... (%d x %d)", rows, cols);
4322 XtVaSetValues(win->sizeCustomDefItem,
4323 XmNlabelString, st1=XmStringCreateSimple(title), NULL);
4324 XmStringFree(st1);
4325 } else {
4326 XmToggleButtonSetState(win->sizeCustomDefItem, False, False);
4327 XtVaSetValues(win->sizeCustomDefItem,
4328 XmNlabelString, st1=XmStringCreateSimple("Custom..."), NULL);
4329 XmStringFree(st1);
4334 ** Scans action argument list for arguments "forward" or "backward" to
4335 ** determine search direction for search and replace actions. "ignoreArgs"
4336 ** tells the routine how many required arguments there are to ignore before
4337 ** looking for keywords
4339 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs)
4341 int i;
4343 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4344 if (!strCaseCmp(args[i], "forward"))
4345 return SEARCH_FORWARD;
4346 if (!strCaseCmp(args[i], "backward"))
4347 return SEARCH_BACKWARD;
4349 return SEARCH_FORWARD;
4353 ** Scans action argument list for arguments "keep" or "nokeep" to
4354 ** determine whether to keep dialogs up for search and replace. "ignoreArgs"
4355 ** tells the routine how many required arguments there are to ignore before
4356 ** looking for keywords
4358 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs)
4360 int i;
4362 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4363 if (!strCaseCmp(args[i], "keep"))
4364 return TRUE;
4365 if (!strCaseCmp(args[i], "nokeep"))
4366 return FALSE;
4368 return GetPrefKeepSearchDlogs();
4372 ** Scans action argument list for arguments "wrap" or "nowrap" to
4373 ** determine search direction for search and replace actions. "ignoreArgs"
4374 ** tells the routine how many required arguments there are to ignore before
4375 ** looking for keywords
4377 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs)
4379 int i;
4381 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4382 if (!strCaseCmp(args[i], "wrap"))
4383 return(TRUE);
4384 if (!strCaseCmp(args[i], "nowrap"))
4385 return(FALSE);
4387 return GetPrefSearchWraps();
4391 ** Scans action argument list for arguments "literal", "case" or "regex" to
4392 ** determine search type for search and replace actions. "ignoreArgs"
4393 ** tells the routine how many required arguments there are to ignore before
4394 ** looking for keywords
4396 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs)
4398 int i, tmpSearchType;
4400 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4401 if (StringToSearchType(args[i], &tmpSearchType))
4402 return tmpSearchType;
4404 return GetPrefSearch();
4408 ** Return a pointer to the string describing search direction for search action
4409 ** routine parameters given a callback XmAnyCallbackStruct pointed to by
4410 ** "callData", by checking if the shift key is pressed (for search callbacks).
4412 static char **shiftKeyToDir(XtPointer callData)
4414 static char *backwardParam[1] = {"backward"};
4415 static char *forwardParam[1] = {"forward"};
4416 if (((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask)
4417 return backwardParam;
4418 return forwardParam;
4421 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData)
4423 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
4424 ((XmAnyCallbackStruct *)callData)->event);
4425 RaiseShellWindow(window->shell);
4428 static void openPrevCB(Widget w, char *name, caddr_t callData)
4430 char *params[1];
4431 Widget menu = MENU_WIDGET(w);
4433 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
4434 ((XmAnyCallbackStruct *)callData)->event);
4435 params[0] = name;
4436 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "open",
4437 ((XmAnyCallbackStruct *)callData)->event, params, 1);
4438 CheckCloseDim();
4441 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData)
4443 char *params[1];
4444 Widget menu = MENU_WIDGET(w);
4446 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
4447 ((XmAnyCallbackStruct *)callData)->event);
4448 params[0] = name;
4449 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tags_file",
4450 ((XmAnyCallbackStruct *)callData)->event, params, 1);
4453 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData)
4455 char *params[1];
4456 #if XmVersion >= 1002
4457 Widget menu = XmGetPostedFromWidget(XtParent(w)); /* If menu is torn off */
4458 #else
4459 Widget menu = w;
4460 #endif
4462 params[0] = name;
4463 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tips_file",
4464 ((XmAnyCallbackStruct *)callData)->event, params, 1);
4468 ** strCaseCmp compares its arguments and returns 0 if the two strings
4469 ** are equal IGNORING case differences. Otherwise returns 1.
4471 static int strCaseCmp(const char *str1, const char *str2)
4473 const char *c1, *c2;
4475 for (c1=str1, c2=str2; *c1!='\0' && *c2!='\0'; c1++, c2++)
4476 if (toupper((unsigned char)*c1) != toupper((unsigned char)*c2))
4477 return 1;
4478 if (*c1 == *c2) {
4479 return(0);
4481 else {
4482 return(1);
4487 ** Comparison function for sorting windows by title for the window menu.
4488 ** Windows are sorted by Untitled and then alphabetically by filename and
4489 ** then alphabetically by path.
4491 static int compareWindowNames(const void *windowA, const void *windowB)
4493 int rc;
4494 const WindowInfo *a = *((WindowInfo**)windowA);
4495 const WindowInfo *b = *((WindowInfo**)windowB);
4496 /* Untitled first */
4497 rc = a->filenameSet == b->filenameSet ? 0 :
4498 a->filenameSet && !b->filenameSet ? 1 : -1;
4499 if (rc != 0)
4500 return rc;
4501 rc = strcmp(a->filename, b->filename);
4502 if (rc != 0)
4503 return rc;
4504 rc = strcmp(a->path, b->path);
4505 return rc;
4509 ** Create popup for right button programmable menu
4511 Widget CreateBGMenu(WindowInfo *window)
4513 Arg args[1];
4515 /* There is still some mystery here. It's important to get the XmNmenuPost
4516 resource set to the correct menu button, or the menu will not post
4517 properly, but there's also some danger that it will take over the entire
4518 button and interfere with text widget translations which use the button
4519 with modifiers. I don't entirely understand why it works properly now
4520 when it failed often in development, and certainly ignores the ~ syntax
4521 in translation event specifications. */
4522 XtSetArg(args[0], XmNmenuPost, GetPrefBGMenuBtn());
4523 return CreatePopupMenu(window->textArea, "bgMenu", args, 1);
4527 ** Add a translation to the text widget to trigger the background menu using
4528 ** the mouse-button + modifier combination specified in the resource:
4529 ** nedit.bgMenuBtn.
4531 void AddBGMenuAction(Widget widget)
4533 static XtTranslations table = NULL;
4535 if (table == NULL) {
4536 char translations[MAX_ACCEL_LEN + 25];
4537 sprintf(translations, "%s: post_window_bg_menu()\n",GetPrefBGMenuBtn());
4538 table = XtParseTranslationTable(translations);
4540 XtOverrideTranslations(widget, table);
4543 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
4544 Cardinal *nArgs)
4546 WindowInfo *window = WidgetToWindow(w);
4548 /* The Motif popup handling code BLOCKS events while the menu is posted,
4549 including the matching btn-up events which complete various dragging
4550 operations which it may interrupt. Cancel to head off problems */
4551 XtCallActionProc(window->lastFocus, "process_cancel", event, NULL, 0);
4553 /* Pop up the menu */
4554 XmMenuPosition(window->bgMenuPane, (XButtonPressedEvent *)event);
4555 XtManageChild(window->bgMenuPane);
4558 These statements have been here for a very long time, but seem
4559 unnecessary and are even dangerous: when any of the lock keys are on,
4560 Motif thinks it shouldn't display the background menu, but this
4561 callback is called anyway. When we then grab the focus and force the
4562 menu to be drawn, bad things can happen (like a total lockup of the X
4563 server).
4565 XtPopup(XtParent(window->bgMenuPane), XtGrabNonexclusive);
4566 XtMapWidget(XtParent(window->bgMenuPane));
4567 XtMapWidget(window->bgMenuPane);
4571 #ifdef SGI_CUSTOM
4572 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData)
4574 WindowInfo *win;
4575 int i, state = XmToggleButtonGetState(w);
4576 Widget parent;
4578 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
4579 ((XmAnyCallbackStruct *)callData)->event);
4580 /* Set the preference */
4581 SetPrefShortMenus(state);
4583 /* Re-create the menus for all windows */
4584 for (win=WindowList; win!=NULL; win=win->next) {
4585 for (i=0; i<win->nToggleShortItems; i++) {
4586 if (state)
4587 XtUnmanageChild(win->toggleShortItems[i]);
4588 else
4589 XtManageChild(win->toggleShortItems[i]);
4592 if (GetPrefShortMenus())
4593 SaveNEditPrefs(window->shell, True);
4596 static void addToToggleShortList(Widget w)
4598 if (ShortMenuWindow->nToggleShortItems >= MAX_SHORTENED_ITEMS) {
4599 fprintf(stderr,"NEdit, internal error: increase MAX_SHORTENED_ITEMS\n");
4600 return;
4602 ShortMenuWindow->toggleShortItems[ShortMenuWindow->nToggleShortItems++] = w;
4606 ** Present the user a dialog for specifying whether or not a short
4607 ** menu mode preference should be applied toward the default setting.
4608 ** Return True if user requested to reset and save the default value.
4609 ** If operation was canceled, will return toggle widget "w" to it's
4610 ** original (opposite) state.
4612 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName)
4614 char msg[100] = "";
4616 if (!GetPrefShortMenus()) {
4617 return False;
4620 sprintf(msg, "%s: %s\nSave as default for future windows as well?",
4621 settingName, XmToggleButtonGetState(w) ? "On" : "Off");
4622 switch(DialogF (DF_QUES, parent, 3, msg, "Yes", "No", "Cancel")) {
4623 case 1: /* yes */
4624 return True;
4625 case 2: /* no */
4626 return False;
4627 case 3: /* cancel */
4628 XmToggleButtonSetState(w, !XmToggleButtonGetState(w), False);
4629 return False;
4631 return False; /* not reached */
4633 #endif