summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Gordon <rockbox@jdgordon.info>2012-07-26 17:51:51 +1000
committerJonathan Gordon <rockbox@jdgordon.info>2012-07-26 17:51:51 +1000
commit4348b4585704ede2f13a72b7f91a06d041316a1c (patch)
tree744974fc8c4271c156cf2e97cf17ec4abe0f4488
parent229d88c89939b81283e03ead9726eb289e13d00f (diff)
downloadrockbox-4348b4585704ede2f13a72b7f91a06d041316a1c.tar.gz
rockbox-4348b4585704ede2f13a72b7f91a06d041316a1c.zip
shortcuts: Remove the selected shortcut with the context menu button
Change-Id: Ie551fdda39bae3b0c5f37c1cb0ff905151d352de
-rw-r--r--apps/shortcuts.c42
-rw-r--r--manual/main_menu/main.tex2
2 files changed, 42 insertions, 2 deletions
diff --git a/apps/shortcuts.c b/apps/shortcuts.c
index d7868461a7..50b8decfc6 100644
--- a/apps/shortcuts.c
+++ b/apps/shortcuts.c
@@ -6,7 +6,6 @@
6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < 6 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ 7 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * \/ \/ \/ \/ \/ 8 * \/ \/ \/ \/ \/
9 * $Id$
10 * 9 *
11 * Copyright (C) 2011 Jonathan Gordon 10 * Copyright (C) 2011 Jonathan Gordon
12 * 11 *
@@ -44,6 +43,7 @@
44#include "onplay.h" 43#include "onplay.h"
45#include "screens.h" 44#include "screens.h"
46#include "talk.h" 45#include "talk.h"
46#include "yesno.h"
47 47
48 48
49#define MAX_SHORTCUT_NAME 32 49#define MAX_SHORTCUT_NAME 32
@@ -135,6 +135,21 @@ static struct shortcut* get_shortcut(int index)
135 return &h->shortcuts[handle_index]; 135 return &h->shortcuts[handle_index];
136} 136}
137 137
138static void remove_shortcut(int index)
139{
140 int this = index, next = index + 1;
141 struct shortcut *prev = get_shortcut(this);
142
143 while (next <= shortcut_count)
144 {
145 struct shortcut *sc = get_shortcut(next);
146 memcpy(prev, sc, sizeof(struct shortcut));
147 next++;
148 prev = sc;
149 }
150 shortcut_count--;
151}
152
138static bool verify_shortcut(struct shortcut* sc) 153static bool verify_shortcut(struct shortcut* sc)
139{ 154{
140 switch (sc->type) 155 switch (sc->type)
@@ -168,15 +183,18 @@ static void init_shortcut(struct shortcut* sc)
168} 183}
169 184
170static int first_idx_to_writeback = -1; 185static int first_idx_to_writeback = -1;
186static bool overwrite_shortcuts = false;
171static void shortcuts_ata_idle_callback(void* data) 187static void shortcuts_ata_idle_callback(void* data)
172{ 188{
173 (void)data; 189 (void)data;
174 int fd; 190 int fd;
175 char buf[MAX_PATH]; 191 char buf[MAX_PATH];
176 int current_idx = first_idx_to_writeback; 192 int current_idx = first_idx_to_writeback;
193 int append = overwrite_shortcuts ? O_TRUNC : O_APPEND;
194
177 if (first_idx_to_writeback < 0) 195 if (first_idx_to_writeback < 0)
178 return; 196 return;
179 fd = open(SHORTCUTS_FILENAME, O_APPEND|O_RDWR|O_CREAT, 0644); 197 fd = open(SHORTCUTS_FILENAME, append|O_RDWR|O_CREAT, 0644);
180 if (fd < 0) 198 if (fd < 0)
181 return; 199 return;
182 while (current_idx < shortcut_count) 200 while (current_idx < shortcut_count)
@@ -218,8 +236,10 @@ void shortcuts_add(enum shortcut_type type, const char* value)
218 sc->u.setting = (void*)value; 236 sc->u.setting = (void*)value;
219 else 237 else
220 strlcpy(sc->u.path, value, MAX_PATH); 238 strlcpy(sc->u.path, value, MAX_PATH);
239
221 if (first_idx_to_writeback < 0) 240 if (first_idx_to_writeback < 0)
222 first_idx_to_writeback = shortcut_count - 1; 241 first_idx_to_writeback = shortcut_count - 1;
242 overwrite_shortcuts = false;
223 register_storage_idle_func(shortcuts_ata_idle_callback); 243 register_storage_idle_func(shortcuts_ata_idle_callback);
224} 244}
225 245
@@ -354,6 +374,24 @@ static int shortcut_menu_get_action(int action, struct gui_synclist *lists)
354 (void)lists; 374 (void)lists;
355 if (action == ACTION_STD_OK) 375 if (action == ACTION_STD_OK)
356 return ACTION_STD_CANCEL; 376 return ACTION_STD_CANCEL;
377 else if (action == ACTION_STD_CONTEXT)
378 {
379 int selection = gui_synclist_get_sel_pos(lists);
380
381 if (!yesno_pop(ID2P(LANG_REALLY_DELETE)))
382 return ACTION_REDRAW;
383
384 remove_shortcut(selection);
385 gui_synclist_set_nb_items(lists, shortcut_count);
386 if (selection >= shortcut_count)
387 gui_synclist_select_item(lists, shortcut_count - 1);
388 first_idx_to_writeback = 0;
389 overwrite_shortcuts = true;
390 shortcuts_ata_idle_callback(NULL);
391 if (shortcut_count == 0)
392 return ACTION_STD_CANCEL;
393 return ACTION_REDRAW;
394 }
357 return action; 395 return action;
358} 396}
359 397
diff --git a/manual/main_menu/main.tex b/manual/main_menu/main.tex
index 33e64c12fe..f8afcd2b9f 100644
--- a/manual/main_menu/main.tex
+++ b/manual/main_menu/main.tex
@@ -332,3 +332,5 @@ The file \fname{shortcuts.txt} can be edited with any text editor. Most items ca
332also be added to it through their context menu item ``Add to shortcuts''. 332also be added to it through their context menu item ``Add to shortcuts''.
333A reboot is needed for manual changes to \fname{shortcuts.txt} to be applied. 333A reboot is needed for manual changes to \fname{shortcuts.txt} to be applied.
334 334
335Shortcuts can be manually removed by selecting the one you wish to remove and pressing
336\ActionStdContext{}.