Branch: refs/heads/master Author: Adam Morris adam.morris@cern.ch Committer: GitHub noreply@github.com Date: Wed, 07 Apr 2021 11:07:13 UTC Commit: b11d05a53cd3a18861b85b9da24f8ea9a6c6c93a https://github.com/geany/geany/commit/b11d05a53cd3a18861b85b9da24f8ea9a6c6c9...
Log Message: ----------- Split geany.conf into geany.conf (preferences) and session.conf (recent files and VTE session) (#2776)
Related to #1763.
## New behaviour
Preferences are written to and read from `geany.conf` (like before), whereas "session data" is written to and read from `session.conf`.
For the sake of backwards compatibility, if `session.conf` does not exist, the data is read from `geany.conf` instead.
## Implementation
I introduced an `enum` in `src/keyfile.c` called `ConfigPayload` which determines whether to read/write preference-data or session-data.
The strings `"geany.conf"` and `"session.conf"` are now defined as preprocessor macros `PREFERENCES_FILE` and `SESSION_FILE`, respectively.
## Matters of taste - The old recent files are not cleared from `geany.conf` - The string `"geany.conf"` still appears in `src/keybindings.c` and `src/libmain.c`, so changing the `PREFERENCES_FILE` macro in `src/keyfile.c` is not enough to rename this file.
Modified Paths: -------------- src/keyfile.c
Modified: src/keyfile.c 109 lines changed, 76 insertions(+), 33 deletions(-) =================================================================== @@ -66,6 +66,9 @@ #include <unistd.h> #endif
+/* define the configuration filenames */ +#define PREFS_FILE "geany.conf" +#define SESSION_FILE "session.conf"
/* some default settings which are used at the very first start of Geany to fill * the configuration file */ @@ -628,34 +631,44 @@ static void save_ui_prefs(GKeyFile *config) } }
+typedef enum ConfigPayload +{ + PREFS, + SESSION +} +ConfigPayload;
-void configuration_save(void) +void write_config_file(gchar const *filename, ConfigPayload payload) { GKeyFile *config = g_key_file_new(); - gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL); + gchar *configfile = g_build_filename(app->configdir, filename, NULL); gchar *data;
g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
- /* this signal can be used e.g. to prepare any settings before Stash code reads them below */ - g_signal_emit_by_name(geany_object, "save-settings", config); - - save_dialog_prefs(config); - save_ui_prefs(config); - project_save_prefs(config); /* save project filename, etc. */ - save_recent_files(config, ui_prefs.recent_queue, "recent_files"); - save_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); - - if (cl_options.load_session) - configuration_save_session_files(config); -#ifdef HAVE_VTE - else if (vte_info.have_vte) + switch (payload) { - vte_get_working_directory(); /* refresh vte_info.dir */ - g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir); - } + case PREFS: + /* this signal can be used e.g. to prepare any settings before Stash code reads them below */ + g_signal_emit_by_name(geany_object, "save-settings", config); + save_dialog_prefs(config); + save_ui_prefs(config); + project_save_prefs(config); /* save project filename, etc. */ + break; + case SESSION: + save_recent_files(config, ui_prefs.recent_queue, "recent_files"); + save_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); + if (cl_options.load_session) + configuration_save_session_files(config); +#ifdef HAVE_VTE + else if (vte_info.have_vte) + { + vte_get_working_directory(); /* refresh vte_info.dir */ + g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir); + } #endif - + break; + } /* write the file */ data = g_key_file_to_data(config, NULL, NULL); utils_write_file(configfile, data); @@ -665,6 +678,14 @@ void configuration_save(void) g_free(configfile); }
+void configuration_save(void) +{ + /* save all configuration files + * it is probably not very efficient to write both files every time + * could be more selective about which file is saved when */ + write_config_file(PREFS_FILE, PREFS); + write_config_file(SESSION_FILE, SESSION); +}
static void load_recent_files(GKeyFile *config, GQueue *queue, const gchar *key) { @@ -1103,7 +1124,7 @@ static void load_ui_prefs(GKeyFile *config) */ void configuration_save_default_session(void) { - gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL); + gchar *configfile = g_build_filename(app->configdir, PREFS_FILE, NULL); gchar *data; GKeyFile *config = g_key_file_new();
@@ -1124,7 +1145,7 @@ void configuration_save_default_session(void)
void configuration_clear_default_session(void) { - gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL); + gchar *configfile = g_build_filename(app->configdir, SESSION_FILE, NULL); gchar *data; GKeyFile *config = g_key_file_new();
@@ -1148,7 +1169,7 @@ void configuration_clear_default_session(void) */ void configuration_reload_default_session(void) { - gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL); + gchar *configfile = g_build_filename(app->configdir, SESSION_FILE, NULL); GKeyFile *config = g_key_file_new();
g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); @@ -1159,34 +1180,56 @@ void configuration_reload_default_session(void) g_key_file_free(config); }
- -gboolean configuration_load(void) +gboolean read_config_file(gchar const *filename, ConfigPayload payload) { - gchar *configfile = g_build_filename(app->configdir, "geany.conf", NULL); + gchar *configfile = g_build_filename(app->configdir, filename, NULL); GKeyFile *config = g_key_file_new();
if (! g_file_test(configfile, G_FILE_TEST_IS_REGULAR)) { /* config file does not (yet) exist, so try to load a global config file which may be */ /* created by distributors */ geany_debug("No user config file found, trying to use global configuration."); - SETPTR(configfile, g_build_filename(app->datadir, "geany.conf", NULL)); + SETPTR(configfile, g_build_filename(app->datadir, filename, NULL)); } g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL); g_free(configfile);
- load_dialog_prefs(config); - load_ui_prefs(config); - project_load_prefs(config); - configuration_load_session_files(config, TRUE); - - /* 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); + switch (payload) + { + case PREFS: + load_dialog_prefs(config); + load_ui_prefs(config); + project_load_prefs(config); + /* 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: + configuration_load_session_files(config, TRUE); + break; + }
g_key_file_free(config); return TRUE; }
+gboolean configuration_load(void) +{ + gboolean prefs_loaded = read_config_file(PREFS_FILE, PREFS); + /* backwards-compatibility: try to read session from preferences if session file doesn't exist */ + gchar *session_filename = SESSION_FILE; + gchar *session_file = g_build_filename(app->configdir, session_filename, NULL); + if (! g_file_test(session_file, G_FILE_TEST_IS_REGULAR)) + { + geany_debug("No user session file found, trying to use configuration file."); + session_filename = PREFS_FILE; + } + g_free(session_file); + gboolean sess_loaded = read_config_file(session_filename, SESSION); + return prefs_loaded && sess_loaded; +} + + static gboolean open_session_file(gchar **tmp, guint len) { guint pos;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).