shell_command-make-input-parameter-optional.patch: add changes to help.etx
[nedit-bw.git] / ColoredWinMenu.diff
blob5093b9d001d257c824251e818e032531af7dbd20
1 Add coloring to the windows menu to indicate modified buffers
3 This is a modified version of Arne Førlie's patch:
5 http://sourceforge.net/tracker/index.php?func=detail&aid=937063&group_id=11005&atid=311005
6 [ 937063 ] Coloured file names in Windows menu
7 89330: colored_win _v2.patch 2004-06-02 16:17
9 This patch color-codes the file names in the windows
10 menu according to state.
11 By default the patch uses the following colours
12 - modified (unsaved) files are red
13 - read-only files are blue
14 - otherwise they are black
16 For modified and read-only, you can also change the background
17 color used; this is normally set to "white"; set it to "default"
18 to use the normal menu background color.
20 A set of X resources are used to modify the defaults.
21 They are documented in the help (do 'make docs' to
22 update the help files before building the executables).
23 nedit.coloredWinMenu: True
24 nedit.defaultWinMenuColor: black
25 nedit.modifiedWinMenuColor: red
26 nedit.readOnlyWinMenuColor: blue
27 nedit.backgroundWinMenuColor: white
29 2006-08-14, ...
31 Updated to be synchronised with CVS head.
33 2007-06-12
35 Added new resource backgroundWinMenuColor
37 2007-07-02
39 Removed irrelevant help info (thanks to Bert Wesarg)
41 ---
43 doc/help.etx | 26 ++++++++++++++++
44 source/menu.c | 39 ++++++++++++++++++++++++
45 source/preferences.c | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++-
46 source/preferences.h | 9 +++++
47 4 files changed, 154 insertions(+), 1 deletion(-)
49 diff --quilt old/doc/help.etx new/doc/help.etx
50 --- old/doc/help.etx
51 +++ new/doc/help.etx
52 @@ -4442,10 +4442,36 @@ X Resources
53 expression searches. Moreover, when set to True, by default literal searches
54 are case insensitive and regular expression searches are case sensitive. When
55 set to False, the "Case Sensitive" buttons are independent of the "Regular
56 Expression" toggle.
58 +**nedit.coloredWinMenu**: True
60 + Controls if the Windows menu shall use colors to code the file's status.
62 + If above resource is set to True, the following five resources can be used
63 + to define the colors to use. For all three cases a color value of "default"
64 + can be used to specify that the default color as specified by the window
65 + manager shall be used.
67 +**nedit.defaultWinMenuColor**: black
69 + Defines the default color of files in the Windows menu.
71 +**nedit.modifiedWinMenuColor**: red
73 + Defines the color of modified (unsaved) files in the Windows menu.
75 +**nedit.readOnlyWinMenuColor**: blue
77 + Defines the color of read-only files in the Windows menu.
79 +**nedit.backgroundWinMenuColor**: white
81 + Defines the color of the background used for colored Windows menu items
82 + when using either the modified or read-only foreground color.
84 **nedit.multiClickTime**: (system specific)
86 Maximum time in milliseconds allowed between mouse clicks within double and
87 triple click actions.
89 diff --quilt old/source/menu.c new/source/menu.c
90 --- old/source/menu.c
91 +++ new/source/menu.c
92 @@ -4831,10 +4831,46 @@ void AddToPrevOpenMenu(const char *filen
94 /* Write the menu contents to disk to restore in later sessions */
95 WriteNEditDB();
98 +static void colorWindowMenuEntries(const WindowInfo* window, Widget widget)
100 + if (GetPrefColoredWinMenu() == True)
102 + Pixel oldFg, oldBg;
103 + const char* bgcolor = "default";
104 + int bgcolorLength = 7;
105 + const char* color;
106 + int colorLength;
107 + if (IS_ANY_LOCKED(window->lockReasons)) {
108 + color = GetPrefRoMenuColor(&colorLength);
109 + bgcolor = GetPrefBgMenuColor(&bgcolorLength);
111 + else if (window->fileChanged == TRUE) {
112 + color = GetPrefModMenuColor(&colorLength);
113 + bgcolor = GetPrefBgMenuColor(&bgcolorLength);
115 + else {
116 + color = GetPrefDefMenuColor(&colorLength);
117 + /* leave background for the default color alone */
119 + XtVaGetValues(XtParent(widget), XmNforeground, &oldFg,
120 + XmNbackground, &oldBg, NULL);
121 + if (strcmp(color, "default") != 0) {
122 + XtVaSetValues(widget, XtVaTypedArg, XmNforeground, XmRString, color, colorLength + 1, NULL);
123 + } else {
124 + XtVaSetValues(widget, XmNforeground, oldFg, NULL);
126 + if (strcmp(bgcolor, "default") != 0) {
127 + XtVaSetValues(widget, XtVaTypedArg, XmNbackground, XmRString, bgcolor, bgcolorLength + 1, NULL);
128 + } else {
129 + XtVaSetValues(widget, XmNbackground, oldBg, NULL);
134 static char *getWindowsMenuEntry(const WindowInfo *window)
136 static char fullTitle[MAXPATHLEN * 2 + 4 + 1];
138 sprintf(fullTitle, "%s%s", window->filename,
139 @@ -4902,10 +4938,11 @@ static void updateWindowMenu(const Windo
140 } else {
141 XmString st1;
142 char* title = getWindowsMenuEntry(windows[windowIndex]);
143 XtVaSetValues(items[n], XmNlabelString,
144 st1=XmStringCreateSimple(title), NULL);
145 + colorWindowMenuEntries(windows[windowIndex], items[n]);
146 XtRemoveAllCallbacks(items[n], XmNactivateCallback);
147 XtAddCallback(items[n], XmNactivateCallback,
148 (XtCallbackProc)raiseCB, windows[windowIndex]);
149 XmStringFree(st1);
150 windowIndex++;
151 @@ -4920,10 +4957,12 @@ static void updateWindowMenu(const Windo
152 Widget btn = XtVaCreateManagedWidget("win", xmPushButtonWidgetClass,
153 window->windowMenuPane,
154 XmNlabelString, st1=XmStringCreateSimple(title),
155 XmNmarginHeight, 0,
156 XmNuserData, TEMPORARY_MENU_ITEM, NULL);
158 + colorWindowMenuEntries(windows[windowIndex], btn);
159 XtAddCallback(btn, XmNactivateCallback, (XtCallbackProc)raiseCB,
160 windows[windowIndex]);
161 XmStringFree(st1);
163 XtFree((char *)windows);
164 diff --quilt old/source/preferences.c new/source/preferences.c
165 --- old/source/preferences.c
166 +++ new/source/preferences.c
167 @@ -110,10 +110,13 @@ static const char CVSID[] = "$Id: prefer
168 #define MAX_WORD_DELIMITERS 256
170 /* maximum number of file extensions allowed in a language mode */
171 #define MAX_FILE_EXTENSIONS 20
173 +/* maximum size of color string */
174 +#define MAX_COLOR_LENGTH 256
176 /* Return values for checkFontStatus */
177 enum fontStatus {GOOD_FONT, BAD_PRIMARY, BAD_FONT, BAD_SIZE, BAD_SPACING};
179 /* enumerated type preference strings
180 ** The order of the elements in this array must be exactly the same
181 @@ -353,10 +356,21 @@ static struct prefData {
182 Boolean honorSymlinks;
183 int truncSubstitution;
184 Boolean forceOSConversion;
185 int hardlinkMode;
186 int zeroSizedMode;
187 + /* Color of modified, readonly, and normal menu items for the filenames
188 + * in the window menu*/
189 + int coloredWinMenu;
190 + char modMenuColor[MAX_COLOR_LENGTH];
191 + int modMenuColorLength;
192 + char roMenuColor[MAX_COLOR_LENGTH];
193 + int roMenuColorLength;
194 + char defMenuColor[MAX_COLOR_LENGTH];
195 + int defMenuColorLength;
196 + char bgMenuColor[MAX_COLOR_LENGTH];
197 + int bgMenuColorLength;
198 } PrefData;
200 /* Temporary storage for preferences strings which are discarded after being
201 read */
202 static struct {
203 @@ -1188,11 +1202,21 @@ static PrefDescripRec PrefDescrip[] = {
204 {"honorSymlinks", "HonorSymlinks", PREF_BOOLEAN, "True",
205 &PrefData.honorSymlinks, NULL, False},
206 {"hardlinkMode", "HardlinkMode", PREF_ENUM, "Ignore",
207 &PrefData.hardlinkMode, HardlinkModes, True},
208 {"zeroSizedMode", "ZeroSizedMode", PREF_ENUM, "Never",
209 - &PrefData.zeroSizedMode, ZeroSizedModes, True}
210 + &PrefData.zeroSizedMode, ZeroSizedModes, True},
211 + {"coloredWinMenu", "ColoredWinMenu", PREF_BOOLEAN, "True",
212 + &PrefData.coloredWinMenu, NULL, False},
213 + {"modifiedWinMenuColor", "ModifiedWinMenuColor", PREF_STRING, "red",
214 + PrefData.modMenuColor, (void *)sizeof(PrefData.modMenuColor), False},
215 + {"readOnlyWinMenuColor", "ReadOnlyWinMenuColor", PREF_STRING, "blue",
216 + PrefData.roMenuColor, (void *)sizeof(PrefData.roMenuColor), False},
217 + {"defaultWinMenuColor", "DefaultWinMenuColor", PREF_STRING, "black",
218 + PrefData.defMenuColor, (void *)sizeof(PrefData.defMenuColor), False},
219 + {"backgroundWinMenuColor", "BackgroundWinMenuColor", PREF_STRING, "white",
220 + PrefData.bgMenuColor, (void *)sizeof(PrefData.bgMenuColor), False},
223 static XrmOptionDescRec OpTable[] = {
224 {"-wrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"Continuous"},
225 {"-nowrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"None"},
226 @@ -1557,10 +1581,16 @@ static void translatePrefFormats(int con
227 if (PrefData.wrapStyle == 3) PrefData.wrapStyle = CONTINUOUS_WRAP;
228 if (PrefData.wrapStyle == 4) PrefData.wrapStyle = NO_WRAP;
229 if (PrefData.autoIndent == 3) PrefData.autoIndent = AUTO_INDENT;
230 if (PrefData.autoIndent == 4) PrefData.autoIndent = NO_AUTO_INDENT;
232 + /* For efficiency, precalculate the lengths of window menu colors */
233 + SetPrefModMenuColorLength(PrefData.modMenuColor);
234 + SetPrefRoMenuColorLength(PrefData.roMenuColor);
235 + SetPrefDefMenuColorLength(PrefData.defMenuColor);
236 + SetPrefBgMenuColorLength(PrefData.bgMenuColor);
238 /* setup language mode dependent info of user menus (to increase
239 performance when switching between documents of different
240 language modes) */
241 SetupUserMenuInfo();
243 @@ -2323,10 +2353,59 @@ Boolean GetPrefForceOSConversion(void)
244 Boolean GetPrefHonorSymlinks(void)
246 return PrefData.honorSymlinks;
249 +int GetPrefColoredWinMenu(void)
251 + return PrefData.coloredWinMenu;
254 +const char *GetPrefModMenuColor(int* length)
256 + *length = PrefData.modMenuColorLength;
257 + return PrefData.modMenuColor;
260 +void SetPrefModMenuColorLength(const char* string)
262 + PrefData.modMenuColorLength = strlen(string);
265 +const char *GetPrefRoMenuColor(int* length)
267 + *length = PrefData.roMenuColorLength;
268 + return PrefData.roMenuColor;
271 +void SetPrefRoMenuColorLength(const char* string)
273 + PrefData.roMenuColorLength = strlen(string);
276 +const char *GetPrefDefMenuColor(int* length)
278 + *length = PrefData.defMenuColorLength;
279 + return PrefData.defMenuColor;
282 +void SetPrefDefMenuColorLength(const char* string)
284 + PrefData.defMenuColorLength = strlen(string);
287 +const char *GetPrefBgMenuColor(int* length)
289 + *length = PrefData.bgMenuColorLength;
290 + return PrefData.bgMenuColor;
293 +void SetPrefBgMenuColorLength(const char* string)
295 + PrefData.bgMenuColorLength = strlen(string);
298 int GetPrefOverrideVirtKeyBindings(void)
300 return PrefData.virtKeyOverride;
303 diff --quilt old/source/preferences.h new/source/preferences.h
304 --- old/source/preferences.h
305 +++ new/source/preferences.h
306 @@ -191,10 +191,19 @@ void DetermineLanguageMode(WindowInfo *w
307 Widget CreateLanguageModeMenu(Widget parent, XtCallbackProc cbProc,
308 void *cbArg, int includePlain);
309 void SetLangModeMenu(Widget optMenu, const char *modeName);
310 void CreateLanguageModeSubMenu(WindowInfo* window, const Widget parent,
311 const char* name, const char* label, const char mnemonic);
312 +int GetPrefColoredWinMenu(void);
313 +const char *GetPrefModMenuColor(int* length);
314 +void SetPrefModMenuColorLength(const char* string);
315 +const char *GetPrefRoMenuColor(int* length);
316 +void SetPrefRoMenuColorLength(const char* string);
317 +const char *GetPrefDefMenuColor(int* length);
318 +void SetPrefDefMenuColorLength(const char* string);
319 +const char *GetPrefBgMenuColor(int* length);
320 +void SetPrefBgMenuColorLength(const char* string);
321 void SetPrefFindReplaceUsesSelection(int state);
322 int GetPrefFindReplaceUsesSelection(void);
323 int GetPrefStickyCaseSenseBtn(void);
324 void SetPrefBeepOnSearchWrap(int state);
325 int GetPrefBeepOnSearchWrap(void);