[geany/geany] 0da0fd: Merge pull request #2114 from eht16/save_config_on_doclist_change
Enrico Tröger
git-noreply at xxxxx
Sun Oct 6 17:10:27 UTC 2019
Branch: refs/heads/master
Author: Enrico Tröger <enrico.troeger at uvena.de>
Committer: GitHub <noreply at github.com>
Date: Sun, 06 Oct 2019 17:10:27 UTC
Commit: 0da0fd4073ca0afa238d56172eb26ce3585a4cf7
https://github.com/geany/geany/commit/0da0fd4073ca0afa238d56172eb26ce3585a4cf7
Log Message:
-----------
Merge pull request #2114 from eht16/save_config_on_doclist_change
Save main and project configuration whenever documents are opened/closed
Modified Paths:
--------------
doc/geany.txt
doc/pluginsignals.c
src/document.h
src/keyfile.c
Modified: doc/geany.txt
14 lines changed, 12 insertions(+), 2 deletions(-)
===================================================================
@@ -2636,6 +2636,16 @@ reload_clean_doc_on_file_change Whether to automatically reload documents f
on disk.
If unsaved changes exist then the user is
prompted to reload manually.
+save_config_on_file_change Automatically save Geany's configuration true immediately
+ to disk once the document list changes
+ (i.e. new documents are opened, saved or
+ closed). This helps to prevent accidentally
+ losing the session file list or other
+ changed settings when Geany is not shut
+ down cleanly. Disable this option if your
+ configuration directory is on a slow drive,
+ network share or similar and you experience
+ problems.
extract_filetype_regex Regex to extract filetype name from file See link immediately
via capture group one.
See `ft_regex`_ for default.
@@ -4715,8 +4725,8 @@ The key names cannot be configured.
Group membership is only read at startup.
.. tip::
- You can make commonly used filetypes appear in the top-level of the
- filetype menu by adding them to the `None` group, e.g.
+ You can make commonly used filetypes appear in the top-level of the
+ filetype menu by adding them to the `None` group, e.g.
`None=C;Python`.
Preferences file format
Modified: doc/pluginsignals.c
3 lines changed, 2 insertions(+), 1 deletions(-)
===================================================================
@@ -141,7 +141,8 @@ signal void (*document_close)(GObject *obj, GeanyDocument *doc, gpointer user_da
signal void (*project_open)(GObject *obj, GKeyFile *config, gpointer user_data);
/** Sent when a project is saved (happens when the project is created, the properties
- * dialog is closed, before the project is closed, or when Geany is exited).
+ * dialog is closed, before the project is closed, when Geany automatically
+ * saves its configuration by opening/closing documents or when Geany is exited).
* This signal is emitted shortly before Geany will write the contents of the
* GKeyFile to the disc.
*
Modified: src/document.h
1 lines changed, 1 insertions(+), 0 deletions(-)
===================================================================
@@ -66,6 +66,7 @@ typedef struct GeanyFilePrefs
gboolean keep_edit_history_on_reload; /* Keep undo stack upon, and allow undoing of, document reloading. */
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;
}
GeanyFilePrefs;
Modified: src/keyfile.c
42 lines changed, 41 insertions(+), 1 deletions(-)
===================================================================
@@ -106,6 +106,7 @@ static GPtrArray *session_files = NULL;
static gint session_notebook_page;
static gint hpan_position;
static gint vpan_position;
+static guint document_list_update_idle_func_id = 0;
static const gchar atomic_file_saving_key[] = "use_atomic_file_saving";
static GPtrArray *keyfile_groups = NULL;
@@ -258,6 +259,8 @@ static void init_pref_groups(void)
"show_keep_edit_history_on_reload_msg", TRUE);
stash_group_add_boolean(group, &file_prefs.reload_clean_doc_on_file_change,
"reload_clean_doc_on_file_change", FALSE);
+ stash_group_add_boolean(group, &file_prefs.save_config_on_file_change,
+ "save_config_on_file_change", TRUE);
stash_group_add_string(group, &file_prefs.extract_filetype_regex,
"extract_filetype_regex", GEANY_DEFAULT_FILETYPE_REGEX);
stash_group_add_boolean(group, &ui_prefs.allow_always_save,
@@ -274,7 +277,7 @@ static void init_pref_groups(void)
/* Note: Interface-related various prefs are in ui_init_prefs() */
/* various build-menu prefs */
- // Warning: don't move PACKAGE group name items here
+ // Warning: don't move PACKAGE group name items here
group = stash_group_new("build-menu");
configuration_add_various_pref_group(group, "build");
@@ -1327,11 +1330,46 @@ void configuration_apply_settings(void)
}
+static gboolean save_configuration_cb(gpointer data)
+{
+ configuration_save();
+ if (app->project != NULL)
+ {
+ project_write_config();
+ }
+ document_list_update_idle_func_id = 0;
+ return G_SOURCE_REMOVE;
+}
+
+
+static void document_list_changed_cb(GObject *obj, GeanyDocument *doc, gpointer data)
+{
+ g_return_if_fail(doc != NULL && doc->is_valid);
+
+ /* save configuration, especially session file list, but only if we are not just starting
+ * and not about to quit */
+ if (file_prefs.save_config_on_file_change &&
+ main_status.main_window_realized &&
+ !main_status.opening_session_files &&
+ !main_status.quitting)
+ {
+ if (document_list_update_idle_func_id == 0)
+ {
+ document_list_update_idle_func_id = g_idle_add(save_configuration_cb, NULL);
+ }
+ }
+}
+
+
void configuration_init(void)
{
keyfile_groups = g_ptr_array_new();
pref_groups = g_ptr_array_new();
init_pref_groups();
+
+ g_signal_connect(geany_object, "document-open", G_CALLBACK(document_list_changed_cb), NULL);
+ g_signal_connect(geany_object, "document-save", G_CALLBACK(document_list_changed_cb), NULL);
+ g_signal_connect(geany_object, "document-close", G_CALLBACK(document_list_changed_cb), NULL);
}
@@ -1340,6 +1378,8 @@ void configuration_finalize(void)
guint i;
StashGroup *group;
+ g_signal_handlers_disconnect_by_func(geany_object, G_CALLBACK(document_list_changed_cb), NULL);
+
foreach_ptr_array(group, i, keyfile_groups)
stash_group_free(group);
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Commits
mailing list