aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHarry Jeffery <harry@exec64.co.uk>2015-11-27 14:00:32 +0000
committerHarry Jeffery <harry@exec64.co.uk>2015-11-27 14:00:32 +0000
commit548677824437a1338fdd253b1d978fec6c7fbd4e (patch)
treed6c28aba5e29a0f2704603b2a00ffe3b94ef8694
parent5f6fb9fb0d5cf523d810e5d3812d8172c5eaa50e (diff)
downloadimv-548677824437a1338fdd253b1d978fec6c7fbd4e.tar.gz
add imv_navigator_remove_path function
-rw-r--r--src/navigator.c35
-rw-r--r--src/navigator.h1
2 files changed, 36 insertions, 0 deletions
diff --git a/src/navigator.c b/src/navigator.c
index c6dff06..49a9858 100644
--- a/src/navigator.c
+++ b/src/navigator.c
@@ -150,6 +150,41 @@ void imv_navigator_prev_path(struct imv_navigator *nav)
nav->changed = prev_path != nav->cur_path;
}
+void imv_navigator_remove_path(struct imv_navigator *nav, const char *path)
+{
+ int removed = -1;
+ for(int i = 0; i < nav->num_paths; ++i) {
+ if(strcmp(path, nav->paths[i]) == 0) {
+ removed = i;
+ free(nav->paths[i]);
+ break;
+ }
+ }
+
+ if(removed == -1) {
+ return;
+ }
+
+ for(int i = removed; i < nav->num_paths - 2; ++i) {
+ nav->paths[i] = nav->paths[i+1];
+ }
+
+ nav->num_paths -= 1;
+
+ if(nav->cur_path == removed) {
+ /* We just removed the current path */
+ if(nav->last_move_direction < 0) {
+ /* Move left */
+ imv_navigator_prev_path(nav);
+ } else {
+ /* Try to stay where we are, unless we ran out of room */
+ if(nav->cur_path == nav->num_paths) {
+ nav->cur_path = 0;
+ }
+ }
+ }
+}
+
void imv_navigator_remove_current_path(struct imv_navigator *nav)
{
if(nav->num_paths == 0) {
diff --git a/src/navigator.h b/src/navigator.h
index 39db489..23bcc24 100644
--- a/src/navigator.h
+++ b/src/navigator.h
@@ -37,6 +37,7 @@ const char *imv_navigator_get_current_path(struct imv_navigator *nav);
void imv_navigator_next_path(struct imv_navigator *nav);
void imv_navigator_prev_path(struct imv_navigator *nav);
void imv_navigator_remove_current_path(struct imv_navigator *nav);
+void imv_navigator_remove_path(struct imv_navigator *nav, const char *path);
void imv_navigator_set_path(struct imv_navigator *nav, const int path);
int imv_navigator_find_path(struct imv_navigator *nav, const char *path);