diff --git a/config.def.h b/config.def.h index 8fa0911..1cc2e82 100644 --- a/config.def.h +++ b/config.def.h @@ -97,18 +97,19 @@ InputbarShortcut inputbar_shortcuts[] = { /* commands */ Command commands[] = { - /* command, abbreviation, function, completion, description */ - {"bmark", "b", cmd_bookmark, 0, "Bookmark current page" }, - {"blist", 0, cmd_open_bookmark, cc_bookmark, "List and open bookmark" }, - {"close", "c", cmd_close, 0, "Close current file" }, - {"export", "e", cmd_export, cc_export, "Export images or attached files" }, - {"info", "i", cmd_info, 0, "Show information about the document" }, - {"open", "o", cmd_open, cc_open, "Open a file" }, - {"print", "p", cmd_print, cc_print, "Print the document" }, - {"rotate", "r", cmd_rotate, 0, "Rotate the page" }, - {"set", "s", cmd_set, cc_set, "Set an option" }, - {"quit", "q", cmd_quit, 0, "Quit zjui" }, - {"write", "w", cmd_save, 0, "Save the document" }, + /* command, abbreviation, function, completion, description */ + {"bmark", "b", cmd_bookmark, 0, "Bookmark current page" }, + {"blist", 0, cmd_open_bookmark, cc_bookmark, "List and open bookmark" }, + {"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" }, + {"info", "i", cmd_info, 0, "Show information about the document" }, + {"open", "o", cmd_open, cc_open, "Open a file" }, + {"print", "p", cmd_print, cc_print, "Print the document" }, + {"rotate", "r", cmd_rotate, 0, "Rotate the page" }, + {"set", "s", cmd_set, cc_set, "Set an option" }, + {"quit", "q", cmd_quit, 0, "Quit zjui" }, + {"write", "w", cmd_save, 0, "Save the document" }, }; /* buffer commands */ diff --git a/zathura.c b/zathura.c index c7f259b..3fd12f0 100644 --- a/zathura.c +++ b/zathura.c @@ -283,6 +283,7 @@ void isc_string_manipulation(Argument*); gboolean cmd_bookmark(int, char**); gboolean cmd_open_bookmark(int, char**); gboolean cmd_close(int, char**); +gboolean cmd_delete_bookmark(int, char**); gboolean cmd_export(int, char**); gboolean cmd_info(int, char**); gboolean cmd_open(int, char**); @@ -1694,6 +1695,47 @@ cmd_close(int argc, char** argv) 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 cmd_export(int argc, char** argv) {