[geany/geany] be739e: session.conf split follow-up #3 (#3014)

Thomas Martitz git-noreply at xxxxx
Thu Feb 17 21:36:55 UTC 2022


Branch:      refs/heads/master
Author:      Thomas Martitz <thomas.martitz at mailbox.org>
Committer:   GitHub <noreply at github.com>
Date:        Thu, 17 Feb 2022 21:36:55 UTC
Commit:      be739e28a6e29aeb08912af36620a4fb78b31176
             https://github.com/geany/geany/commit/be739e28a6e29aeb08912af36620a4fb78b31176

Log Message:
-----------
session.conf split follow-up #3 (#3014)

Move search positions and layout to session.conf

This will remember the x,y positions as well as the find/replace
dialog expanders as part of session.conf.

To implemenet this, a new interface configuration_add_session_group()
is created that connects a StashGroup to session.conf.


Modified Paths:
--------------
    src/keyfile.c
    src/keyfile.h
    src/search.c

Modified: src/keyfile.c
68 lines changed, 38 insertions(+), 30 deletions(-)
===================================================================
@@ -113,9 +113,16 @@ 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;
+typedef enum
+{
+	PREFS,
+	SESSION,
+
+	MAX_PAYLOAD
+} ConfigPayload;
 
-GPtrArray *pref_groups = NULL;
+static GPtrArray *keyfile_groups[MAX_PAYLOAD];
+GPtrArray *pref_groups;
 
 static struct
 {
@@ -125,12 +132,11 @@ static struct
 }
 build_menu_prefs;
 
