diff --git a/data/geany.glade b/data/geany.glade index 71327353c4..5cf890809e 100644 --- a/data/geany.glade +++ b/data/geany.glade @@ -4601,6 +4601,22 @@ 3 + + + Default to last save directory + True + True + False + Default to last save directory + True + True + + + False + False + 4 + + diff --git a/src/dialogs.c b/src/dialogs.c index 5fe792e7ad..4333d3f1ff 100644 --- a/src/dialogs.c +++ b/src/dialogs.c @@ -39,6 +39,7 @@ #include "utils.h" #include "ui_utils.h" #include "win32.h" +#include "prefs.h" #include #include @@ -509,6 +510,16 @@ static gboolean handle_save_as(const gchar *utf8_filename, gboolean rename_file) } success = document_save_file_as(doc, utf8_filename); + if (success && file_prefs.remember_last_save_path) + { + /* save the last used path for the next time we save the same path is used */ + if (prefs.last_save_path != NULL) + { + g_free(prefs.last_save_path); + } + prefs.last_save_path = g_path_get_dirname(utf8_filename); + } + build_menu_update(doc); return success; } diff --git a/src/document.h b/src/document.h index 4533d26033..36bf52bd38 100644 --- a/src/document.h +++ b/src/document.h @@ -67,6 +67,7 @@ typedef struct GeanyFilePrefs gboolean show_keep_edit_history_on_reload_msg; /* whether to show the message introducing the above feature */ gboolean reload_clean_doc_on_file_change; gboolean save_config_on_file_change; + gboolean remember_last_save_path; } GeanyFilePrefs; diff --git a/src/keyfile.c b/src/keyfile.c index 90ad79a86e..900c4631a4 100644 --- a/src/keyfile.c +++ b/src/keyfile.c @@ -267,6 +267,8 @@ static void init_pref_groups(void) stash_group_add_boolean(group, &ui_prefs.allow_always_save, "allow_always_save", FALSE); + stash_group_add_string(group, &prefs.last_save_path, "last_save_path", NULL); + group = stash_group_new(PACKAGE); configuration_add_various_pref_group(group, "search"); @@ -508,6 +510,7 @@ static void save_dialog_prefs(GKeyFile *config) g_key_file_set_boolean(config, PACKAGE, "pref_editor_new_line", file_prefs.final_new_line); g_key_file_set_boolean(config, PACKAGE, "pref_editor_ensure_convert_line_endings", file_prefs.ensure_convert_new_lines); g_key_file_set_boolean(config, PACKAGE, "pref_editor_replace_tabs", file_prefs.replace_tabs); + g_key_file_set_boolean(config, PACKAGE, "pref_editor_remember_last_save_path", file_prefs.remember_last_save_path); g_key_file_set_boolean(config, PACKAGE, "pref_editor_trail_space", file_prefs.strip_trailing_spaces); /* toolbar */ @@ -869,6 +872,7 @@ static void load_dialog_prefs(GKeyFile *config) } file_prefs.default_eol_character = utils_get_setting_integer(config, PACKAGE, "default_eol_character", GEANY_DEFAULT_EOL_CHARACTER); file_prefs.replace_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_replace_tabs", FALSE); + file_prefs.remember_last_save_path = utils_get_setting_boolean(config, PACKAGE, "pref_editor_remember_last_save_path", FALSE); file_prefs.ensure_convert_new_lines = utils_get_setting_boolean(config, PACKAGE, "pref_editor_ensure_convert_line_endings", FALSE); file_prefs.final_new_line = utils_get_setting_boolean(config, PACKAGE, "pref_editor_new_line", TRUE); file_prefs.strip_trailing_spaces = utils_get_setting_boolean(config, PACKAGE, "pref_editor_trail_space", FALSE); diff --git a/src/libmain.c b/src/libmain.c index d316f440ac..43995cb97a 100644 --- a/src/libmain.c +++ b/src/libmain.c @@ -1324,6 +1324,7 @@ static gboolean do_main_quit(void) g_free(printing_prefs.page_header_datefmt); g_strfreev(ui_prefs.custom_commands); g_strfreev(ui_prefs.custom_commands_labels); + g_free(prefs.last_save_path); queue_free(ui_prefs.recent_queue); queue_free(ui_prefs.recent_projects_queue); diff --git a/src/prefs.c b/src/prefs.c index a5d4761217..29286fb078 100644 --- a/src/prefs.c +++ b/src/prefs.c @@ -589,6 +589,9 @@ static void prefs_init_dialog(void) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.replace_tabs); + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_remember_last_save_dir"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), file_prefs.remember_last_save_path); + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_indent"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.show_indent_guide); @@ -1048,6 +1051,8 @@ on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_replace_tabs"); file_prefs.replace_tabs = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_remember_last_save_dir"); + file_prefs.remember_last_save_path = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); /* Editor settings */ widget = ui_lookup_widget(ui_widgets.prefs_dialog, "entry_toggle_mark"); diff --git a/src/prefs.h b/src/prefs.h index 09b8c7ba6d..6b8ad02164 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -42,6 +42,7 @@ typedef struct GeanyPrefs #ifdef G_OS_WIN32 gint socket_remote_cmd_port; #endif + gchar *last_save_path; /**< Last path used to save a file. */ } GeanyPrefs; diff --git a/src/utils.c b/src/utils.c index 5659bc7369..c52c0b342e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -1618,6 +1618,11 @@ const gchar *utils_get_default_dir_utf8(void) { return app->project->base_path; } + + if (file_prefs.remember_last_save_path && !EMPTY(prefs.last_save_path)) + { + return prefs.last_save_path; + } if (!EMPTY(prefs.default_open_path)) {