Delete bookmark

This commit is contained in:
Moritz Lipp 2010-01-31 21:24:33 +01:00
parent db76477a18
commit 0c5f0dfb0c
2 changed files with 55 additions and 12 deletions

View file

@ -101,6 +101,7 @@ Command commands[] = {
{"bmark", "b", cmd_bookmark, 0, "Bookmark current page" }, {"bmark", "b", cmd_bookmark, 0, "Bookmark current page" },
{"blist", 0, cmd_open_bookmark, cc_bookmark, "List and open bookmark" }, {"blist", 0, cmd_open_bookmark, cc_bookmark, "List and open bookmark" },
{"close", "c", cmd_close, 0, "Close current file" }, {"close", "c", cmd_close, 0, "Close current file" },
{"delbmark", 0, cmd_delete_bookmark, cc_bookmark, "Bookmark current page" },
{"export", "e", cmd_export, cc_export, "Export images or attached files" }, {"export", "e", cmd_export, cc_export, "Export images or attached files" },
{"info", "i", cmd_info, 0, "Show information about the document" }, {"info", "i", cmd_info, 0, "Show information about the document" },
{"open", "o", cmd_open, cc_open, "Open a file" }, {"open", "o", cmd_open, cc_open, "Open a file" },

View file

@ -283,6 +283,7 @@ void isc_string_manipulation(Argument*);
gboolean cmd_bookmark(int, char**); gboolean cmd_bookmark(int, char**);
gboolean cmd_open_bookmark(int, char**); gboolean cmd_open_bookmark(int, char**);
gboolean cmd_close(int, char**); gboolean cmd_close(int, char**);
gboolean cmd_delete_bookmark(int, char**);
gboolean cmd_export(int, char**); gboolean cmd_export(int, char**);
gboolean cmd_info(int, char**); gboolean cmd_info(int, char**);
gboolean cmd_open(int, char**); gboolean cmd_open(int, char**);
@ -1694,6 +1695,47 @@ cmd_close(int argc, char** argv)
return TRUE; return TRUE;
} }
gboolean
cmd_delete_bookmark(int argc, char** argv)
{
if(!Zathura.PDF.document || argc < 1)
return TRUE;
/* get id */
int i;
GString *id = g_string_new("");
for(i = 0; i < argc; i++)
{
if(i != 0)
id = g_string_append_c(id, ' ');
id = g_string_append(id, argv[i]);
}
/* check for bookmark to delete */
for(i = 0; i < Zathura.Bookmarks.number_of_bookmarks; i++)
{
if(!strcmp(id->str, Zathura.Bookmarks.bookmarks[i].id))
{
/* update key file */
g_key_file_remove_key(Zathura.Bookmarks.data, Zathura.PDF.file, Zathura.Bookmarks.bookmarks[i].id, NULL);
/* update bookmarks */
Zathura.Bookmarks.bookmarks[i].id = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].id;
Zathura.Bookmarks.bookmarks[i].page = Zathura.Bookmarks.bookmarks[Zathura.Bookmarks.number_of_bookmarks - 1].page;
Zathura.Bookmarks.bookmarks = realloc(Zathura.Bookmarks.bookmarks,
Zathura.Bookmarks.number_of_bookmarks * sizeof(Bookmark));
Zathura.Bookmarks.number_of_bookmarks--;
return TRUE;
}
}
return TRUE;
}
gboolean gboolean
cmd_export(int argc, char** argv) cmd_export(int argc, char** argv)
{ {