nsxiv284be74
Count number of marked files
+11 −3
2 files changed
- M commands.c +7 −3
- M main.c +4 −0
| @@ -50,6 +50,7 @@ extern win_t win; | |||
| 50 | 50 | extern fileinfo_t *files; | |
| 51 | 51 | extern int filecnt, fileidx; | |
| 52 | 52 | extern int alternate; | |
| 53 | + | extern int markcnt; | |
| 53 | 54 | ||
| 54 | 55 | extern int prefix; | |
| 55 | 56 | extern bool extprefix; | |
| @@ -62,7 +63,7 @@ bool cg_quit(arg_t a) | |||
| 62 | 63 | { | |
| 63 | 64 | unsigned int i; | |
| 64 | 65 | ||
| 65 | − | if (options->to_stdout) { | |
| 66 | + | if (options->to_stdout && markcnt > 0) { | |
| 66 | 67 | for (i = 0; i < filecnt; i++) { | |
| 67 | 68 | if (files[i].marked) | |
| 68 | 69 | printf("%s\n", files[i].name); | |
| @@ -195,6 +196,7 @@ bool cg_scroll_screen(arg_t a) | |||
| 195 | 196 | bool cg_toggle_image_mark(arg_t a) | |
| 196 | 197 | { | |
| 197 | 198 | files[fileidx].marked = !files[fileidx].marked; | |
| 199 | + | markcnt += files[fileidx].marked ? 1 : -1; | |
| 198 | 200 | if (mode == MODE_THUMB) | |
| 199 | 201 | tns_mark(&tns, fileidx, files[fileidx].marked); | |
| 200 | 202 | return true; | |
| @@ -202,10 +204,12 @@ bool cg_toggle_image_mark(arg_t a) | |||
| 202 | 204 | ||
| 203 | 205 | bool cg_reverse_marks(arg_t a) | |
| 204 | 206 | { | |
| 205 | − | int i, cnt = mode == MODE_IMAGE ? filecnt : tns.cnt; | |
| 207 | + | int i; | |
| 206 | 208 | ||
| 207 | − | for (i = 0; i < cnt; i++) | |
| 209 | + | for (i = 0; i < filecnt; i++) { | |
| 208 | 210 | files[i].marked = !files[i].marked; | |
| 211 | + | markcnt += files[i].marked ? 1 : -1; | |
| 212 | + | } | |
| 209 | 213 | if (mode == MODE_THUMB) | |
| 210 | 214 | tns.dirty = true; | |
| 211 | 215 | return true; | |
| @@ -73,6 +73,7 @@ win_t win; | |||
| 73 | 73 | fileinfo_t *files; | |
| 74 | 74 | int filecnt, fileidx; | |
| 75 | 75 | int alternate; | |
| 76 | + | int markcnt; | |
| 76 | 77 | ||
| 77 | 78 | int prefix; | |
| 78 | 79 | bool extprefix; | |
| @@ -168,6 +169,8 @@ void remove_file(int n, bool manual) | |||
| 168 | 169 | cleanup(); | |
| 169 | 170 | exit(manual ? EXIT_SUCCESS : EXIT_FAILURE); | |
| 170 | 171 | } | |
| 172 | + | if (files[n].marked) | |
| 173 | + | markcnt--; | |
| 171 | 174 | ||
| 172 | 175 | if (files[n].path != files[n].name) | |
| 173 | 176 | free((void*) files[n].path); | |
| @@ -627,6 +630,7 @@ void on_buttonpress(XButtonEvent *bev) | |||
| 627 | 630 | case Button3: | |
| 628 | 631 | if ((sel = tns_translate(&tns, bev->x, bev->y)) >= 0) { | |
| 629 | 632 | files[sel].marked = !files[sel].marked; | |
| 633 | + | markcnt += files[sel].marked ? 1 : -1; | |
| 630 | 634 | tns_mark(&tns, sel, files[sel].marked); | |
| 631 | 635 | redraw(); | |
| 632 | 636 | } | |