import shell in help output
[nedit-bw.git] / remove_zero_sized_files.patch
blob60c5ea2ac7fc29e3c91ed1fd4c5bdd1539a19e39
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 | 5 +++++
10 source/preferences.c | 20 ++++++++++++++++++++
11 source/preferences.h | 2 ++
12 6 files changed, 108 insertions(+)
14 diff --quilt old/source/file.c new/source/file.c
15 --- old/source/file.c
16 +++ new/source/file.c
17 @@ -896,10 +896,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 @@ -919,10 +946,11 @@ int CloseFileAndWindow(WindowInfo *windo
56 /* New File*/
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 @@ -939,17 +967,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 @@ -1032,10 +1035,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 @@ -1909,10 +1925,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 @@ -115,10 +115,14 @@ enum truncSubstitution {TRUNCSUBST_SILEN
176 /* This enum must be kept in sync with HardlinkModes[] in in preferences.c */
177 enum hardlinkMode {HARDLINK_IGNORE, HARDLINK_PROMPT, HARDLINK_UNLINK,
178 N_HARDLINK_MODES};
180 +/* This enum must be kept in sync with ZeroSizedModes[] in in preferences.c */
181 +enum zeroSizedMode {ZEROSIZED_NEVER, ZEROSIZED_PROMPT, ZEROSIZED_ALWAYS,
182 + N_ZEROSIZED_MODES};
184 #define NO_FLASH_STRING "off"
185 #define FLASH_DELIMIT_STRING "delimiter"
186 #define FLASH_RANGE_STRING "range"
188 #define CHARSET (XmStringCharSet)XmSTRING_DEFAULT_CHARSET
189 @@ -574,10 +578,11 @@ typedef struct _WindowInfo {
190 "tabbed" documents, while each document
191 has its own background menu. */
192 int inMacroHook; /* to protect GC in MacroApplyHook() */
193 Widget hardlinkDefItem[N_HARDLINK_MODES];
194 Boolean hardlinkDontPromptAgain;
195 + Widget zeroSizedDefItem[N_ZEROSIZED_MODES];
196 } WindowInfo;
198 extern WindowInfo *WindowList;
199 extern Display *TheDisplay;
200 extern Widget TheAppShell;
201 diff --quilt old/source/preferences.c new/source/preferences.c
202 --- old/source/preferences.c
203 +++ new/source/preferences.c
204 @@ -174,10 +174,17 @@ static char *HardlinkModes[] = {
205 "Prompt",
206 "Unlink",
207 NULL
210 +static char *ZeroSizedModes[] = {
211 + "Never",
212 + "Prompt",
213 + "Always",
214 + NULL
217 /* list of available language modes and language specific preferences */
218 static int NLanguageModes = 0;
219 typedef struct {
220 char *name;
221 int nExtensions;
222 @@ -345,10 +352,11 @@ static struct prefData {
223 Boolean honorSymlinks;
224 int truncSubstitution;
225 Boolean forceOSConversion;
226 Boolean showScrolltip;
227 int hardlinkMode;
228 + int zeroSizedMode;
229 } PrefData;
231 /* Temporary storage for preferences strings which are discarded after being
232 read */
233 static struct {
234 @@ -1177,10 +1185,12 @@ static PrefDescripRec PrefDescrip[] = {
235 &PrefData.showCursorline, NULL, True},
236 // {"showScrolltip", "ShowScrolltip", PREF_BOOLEAN, "True",
237 // &PrefData.showScrolltip, NULL, False},
238 {"hardlinkMode", "HardlinkMode", PREF_ENUM, "Ignore",
239 &PrefData.hardlinkMode, HardlinkModes, True},
240 + {"zeroSizedMode", "ZeroSizedMode", PREF_ENUM, "Never",
241 + &PrefData.zeroSizedMode, ZeroSizedModes, True},
244 static XrmOptionDescRec OpTable[] = {
245 {"-wrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"Continuous"},
246 {"-nowrap", ".autoWrap", XrmoptionNoArg, (caddr_t)"None"},
247 @@ -2332,10 +2342,20 @@ void SetPrefHardlinkMode(int mode)
248 int GetPrefHardlinkMode(void)
250 return PrefData.hardlinkMode;
253 +void SetPrefZeroSizedMode(int mode)
255 + setIntPref(&PrefData.zeroSizedMode, mode);
258 +int GetPrefZeroSizedMode(void)
260 + return PrefData.zeroSizedMode;
264 ** If preferences don't get saved, ask the user on exit whether to save
266 void MarkPrefsChanged(void)
268 diff --quilt old/source/preferences.h new/source/preferences.h
269 --- old/source/preferences.h
270 +++ new/source/preferences.h
271 @@ -216,7 +216,9 @@ Boolean GetPrefHonorSymlinks(void);
272 Boolean GetPrefForceOSConversion(void);
273 void SetPrefFocusOnRaise(Boolean);
274 Boolean GetPrefShowScrolltip(void);
275 void SetPrefHardlinkMode(int mode);
276 int GetPrefHardlinkMode(void);
277 +void SetPrefZeroSizedMode(int mode);
278 +int GetPrefZeroSizedMode(void);
280 #endif /* NEDIT_PREFERENCES_H_INCLUDED */
281 diff --quilt old/doc/help.etx new/doc/help.etx
282 --- old/doc/help.etx
283 +++ new/doc/help.etx
284 @@ -4128,10 +4128,13 @@ Preferences
285 name but a new destine file or ignore it.
287 ~Unlink~
288 Always make a destine copy of the file.
290 +**Remove Zero Sized Files**
291 + NEdit can delete files after close, that have a size of 0.
293 **Show Cursorline**
294 Background the current line with a colored bar. Use the color dialog to
295 change the background color.
297 **Terminate with Line Break on Save**