aboutsummaryrefslogtreecommitdiffstats
path: root/commands.c
diff options
context:
space:
mode:
authorBert Münnich <be.muennich@gmail.com>2013-08-10 21:18:53 +0200
committerBert Münnich <be.muennich@gmail.com>2013-08-10 21:18:53 +0200
commit7d878bd16df1abffde780e195144b845dc133166 (patch)
treeee956a3830bf27b82a2004b6e8f160ddf60a7011 /commands.c
parent84d77b173288f838ffdbe2cd12061cf7a725f185 (diff)
downloadnsxiv-7d878bd16df1abffde780e195144b845dc133166.tar.zst
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
Diffstat (limited to 'commands.c')
-rw-r--r--commands.c47
1 files changed, 45 insertions, 2 deletions
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;