mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2024-12-29 11:55:59 +01:00
Began to implement cmd_open completion
This commit is contained in:
parent
7a0f870ff1
commit
bd37f6333e
5 changed files with 102 additions and 0 deletions
|
@ -41,6 +41,12 @@ cmd_info(girara_session_t* session, girara_list_t* argument_list)
|
|||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
cmd_open(girara_session_t* session, girara_list_t* argument_list)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
cmd_print(girara_session_t* session, girara_list_t* argument_list)
|
||||
{
|
||||
|
|
|
@ -51,6 +51,15 @@ bool cmd_close(girara_session_t* session, girara_list_t* argument_list);
|
|||
*/
|
||||
bool cmd_info(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
/**
|
||||
* Opens a document file
|
||||
*
|
||||
* @param session The used girara session
|
||||
* @param argument_list List of passed arguments
|
||||
* @return true if no error occured
|
||||
*/
|
||||
bool cmd_open(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
/**
|
||||
* Print the current file
|
||||
*
|
||||
|
|
76
completion.c
76
completion.c
|
@ -63,3 +63,79 @@ cc_print(girara_session_t* session, char* input)
|
|||
|
||||
return completion;
|
||||
}
|
||||
|
||||
girara_completion_t*
|
||||
cc_open(girara_session_t* session, char* input)
|
||||
{
|
||||
girara_completion_t* completion = girara_completion_init();
|
||||
girara_completion_group_t* group = girara_completion_group_create(session, NULL);
|
||||
|
||||
if (!session || !input || !completion || !group) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
gchar* path = girara_fix_path(input);
|
||||
if (path == NULL || strlen(path) == 0) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* If the path does not begin with a slash we update the path with the current
|
||||
* working directory */
|
||||
if (path[0] != '/') {
|
||||
size_t path_max;
|
||||
#ifdef PATH_MAX
|
||||
path_max = PATH_MAX;
|
||||
#else
|
||||
path_max = pathconf(path,_PC_PATH_MAX);
|
||||
if (path_max <= 0)
|
||||
path_max = 4096;
|
||||
#endif
|
||||
|
||||
char cwd[path_max];
|
||||
getcwd(cwd, path_max);
|
||||
|
||||
char* tmp_path = g_strdup_printf("%s/%s", cwd, path);
|
||||
if (tmp_path == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
path = tmp_path;
|
||||
}
|
||||
|
||||
/* read directory */
|
||||
if (g_file_test(path, G_FILE_TEST_IS_DIR) == TRUE) {
|
||||
GDir* dir = g_dir_open(path, 0, NULL);
|
||||
if (dir == NULL) {
|
||||
goto error_free;
|
||||
}
|
||||
|
||||
/* read files */
|
||||
char* name = NULL;
|
||||
while ((name = (char*) g_dir_read_name(dir)) != NULL) {
|
||||
char* e_name = g_filename_display_name(name);
|
||||
g_free(e_name);
|
||||
}
|
||||
|
||||
g_dir_close(dir);
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
|
||||
girara_completion_add_group(completion, group);
|
||||
|
||||
return completion;
|
||||
|
||||
error_free:
|
||||
|
||||
if (completion) {
|
||||
girara_completion_free(completion);
|
||||
}
|
||||
if (group) {
|
||||
girara_completion_group_free(group);
|
||||
}
|
||||
|
||||
g_free(path);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
10
completion.h
10
completion.h
|
@ -14,4 +14,14 @@
|
|||
*/
|
||||
girara_completion_t* cc_print(girara_session_t* session, char* input);
|
||||
|
||||
/**
|
||||
* Completion for the open command - Creates a list of accesible directories or
|
||||
* files
|
||||
*
|
||||
* @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_open(girara_session_t* session, char* input);
|
||||
|
||||
#endif // COMPLETION_H
|
||||
|
|
1
config.c
1
config.c
|
@ -111,6 +111,7 @@ config_load_default(zathura_t* zathura)
|
|||
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, "open", "o", cmd_open, cc_open, "Open document");
|
||||
girara_inputbar_command_add(gsession, "print", NULL, cmd_print, cc_print, "Print document");
|
||||
girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save document");
|
||||
|
||||
|
|
Loading…
Reference in a new issue