core-typeof-syntax: push up
[nedit-bw.git] / remove_zero_sized_files.patch
blobcdfd749391c271589297ee41486d8e949b4546e7
1 If a window will be closed, check the file size and never/prompt/always
2 remove the file if the size is 0.
4 ---
6 doc/help.etx | 3 +++
7 source/file.c | 30 ++++++++++++++++++++++++++++++
8 source/menu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++
9 source/nedit.h | 4 ++++
10 source/preferences.c | 22 +++++++++++++++++++++-
11 source/preferences.h | 2 ++
12 6 files changed, 108 insertions(+), 1 deletion(-)
14 diff --quilt old/source/file.c new/source/file.c
15 --- old/source/file.c
16 +++ new/source/file.c
17 @@ -887,10 +887,37 @@ int CloseAllFilesAndWindows(void)
20 return TRUE;
23 +static void removeZeroSizedFile(WindowInfo *window)
25 + int response;
26 + struct stat statbuf;
27 + char fullname[MAXPATHLEN + 1];
29 + /* Get the full name of the file */
30 + strcpy(fullname, window->path);
31 + strcat(fullname, window->filename);
33 + if (GetPrefZeroSizedMode() == ZEROSIZED_NEVER)
34 + return;
36 + if (stat(fullname, &statbuf) == 0
37 + && statbuf.st_size == 0
38 + && !S_ISFIFO(statbuf.st_mode)) {
39 + if (GetPrefZeroSizedMode() == ZEROSIZED_PROMPT) {
40 + response = DialogF(DF_QUES, window->shell, 2, "Zero Sized File",
41 + "%s has a file size of 0.\nDo you want to remove this file?",
42 + "Yes", "No", fullname);
43 + if (response == 2)
44 + return;
45 + }
46 + remove(fullname);
47 + }
50 int CloseFileAndWindow(WindowInfo *window, int preResponse)
52 int response, stat;
54 /* Make sure that the window is not in iconified state */
55 @@ -907,10 +934,11 @@ int CloseFileAndWindow(WindowInfo *windo
56 /* New document, unchanged yet */
57 || (window->fileMissing && window->lastModTime == 0)
58 /* File deleted/modified externally, ignored by user. */
59 || !GetPrefWarnFileMods())))
61 + removeZeroSizedFile(window);
62 RemoveBackupFile(window);
63 CloseWindow(window);
64 /* up-to-date windows don't have outstanding backup files to close */
65 } else
67 @@ -927,17 +955,19 @@ int CloseFileAndWindow(WindowInfo *windo
69 /* Save */
70 stat = SaveWindow(window);
71 if (stat)
73 + removeZeroSizedFile(window);
74 CloseWindow(window);
75 } else
77 return FALSE;
79 } else if (response == NO_SBC_DIALOG_RESPONSE)
81 + removeZeroSizedFile(window);
82 /* Don't Save */
83 RemoveBackupFile(window);
84 CloseWindow(window);
85 } else /* 3 == Cancel */
87 diff --quilt old/source/menu.c new/source/menu.c
88 --- old/source/menu.c
89 +++ new/source/menu.c
90 @@ -142,10 +142,13 @@ static void smartIndentDefCB(Widget w, W
91 static void autoSaveDefCB(Widget w, WindowInfo *window, caddr_t callData);
92 static void preserveDefCB(Widget w, WindowInfo *window, caddr_t callData);
93 static void ignoreHardlinkDefCB(Widget w, WindowInfo *window, caddr_t callData);
94 static void promptHardlinkDefCB(Widget w, WindowInfo *window, caddr_t callData);
95 static void unlinkHardlinkDefCB(Widget w, WindowInfo *window, caddr_t callData);
96 +static void neverZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData);
97 +static void promptZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData);
98 +static void alwaysZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData);
99 static void noWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
100 static void newlineWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
101 static void contWrapDefCB(Widget w, WindowInfo *window, caddr_t callData);
102 static void wrapMarginDefCB(Widget w, WindowInfo *window, caddr_t callData);
103 static void shellSelDefCB(Widget widget, WindowInfo* window, caddr_t callData);
104 @@ -1035,10 +1038,23 @@ Widget CreateMenuBar(Widget parent, Wind
105 GetPrefHardlinkMode() == HARDLINK_PROMPT, SHORT);
106 window->hardlinkDefItem[HARDLINK_UNLINK] = createMenuRadioToggle(
107 subSubPane, "unlink", "Unlink", 'U', unlinkHardlinkDefCB, window,
108 GetPrefHardlinkMode() == HARDLINK_UNLINK, SHORT);
110 + /* zero sized mode default sub menu */
111 + subSubPane = createMenu(subPane, "zeroSizedMode", "Remove Zero Sized Files", 'Z',
112 + NULL, FULL);
113 + window->zeroSizedDefItem[ZEROSIZED_NEVER] = createMenuRadioToggle(
114 + subSubPane, "never", "Never", 'N', neverZeroSizedDefCB, window,
115 + GetPrefZeroSizedMode() == ZEROSIZED_NEVER, SHORT);
116 + window->zeroSizedDefItem[ZEROSIZED_PROMPT] = createMenuRadioToggle(
117 + subSubPane, "prompt", "Prompt", 'P', promptZeroSizedDefCB, window,
118 + GetPrefZeroSizedMode() == ZEROSIZED_PROMPT, SHORT);
119 + window->zeroSizedDefItem[ZEROSIZED_ALWAYS] = createMenuRadioToggle(
120 + subSubPane, "always", "Always", 'A', alwaysZeroSizedDefCB, window,
121 + GetPrefZeroSizedMode() == ZEROSIZED_ALWAYS, SHORT);
123 /* Show Matching sub menu */
124 subSubPane = createMenu(subPane, "showMatching", "Show Matching (..)", 'M',
125 NULL, FULL);
126 window->showMatchingOffDefItem = createMenuRadioToggle(subSubPane, "off",
127 "Off", 'O', showMatchingOffDefCB, window,
128 @@ -1915,10 +1931,42 @@ static void promptHardlinkDefCB(Widget w
129 static void unlinkHardlinkDefCB(Widget w, WindowInfo *window, caddr_t callData)
131 setHardlinkModeMenu(HARDLINK_UNLINK);
134 +static void setZeroSizedModeMenu(enum zeroSizedMode mode)
136 + WindowInfo *win;
137 + int i;
139 + if (mode >= N_ZEROSIZED_MODES)
140 + return;
142 + /* Set the preference and make the other windows' menus agree */
143 + SetPrefZeroSizedMode(mode);
144 + for (win = WindowList; win != NULL; win = win->next) {
145 + for (i = 0; i < N_ZEROSIZED_MODES; i++)
146 + XmToggleButtonSetState(win->zeroSizedDefItem[i],
147 + mode == i ? True : False, False);
151 +static void neverZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData)
153 + setZeroSizedModeMenu(ZEROSIZED_NEVER);
156 +static void promptZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData)
158 + setZeroSizedModeMenu(ZEROSIZED_PROMPT);
161 +static void alwaysZeroSizedDefCB(Widget w, WindowInfo *window, caddr_t callData)
163 + setZeroSizedModeMenu(ZEROSIZED_ALWAYS);
166 static void fontDefCB(Widget w, WindowInfo *window, caddr_t callData)
168 HidePointerOnKeyedEvent(WidgetToWindow(MENU_WIDGET(w))->lastFocus,
169 ((XmAnyCallbackStruct *)callData)->event);
170 ChooseFonts(WidgetToWindow(MENU_WIDGET(w)), False);
171 diff --quilt old/source/nedit.h new/source/nedit.h
172 --- old/source/nedit.h
173 +++ new/source/nedit.h
174 @@ -114,10 +114,13 @@ enum showWrapMarginEnums {SHOW_WRAP_MARG
175 enum truncSubstitution {TRUNCSUBST_SILENT, TRUNCSUBST_FAIL, TRUNCSUBST_WARN, TRUNCSUBST_IGNORE};
177 /* This enum must be kept in sync with HardlinkModes[] in in preferences.c */
178 enum hardlinkMode {HARDLINK_IGNORE, HARDLINK_PROMPT, HARDLINK_UNLINK, N_HARDLINK_MODES};
180 +/* This enum must be kept in sync with ZeroSizedModes[] in in preferences.c */
181 +enum zeroSizedMode {ZEROSIZED_NEVER = 0, ZEROSIZED_PROMPT, ZEROSIZED_ALWAYS, N_ZEROSIZED_MODES};
183 #define NO_FLASH_STRING "off"
184 #define FLASH_DELIMIT_STRING "delimiter"
185 #define FLASH_RANGE_STRING "range"
187 #define CHARSET (XmStringCharSet)XmSTRING_DEFAULT_CHARSET
188 @@ -574,10 +577,11 @@ typedef struct _WindowInfo {
189 has its own background menu. */
190 Boolean transient;
191 Boolean inMacroHook; /* to protect GC */
192 Widget hardlinkDefItem[N_HARDLINK_MODES];
193 Bool HLdontpromptagain;
194 + Widget zeroSizedDefItem[N_ZEROSIZED_MODES];
195 } WindowInfo;
197 extern WindowInfo *WindowList;
198 extern Display *TheDisplay;
199 extern Widget TheAppShell;
200 diff --quilt old/source/preferences.c new/source/preferences.c
201 --- old/source/preferences.c
202 +++ new/source/preferences.c
203 @@ -173,10 +173,17 @@ static char *HardlinkModes[] = {
204 "Prompt",
205 "Unlink",
206 NULL
209 +static char *ZeroSizedModes[] = {
210 + "Never",
211 + "Prompt",
212 + "Always",
213 + NULL
216 /* list of available language modes and language specific preferences */
217 static int NLanguageModes = 0;
218 typedef struct {
219 char *name;
220 int nExtensions;
221 @@ -345,10 +352,11 @@ static struct prefData {
222 Boolean showScrolltip;
223 Boolean honorSymlinks;
224 int truncSubstitution;
225 Boolean forceOSConversion;
226 int hardlinkMode;
227 + int zeroSizedMode;
228 } PrefData;
230 /* Temporary storage for preferences strings which are discarded after being
231 read */
232 static struct {
233 @@ -1178,11 +1186,13 @@ static PrefDescripRec PrefDescrip[] = {
234 {"showScrolltip", "ShowScrolltip", PREF_BOOLEAN, "True",
235 &PrefData.showScrolltip, NULL, False},
236 {"honorSymlinks", "HonorSymlinks", PREF_BOOLEAN, "True",
237 &PrefData.honorSymlinks, NULL, False},
238 {"hardlinkMode", "HardlinkMode", PREF_ENUM, "Ignore",
239 - &PrefData.hardlinkMode, HardlinkModes, True}
240 + &PrefData.hardlinkMode, HardlinkModes, True},
241 + {"zeroSizedMode", "ZeroSizedMode", PREF_ENUM, "Never",
242 + &PrefData.zeroSizedMode, ZeroSizedModes, True}
245 static XrmOptionDescRec OpTable[] = {
246 {"-wrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"Continuous"},
247 {"-nowrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"None"},
248 @@ -2348,10 +2358,20 @@ int GetPrefHardlinkMode(void)
249 void SetPrefHardlinkMode(int mode)
251 setIntPref(&PrefData.hardlinkMode, mode);
254 +int GetPrefZeroSizedMode(void)
256 + return PrefData.zeroSizedMode;
259 +void SetPrefZeroSizedMode(int mode)
261 + setIntPref(&PrefData.zeroSizedMode, mode);
265 ** If preferences don't get saved, ask the user on exit whether to save
267 void MarkPrefsChanged(void)
269 diff --quilt old/source/preferences.h new/source/preferences.h
270 --- old/source/preferences.h
271 +++ new/source/preferences.h
272 @@ -217,7 +217,9 @@ void SetPrefFocusOnRaise(Boolean);
273 void SetPrefShowCursorline(Boolean value);
274 Boolean GetPrefShowCursorline(void);
275 Boolean GetPrefShowScrolltip(void);
276 int GetPrefHardlinkMode(void);
277 void SetPrefHardlinkMode(int mode);
278 +int GetPrefZeroSizedMode(void);
279 +void SetPrefZeroSizedMode(int mode);
281 #endif /* NEDIT_PREFERENCES_H_INCLUDED */
282 diff --quilt old/doc/help.etx new/doc/help.etx
283 --- old/doc/help.etx
284 +++ new/doc/help.etx
285 @@ -4131,10 +4131,13 @@ Preferences
286 name but a new destine file or ignore it.
288 ~Unlink~
289 Always make a destine copy of the file.
291 +**Remove Zero Sized Files**
292 + NEdit can delete files after close, that have a size of 0.
294 **Show Hidden Files**
295 Show hidden files by default in file selection boxes.
297 **Show Cursorline**
298 Background the current line with a colored bar.