From 87a1ace8a1cb83132f791cb19c3fa31b9b6e3f3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bert=20M=C3=BCnnich?= Date: Sat, 9 Jun 2018 13:12:46 +0200 Subject: [PATCH] (Un)mark single image through generic function --- commands.c | 20 ++++++-------------- main.c | 12 ++++++++++++ 2 files changed, 18 insertions(+), 14 deletions(-) diff --git a/commands.c b/commands.c index 894ddd1..7c00028 100644 --- a/commands.c +++ b/commands.c @@ -27,6 +27,7 @@ void remove_file(int, bool); void load_image(int); +bool mark_image(int, bool); void close_info(void); void open_info(void); int ptr_third_x(void); @@ -193,12 +194,8 @@ bool cg_zoom(arg_t d) bool cg_toggle_image_mark(arg_t _) { - files[fileidx].flags ^= FF_MARK; - markcnt += files[fileidx].flags & FF_MARK ? 1 : -1; - if (mode == MODE_THUMB) - tns_mark(&tns, fileidx, !!(files[fileidx].flags & FF_MARK)); markidx = fileidx; - return true; + return mark_image(fileidx, !(files[fileidx].flags & FF_MARK)); } bool cg_reverse_marks(arg_t _) @@ -217,18 +214,13 @@ bool cg_reverse_marks(arg_t _) bool cg_mark_range(arg_t _) { int i, d = fileidx < markidx ? 1 : -1; - int flag = files[markidx].flags & FF_MARK; - int oldmarkcnt = markcnt; + bool dirty = false, on = !!(files[markidx].flags & FF_MARK); for (i = fileidx; i != markidx; i += d) { - if ((files[i].flags & FF_MARK) ^ flag) { - files[i].flags = (files[i].flags & ~FF_MARK) | flag; - markcnt += flag ? 1 : -1; - if (mode == MODE_THUMB) - tns_mark(&tns, i, !!flag); - } + if (mark_image(i, on)) + dirty = true; } - return markcnt != oldmarkcnt; + return dirty; } bool cg_unmark_all(arg_t _) diff --git a/main.c b/main.c index aa9775d..190ca29 100644 --- a/main.c +++ b/main.c @@ -321,6 +321,18 @@ void load_image(int new) reset_timeout(animate); } +bool mark_image(int n, bool on) +{ + if (!!(files[n].flags & FF_MARK) != on) { + files[n].flags ^= FF_MARK; + markcnt += on ? 1 : -1; + if (mode == MODE_THUMB) + tns_mark(&tns, n, on); + return true; + } + return false; +} + void bar_put(win_bar_t *bar, const char *fmt, ...) { size_t len = bar->size - (bar->p - bar->buf), n;