Refactor notification when writing files

This commit is contained in:
Sebastian Ramacher 2020-09-03 22:51:31 +02:00
parent c6b50cbdcb
commit a17a6e5e83
2 changed files with 11 additions and 13 deletions

View file

@ -313,11 +313,7 @@ cmd_save(girara_session_t* session, girara_list_t* argument_list)
} }
if (girara_list_size(argument_list) == 1) { if (girara_list_size(argument_list) == 1) {
if (document_save(zathura, girara_list_nth(argument_list, 0), false) == true) { document_save(zathura, girara_list_nth(argument_list, 0), false);
girara_notify(session, GIRARA_INFO, _("Document saved."));
} else {
girara_notify(session, GIRARA_INFO, _("Failed to save document."));
}
} else { } else {
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments.")); girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments."));
return false; return false;
@ -339,11 +335,7 @@ cmd_savef(girara_session_t* session, girara_list_t* argument_list)
} }
if (girara_list_size(argument_list) == 1) { if (girara_list_size(argument_list) == 1) {
if (document_save(zathura, girara_list_nth(argument_list, 0), true) == true) { document_save(zathura, girara_list_nth(argument_list, 0), true);
girara_notify(session, GIRARA_INFO, _("Document saved."));
} else {
girara_notify(session, GIRARA_INFO, _("Failed to save document."));
}
} else { } else {
girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments.")); girara_notify(session, GIRARA_ERROR, _("Invalid number of arguments."));
return false; return false;

View file

@ -1356,15 +1356,21 @@ document_save(zathura_t* zathura, const char* path, bool overwrite)
} }
if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) { if ((overwrite == false) && g_file_test(file_path, G_FILE_TEST_EXISTS)) {
girara_error("File already exists: %s. Use :write! to overwrite it.", file_path); girara_notify(zathura->ui.session, GIRARA_ERROR, _("File already exists: %s. Use :write! to overwrite it."), file_path);
g_free(file_path); g_free(file_path);
return false; return false;
} }
zathura_error_t error = zathura_document_save_as(zathura->document, file_path); const zathura_error_t error = zathura_document_save_as(zathura->document, file_path);
g_free(file_path); g_free(file_path);
return (error == ZATHURA_ERROR_OK) ? true : false; if (error != ZATHURA_ERROR_OK) {
girara_notify(zathura->ui.session, GIRARA_ERROR, _("Failed to save document."));
return false;
}
girara_notify(zathura->ui.session, GIRARA_INFO, _("Document saved."));
return true;
} }
static void static void