From 4348b4585704ede2f13a72b7f91a06d041316a1c Mon Sep 17 00:00:00 2001 From: Jonathan Gordon Date: Thu, 26 Jul 2012 17:51:51 +1000 Subject: [PATCH] shortcuts: Remove the selected shortcut with the context menu button Change-Id: Ie551fdda39bae3b0c5f37c1cb0ff905151d352de --- apps/shortcuts.c | 42 ++++++++++++++++++++++++++++++++++++++++-- manual/main_menu/main.tex | 2 ++ 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 @@ * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ - * $Id$ * * Copyright (C) 2011 Jonathan Gordon * @@ -44,6 +43,7 @@ #include "onplay.h" #include "screens.h" #include "talk.h" +#include "yesno.h" #define MAX_SHORTCUT_NAME 32 @@ -135,6 +135,21 @@ static struct shortcut* get_shortcut(int index) return &h->shortcuts[handle_index]; } +static void remove_shortcut(int index) +{ + int this = index, next = index + 1; + struct shortcut *prev = get_shortcut(this); + + while (next <= shortcut_count) + { + struct shortcut *sc = get_shortcut(next); + memcpy(prev, sc, sizeof(struct shortcut)); + next++; + prev = sc; + } + shortcut_count--; +} + static bool verify_shortcut(struct shortcut* sc) { switch (sc->type) @@ -168,15 +183,18 @@ static void init_shortcut(struct shortcut* sc) } static int first_idx_to_writeback = -1; +static bool overwrite_shortcuts = false; static void shortcuts_ata_idle_callback(void* data) { (void)data; int fd; char buf[MAX_PATH]; int current_idx = first_idx_to_writeback; + int append = overwrite_shortcuts ? O_TRUNC : O_APPEND; + if (first_idx_to_writeback < 0) return; - fd = open(SHORTCUTS_FILENAME, O_APPEND|O_RDWR|O_CREAT, 0644); + fd = open(SHORTCUTS_FILENAME, append|O_RDWR|O_CREAT, 0644); if (fd < 0) return; while (current_idx < shortcut_count) @@ -218,8 +236,10 @@ void shortcuts_add(enum shortcut_type type, const char* value) sc->u.setting = (void*)value; else strlcpy(sc->u.path, value, MAX_PATH); + if (first_idx_to_writeback < 0) first_idx_to_writeback = shortcut_count - 1; + overwrite_shortcuts = false; register_storage_idle_func(shortcuts_ata_idle_callback); } @@ -354,6 +374,24 @@ static int shortcut_menu_get_action(int action, struct gui_synclist *lists) (void)lists; if (action == ACTION_STD_OK) return ACTION_STD_CANCEL; + else if (action == ACTION_STD_CONTEXT) + { + int selection = gui_synclist_get_sel_pos(lists); + + if (!yesno_pop(ID2P(LANG_REALLY_DELETE))) + return ACTION_REDRAW; + + remove_shortcut(selection); + gui_synclist_set_nb_items(lists, shortcut_count); + if (selection >= shortcut_count) + gui_synclist_select_item(lists, shortcut_count - 1); + first_idx_to_writeback = 0; + overwrite_shortcuts = true; + shortcuts_ata_idle_callback(NULL); + if (shortcut_count == 0) + return ACTION_STD_CANCEL; + return ACTION_REDRAW; + } return action; } 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 also be added to it through their context menu item ``Add to shortcuts''. A reboot is needed for manual changes to \fname{shortcuts.txt} to be applied. +Shortcuts can be manually removed by selecting the one you wish to remove and pressing +\ActionStdContext{}. -- 2.11.4.GIT