-
 /* The group will be free'd on quitting.
  * @param for_prefs_dialog is whether the group also has Prefs dialog items. */
 void configuration_add_pref_group(struct StashGroup *group, gboolean for_prefs_dialog)
 {
-	g_ptr_array_add(keyfile_groups, group);
+	g_ptr_array_add(keyfile_groups[PREFS], group);
 
 	if (for_prefs_dialog)
 		g_ptr_array_add(pref_groups, group);
@@ -147,6 +153,14 @@ void configuration_add_various_pref_group(struct StashGroup *group,
 }
 
 
+/* The group will be free'd on quitting.
+ * @param for_prefs_dialog is whether the group also has Prefs dialog items. */
+void configuration_add_session_group(struct StashGroup *group)
+{
+	g_ptr_array_add(keyfile_groups[SESSION], group);
+}
+
+
 static void init_pref_groups(void)
 {
 	StashGroup *group;
@@ -309,12 +323,12 @@ typedef enum SettingAction
 }
 SettingAction;
 
-static void settings_action(GKeyFile *config, SettingAction action)
+static void settings_action(GKeyFile *config, SettingAction action, ConfigPayload payload)
 {
 	guint i;
 	StashGroup *group;
 
-	foreach_ptr_array(group, i, keyfile_groups)
+	foreach_ptr_array(group, i, keyfile_groups[payload])
 	{
 		switch (action)
 		{
@@ -440,9 +454,6 @@ void configuration_save_session_files(GKeyFile *config)
 
 static void save_dialog_prefs(GKeyFile *config)
 {
-	/* new settings should be added in init_pref_groups() */
-	settings_action(config, SETTING_WRITE);
-
 	/* Some of the key names are not consistent, but this is for backwards compatibility */
 
 	/* general */
@@ -578,12 +589,6 @@ static void save_dialog_prefs(GKeyFile *config)
 #endif
 }
 
-typedef enum ConfigPayload
-{
-	PREFS,
-	SESSION
-}
-ConfigPayload;
 
 static void save_ui_prefs(GKeyFile *config)
 {
@@ -672,6 +677,10 @@ void write_config_file(gchar const *filename, ConfigPayload payload)
 #endif
 			break;
 	}
+
+	/* new settings should be added in init_pref_groups() */
+	settings_action(config, SETTING_WRITE, payload);
+
 	/* write the file */
 	data = g_key_file_to_data(config, NULL, NULL);
 	utils_write_file(configfile, data);
@@ -1028,16 +1037,6 @@ static void load_dialog_prefs(GKeyFile *config)
 	printing_prefs.print_page_header = utils_get_setting_boolean(config, "printing", "print_page_header", TRUE);
 	printing_prefs.page_header_basename = utils_get_setting_boolean(config, "printing", "page_header_basename", FALSE);
 	printing_prefs.page_header_datefmt = utils_get_setting_string(config, "printing", "page_header_datefmt", "%c");
-
-	/* read stash prefs */
-	settings_action(config, SETTING_READ);
-
-	/* build menu
-	 * after stash prefs as it uses some of them */
-	build_set_group_count(GEANY_GBG_FT, build_menu_prefs.number_ft_menu_items);
-	build_set_group_count(GEANY_GBG_NON_FT, build_menu_prefs.number_non_ft_menu_items);
-	build_set_group_count(GEANY_GBG_EXEC, build_menu_prefs.number_exec_menu_items);
-	build_load_menu(config, GEANY_BCS_PREF, NULL);
 }
 
 
@@ -1200,17 +1199,27 @@ gboolean read_config_file(gchar const *filename, ConfigPayload payload)
 	g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
 	g_free(configfile);
 
+	/* read stash prefs */
+	settings_action(config, SETTING_READ, payload);
+
 	switch (payload)
 	{
 		case PREFS:
 			load_dialog_prefs(config);
 			load_ui_prefs(config);
+
+			/* build menu, after stash prefs as it uses some of them */
+			build_set_group_count(GEANY_GBG_FT, build_menu_prefs.number_ft_menu_items);
+			build_set_group_count(GEANY_GBG_NON_FT, build_menu_prefs.number_non_ft_menu_items);
+			build_set_group_count(GEANY_GBG_EXEC, build_menu_prefs.number_exec_menu_items);
+			build_load_menu(config, GEANY_BCS_PREF, NULL);
 			/* this signal can be used e.g. to delay building UI elements until settings have been read */
 			g_signal_emit_by_name(geany_object, "load-settings", config);
 			break;
 		case SESSION:
 			project_load_prefs(config);
 			load_ui_session(config);
+			/* read stash prefs */
 			configuration_load_session_files(config, TRUE);
 			break;
 	}
@@ -1432,7 +1441,8 @@ static void document_list_changed_cb(GObject *obj, GeanyDocument *doc, gpointer
 
 void configuration_init(void)
 {
-	keyfile_groups = g_ptr_array_new();
+	keyfile_groups[PREFS] = g_ptr_array_new_with_free_func((GDestroyNotify) stash_group_free);
+	keyfile_groups[SESSION] = g_ptr_array_new_with_free_func((GDestroyNotify) stash_group_free);
 	pref_groups = g_ptr_array_new();
 	init_pref_groups();
 
@@ -1449,9 +1459,7 @@ void configuration_finalize(void)
 
 	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);
-
-	g_ptr_array_free(keyfile_groups, TRUE);
 	g_ptr_array_free(pref_groups, TRUE);
+	g_ptr_array_free(keyfile_groups[SESSION], TRUE);
+	g_ptr_array_free(keyfile_groups[PREFS], TRUE);
 }


Modified: src/keyfile.h
2 lines changed, 2 insertions(+), 0 deletions(-)
===================================================================
@@ -40,6 +40,8 @@ void configuration_add_pref_group(struct StashGroup *group, gboolean for_prefs_d
 void configuration_add_various_pref_group(struct StashGroup *group,
 	const gchar *prefix);
 
+void configuration_add_session_group(struct StashGroup *group);
+
 void configuration_save(void);
 
 gboolean configuration_load(void);


Modified: src/search.c
5 lines changed, 4 insertions(+), 1 deletions(-)
===================================================================
@@ -198,9 +198,12 @@ static void init_prefs(void)
 		"pref_search_always_wrap", FALSE, "check_hide_find_dialog");
 	stash_group_add_toggle_button(group, &search_prefs.use_current_file_dir,
 		"pref_search_current_file_dir", TRUE, "check_fif_current_dir");
+
+	/* dialog layout & positions */
+	group = stash_group_new("search");
+	configuration_add_session_group(group);
 	stash_group_add_boolean(group, &find_dlg.all_expanded, "find_all_expanded", FALSE);
 	stash_group_add_boolean(group, &replace_dlg.all_expanded, "replace_all_expanded", FALSE);
-	/* dialog positions */
 	stash_group_add_integer(group, &find_dlg.position[0], "position_find_x", -1);
 	stash_group_add_integer(group, &find_dlg.position[1], "position_find_y", -1);
 	stash_group_add_integer(group, &replace_dlg.position[0], "position_replace_x", -1);



--------------
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