Skip to content

Commit

Permalink
Split blist into blist and bjump (fixes #126)
Browse files Browse the repository at this point in the history
  • Loading branch information
sebastinas committed May 15, 2024
1 parent ee90593 commit 0448632
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 16 deletions.
5 changes: 4 additions & 1 deletion doc/man/zathura.1.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
43 changes: 29 additions & 14 deletions zathura/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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, "<b>%s</b>: %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);
Expand All @@ -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, "<b>%s</b>: %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;
}

Expand Down
9 changes: 9 additions & 0 deletions zathura/commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
3 changes: 2 additions & 1 deletion zathura/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
Expand Down

0 comments on commit 0448632

Please sign in to comment.