1
0
Fork 0
forked from len0rd/rockbox

shortcuts_view: fix displaying last path segments so that plugin exactly shows what is said in the manual.

fix bug it shows "Bad entry selected!" when exit right after delete last item.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@22428 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2009-08-19 13:46:59 +00:00
parent e6b53c7c90
commit 237d36cd93
2 changed files with 15 additions and 21 deletions

View file

@ -222,11 +222,11 @@ bool parse_entry_content(char *line, sc_entry_t *entry, int last_segm)
char *last_segments(char *path, int nsegm) char *last_segments(char *path, int nsegm)
{ {
char *p = rb->strrchr(path, PATH_SEPARATOR[0]); /* Hack */ /* don't count one trailing separator */
int seg_cnt; char *p = path+rb->strlen(path)-PATH_SEPARATOR_LEN;
if (p == NULL) int seg_cnt = 0;
return path; /* No separator??? */ if(p <= path)
seg_cnt = 0; return path;
while ((p > path) && (seg_cnt < nsegm)) { while ((p > path) && (seg_cnt < nsegm)) {
p--; p--;
if (!starts_with(p, PATH_SEPARATOR)) { if (!starts_with(p, PATH_SEPARATOR)) {

View file

@ -35,32 +35,31 @@ enum sc_list_action_type
static char *link_filename; static char *link_filename;
static bool user_file; static bool user_file;
static int gselected_item;
static bool usb_connected = false; static bool usb_connected = false;
enum sc_list_action_type draw_sc_list(struct gui_synclist gui_sc); enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc);
/* Will be passed sc_file* as data */ /* Will be passed sc_file* as data */
char* build_sc_list(int selected_item, void *data, char* build_sc_list(int selected_item, void *data,
char *buffer, size_t buffer_len); char *buffer, size_t buffer_len);
/* Returns true iff we should leave the main loop */ /* Returns true iff we should leave the main loop */
bool list_sc(bool is_editable); bool list_sc(void);
bool goto_entry(char *file_or_dir); bool goto_entry(char *file_or_dir);
bool ends_with(char *str, char *suffix); bool ends_with(char *str, char *suffix);
enum sc_list_action_type draw_sc_list(struct gui_synclist gui_sc) enum sc_list_action_type draw_sc_list(struct gui_synclist *gui_sc)
{ {
int button; int button;
rb->gui_synclist_draw(&gui_sc); rb->gui_synclist_draw(gui_sc);
while (true) { while (true) {
/* user input */ /* user input */
button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK); button = rb->get_action(CONTEXT_LIST, TIMEOUT_BLOCK);
if (rb->gui_synclist_do_button(&gui_sc, &button, if (rb->gui_synclist_do_button(gui_sc, &button,
LIST_WRAP_UNLESS_HELD)) { LIST_WRAP_UNLESS_HELD)) {
/* automatic handling of user input. /* automatic handling of user input.
* _UNLESS_HELD can be _ON or _OFF also * _UNLESS_HELD can be _ON or _OFF also
@ -69,7 +68,6 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist gui_sc)
} }
switch (button) { /* process the user input */ switch (button) { /* process the user input */
case ACTION_STD_OK: case ACTION_STD_OK:
gselected_item = rb->gui_synclist_get_sel_pos(&gui_sc);
return SCLA_SELECT; return SCLA_SELECT;
case ACTION_STD_MENU: case ACTION_STD_MENU:
/* Only allow delete entries in the default file /* Only allow delete entries in the default file
@ -77,7 +75,6 @@ enum sc_list_action_type draw_sc_list(struct gui_synclist gui_sc)
* to the default file only. The behaviour is thus * to the default file only. The behaviour is thus
* symmetric in this respect. */ * symmetric in this respect. */
if (!user_file) { if (!user_file) {
gselected_item = rb->gui_synclist_get_sel_pos(&gui_sc);
return SCLA_DELETE; return SCLA_DELETE;
} }
break; break;
@ -106,33 +103,30 @@ char* build_sc_list(int selected_item, void *data,
} }
bool list_sc(bool is_editable) bool list_sc(void)
{ {
int selected_item = 0; int selected_item = 0;
char selected_dir[MAX_PATH];
enum sc_list_action_type action = SCLA_NONE; enum sc_list_action_type action = SCLA_NONE;
struct gui_synclist gui_sc; struct gui_synclist gui_sc;
rb->memset(selected_dir, 0, sizeof(selected_dir));
/* Setup the GUI list object, draw it to the screen, /* Setup the GUI list object, draw it to the screen,
* and then handle the user input to it */ * and then handle the user input to it */
rb->gui_synclist_init(&gui_sc, &build_sc_list, &sc_file, false, 1, NULL); rb->gui_synclist_init(&gui_sc, &build_sc_list, &sc_file, false, 1, NULL);
rb->gui_synclist_set_title(&gui_sc, rb->gui_synclist_set_title(&gui_sc,
(is_editable?"Shortcuts (editable)":"Shortcuts (sealed)"), NOICON); (user_file?"Shortcuts (sealed)":"Shortcuts (editable)"), NOICON);
rb->gui_synclist_set_nb_items(&gui_sc, sc_file.entry_cnt); rb->gui_synclist_set_nb_items(&gui_sc, sc_file.entry_cnt);
rb->gui_synclist_limit_scroll(&gui_sc, false); rb->gui_synclist_limit_scroll(&gui_sc, false);
rb->gui_synclist_select_item(&gui_sc, 0); rb->gui_synclist_select_item(&gui_sc, 0);
/* Draw the prepared widget to the LCD now */ /* Draw the prepared widget to the LCD now */
action = draw_sc_list(gui_sc); action = draw_sc_list(&gui_sc);
if (action == SCLA_USB) { if (action == SCLA_USB) {
usb_connected = true; usb_connected = true;
return true; return true;
} }
/* which item do we action? */ /* which item do we action? */
selected_item = gselected_item; selected_item = rb->gui_synclist_get_sel_pos(&gui_sc);
if (!is_valid_index(&sc_file, selected_item)) { if (!is_valid_index(&sc_file, selected_item)) {
/* This should never happen */ /* This should never happen */
@ -230,7 +224,7 @@ enum plugin_status plugin_start(const void* void_parameter)
do { do {
/* Display a menu to choose between the entries */ /* Display a menu to choose between the entries */
leave_loop = list_sc(!user_file); leave_loop = list_sc();
} while (!leave_loop); } while (!leave_loop);
return usb_connected ? PLUGIN_USB_CONNECTED : PLUGIN_OK; return usb_connected ? PLUGIN_USB_CONNECTED : PLUGIN_OK;