Skip to content

Commit

Permalink
session.conf split follow-up #3 (geany#3014)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
kugel- committed Feb 17, 2022
1 parent da12533 commit be739e2
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 31 deletions.
68 changes: 38 additions & 30 deletions src/keyfile.c
Expand Up @@ -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
{
Expand All @@ -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);
Expand All @@ -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;
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}


Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();

Expand All @@ -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);
}
2 changes: 2 additions & 0 deletions src/keyfile.h
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion src/search.c
Expand Up @@ -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);
Expand Down

0 comments on commit be739e2

Please sign in to comment.