diff --git a/doc/man/zathurarc.5.rst b/doc/man/zathurarc.5.rst index 85a4656..15023bc 100644 --- a/doc/man/zathurarc.5.rst +++ b/doc/man/zathurarc.5.rst @@ -820,6 +820,28 @@ Defines if the last/first page should be wrapped * Value type: Boolean * Default value: false + +show-directories +^^^^^^^^^^^^^^^^ +Defines if the directories should be displayed in completion. + +* Value type: Boolean +* Default value: true + +show-hidden +^^^^^^^^^^^ +Defines if hidden files and directories should be displayed in completion. + +* Value type: Boolean +* Default value: false + +show-recent +^^^^^^^^^^^ +Defines if recent files should be displayed in completion. + +* Value type: Boolean +* Default value: true + scroll-page-aware ^^^^^^^^^^^^^^^^^ Defines if scrolling by half or full pages stops at page boundaries. diff --git a/zathura/completion.c b/zathura/completion.c index d558fd0..708c12d 100644 --- a/zathura/completion.c +++ b/zathura/completion.c @@ -12,6 +12,7 @@ #include "completion.h" #include "utils.h" #include "page.h" +#include "database.h" #include #include @@ -32,7 +33,7 @@ compare_case_insensitive(const char* str1, const char* str2) static girara_list_t* list_files(zathura_t* zathura, const char* current_path, const char* current_file, - unsigned int current_file_length, bool is_dir, bool check_file_ext) + size_t current_file_length, bool is_dir, bool check_file_ext) { if (zathura == NULL || zathura->ui.session == NULL || current_path == NULL) { return NULL; @@ -113,15 +114,20 @@ error_free: } static girara_completion_t* -list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext) +list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext, bool include_history) { girara_completion_t* completion = girara_completion_init(); - girara_completion_group_t* group = girara_completion_group_create(zathura->ui.session, NULL); + girara_completion_group_t* group = girara_completion_group_create(zathura->ui.session, "files"); + girara_completion_group_t* history_group = NULL; gchar* path = NULL; gchar* current_path = NULL; - if (completion == NULL || group == NULL) { + if (include_history == true) { + history_group = girara_completion_group_create(zathura->ui.session, "recent files"); + } + + if (completion == NULL || group == NULL || (include_history == true && history_group == NULL)) { goto error_free; } @@ -169,12 +175,12 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext) /* get current file */ gchar* current_file = is_dir ? "" : basename(path); - int current_file_length = strlen(current_file); + const size_t current_file_length = strlen(current_file); /* read directory */ if (g_file_test(current_path, G_FILE_TEST_IS_DIR) == TRUE) { girara_list_t* names = list_files(zathura, current_path, current_file, current_file_length, is_dir, check_file_ext); - if (!names) { + if (names == NULL) { goto error_free; } @@ -184,10 +190,26 @@ list_files_for_cc(zathura_t* zathura, const char* input, bool check_file_ext) girara_list_free(names); } + if (include_history == true) { + girara_list_t* recent_files = zathura_db_get_recent_files(zathura->database); + if (recent_files == NULL) { + goto error_free; + } + + const size_t path_len = strlen(path); + GIRARA_LIST_FOREACH(recent_files, const char*, iter, file) + if (strncmp(path, file, path_len) == 0) { + girara_completion_group_add_element(history_group, file, NULL); + } + GIRARA_LIST_FOREACH_END(recent_files, const char*, iter, file); + girara_list_free(recent_files); + } + g_free(path); g_free(current_path); girara_completion_add_group(completion, group); + girara_completion_add_group(completion, history_group); return completion; @@ -196,6 +218,9 @@ error_free: if (completion) { girara_completion_free(completion); } + if (history_group) { + girara_completion_group_free(history_group); + } if (group) { girara_completion_group_free(group); } @@ -213,7 +238,10 @@ cc_open(girara_session_t* session, const char* input) g_return_val_if_fail(session->global.data != NULL, NULL); zathura_t* zathura = session->global.data; - return list_files_for_cc(zathura, input, true); + bool show_recent = true; + girara_setting_get(zathura->ui.session, "show-recent", &show_recent); + + return list_files_for_cc(zathura, input, true, show_recent); } girara_completion_t* @@ -223,7 +251,7 @@ cc_write(girara_session_t* session, const char* input) g_return_val_if_fail(session->global.data != NULL, NULL); zathura_t* zathura = session->global.data; - return list_files_for_cc(zathura, input, false); + return list_files_for_cc(zathura, input, false, false); } girara_completion_t* diff --git a/zathura/config.c b/zathura/config.c index 245911a..8e4e101 100644 --- a/zathura/config.c +++ b/zathura/config.c @@ -212,6 +212,8 @@ config_load_default(zathura_t* zathura) girara_setting_add(gsession, "show-hidden", &bool_value, BOOLEAN, false, _("Show hidden files and directories"), NULL, NULL); bool_value = true; girara_setting_add(gsession, "show-directories", &bool_value, BOOLEAN, false, _("Show directories"), NULL, NULL); + bool_value = true; + girara_setting_add(gsession, "show-recent", &bool_value, BOOLEAN, false, _("Show recent files"), NULL, NULL); bool_value = false; girara_setting_add(gsession, "open-first-page", &bool_value, BOOLEAN, false, _("Always open on first page"), NULL, NULL); bool_value = false;