diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c old mode 100644 new mode 100755 index 9560345..29d186e --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -1384,6 +1384,7 @@ static void viewer_bottom(void) cline = 1; last_screen_top_ptr = screen_top_ptr; last_file_pos = file_pos; + buffer_end = BUFFER_END(); } #ifdef HAVE_LCD_BITMAP @@ -1494,6 +1495,22 @@ static void viewer_add_bookmark(void) bookmark_count++; } +static int viewer_add_last_read_bookmark(void) +{ + int i; + + i = viewer_find_bookmark(cpage, cline); + if (i >= 0) + bookmarks[i].flag |= BOOKMARK_LAST; + else + { + viewer_add_bookmark(); + i = bookmark_count-1; + bookmarks[i].flag = BOOKMARK_LAST; + } + return i; +} + static void viewer_remove_bookmark(int i) { int j; @@ -1508,28 +1525,46 @@ static void viewer_remove_bookmark(int i) bookmark_count--; } -static void viewer_remove_last_bookmark(void) +static void viewer_remove_last_read_bookmark(void) { int i, j; for (i = 0; i < bookmark_count; i++) { - if (bookmarks[i].flag == BOOKMARK_LAST) + if (bookmarks[i].flag & BOOKMARK_LAST) { - for (j = i+1; j < bookmark_count; j++) - rb->memcpy(&bookmarks[j-1], &bookmarks[j], - sizeof(struct bookmark_info)); + if (bookmarks[i].flag == BOOKMARK_LAST) + { + for (j = i+1; j < bookmark_count; j++) + rb->memcpy(&bookmarks[j-1], &bookmarks[j], + sizeof(struct bookmark_info)); - bookmark_count--; + bookmark_count--; + } + else + bookmarks[i].flag = BOOKMARK_USER; break; } - bookmarks[i].flag = BOOKMARK_USER; } } -static void viewer_select_bookmark(void) +static int viewer_get_last_read_bookmark(void) { int i; + + for (i = 0; i < bookmark_count; i++) + { + if (bookmarks[i].flag & BOOKMARK_LAST) + return i; + } + return -1; +} + +static void viewer_select_bookmark(int initval) +{ + int i; + int ipage = 0; + int iline = 0; int screen_pos; int screen_top; int selected = -1; @@ -1537,6 +1572,12 @@ static void viewer_select_bookmark(void) struct opt_items items[bookmark_count]; unsigned char names[bookmark_count][38]; + if (initval >= 0 && initval < bookmark_count) + { + ipage = bookmarks[initval].page; + iline = bookmarks[initval].line; + } + rb->qsort(bookmarks, bookmark_count, sizeof(struct bookmark_info), bm_comp); @@ -1550,6 +1591,8 @@ static void viewer_select_bookmark(void) "(last read page)":""); items[i].string = names[i]; items[i].voice_id = -1; + if (selected < 0 && bookmarks[i].page == ipage && bookmarks[i].line == iline) + selected = i; } rb->set_option("Select bookmark", &selected, INT, items, @@ -1557,21 +1600,26 @@ static void viewer_select_bookmark(void) if (selected < 0 || selected >= bookmark_count) { - rb->splash(HZ, "Start the first page."); - file_pos = 0; - screen_top_ptr = buffer; - cline = 1; - cpage = 1; - } - else - { - screen_pos = bookmarks[selected].file_position; - screen_top = screen_pos % buffer_size; - file_pos = screen_pos - screen_top; - screen_top_ptr = buffer + screen_top; - cpage = bookmarks[selected].page; - cline = bookmarks[selected].line; + if (initval < 0 || (selected = viewer_get_last_read_bookmark()) < 0) + { + if (initval < 0) + rb->splash(HZ, "Start the first page."); + file_pos = 0; + screen_top_ptr = buffer; + cpage = 1; + cline = 1; + buffer_end = BUFFER_END(); + return; + } } + + screen_pos = bookmarks[selected].file_position; + screen_top = screen_pos % buffer_size; + file_pos = screen_pos - screen_top; + screen_top_ptr = buffer + screen_top; + cpage = bookmarks[selected].page; + cline = bookmarks[selected].line; + buffer_end = BUFFER_END(); } static void viewer_default_preferences(void) @@ -1784,7 +1832,7 @@ read_end: rb->memcpy(&old_prefs, &prefs, sizeof(struct preferences)); if (bookmark_count > 1) - viewer_select_bookmark(); + viewer_select_bookmark(-1); else if (bookmark_count == 1) { int screen_pos; @@ -1798,7 +1846,7 @@ read_end: cline = bookmarks[0].line; } - viewer_remove_last_bookmark(); + viewer_remove_last_read_bookmark(); buffer_end = BUFFER_END(); /* Update whenever file_pos changes */ @@ -1999,14 +2047,7 @@ static void calc_page(void) rb->splash(0, "Calculating page/line number..."); /* add reading page to bookmarks */ - i = viewer_find_bookmark(cpage, cline); - if (i >= 0) - bookmarks[i].flag |= BOOKMARK_LAST; - else - { - viewer_add_bookmark(); - bookmarks[bookmark_count-1].flag = BOOKMARK_LAST; - } + viewer_add_last_read_bookmark(); rb->qsort(bookmarks, bookmark_count, sizeof(struct bookmark_info), bm_comp); @@ -2361,6 +2402,7 @@ static void viewer_menu(void) {"Quit", NULL }, {"Viewer Options", NULL }, {"Show Playback Menu", NULL }, + {"Select Bookmark", NULL }, {"Return", NULL }, }; @@ -2381,7 +2423,14 @@ static void viewer_menu(void) case 2: /* playback control */ playback_control(NULL); break; - case 3: /* return */ + case 3: /* select bookmark */ + viewer_select_bookmark(viewer_add_last_read_bookmark()); + viewer_remove_last_read_bookmark(); + fill_buffer(file_pos, buffer, buffer_size); + if (prefs.scroll_mode == PAGE && cline > 1) + viewer_scroll_to_top_line(); + break; + case 4: /* return */ break; } menu_exit(m);