mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 09:26:00 +01:00
cc_open: List only supported file types
This commit is contained in:
parent
a5d8cf8724
commit
caa058e4d2
3 changed files with 60 additions and 2 deletions
27
completion.c
27
completion.c
|
@ -67,10 +67,14 @@ cc_print(girara_session_t* session, char* input)
|
|||
girara_completion_t*
|
||||
cc_open(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);
|
||||
|
||||
if (!session || !input || !completion || !group) {
|
||||
if (!input || !completion || !group) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
|
@ -113,11 +117,30 @@ cc_open(girara_session_t* session, char* input)
|
|||
/* read files */
|
||||
char* name = NULL;
|
||||
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
|
||||
char* e_name = g_filename_display_name(name);
|
||||
char* e_name = g_filename_display_name(name);
|
||||
if (e_name == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
char* full_path = g_strdup_printf("%s/%s", path, e_name);
|
||||
if (full_path == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
if (file_valid_extension(zathura, full_path) == true) {
|
||||
girara_completion_group_add_element(group, full_path, NULL);
|
||||
}
|
||||
|
||||
g_free(full_path);
|
||||
g_free(e_name);
|
||||
}
|
||||
|
||||
g_dir_close(dir);
|
||||
/* given path is a file */
|
||||
} else if (g_file_test(path, G_FILE_TEST_IS_REGULAR) == TRUE) {
|
||||
if (file_valid_extension(zathura, path) == true) {
|
||||
girara_completion_group_add_element(group, path, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
|
|
25
utils.c
25
utils.c
|
@ -48,6 +48,31 @@ file_get_extension(const char* path)
|
|||
return path + i + 1;
|
||||
}
|
||||
|
||||
bool
|
||||
file_valid_extension(zathura_t* zathura, const char* path)
|
||||
{
|
||||
if (path == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const char* file_extension = file_get_extension(path);
|
||||
|
||||
girara_list_iterator_t* iter = girara_list_iterator(zathura->plugins.plugins);
|
||||
if (iter == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
do {
|
||||
zathura_document_plugin_t* plugin = (zathura_document_plugin_t*) girara_list_iterator_data(iter);
|
||||
if (!strcmp(file_extension, plugin->file_extension)) {
|
||||
return true;
|
||||
}
|
||||
} while (girara_list_iterator_next(iter));
|
||||
girara_list_iterator_free(iter);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
execute_command(char* const argv[], char** output)
|
||||
{
|
||||
|
|
10
utils.h
10
utils.h
|
@ -31,6 +31,16 @@ bool file_exists(const char* path);
|
|||
*/
|
||||
const char* file_get_extension(const char* path);
|
||||
|
||||
/**
|
||||
* This function checks if the file has a valid extension. A extension is
|
||||
* evaluated as valid if it matches a supported filetype.
|
||||
*
|
||||
* @param zathura Zathura object
|
||||
* @param path The path to the file
|
||||
* @return true if the extension is valid, otherwise false
|
||||
*/
|
||||
bool file_valid_extension(zathura_t* zathura, const char* path);
|
||||
|
||||
/**
|
||||
* Executes a system command and saves its output into output
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue