mirror of
https://git.pwmt.org/pwmt/zathura.git
synced 2025-02-27 08:14:39 +01:00
implement :write and :write!
This commit is contained in:
parent
36bdb57bf4
commit
87aa9b9a46
6 changed files with 88 additions and 2 deletions
40
commands.c
40
commands.c
|
@ -91,5 +91,45 @@ cmd_print(girara_session_t* session, girara_list_t* argument_list)
|
|||
bool
|
||||
cmd_save(girara_session_t* session, girara_list_t* argument_list)
|
||||
{
|
||||
g_return_val_if_fail(session != NULL, false);
|
||||
g_return_val_if_fail(session->global.data != NULL, false);
|
||||
zathura_t* zathura = session->global.data;
|
||||
|
||||
if (zathura->document == NULL) {
|
||||
girara_error("no document as been opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (girara_list_size(argument_list) == 1) {
|
||||
document_save(zathura, girara_list_nth(argument_list, 0), false);
|
||||
}
|
||||
else {
|
||||
girara_error("invalid arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool
|
||||
cmd_savef(girara_session_t* session, girara_list_t* argument_list)
|
||||
{
|
||||
g_return_val_if_fail(session != NULL, false);
|
||||
g_return_val_if_fail(session->global.data != NULL, false);
|
||||
zathura_t* zathura = session->global.data;
|
||||
|
||||
if (zathura->document == NULL) {
|
||||
girara_error("no document as been opened");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (girara_list_size(argument_list) == 1) {
|
||||
document_save(zathura, girara_list_nth(argument_list, 0), true);
|
||||
}
|
||||
else {
|
||||
girara_error("invalid arguments");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
10
commands.h
10
commands.h
|
@ -78,4 +78,14 @@ bool cmd_print(girara_session_t* session, girara_list_t* argument_list);
|
|||
*/
|
||||
bool cmd_save(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
/**
|
||||
* Save the current file and overwrite existing files
|
||||
*
|
||||
* @param session The used girara session
|
||||
* @param argument_list List of passed arguments
|
||||
* @return true if no error occured
|
||||
*/
|
||||
bool cmd_savef(girara_session_t* session, girara_list_t* argument_list);
|
||||
|
||||
|
||||
#endif // COMMANDS_H
|
||||
|
|
3
config.c
3
config.c
|
@ -114,7 +114,8 @@ config_load_default(zathura_t* zathura)
|
|||
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, NULL, "Print document");
|
||||
girara_inputbar_command_add(gsession, "save", NULL, cmd_save, NULL, "Save 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);
|
||||
|
|
|
@ -160,7 +160,9 @@ sc_scroll(girara_session_t* session, girara_argument_t* argument, unsigned int t
|
|||
g_return_val_if_fail(session->global.data != NULL, false);
|
||||
zathura_t* zathura = session->global.data;
|
||||
g_return_val_if_fail(argument != NULL, false);
|
||||
g_return_val_if_fail(zathura->document != NULL, false);
|
||||
if (zathura->document == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
GtkAdjustment* adjustment = NULL;
|
||||
if ( (argument->n == LEFT) || (argument->n == RIGHT) )
|
||||
|
|
21
zathura.c
21
zathura.c
|
@ -309,6 +309,27 @@ error_out:
|
|||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
document_save(zathura_t* zathura, const char* path, bool overwrite)
|
||||
{
|
||||
g_return_val_if_fail(zathura, false);
|
||||
g_return_val_if_fail(zathura->document, false);
|
||||
g_return_val_if_fail(path, false);
|
||||
|
||||
gchar* file_path = girara_fix_path(path);
|
||||
if (!overwrite && g_file_test(file_path, G_FILE_TEST_EXISTS))
|
||||
{
|
||||
gchar* message = g_strdup_printf("File already exists: %s. Use :write! to overwrite it.", file_path);
|
||||
girara_error(message);
|
||||
g_free(message);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool res = zathura_document_save_as(zathura->document, file_path);
|
||||
g_free(file_path);
|
||||
return res;
|
||||
}
|
||||
|
||||
static void
|
||||
remove_page_from_table(GtkWidget* page, gpointer permanent)
|
||||
{
|
||||
|
|
12
zathura.h
12
zathura.h
|
@ -114,6 +114,18 @@ void zathura_free(zathura_t* zathura);
|
|||
*/
|
||||
bool document_open(zathura_t* zathura, const char* path, const char* password);
|
||||
|
||||
/**
|
||||
* Save a open file
|
||||
*
|
||||
* @param zathura The zathura session
|
||||
* @param path The path
|
||||
* @param overwrite Overwrite existing file
|
||||
*
|
||||
* @return If no error occured true, otherwise false, is returned.
|
||||
*/
|
||||
bool document_save(zathura_t* zathura, const char* path, bool overwrite);
|
||||
|
||||
|
||||
/**
|
||||
* Closes the current opened document
|
||||
*
|
||||
|
|
Loading…
Add table
Reference in a new issue