diff --git a/completion.c b/completion.c index 5fc32cf..dca7a03 100644 --- a/completion.c +++ b/completion.c @@ -6,6 +6,7 @@ #include #include +#include "bookmarks.h" #include "completion.h" #include "utils.h" @@ -142,3 +143,26 @@ error_free: return NULL; } + +girara_completion_t* +cc_bookmarks(girara_session_t* session, char* input) +{ + g_return_val_if_fail(session != NULL, NULL); + g_return_val_if_fail(session->global.data != NULL, NULL); + zathura_t* zathura = session->global.data; + + girara_completion_t* completion = girara_completion_init(); + girara_completion_group_t* group = girara_completion_group_create(session, NULL); + + const size_t input_length = input ? strlen(input) : 0; + + GIRARA_LIST_FOREACH(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + if (input_length <= strlen(bookmark->id) && !strncmp(input, bookmark->id, input_length)) { + gchar* paged = g_strdup_printf("Page %d", bookmark->page); + girara_completion_group_add_element(group, bookmark->id, paged); + g_free(paged); + } + GIRARA_LIST_FOREACH_END(zathura->bookmarks.bookmarks, zathura_bookmark_t*, iter, bookmark) + + return completion; +} diff --git a/completion.h b/completion.h index 7041d8a..9de1d91 100644 --- a/completion.h +++ b/completion.h @@ -15,4 +15,14 @@ */ girara_completion_t* cc_open(girara_session_t* session, char* input); +/** + * Completion for the bmarks command - Creates a list of bookmarks + * + * @param session The used girara session + * @param input The current input + * @return The completion object or NULL if an error occured + */ +girara_completion_t* cc_bookmarks(girara_session_t* session, char* input); + + #endif // COMPLETION_H diff --git a/config.c b/config.c index b54aea8..fd71d49 100644 --- a/config.c +++ b/config.c @@ -107,16 +107,16 @@ config_load_default(zathura_t* zathura) girara_shortcut_add(gsession, 0, 0, "z0", sc_zoom, NORMAL | FULLSCREEN, ZOOM_ORIGINAL, NULL); /* 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, NULL, "Delete a bookmark"); - girara_inputbar_command_add(gsession, "blist", NULL, cmd_bookmark_open, NULL, "List all bookmarks"); - 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, "help", NULL, cmd_help, NULL, "Show help"); - girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); - girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, "Print document"); - girara_inputbar_command_add(gsession, "write", NULL, cmd_save, NULL, "Save document"); - girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, NULL, "Save document (and force overwriting)"); + 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, "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, "help", NULL, cmd_help, NULL, "Show help"); + girara_inputbar_command_add(gsession, "open", "o", cmd_open, cc_open, "Open document"); + girara_inputbar_command_add(gsession, "print", NULL, cmd_print, NULL, "Print document"); + girara_inputbar_command_add(gsession, "write", NULL, cmd_save, NULL, "Save document"); + girara_inputbar_command_add(gsession, "write!", NULL, cmd_savef, NULL, "Save document (and force overwriting)"); /* add shortcut mappings */ girara_shortcut_mapping_add(gsession, "abort", sc_abort);