diff --git a/apps/plugins/viewer.c b/apps/plugins/viewer.c old mode 100644 new mode 100755 index 5ae4943..ccfbc35 --- a/apps/plugins/viewer.c +++ b/apps/plugins/viewer.c @@ -1539,6 +1539,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; @@ -1553,28 +1569,34 @@ 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 void viewer_select_bookmark(int initval) { int i; + int ipage = 0; + int iline = 0; int screen_pos; int screen_top; int selected = -1; @@ -1582,6 +1604,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); @@ -1595,6 +1623,8 @@ static void viewer_select_bookmark(void) "(last read page)":""); items[i].string = names[i]; items[i].voice_id = -1; + if (bookmarks[i].page == ipage && bookmarks[i].line == iline) + selected = i; } rb->set_option("Select bookmark", &selected, INT, items, @@ -1602,11 +1632,14 @@ 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; + if (initval < 0) + { + rb->splash(HZ, "Start the first page."); + file_pos = 0; + screen_top_ptr = buffer; + cline = 1; + cpage = 1; + } } else { @@ -1842,7 +1875,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; @@ -1856,7 +1889,7 @@ read_end: cline = bookmarks[0].line; } - viewer_remove_last_bookmark(); + viewer_remove_last_read_bookmark(); check_bom(); get_filesize(); @@ -2056,14 +2089,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); @@ -2427,6 +2453,7 @@ static void viewer_menu(void) {"Quit", NULL }, {"Viewer Options", NULL }, {"Show Playback Menu", NULL }, + {"Select Bookmark", NULL }, {"Return", NULL }, }; @@ -2446,7 +2473,11 @@ 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(); + break; + case 4: /* return */ break; } menu_exit(m);