Committed SF patch #963120: Open tab in window on current desktop.
[nedit.git] / source / menu.c
blob52669e76019e94a705adb540d4289787e43f2280
1 static const char CVSID[] = "$Id: menu.c,v 1.104 2004/05/06 08:39:56 jlous 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"
59 #include "../Xlt/BubbleButton.h"
61 #include <stdlib.h>
62 #include <stdio.h>
63 #include <string.h>
64 #include <ctype.h>
65 #ifdef VMS
66 #include "../util/VMSparam.h"
67 #else
68 #ifndef __MVS__
69 #include <sys/param.h>
70 #endif
71 #endif /*VMS*/
72 #include <X11/X.h>
73 #include <Xm/Xm.h>
74 #include <Xm/CascadeB.h>
75 #include <Xm/PushB.h>
76 #include <Xm/ToggleB.h>
77 #include <Xm/Separator.h>
78 #include <Xm/RowColumn.h>
79 #include <Xm/MenuShell.h>
81 #ifdef HAVE_DEBUG_H
82 #include "../debug.h"
83 #endif
85 #if XmVersion >= 1002
86 #define MENU_WIDGET(w) (XmGetPostedFromWidget(XtParent(w)))
87 #else
88 #define MENU_WIDGET(w) (w)
89 #endif
91 /* Menu modes for SGI_CUSTOM short-menus feature */
92 enum menuModes {FULL, SHORT};
94 typedef void (*menuCallbackProc)();
96 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData);
97 static void doTabActionCB(Widget w, XtPointer clientData, XtPointer callData);
98 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData);
99 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData);
100 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData);
101 static void findCB(Widget w, XtPointer clientData, XtPointer callData);
102 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData);
103 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData);
104 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData);
105 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData);
106 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData);
107 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData);
108 static void markCB(Widget w, XtPointer clientData, XtPointer callData);
109 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData);
110 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData);
111 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData);
112 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData);
113 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData);
114 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData);
115 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData);
116 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData);
117 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData);
118 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData);
119 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData);
120 static void fontCB(Widget w, WindowInfo *window, caddr_t callData);
121 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData);
122 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData);
123 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData);
124 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData);
125 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData);
126 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData);
127 static void statsCB(Widget w, WindowInfo *window, caddr_t callData);
128 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
129 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
130 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData);
131 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
132 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData);
133 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
134 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
135 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
136 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData);
137 static void openInTabDefCB(Widget w, WindowInfo *window, caddr_t callData);
138 static void tabBarDefCB(Widget w, WindowInfo *window, caddr_t callData);
139 static void tabBarHideDefCB(Widget w, WindowInfo *window, caddr_t callData);
140 static void tabSortDefCB(Widget w, WindowInfo *window, caddr_t callData);
141 static void toolTipsDefCB(Widget w, WindowInfo *window, caddr_t callData);
142 static void tabNavigateDefCB(Widget w, WindowInfo *window, caddr_t callData);
143 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
144 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData);
145 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData);
146 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
147 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData);
148 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData);
149 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
150 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData);
151 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData);
152 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData);
153 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData);
154 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData);
155 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData);
156 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData);
157 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData);
158 static void smartTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
159 static void showAllTagsDefCB(Widget parent, XtPointer client_data, XtPointer call_data);
160 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData);
161 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData);
162 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData);
163 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData);
164 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData);
165 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData);
166 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData);
167 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
168 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
169 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window,
170 caddr_t callData);
171 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData);
172 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData);
173 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData);
174 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData);
175 static void autoScrollDefCB(Widget w, WindowInfo *window, caddr_t callData);
176 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
177 static void modWarnRealDefCB(Widget w, WindowInfo *window, caddr_t callData);
178 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData);
179 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData);
180 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData);
181 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData);
182 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData);
183 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData);
184 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData);
185 #ifdef REPLACE_SCOPE
186 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData);
187 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData);
188 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData);
189 #endif
190 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData);
191 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData);
192 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData);
193 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData);
194 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData);
195 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData);
196 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData);
197 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData);
198 static void learnCB(Widget w, WindowInfo *window, caddr_t callData);
199 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData);
200 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData);
201 static void replayCB(Widget w, WindowInfo *window, caddr_t callData);
202 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData);
203 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData);
204 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window,
205 caddr_t callData);
206 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window,
207 caddr_t callData);
208 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
209 static void newWindowAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
210 static void newTabAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
211 static void openDialogAP(Widget w, XEvent *event, String *args,
212 Cardinal *nArgs);
213 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
214 static void openSelectedAP(Widget w, XEvent *event, String *args,
215 Cardinal *nArgs);
216 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
217 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
218 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
219 Cardinal *nArgs);
220 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
221 static void revertDialogAP(Widget w, XEvent *event, String *args,
222 Cardinal *nArgs);
223 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
224 static void includeDialogAP(Widget w, XEvent *event, String *args,
225 Cardinal *nArgs);
226 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
227 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
228 Cardinal *nArgs) ;
229 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
230 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
231 Cardinal *nArgs);
232 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
233 static void unloadTagsAP(Widget w, XEvent *event, String *args,
234 Cardinal *nArgs);
235 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
236 Cardinal *nArgs);
237 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
238 static void unloadTipsAP(Widget w, XEvent *event, String *args,
239 Cardinal *nArgs);
240 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
241 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
242 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
243 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
244 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
245 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
246 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
247 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
248 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
249 Cardinal *nArgs);
250 static void shiftRightAP(Widget w, XEvent *event, String *args,
251 Cardinal *nArgs);
252 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
253 Cardinal *nArgs);
254 static void findDialogAP(Widget w, XEvent *event, String *args,
255 Cardinal *nArgs);
256 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
257 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
258 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
259 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
260 static void startIncrFindAP(Widget w, XEvent *event, String *args,
261 Cardinal *nArgs);
262 static void replaceDialogAP(Widget w, XEvent *event, String *args,
263 Cardinal *nArgs);
264 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
265 static void replaceAllAP(Widget w, XEvent *event, String *args,
266 Cardinal *nArgs);
267 static void replaceInSelAP(Widget w, XEvent *event, String *args,
268 Cardinal *nArgs);
269 static void replaceSameAP(Widget w, XEvent *event, String *args,
270 Cardinal *nArgs);
271 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
272 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
273 Cardinal *nArgs);
274 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
275 static void gotoDialogAP(Widget w, XEvent *event, String *args,
276 Cardinal *nArgs);
277 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
278 Cardinal *nArgs);
279 static void repeatDialogAP(Widget w, XEvent *event, String *args,
280 Cardinal *nArgs);
281 static void repeatMacroAP(Widget w, XEvent *event, String *args,
282 Cardinal *nArgs);
283 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
284 static void markDialogAP(Widget w, XEvent *event, String *args,
285 Cardinal *nArgs);
286 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
287 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
288 Cardinal *nArgs);
289 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
290 Cardinal *nArgs);
291 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
292 Cardinal *nArgs);
293 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
294 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
295 static void splitPaneAP(Widget w, XEvent *event, String *args,
296 Cardinal *nArgs);
297 static void detachDocumentDialogAP(Widget w, XEvent *event, String *args,
298 Cardinal *nArgs);
299 static void detachDocumentAP(Widget w, XEvent *event, String *args,
300 Cardinal *nArgs);
301 static void moveDocumentDialogAP(Widget w, XEvent *event, String *args,
302 Cardinal *nArgs);
303 static void nextDocumentAP(Widget w, XEvent *event, String *args,
304 Cardinal *nArgs);
305 static void prevDocumentAP(Widget w, XEvent *event, String *args,
306 Cardinal *nArgs);
307 static void lastDocumentAP(Widget w, XEvent *event, String *args,
308 Cardinal *nArgs);
309 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
310 static void capitalizeAP(Widget w, XEvent *event, String *args,
311 Cardinal *nArgs);
312 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
313 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
314 static void controlDialogAP(Widget w, XEvent *event, String *args,
315 Cardinal *nArgs);
316 #ifndef VMS
317 static void filterDialogAP(Widget w, XEvent *event, String *args,
318 Cardinal *nArgs);
319 static void shellFilterAP(Widget w, XEvent *event, String *args,
320 Cardinal *nArgs);
321 static void execDialogAP(Widget w, XEvent *event, String *args,
322 Cardinal *nArgs);
323 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
324 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
325 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
326 #endif
327 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
328 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs);
329 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
330 Cardinal *nArgs);
331 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
332 Cardinal *nArgs);
333 static Widget createMenu(Widget parent, char *name, char *label,
334 char mnemonic, Widget *cascadeBtn, int mode);
335 static Widget createMenuItem(Widget parent, char *name, char *label,
336 char mnemonic, menuCallbackProc callback, void *cbArg, int mode);
337 static Widget createFakeMenuItem(Widget parent, char *name,
338 menuCallbackProc callback, void *cbArg);
339 static Widget createMenuToggle(Widget parent, char *name, char *label,
340 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
341 int mode);
342 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
343 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
344 int mode);
345 static Widget createMenuSeparator(Widget parent, char *name, int mode);
346 static void invalidatePrevOpenMenus(void);
347 static void updateWindowMenu(const WindowInfo *window);
348 static void updatePrevOpenMenu(WindowInfo *window);
349 static void updateTagsFileMenu(WindowInfo *window);
350 static void updateTipsFileMenu(WindowInfo *window);
351 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs);
352 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs);
353 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs);
354 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs);
355 static char **shiftKeyToDir(XtPointer callData);
356 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData);
357 static void openPrevCB(Widget w, char *name, caddr_t callData);
358 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData);
359 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData);
360 static int cmpStrPtr(const void *strA, const void *strB);
361 static void setWindowSizeDefault(int rows, int cols);
362 static void updateWindowSizeMenus(void);
363 static void updateWindowSizeMenu(WindowInfo *win);
364 static int strCaseCmp(const char *str1, const char *str2);
365 static int compareWindowNames(const void *windowA, const void *windowB);
366 static int compareWindowShell(const void *windowA, const void *windowB);
367 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
368 Cardinal *nArgs);
369 static void tabMenuPostAP(Widget w, XEvent *event, String *args,
370 Cardinal *nArgs);
371 static void raiseWindowAP(Widget w, XEvent *event, String *args,
372 Cardinal *nArgs);
373 static void focusPaneAP(Widget w, XEvent *event, String *args,
374 Cardinal *nArgs);
375 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
376 Cardinal *nArgs);
377 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
378 Cardinal *nArgs);
379 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
380 Cardinal *nArgs);
381 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
382 Cardinal *nArgs);
383 static void setWrapTextAP(Widget w, XEvent *event, String *args,
384 Cardinal *nArgs);
385 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
386 Cardinal *nArgs);
387 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
388 Cardinal *nArgs);
389 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
390 Cardinal *nArgs);
391 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
392 Cardinal *nArgs);
393 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
394 Cardinal *nArgs);
395 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
396 Cardinal *nArgs);
397 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
398 Cardinal *nArgs);
399 static void setLockedAP(Widget w, XEvent *event, String *args,
400 Cardinal *nArgs);
401 static void setUseTabsAP(Widget w, XEvent *event, String *args,
402 Cardinal *nArgs);
403 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
404 Cardinal *nArgs);
405 static void setTabDistAP(Widget w, XEvent *event, String *args,
406 Cardinal *nArgs);
407 static void setFontsAP(Widget w, XEvent *event, String *args,
408 Cardinal *nArgs);
409 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
410 Cardinal *nArgs);
411 #ifdef SGI_CUSTOM
412 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData);
413 static void addToToggleShortList(Widget w);
414 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName);
415 #endif
417 static HelpMenu * buildHelpMenu( Widget pane, HelpMenu * menu,
418 WindowInfo * window);
420 /* Application action table */
421 static XtActionsRec Actions[] = {
422 {"new", newAP},
423 {"new_window", newWindowAP},
424 {"new_tab", newTabAP},
425 {"open", openAP},
426 {"open-dialog", openDialogAP},
427 {"open_dialog", openDialogAP},
428 {"open-selected", openSelectedAP},
429 {"open_selected", openSelectedAP},
430 {"close", closeAP},
431 {"save", saveAP},
432 {"save-as", saveAsAP},
433 {"save_as", saveAsAP},
434 {"save-as-dialog", saveAsDialogAP},
435 {"save_as_dialog", saveAsDialogAP},
436 {"revert-to-saved", revertAP},
437 {"revert_to_saved", revertAP},
438 {"revert_to_saved_dialog", revertDialogAP},
439 {"include-file", includeAP},
440 {"include_file", includeAP},
441 {"include-file-dialog", includeDialogAP},
442 {"include_file_dialog", includeDialogAP},
443 {"load-macro-file", loadMacroAP},
444 {"load_macro_file", loadMacroAP},
445 {"load-macro-file-dialog", loadMacroDialogAP},
446 {"load_macro_file_dialog", loadMacroDialogAP},
447 {"load-tags-file", loadTagsAP},
448 {"load_tags_file", loadTagsAP},
449 {"load-tags-file-dialog", loadTagsDialogAP},
450 {"load_tags_file_dialog", loadTagsDialogAP},
451 {"unload_tags_file", unloadTagsAP},
452 {"load_tips_file", loadTipsAP},
453 {"load_tips_file_dialog", loadTipsDialogAP},
454 {"unload_tips_file", unloadTipsAP},
455 {"print", printAP},
456 {"print-selection", printSelAP},
457 {"print_selection", printSelAP},
458 {"exit", exitAP},
459 {"undo", undoAP},
460 {"redo", redoAP},
461 {"delete", clearAP},
462 {"select-all", selAllAP},
463 {"select_all", selAllAP},
464 {"shift-left", shiftLeftAP},
465 {"shift_left", shiftLeftAP},
466 {"shift-left-by-tab", shiftLeftTabAP},
467 {"shift_left_by_tab", shiftLeftTabAP},
468 {"shift-right", shiftRightAP},
469 {"shift_right", shiftRightAP},
470 {"shift-right-by-tab", shiftRightTabAP},
471 {"shift_right_by_tab", shiftRightTabAP},
472 {"find", findAP},
473 {"find-dialog", findDialogAP},
474 {"find_dialog", findDialogAP},
475 {"find-again", findSameAP},
476 {"find_again", findSameAP},
477 {"find-selection", findSelAP},
478 {"find_selection", findSelAP},
479 {"find_incremental", findIncrAP},
480 {"start_incremental_find", startIncrFindAP},
481 {"replace", replaceAP},
482 {"replace-dialog", replaceDialogAP},
483 {"replace_dialog", replaceDialogAP},
484 {"replace-all", replaceAllAP},
485 {"replace_all", replaceAllAP},
486 {"replace-in-selection", replaceInSelAP},
487 {"replace_in_selection", replaceInSelAP},
488 {"replace-again", replaceSameAP},
489 {"replace_again", replaceSameAP},
490 {"replace_find", replaceFindAP},
491 {"replace_find_same", replaceFindSameAP},
492 {"replace_find_again", replaceFindSameAP},
493 {"goto-line-number", gotoAP},
494 {"goto_line_number", gotoAP},
495 {"goto-line-number-dialog", gotoDialogAP},
496 {"goto_line_number_dialog", gotoDialogAP},
497 {"goto-selected", gotoSelectedAP},
498 {"goto_selected", gotoSelectedAP},
499 {"mark", markAP},
500 {"mark-dialog", markDialogAP},
501 {"mark_dialog", markDialogAP},
502 {"goto-mark", gotoMarkAP},
503 {"goto_mark", gotoMarkAP},
504 {"goto-mark-dialog", gotoMarkDialogAP},
505 {"goto_mark_dialog", gotoMarkDialogAP},
506 {"match", selectToMatchingAP},
507 {"select_to_matching", selectToMatchingAP},
508 {"goto_matching", gotoMatchingAP},
509 {"find-definition", findDefAP},
510 {"find_definition", findDefAP},
511 {"show_tip", showTipAP},
512 {"split-pane", splitPaneAP},
513 {"split_pane", splitPaneAP},
514 {"close-pane", closePaneAP},
515 {"close_pane", closePaneAP},
516 {"detach_document", detachDocumentAP},
517 {"detach_document_dialog", detachDocumentDialogAP},
518 {"move_document_dialog", moveDocumentDialogAP},
519 {"next_document", nextDocumentAP},
520 {"previous_document", prevDocumentAP},
521 {"last_document", lastDocumentAP},
522 {"uppercase", capitalizeAP},
523 {"lowercase", lowercaseAP},
524 {"fill-paragraph", fillAP},
525 {"fill_paragraph", fillAP},
526 {"control-code-dialog", controlDialogAP},
527 {"control_code_dialog", controlDialogAP},
528 #ifndef VMS
529 {"filter-selection-dialog", filterDialogAP},
530 {"filter_selection_dialog", filterDialogAP},
531 {"filter-selection", shellFilterAP},
532 {"filter_selection", shellFilterAP},
533 {"execute-command", execAP},
534 {"execute_command", execAP},
535 {"execute-command-dialog", execDialogAP},
536 {"execute_command_dialog", execDialogAP},
537 {"execute-command-line", execLineAP},
538 {"execute_command_line", execLineAP},
539 {"shell-menu-command", shellMenuAP},
540 {"shell_menu_command", shellMenuAP},
541 #endif /*VMS*/
542 {"macro-menu-command", macroMenuAP},
543 {"macro_menu_command", macroMenuAP},
544 {"bg_menu_command", bgMenuAP},
545 {"post_window_bg_menu", bgMenuPostAP},
546 {"post_tab_context_menu", tabMenuPostAP},
547 {"beginning-of-selection", beginningOfSelectionAP},
548 {"beginning_of_selection", beginningOfSelectionAP},
549 {"end-of-selection", endOfSelectionAP},
550 {"end_of_selection", endOfSelectionAP},
551 {"repeat_macro", repeatMacroAP},
552 {"repeat_dialog", repeatDialogAP},
553 {"raise_window", raiseWindowAP},
554 {"focus_pane", focusPaneAP},
555 {"set_statistics_line", setStatisticsLineAP},
556 {"set_incremental_search_line", setIncrementalSearchLineAP},
557 {"set_show_line_numbers", setShowLineNumbersAP},
558 {"set_auto_indent", setAutoIndentAP},
559 {"set_wrap_text", setWrapTextAP},
560 {"set_wrap_margin", setWrapMarginAP},
561 {"set_highlight_syntax", setHighlightSyntaxAP},
562 #ifndef VMS
563 {"set_make_backup_copy", setMakeBackupCopyAP},
564 #endif
565 {"set_incremental_backup", setIncrementalBackupAP},
566 {"set_show_matching", setShowMatchingAP},
567 {"set_match_syntax_based", setMatchSyntaxBasedAP},
568 {"set_overtype_mode", setOvertypeModeAP},
569 {"set_locked", setLockedAP},
570 {"set_tab_dist", setTabDistAP},
571 {"set_em_tab_dist", setEmTabDistAP},
572 {"set_use_tabs", setUseTabsAP},
573 {"set_fonts", setFontsAP},
574 {"set_language_mode", setLanguageModeAP}
577 /* List of previously opened files for File menu */
578 static int NPrevOpen = 0;
579 static char **PrevOpen;
581 #ifdef SGI_CUSTOM
582 /* Window to receive items to be toggled on and off in short menus mode */
583 static WindowInfo *ShortMenuWindow;
584 #endif
586 void HidePointerOnKeyedEvent(Widget w, XEvent *event)
588 if (event && (event->type == KeyPress || event->type == KeyRelease)) {
589 ShowHidePointer((TextWidget)w, True);
594 ** Install actions for use in translation tables and macro recording, relating
595 ** to menu item commands
597 void InstallMenuActions(XtAppContext context)
599 XtAppAddActions(context, Actions, XtNumber(Actions));
603 ** Return the (statically allocated) action table for menu item actions.
605 XtActionsRec *GetMenuActions(int *nActions)
607 *nActions = XtNumber(Actions);
608 return Actions;
612 ** Create the menu bar
614 Widget CreateMenuBar(Widget parent, WindowInfo *window)
616 Widget menuBar, menuPane, btn, subPane, subSubPane, subSubSubPane, cascade;
619 ** cache user menus:
620 ** allocate user menu cache
622 window->userMenuCache = CreateUserMenuCache();
625 ** Create the menu bar (row column) widget
627 menuBar = XmCreateMenuBar(parent, "menuBar", NULL, 0);
629 #ifdef SGI_CUSTOM
631 ** Short menu mode is a special feature for the SGI system distribution
632 ** version of NEdit.
634 ** To make toggling short-menus mode faster (re-creating the menus was
635 ** too slow), a list is kept in the window data structure of items to
636 ** be turned on and off. Initialize that list and give the menu creation
637 ** routines a pointer to the window on which this list is kept. This is
638 ** (unfortunately) a global variable to keep the interface simple for
639 ** the mainstream case.
641 ShortMenuWindow = window;
642 window->nToggleShortItems = 0;
643 #endif
646 ** "File" pull down menu.
648 menuPane = createMenu(menuBar, "fileMenu", "File", 0, NULL, SHORT);
649 createMenuItem(menuPane, "newWindow", "New Window", 'N', doActionCB, "new_window", SHORT);
650 createMenuItem(menuPane, "newTab", "New Tab", 'T', doActionCB, "new_tab", SHORT);
651 createMenuItem(menuPane, "open", "Open...", 'O', doActionCB, "open_dialog",
652 SHORT);
653 window->openSelItem=createMenuItem(menuPane, "openSelected", "Open Selected", 'd',
654 doActionCB, "open_selected", FULL);
655 if (GetPrefMaxPrevOpenFiles() != 0) {
656 window->prevOpenMenuPane = createMenu(menuPane, "openPrevious",
657 "Open Previous", 'v', &window->prevOpenMenuItem, SHORT);
658 XtSetSensitive(window->prevOpenMenuItem, NPrevOpen != 0);
659 XtAddCallback(window->prevOpenMenuItem, XmNcascadingCallback,
660 (XtCallbackProc)prevOpenMenuCB, window);
662 createMenuSeparator(menuPane, "sep1", SHORT);
663 window->closeItem = createMenuItem(menuPane, "close", "Close", 'C',
664 doActionCB, "close", SHORT);
665 createMenuItem(menuPane, "save", "Save", 'S', doActionCB, "save", SHORT);
666 createMenuItem(menuPane, "saveAs", "Save As...", 'A', doActionCB,
667 "save_as_dialog", SHORT);
668 createMenuItem(menuPane, "revertToSaved", "Revert to Saved", 'R',
669 doActionCB, "revert_to_saved_dialog", SHORT);
670 createMenuSeparator(menuPane, "sep2", SHORT);
671 createMenuItem(menuPane, "includeFile", "Include File...", 'I',
672 doActionCB, "include_file_dialog", SHORT);
673 createMenuItem(menuPane, "loadMacroFile", "Load Macro File...", 'M',
674 doActionCB, "load_macro_file_dialog", FULL);
675 createMenuItem(menuPane, "loadTagsFile", "Load Tags File...", 'T',
676 doActionCB, "load_tags_file_dialog", FULL);
677 window->unloadTagsMenuPane = createMenu(menuPane, "unloadTagsFiles",
678 "Unload Tags File", 'U', &window->unloadTagsMenuItem, FULL);
679 XtSetSensitive(window->unloadTagsMenuItem, TagsFileList != NULL);
680 XtAddCallback(window->unloadTagsMenuItem, XmNcascadingCallback,
681 (XtCallbackProc)unloadTagsFileMenuCB, window);
682 createMenuItem(menuPane, "loadTipsFile", "Load Calltips File...", 'F',
683 doActionCB, "load_tips_file_dialog", FULL);
684 window->unloadTipsMenuPane = createMenu(menuPane, "unloadTipsFiles",
685 "Unload Calltips File", 'e', &window->unloadTipsMenuItem, FULL);
686 XtSetSensitive(window->unloadTipsMenuItem, TipsFileList != NULL);
687 XtAddCallback(window->unloadTipsMenuItem, XmNcascadingCallback,
688 (XtCallbackProc)unloadTipsFileMenuCB, window);
689 createMenuSeparator(menuPane, "sep3", SHORT);
690 createMenuItem(menuPane, "print", "Print...", 'P', doActionCB, "print",
691 SHORT);
692 window->printSelItem = createMenuItem(menuPane, "printSelection",
693 "Print Selection...", 'l', doActionCB, "print_selection",
694 SHORT);
695 XtSetSensitive(window->printSelItem, window->wasSelected);
696 createMenuSeparator(menuPane, "sep4", SHORT);
697 createMenuItem(menuPane, "exit", "Exit", 'x', doActionCB, "exit", SHORT);
698 CheckCloseDim();
701 ** "Edit" pull down menu.
703 menuPane = createMenu(menuBar, "editMenu", "Edit", 0, NULL, SHORT);
704 window->undoItem = createMenuItem(menuPane, "undo", "Undo", 'U',
705 doActionCB, "undo", SHORT);
706 XtSetSensitive(window->undoItem, False);
707 window->redoItem = createMenuItem(menuPane, "redo", "Redo", 'R',
708 doActionCB, "redo", SHORT);
709 XtSetSensitive(window->redoItem, False);
710 createMenuSeparator(menuPane, "sep1", SHORT);
711 window->cutItem = createMenuItem(menuPane, "cut", "Cut", 't', doActionCB,
712 "cut_clipboard", SHORT);
713 XtSetSensitive(window->cutItem, window->wasSelected);
714 window->copyItem = createMenuItem(menuPane, "copy", "Copy", 'C', doActionCB,
715 "copy_clipboard", SHORT);
716 XtSetSensitive(window->copyItem, window->wasSelected);
717 createMenuItem(menuPane, "paste", "Paste", 'P', doActionCB,
718 "paste_clipboard", SHORT);
719 createMenuItem(menuPane, "pasteColumn", "Paste Column", 's', pasteColCB,
720 window, SHORT);
721 window->delItem=createMenuItem(menuPane, "delete", "Delete", 'D', doActionCB, "delete_selection",
722 SHORT);
723 XtSetSensitive(window->delItem, window->wasSelected);
724 createMenuItem(menuPane, "selectAll", "Select All", 'A', doActionCB,
725 "select_all", SHORT);
726 createMenuSeparator(menuPane, "sep2", SHORT);
727 createMenuItem(menuPane, "shiftLeft", "Shift Left", 'L',
728 shiftLeftCB, window, SHORT);
729 createFakeMenuItem(menuPane, "shiftLeftShift", shiftLeftCB, window);
730 createMenuItem(menuPane, "shiftRight", "Shift Right", 'g',
731 shiftRightCB, window, SHORT);
732 createFakeMenuItem(menuPane, "shiftRightShift", shiftRightCB, window);
733 window->lowerItem=createMenuItem(menuPane, "lowerCase", "Lower-case", 'w',
734 doActionCB, "lowercase", SHORT);
735 window->upperItem=createMenuItem(menuPane, "upperCase", "Upper-case", 'e',
736 doActionCB, "uppercase", SHORT);
737 createMenuItem(menuPane, "fillParagraph", "Fill Paragraph", 'F',
738 doActionCB, "fill_paragraph", SHORT);
739 createMenuSeparator(menuPane, "sep3", FULL);
740 createMenuItem(menuPane, "insertFormFeed", "Insert Form Feed", 'I',
741 formFeedCB, window, FULL);
742 createMenuItem(menuPane, "insertCtrlCode", "Insert Ctrl Code...", 'n',
743 doActionCB, "control_code_dialog", FULL);
744 #ifdef SGI_CUSTOM
745 createMenuSeparator(menuPane, "sep4", SHORT);
746 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
747 doActionCB, "set_overtype_mode", False, SHORT);
748 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
749 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
750 #endif
753 ** "Search" pull down menu.
755 menuPane = createMenu(menuBar, "searchMenu", "Search", 0, NULL, SHORT);
756 createMenuItem(menuPane, "find", "Find...", 'F', findCB, window, SHORT);
757 createFakeMenuItem(menuPane, "findShift", findCB, window);
758 window->findAgainItem=createMenuItem(menuPane, "findAgain", "Find Again", 'i', findSameCB, window,
759 SHORT);
760 XtSetSensitive(window->findAgainItem, NHist);
761 createFakeMenuItem(menuPane, "findAgainShift", findSameCB, window);
762 window->findSelItem=createMenuItem(menuPane, "findSelection", "Find Selection", 'S',
763 findSelCB, window, SHORT);
764 createFakeMenuItem(menuPane, "findSelectionShift", findSelCB, window);
765 createMenuItem(menuPane, "findIncremental", "Find Incremental", 'n',
766 findIncrCB, window, SHORT);
767 createFakeMenuItem(menuPane, "findIncrementalShift", findIncrCB, window);
768 createMenuItem(menuPane, "replace", "Replace...", 'R', replaceCB, window,
769 SHORT);
770 createFakeMenuItem(menuPane, "replaceShift", replaceCB, window);
771 window->replaceFindAgainItem=createMenuItem(menuPane, "replaceFindAgain", "Replace Find Again", 'A',
772 replaceFindSameCB, window, SHORT);
773 XtSetSensitive(window->replaceFindAgainItem, NHist);
774 createFakeMenuItem(menuPane, "replaceFindAgainShift", replaceFindSameCB, window);
775 window->replaceAgainItem=createMenuItem(menuPane, "replaceAgain", "Replace Again", 'p',
776 replaceSameCB, window, SHORT);
777 XtSetSensitive(window->replaceAgainItem, NHist);
778 createFakeMenuItem(menuPane, "replaceAgainShift", replaceSameCB, window);
779 createMenuSeparator(menuPane, "sep1", FULL);
780 createMenuItem(menuPane, "gotoLineNumber", "Goto Line Number...", 'L',
781 doActionCB, "goto_line_number_dialog", FULL);
782 window->gotoSelItem=createMenuItem(menuPane, "gotoSelected", "Goto Selected", 'G',
783 doActionCB, "goto_selected", FULL);
784 createMenuSeparator(menuPane, "sep2", FULL);
785 createMenuItem(menuPane, "mark", "Mark", 'k', markCB, window, FULL);
786 createMenuItem(menuPane, "gotoMark", "Goto Mark", 'o', gotoMarkCB, window,
787 FULL);
788 createFakeMenuItem(menuPane, "gotoMarkShift", gotoMarkCB, window);
789 createMenuSeparator(menuPane, "sep3", FULL);
790 createMenuItem(menuPane, "gotoMatching", "Goto Matching (..)", 'M',
791 gotoMatchingCB, window, FULL);
792 createFakeMenuItem(menuPane, "gotoMatchingShift", gotoMatchingCB, window);
793 window->findDefItem = createMenuItem(menuPane, "findDefinition",
794 "Find Definition", 'D', doActionCB, "find_definition", FULL);
795 XtSetSensitive(window->findDefItem, TagsFileList != NULL);
796 window->showTipItem = createMenuItem(menuPane, "showCalltip",
797 "Show Calltip", 'C', doActionCB, "show_tip", FULL);
798 XtSetSensitive(window->showTipItem, (TagsFileList != NULL ||
799 TipsFileList != NULL) );
802 ** Preferences menu, Default Settings sub menu
804 menuPane = createMenu(menuBar, "preferencesMenu", "Preferences", 0, NULL,
805 SHORT);
806 subPane = createMenu(menuPane, "defaultSettings", "Default Settings", 'D',
807 NULL, FULL);
808 createMenuItem(subPane, "languageModes", "Language Modes...", 'L',
809 languageDefCB, window, FULL);
811 /* Auto Indent sub menu */
812 subSubPane = createMenu(subPane, "autoIndent", "Auto Indent", 'A',
813 NULL, FULL);
814 window->autoIndentOffDefItem = createMenuRadioToggle(subSubPane, "off",
815 "Off", 'O', autoIndentOffDefCB, window,
816 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == NO_AUTO_INDENT, SHORT);
817 window->autoIndentDefItem = createMenuRadioToggle(subSubPane, "on",
818 "On", 'n', autoIndentDefCB, window,
819 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == AUTO_INDENT, SHORT);
820 window->smartIndentDefItem = createMenuRadioToggle(subSubPane, "smart",
821 "Smart", 'S', smartIndentDefCB, window,
822 GetPrefAutoIndent(PLAIN_LANGUAGE_MODE) == SMART_INDENT, SHORT);
823 createMenuSeparator(subSubPane, "sep1", SHORT);
824 createMenuItem(subSubPane, "ProgramSmartIndent", "Program Smart Indent...",
825 'P', smartMacrosDefCB, window, FULL);
827 /* Wrap sub menu */
828 subSubPane = createMenu(subPane, "wrap", "Wrap", 'W', NULL, FULL);
829 window->noWrapDefItem = createMenuRadioToggle(subSubPane,
830 "none", "None", 'N', noWrapDefCB,
831 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NO_WRAP, SHORT);
832 window->newlineWrapDefItem = createMenuRadioToggle(subSubPane,
833 "autoNewline", "Auto Newline", 'A', newlineWrapDefCB,
834 window, GetPrefWrap(PLAIN_LANGUAGE_MODE) == NEWLINE_WRAP, SHORT);
835 window->contWrapDefItem = createMenuRadioToggle(subSubPane, "continuous",
836 "Continuous", 'C', contWrapDefCB, window,
837 GetPrefWrap(PLAIN_LANGUAGE_MODE) == CONTINUOUS_WRAP, SHORT);
838 createMenuSeparator(subSubPane, "sep1", SHORT);
839 createMenuItem(subSubPane, "wrapMargin", "Wrap Margin...", 'W',
840 wrapMarginDefCB, window, SHORT);
842 /* Smart Tags sub menu */
843 subSubPane = createMenu(subPane, "smartTags", "Tag Collisions", 'l',
844 NULL, FULL);
845 window->allTagsDefItem = createMenuRadioToggle(subSubPane, "showall",
846 "Show All", 'A', showAllTagsDefCB, window, !GetPrefSmartTags(),
847 FULL);
848 window->smartTagsDefItem = createMenuRadioToggle(subSubPane, "smart",
849 "Smart", 'S', smartTagsDefCB, window, GetPrefSmartTags(), FULL);
851 createMenuItem(subPane, "tabDistance", "Tab Stops...", 'T', tabsDefCB, window,
852 SHORT);
853 createMenuItem(subPane, "textFont", "Text Fonts...", 'F', fontDefCB, window,
854 FULL);
855 createMenuItem(subPane, "colors", "Colors...", 'C', colorDefCB, window,
856 FULL);
858 /* Customize Menus sub menu */
859 subSubPane = createMenu(subPane, "customizeMenus", "Customize Menus",
860 'u', NULL, FULL);
861 #ifndef VMS
862 createMenuItem(subSubPane, "shellMenu", "Shell Menu...", 'S',
863 shellDefCB, window, FULL);
864 #endif
865 createMenuItem(subSubPane, "macroMenu", "Macro Menu...", 'M',
866 macroDefCB, window, FULL);
867 createMenuItem(subSubPane, "windowBackgroundMenu",
868 "Window Background Menu...", 'W', bgMenuDefCB, window, FULL);
869 createMenuSeparator(subSubPane, "sep1", SHORT);
870 window->pathInWindowsMenuDefItem = createMenuToggle(subSubPane, "pathInWindowsMenu",
871 "Show Path In Windows Menu", 'P', pathInWindowsMenuDefCB, window, GetPrefShowPathInWindowsMenu(),
872 SHORT);
873 createMenuItem(subPane, "custimizeTitle", "Customize Window Title...", 'd',
874 customizeTitleDefCB, window, FULL);
876 /* Search sub menu */
877 subSubPane = createMenu(subPane, "searching", "Searching",
878 'g', NULL, FULL);
879 window->searchDlogsDefItem = createMenuToggle(subSubPane, "verbose",
880 "Verbose", 'V', searchDlogsDefCB, window,
881 GetPrefSearchDlogs(), SHORT);
882 window->searchWrapsDefItem = createMenuToggle(subSubPane, "wrapAround",
883 "Wrap Around", 'W', searchWrapsDefCB, window,
884 GetPrefSearchWraps(), SHORT);
885 window->beepOnSearchWrapDefItem = createMenuToggle(subSubPane,
886 "beepOnSearchWrap", "Beep On Search Wrap", 'B',
887 beepOnSearchWrapDefCB, window, GetPrefBeepOnSearchWrap(), SHORT);
888 window->keepSearchDlogsDefItem = createMenuToggle(subSubPane,
889 "keepDialogsUp", "Keep Dialogs Up", 'K',
890 keepSearchDlogsDefCB, window, GetPrefKeepSearchDlogs(), SHORT);
891 subSubSubPane = createMenu(subSubPane, "defaultSearchStyle",
892 "Default Search Style", 'D', NULL, FULL);
893 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
894 window->searchLiteralDefItem = createMenuToggle(subSubSubPane, "literal",
895 "Literal", 'L', searchLiteralCB, window,
896 GetPrefSearch() == SEARCH_LITERAL, FULL);
897 window->searchCaseSenseDefItem = createMenuToggle(subSubSubPane,
898 "caseSensitive", "Literal, Case Sensitive", 'C', searchCaseSenseCB, window,
899 GetPrefSearch() == SEARCH_CASE_SENSE, FULL);
900 window->searchLiteralWordDefItem = createMenuToggle(subSubSubPane, "literalWord",
901 "Literal, Whole Word", 'W', searchLiteralWordCB, window,
902 GetPrefSearch() == SEARCH_LITERAL_WORD, FULL);
903 window->searchCaseSenseWordDefItem = createMenuToggle(subSubSubPane,
904 "caseSensitiveWord", "Literal, Case Sensitive, Whole Word", 't', searchCaseSenseWordCB, window,
905 GetPrefSearch() == SEARCH_CASE_SENSE_WORD, FULL);
906 window->searchRegexDefItem = createMenuToggle(subSubSubPane,
907 "regularExpression", "Regular Expression", 'R', searchRegexCB,
908 window, GetPrefSearch() == SEARCH_REGEX, FULL);
909 window->searchRegexNoCaseDefItem = createMenuToggle(subSubSubPane,
910 "regularExpressionNoCase", "Regular Expression, Case Insensitive", 'I', searchRegexNoCaseCB, window,
911 GetPrefSearch() == SEARCH_REGEX_NOCASE, FULL);
912 #ifdef REPLACE_SCOPE
913 subSubSubPane = createMenu(subSubPane, "defaultReplaceScope",
914 "Default Replace Scope", 'R', NULL, FULL);
915 XtVaSetValues(subSubSubPane, XmNradioBehavior, True, NULL);
916 window->replScopeWinDefItem = createMenuToggle(subSubSubPane, "window",
917 "In Window", 'W', replaceScopeWindowCB, window,
918 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_WINDOW, FULL);
919 window->replScopeSelDefItem = createMenuToggle(subSubSubPane, "selection",
920 "In Selection", 'S', replaceScopeSelectionCB, window,
921 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SELECTION, FULL);
922 window->replScopeSmartDefItem = createMenuToggle(subSubSubPane, "window",
923 "Smart", 'm', replaceScopeSmartCB, window,
924 GetPrefReplaceDefScope() == REPL_DEF_SCOPE_SMART, FULL);
925 #endif
927 /* Syntax Highlighting sub menu */
928 subSubPane = createMenu(subPane, "syntaxHighlighting","Syntax Highlighting",
929 'H', NULL, FULL);
930 window->highlightOffDefItem = createMenuRadioToggle(subSubPane, "off","Off",
931 'O', highlightOffDefCB, window, !GetPrefHighlightSyntax(), FULL);
932 window->highlightDefItem = createMenuRadioToggle(subSubPane, "on",
933 "On", 'n', highlightDefCB, window, GetPrefHighlightSyntax(), FULL);
934 createMenuSeparator(subSubPane, "sep1", SHORT);
935 createMenuItem(subSubPane, "recognitionPatterns", "Recognition Patterns...",
936 'R', highlightingDefCB, window, FULL);
937 createMenuItem(subSubPane, "textDrawingStyles", "Text Drawing Styles...", 'T',
938 stylesDefCB, window, FULL);
939 window->backlightCharsDefItem = createMenuToggle(subPane,
940 "backlightChars", "Apply Backlighting", 'g', backlightCharsDefCB,
941 window, GetPrefBacklightChars(), FULL);
943 /* tabbed editing sub menu */
944 subSubPane = createMenu(subPane, "tabbedEditMenu", "Tabbed Editing", 0,
945 &cascade, SHORT);
946 window->openInTabDefItem = createMenuToggle(subSubPane, "openAsTab",
947 "Open File In New Tab", 'T', openInTabDefCB, window,
948 GetPrefOpenInTab(), FULL);
949 window->tabBarDefItem = createMenuToggle(subSubPane, "showTabBar",
950 "Show Tab Bar", 'B', tabBarDefCB, window,
951 GetPrefTabBar(), FULL);
952 window->tabBarHideDefItem = createMenuToggle(subSubPane,
953 "hideTabBar", "Hide Tab Bar When Only One Document is Open", 'H',
954 tabBarHideDefCB, window, GetPrefTabBarHideOne(), FULL);
955 window->tabNavigateDefItem = createMenuToggle(subSubPane, "tabNavigateDef",
956 "Next/Prev Tabs Across Windows", 'W', tabNavigateDefCB, window,
957 GetPrefGlobalTabNavigate(), FULL);
958 window->tabSortDefItem = createMenuToggle(subSubPane, "tabSortDef",
959 "Sort Tabs Alphabetically", 'S', tabSortDefCB, window,
960 GetPrefSortTabs(), FULL);
962 window->toolTipsDefItem = createMenuToggle(subPane, "showTooltips",
963 "Show Tooltips", 0, toolTipsDefCB, window, GetPrefToolTips(),
964 FULL);
965 window->statsLineDefItem = createMenuToggle(subPane, "statisticsLine",
966 "Statistics Line", 'S', statsLineDefCB, window, GetPrefStatsLine(),
967 SHORT);
968 window->iSearchLineDefItem = createMenuToggle(subPane,
969 "incrementalSearchLine", "Incremental Search Line", 'i',
970 iSearchLineDefCB, window, GetPrefISearchLine(), FULL);
971 window->lineNumsDefItem = createMenuToggle(subPane, "showLineNumbers",
972 "Show Line Numbers", 'N', lineNumsDefCB, window, GetPrefLineNums(),
973 SHORT);
974 window->saveLastDefItem = createMenuToggle(subPane, "preserveLastVersion",
975 "Make Backup Copy (*.bck)", 'e', preserveDefCB, window,
976 GetPrefSaveOldVersion(), SHORT);
977 window->autoSaveDefItem = createMenuToggle(subPane, "incrementalBackup",
978 "Incremental Backup", 'B', autoSaveDefCB, window, GetPrefAutoSave(),
979 SHORT);
982 /* Show Matching sub menu */
983 subSubPane = createMenu(subPane, "showMatching", "Show Matching (..)", 'M',
984 NULL, FULL);
985 window->showMatchingOffDefItem = createMenuRadioToggle(subSubPane, "off",
986 "Off", 'O', showMatchingOffDefCB, window,
987 GetPrefShowMatching() == NO_FLASH, SHORT);
988 window->showMatchingDelimitDefItem = createMenuRadioToggle(subSubPane,
989 "delimiter", "Delimiter", 'D', showMatchingDelimitDefCB, window,
990 GetPrefShowMatching() == FLASH_DELIMIT, SHORT);
991 window->showMatchingRangeDefItem = createMenuRadioToggle(subSubPane,
992 "range", "Range", 'R', showMatchingRangeDefCB, window,
993 GetPrefShowMatching() == FLASH_RANGE, SHORT);
994 createMenuSeparator(subSubPane, "sep", SHORT);
995 window->matchSyntaxBasedDefItem = createMenuToggle(subSubPane,
996 "matchSyntax", "Syntax Based", 'S', matchSyntaxBasedDefCB, window,
997 GetPrefMatchSyntaxBased(), SHORT);
999 /* Append LF at end of files on save */
1000 window->appendLFItem = createMenuToggle(subPane, "appendLFItem",
1001 "Terminate with Line Break on Save", 'v', appendLFCB, NULL,
1002 GetPrefAppendLF(), FULL);
1004 window->sortOpenPrevDefItem = createMenuToggle(subPane, "sortOpenPrevMenu",
1005 "Sort Open Prev. Menu", 'o', sortOpenPrevDefCB, window,
1006 GetPrefSortOpenPrevMenu(), FULL);
1007 window->reposDlogsDefItem = createMenuToggle(subPane, "popupsUnderPointer",
1008 "Popups Under Pointer", 'P', reposDlogsDefCB, window,
1009 GetPrefRepositionDialogs(), FULL);
1010 window->autoScrollDefItem = createMenuToggle(subPane, "autoScroll",
1011 "Auto Scroll Near Window Top/Bottom", 0, autoScrollDefCB, window,
1012 GetPrefAutoScroll(), FULL);
1013 subSubPane = createMenu(subPane, "warnings", "Warnings", 'r', NULL, FULL);
1014 window->modWarnDefItem = createMenuToggle(subSubPane,
1015 "filesModifiedExternally", "Files Modified Externally", 'F',
1016 modWarnDefCB, window, GetPrefWarnFileMods(), FULL);
1017 window->modWarnRealDefItem = createMenuToggle(subSubPane,
1018 "checkModifiedFileContents", "Check Modified File Contents", 'C',
1019 modWarnRealDefCB, window, GetPrefWarnRealFileMods(), FULL);
1020 XtSetSensitive(window->modWarnRealDefItem, GetPrefWarnFileMods());
1021 window->exitWarnDefItem = createMenuToggle(subSubPane, "onExit", "On Exit", 'O',
1022 exitWarnDefCB, window, GetPrefWarnExit(), FULL);
1024 /* Initial Window Size sub menu (simulates radioBehavior) */
1025 subSubPane = createMenu(subPane, "initialwindowSize",
1026 "Initial Window Size", 'z', NULL, FULL);
1027 /* XtVaSetValues(subSubPane, XmNradioBehavior, True, NULL); */
1028 window->size24x80DefItem = btn = createMenuToggle(subSubPane, "24X80",
1029 "24 x 80", '2', size24x80CB, window, False, SHORT);
1030 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1031 window->size40x80DefItem = btn = createMenuToggle(subSubPane, "40X80",
1032 "40 x 80", '4', size40x80CB, window, False, SHORT);
1033 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1034 window->size60x80DefItem = btn = createMenuToggle(subSubPane, "60X80",
1035 "60 x 80", '6', size60x80CB, window, False, SHORT);
1036 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1037 window->size80x80DefItem = btn = createMenuToggle(subSubPane, "80X80",
1038 "80 x 80", '8', size80x80CB, window, False, SHORT);
1039 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1040 window->sizeCustomDefItem = btn = createMenuToggle(subSubPane, "custom",
1041 "Custom...", 'C', sizeCustomCB, window, False, SHORT);
1042 XtVaSetValues(btn, XmNindicatorType, XmONE_OF_MANY, NULL);
1043 updateWindowSizeMenu(window);
1046 ** Remainder of Preferences menu
1048 createMenuItem(menuPane, "saveDefaults", "Save Defaults...", 'v',
1049 savePrefCB, window, FULL);
1050 #ifdef SGI_CUSTOM
1051 window->shortMenusDefItem = createMenuToggle(menuPane,
1052 "shortMenus", "Short Menus", 'h', shortMenusCB, window,
1053 GetPrefShortMenus(), SHORT);
1054 #endif
1055 createMenuSeparator(menuPane, "sep1", SHORT);
1056 window->statsLineItem = createMenuToggle(menuPane, "statisticsLine", "Statistics Line", 'S',
1057 statsCB, window, GetPrefStatsLine(), SHORT);
1058 window->iSearchLineItem = createMenuToggle(menuPane, "incremntalSearchLine","Incremental Search Line",
1059 'I', doActionCB, "set_incremental_search_line", GetPrefISearchLine(), FULL);
1060 window->lineNumsItem = createMenuToggle(menuPane, "lineNumbers", "Show Line Numbers", 'N',
1061 doActionCB, "set_show_line_numbers", GetPrefLineNums(), SHORT);
1062 CreateLanguageModeSubMenu(window, menuPane, "languageMode",
1063 "Language Mode", 'L');
1064 subPane = createMenu(menuPane, "autoIndent", "Auto Indent",
1065 'A', NULL, FULL);
1066 window->autoIndentOffItem = createMenuRadioToggle(subPane, "off", "Off",
1067 'O', autoIndentOffCB, window, window->indentStyle == NO_AUTO_INDENT,
1068 SHORT);
1069 window->autoIndentItem = createMenuRadioToggle(subPane, "on", "On", 'n',
1070 autoIndentCB, window, window->indentStyle == AUTO_INDENT, SHORT);
1071 window->smartIndentItem = createMenuRadioToggle(subPane, "smart", "Smart",
1072 'S', smartIndentCB, window, window->indentStyle == SMART_INDENT,
1073 SHORT);
1074 subPane = createMenu(menuPane, "wrap", "Wrap",
1075 'W', NULL, FULL);
1076 window->noWrapItem = createMenuRadioToggle(subPane, "none",
1077 "None", 'N', noWrapCB, window,
1078 window->wrapMode==NO_WRAP, SHORT);
1079 window->newlineWrapItem = createMenuRadioToggle(subPane, "autoNewlineWrap",
1080 "Auto Newline", 'A', newlineWrapCB, window,
1081 window->wrapMode==NEWLINE_WRAP, SHORT);
1082 window->continuousWrapItem = createMenuRadioToggle(subPane,
1083 "continuousWrap", "Continuous", 'C', continuousWrapCB, window,
1084 window->wrapMode==CONTINUOUS_WRAP, SHORT);
1085 createMenuSeparator(subPane, "sep1", SHORT);
1086 createMenuItem(subPane, "wrapMargin", "Wrap Margin...", 'W',
1087 wrapMarginCB, window, SHORT);
1088 createMenuItem(menuPane, "tabs", "Tab Stops...", 'T', tabsCB, window, SHORT);
1089 createMenuItem(menuPane, "textFont", "Text Fonts...", 'F', fontCB, window,
1090 FULL);
1091 window->highlightItem = createMenuToggle(menuPane, "highlightSyntax",
1092 "Highlight Syntax", 'H', doActionCB, "set_highlight_syntax",
1093 GetPrefHighlightSyntax(), SHORT);
1094 window->backlightCharsItem = createMenuToggle(menuPane, "backlightChars",
1095 "Apply Backlighting", 'g', backlightCharsCB, window,
1096 window->backlightChars, FULL);
1097 #ifndef VMS
1098 window->saveLastItem = createMenuToggle(menuPane, "makeBackupCopy",
1099 "Make Backup Copy (*.bck)", 'e', preserveCB, window,
1100 window->saveOldVersion, SHORT);
1101 #endif
1102 window->autoSaveItem = createMenuToggle(menuPane, "incrementalBackup",
1103 "Incremental Backup", 'B', autoSaveCB, window, window->autoSave,
1104 SHORT);
1106 subPane = createMenu(menuPane, "showMatching", "Show Matching (..)",
1107 'M', NULL, FULL);
1108 window->showMatchingOffItem = createMenuRadioToggle(subPane, "off", "Off",
1109 'O', showMatchingOffCB, window, window->showMatchingStyle == NO_FLASH,
1110 SHORT);
1111 window->showMatchingDelimitItem = createMenuRadioToggle(subPane,
1112 "delimiter", "Delimiter", 'D', showMatchingDelimitCB, window,
1113 window->showMatchingStyle == FLASH_DELIMIT, SHORT);
1114 window->showMatchingRangeItem = createMenuRadioToggle(subPane, "range",
1115 "Range", 'R', showMatchingRangeCB, window,
1116 window->showMatchingStyle == FLASH_RANGE, SHORT);
1117 createMenuSeparator(subPane, "sep", SHORT);
1118 window->matchSyntaxBasedItem = createMenuToggle(subPane, "matchSyntax",
1119 "Syntax Based", 'S', matchSyntaxBasedCB, window,
1120 window->matchSyntaxBased, SHORT);
1122 #ifndef SGI_CUSTOM
1123 createMenuSeparator(menuPane, "sep2", SHORT);
1124 window->overtypeModeItem = createMenuToggle(menuPane, "overtype", "Overtype", 'O',
1125 doActionCB, "set_overtype_mode", False, SHORT);
1126 window->readOnlyItem = createMenuToggle(menuPane, "readOnly", "Read Only",
1127 'y', doActionCB, "set_locked", IS_USER_LOCKED(window->lockReasons), FULL);
1128 #endif
1130 #ifndef VMS
1132 ** Create the Shell menu
1134 menuPane = window->shellMenuPane =
1135 createMenu(menuBar, "shellMenu", "Shell", 0, &cascade, FULL);
1136 btn = createMenuItem(menuPane, "executeCommand", "Execute Command...",
1137 'E', doActionCB, "execute_command_dialog", SHORT);
1138 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1139 btn = createMenuItem(menuPane, "executeCommandLine", "Execute Command Line",
1140 'x', doActionCB, "execute_command_line", SHORT);
1141 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1142 window->filterItem = createMenuItem(menuPane, "filterSelection",
1143 "Filter Selection...", 'F', doActionCB, "filter_selection_dialog",
1144 SHORT);
1145 XtVaSetValues(window->filterItem, XmNuserData, PERMANENT_MENU_ITEM,
1146 XmNsensitive, window->wasSelected, NULL);
1147 window->cancelShellItem = createMenuItem(menuPane, "cancelShellCommand",
1148 "Cancel Shell Command", 'C', cancelShellCB, window, SHORT);
1149 XtVaSetValues(window->cancelShellItem, XmNuserData, PERMANENT_MENU_ITEM,
1150 XmNsensitive, False, NULL);
1151 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1152 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1153 #endif
1156 ** Create the Macro menu
1158 menuPane = window->macroMenuPane =
1159 createMenu(menuBar, "macroMenu", "Macro", 0, &cascade, FULL);
1160 window->learnItem = createMenuItem(menuPane, "learnKeystrokes",
1161 "Learn Keystrokes", 'L', learnCB, window, SHORT);
1162 XtVaSetValues(window->learnItem , XmNuserData, PERMANENT_MENU_ITEM, NULL);
1163 window->finishLearnItem = createMenuItem(menuPane, "finishLearn",
1164 "Finish Learn", 'F', finishLearnCB, window, SHORT);
1165 XtVaSetValues(window->finishLearnItem , XmNuserData, PERMANENT_MENU_ITEM,
1166 XmNsensitive, False, NULL);
1167 window->cancelMacroItem = createMenuItem(menuPane, "cancelLearn",
1168 "Cancel Learn", 'C', cancelLearnCB, window, SHORT);
1169 XtVaSetValues(window->cancelMacroItem, XmNuserData, PERMANENT_MENU_ITEM,
1170 XmNsensitive, False, NULL);
1171 window->replayItem = createMenuItem(menuPane, "replayKeystrokes",
1172 "Replay Keystrokes", 'K', replayCB, window, SHORT);
1173 XtVaSetValues(window->replayItem, XmNuserData, PERMANENT_MENU_ITEM,
1174 XmNsensitive, GetReplayMacro() != NULL, NULL);
1175 window->repeatItem = createMenuItem(menuPane, "repeat",
1176 "Repeat...", 'R', doActionCB, "repeat_dialog", SHORT);
1177 XtVaSetValues(window->repeatItem, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1178 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1179 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1182 ** Create the Windows menu
1184 menuPane = window->windowMenuPane = createMenu(menuBar, "windowsMenu",
1185 "Windows", 0, &cascade, FULL);
1186 XtAddCallback(cascade, XmNcascadingCallback, (XtCallbackProc)windowMenuCB,
1187 window);
1188 window->splitPaneItem = createMenuItem(menuPane, "splitPane",
1189 "Split Pane", 'S', doActionCB, "split_pane", SHORT);
1190 XtVaSetValues(window->splitPaneItem, XmNuserData, PERMANENT_MENU_ITEM,
1191 NULL);
1192 window->closePaneItem = createMenuItem(menuPane, "closePane",
1193 "Close Pane", 'C', doActionCB, "close_pane", SHORT);
1194 XtVaSetValues(window->closePaneItem, XmNuserData, PERMANENT_MENU_ITEM,NULL);
1195 XtSetSensitive(window->closePaneItem, False);
1197 btn = createMenuSeparator(menuPane, "sep01", SHORT);
1198 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1199 window->detachDocumentItem = createMenuItem(menuPane, "detachBuffer",
1200 "Detach Tab", 'D', doActionCB, "detach_document", SHORT);
1201 XtSetSensitive(window->detachDocumentItem, False);
1203 window->moveDocumentItem = createMenuItem(menuPane, "moveDocument",
1204 "Move Tab To...", 'M', doActionCB, "move_document_dialog", SHORT);
1205 XtSetSensitive(window->moveDocumentItem, False);
1206 btn = createMenuSeparator(menuPane, "sep1", SHORT);
1207 XtVaSetValues(btn, XmNuserData, PERMANENT_MENU_ITEM, NULL);
1210 ** Create "Help" pull down menu.
1212 menuPane = createMenu(menuBar, "helpMenu", "Help", 0, &cascade, SHORT);
1213 XtVaSetValues(menuBar, XmNmenuHelpWidget, cascade, NULL);
1214 buildHelpMenu( menuPane, &H_M[0], window );
1216 return menuBar;
1219 /*----------------------------------------------------------------------------*/
1221 static Widget makeHelpMenuItem(
1223 Widget parent,
1224 char *name, /* to be assigned to the child widget */
1225 char *label, /* text to be displayed in menu */
1226 char mnemonic, /* letter in label to be underlined */
1227 menuCallbackProc callback, /* activated when menu item selected */
1228 void *cbArg, /* passed to activated call back */
1229 int mode, /* SGI_CUSTOM menu option */
1230 enum HelpTopic topic /* associated with this menu item */
1233 Widget menuItem =
1234 createMenuItem( parent, name, label, mnemonic, callback, cbArg, mode );
1236 XtVaSetValues( menuItem, XmNuserData, topic, 0 );
1237 return menuItem;
1240 /*----------------------------------------------------------------------------*/
1242 static void helpCB( Widget menuItem, XtPointer clientData, XtPointer callData )
1244 enum HelpTopic topic;
1246 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(menuItem))->lastFocus,
1247 ((XmAnyCallbackStruct *)callData)->event);
1248 XtVaGetValues( menuItem, XmNuserData, &topic, 0 );
1250 Help(topic);
1253 /*----------------------------------------------------------------------------*/
1255 #define NON_MENU_HELP 9
1257 static HelpMenu * buildHelpMenu(
1259 Widget pane, /* Menu pane on which to place new menu items */
1260 HelpMenu * menu, /* Data to drive building the help menu */
1261 WindowInfo * window /* Main NEdit window information */
1264 #ifdef VMS
1265 int hideIt = 1; /* All menu items matching this will be inaccessible */
1266 #else
1267 int hideIt = -1; /* This value should make all menu items accessible */
1268 #endif
1270 if( menu != NULL )
1272 int crntLevel = menu->level;
1274 /*-------------------------
1275 * For each menu element ...
1276 *-------------------------*/
1277 while( menu != NULL && menu->level == crntLevel )
1279 /*----------------------------------------------
1280 * ... see if dealing with a separator or submenu
1281 *----------------------------------------------*/
1282 if( menu->topic == HELP_none )
1284 if( menu->mnemonic == '-' )
1286 createMenuSeparator(pane, menu->wgtName, SHORT);
1287 menu = menu->next;
1289 else
1291 /*-------------------------------------------------------
1292 * Do not show any of the submenu when it is to be hidden.
1293 *-------------------------------------------------------*/
1294 if( menu->hideIt == hideIt || menu->hideIt == NON_MENU_HELP )
1296 do { menu = menu->next;
1297 } while( menu != NULL && menu->level > crntLevel );
1300 else
1302 Widget subPane =
1303 createMenu( pane, menu->wgtName, menu->subTitle,
1304 menu->mnemonic, NULL, FULL);
1306 menu = buildHelpMenu( subPane, menu->next, window );
1311 else
1313 /*---------------------------------------
1314 * Show menu item if not going to hide it.
1315 * This is the easy way out of hiding
1316 * menu items. When entire submenus want
1317 * to be hidden, either the entire branch
1318 * will have to be marked, or this algorithm
1319 * will have to become a lot smarter.
1320 *---------------------------------------*/
1321 if( menu->hideIt != hideIt && menu->hideIt != NON_MENU_HELP )
1322 makeHelpMenuItem(
1323 pane, menu->wgtName, HelpTitles[menu->topic],
1324 menu->mnemonic, helpCB, window, SHORT, menu->topic );
1326 menu = menu->next;
1331 return menu;
1334 /*----------------------------------------------------------------------------*/
1337 ** handle actions called from the context menus of tabs.
1339 static void doTabActionCB(Widget w, XtPointer clientData, XtPointer callData)
1341 Widget menu = MENU_WIDGET(w);
1342 WindowInfo *win, *window = WidgetToWindow(menu);
1344 /* extract the window to be acted upon, see comment in
1345 tabMenuPostAP() for detail */
1346 XtVaGetValues(window->tabMenuPane, XmNuserData, &win, NULL);
1348 HidePointerOnKeyedEvent(win->lastFocus,
1349 ((XmAnyCallbackStruct *)callData)->event);
1350 XtCallActionProc(win->lastFocus, (char *)clientData,
1351 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1354 static void doActionCB(Widget w, XtPointer clientData, XtPointer callData)
1356 Widget menu = MENU_WIDGET(w);
1358 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1359 ((XmAnyCallbackStruct *)callData)->event);
1360 XtCallActionProc(WidgetToWindow(menu)->lastFocus, (char *)clientData,
1361 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1364 static void pasteColCB(Widget w, XtPointer clientData, XtPointer callData)
1366 static char *params[1] = {"rect"};
1368 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1369 ((XmAnyCallbackStruct *)callData)->event);
1370 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "paste_clipboard",
1371 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1374 static void shiftLeftCB(Widget w, XtPointer clientData, XtPointer callData)
1376 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1377 ((XmAnyCallbackStruct *)callData)->event);
1378 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1379 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1380 ? "shift_left_by_tab" : "shift_left",
1381 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1384 static void shiftRightCB(Widget w, XtPointer clientData, XtPointer callData)
1386 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1387 ((XmAnyCallbackStruct *)callData)->event);
1388 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1389 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1390 ? "shift_right_by_tab" : "shift_right",
1391 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1394 static void findCB(Widget w, XtPointer clientData, XtPointer callData)
1396 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1397 ((XmAnyCallbackStruct *)callData)->event);
1398 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_dialog",
1399 ((XmAnyCallbackStruct *)callData)->event,
1400 shiftKeyToDir(callData), 1);
1403 static void findSameCB(Widget w, XtPointer clientData, XtPointer callData)
1405 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1406 ((XmAnyCallbackStruct *)callData)->event);
1407 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_again",
1408 ((XmAnyCallbackStruct *)callData)->event,
1409 shiftKeyToDir(callData), 1);
1412 static void findSelCB(Widget w, XtPointer clientData, XtPointer callData)
1414 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1415 ((XmAnyCallbackStruct *)callData)->event);
1416 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "find_selection",
1417 ((XmAnyCallbackStruct *)callData)->event,
1418 shiftKeyToDir(callData), 1);
1421 static void findIncrCB(Widget w, XtPointer clientData, XtPointer callData)
1423 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1424 ((XmAnyCallbackStruct *)callData)->event);
1425 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1426 "start_incremental_find", ((XmAnyCallbackStruct *)callData)->event,
1427 shiftKeyToDir(callData), 1);
1430 static void replaceCB(Widget w, XtPointer clientData, XtPointer callData)
1432 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1433 ((XmAnyCallbackStruct *)callData)->event);
1434 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_dialog",
1435 ((XmAnyCallbackStruct *)callData)->event,
1436 shiftKeyToDir(callData), 1);
1439 static void replaceSameCB(Widget w, XtPointer clientData, XtPointer callData)
1441 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1442 ((XmAnyCallbackStruct *)callData)->event);
1443 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_again",
1444 ((XmAnyCallbackStruct *)callData)->event,
1445 shiftKeyToDir(callData), 1);
1448 static void replaceFindSameCB(Widget w, XtPointer clientData, XtPointer callData)
1450 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1451 ((XmAnyCallbackStruct *)callData)->event);
1452 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "replace_find_same",
1453 ((XmAnyCallbackStruct *)callData)->event,
1454 shiftKeyToDir(callData), 1);
1457 static void markCB(Widget w, XtPointer clientData, XtPointer callData)
1459 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1460 WindowInfo *window = WidgetToWindow(MENU_WIDGET(w));
1462 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1463 ((XmAnyCallbackStruct *)callData)->event);
1464 if (event->type == KeyPress || event->type == KeyRelease)
1465 BeginMarkCommand(window);
1466 else
1467 XtCallActionProc(window->lastFocus, "mark_dialog", event, NULL, 0);
1470 static void gotoMarkCB(Widget w, XtPointer clientData, XtPointer callData)
1472 XEvent *event = ((XmAnyCallbackStruct *)callData)->event;
1473 WindowInfo *window = WidgetToWindow(MENU_WIDGET(w));
1474 int extend = event->xbutton.state & ShiftMask;
1475 static char *params[1] = {"extend"};
1477 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1478 ((XmAnyCallbackStruct *)callData)->event);
1479 if (event->type == KeyPress || event->type == KeyRelease)
1480 BeginGotoMarkCommand(window, extend);
1481 else
1482 XtCallActionProc(window->lastFocus, "goto_mark_dialog", event, params,
1483 extend ? 1 : 0);
1486 static void gotoMatchingCB(Widget w, XtPointer clientData, XtPointer callData)
1488 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1489 ((XmAnyCallbackStruct *)callData)->event);
1490 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1491 ((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask
1492 ? "select_to_matching" : "goto_matching",
1493 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1496 static void autoIndentOffCB(Widget w, WindowInfo *window, caddr_t callData)
1498 static char *params[1] = {"off"};
1499 Widget menu = MENU_WIDGET(w);
1501 window = WidgetToWindow(menu);
1503 #ifdef SGI_CUSTOM
1504 if (shortPrefAskDefault(window->shell, w, "Auto Indent Off")) {
1505 autoIndentOffDefCB(w, window, callData);
1506 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1508 #endif
1509 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1510 ((XmAnyCallbackStruct *)callData)->event);
1511 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1512 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1515 static void autoIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1517 static char *params[1] = {"on"};
1518 Widget menu = MENU_WIDGET(w);
1520 window = WidgetToWindow(menu);
1522 #ifdef SGI_CUSTOM
1523 if (shortPrefAskDefault(window->shell, w, "Auto Indent")) {
1524 autoIndentDefCB(w, window, callData);
1525 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1527 #endif
1528 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1529 ((XmAnyCallbackStruct *)callData)->event);
1530 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1531 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1534 static void smartIndentCB(Widget w, WindowInfo *window, caddr_t callData)
1536 static char *params[1] = {"smart"};
1537 Widget menu = MENU_WIDGET(w);
1539 window = WidgetToWindow(menu);
1541 #ifdef SGI_CUSTOM
1542 if (shortPrefAskDefault(window->shell, w, "Smart Indent")) {
1543 smartIndentDefCB(w, window, callData);
1544 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1546 #endif
1547 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1548 ((XmAnyCallbackStruct *)callData)->event);
1549 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_auto_indent",
1550 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1553 static void autoSaveCB(Widget w, WindowInfo *window, caddr_t callData)
1555 Widget menu = MENU_WIDGET(w);
1557 window = WidgetToWindow(menu);
1559 #ifdef SGI_CUSTOM
1560 if (shortPrefAskDefault(window->shell, w, "Incremental Backup")) {
1561 autoSaveDefCB(w, window, callData);
1562 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1564 #endif
1565 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1566 ((XmAnyCallbackStruct *)callData)->event);
1567 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_incremental_backup",
1568 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1571 static void preserveCB(Widget w, WindowInfo *window, caddr_t callData)
1573 Widget menu = MENU_WIDGET(w);
1575 window = WidgetToWindow(menu);
1577 #ifdef SGI_CUSTOM
1578 if (shortPrefAskDefault(window->shell, w, "Make Backup Copy")) {
1579 preserveDefCB(w, window, callData);
1580 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1582 #endif
1583 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1584 ((XmAnyCallbackStruct *)callData)->event);
1585 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_make_backup_copy",
1586 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1589 static void showMatchingOffCB(Widget w, WindowInfo *window, caddr_t callData)
1591 static char *params[1] = {NO_FLASH_STRING};
1592 Widget menu = MENU_WIDGET(w);
1594 window = WidgetToWindow(menu);
1596 #ifdef SGI_CUSTOM
1597 if (shortPrefAskDefault(window->shell, w, "Show Matching Off")) {
1598 showMatchingOffDefCB(w, window, callData);
1599 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1601 #endif
1602 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1603 ((XmAnyCallbackStruct *)callData)->event);
1604 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1605 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1608 static void showMatchingDelimitCB(Widget w, WindowInfo *window, caddr_t callData)
1610 static char *params[1] = {FLASH_DELIMIT_STRING};
1611 Widget menu = MENU_WIDGET(w);
1613 window = WidgetToWindow(menu);
1615 #ifdef SGI_CUSTOM
1616 if (shortPrefAskDefault(window->shell, w, "Show Matching Delimiter")) {
1617 showMatchingDelimitDefCB(w, window, callData);
1618 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1620 #endif
1621 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1622 ((XmAnyCallbackStruct *)callData)->event);
1623 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1624 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1627 static void showMatchingRangeCB(Widget w, WindowInfo *window, caddr_t callData)
1629 static char *params[1] = {FLASH_RANGE_STRING};
1630 Widget menu = MENU_WIDGET(w);
1632 window = WidgetToWindow(menu);
1634 #ifdef SGI_CUSTOM
1635 if (shortPrefAskDefault(window->shell, w, "Show Matching Range")) {
1636 showMatchingRangeDefCB(w, window, callData);
1637 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1639 #endif
1640 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1641 ((XmAnyCallbackStruct *)callData)->event);
1642 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_show_matching",
1643 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1646 static void matchSyntaxBasedCB(Widget w, WindowInfo *window, caddr_t callData)
1648 Widget menu = MENU_WIDGET(w);
1650 window = WidgetToWindow(menu);
1652 #ifdef SGI_CUSTOM
1653 if (shortPrefAskDefault(window->shell, w, "Match Syntax Based")) {
1654 matchSyntaxBasedDefCB(w, window, callData);
1655 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1657 #endif
1658 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1659 ((XmAnyCallbackStruct *)callData)->event);
1660 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_match_syntax_based",
1661 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1664 static void fontCB(Widget w, WindowInfo *window, caddr_t callData)
1666 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), True);
1669 static void noWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1671 static char *params[1] = {"none"};
1672 Widget menu = MENU_WIDGET(w);
1674 window = WidgetToWindow(menu);
1676 #ifdef SGI_CUSTOM
1677 if (shortPrefAskDefault(window->shell, w, "No Wrap")) {
1678 noWrapDefCB(w, window, callData);
1679 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1681 #endif
1682 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1683 ((XmAnyCallbackStruct *)callData)->event);
1684 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1685 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1688 static void newlineWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1690 static char *params[1] = {"auto"};
1691 Widget menu = MENU_WIDGET(w);
1693 window = WidgetToWindow(menu);
1695 #ifdef SGI_CUSTOM
1696 if (shortPrefAskDefault(window->shell, w, "Auto Newline Wrap")) {
1697 newlineWrapDefCB(w, window, callData);
1698 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1700 #endif
1701 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1702 ((XmAnyCallbackStruct *)callData)->event);
1703 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1704 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1707 static void continuousWrapCB(Widget w, WindowInfo *window, caddr_t callData)
1709 static char *params[1] = {"continuous"};
1710 Widget menu = MENU_WIDGET(w);
1712 window = WidgetToWindow(menu);
1714 #ifdef SGI_CUSTOM
1715 if (shortPrefAskDefault(window->shell, w, "Continuous Wrap")) {
1716 contWrapDefCB(w, window, callData);
1717 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1719 #endif
1720 HidePointerOnKeyedEvent(WidgetToWindow(menu)->lastFocus,
1721 ((XmAnyCallbackStruct *)callData)->event);
1722 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_wrap_text",
1723 ((XmAnyCallbackStruct *)callData)->event, params, 1);
1726 static void wrapMarginCB(Widget w, WindowInfo *window, caddr_t callData)
1728 window = WidgetToWindow(MENU_WIDGET(w));
1730 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1731 ((XmAnyCallbackStruct *)callData)->event);
1732 WrapMarginDialog(window->shell, window);
1735 static void backlightCharsCB(Widget w, WindowInfo *window, caddr_t callData)
1737 int applyBacklight = XmToggleButtonGetState(w);
1738 window = WidgetToWindow(MENU_WIDGET(w));
1739 SetBacklightChars(window, applyBacklight?GetPrefBacklightCharTypes():NULL);
1742 static void tabsCB(Widget w, WindowInfo *window, caddr_t callData)
1744 window = WidgetToWindow(MENU_WIDGET(w));
1746 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1747 ((XmAnyCallbackStruct *)callData)->event);
1748 TabsPrefDialog(window->shell, window);
1751 static void statsCB(Widget w, WindowInfo *window, caddr_t callData)
1753 Widget menu = MENU_WIDGET(w);
1755 window = WidgetToWindow(menu);
1757 #ifdef SGI_CUSTOM
1758 if (shortPrefAskDefault(window->shell, w, "Statistics Line")) {
1759 statsLineDefCB(w, window, callData);
1760 SaveNEditPrefs(window->shell, GetPrefShortMenus());
1762 #endif
1763 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1764 ((XmAnyCallbackStruct *)callData)->event);
1765 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "set_statistics_line",
1766 ((XmAnyCallbackStruct *)callData)->event, NULL, 0);
1769 static void autoIndentOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1771 WindowInfo *win;
1773 /* Set the preference and make the other windows' menus agree */
1774 SetPrefAutoIndent(NO_AUTO_INDENT);
1775 for (win=WindowList; win!=NULL; win=win->next) {
1776 if (!IsTopDocument(win))
1777 continue;
1778 XmToggleButtonSetState(win->autoIndentOffDefItem, True, False);
1779 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1780 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1784 static void autoIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1786 WindowInfo *win;
1788 /* Set the preference and make the other windows' menus agree */
1789 SetPrefAutoIndent(AUTO_INDENT);
1790 for (win=WindowList; win!=NULL; win=win->next) {
1791 if (!IsTopDocument(win))
1792 continue;
1793 XmToggleButtonSetState(win->autoIndentDefItem, True, False);
1794 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1795 XmToggleButtonSetState(win->smartIndentDefItem, False, False);
1799 static void smartIndentDefCB(Widget w, WindowInfo *window, caddr_t callData)
1801 WindowInfo *win;
1803 /* Set the preference and make the other windows' menus agree */
1804 SetPrefAutoIndent(SMART_INDENT);
1805 for (win=WindowList; win!=NULL; win=win->next) {
1806 if (!IsTopDocument(win))
1807 continue;
1808 XmToggleButtonSetState(win->smartIndentDefItem, True, False);
1809 XmToggleButtonSetState(win->autoIndentOffDefItem, False, False);
1810 XmToggleButtonSetState(win->autoIndentDefItem, False, False);
1814 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1816 WindowInfo *win;
1817 int state = XmToggleButtonGetState(w);
1819 /* Set the preference and make the other windows' menus agree */
1820 SetPrefAutoSave(state);
1821 for (win=WindowList; win!=NULL; win=win->next) {
1822 if (IsTopDocument(win))
1823 XmToggleButtonSetState(win->autoSaveDefItem, state, False);
1827 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData)
1829 WindowInfo *win;
1830 int state = XmToggleButtonGetState(w);
1832 /* Set the preference and make the other windows' menus agree */
1833 SetPrefSaveOldVersion(state);
1834 for (win=WindowList; win!=NULL; win=win->next) {
1835 if (IsTopDocument(win))
1836 XmToggleButtonSetState(win->saveLastDefItem, state, False);
1840 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData)
1842 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1843 ((XmAnyCallbackStruct *)callData)->event);
1844 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), False);
1847 static void colorDefCB(Widget w, WindowInfo *window, caddr_t callData)
1849 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1850 ((XmAnyCallbackStruct *)callData)->event);
1851 ChooseColors(WidgetToWindow(MENU_WIDGET(w)));
1854 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1856 WindowInfo *win;
1858 /* Set the preference and make the other windows' menus agree */
1859 SetPrefWrap(NO_WRAP);
1860 for (win=WindowList; win!=NULL; win=win->next) {
1861 if (!IsTopDocument(win))
1862 continue;
1863 XmToggleButtonSetState(win->noWrapDefItem, True, False);
1864 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1865 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1869 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1871 WindowInfo *win;
1873 /* Set the preference and make the other windows' menus agree */
1874 SetPrefWrap(NEWLINE_WRAP);
1875 for (win=WindowList; win!=NULL; win=win->next) {
1876 if (!IsTopDocument(win))
1877 continue;
1878 XmToggleButtonSetState(win->newlineWrapDefItem, True, False);
1879 XmToggleButtonSetState(win->contWrapDefItem, False, False);
1880 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1884 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
1886 WindowInfo *win;
1888 /* Set the preference and make the other windows' menus agree */
1889 SetPrefWrap(CONTINUOUS_WRAP);
1890 for (win=WindowList; win!=NULL; win=win->next) {
1891 if (!IsTopDocument(win))
1892 continue;
1893 XmToggleButtonSetState(win->contWrapDefItem, True, False);
1894 XmToggleButtonSetState(win->newlineWrapDefItem, False, False);
1895 XmToggleButtonSetState(win->noWrapDefItem, False, False);
1899 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData)
1901 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1902 ((XmAnyCallbackStruct *)callData)->event);
1903 WrapMarginDialog(WidgetToWindow(MENU_WIDGET(w))->shell, NULL);
1906 static void smartTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1908 WindowInfo *win;
1910 SetPrefSmartTags(True);
1911 for (win=WindowList; win!=NULL; win=win->next) {
1912 if (!IsTopDocument(win))
1913 continue;
1914 XmToggleButtonSetState(win->smartTagsDefItem, True, False);
1915 XmToggleButtonSetState(win->allTagsDefItem, False, False);
1919 static void showAllTagsDefCB(Widget w, XtPointer client_data, XtPointer callData)
1921 WindowInfo *win;
1923 SetPrefSmartTags(False);
1924 for (win=WindowList; win!=NULL; win=win->next) {
1925 if (!IsTopDocument(win))
1926 continue;
1927 XmToggleButtonSetState(win->smartTagsDefItem, False, False);
1928 XmToggleButtonSetState(win->allTagsDefItem, True, False);
1932 static void tabsDefCB(Widget w, WindowInfo *window, caddr_t callData)
1934 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
1935 ((XmAnyCallbackStruct *)callData)->event);
1936 TabsPrefDialog(WidgetToWindow(MENU_WIDGET(w))->shell, NULL);
1939 static void showMatchingOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
1941 WindowInfo *win;
1943 /* Set the preference and make the other windows' menus agree */
1944 SetPrefShowMatching(NO_FLASH);
1945 for (win=WindowList; win!=NULL; win=win->next) {
1946 if (!IsTopDocument(win))
1947 continue;
1948 XmToggleButtonSetState(win->showMatchingOffDefItem, True, False);
1949 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1950 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1954 static void showMatchingDelimitDefCB(Widget w, WindowInfo *window, caddr_t callData)
1956 WindowInfo *win;
1958 /* Set the preference and make the other windows' menus agree */
1959 SetPrefShowMatching(FLASH_DELIMIT);
1960 for (win=WindowList; win!=NULL; win=win->next) {
1961 if (!IsTopDocument(win))
1962 continue;
1963 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1964 XmToggleButtonSetState(win->showMatchingDelimitDefItem, True, False);
1965 XmToggleButtonSetState(win->showMatchingRangeDefItem, False, False);
1969 static void showMatchingRangeDefCB(Widget w, WindowInfo *window, caddr_t callData)
1971 WindowInfo *win;
1973 /* Set the preference and make the other windows' menus agree */
1974 SetPrefShowMatching(FLASH_RANGE);
1975 for (win=WindowList; win!=NULL; win=win->next) {
1976 if (!IsTopDocument(win))
1977 continue;
1978 XmToggleButtonSetState(win->showMatchingOffDefItem, False, False);
1979 XmToggleButtonSetState(win->showMatchingDelimitDefItem, False, False);
1980 XmToggleButtonSetState(win->showMatchingRangeDefItem, True, False);
1984 static void matchSyntaxBasedDefCB(Widget w, WindowInfo *window, caddr_t callData)
1986 WindowInfo *win;
1988 int state = XmToggleButtonGetState(w);
1990 /* Set the preference and make the other windows' menus agree */
1991 SetPrefMatchSyntaxBased(state);
1992 for (win=WindowList; win!=NULL; win=win->next) {
1993 if (IsTopDocument(win))
1994 XmToggleButtonSetState(win->matchSyntaxBasedDefItem, state, False);
1998 static void backlightCharsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2000 WindowInfo *win;
2001 int state = XmToggleButtonGetState(w);
2003 /* Set the preference and make the other windows' menus agree */
2004 SetPrefBacklightChars(state);
2005 for (win=WindowList; win!=NULL; win=win->next) {
2006 if (IsTopDocument(win))
2007 XmToggleButtonSetState(win->backlightCharsDefItem, state, False);
2011 static void highlightOffDefCB(Widget w, WindowInfo *window, caddr_t callData)
2013 WindowInfo *win;
2015 /* Set the preference and make the other windows' menus agree */
2016 SetPrefHighlightSyntax(False);
2017 for (win=WindowList; win!=NULL; win=win->next) {
2018 if (!IsTopDocument(win))
2019 continue;
2020 XmToggleButtonSetState(win->highlightOffDefItem, True, False);
2021 XmToggleButtonSetState(win->highlightDefItem, False, False);
2025 static void highlightDefCB(Widget w, WindowInfo *window, caddr_t callData)
2027 WindowInfo *win;
2029 /* Set the preference and make the other windows' menus agree */
2030 SetPrefHighlightSyntax(True);
2031 for (win=WindowList; win!=NULL; win=win->next) {
2032 if (!IsTopDocument(win))
2033 continue;
2034 XmToggleButtonSetState(win->highlightOffDefItem, False, False);
2035 XmToggleButtonSetState(win->highlightDefItem, True, False);
2039 static void highlightingDefCB(Widget w, WindowInfo *window, caddr_t callData)
2041 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2042 ((XmAnyCallbackStruct *)callData)->event);
2043 EditHighlightPatterns(WidgetToWindow(MENU_WIDGET(w)));
2046 static void smartMacrosDefCB(Widget w, WindowInfo *window, caddr_t callData)
2048 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2049 ((XmAnyCallbackStruct *)callData)->event);
2050 EditSmartIndentMacros(WidgetToWindow(MENU_WIDGET(w)));
2053 static void stylesDefCB(Widget w, WindowInfo *window, caddr_t callData)
2055 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2056 ((XmAnyCallbackStruct *)callData)->event);
2057 EditHighlightStyles(NULL);
2060 static void languageDefCB(Widget w, WindowInfo *window, caddr_t callData)
2062 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2063 ((XmAnyCallbackStruct *)callData)->event);
2064 EditLanguageModes();
2067 #ifndef VMS
2068 static void shellDefCB(Widget w, WindowInfo *window, caddr_t callData)
2070 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2071 ((XmAnyCallbackStruct *)callData)->event);
2072 EditShellMenu(WidgetToWindow(MENU_WIDGET(w)));
2074 #endif /* VMS */
2076 static void macroDefCB(Widget w, WindowInfo *window, caddr_t callData)
2078 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2079 ((XmAnyCallbackStruct *)callData)->event);
2080 EditMacroMenu(WidgetToWindow(MENU_WIDGET(w)));
2083 static void bgMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
2085 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2086 ((XmAnyCallbackStruct *)callData)->event);
2087 EditBGMenu(WidgetToWindow(MENU_WIDGET(w)));
2090 static void customizeTitleDefCB(Widget w, WindowInfo *window, caddr_t callData)
2092 window = WidgetToWindow(MENU_WIDGET(w));
2094 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2095 ((XmAnyCallbackStruct *)callData)->event);
2096 EditCustomTitleFormat(window);
2099 static void searchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2101 WindowInfo *win;
2102 int state = XmToggleButtonGetState(w);
2104 /* Set the preference and make the other windows' menus agree */
2105 SetPrefSearchDlogs(state);
2106 for (win=WindowList; win!=NULL; win=win->next) {
2107 if (IsTopDocument(win))
2108 XmToggleButtonSetState(win->searchDlogsDefItem, state, False);
2112 static void beepOnSearchWrapDefCB(Widget w, WindowInfo *window, caddr_t callData)
2114 WindowInfo *win;
2115 int state = XmToggleButtonGetState(w);
2117 /* Set the preference and make the other windows' menus agree */
2118 SetPrefBeepOnSearchWrap(state);
2119 for (win=WindowList; win!=NULL; win=win->next) {
2120 if (IsTopDocument(win))
2121 XmToggleButtonSetState(win->beepOnSearchWrapDefItem, state, False);
2125 static void keepSearchDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2127 WindowInfo *win;
2128 int state = XmToggleButtonGetState(w);
2130 /* Set the preference and make the other windows' menus agree */
2131 SetPrefKeepSearchDlogs(state);
2132 for (win=WindowList; win!=NULL; win=win->next) {
2133 if (IsTopDocument(win))
2134 XmToggleButtonSetState(win->keepSearchDlogsDefItem, state, False);
2138 static void searchWrapsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2140 WindowInfo *win;
2141 int state = XmToggleButtonGetState(w);
2143 /* Set the preference and make the other windows' menus agree */
2144 SetPrefSearchWraps(state);
2145 for (win=WindowList; win!=NULL; win=win->next) {
2146 if (IsTopDocument(win))
2147 XmToggleButtonSetState(win->searchWrapsDefItem, state, False);
2151 static void appendLFCB(Widget w, WindowInfo* window, caddr_t callData)
2153 WindowInfo *win;
2154 int state = XmToggleButtonGetState(w);
2156 SetPrefAppendLF(state);
2157 for (win = WindowList; win != NULL; win = win->next) {
2158 if (IsTopDocument(win))
2159 XmToggleButtonSetState(win->appendLFItem, state, False);
2163 static void sortOpenPrevDefCB(Widget w, WindowInfo *window, caddr_t callData)
2165 WindowInfo *win;
2166 int state = XmToggleButtonGetState(w);
2168 /* Set the preference, make the other windows' menus agree,
2169 and invalidate their Open Previous menus */
2170 SetPrefSortOpenPrevMenu(state);
2171 for (win=WindowList; win!=NULL; win=win->next) {
2172 win->prevOpenMenuValid = False;
2173 if (IsTopDocument(win))
2174 XmToggleButtonSetState(win->sortOpenPrevDefItem, state, False);
2178 static void reposDlogsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2180 WindowInfo *win;
2181 int state = XmToggleButtonGetState(w);
2183 /* Set the preference and make the other windows' menus agree */
2184 SetPrefRepositionDialogs(state);
2185 SetPointerCenteredDialogs(state);
2186 for (win=WindowList; win!=NULL; win=win->next) {
2187 if (IsTopDocument(win))
2188 XmToggleButtonSetState(win->reposDlogsDefItem, state, False);
2192 static void autoScrollDefCB(Widget w, WindowInfo *window, caddr_t callData)
2194 WindowInfo *win;
2195 int state = XmToggleButtonGetState(w);
2197 /* Set the preference and make the other windows' menus agree */
2198 SetPrefAutoScroll(state);
2199 /* XXX: Should we ensure auto-scroll now if needed? */
2200 for (win=WindowList; win!=NULL; win=win->next) {
2201 if (IsTopDocument(win))
2202 XmToggleButtonSetState(win->autoScrollDefItem, state, False);
2206 static void modWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
2208 WindowInfo *win;
2209 int state = XmToggleButtonGetState(w);
2211 /* Set the preference and make the other windows' menus agree */
2212 SetPrefWarnFileMods(state);
2213 for (win=WindowList; win!=NULL; win=win->next) {
2214 if (!IsTopDocument(win))
2215 continue;
2216 XmToggleButtonSetState(win->modWarnDefItem, state, False);
2217 XtSetSensitive(win->modWarnRealDefItem, state);
2221 static void modWarnRealDefCB(Widget w, WindowInfo *window, caddr_t callData)
2223 WindowInfo *win;
2224 int state = XmToggleButtonGetState(w);
2226 /* Set the preference and make the other windows' menus agree */
2227 SetPrefWarnRealFileMods(state);
2228 for (win=WindowList; win!=NULL; win=win->next) {
2229 if (IsTopDocument(win))
2230 XmToggleButtonSetState(win->modWarnRealDefItem, state, False);
2234 static void exitWarnDefCB(Widget w, WindowInfo *window, caddr_t callData)
2236 WindowInfo *win;
2237 int state = XmToggleButtonGetState(w);
2239 /* Set the preference and make the other windows' menus agree */
2240 SetPrefWarnExit(state);
2241 for (win=WindowList; win!=NULL; win=win->next) {
2242 if (IsTopDocument(win))
2243 XmToggleButtonSetState(win->exitWarnDefItem, state, False);
2247 static void openInTabDefCB(Widget w, WindowInfo *window, caddr_t callData)
2249 WindowInfo *win;
2250 int state = XmToggleButtonGetState(w);
2252 /* Set the preference and make the other windows' menus agree */
2253 SetPrefOpenInTab(state);
2254 for (win=WindowList; win!=NULL; win=win->next)
2255 XmToggleButtonSetState(win->openInTabDefItem, state, False);
2258 static void tabBarDefCB(Widget w, WindowInfo *window, caddr_t callData)
2260 WindowInfo *win;
2261 int state = XmToggleButtonGetState(w);
2263 /* Set the preference and make the other windows' menus agree */
2264 SetPrefTabBar(state);
2265 for (win=WindowList; win!=NULL; win=win->next) {
2266 if (!IsTopDocument(win))
2267 continue;
2268 XmToggleButtonSetState(win->tabBarDefItem, state, False);
2269 ShowWindowTabBar(win);
2273 static void tabBarHideDefCB(Widget w, WindowInfo *window, caddr_t callData)
2275 WindowInfo *win;
2276 int state = XmToggleButtonGetState(w);
2278 /* Set the preference and make the other windows' menus agree */
2279 SetPrefTabBarHideOne(state);
2280 for (win=WindowList; win!=NULL; win=win->next) {
2281 if (!IsTopDocument(win))
2282 continue;
2283 XmToggleButtonSetState(win->tabBarHideDefItem, state, False);
2284 ShowWindowTabBar(win);
2288 static void toolTipsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2290 WindowInfo *win;
2291 int state = XmToggleButtonGetState(w);
2293 /* Set the preference and make the other windows' menus agree */
2294 SetPrefToolTips(state);
2295 for (win=WindowList; win!=NULL; win=win->next) {
2296 XtVaSetValues(win->tab, XltNshowBubble, GetPrefToolTips(), NULL);
2297 if (IsTopDocument(win))
2298 XmToggleButtonSetState(win->toolTipsDefItem, state, False);
2302 static void tabNavigateDefCB(Widget w, WindowInfo *window, caddr_t callData)
2304 WindowInfo *win;
2305 int state = XmToggleButtonGetState(w);
2307 /* Set the preference and make the other windows' menus agree */
2308 SetPrefGlobalTabNavigate(state);
2309 for (win=WindowList; win!=NULL; win=win->next) {
2310 if (IsTopDocument(win))
2311 XmToggleButtonSetState(win->tabNavigateDefItem, state, False);
2315 static void tabSortDefCB(Widget w, WindowInfo *window, caddr_t callData)
2317 WindowInfo *win;
2318 int state = XmToggleButtonGetState(w);
2320 /* Set the preference and make the other windows' menus agree */
2321 SetPrefSortTabs(state);
2322 for (win=WindowList; win!=NULL; win=win->next) {
2323 if (IsTopDocument(win))
2324 XmToggleButtonSetState(win->tabSortDefItem, state, False);
2327 /* If we just enabled sorting, sort all tabs. Note that this reorders
2328 the next pointers underneath us, which is scary, but SortTabBar never
2329 touches windows that are earlier in the WindowList so it's ok. */
2330 if (state) {
2331 Widget shell=(Widget)0;
2332 for (win=WindowList; win!=NULL; win=win->next) {
2333 if ( win->shell != shell ) {
2334 SortTabBar(win);
2335 shell = win->shell;
2341 static void statsLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
2343 WindowInfo *win;
2344 int state = XmToggleButtonGetState(w);
2346 /* Set the preference and make the other windows' menus agree */
2347 SetPrefStatsLine(state);
2348 for (win=WindowList; win!=NULL; win=win->next) {
2349 if (IsTopDocument(win))
2350 XmToggleButtonSetState(win->statsLineDefItem, state, False);
2354 static void iSearchLineDefCB(Widget w, WindowInfo *window, caddr_t callData)
2356 WindowInfo *win;
2357 int state = XmToggleButtonGetState(w);
2359 /* Set the preference and make the other windows' menus agree */
2360 SetPrefISearchLine(state);
2361 for (win=WindowList; win!=NULL; win=win->next) {
2362 if (IsTopDocument(win))
2363 XmToggleButtonSetState(win->iSearchLineDefItem, state, False);
2367 static void lineNumsDefCB(Widget w, WindowInfo *window, caddr_t callData)
2369 WindowInfo *win;
2370 int state = XmToggleButtonGetState(w);
2372 /* Set the preference and make the other windows' menus agree */
2373 SetPrefLineNums(state);
2374 for (win=WindowList; win!=NULL; win=win->next) {
2375 if (IsTopDocument(win))
2376 XmToggleButtonSetState(win->lineNumsDefItem, state, False);
2380 static void pathInWindowsMenuDefCB(Widget w, WindowInfo *window, caddr_t callData)
2382 WindowInfo *win;
2383 int state = XmToggleButtonGetState(w);
2385 /* Set the preference and make the other windows' menus agree */
2386 SetPrefShowPathInWindowsMenu(state);
2387 for (win=WindowList; win!=NULL; win=win->next) {
2388 if (IsTopDocument(win))
2389 XmToggleButtonSetState(win->pathInWindowsMenuDefItem, state, False);
2391 InvalidateWindowMenus();
2394 static void searchLiteralCB(Widget w, WindowInfo *window, caddr_t callData)
2396 WindowInfo *win;
2398 /* Set the preference and make the other windows' menus agree */
2399 if (XmToggleButtonGetState(w)) {
2400 SetPrefSearch(SEARCH_LITERAL);
2401 for (win=WindowList; win!=NULL; win=win->next){
2402 if (!IsTopDocument(win))
2403 continue;
2404 XmToggleButtonSetState(win->searchLiteralDefItem, True, False);
2405 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2406 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2407 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2408 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2409 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2414 static void searchCaseSenseCB(Widget w, WindowInfo *window, caddr_t callData)
2416 WindowInfo *win;
2418 /* Set the preference and make the other windows' menus agree */
2419 if (XmToggleButtonGetState(w)) {
2420 SetPrefSearch(SEARCH_CASE_SENSE);
2421 for (win=WindowList; win!=NULL; win=win->next) {
2422 if (!IsTopDocument(win))
2423 continue;
2424 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2425 XmToggleButtonSetState(win->searchCaseSenseDefItem, True, False);
2426 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2427 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2428 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2429 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2434 static void searchLiteralWordCB(Widget w, WindowInfo *window, caddr_t callData)
2436 WindowInfo *win;
2438 /* Set the preference and make the other windows' menus agree */
2439 if (XmToggleButtonGetState(w)) {
2440 SetPrefSearch(SEARCH_LITERAL_WORD);
2441 for (win=WindowList; win!=NULL; win=win->next){
2442 if (!IsTopDocument(win))
2443 continue;
2444 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2445 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2446 XmToggleButtonSetState(win->searchLiteralWordDefItem, True, False);
2447 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2448 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2449 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2454 static void searchCaseSenseWordCB(Widget w, WindowInfo *window, caddr_t callData)
2456 WindowInfo *win;
2458 /* Set the preference and make the other windows' menus agree */
2459 if (XmToggleButtonGetState(w)) {
2460 SetPrefSearch(SEARCH_CASE_SENSE_WORD);
2461 for (win=WindowList; win!=NULL; win=win->next) {
2462 if (!IsTopDocument(win))
2463 continue;
2464 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2465 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2466 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2467 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, True, False);
2468 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2469 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2474 static void searchRegexCB(Widget w, WindowInfo *window, caddr_t callData)
2476 WindowInfo *win;
2478 /* Set the preference and make the other windows' menus agree */
2479 if (XmToggleButtonGetState(w)) {
2480 SetPrefSearch(SEARCH_REGEX);
2481 for (win=WindowList; win!=NULL; win=win->next){
2482 if (!IsTopDocument(win))
2483 continue;
2484 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2485 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2486 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2487 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2488 XmToggleButtonSetState(win->searchRegexDefItem, True, False);
2489 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, False, False);
2494 static void searchRegexNoCaseCB(Widget w, WindowInfo *window, caddr_t callData)
2496 WindowInfo *win;
2498 /* Set the preference and make the other windows' menus agree */
2499 if (XmToggleButtonGetState(w)) {
2500 SetPrefSearch(SEARCH_REGEX_NOCASE);
2501 for (win=WindowList; win!=NULL; win=win->next){
2502 if (!IsTopDocument(win))
2503 continue;
2504 XmToggleButtonSetState(win->searchLiteralDefItem, False, False);
2505 XmToggleButtonSetState(win->searchCaseSenseDefItem, False, False);
2506 XmToggleButtonSetState(win->searchLiteralWordDefItem, False, False);
2507 XmToggleButtonSetState(win->searchCaseSenseWordDefItem, False, False);
2508 XmToggleButtonSetState(win->searchRegexDefItem, False, False);
2509 XmToggleButtonSetState(win->searchRegexNoCaseDefItem, True, False);
2514 #ifdef REPLACE_SCOPE
2515 static void replaceScopeWindowCB(Widget w, WindowInfo *window, caddr_t callData)
2517 WindowInfo *win;
2519 /* Set the preference and make the other windows' menus agree */
2520 if (XmToggleButtonGetState(w)) {
2521 SetPrefReplaceDefScope(REPL_DEF_SCOPE_WINDOW);
2522 for (win=WindowList; win!=NULL; win=win->next){
2523 if (!IsTopDocument(win))
2524 continue;
2525 XmToggleButtonSetState(win->replScopeWinDefItem, True, False);
2526 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2527 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2532 static void replaceScopeSelectionCB(Widget w, WindowInfo *window, caddr_t callData)
2534 WindowInfo *win;
2536 /* Set the preference and make the other windows' menus agree */
2537 if (XmToggleButtonGetState(w)) {
2538 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SELECTION);
2539 for (win=WindowList; win!=NULL; win=win->next){
2540 if (!IsTopDocument(win))
2541 continue;
2542 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2543 XmToggleButtonSetState(win->replScopeSelDefItem, True, False);
2544 XmToggleButtonSetState(win->replScopeSmartDefItem, False, False);
2549 static void replaceScopeSmartCB(Widget w, WindowInfo *window, caddr_t callData)
2551 WindowInfo *win;
2553 /* Set the preference and make the other windows' menus agree */
2554 if (XmToggleButtonGetState(w)) {
2555 SetPrefReplaceDefScope(REPL_DEF_SCOPE_SMART);
2556 for (win=WindowList; win!=NULL; win=win->next){
2557 if (!IsTopDocument(win))
2558 continue;
2559 XmToggleButtonSetState(win->replScopeWinDefItem, False, False);
2560 XmToggleButtonSetState(win->replScopeSelDefItem, False, False);
2561 XmToggleButtonSetState(win->replScopeSmartDefItem, True, False);
2565 #endif
2567 static void size24x80CB(Widget w, WindowInfo *window, caddr_t callData)
2569 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2570 ((XmAnyCallbackStruct *)callData)->event);
2571 setWindowSizeDefault(24, 80);
2574 static void size40x80CB(Widget w, WindowInfo *window, caddr_t callData)
2576 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2577 ((XmAnyCallbackStruct *)callData)->event);
2578 setWindowSizeDefault(40, 80);
2581 static void size60x80CB(Widget w, WindowInfo *window, caddr_t callData)
2583 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2584 ((XmAnyCallbackStruct *)callData)->event);
2585 setWindowSizeDefault(60, 80);
2588 static void size80x80CB(Widget w, WindowInfo *window, caddr_t callData)
2590 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2591 ((XmAnyCallbackStruct *)callData)->event);
2592 setWindowSizeDefault(80, 80);
2595 static void sizeCustomCB(Widget w, WindowInfo *window, caddr_t callData)
2597 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2598 ((XmAnyCallbackStruct *)callData)->event);
2599 RowColumnPrefDialog(WidgetToWindow(MENU_WIDGET(w))->shell);
2600 updateWindowSizeMenus();
2603 static void savePrefCB(Widget w, WindowInfo *window, caddr_t callData)
2605 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2606 ((XmAnyCallbackStruct *)callData)->event);
2607 SaveNEditPrefs(WidgetToWindow(MENU_WIDGET(w))->shell, False);
2610 static void formFeedCB(Widget w, XtPointer clientData, XtPointer callData)
2612 static char *params[1] = {"\f"};
2614 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2615 ((XmAnyCallbackStruct *)callData)->event);
2616 XtCallActionProc(WidgetToWindow(MENU_WIDGET(w))->lastFocus, "insert_string",
2617 ((XmAnyCallbackStruct *)callData)->event, params, 1);
2620 static void cancelShellCB(Widget w, WindowInfo *window, XtPointer callData)
2622 #ifndef VMS
2623 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2624 ((XmAnyCallbackStruct *)callData)->event);
2625 AbortShellCommand(WidgetToWindow(MENU_WIDGET(w)));
2626 #endif
2629 static void learnCB(Widget w, WindowInfo *window, caddr_t callData)
2631 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2632 ((XmAnyCallbackStruct *)callData)->event);
2633 BeginLearn(WidgetToWindow(MENU_WIDGET(w)));
2636 static void finishLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2638 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2639 ((XmAnyCallbackStruct *)callData)->event);
2640 FinishLearn();
2643 static void cancelLearnCB(Widget w, WindowInfo *window, caddr_t callData)
2645 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2646 ((XmAnyCallbackStruct *)callData)->event);
2647 CancelMacroOrLearn(WidgetToWindow(MENU_WIDGET(w)));
2650 static void replayCB(Widget w, WindowInfo *window, caddr_t callData)
2652 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
2653 ((XmAnyCallbackStruct *)callData)->event);
2654 Replay(WidgetToWindow(MENU_WIDGET(w)));
2657 static void windowMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2659 window = WidgetToWindow(MENU_WIDGET(w));
2661 if (!window->windowMenuValid) {
2662 updateWindowMenu(window);
2663 window->windowMenuValid = True;
2667 static void prevOpenMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2669 window = WidgetToWindow(MENU_WIDGET(w));
2671 if (!window->prevOpenMenuValid) {
2672 updatePrevOpenMenu(window);
2673 window->prevOpenMenuValid = True;
2677 static void unloadTagsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2679 updateTagsFileMenu(WidgetToWindow(MENU_WIDGET(w)));
2682 static void unloadTipsFileMenuCB(Widget w, WindowInfo *window, caddr_t callData)
2684 updateTipsFileMenu(window);
2688 ** open a new tab or window, per preference.
2690 static void newAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2692 WindowInfo *window = WidgetToWindow(w);
2694 EditNewFile(GetPrefOpenInTab()? window : NULL, NULL, False, NULL,
2695 window->path);
2696 CheckCloseDim();
2700 ** open a new window.
2702 static void newWindowAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2704 WindowInfo *window = WidgetToWindow(w);
2706 EditNewFile(NULL, NULL, False, NULL, window->path);
2707 CheckCloseDim();
2711 ** open a new tabbed document
2713 static void newTabAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2715 WindowInfo *window = WidgetToWindow(w);
2717 EditNewFile(window, NULL, False, NULL, window->path);
2718 CheckCloseDim();
2721 static void openDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2723 WindowInfo *window = WidgetToWindow(w);
2724 char fullname[MAXPATHLEN], *params[2];
2725 int response;
2726 int n=1;
2728 response = PromptForExistingFile(window, "Open File", fullname);
2729 if (response != GFN_OK)
2730 return;
2731 params[0] = fullname;
2733 if (*nArgs>0 && !strcmp(args[0], "1"))
2734 params[n++] = "1";
2736 XtCallActionProc(window->lastFocus, "open", event, params, n);
2737 CheckCloseDim();
2740 static void openAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2742 WindowInfo *window = WidgetToWindow(w);
2743 char filename[MAXPATHLEN], pathname[MAXPATHLEN];
2745 if (*nArgs == 0) {
2746 fprintf(stderr, "nedit: open action requires file argument\n");
2747 return;
2749 if (ParseFilename(args[0], filename, pathname) != 0) {
2750 fprintf(stderr, "nedit: invalid file name for open action: %s\n",
2751 args[0]);
2752 return;
2754 EditExistingFile(window, filename, pathname, 0, NULL, False,
2755 NULL, GetPrefOpenInTab(), False);
2756 CheckCloseDim();
2759 static void openSelectedAP(Widget w, XEvent *event, String *args,
2760 Cardinal *nArgs)
2762 OpenSelectedFile(WidgetToWindow(w), event->xbutton.time);
2763 CheckCloseDim();
2766 static void closeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2768 int preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2770 if (*nArgs > 0) {
2771 if (strcmp(args[0], "prompt") == 0) {
2772 preResponse = PROMPT_SBC_DIALOG_RESPONSE;
2774 else if (strcmp(args[0], "save") == 0) {
2775 preResponse = YES_SBC_DIALOG_RESPONSE;
2777 else if (strcmp(args[0], "nosave") == 0) {
2778 preResponse = NO_SBC_DIALOG_RESPONSE;
2781 CloseFileAndWindow(WidgetToWindow(w), preResponse);
2782 CheckCloseDim();
2785 static void saveAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2787 WindowInfo *window = WidgetToWindow(w);
2789 if (CheckReadOnly(window))
2790 return;
2791 SaveWindow(window);
2794 static void saveAsDialogAP(Widget w, XEvent *event, String *args,
2795 Cardinal *nArgs)
2797 WindowInfo *window = WidgetToWindow(w);
2798 int response, addWrap, fileFormat;
2799 char fullname[MAXPATHLEN], *params[2];
2801 response = PromptForNewFile(window, "Save File As", fullname,
2802 &fileFormat, &addWrap);
2803 if (response != GFN_OK)
2804 return;
2805 window->fileFormat = fileFormat;
2806 params[0] = fullname;
2807 params[1] = "wrapped";
2808 XtCallActionProc(window->lastFocus, "save_as", event, params, addWrap?2:1);
2811 static void saveAsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2813 if (*nArgs == 0) {
2814 fprintf(stderr, "nedit: save_as action requires file argument\n");
2815 return;
2817 SaveWindowAs(WidgetToWindow(w), args[0],
2818 *nArgs == 2 && !strCaseCmp(args[1], "wrapped"));
2821 static void revertDialogAP(Widget w, XEvent *event, String *args,
2822 Cardinal *nArgs)
2824 WindowInfo *window = WidgetToWindow(w);
2825 int b;
2827 /* re-reading file is irreversible, prompt the user first */
2828 if (window->fileChanged)
2830 b = DialogF(DF_QUES, window->shell, 2, "Discard Changes",
2831 "Discard changes to\n%s%s?", "OK", "Cancel", window->path,
2832 window->filename);
2833 } else
2835 b = DialogF(DF_QUES, window->shell, 2, "Reload File",
2836 "Re-load file\n%s%s?", "Re-read", "Cancel", window->path,
2837 window->filename);
2840 if (b != 1)
2842 return;
2844 XtCallActionProc(window->lastFocus, "revert_to_saved", event, NULL, 0);
2848 static void revertAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2850 RevertToSaved(WidgetToWindow(w));
2853 static void includeDialogAP(Widget w, XEvent *event, String *args,
2854 Cardinal *nArgs)
2856 WindowInfo *window = WidgetToWindow(w);
2857 char filename[MAXPATHLEN], *params[1];
2858 int response;
2860 if (CheckReadOnly(window))
2861 return;
2862 response = PromptForExistingFile(window, "Include File", filename);
2863 if (response != GFN_OK)
2864 return;
2865 params[0] = filename;
2866 XtCallActionProc(window->lastFocus, "include_file", event, params, 1);
2869 static void includeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2871 WindowInfo *window = WidgetToWindow(w);
2873 if (CheckReadOnly(window))
2874 return;
2875 if (*nArgs == 0) {
2876 fprintf(stderr, "nedit: include action requires file argument\n");
2877 return;
2879 IncludeFile(WidgetToWindow(w), args[0]);
2882 static void loadMacroDialogAP(Widget w, XEvent *event, String *args,
2883 Cardinal *nArgs)
2885 WindowInfo *window = WidgetToWindow(w);
2886 char filename[MAXPATHLEN], *params[1];
2887 int response;
2889 response = PromptForExistingFile(window, "Load Macro File", filename);
2890 if (response != GFN_OK)
2891 return;
2892 params[0] = filename;
2893 XtCallActionProc(window->lastFocus, "load_macro_file", event, params, 1);
2896 static void loadMacroAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2898 if (*nArgs == 0) {
2899 fprintf(stderr,"nedit: load_macro_file action requires file argument\n");
2900 return;
2902 ReadMacroFile(WidgetToWindow(w), args[0], True);
2905 static void loadTagsDialogAP(Widget w, XEvent *event, String *args,
2906 Cardinal *nArgs)
2908 WindowInfo *window = WidgetToWindow(w);
2909 char filename[MAXPATHLEN], *params[1];
2910 int response;
2912 response = PromptForExistingFile(window, "Load Tags File", filename);
2913 if (response != GFN_OK)
2914 return;
2915 params[0] = filename;
2916 XtCallActionProc(window->lastFocus, "load_tags_file", event, params, 1);
2919 static void loadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2921 if (*nArgs == 0) {
2922 fprintf(stderr,"nedit: load_tags_file action requires file argument\n");
2923 return;
2926 if (!AddTagsFile(args[0], TAG))
2928 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1, "Error Reading File",
2929 "Error reading ctags file:\n'%s'\ntags not loaded", "Dismiss",
2930 args[0]);
2934 static void unloadTagsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2936 if (*nArgs == 0) {
2937 fprintf(stderr,
2938 "nedit: unload_tags_file action requires file argument\n");
2939 return;
2941 DeleteTagsFile(args[0], TAG);
2944 static void loadTipsDialogAP(Widget w, XEvent *event, String *args,
2945 Cardinal *nArgs)
2947 WindowInfo *window = WidgetToWindow(w);
2948 char filename[MAXPATHLEN], *params[1];
2949 int response;
2951 response = PromptForExistingFile(window, "Load Calltips File", filename);
2952 if (response != GFN_OK)
2953 return;
2954 params[0] = filename;
2955 XtCallActionProc(window->lastFocus, "load_tips_file", event, params, 1);
2958 static void loadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2960 if (*nArgs == 0) {
2961 fprintf(stderr,"nedit: load_tips_file action requires file argument\n");
2962 return;
2965 if (!AddTagsFile(args[0], TIP))
2967 DialogF(DF_WARN, WidgetToWindow(w)->shell, 1, "Error Reading File",
2968 "Error reading tips file:\n'%s'\ntips not loaded", "Dismiss",
2969 args[0]);
2973 static void unloadTipsAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2975 if (*nArgs == 0) {
2976 fprintf(stderr,
2977 "nedit: unload_tips_file action requires file argument\n");
2978 return;
2980 DeleteTagsFile(args[0], TIP);
2983 static void printAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2985 PrintWindow(WidgetToWindow(w), False);
2988 static void printSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2990 PrintWindow(WidgetToWindow(w), True);
2993 static void exitAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
2995 WindowInfo *window = WidgetToWindow(w);
2997 if (!CheckPrefsChangesSaved(window->shell))
2998 return;
3000 /* If this is not the last window (more than one window is open),
3001 confirm with the user before exiting. */
3002 if (GetPrefWarnExit() && !(window == WindowList && window->next == NULL)) {
3003 int resp, titleLen, lineLen;
3004 char exitMsg[DF_MAX_MSG_LENGTH], *ptr, *title;
3005 char filename[MAXPATHLEN];
3006 WindowInfo *win;
3008 /* List the windows being edited and make sure the
3009 user really wants to exit */
3010 ptr = exitMsg;
3011 lineLen = 0;
3012 strcpy(ptr, "Editing: "); ptr += 9; lineLen += 9;
3013 for (win=WindowList; win!=NULL; win=win->next) {
3014 sprintf(filename, "%s%s", win->filename, win->fileChanged? "*": "");
3015 title = filename;
3016 titleLen = strlen(title);
3017 if (ptr - exitMsg + titleLen + 30 >= DF_MAX_MSG_LENGTH) {
3018 strcpy(ptr, "..."); ptr += 3;
3019 break;
3021 if (lineLen + titleLen + (win->next==NULL?5:2) > 50) {
3022 *ptr++ = '\n';
3023 lineLen = 0;
3025 if (win->next == NULL) {
3026 sprintf(ptr, "and %s.", title);
3027 ptr += 5 + titleLen;
3028 lineLen += 5 + titleLen;
3029 } else {
3030 sprintf(ptr, "%s, ", title);
3031 ptr += 2 + titleLen;
3032 lineLen += 2 + titleLen;
3035 sprintf(ptr, "\n\nExit NEdit?");
3036 resp = DialogF(DF_QUES, window->shell, 2, "Exit", "%s", "Exit",
3037 "Cancel", exitMsg);
3038 if (resp == 2)
3039 return;
3042 /* Close all files and exit when the last one is closed */
3043 if (CloseAllFilesAndWindows())
3044 exit(EXIT_SUCCESS);
3047 static void undoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3049 WindowInfo *window = WidgetToWindow(w);
3051 if (CheckReadOnly(window))
3052 return;
3053 Undo(window);
3056 static void redoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3058 WindowInfo *window = WidgetToWindow(w);
3060 if (CheckReadOnly(window))
3061 return;
3062 Redo(window);
3065 static void clearAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3067 WindowInfo *window = WidgetToWindow(w);
3069 if (CheckReadOnly(window))
3070 return;
3071 BufRemoveSelected(window->buffer);
3074 static void selAllAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3076 WindowInfo *window = WidgetToWindow(w);
3078 BufSelect(window->buffer, 0, window->buffer->length);
3081 static void shiftLeftAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3083 WindowInfo *window = WidgetToWindow(w);
3085 if (CheckReadOnly(window))
3086 return;
3087 ShiftSelection(window, SHIFT_LEFT, False);
3090 static void shiftLeftTabAP(Widget w, XEvent *event, String *args,
3091 Cardinal *nArgs)
3093 WindowInfo *window = WidgetToWindow(w);
3095 if (CheckReadOnly(window))
3096 return;
3097 ShiftSelection(window, SHIFT_LEFT, True);
3100 static void shiftRightAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3102 WindowInfo *window = WidgetToWindow(w);
3104 if (CheckReadOnly(window))
3105 return;
3106 ShiftSelection(window, SHIFT_RIGHT, False);
3109 static void shiftRightTabAP(Widget w, XEvent *event, String *args,
3110 Cardinal *nArgs)
3112 WindowInfo *window = WidgetToWindow(w);
3114 if (CheckReadOnly(window))
3115 return;
3116 ShiftSelection(window, SHIFT_RIGHT, True);
3119 static void findDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3121 DoFindDlog(WidgetToWindow(w), searchDirection(0, args, nArgs),
3122 searchKeepDialogs(0, args, nArgs), searchType(0, args, nArgs),
3123 event->xbutton.time);
3126 static void findAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3128 if (*nArgs == 0) {
3129 fprintf(stderr, "nedit: find action requires search string argument\n");
3130 return;
3132 SearchAndSelect(WidgetToWindow(w), searchDirection(1, args, nArgs), args[0],
3133 searchType(1, args, nArgs), searchWrap(1, args, nArgs));
3136 static void findSameAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3138 SearchAndSelectSame(WidgetToWindow(w), searchDirection(0, args, nArgs),
3139 searchWrap(0, args, nArgs));
3142 static void findSelAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3144 SearchForSelected(WidgetToWindow(w), searchDirection(0, args, nArgs),
3145 searchType(0, args, nArgs), searchWrap(0, args, nArgs),
3146 event->xbutton.time);
3149 static void startIncrFindAP(Widget w, XEvent *event, String *args,
3150 Cardinal *nArgs)
3152 BeginISearch(WidgetToWindow(w), searchDirection(0, args, nArgs));
3155 static void findIncrAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3157 int i, continued = FALSE;
3158 if (*nArgs == 0) {
3159 fprintf(stderr, "nedit: find action requires search string argument\n");
3160 return;
3162 for (i=1; i<(int)*nArgs; i++)
3163 if (!strCaseCmp(args[i], "continued"))
3164 continued = TRUE;
3165 SearchAndSelectIncremental(WidgetToWindow(w),
3166 searchDirection(1, args, nArgs), args[0],
3167 searchType(1, args, nArgs), searchWrap(1, args, nArgs), continued);
3170 static void replaceDialogAP(Widget w, XEvent *event, String *args,
3171 Cardinal *nArgs)
3173 WindowInfo *window = WidgetToWindow(w);
3175 if (CheckReadOnly(window))
3176 return;
3177 DoFindReplaceDlog(window, searchDirection(0, args, nArgs),
3178 searchKeepDialogs(0, args, nArgs), searchType(0, args, nArgs),
3179 event->xbutton.time);
3182 static void replaceAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3184 WindowInfo *window = WidgetToWindow(w);
3186 if (CheckReadOnly(window))
3187 return;
3188 if (*nArgs < 2) {
3189 fprintf(stderr,
3190 "nedit: replace action requires search and replace string arguments\n");
3191 return;
3193 SearchAndReplace(window, searchDirection(2, args, nArgs),
3194 args[0], args[1], searchType(2, args, nArgs), searchWrap(2, args, nArgs));
3197 static void replaceAllAP(Widget w, XEvent *event, String *args,
3198 Cardinal *nArgs)
3200 WindowInfo *window = WidgetToWindow(w);
3202 if (CheckReadOnly(window))
3203 return;
3204 if (*nArgs < 2) {
3205 fprintf(stderr,
3206 "nedit: replace_all action requires search and replace string arguments\n");
3207 return;
3209 ReplaceAll(window, args[0], args[1], searchType(2, args, nArgs));
3212 static void replaceInSelAP(Widget w, XEvent *event, String *args,
3213 Cardinal *nArgs)
3215 WindowInfo *window = WidgetToWindow(w);
3217 if (CheckReadOnly(window))
3218 return;
3219 if (*nArgs < 2) {
3220 fprintf(stderr,
3221 "nedit: replace_in_selection requires search and replace string arguments\n");
3222 return;
3224 ReplaceInSelection(window, args[0], args[1],
3225 searchType(2, args, nArgs));
3228 static void replaceSameAP(Widget w, XEvent *event, String *args,
3229 Cardinal *nArgs)
3231 WindowInfo *window = WidgetToWindow(w);
3233 if (CheckReadOnly(window))
3234 return;
3235 ReplaceSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
3238 static void replaceFindAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3240 WindowInfo *window = WidgetToWindow(w);
3242 if (CheckReadOnly(window))
3244 return;
3247 if (*nArgs < 2)
3249 DialogF(DF_WARN, window->shell, 1, "Error in replace_find",
3250 "replace_find action requires search and replace string arguments",
3251 "OK");
3252 return;
3255 ReplaceAndSearch(window, searchDirection(2, args, nArgs), args[0], args[1],
3256 searchType(2, args, nArgs), searchWrap(0, args, nArgs));
3259 static void replaceFindSameAP(Widget w, XEvent *event, String *args,
3260 Cardinal *nArgs)
3262 WindowInfo *window = WidgetToWindow(w);
3264 if (CheckReadOnly(window))
3265 return;
3266 ReplaceFindSame(window, searchDirection(0, args, nArgs), searchWrap(0, args, nArgs));
3269 static void gotoAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3271 int lineNum, column, position, curCol;
3273 /* Accept various formats:
3274 [line]:[column] (menu action)
3275 line (macro call)
3276 line, column (macro call) */
3277 if ( *nArgs == 0 ||
3278 *nArgs > 2 ||
3279 (*nArgs == 1 &&
3280 StringToLineAndCol( args[0], &lineNum, &column ) == -1) ||
3281 (*nArgs == 2 &&
3282 (!StringToNum(args[0], &lineNum) ||
3283 !StringToNum(args[1], &column)) ) ) {
3284 fprintf(stderr,"nedit: goto_line_number action requires line and/or column number\n");
3285 return;
3287 /* User specified column, but not line number */
3288 if ( lineNum == -1 ) {
3289 position = TextGetCursorPos(w);
3290 if (TextPosToLineAndCol(w, position, &lineNum,
3291 &curCol) == False) {
3292 return;
3295 /* User didn't specify a column */
3296 else if ( column == -1 ) {
3297 SelectNumberedLine(WidgetToWindow(w), lineNum);
3298 return;
3301 position = TextLineAndColToPos(w, lineNum, column );
3302 if ( position == -1 ) {
3303 return;
3305 TextSetCursorPos(w, position);
3306 return;
3309 static void gotoDialogAP(Widget w, XEvent *event, String *args,
3310 Cardinal *nArgs)
3312 GotoLineNumber(WidgetToWindow(w));
3315 static void gotoSelectedAP(Widget w, XEvent *event, String *args,
3316 Cardinal *nArgs)
3318 GotoSelectedLineNumber(WidgetToWindow(w), event->xbutton.time);
3321 static void repeatDialogAP(Widget w, XEvent *event, String *args,
3322 Cardinal *nArgs)
3324 RepeatDialog(WidgetToWindow(w));
3327 static void repeatMacroAP(Widget w, XEvent *event, String *args,
3328 Cardinal *nArgs)
3330 int how;
3332 if (*nArgs != 2) {
3333 fprintf(stderr, "nedit: repeat_macro requires two arguments\n");
3334 return;
3336 if (!strcmp(args[0], "in_selection"))
3337 how = REPEAT_IN_SEL;
3338 else if (!strcmp(args[0], "to_end"))
3339 how = REPEAT_TO_END;
3340 else if (sscanf(args[0], "%d", &how) != 1) {
3341 fprintf(stderr, "nedit: repeat_macro requires method/count\n");
3342 return;
3344 RepeatMacro(WidgetToWindow(w), args[1], how);
3347 static void markAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3349 if (*nArgs == 0 || strlen(args[0]) != 1 ||
3350 !isalnum((unsigned char)args[0][0])) {
3351 fprintf(stderr,"nedit: mark action requires a single-letter label\n");
3352 return;
3354 AddMark(WidgetToWindow(w), w, args[0][0]);
3357 static void markDialogAP(Widget w, XEvent *event, String *args,
3358 Cardinal *nArgs)
3360 MarkDialog(WidgetToWindow(w));
3363 static void gotoMarkAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3365 if (*nArgs == 0 || strlen(args[0]) != 1 ||
3366 !isalnum((unsigned char)args[0][0])) {
3367 fprintf(stderr,
3368 "nedit: goto_mark action requires a single-letter label\n");
3369 return;
3371 GotoMark(WidgetToWindow(w), w, args[0][0], *nArgs > 1 &&
3372 !strcmp(args[1], "extend"));
3375 static void gotoMarkDialogAP(Widget w, XEvent *event, String *args,
3376 Cardinal *nArgs)
3378 GotoMarkDialog(WidgetToWindow(w), *nArgs!=0 && !strcmp(args[0], "extend"));
3381 static void selectToMatchingAP(Widget w, XEvent *event, String *args,
3382 Cardinal *nArgs)
3384 SelectToMatchingCharacter(WidgetToWindow(w));
3387 static void gotoMatchingAP(Widget w, XEvent *event, String *args,
3388 Cardinal *nArgs)
3390 GotoMatchingCharacter(WidgetToWindow(w));
3393 static void findDefAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3395 FindDefinition(WidgetToWindow(w), event->xbutton.time,
3396 *nArgs == 0 ? NULL : args[0]);
3399 static void showTipAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3401 FindDefCalltip(WidgetToWindow(w), event->xbutton.time,
3402 *nArgs == 0 ? NULL : args[0]);
3405 static void splitPaneAP(Widget w, XEvent *event, String *args,
3406 Cardinal *nArgs)
3408 WindowInfo *window = WidgetToWindow(w);
3410 SplitPane(window);
3411 if (IsTopDocument(window)) {
3412 XtSetSensitive(window->splitPaneItem, window->nPanes < MAX_PANES);
3413 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
3417 static void closePaneAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3419 WindowInfo *window = WidgetToWindow(w);
3421 ClosePane(window);
3422 if (IsTopDocument(window)) {
3423 XtSetSensitive(window->splitPaneItem, window->nPanes < MAX_PANES);
3424 XtSetSensitive(window->closePaneItem, window->nPanes > 0);
3428 static void detachDocumentDialogAP(Widget w, XEvent *event, String *args,
3429 Cardinal *nArgs)
3431 WindowInfo *window = WidgetToWindow(w);
3432 int resp;
3434 if (NDocuments(window) < 2)
3435 return;
3437 resp = DialogF(DF_QUES, window->shell, 2, "Detach %s?",
3438 "Detach", "Cancel", window->filename);
3440 if (resp == 1)
3441 DetachDocument(window);
3444 static void detachDocumentAP(Widget w, XEvent *event, String *args,
3445 Cardinal *nArgs)
3447 WindowInfo *window = WidgetToWindow(w);
3449 if (NDocuments(window) < 2)
3450 return;
3452 DetachDocument(window);
3455 static void moveDocumentDialogAP(Widget w, XEvent *event, String *args,
3456 Cardinal *nArgs)
3458 MoveDocumentDialog(WidgetToWindow(w));
3461 static void nextDocumentAP(Widget w, XEvent *event, String *args,
3462 Cardinal *nArgs)
3464 NextDocument(WidgetToWindow(w));
3467 static void prevDocumentAP(Widget w, XEvent *event, String *args,
3468 Cardinal *nArgs)
3470 PreviousDocument(WidgetToWindow(w));
3473 static void lastDocumentAP(Widget w, XEvent *event, String *args,
3474 Cardinal *nArgs)
3476 LastDocument(WidgetToWindow(w));
3479 static void capitalizeAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3481 WindowInfo *window = WidgetToWindow(w);
3483 if (CheckReadOnly(window))
3484 return;
3485 UpcaseSelection(window);
3488 static void lowercaseAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3490 WindowInfo *window = WidgetToWindow(w);
3492 if (CheckReadOnly(window))
3493 return;
3494 DowncaseSelection(window);
3497 static void fillAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3499 WindowInfo *window = WidgetToWindow(w);
3501 if (CheckReadOnly(window))
3502 return;
3503 FillSelection(window);
3506 static void controlDialogAP(Widget w, XEvent *event, String *args,
3507 Cardinal *nArgs)
3509 WindowInfo *window = WidgetToWindow(w);
3510 unsigned char charCodeString[2];
3511 char charCodeText[DF_MAX_PROMPT_LENGTH], dummy[DF_MAX_PROMPT_LENGTH];
3512 char *params[1];
3513 int charCode, nRead, response;
3515 if (CheckReadOnly(window))
3516 return;
3518 response = DialogF(DF_PROMPT, window->shell, 2, "Insert Ctrl Code",
3519 "ASCII Character Code:", charCodeText, "OK", "Cancel");
3521 if (response == 2)
3522 return;
3523 /* If we don't scan for a trailing string invalid input
3524 would be accepted sometimes. */
3525 nRead = sscanf(charCodeText, "%i%s", &charCode, dummy);
3526 if (nRead != 1 || charCode < 0 || charCode > 255) {
3527 XBell(TheDisplay, 0);
3528 return;
3530 charCodeString[0] = (unsigned char)charCode;
3531 charCodeString[1] = '\0';
3532 params[0] = (char *)charCodeString;
3534 if (!BufSubstituteNullChars((char *)charCodeString, 1, window->buffer))
3536 DialogF(DF_ERR, window->shell, 1, "Error", "Too much binary data",
3537 "Dismiss");
3538 return;
3541 XtCallActionProc(w, "insert_string", event, params, 1);
3544 #ifndef VMS
3545 static void filterDialogAP(Widget w, XEvent *event, String *args,
3546 Cardinal *nArgs)
3548 WindowInfo *window = WidgetToWindow(w);
3549 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3550 int resp;
3551 static char **cmdHistory = NULL;
3552 static int nHistoryCmds = 0;
3554 if (CheckReadOnly(window))
3555 return;
3556 if (!window->buffer->primary.selected) {
3557 XBell(TheDisplay, 0);
3558 return;
3561 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3563 resp = DialogF(DF_PROMPT, window->shell, 2, "Filter Selection",
3564 "Shell command: (use up arrow key to recall previous)",
3565 cmdText, "OK", "Cancel");
3567 if (resp == 2)
3568 return;
3569 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3570 params[0] = cmdText;
3571 XtCallActionProc(w, "filter_selection", event, params, 1);
3574 static void shellFilterAP(Widget w, XEvent *event, String *args,
3575 Cardinal *nArgs)
3577 WindowInfo *window = WidgetToWindow(w);
3579 if (CheckReadOnly(window))
3580 return;
3581 if (*nArgs == 0) {
3582 fprintf(stderr,
3583 "nedit: filter_selection requires shell command argument\n");
3584 return;
3586 FilterSelection(window, args[0],
3587 event->xany.send_event == MACRO_EVENT_MARKER);
3590 static void execDialogAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3592 WindowInfo *window = WidgetToWindow(w);
3593 char *params[1], cmdText[DF_MAX_PROMPT_LENGTH];
3594 int resp;
3595 static char **cmdHistory = NULL;
3596 static int nHistoryCmds = 0;
3598 if (CheckReadOnly(window))
3599 return;
3600 SetDialogFPromptHistory(cmdHistory, nHistoryCmds);
3602 resp = DialogF(DF_PROMPT, window->shell, 2, "Execute Command",
3603 "Shell command: (use up arrow key to recall previous;\n"
3604 "%% expands to current filename, # to line number)", cmdText, "OK",
3605 "Cancel");
3607 if (resp == 2)
3608 return;
3609 AddToHistoryList(cmdText, &cmdHistory, &nHistoryCmds);
3610 params[0] = cmdText;
3611 XtCallActionProc(w, "execute_command", event, params, 1);;
3614 static void execAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3616 WindowInfo *window = WidgetToWindow(w);
3618 if (CheckReadOnly(window))
3619 return;
3620 if (*nArgs == 0) {
3621 fprintf(stderr,
3622 "nedit: execute_command requires shell command argument\n");
3623 return;
3625 ExecShellCommand(window, args[0],
3626 event->xany.send_event == MACRO_EVENT_MARKER);
3629 static void execLineAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3631 WindowInfo *window = WidgetToWindow(w);
3633 if (CheckReadOnly(window))
3634 return;
3635 ExecCursorLine(window, event->xany.send_event == MACRO_EVENT_MARKER);
3638 static void shellMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3640 if (*nArgs == 0) {
3641 fprintf(stderr,
3642 "nedit: shell_menu_command requires item-name argument\n");
3643 return;
3645 HidePointerOnKeyedEvent(w, event);
3646 DoNamedShellMenuCmd(WidgetToWindow(w), args[0],
3647 event->xany.send_event == MACRO_EVENT_MARKER);
3649 #endif
3651 static void macroMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3653 if (*nArgs == 0) {
3654 fprintf(stderr,
3655 "nedit: macro_menu_command requires item-name argument\n");
3656 return;
3658 /* Don't allow users to execute a macro command from the menu (or accel)
3659 if there's already a macro command executing, UNLESS the macro is
3660 directly called from another one. NEdit can't handle
3661 running multiple, independent uncoordinated, macros in the same
3662 window. Macros may invoke macro menu commands recursively via the
3663 macro_menu_command action proc, which is important for being able to
3664 repeat any operation, and to embed macros within eachother at any
3665 level, however, a call here with a macro running means that THE USER
3666 is explicitly invoking another macro via the menu or an accelerator,
3667 UNLESS the macro event marker is set */
3668 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3669 if (WidgetToWindow(w)->macroCmdData != NULL) {
3670 XBell(TheDisplay, 0);
3671 return;
3674 HidePointerOnKeyedEvent(w, event);
3675 DoNamedMacroMenuCmd(WidgetToWindow(w), args[0]);
3678 static void bgMenuAP(Widget w, XEvent *event, String *args, Cardinal *nArgs)
3680 if (*nArgs == 0) {
3681 fprintf(stderr,
3682 "nedit: bg_menu_command requires item-name argument\n");
3683 return;
3685 /* Same remark as for macro menu commands (see above). */
3686 if (event->xany.send_event != MACRO_EVENT_MARKER) {
3687 if (WidgetToWindow(w)->macroCmdData != NULL) {
3688 XBell(TheDisplay, 0);
3689 return;
3692 HidePointerOnKeyedEvent(w, event);
3693 DoNamedBGMenuCmd(WidgetToWindow(w), args[0]);
3696 static void beginningOfSelectionAP(Widget w, XEvent *event, String *args,
3697 Cardinal *nArgs)
3699 textBuffer *buf = TextGetBuffer(w);
3700 int start, end, isRect, rectStart, rectEnd;
3702 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3703 return;
3704 if (!isRect)
3705 TextSetCursorPos(w, start);
3706 else
3707 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3708 BufStartOfLine(buf, start), rectStart));
3711 static void endOfSelectionAP(Widget w, XEvent *event, String *args,
3712 Cardinal *nArgs)
3714 textBuffer *buf = TextGetBuffer(w);
3715 int start, end, isRect, rectStart, rectEnd;
3717 if (!BufGetSelectionPos(buf, &start, &end, &isRect, &rectStart, &rectEnd))
3718 return;
3719 if (!isRect)
3720 TextSetCursorPos(w, end);
3721 else
3722 TextSetCursorPos(w, BufCountForwardDispChars(buf,
3723 BufStartOfLine(buf, end), rectEnd));
3726 static void raiseWindowAP(Widget w, XEvent *event, String *args,
3727 Cardinal *nArgs)
3729 WindowInfo *window = WidgetToWindow(w);
3730 WindowInfo *nextWindow;
3731 WindowInfo *tmpWindow;
3732 int windowIndex;
3734 if (*nArgs > 0) {
3735 if (strcmp(args[0], "last") == 0) {
3736 window = WindowList;
3738 else if (strcmp(args[0], "first") == 0) {
3739 window = WindowList;
3740 if (window != NULL) {
3741 nextWindow = window->next;
3742 while (nextWindow != NULL) {
3743 window = nextWindow;
3744 nextWindow = nextWindow->next;
3748 else if (strcmp(args[0], "previous") == 0) {
3749 tmpWindow = window;
3750 window = WindowList;
3751 if (window != NULL) {
3752 nextWindow = window->next;
3753 while (nextWindow != NULL && nextWindow != tmpWindow) {
3754 window = nextWindow;
3755 nextWindow = nextWindow->next;
3757 if (nextWindow == NULL && tmpWindow != WindowList) {
3758 window = NULL;
3762 else if (strcmp(args[0], "next") == 0) {
3763 if (window != NULL) {
3764 window = window->next;
3765 if (window == NULL) {
3766 window = WindowList;
3770 else {
3771 if (sscanf(args[0], "%d", &windowIndex) == 1) {
3772 if (windowIndex > 0) {
3773 for (window = WindowList; window != NULL && windowIndex > 1;
3774 --windowIndex) {
3775 window = window->next;
3778 else if (windowIndex < 0) {
3779 for (window = WindowList; window != NULL;
3780 window = window->next) {
3781 ++windowIndex;
3783 if (windowIndex >= 0) {
3784 for (window = WindowList; window != NULL &&
3785 windowIndex > 0; window = window->next) {
3786 --windowIndex;
3789 else {
3790 window = NULL;
3793 else {
3794 window = NULL;
3797 else {
3798 window = NULL;
3802 if (window != NULL) {
3803 RaiseDocumentWindow(window);
3805 else {
3806 XBell(TheDisplay, 0);
3810 static void focusPaneAP(Widget w, XEvent *event, String *args,
3811 Cardinal *nArgs)
3813 WindowInfo *window = WidgetToWindow(w);
3814 Widget newFocusPane = NULL;
3815 int paneIndex;
3817 if (*nArgs > 0) {
3818 if (strcmp(args[0], "first") == 0) {
3819 paneIndex = 0;
3821 else if (strcmp(args[0], "last") == 0) {
3822 paneIndex = window->nPanes;
3824 else if (strcmp(args[0], "next") == 0) {
3825 paneIndex = WidgetToPaneIndex(window, window->lastFocus) + 1;
3826 if (paneIndex > window->nPanes) {
3827 paneIndex = 0;
3830 else if (strcmp(args[0], "previous") == 0) {
3831 paneIndex = WidgetToPaneIndex(window, window->lastFocus) - 1;
3832 if (paneIndex < 0) {
3833 paneIndex = window->nPanes;
3836 else {
3837 if (sscanf(args[0], "%d", &paneIndex) == 1) {
3838 if (paneIndex > 0) {
3839 paneIndex = paneIndex - 1;
3841 else if (paneIndex < 0) {
3842 paneIndex = window->nPanes + (paneIndex + 1);
3844 else {
3845 paneIndex = -1;
3849 if (paneIndex >= 0 && paneIndex <= window->nPanes) {
3850 newFocusPane = GetPaneByIndex(window, paneIndex);
3852 if (newFocusPane != NULL) {
3853 window->lastFocus = newFocusPane;
3854 XmProcessTraversal(window->lastFocus, XmTRAVERSE_CURRENT);
3856 else {
3857 XBell(TheDisplay, 0);
3860 else {
3861 fprintf(stderr, "nedit: focus_pane requires argument\n");
3865 #define ACTION_BOOL_PARAM_OR_TOGGLE(newState, numArgs, argvVal, oValue, actionName) \
3866 if ((numArgs) > 0) { \
3867 int intState; \
3869 if (sscanf(argvVal[0], "%d", &intState) == 1) { \
3870 (newState) = (intState != 0); \
3872 else { \
3873 fprintf(stderr, "nedit: %s requires 0 or 1 argument\n", actionName); \
3874 return; \
3877 else { \
3878 (newState) = !(oValue); \
3881 static void setStatisticsLineAP(Widget w, XEvent *event, String *args,
3882 Cardinal *nArgs)
3884 WindowInfo *window = WidgetToWindow(w);
3885 Boolean newState;
3887 /* stats line is a shell-level item, so we toggle the button
3888 state regardless of it's 'topness' */
3889 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->showStats,
3890 "set_statistics_line");
3891 XmToggleButtonSetState(window->statsLineItem, newState, False);
3892 ShowStatsLine(window, newState);
3895 static void setIncrementalSearchLineAP(Widget w, XEvent *event, String *args,
3896 Cardinal *nArgs)
3898 WindowInfo *window = WidgetToWindow(w);
3899 Boolean newState;
3901 /* i-search line is a shell-level item, so we toggle the button
3902 state regardless of it's 'topness' */
3903 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args,
3904 window->showISearchLine, "set_incremental_search_line");
3905 XmToggleButtonSetState(window->iSearchLineItem, newState, False);
3906 ShowISearchLine(window, newState);
3909 static void setShowLineNumbersAP(Widget w, XEvent *event, String *args,
3910 Cardinal *nArgs)
3912 WindowInfo *window = WidgetToWindow(w);
3913 Boolean newState;
3915 /* line numbers panel is a shell-level item, so we toggle the button
3916 state regardless of it's 'topness' */
3917 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args,
3918 window->showLineNumbers, "set_show_line_numbers");
3919 XmToggleButtonSetState(window->lineNumsItem, newState, False);
3920 ShowLineNumbers(window, newState);
3923 static void setAutoIndentAP(Widget w, XEvent *event, String *args,
3924 Cardinal *nArgs)
3926 WindowInfo *window = WidgetToWindow(w);
3927 if (*nArgs > 0) {
3928 if (strcmp(args[0], "off") == 0) {
3929 SetAutoIndent(window, NO_AUTO_INDENT);
3931 else if (strcmp(args[0], "on") == 0) {
3932 SetAutoIndent(window, AUTO_INDENT);
3934 else if (strcmp(args[0], "smart") == 0) {
3935 SetAutoIndent(window, SMART_INDENT);
3937 else {
3938 fprintf(stderr, "nedit: set_auto_indent invalid argument\n");
3941 else {
3942 fprintf(stderr, "nedit: set_auto_indent requires argument\n");
3946 static void setWrapTextAP(Widget w, XEvent *event, String *args,
3947 Cardinal *nArgs)
3949 WindowInfo *window = WidgetToWindow(w);
3950 if (*nArgs > 0) {
3951 if (strcmp(args[0], "none") == 0) {
3952 SetAutoWrap(window, NO_WRAP);
3954 else if (strcmp(args[0], "auto") == 0) {
3955 SetAutoWrap(window, NEWLINE_WRAP);
3957 else if (strcmp(args[0], "continuous") == 0) {
3958 SetAutoWrap(window, CONTINUOUS_WRAP);
3960 else {
3961 fprintf(stderr, "nedit: set_wrap_text invalid argument\n");
3964 else {
3965 fprintf(stderr, "nedit: set_wrap_text requires argument\n");
3969 static void setWrapMarginAP(Widget w, XEvent *event, String *args,
3970 Cardinal *nArgs)
3972 WindowInfo *window = WidgetToWindow(w);
3974 if (*nArgs > 0) {
3975 int newMargin = 0;
3976 if (sscanf(args[0], "%d", &newMargin) == 1 &&
3977 newMargin >= 0 &&
3978 newMargin < 1000) {
3979 int i;
3981 XtVaSetValues(window->textArea, textNwrapMargin, newMargin, NULL);
3982 for (i = 0; i < window->nPanes; ++i) {
3983 XtVaSetValues(window->textPanes[i], textNwrapMargin, newMargin, NULL);
3986 else {
3987 fprintf(stderr,
3988 "nedit: set_wrap_margin requires integer argument >= 0 and < 1000\n");
3991 else {
3992 fprintf(stderr, "nedit: set_wrap_margin requires argument\n");
3996 static void setHighlightSyntaxAP(Widget w, XEvent *event, String *args,
3997 Cardinal *nArgs)
3999 WindowInfo *window = WidgetToWindow(w);
4000 Boolean newState;
4002 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->highlightSyntax, "set_highlight_syntax");
4004 if (IsTopDocument(window))
4005 XmToggleButtonSetState(window->highlightItem, newState, False);
4006 window->highlightSyntax = newState;
4007 if (window->highlightSyntax) {
4008 StartHighlighting(window, True);
4009 } else {
4010 StopHighlighting(window);
4014 static void setMakeBackupCopyAP(Widget w, XEvent *event, String *args,
4015 Cardinal *nArgs)
4017 WindowInfo *window = WidgetToWindow(w);
4018 Boolean newState;
4020 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->saveOldVersion, "set_make_backup_copy");
4022 if (IsTopDocument(window))
4023 XmToggleButtonSetState(window->saveLastItem, newState, False);
4024 window->saveOldVersion = newState;
4027 static void setIncrementalBackupAP(Widget w, XEvent *event, String *args,
4028 Cardinal *nArgs)
4030 WindowInfo *window = WidgetToWindow(w);
4031 Boolean newState;
4033 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->autoSave, "set_incremental_backup");
4035 if (IsTopDocument(window))
4036 XmToggleButtonSetState(window->autoSaveItem, newState, False);
4037 window->autoSave = newState;
4040 static void setShowMatchingAP(Widget w, XEvent *event, String *args,
4041 Cardinal *nArgs)
4043 WindowInfo *window = WidgetToWindow(w);
4044 if (*nArgs > 0) {
4045 if (strcmp(args[0], NO_FLASH_STRING) == 0) {
4046 SetShowMatching(window, NO_FLASH);
4048 else if (strcmp(args[0], FLASH_DELIMIT_STRING) == 0) {
4049 SetShowMatching(window, FLASH_DELIMIT);
4051 else if (strcmp(args[0], FLASH_RANGE_STRING) == 0) {
4052 SetShowMatching(window, FLASH_RANGE);
4054 /* For backward compatibility with pre-5.2 versions, we also
4055 accept 0 and 1 as aliases for NO_FLASH and FLASH_DELIMIT.
4056 It is quite unlikely, though, that anyone ever used this
4057 action procedure via the macro language or a key binding,
4058 so this can probably be left out safely. */
4059 else if (strcmp(args[0], "0") == 0) {
4060 SetShowMatching(window, NO_FLASH);
4062 else if (strcmp(args[0], "1") == 0) {
4063 SetShowMatching(window, FLASH_DELIMIT);
4065 else {
4066 fprintf(stderr, "nedit: Invalid argument for set_show_matching\n");
4069 else {
4070 fprintf(stderr, "nedit: set_show_matching requires argument\n");
4074 static void setMatchSyntaxBasedAP(Widget w, XEvent *event, String *args,
4075 Cardinal *nArgs)
4077 WindowInfo *window = WidgetToWindow(w);
4078 Boolean newState;
4080 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->matchSyntaxBased, "set_match_syntax_based");
4082 if (IsTopDocument(window))
4083 XmToggleButtonSetState(window->matchSyntaxBasedItem, newState, False);
4084 window->matchSyntaxBased = newState;
4087 static void setOvertypeModeAP(Widget w, XEvent *event, String *args,
4088 Cardinal *nArgs)
4090 WindowInfo *window = WidgetToWindow(w);
4091 Boolean newState;
4093 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->overstrike, "set_overtype_mode");
4095 if (IsTopDocument(window))
4096 XmToggleButtonSetState(window->overtypeModeItem, newState, False);
4097 SetOverstrike(window, newState);
4100 static void setLockedAP(Widget w, XEvent *event, String *args,
4101 Cardinal *nArgs)
4103 WindowInfo *window = WidgetToWindow(w);
4104 Boolean newState;
4106 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, IS_USER_LOCKED(window->lockReasons), "set_locked");
4108 SET_USER_LOCKED(window->lockReasons, newState);
4109 if (IsTopDocument(window))
4110 XmToggleButtonSetState(window->readOnlyItem, IS_ANY_LOCKED(window->lockReasons), False);
4111 UpdateWindowTitle(window);
4112 UpdateWindowReadOnly(window);
4115 static void setTabDistAP(Widget w, XEvent *event, String *args,
4116 Cardinal *nArgs)
4118 WindowInfo *window = WidgetToWindow(w);
4120 if (*nArgs > 0) {
4121 int newTabDist = 0;
4122 if (sscanf(args[0], "%d", &newTabDist) == 1 &&
4123 newTabDist > 0 &&
4124 newTabDist <= MAX_EXP_CHAR_LEN) {
4125 SetTabDist(window, newTabDist);
4127 else {
4128 fprintf(stderr,
4129 "nedit: set_tab_dist requires integer argument > 0 and <= %d\n",
4130 MAX_EXP_CHAR_LEN);
4133 else {
4134 fprintf(stderr, "nedit: set_tab_dist requires argument\n");
4138 static void setEmTabDistAP(Widget w, XEvent *event, String *args,
4139 Cardinal *nArgs)
4141 WindowInfo *window = WidgetToWindow(w);
4143 if (*nArgs > 0) {
4144 int newEmTabDist = 0;
4145 if (sscanf(args[0], "%d", &newEmTabDist) == 1 &&
4146 newEmTabDist >= -1 &&
4147 newEmTabDist < 1000) {
4148 if (newEmTabDist < 0) {
4149 newEmTabDist = 0;
4151 SetEmTabDist(window, newEmTabDist);
4153 else {
4154 fprintf(stderr,
4155 "nedit: set_em_tab_dist requires integer argument >= -1 and < 1000\n");
4158 else {
4159 fprintf(stderr, "nedit: set_em_tab_dist requires argument\n");
4163 static void setUseTabsAP(Widget w, XEvent *event, String *args,
4164 Cardinal *nArgs)
4166 WindowInfo *window = WidgetToWindow(w);
4167 Boolean newState;
4169 ACTION_BOOL_PARAM_OR_TOGGLE(newState, *nArgs, args, window->buffer->useTabs, "set_use_tabs");
4171 window->buffer->useTabs = newState;
4174 static void setFontsAP(Widget w, XEvent *event, String *args,
4175 Cardinal *nArgs)
4177 WindowInfo *window = WidgetToWindow(w);
4178 if (*nArgs >= 4) {
4179 SetFonts(window, args[0], args[1], args[2], args[3]);
4181 else {
4182 fprintf(stderr, "nedit: set_fonts requires 4 arguments\n");
4186 static void setLanguageModeAP(Widget w, XEvent *event, String *args,
4187 Cardinal *nArgs)
4189 WindowInfo *window = WidgetToWindow(w);
4191 if (*nArgs > 0) {
4192 SetLanguageMode(window, FindLanguageMode(args[0]), FALSE);
4194 else {
4195 fprintf(stderr, "nedit: set_language_mode requires argument\n");
4200 ** Same as AddSubMenu from libNUtil.a but 1) mnemonic is optional (NEdit
4201 ** users like to be able to re-arrange the mnemonics so they can set Alt
4202 ** key combinations as accelerators), 2) supports the short/full option
4203 ** of SGI_CUSTOM mode, 3) optionally returns the cascade button widget
4204 ** in "cascadeBtn" if "cascadeBtn" is non-NULL.
4206 static Widget createMenu(Widget parent, char *name, char *label,
4207 char mnemonic, Widget *cascadeBtn, int mode)
4209 Widget menu, cascade;
4210 XmString st1;
4212 menu = CreatePulldownMenu(parent, name, NULL, 0);
4213 cascade = XtVaCreateWidget(name, xmCascadeButtonWidgetClass, parent,
4214 XmNlabelString, st1=XmStringCreateSimple(label),
4215 XmNsubMenuId, menu, NULL);
4216 XmStringFree(st1);
4217 if (mnemonic != 0)
4218 XtVaSetValues(cascade, XmNmnemonic, mnemonic, NULL);
4219 #ifdef SGI_CUSTOM
4220 if (mode == SHORT || !GetPrefShortMenus())
4221 XtManageChild(cascade);
4222 if (mode == FULL)
4223 addToToggleShortList(cascade);
4224 #else
4225 XtManageChild(cascade);
4226 #endif
4227 if (cascadeBtn != NULL)
4228 *cascadeBtn = cascade;
4229 return menu;
4233 ** Same as AddMenuItem from libNUtil.a without setting the accelerator
4234 ** (these are set in the fallback app-defaults so users can change them),
4235 ** and with the short/full option required in SGI_CUSTOM mode.
4237 static Widget createMenuItem(Widget parent, char *name, char *label,
4238 char mnemonic, menuCallbackProc callback, void *cbArg, int mode)
4240 Widget button;
4241 XmString st1;
4244 button = XtVaCreateWidget(name, xmPushButtonWidgetClass, parent,
4245 XmNlabelString, st1=XmStringCreateSimple(label),
4246 XmNmnemonic, mnemonic, NULL);
4247 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
4248 XmStringFree(st1);
4249 #ifdef SGI_CUSTOM
4250 if (mode == SHORT || !GetPrefShortMenus())
4251 XtManageChild(button);
4252 if (mode == FULL)
4253 addToToggleShortList(button);
4254 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4255 #else
4256 XtManageChild(button);
4257 #endif
4258 return button;
4262 ** "fake" menu items allow accelerators to be attached, but don't show up
4263 ** in the menu. They are necessary to process the shifted menu items because
4264 ** Motif does not properly process the event descriptions in accelerator
4265 ** resources, and you can't specify "shift key is optional"
4267 static Widget createFakeMenuItem(Widget parent, char *name,
4268 menuCallbackProc callback, void *cbArg)
4270 Widget button;
4271 XmString st1;
4273 button = XtVaCreateManagedWidget(name, xmPushButtonWidgetClass, parent,
4274 XmNlabelString, st1=XmStringCreateSimple(""),
4275 XmNshadowThickness, 0,
4276 XmNmarginHeight, 0,
4277 XmNheight, 0, NULL);
4278 XtAddCallback(button, XmNactivateCallback, (XtCallbackProc)callback, cbArg);
4279 XmStringFree(st1);
4280 XtVaSetValues(button, XmNtraversalOn, False, NULL);
4282 return button;
4286 ** Add a toggle button item to an already established pull-down or pop-up
4287 ** menu, including mnemonics, accelerators and callbacks.
4289 static Widget createMenuToggle(Widget parent, char *name, char *label,
4290 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
4291 int mode)
4293 Widget button;
4294 XmString st1;
4296 button = XtVaCreateWidget(name, xmToggleButtonWidgetClass, parent,
4297 XmNlabelString, st1=XmStringCreateSimple(label),
4298 XmNmnemonic, mnemonic,
4299 XmNset, set, NULL);
4300 XtAddCallback(button, XmNvalueChangedCallback, (XtCallbackProc)callback,
4301 cbArg);
4302 XmStringFree(st1);
4303 #ifdef SGI_CUSTOM
4304 if (mode == SHORT || !GetPrefShortMenus())
4305 XtManageChild(button);
4306 if (mode == FULL)
4307 addToToggleShortList(button);
4308 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4309 #else
4310 XtManageChild(button);
4311 #endif
4312 return button;
4316 ** Create a toggle button with a diamond (radio-style) appearance
4318 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
4319 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
4320 int mode)
4322 Widget button;
4323 button = createMenuToggle(parent, name, label, mnemonic, callback, cbArg,
4324 set, mode);
4325 XtVaSetValues(button, XmNindicatorType, XmONE_OF_MANY, NULL);
4326 return button;
4329 static Widget createMenuSeparator(Widget parent, char *name, int mode)
4331 Widget button;
4333 button = XmCreateSeparator(parent, name, NULL, 0);
4334 #ifdef SGI_CUSTOM
4335 if (mode == SHORT || !GetPrefShortMenus())
4336 XtManageChild(button);
4337 if (mode == FULL)
4338 addToToggleShortList(button);
4339 XtVaSetValues(button, XmNuserData, PERMANENT_MENU_ITEM, NULL);
4340 #else
4341 XtManageChild(button);
4342 #endif
4343 return button;
4347 ** Make sure the close menu item is dimmed appropriately for the current
4348 ** set of windows. It should be dim only for the last Untitled, unmodified,
4349 ** editor window, and sensitive otherwise.
4351 void CheckCloseDim(void)
4353 WindowInfo *window;
4355 if (WindowList == NULL)
4356 return;
4357 if (WindowList->next==NULL &&
4358 !WindowList->filenameSet && !WindowList->fileChanged) {
4359 XtSetSensitive(WindowList->closeItem, FALSE);
4360 return;
4363 for (window=WindowList; window!=NULL; window=window->next) {
4364 if (!IsTopDocument(window))
4365 continue;
4366 XtSetSensitive(window->closeItem, True);
4371 ** Invalidate the Window menus of all NEdit windows to but don't change
4372 ** the menus until they're needed (Originally, this was "UpdateWindowMenus",
4373 ** but creating and destroying manu items for every window every time a
4374 ** new window was created or something changed, made things move very
4375 ** slowly with more than 10 or so windows).
4377 void InvalidateWindowMenus(void)
4379 WindowInfo *w;
4381 /* Mark the window menus invalid (to be updated when the user pulls one
4382 down), unless the menu is torn off, meaning it is visible to the user
4383 and should be updated immediately */
4384 for (w=WindowList; w!=NULL; w=w->next) {
4385 if (!XmIsMenuShell(XtParent(w->windowMenuPane)))
4386 updateWindowMenu(w);
4387 else
4388 w->windowMenuValid = False;
4393 ** Mark the Previously Opened Files menus of all NEdit windows as invalid.
4394 ** Since actually changing the menus is slow, they're just marked and updated
4395 ** when the user pulls one down.
4397 static void invalidatePrevOpenMenus(void)
4399 WindowInfo *w;
4401 /* Mark the menus invalid (to be updated when the user pulls one
4402 down), unless the menu is torn off, meaning it is visible to the user
4403 and should be updated immediately */
4404 for (w=WindowList; w!=NULL; w=w->next) {
4405 if (!XmIsMenuShell(XtParent(w->prevOpenMenuPane)))
4406 updatePrevOpenMenu(w);
4407 else
4408 w->prevOpenMenuValid = False;
4413 ** Add a file to the list of previously opened files for display in the
4414 ** File menu.
4416 void AddToPrevOpenMenu(const char *filename)
4418 int i;
4419 char *nameCopy;
4420 WindowInfo *w;
4422 /* If the Open Previous command is disabled, just return */
4423 if (GetPrefMaxPrevOpenFiles() == 0)
4424 return;
4426 /* If the name is already in the list, move it to the start */
4427 for (i=0; i<NPrevOpen; i++) {
4428 if (!strcmp(filename, PrevOpen[i])) {
4429 nameCopy = PrevOpen[i];
4430 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * i);
4431 PrevOpen[0] = nameCopy;
4432 invalidatePrevOpenMenus();
4433 WriteNEditDB();
4434 return;
4438 /* If the list is already full, make room */
4439 if (NPrevOpen == GetPrefMaxPrevOpenFiles())
4440 XtFree(PrevOpen[--NPrevOpen]);
4442 /* Add it to the list */
4443 nameCopy = XtMalloc(strlen(filename) + 1);
4444 strcpy(nameCopy, filename);
4445 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * NPrevOpen);
4446 PrevOpen[0] = nameCopy;
4447 NPrevOpen++;
4449 /* Mark the Previously Opened Files menu as invalid in all windows */
4450 invalidatePrevOpenMenus();
4452 /* Undim the menu in all windows if it was previously empty */
4453 if (NPrevOpen == 1)
4454 for (w=WindowList; w!=NULL; w=w->next) {
4455 if (!IsTopDocument(w))
4456 continue;
4457 XtSetSensitive(w->prevOpenMenuItem, True);
4460 /* Write the menu contents to disk to restore in later sessions */
4461 WriteNEditDB();
4464 static char* getWindowsMenuEntry(const WindowInfo* window)
4466 static char fullTitle[MAXPATHLEN * 2 + 3+ 1];
4467 const char *title;
4469 XtVaGetValues(window->shell, XmNiconName, &title, NULL);
4470 #ifdef SGI_CUSTOM
4471 title = title + SGI_WINDOW_TITLE_LEN;
4472 #endif
4474 sprintf(fullTitle, "%s%s", window->filename,
4475 window->fileChanged? "*" : "");
4477 if (GetPrefShowPathInWindowsMenu() && window->filenameSet)
4479 strcat(fullTitle, " - ");
4480 strcat(fullTitle, window->path);
4483 return(fullTitle);
4487 ** Update the Window menu of a single window to reflect the current state of
4488 ** all NEdit windows as determined by the global WindowList.
4490 static void updateWindowMenu(const WindowInfo *window)
4492 WindowInfo *w;
4493 WidgetList items;
4494 Cardinal nItems;
4495 int i, n, nWindows, windowIndex;
4496 WindowInfo **windows;
4498 if (!IsTopDocument(window))
4499 return;
4501 /* Make a sorted list of windows */
4502 /* windows = MakeSortedWindowArray();*/
4503 for (w=WindowList, nWindows=0; w!=NULL; w=w->next, nWindows++);
4504 windows = (WindowInfo **)XtMalloc(sizeof(WindowInfo *) * nWindows);
4505 for (w=WindowList, i=0; w!=NULL; w=w->next, i++)
4506 windows[i] = w;
4507 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowNames);
4509 /* if the menu is torn off, unmanage the menu pane
4510 before updating it to prevent the tear-off menu
4511 from shrinking/expanding as the menu entries
4512 are added */
4513 if (!XmIsMenuShell(XtParent(window->windowMenuPane)))
4514 XtUnmanageChild(window->windowMenuPane);
4516 /* While it is not possible on some systems (ibm at least) to substitute
4517 a new menu pane, it is possible to substitute menu items, as long as
4518 at least one remains in the menu at all times. This routine assumes
4519 that the menu contains permanent items marked with the value
4520 PERMANENT_MENU_ITEM in the userData resource, and adds and removes items
4521 which it marks with the value TEMPORARY_MENU_ITEM */
4523 /* Go thru all of the items in the menu and rename them to
4524 match the window list. Delete any extras */
4525 XtVaGetValues(window->windowMenuPane, XmNchildren, &items,
4526 XmNnumChildren, &nItems, NULL);
4527 windowIndex = 0;
4528 nWindows = NWindows();
4529 for (n=0; n<(int)nItems; n++) {
4530 XtPointer userData;
4531 XtVaGetValues(items[n], XmNuserData, &userData, NULL);
4532 if (userData == TEMPORARY_MENU_ITEM) {
4533 if (windowIndex >= nWindows) {
4534 /* unmanaging before destroying stops parent from displaying */
4535 XtUnmanageChild(items[n]);
4536 XtDestroyWidget(items[n]);
4537 } else {
4538 XmString st1;
4539 char* title = getWindowsMenuEntry(windows[windowIndex]);
4540 XtVaSetValues(items[n], XmNlabelString,
4541 st1=XmStringCreateSimple(title), NULL);
4542 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4543 XtAddCallback(items[n], XmNactivateCallback,
4544 (XtCallbackProc)raiseCB, windows[windowIndex]);
4545 XmStringFree(st1);
4546 windowIndex++;
4551 /* Add new items for the titles of the remaining windows to the menu */
4552 for (; windowIndex<nWindows; windowIndex++) {
4553 XmString st1;
4554 char* title = getWindowsMenuEntry(windows[windowIndex]);
4555 Widget btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4556 window->windowMenuPane,
4557 XmNlabelString, st1=XmStringCreateSimple(title),
4558 XmNmarginHeight, 0,
4559 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4560 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)raiseCB,
4561 windows[windowIndex]);
4562 XmStringFree(st1);
4564 XtFree((char *)windows);
4566 /* if the menu is torn off, we need to manually adjust the
4567 dimension of the menuShell _before_ re-managing the menu
4568 pane, to either expose the hidden menu entries or remove
4569 the empty space */
4570 if (!XmIsMenuShell(XtParent(window->windowMenuPane))) {
4571 Dimension width, height;
4573 XtVaGetValues(window->windowMenuPane, XmNwidth, &width,
4574 XmNheight, &height, NULL);
4575 XtVaSetValues(XtParent(window->windowMenuPane), XmNwidth, width,
4576 XmNheight, height, NULL);
4577 XtManageChild(window->windowMenuPane);
4582 ** Update the Previously Opened Files menu of a single window to reflect the
4583 ** current state of the list as retrieved from GetPrevOpenFiles.
4584 ** Thanks to Markus Schwarzenberg for the sorting part.
4586 static void updatePrevOpenMenu(WindowInfo *window)
4588 Widget btn;
4589 WidgetList items;
4590 Cardinal nItems;
4591 int n, index;
4592 XmString st1;
4593 char **prevOpenSorted;
4595 /* Sort the previously opened file list if requested */
4596 prevOpenSorted = (char **)XtMalloc(NPrevOpen * sizeof(char*));
4597 memcpy(prevOpenSorted, PrevOpen, NPrevOpen * sizeof(char*));
4598 if (GetPrefSortOpenPrevMenu())
4599 qsort(prevOpenSorted, NPrevOpen, sizeof(char*), cmpStrPtr);
4601 /* Go thru all of the items in the menu and rename them to match the file
4602 list. In older Motifs (particularly ibm), it was dangerous to replace
4603 a whole menu pane, which would be much simpler. However, since the
4604 code was already written for the Windows menu and is well tested, I'll
4605 stick with this weird method of re-naming the items */
4606 XtVaGetValues(window->prevOpenMenuPane, XmNchildren, &items,
4607 XmNnumChildren, &nItems, NULL);
4608 index = 0;
4609 for (n=0; n<(int)nItems; n++) {
4610 if (index >= NPrevOpen) {
4611 /* unmanaging before destroying stops parent from displaying */
4612 XtUnmanageChild(items[n]);
4613 XtDestroyWidget(items[n]);
4614 } else {
4615 XtVaSetValues(items[n], XmNlabelString,
4616 st1=XmStringCreateSimple(prevOpenSorted[index]), NULL);
4617 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4618 XtAddCallback(items[n], XmNactivateCallback,
4619 (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
4620 XmStringFree(st1);
4621 index++;
4625 /* Add new items for the remaining file names to the menu */
4626 for (; index<NPrevOpen; index++) {
4627 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4628 window->prevOpenMenuPane,
4629 XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
4630 XmNmarginHeight, 0,
4631 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4632 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)openPrevCB,
4633 prevOpenSorted[index]);
4634 XmStringFree(st1);
4637 XtFree((char*)prevOpenSorted);
4641 ** This function manages the display of the Tags File Menu, which is displayed
4642 ** when the user selects Un-load Tags File.
4644 static void updateTagsFileMenu(WindowInfo *window)
4646 tagFile *tf;
4647 Widget btn;
4648 WidgetList items;
4649 Cardinal nItems;
4650 int n;
4651 XmString st1;
4653 /* Go thru all of the items in the menu and rename them to match the file
4654 list. In older Motifs (particularly ibm), it was dangerous to replace
4655 a whole menu pane, which would be much simpler. However, since the
4656 code was already written for the Windows menu and is well tested, I'll
4657 stick with this weird method of re-naming the items */
4658 XtVaGetValues(window->unloadTagsMenuPane, XmNchildren, &items,
4659 XmNnumChildren, &nItems, NULL);
4660 tf = TagsFileList;
4661 for (n=0; n<(int)nItems; n++) {
4662 if (!tf) {
4663 /* unmanaging before destroying stops parent from displaying */
4664 XtUnmanageChild(items[n]);
4665 XtDestroyWidget(items[n]);
4666 } else {
4667 XtVaSetValues(items[n], XmNlabelString,
4668 st1=XmStringCreateSimple(tf->filename), NULL);
4669 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4670 XtAddCallback(items[n], XmNactivateCallback,
4671 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4672 XmStringFree(st1);
4673 tf = tf->next;
4677 /* Add new items for the remaining file names to the menu */
4678 while (tf) {
4679 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4680 window->unloadTagsMenuPane, XmNlabelString,
4681 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4682 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4683 XtAddCallback(btn, XmNactivateCallback,
4684 (XtCallbackProc)unloadTagsFileCB, tf->filename);
4685 XmStringFree(st1);
4686 tf = tf->next;
4691 ** This function manages the display of the Tips File Menu, which is displayed
4692 ** when the user selects Un-load Calltips File.
4694 static void updateTipsFileMenu(WindowInfo *window)
4696 tagFile *tf;
4697 Widget btn;
4698 WidgetList items;
4699 Cardinal nItems;
4700 int n;
4701 XmString st1;
4703 /* Go thru all of the items in the menu and rename them to match the file
4704 list. In older Motifs (particularly ibm), it was dangerous to replace
4705 a whole menu pane, which would be much simpler. However, since the
4706 code was already written for the Windows menu and is well tested, I'll
4707 stick with this weird method of re-naming the items */
4708 XtVaGetValues(window->unloadTipsMenuPane, XmNchildren, &items,
4709 XmNnumChildren, &nItems, NULL);
4710 tf = TipsFileList;
4711 for (n=0; n<(int)nItems; n++) {
4712 if (!tf) {
4713 /* unmanaging before destroying stops parent from displaying */
4714 XtUnmanageChild(items[n]);
4715 XtDestroyWidget(items[n]);
4716 } else {
4717 XtVaSetValues(items[n], XmNlabelString,
4718 st1=XmStringCreateSimple(tf->filename), NULL);
4719 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
4720 XtAddCallback(items[n], XmNactivateCallback,
4721 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4722 XmStringFree(st1);
4723 tf = tf->next;
4727 /* Add new items for the remaining file names to the menu */
4728 while (tf) {
4729 btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
4730 window->unloadTipsMenuPane, XmNlabelString,
4731 st1=XmStringCreateSimple(tf->filename),XmNmarginHeight, 0,
4732 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
4733 XtAddCallback(btn, XmNactivateCallback,
4734 (XtCallbackProc)unloadTipsFileCB, tf->filename);
4735 XmStringFree(st1);
4736 tf = tf->next;
4741 ** Comparison function for sorting file names for the Open Previous submenu
4743 static int cmpStrPtr(const void *strA, const void *strB)
4745 return strcmp(*((char**)strA), *((char**)strB));
4748 #ifdef VMS
4749 static char neditDBBadFilenameChars[] = "\n\t*?()[]{}!@#%^&:;' ";
4750 #else
4751 static char neditDBBadFilenameChars[] = "\n";
4752 #endif
4755 ** Write dynamic database of file names for "Open Previous". Eventually,
4756 ** this may hold window positions, and possibly file marks, in which case,
4757 ** it should be moved to a different module, but for now it's just a list
4758 ** of previously opened files.
4760 void WriteNEditDB(void)
4762 const char* fullName = GetRCFileName(NEDIT_HISTORY);
4763 FILE *fp;
4764 int i;
4765 static char fileHeader[] =
4766 "# File name database for NEdit Open Previous command\n";
4768 if (fullName == NULL) {
4769 /* GetRCFileName() might return NULL if an error occurs during
4770 creation of the preference file directory. */
4771 return;
4774 /* If the Open Previous command is disabled, just return */
4775 if (GetPrefMaxPrevOpenFiles() == 0) {
4776 return;
4779 /* open the file */
4780 if ((fp = fopen(fullName, "w")) == NULL) {
4781 return;
4784 /* write the file header text to the file */
4785 fprintf(fp, "%s", fileHeader);
4787 /* Write the list of file names */
4788 for (i = 0; i < NPrevOpen; ++i) {
4789 size_t lineLen = strlen(PrevOpen[i]);
4791 if (lineLen > 0 && PrevOpen[i][0] != '#' &&
4792 strcspn(PrevOpen[i], neditDBBadFilenameChars) == lineLen) {
4793 fprintf(fp, "%s\n", PrevOpen[i]);
4797 fclose(fp);
4801 ** Read dynamic database of file names for "Open Previous". Eventually,
4802 ** this may hold window positions, and possibly file marks, in which case,
4803 ** it should be moved to a different module, but for now it's just a list
4804 ** of previously opened files. This routine should only be called once,
4805 ** at startup time, before any windows are open.
4807 void ReadNEditDB(void)
4809 const char *fullName = GetRCFileName(NEDIT_HISTORY);
4810 char line[MAXPATHLEN + 2];
4811 char *nameCopy;
4812 FILE *fp;
4813 size_t lineLen;
4815 /* If the Open Previous command is disabled, just return */
4816 if (GetPrefMaxPrevOpenFiles() == 0) {
4817 return;
4820 /* Initialize the files list and allocate a (permanent) block memory
4821 of the size prescribed by the maxPrevOpenFiles resource */
4822 PrevOpen = (char **)XtMalloc(sizeof(char *) * GetPrefMaxPrevOpenFiles());
4823 NPrevOpen = 0;
4825 /* Don't move this check ahead of the previous statements. PrevOpen
4826 must be initialized at all times. */
4827 if (fullName == NULL)
4829 /* GetRCFileName() might return NULL if an error occurs during
4830 creation of the preference file directory. */
4831 return;
4834 /* open the file */
4835 if ((fp = fopen(fullName, "r")) == NULL) {
4836 return;
4839 /* read lines of the file, lines beginning with # are considered to be
4840 comments and are thrown away. Lines are subject to cursory checking,
4841 then just copied to the Open Previous file menu list */
4842 while (True) {
4843 if (fgets(line, sizeof(line), fp) == NULL) {
4844 /* end of file */
4845 fclose(fp);
4846 return;
4848 if (line[0] == '#') {
4849 /* comment */
4850 continue;
4852 lineLen = strlen(line);
4853 if (lineLen == 0) {
4854 /* blank line */
4855 continue;
4857 if (line[lineLen - 1] != '\n') {
4858 /* no newline, probably truncated */
4859 fprintf(stderr, "nedit: Line too long in history file\n");
4860 while (fgets(line, sizeof(line), fp) != NULL) {
4861 lineLen = strlen(line);
4862 if (lineLen > 0 && line[lineLen - 1] == '\n') {
4863 break;
4866 continue;
4868 line[--lineLen] = '\0';
4869 if (strcspn(line, neditDBBadFilenameChars) != lineLen) {
4870 /* non-filename characters */
4871 fprintf(stderr, "nedit: History file may be corrupted\n");
4872 continue;
4874 nameCopy = XtMalloc(lineLen + 1);
4875 strcpy(nameCopy, line);
4876 PrevOpen[NPrevOpen++] = nameCopy;
4877 if (NPrevOpen >= GetPrefMaxPrevOpenFiles()) {
4878 /* too many entries */
4879 fclose(fp);
4880 return;
4885 static void setWindowSizeDefault(int rows, int cols)
4887 SetPrefRows(rows);
4888 SetPrefCols(cols);
4889 updateWindowSizeMenus();
4892 static void updateWindowSizeMenus(void)
4894 WindowInfo *win;
4896 for (win=WindowList; win!=NULL; win=win->next)
4897 updateWindowSizeMenu(win);
4900 static void updateWindowSizeMenu(WindowInfo *win)
4902 int rows = GetPrefRows(), cols = GetPrefCols();
4903 char title[50];
4904 XmString st1;
4906 if (!IsTopDocument(win))
4907 return;
4909 XmToggleButtonSetState(win->size24x80DefItem, rows==24&&cols==80,False);
4910 XmToggleButtonSetState(win->size40x80DefItem, rows==40&&cols==80,False);
4911 XmToggleButtonSetState(win->size60x80DefItem, rows==60&&cols==80,False);
4912 XmToggleButtonSetState(win->size80x80DefItem, rows==80&&cols==80,False);
4913 if ((rows!=24 && rows!=40 && rows!=60 && rows!=80) || cols!=80) {
4914 XmToggleButtonSetState(win->sizeCustomDefItem, True, False);
4915 sprintf(title, "Custom... (%d x %d)", rows, cols);
4916 XtVaSetValues(win->sizeCustomDefItem,
4917 XmNlabelString, st1=XmStringCreateSimple(title), NULL);
4918 XmStringFree(st1);
4919 } else {
4920 XmToggleButtonSetState(win->sizeCustomDefItem, False, False);
4921 XtVaSetValues(win->sizeCustomDefItem,
4922 XmNlabelString, st1=XmStringCreateSimple("Custom..."), NULL);
4923 XmStringFree(st1);
4928 ** Scans action argument list for arguments "forward" or "backward" to
4929 ** determine search direction for search and replace actions. "ignoreArgs"
4930 ** tells the routine how many required arguments there are to ignore before
4931 ** looking for keywords
4933 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs)
4935 int i;
4937 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4938 if (!strCaseCmp(args[i], "forward"))
4939 return SEARCH_FORWARD;
4940 if (!strCaseCmp(args[i], "backward"))
4941 return SEARCH_BACKWARD;
4943 return SEARCH_FORWARD;
4947 ** Scans action argument list for arguments "keep" or "nokeep" to
4948 ** determine whether to keep dialogs up for search and replace. "ignoreArgs"
4949 ** tells the routine how many required arguments there are to ignore before
4950 ** looking for keywords
4952 static int searchKeepDialogs(int ignoreArgs, String *args, Cardinal *nArgs)
4954 int i;
4956 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4957 if (!strCaseCmp(args[i], "keep"))
4958 return TRUE;
4959 if (!strCaseCmp(args[i], "nokeep"))
4960 return FALSE;
4962 return GetPrefKeepSearchDlogs();
4966 ** Scans action argument list for arguments "wrap" or "nowrap" to
4967 ** determine search direction for search and replace actions. "ignoreArgs"
4968 ** tells the routine how many required arguments there are to ignore before
4969 ** looking for keywords
4971 static int searchWrap(int ignoreArgs, String *args, Cardinal *nArgs)
4973 int i;
4975 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4976 if (!strCaseCmp(args[i], "wrap"))
4977 return(TRUE);
4978 if (!strCaseCmp(args[i], "nowrap"))
4979 return(FALSE);
4981 return GetPrefSearchWraps();
4985 ** Scans action argument list for arguments "literal", "case" or "regex" to
4986 ** determine search type for search and replace actions. "ignoreArgs"
4987 ** tells the routine how many required arguments there are to ignore before
4988 ** looking for keywords
4990 static int searchType(int ignoreArgs, String *args, Cardinal *nArgs)
4992 int i, tmpSearchType;
4994 for (i=ignoreArgs; i<(int)*nArgs; i++) {
4995 if (StringToSearchType(args[i], &tmpSearchType))
4996 return tmpSearchType;
4998 return GetPrefSearch();
5002 ** Return a pointer to the string describing search direction for search action
5003 ** routine parameters given a callback XmAnyCallbackStruct pointed to by
5004 ** "callData", by checking if the shift key is pressed (for search callbacks).
5006 static char **shiftKeyToDir(XtPointer callData)
5008 static char *backwardParam[1] = {"backward"};
5009 static char *forwardParam[1] = {"forward"};
5010 if (((XmAnyCallbackStruct *)callData)->event->xbutton.state & ShiftMask)
5011 return backwardParam;
5012 return forwardParam;
5015 static void raiseCB(Widget w, WindowInfo *window, caddr_t callData)
5017 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5018 ((XmAnyCallbackStruct *)callData)->event);
5019 RaiseDocumentWindow(window);
5022 static void openPrevCB(Widget w, char *name, caddr_t callData)
5024 char *params[1];
5025 Widget menu = MENU_WIDGET(w);
5027 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5028 ((XmAnyCallbackStruct *)callData)->event);
5029 params[0] = name;
5030 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "open",
5031 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5032 CheckCloseDim();
5035 static void unloadTagsFileCB(Widget w, char *name, caddr_t callData)
5037 char *params[1];
5038 Widget menu = MENU_WIDGET(w);
5040 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5041 ((XmAnyCallbackStruct *)callData)->event);
5042 params[0] = name;
5043 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tags_file",
5044 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5047 static void unloadTipsFileCB(Widget w, char *name, caddr_t callData)
5049 char *params[1];
5050 #if XmVersion >= 1002
5051 Widget menu = XmGetPostedFromWidget(XtParent(w)); /* If menu is torn off */
5052 #else
5053 Widget menu = w;
5054 #endif
5056 params[0] = name;
5057 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "unload_tips_file",
5058 ((XmAnyCallbackStruct *)callData)->event, params, 1);
5062 ** strCaseCmp compares its arguments and returns 0 if the two strings
5063 ** are equal IGNORING case differences. Otherwise returns 1.
5065 static int strCaseCmp(const char *str1, const char *str2)
5067 const char *c1, *c2;
5069 for (c1=str1, c2=str2; *c1!='\0' && *c2!='\0'; c1++, c2++)
5070 if (toupper((unsigned char)*c1) != toupper((unsigned char)*c2))
5071 return 1;
5072 if (*c1 == *c2) {
5073 return(0);
5075 else {
5076 return(1);
5081 ** Comparison function for sorting windows by title for the window menu.
5082 ** Windows are sorted by Untitled and then alphabetically by filename and
5083 ** then alphabetically by path.
5085 static int compareWindowNames(const void *windowA, const void *windowB)
5087 int rc;
5088 const WindowInfo *a = *((WindowInfo**)windowA);
5089 const WindowInfo *b = *((WindowInfo**)windowB);
5090 /* Untitled first */
5091 rc = a->filenameSet == b->filenameSet ? 0 :
5092 a->filenameSet && !b->filenameSet ? 1 : -1;
5093 if (rc != 0)
5094 return rc;
5095 rc = strcmp(a->filename, b->filename);
5096 if (rc != 0)
5097 return rc;
5098 rc = strcmp(a->path, b->path);
5099 return rc;
5102 static int compareWindowShell(const void *windowA, const void *windowB)
5104 const WindowInfo *a = *((WindowInfo**)windowA);
5105 const WindowInfo *b = *((WindowInfo**)windowB);
5107 return a->shell > b->shell;
5111 ** create & return a sorted list of windows
5112 ** Windows are first sort by their filename then,
5113 ** if windows are tabbed, grouped by their shell windows
5115 ** Note: caller must XtFree the returned window list.
5117 WindowInfo **MakeSortedWindowArray(void)
5119 WindowInfo *w, **windows;
5120 int i, nWindows;
5122 /* Make a sorted list of windows */
5123 for (w=WindowList, nWindows=0; w!=NULL; w=w->next, nWindows++);
5124 windows = (WindowInfo **)XtMalloc(sizeof(WindowInfo *) * nWindows);
5125 for (w=WindowList, i=0; w!=NULL; w=w->next, i++)
5126 windows[i] = w;
5127 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowNames);
5129 /* group the documents together by their shell window */
5130 if (GetPrefOpenInTab())
5131 qsort(windows, nWindows, sizeof(WindowInfo *), compareWindowShell);
5133 return windows;
5137 ** Create popup for right button programmable menu
5139 Widget CreateBGMenu(WindowInfo *window)
5141 Arg args[1];
5143 /* There is still some mystery here. It's important to get the XmNmenuPost
5144 resource set to the correct menu button, or the menu will not post
5145 properly, but there's also some danger that it will take over the entire
5146 button and interfere with text widget translations which use the button
5147 with modifiers. I don't entirely understand why it works properly now
5148 when it failed often in development, and certainly ignores the ~ syntax
5149 in translation event specifications. */
5150 XtSetArg(args[0], XmNmenuPost, GetPrefBGMenuBtn());
5151 return CreatePopupMenu(window->textArea, "bgMenu", args, 1);
5155 ** Create context popup menu for tabs & tab bar
5157 Widget CreateTabContextMenu(Widget parent, WindowInfo *window)
5159 Widget menu;
5160 Arg args[8];
5161 int n;
5163 n = 0;
5164 XtSetArg(args[n], XmNtearOffModel, XmTEAR_OFF_DISABLED); n++;
5165 menu = XmCreatePopupMenu(parent, "tabContext", args, n);
5167 createMenuItem(menu, "new", "New Tab", 0, doTabActionCB, "new_tab", SHORT);
5168 createMenuItem(menu, "close", "Close Tab", 0, doTabActionCB, "close", SHORT);
5169 createMenuSeparator(menu, "sep1", SHORT);
5170 window->contextDetachDocumentItem = createMenuItem(menu, "detach",
5171 "Detach Tab", 0, doTabActionCB, "detach_document", SHORT);
5172 XtSetSensitive(window->contextDetachDocumentItem, False);
5173 window->contextMoveDocumentItem = createMenuItem(menu, "attach",
5174 "Move Tab To...", 0, doTabActionCB, "move_document_dialog", SHORT);
5176 return menu;
5180 ** Add a translation to the text widget to trigger the background menu using
5181 ** the mouse-button + modifier combination specified in the resource:
5182 ** nedit.bgMenuBtn.
5184 void AddBGMenuAction(Widget widget)
5186 static XtTranslations table = NULL;
5188 if (table == NULL) {
5189 char translations[MAX_ACCEL_LEN + 25];
5190 sprintf(translations, "%s: post_window_bg_menu()\n",GetPrefBGMenuBtn());
5191 table = XtParseTranslationTable(translations);
5193 XtOverrideTranslations(widget, table);
5196 static void bgMenuPostAP(Widget w, XEvent *event, String *args,
5197 Cardinal *nArgs)
5199 WindowInfo *window = WidgetToWindow(w);
5201 /* The Motif popup handling code BLOCKS events while the menu is posted,
5202 including the matching btn-up events which complete various dragging
5203 operations which it may interrupt. Cancel to head off problems */
5204 XtCallActionProc(window->lastFocus, "process_cancel", event, NULL, 0);
5206 /* Pop up the menu */
5207 XmMenuPosition(window->bgMenuPane, (XButtonPressedEvent *)event);
5208 XtManageChild(window->bgMenuPane);
5211 These statements have been here for a very long time, but seem
5212 unnecessary and are even dangerous: when any of the lock keys are on,
5213 Motif thinks it shouldn't display the background menu, but this
5214 callback is called anyway. When we then grab the focus and force the
5215 menu to be drawn, bad things can happen (like a total lockup of the X
5216 server).
5218 XtPopup(XtParent(window->bgMenuPane), XtGrabNonexclusive);
5219 XtMapWidget(XtParent(window->bgMenuPane));
5220 XtMapWidget(window->bgMenuPane);
5224 void AddTabContextMenuAction(Widget widget)
5226 static XtTranslations table = NULL;
5228 if (table == NULL) {
5229 char *translations = "<Btn3Down>: post_tab_context_menu()\n";
5230 table = XtParseTranslationTable(translations);
5232 XtOverrideTranslations(widget, table);
5236 ** action procedure for posting context menu of tabs
5238 static void tabMenuPostAP(Widget w, XEvent *event, String *args,
5239 Cardinal *nArgs)
5241 WindowInfo *window;
5242 XButtonPressedEvent *xbutton = (XButtonPressedEvent *)event;
5243 Widget wgt;
5245 /* Determine if the context menu was called from tabs or gutter,
5246 then stored the corresponding window info as userData of
5247 the popup menu pane, which will later be extracted by
5248 doTabActionCB() to act upon. When the context menu was called
5249 from the gutter, the active doc is assumed.
5251 Lesstif requires the action [to pupop the menu] to also be
5252 to the tabs, else nothing happed when right-click on tabs.
5253 Even so, the action procedure sometime appear to be called
5254 from the gutter even if users did right-click on the tabs.
5255 Here we try to cater for the uncertainty. */
5256 if (XtClass(w) == xrwsBubbleButtonWidgetClass)
5257 window = TabToWindow(w);
5258 else if (xbutton->subwindow) {
5259 wgt = XtWindowToWidget(XtDisplay(w), xbutton->subwindow);
5260 window = TabToWindow(wgt);
5262 else {
5263 window = WidgetToWindow(w);
5265 XtVaSetValues(window->tabMenuPane, XmNuserData, (XtPointer)window, NULL);
5267 /* The Motif popup handling code BLOCKS events while the menu is posted,
5268 including the matching btn-up events which complete various dragging
5269 operations which it may interrupt. Cancel to head off problems */
5270 XtCallActionProc(window->lastFocus, "process_cancel", event, NULL, 0);
5272 /* Pop up the menu */
5273 XmMenuPosition(window->tabMenuPane, (XButtonPressedEvent *)event);
5274 XtManageChild(window->tabMenuPane);
5278 ** Event handler for restoring the input hint of menu tearoffs
5279 ** previously disabled in ShowHiddenTearOff()
5281 static void tearoffMappedCB(Widget w, XtPointer clientData, XUnmapEvent *event)
5283 Widget shell = (Widget)clientData;
5284 XWMHints *wmHints;
5286 if (event->type != MapNotify)
5287 return;
5289 /* restore the input hint previously disabled in ShowHiddenTearOff() */
5290 wmHints = XGetWMHints(TheDisplay, XtWindow(shell));
5291 wmHints->input = True;
5292 wmHints->flags |= InputHint;
5293 XSetWMHints(TheDisplay, XtWindow(shell), wmHints);
5294 XFree(wmHints);
5296 /* we only need to do this only */
5297 XtRemoveEventHandler(shell, StructureNotifyMask, False,
5298 (XtEventHandler)tearoffMappedCB, shell);
5302 ** Redisplay (map) a hidden tearoff
5304 void ShowHiddenTearOff(Widget menuPane)
5306 Widget shell;
5308 if (!menuPane)
5309 return;
5311 shell = XtParent(menuPane);
5312 if (!XmIsMenuShell(shell)) {
5313 XWindowAttributes winAttr;
5315 XGetWindowAttributes(XtDisplay(shell), XtWindow(shell), &winAttr);
5316 if (winAttr.map_state == IsUnmapped) {
5317 XWMHints *wmHints;
5319 /* to workaround a problem where the remapped tearoffs
5320 always receive the input focus insteads of the text
5321 editing window, we disable the input hint of the
5322 tearoff shell temporarily. */
5323 wmHints = XGetWMHints(XtDisplay(shell), XtWindow(shell));
5324 wmHints->input = False;
5325 wmHints->flags |= InputHint;
5326 XSetWMHints(XtDisplay(shell), XtWindow(shell), wmHints);
5327 XFree(wmHints);
5329 /* show the tearoff */
5330 XtMapWidget(shell);
5332 /* the input hint will be restored when the tearoff
5333 is mapped */
5334 XtAddEventHandler(shell, StructureNotifyMask, False,
5335 (XtEventHandler)tearoffMappedCB, shell);
5340 #ifdef SGI_CUSTOM
5341 static void shortMenusCB(Widget w, WindowInfo *window, caddr_t callData)
5343 WindowInfo *win;
5344 int i, state = XmToggleButtonGetState(w);
5345 Widget parent;
5347 window = WidgetToWindow(w);
5349 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
5350 ((XmAnyCallbackStruct *)callData)->event);
5351 /* Set the preference */
5352 SetPrefShortMenus(state);
5354 /* Re-create the menus for all windows */
5355 for (win=WindowList; win!=NULL; win=win->next) {
5356 for (i=0; i<win->nToggleShortItems; i++) {
5357 if (state)
5358 XtUnmanageChild(win->toggleShortItems[i]);
5359 else
5360 XtManageChild(win->toggleShortItems[i]);
5363 if (GetPrefShortMenus())
5364 SaveNEditPrefs(window->shell, True);
5367 static void addToToggleShortList(Widget w)
5369 if (ShortMenuWindow->nToggleShortItems >= MAX_SHORTENED_ITEMS) {
5370 fprintf(stderr,"nedit, internal error: increase MAX_SHORTENED_ITEMS\n");
5371 return;
5373 ShortMenuWindow->toggleShortItems[ShortMenuWindow->nToggleShortItems++] = w;
5377 ** Present the user a dialog for specifying whether or not a short
5378 ** menu mode preference should be applied toward the default setting.
5379 ** Return True if user requested to reset and save the default value.
5380 ** If operation was canceled, will return toggle widget "w" to it's
5381 ** original (opposite) state.
5383 static int shortPrefAskDefault(Widget parent, Widget w, const char *settingName)
5385 char msg[100] = "";
5387 if (!GetPrefShortMenus()) {
5388 return False;
5391 sprintf(msg, "%s: %s\nSave as default for future windows as well?",
5392 settingName, XmToggleButtonGetState(w) ? "On" : "Off");
5393 switch (DialogF (DF_QUES, parent, 3, "Save Default", msg, "Yes", "No",
5394 "Cancel"))
5396 case 1: /* yes */
5397 return True;
5398 case 2: /* no */
5399 return False;
5400 case 3: /* cancel */
5401 XmToggleButtonSetState(w, !XmToggleButtonGetState(w), False);
5402 return False;
5404 return False; /* not reached */
5406 #endif