release client: fix race between menu building and IsServer
[nedit-bw.git] / radioOpenPrev.diff
blob66e30d38a029aa0a38551cbd3b6dc3dbd0928e5e
1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Display the File->Open Previous menu using radio buttons
4 The radio buttons indicate which files are currently open.
6 The rebuilding of the Open Previous menu is also performed when a document
7 is closed, to allow the refresh of "torn-off" copies of this menu. This is
8 why the invalidatePrevOpenMenus() function was made public rather than
9 static.
11 ---
13 source/menu.c | 36 ++++++++++++++++++++++++------------
14 source/menu.h | 1 +
15 source/window.c | 1 +
16 3 files changed, 26 insertions(+), 12 deletions(-)
18 diff --quilt old/source/menu.c new/source/menu.c
19 --- old/source/menu.c
20 +++ new/source/menu.c
21 @@ -372,7 +372,6 @@ static Widget createMenuRadioToggle(Widg
22 char mnemonic, menuCallbackProc callback, void *cbArg, int set,
23 int mode);
24 static Widget createMenuSeparator(Widget parent, char *name, int mode);
25 -static void invalidatePrevOpenMenus(void);
26 static void updateWindowMenu(const WindowInfo *window);
27 static void updatePrevOpenMenu(WindowInfo *window);
28 static void updateTagsFileMenu(WindowInfo *window);
29 @@ -4715,7 +4714,7 @@ void InvalidateWindowMenus(void)
30 ** Since actually changing the menus is slow, they're just marked and updated
31 ** when the user pulls one down.
33 -static void invalidatePrevOpenMenus(void)
34 +void InvalidatePrevOpenMenus(void)
36 WindowInfo *w;
38 @@ -4779,7 +4778,7 @@ void AddToPrevOpenMenu(const char *filen
39 nameCopy = PrevOpen[i];
40 memmove(&PrevOpen[1], &PrevOpen[0], sizeof(char *) * i);
41 PrevOpen[0] = nameCopy;
42 - invalidatePrevOpenMenus();
43 + InvalidatePrevOpenMenus();
44 WriteNEditDB();
45 return;
47 @@ -4799,7 +4798,7 @@ void AddToPrevOpenMenu(const char *filen
48 NPrevOpen++;
50 /* Mark the Previously Opened Files menu as invalid in all windows */
51 - invalidatePrevOpenMenus();
52 + InvalidatePrevOpenMenus();
54 /* Undim the menu in all windows if it was previously empty */
55 if (NPrevOpen > 0) {
56 @@ -4974,12 +4973,15 @@ static void updateWindowMenu(const Windo
58 static void updatePrevOpenMenu(WindowInfo *window)
60 + char filename[MAXPATHLEN];
61 + char pathname[MAXPATHLEN];
62 Widget btn;
63 WidgetList items;
64 Cardinal nItems;
65 int n, index;
66 XmString st1;
67 char **prevOpenSorted;
68 + Boolean fileIsOpen = False;
70 /* Read history file to get entries written by other sessions. */
71 ReadNEditDB();
72 @@ -5004,11 +5006,15 @@ static void updatePrevOpenMenu(WindowInf
73 XtUnmanageChild(items[n]);
74 XtDestroyWidget(items[n]);
75 } else {
76 - XtVaSetValues(items[n], XmNlabelString,
77 - st1=XmStringCreateSimple(prevOpenSorted[index]), NULL);
78 - XtRemoveAllCallbacks(items[n], XmNactivateCallback);
79 - XtAddCallback(items[n], XmNactivateCallback,
80 - (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
81 + ParseFilename(prevOpenSorted[index], filename, pathname);
82 + fileIsOpen = !!FindWindowWithFile(filename, pathname);
83 + XtVaSetValues(items[n],
84 + XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
85 + XmNset, fileIsOpen,
86 + NULL);
87 + XtRemoveAllCallbacks(items[n], XmNvalueChangedCallback);
88 + XtAddCallback(items[n], XmNvalueChangedCallback,
89 + (XtCallbackProc)openPrevCB, prevOpenSorted[index]);
90 XmStringFree(st1);
91 index++;
93 @@ -5016,12 +5022,16 @@ static void updatePrevOpenMenu(WindowInf
95 /* Add new items for the remaining file names to the menu */
96 for (; index<NPrevOpen; index++) {
97 - btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
98 + ParseFilename(prevOpenSorted[index], filename, pathname);
99 + fileIsOpen = !!FindWindowWithFile(filename, pathname);
100 + btn = XtVaCreateManagedWidget("win", xmToggleButtonWidgetClass,
101 window->prevOpenMenuPane,
102 XmNlabelString, st1=XmStringCreateSimple(prevOpenSorted[index]),
103 XmNmarginHeight, 0,
104 - XmNuserData, TEMPORARY_MENU_ITEM, NULL);
105 - XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)openPrevCB,
106 + XmNuserData, TEMPORARY_MENU_ITEM,
107 + XmNset, fileIsOpen,
108 + XmNindicatorType, XmONE_OF_MANY, NULL);
109 + XtAddCallback(btn, XmNvalueChangedCallback, (XtCallbackProc)openPrevCB,
110 prevOpenSorted[index]);
111 XmStringFree(st1);
113 @@ -5512,6 +5522,8 @@ static void openPrevCB(Widget w, char *n
114 char *params[1];
115 Widget menu = MENU_WIDGET(w);
117 + XtVaSetValues(w,
118 + XmNset, True, NULL);
119 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
120 ((XmAnyCallbackStruct *)callData)->event);
121 params[0] = name;
122 diff --quilt old/source/menu.h new/source/menu.h
123 --- old/source/menu.h
124 +++ new/source/menu.h
125 @@ -40,6 +40,7 @@ Widget CreateMenuBar(Widget parent, Wind
126 void InstallMenuActions(XtAppContext context);
127 XtActionsRec *GetMenuActions(int *nActions);
128 void InvalidateWindowMenus(void);
129 +void InvalidatePrevOpenMenus(void);
130 void CheckCloseDim(void);
131 void AddToPrevOpenMenu(const char *filename);
132 void WriteNEditDB(void);
133 diff --quilt old/source/window.c new/source/window.c
134 --- old/source/window.c
135 +++ new/source/window.c
136 @@ -1085,6 +1085,7 @@ void CloseWindow(WindowInfo *window)
137 /* remove the window from the global window list, update window menus */
138 removeFromWindowList(window);
139 InvalidateWindowMenus();
140 + InvalidatePrevOpenMenus(); /* refresh "is opened" radio buttons here */
141 CheckCloseDim(); /* Close of window running a macro may have been disabled. */
143 /* remove the tab of the closing document from tab bar */