add language_mode_hook(prev-mode)
[nedit-bw.git] / radioOpenPrev.diff
blob87b32032b7b7d01e5207337432b8045fa239318d
1 Display the File->Open Previous menu using radio buttons
3 The radio buttons indicate which files are currently open.
5 The rebuilding of the Open Previous menu is also performed when a document
6 is closed, to allow the refresh of "torn-off" copies of this menu. This is
7 why the invalidatePrevOpenMenus() function was made public rather than
8 static.
10 ---
12 source/menu.c | 36 ++++++++++++++++++++++++------------
13 source/menu.h | 1 +
14 source/window.c | 1 +
15 3 files changed, 26 insertions(+), 12 deletions(-)
17 diff --quilt old/source/menu.c new/source/menu.c
18 --- old/source/menu.c
19 +++ new/source/menu.c
20 @@ -370,11 +370,10 @@ static Widget createMenuToggle(Widget pa
21 int mode);
22 static Widget createMenuRadioToggle(Widget parent, char *name, char *label,
23 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
24 int mode);
25 static Widget createMenuSeparator(Widget parent, char *name, int mode);
26 -static void invalidatePrevOpenMenus(void);
27 static void updateWindowMenu(const WindowInfo *window);
28 static void updatePrevOpenMenu(WindowInfo *window);
29 static void updateTagsFileMenu(WindowInfo *window);
30 static void updateTipsFileMenu(WindowInfo *window);
31 static int searchDirection(int ignoreArgs, String *args, Cardinal *nArgs);
32 @@ -4743,11 +4742,11 @@ void InvalidateWindowMenus(void)
34 ** Mark the Previously Opened Files menus of all NEdit windows as invalid.
35 ** Since actually changing the menus is slow, they're just marked and updated
36 ** when the user pulls one down.
38 -static void invalidatePrevOpenMenus(void)
39 +void InvalidatePrevOpenMenus(void)
41 WindowInfo *w;
43 /* Mark the menus invalid (to be updated when the user pulls one
44 down), unless the menu is torn off, meaning it is visible to the user
45 @@ -4808,11 +4807,11 @@ void AddToPrevOpenMenu(const char *filen
46 for (i=0; i<NPrevOpen; i++) {
47 if (!strcmp(filename, PrevOpen[i])) {
48 nameCopy = PrevOpen[i];
49 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * i);
50 PrevOpen[0] = nameCopy;
51 - invalidatePrevOpenMenus();
52 + InvalidatePrevOpenMenus();
53 WriteNEditDB();
54 return;
58 @@ -4828,11 +4827,11 @@ void AddToPrevOpenMenu(const char *filen
59 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * NPrevOpen);
60 PrevOpen[0] = nameCopy;
61 NPrevOpen++;
63 /* Mark the Previously Opened Files menu as invalid in all windows */
64 - invalidatePrevOpenMenus();
65 + InvalidatePrevOpenMenus();
67 /* Undim the menu in all windows if it was previously empty */
68 if (NPrevOpen > 0) {
69 for (w=WindowList; w!=NULL; w=w->next) {
70 if (!IsTopDocument(w))
71 @@ -5003,16 +5002,19 @@ static void updateWindowMenu(const Windo
72 ** current state of the list as retrieved from FIXME.
73 ** Thanks to Markus Schwarzenberg for the sorting part.
75 static void updatePrevOpenMenu(WindowInfo *window)
77 + char filename[MAXPATHLEN];
78 + char pathname[MAXPATHLEN];
79 Widget btn;
80 WidgetList items;
81 Cardinal nItems;
82 int n, index;
83 XmString st1;
84 char **prevOpenSorted;
85 + Boolean fileIsOpen = False;
87 /* Read history file to get entries written by other sessions. */
88 ReadNEditDB();
90 /* Sort the previously opened file list if requested */
91 @@ -5033,28 +5035,36 @@ static void updatePrevOpenMenu(WindowInf
92 if (index >= NPrevOpen) {
93 /* unmanaging before destroying stops parent from displaying */
94 XtUnmanageChild(items[n]);
95 XtDestroyWidget(items[n]);
96 } else {
97 - XtVaSetValues(items[n], XmNlabelString,
98 - st1=XmStringCreateSimple(prevOpenSorted[index]), NULL);
99 - XtRemoveAllCallbacks(items[n], XmNactivateCallback);
100 - XtAddCallback(items[n], XmNactivateCallback,
101 - (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
102 + ParseFilename(prevOpenSorted[index], filename, pathname);
103 + fileIsOpen = !!FindWindowWithFile(filename, pathname);
104 + XtVaSetValues(items[n],
105 + XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
106 + XmNset, fileIsOpen,
107 + NULL);
108 + XtRemoveAllCallbacks(items[n], XmNvalueChangedCallback);
109 + XtAddCallback(items[n], XmNvalueChangedCallback,
110 + (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
111 XmStringFree(st1);
112 index++;
116 /* Add new items for the remaining file names to the menu */
117 for (; index<NPrevOpen; index++) {
118 - btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
119 + ParseFilename(prevOpenSorted[index], filename, pathname);
120 + fileIsOpen = !!FindWindowWithFile(filename, pathname);
121 + btn = XtVaCreateManagedWidget("win", xmToggleButtonWidgetClass,
122 window->prevOpenMenuPane,
123 XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
124 XmNmarginHeight, 0,
125 - XmNuserData, TEMPORARY_MENU_ITEM, NULL);
126 - XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)openPrevCB,
127 + XmNuserData, TEMPORARY_MENU_ITEM,
128 + XmNset, fileIsOpen,
129 + XmNindicatorType, XmONE_OF_MANY, NULL);
130 + XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc)openPrevCB,
131 prevOpenSorted[index]);
132 XmStringFree(st1);
135 XtFree((char*)prevOpenSorted);
136 @@ -5523,10 +5533,12 @@ static void raiseCB(Widget w, WindowInfo
137 static void openPrevCB(Widget w, char *name, caddr_t callData)
139 char *params[1];
140 Widget menu = MENU_WIDGET(w);
142 + XtVaSetValues(w,
143 + XmNset, True, NULL);
144 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
145 ((XmAnyCallbackStruct *)callData)->event);
146 params[0] = name;
147 XtCallActionProc(WidgetToWindow(menu)->lastFocus, "open",
148 ((XmAnyCallbackStruct *)callData)->event, params, 1);
149 diff --quilt old/source/menu.h new/source/menu.h
150 --- old/source/menu.h
151 +++ new/source/menu.h
152 @@ -38,10 +38,11 @@
154 Widget CreateMenuBar(Widget parent, WindowInfo *window);
155 void InstallMenuActions(XtAppContext context);
156 XtActionsRec *GetMenuActions(int *nActions);
157 void InvalidateWindowMenus(void);
158 +void InvalidatePrevOpenMenus(void);
159 void CheckCloseDim(void);
160 void AddToPrevOpenMenu(const char *filename);
161 void WriteNEditDB(void);
162 void ReadNEditDB(void);
163 Widget CreateBGMenu(WindowInfo *window);
164 diff --quilt old/source/window.c new/source/window.c
165 --- old/source/window.c
166 +++ new/source/window.c
167 @@ -1063,10 +1063,11 @@ void CloseWindow(WindowInfo *window)
170 /* remove the window from the global window list, update window menus */
171 removeFromWindowList(window);
172 InvalidateWindowMenus();
173 + InvalidatePrevOpenMenus(); /* refresh "is opened" radio buttons here */
174 CheckCloseDim(); /* Close of window running a macro may have been disabled. */
176 /* remove the tab of the closing document from tab bar */
177 XtDestroyWidget(window->tab);