[geany/geany] 26996a: Save main and project configuration whenever documents are opened/closed

Enrico Tröger git-noreply at xxxxx
Thu Oct 3 08:01:10 UTC 2019


Branch:      refs/heads/master
Author:      Enrico Tröger <enrico.troeger at uvena.de>
Committer:   Enrico Tröger <enrico.troeger at uvena.de>
Date:        Thu, 03 Oct 2019 08:01:10 UTC
Commit:      26996aa1aaec0d48c0cc4fa6519d4876e4d57855
             https://github.com/geany/geany/commit/26996aa1aaec0d48c0cc4fa6519d4876e4d57855

Log Message:
-----------
Save main and project configuration whenever documents are opened/closed

The main idea is to save the session file list more often to prevent
accidental lost but saving the rest of the configuration might help
as well.
To prevent too many save attempts, an idle function is used and it's
only added once until it was executed.


Modified Paths:
--------------
    doc/pluginsignals.c
    src/keyfile.c

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/keyfile.c
37 lines changed, 37 insertions(+), 0 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;
@@ -1327,11 +1328,45 @@ 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 (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 +1375,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