From 7d878bd16df1abffde780e195144b845dc133166 Mon Sep 17 00:00:00 2001 From: Bert Münnich Date: Sat, 10 Aug 2013 21:18:53 +0200 Subject: Added file marks; fixes issue #94 - Command it_toggle_image_mark (bound to 'm') toggles mark of current image - Command it_navigate_marked (bound to 'N'/'P') can be used to go to the next/previous marked image - When option -o is given, all marked files get printed --- commands.c | 47 +++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 45 insertions(+), 2 deletions(-) (limited to 'commands.c') diff --git a/commands.c b/commands.c index 36da023..c1792a5 100644 --- a/commands.c +++ b/commands.c @@ -48,6 +48,7 @@ extern win_t win; extern fileinfo_t *files; extern int filecnt, fileidx; +extern int markcnt; extern int alternate; extern int prefix; @@ -61,8 +62,10 @@ bool it_quit(arg_t a) unsigned int i; if (options->to_stdout) { - for (i = 0; i < filecnt; i++) - printf("%s\n", files[i].name); + for (i = 0; i < filecnt; i++) { + if (!markcnt || files[i].marked) + printf("%s\n", files[i].name); + } } cleanup(); exit(EXIT_SUCCESS); @@ -237,6 +240,46 @@ bool i_toggle_animation(arg_t a) return true; } +bool it_toggle_image_mark(arg_t a) +{ + int sel = mode == MODE_IMAGE ? fileidx : tns.sel; + + files[sel].marked = !files[sel].marked; + markcnt += files[sel].marked ? 1 : -1; + return true; +} + +bool it_navigate_marked(arg_t a) +{ + long n = (long) a; + int d, i, cnt, sel, new; + + if (mode == MODE_IMAGE) + cnt = filecnt, sel = new = fileidx; + else + cnt = tns.cnt, sel = new = tns.sel; + if (prefix > 0) + n *= prefix; + d = n > 0 ? 1 : -1; + for (i = sel + d; n != 0 && i >= 0 && i < cnt; i += d) { + if (files[i].marked) { + n -= d; + new = i; + } + } + if (new != sel) { + if (mode == MODE_IMAGE) { + load_image(new); + } else { + tns.sel = new; + tns.dirty = true; + } + return true; + } else { + return false; + } +} + bool it_scroll_move(arg_t a) { direction_t dir = (direction_t) a; -- cgit v1.2.3-54-g00ecf