1 From: Tony Balinski <ajbj@free.fr>
2 Subject: Add coloring to the windows menu to indicate modified buffers
4 This is a modified version of Arne Førlie's patch:
6 http://sourceforge.net/tracker/index.php?func=detail&aid=937063&group_id=11005&atid=311005
7 [ 937063 ] Coloured file names in Windows menu
8 89330: colored_win _v2.patch 2004-06-02 16:17
10 This patch color-codes the file names in the windows menu according to
13 By default the patch uses the following colours:
15 - modified (unsaved) files are red
16 - read-only files are blue
17 - otherwise they are black
19 For modified and read-only, you can also change the background color used;
20 this is normally set to "white"; set it to "default" to use the normal menu
23 A set of X resources are used to modify the defaults. They are documented in
24 the help (do 'make docs' to update the help files before building the
27 nedit.coloredWinMenu: True
28 nedit.defaultWinMenuColor: black
29 nedit.modifiedWinMenuColor: red
30 nedit.readOnlyWinMenuColor: blue
31 nedit.backgroundWinMenuColor: white
35 Updated to be synchronised with CVS head.
39 Added new resource backgroundWinMenuColor
43 Removed irrelevant help info (thanks to Bert Wesarg)
47 doc/help.etx | 26 ++++++++++++++++
48 source/menu.c | 39 +++++++++++++++++++++++++
49 source/preferences.c | 79 +++++++++++++++++++++++++++++++++++++++++++++++++++
50 source/preferences.h | 9 +++++
51 4 files changed, 153 insertions(+)
53 diff --quilt old/doc/help.etx new/doc/help.etx
56 @@ -4603,6 +4603,32 @@ X Resources
57 set to False, the "Case Sensitive" buttons are independent of the "Regular
60 +**nedit.coloredWinMenu**: True
62 + Controls if the Windows menu shall use colors to code the file's status.
64 + If above resource is set to True, the following five resources can be used
65 + to define the colors to use. For all three cases a color value of "default"
66 + can be used to specify that the default color as specified by the window
67 + manager shall be used.
69 +**nedit.defaultWinMenuColor**: black
71 + Defines the default color of files in the Windows menu.
73 +**nedit.modifiedWinMenuColor**: red
75 + Defines the color of modified (unsaved) files in the Windows menu.
77 +**nedit.readOnlyWinMenuColor**: blue
79 + Defines the color of read-only files in the Windows menu.
81 +**nedit.backgroundWinMenuColor**: white
83 + Defines the color of the background used for colored Windows menu items
84 + when using either the modified or read-only foreground color.
86 **nedit.multiClickTime**: (system specific)
88 Maximum time in milliseconds allowed between mouse clicks within double and
89 diff --quilt old/source/menu.c new/source/menu.c
92 @@ -4834,6 +4834,42 @@ void AddToPrevOpenMenu(const char *filen
96 +static void colorWindowMenuEntries(const WindowInfo* window, Widget widget)
98 + if (GetPrefColoredWinMenu() == True)
100 + Pixel oldFg, oldBg;
101 + const char* bgcolor = "default";
102 + int bgcolorLength = 7;
105 + if (IS_ANY_LOCKED(window->lockReasons)) {
106 + color = GetPrefRoMenuColor(&colorLength);
107 + bgcolor = GetPrefBgMenuColor(&bgcolorLength);
109 + else if (window->fileChanged == TRUE) {
110 + color = GetPrefModMenuColor(&colorLength);
111 + bgcolor = GetPrefBgMenuColor(&bgcolorLength);
114 + color = GetPrefDefMenuColor(&colorLength);
115 + /* leave background for the default color alone */
117 + XtVaGetValues(XtParent(widget), XmNforeground, &oldFg,
118 + XmNbackground, &oldBg, NULL);
119 + if (strcmp(color, "default") != 0) {
120 + XtVaSetValues(widget, XtVaTypedArg, XmNforeground, XmRString, color, colorLength + 1, NULL);
122 + XtVaSetValues(widget, XmNforeground, oldFg, NULL);
124 + if (strcmp(bgcolor, "default") != 0) {
125 + XtVaSetValues(widget, XtVaTypedArg, XmNbackground, XmRString, bgcolor, bgcolorLength + 1, NULL);
127 + XtVaSetValues(widget, XmNbackground, oldBg, NULL);
132 static char* getWindowsMenuEntry(const WindowInfo* window)
134 static char fullTitle[MAXPATHLEN * 2 + 3+ 1];
135 @@ -4905,6 +4941,7 @@ static void updateWindowMenu(const Windo
136 char* title = getWindowsMenuEntry(windows[windowIndex]);
137 XtVaSetValues(items[n], XmNlabelString,
138 st1=XmStringCreateSimple(title), NULL);
139 + colorWindowMenuEntries(windows[windowIndex], items[n]);
140 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
141 XtAddCallback(items[n], XmNactivateCallback,
142 (XtCallbackProc)raiseCB, windows[windowIndex]);
143 @@ -4923,6 +4960,8 @@ static void updateWindowMenu(const Windo
144 XmNlabelString, st1=XmStringCreateSimple(title),
146 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
148 + colorWindowMenuEntries(windows[windowIndex], btn);
149 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)raiseCB,
150 windows[windowIndex]);
152 diff --quilt old/source/preferences.c new/source/preferences.c
153 --- old/source/preferences.c
154 +++ new/source/preferences.c
155 @@ -112,6 +112,9 @@ static const char CVSID[] = "$Id: prefer
156 /* maximum number of file extensions allowed in a language mode */
157 #define MAX_FILE_EXTENSIONS 20
159 +/* maximum size of color string */
160 +#define MAX_COLOR_LENGTH 256
162 /* Return values for checkFontStatus */
163 enum fontStatus {GOOD_FONT, BAD_PRIMARY, BAD_FONT, BAD_SIZE, BAD_SPACING};
165 @@ -355,6 +358,17 @@ static struct prefData {
166 Boolean showScrolltip;
169 + /* Color of modified, readonly, and normal menu items for the filenames
170 + * in the window menu*/
171 + int coloredWinMenu;
172 + char modMenuColor[MAX_COLOR_LENGTH];
173 + int modMenuColorLength;
174 + char roMenuColor[MAX_COLOR_LENGTH];
175 + int roMenuColorLength;
176 + char defMenuColor[MAX_COLOR_LENGTH];
177 + int defMenuColorLength;
178 + char bgMenuColor[MAX_COLOR_LENGTH];
179 + int bgMenuColorLength;
182 /* Temporary storage for preferences strings which are discarded after being
183 @@ -1189,6 +1203,16 @@ static PrefDescripRec PrefDescrip[] = {
184 &PrefData.hardlinkMode, HardlinkModes, True},
185 {"zeroSizedMode", "ZeroSizedMode", PREF_ENUM, "Never",
186 &PrefData.zeroSizedMode, ZeroSizedModes, True},
187 + {"coloredWinMenu", "ColoredWinMenu", PREF_BOOLEAN, "True",
188 + &PrefData.coloredWinMenu, NULL, False},
189 + {"modifiedWinMenuColor", "ModifiedWinMenuColor", PREF_STRING, "red",
190 + PrefData.modMenuColor, (void *)sizeof(PrefData.modMenuColor), False},
191 + {"readOnlyWinMenuColor", "ReadOnlyWinMenuColor", PREF_STRING, "blue",
192 + PrefData.roMenuColor, (void *)sizeof(PrefData.roMenuColor), False},
193 + {"defaultWinMenuColor", "DefaultWinMenuColor", PREF_STRING, "black",
194 + PrefData.defMenuColor, (void *)sizeof(PrefData.defMenuColor), False},
195 + {"backgroundWinMenuColor", "BackgroundWinMenuColor", PREF_STRING, "white",
196 + PrefData.bgMenuColor, (void *)sizeof(PrefData.bgMenuColor), False},
199 static XrmOptionDescRec OpTable[] = {
200 @@ -1552,6 +1576,12 @@ static void translatePrefFormats(int con
201 if (PrefData.autoIndent == 3) PrefData.autoIndent = AUTO_INDENT;
202 if (PrefData.autoIndent == 4) PrefData.autoIndent = NO_AUTO_INDENT;
204 + /* For efficiency, precalculate the lengths of window menu colors */
205 + SetPrefModMenuColorLength(PrefData.modMenuColor);
206 + SetPrefRoMenuColorLength(PrefData.roMenuColor);
207 + SetPrefDefMenuColorLength(PrefData.defMenuColor);
208 + SetPrefBgMenuColorLength(PrefData.bgMenuColor);
210 /* setup language mode dependent info of user menus (to increase
211 performance when switching between documents of different
213 @@ -2308,6 +2338,55 @@ Boolean GetPrefHonorSymlinks(void)
214 return PrefData.honorSymlinks;
217 +int GetPrefColoredWinMenu(void)
219 + return PrefData.coloredWinMenu;
222 +const char *GetPrefModMenuColor(int* length)
224 + *length = PrefData.modMenuColorLength;
225 + return PrefData.modMenuColor;
228 +void SetPrefModMenuColorLength(const char* string)
230 + PrefData.modMenuColorLength = strlen(string);
233 +const char *GetPrefRoMenuColor(int* length)
235 + *length = PrefData.roMenuColorLength;
236 + return PrefData.roMenuColor;
239 +void SetPrefRoMenuColorLength(const char* string)
241 + PrefData.roMenuColorLength = strlen(string);
244 +const char *GetPrefDefMenuColor(int* length)
246 + *length = PrefData.defMenuColorLength;
247 + return PrefData.defMenuColor;
250 +void SetPrefDefMenuColorLength(const char* string)
252 + PrefData.defMenuColorLength = strlen(string);
255 +const char *GetPrefBgMenuColor(int* length)
257 + *length = PrefData.bgMenuColorLength;
258 + return PrefData.bgMenuColor;
261 +void SetPrefBgMenuColorLength(const char* string)
263 + PrefData.bgMenuColorLength = strlen(string);
266 int GetPrefOverrideVirtKeyBindings(void)
268 return PrefData.virtKeyOverride;
269 diff --quilt old/source/preferences.h new/source/preferences.h
270 --- old/source/preferences.h
271 +++ new/source/preferences.h
272 @@ -194,6 +194,15 @@ Widget CreateLanguageModeMenu(Widget par
273 void SetLangModeMenu(Widget optMenu, const char *modeName);
274 void CreateLanguageModeSubMenu(WindowInfo* window, const Widget parent,
275 const char* name, const char* label, const char mnemonic);
276 +int GetPrefColoredWinMenu(void);
277 +const char *GetPrefModMenuColor(int* length);
278 +void SetPrefModMenuColorLength(const char* string);
279 +const char *GetPrefRoMenuColor(int* length);
280 +void SetPrefRoMenuColorLength(const char* string);
281 +const char *GetPrefDefMenuColor(int* length);
282 +void SetPrefDefMenuColorLength(const char* string);
283 +const char *GetPrefBgMenuColor(int* length);
284 +void SetPrefBgMenuColorLength(const char* string);
285 void SetPrefFindReplaceUsesSelection(int state);
286 int GetPrefFindReplaceUsesSelection(void);
287 int GetPrefStickyCaseSenseBtn(void);