mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 08:45:59 +01:00
completion for bookmarks
This commit is contained in:
parent
225bc75baf
commit
b614508e16
3 changed files with 44 additions and 10 deletions
24
completion.c
24
completion.c
|
@ -6,6 +6,7 @@
|
|||
#include <unistd.h>
|
||||
#include <libgen.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
10
completion.h
10
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
|
||||
|
|
20
config.c
20
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);
|
||||
|
|
Loading…
Reference in a new issue