From 044863268f9444cf896ecf8b893e12829b2f478e Mon Sep 17 00:00:00 2001 From: Sebastian Ramacher Date: Wed, 15 May 2024 21:56:06 +0200 Subject: [PATCH] Split blist into blist and bjump (fixes #126) --- doc/man/zathura.1.rst | 5 ++++- zathura/commands.c | 43 +++++++++++++++++++++++++++++-------------- zathura/commands.h | 9 +++++++++ zathura/config.c | 3 ++- 4 files changed, 44 insertions(+), 16 deletions(-) diff --git a/doc/man/zathura.1.rst b/doc/man/zathura.1.rst index f5eb4894..ea1ed83b 100644 --- a/doc/man/zathura.1.rst +++ b/doc/man/zathura.1.rst @@ -225,7 +225,10 @@ bdelete Delete a bookmark. blist - List bookmarks. Adding a bookmark name opens it. + List bookmarks. + +bjump + Jump to given bookmark. close Close document diff --git a/zathura/commands.c b/zathura/commands.c index 83bc3cec..07fef0d6 100644 --- a/zathura/commands.c +++ b/zathura/commands.c @@ -91,6 +91,34 @@ bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list return true; } +bool cmd_bookmark_list(girara_session_t* session, girara_list_t* argument_list) { + g_return_val_if_fail(session != NULL, false); + g_return_val_if_fail(session->global.data != NULL, false); + zathura_t* zathura = session->global.data; + if (zathura->document == NULL) { + girara_notify(session, GIRARA_ERROR, _("No document opened.")); + return false; + } + + GString* string = g_string_new(NULL); + for (size_t idx = 0; idx != girara_list_size(zathura->bookmarks.bookmarks); ++idx) { + zathura_bookmark_t* bookmark = girara_list_nth(zathura->bookmarks.bookmarks, idx); + g_string_append_printf(string, "%s: %u\n", bookmark->id, bookmark->page); + } + + if (strlen(string->str) > 0) { + g_string_erase(string, strlen(string->str) - 1, 1); + girara_notify(session, GIRARA_INFO, "%s", string->str); + } else { + girara_notify(session, GIRARA_INFO, _("No bookmarks available.")); + } + + g_string_free(string, TRUE); + return false; + + return true; +} + bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) { g_return_val_if_fail(session != NULL, false); g_return_val_if_fail(session->global.data != NULL, false); @@ -102,20 +130,7 @@ bool cmd_bookmark_open(girara_session_t* session, girara_list_t* argument_list) const unsigned int argc = girara_list_size(argument_list); if (argc != 1) { - GString* string = g_string_new(NULL); - for (size_t idx = 0; idx != girara_list_size(zathura->bookmarks.bookmarks); ++idx) { - zathura_bookmark_t* bookmark = girara_list_nth(zathura->bookmarks.bookmarks, idx); - g_string_append_printf(string, "%s: %u\n", bookmark->id, bookmark->page); - } - - if (strlen(string->str) > 0) { - g_string_erase(string, strlen(string->str) - 1, 1); - girara_notify(session, GIRARA_INFO, "%s", string->str); - } else { - girara_notify(session, GIRARA_INFO, _("No bookmarks available.")); - } - - g_string_free(string, TRUE); + girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments given.")); return false; } diff --git a/zathura/commands.h b/zathura/commands.h index 7965b71e..2bbdc224 100644 --- a/zathura/commands.h +++ b/zathura/commands.h @@ -24,6 +24,15 @@ bool cmd_bookmark_create(girara_session_t* session, girara_list_t* argument_list */ bool cmd_bookmark_delete(girara_session_t* session, girara_list_t* argument_list); +/** + * List bookmarks + * + * @param session The used girara session + * @param argument_list List of passed arguments + * @return true if no error occurred + */ +bool cmd_bookmark_list(girara_session_t* session, girara_list_t* argument_list); + /** * Open a bookmark * diff --git a/zathura/config.c b/zathura/config.c index 90ebdfee..8e0a8ab5 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -572,7 +572,8 @@ void config_load_default(zathura_t* zathura) { /* define default inputbar commands */ girara_inputbar_command_add(gsession, "bmark", NULL, cmd_bookmark_create, NULL, _("Add a bookmark")); girara_inputbar_command_add(gsession, "bdelete", NULL, cmd_bookmark_delete, cc_bookmarks, _("Delete a bookmark")); - girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, cc_bookmarks, _("List all bookmarks")); + girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_list, NULL, _("List all bookmarks")); + girara_inputbar_command_add(gsession, "bjump", NULL, cmd_bookmark_open, cc_bookmarks, _("Jump to bookmark")); girara_inputbar_command_add(gsession, "close", NULL, cmd_close, NULL, _("Close current file")); girara_inputbar_command_add(gsession, "info", NULL, cmd_info, NULL, _("Show file information")); girara_inputbar_command_add(gsession, "exec", NULL, cmd_exec, NULL, _("Execute a command"));