Revision: 5036 http://geany.svn.sourceforge.net/geany/?rev=5036&view=rev Author: statc Date: 2010-06-17 14:53:18 +0000 (Thu, 17 Jun 2010)
Log Message: ----------- Apply patch from Dimitar Zhekov to improve saving of project configuration files together with some refactoring.
* limit Project -> Properties to saving the preferences only; * limit project_close() to saving the file list only; * use enums instead of separate functions for saving particular types of settings.
Modified Paths: -------------- branches/sm/ChangeLog.sm branches/sm/src/document.c branches/sm/src/keyfile.c branches/sm/src/keyfile.h branches/sm/src/main.c branches/sm/src/prefs.c branches/sm/src/project.c branches/sm/src/project.h branches/sm/src/ui_utils.c
Modified: branches/sm/ChangeLog.sm =================================================================== --- branches/sm/ChangeLog.sm 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/ChangeLog.sm 2010-06-17 14:53:18 UTC (rev 5036) @@ -1,3 +1,12 @@ +2010-06-16 Eugene Arshinov <earshinov(at)gmail(dot)com> + + * src/document.c, src/keyfile.c, src/keyfile.h, src/main.c, src/prefs.c, + src/project.c, src/project.h src/ui_utils.c: + Apply patch from Dimitar Zhekov to improve saving of project + configuration files: + - limit Project -> Properties to saving the preferences only; + - limit project_close() to saving the file list only. + 2010-05-31 Eugene Arshinov <earshinov(at)gmail(dot)com>
* src/callbacks.c, src/document.c, src/document.h, src/keyfile.c,
Modified: branches/sm/src/document.c =================================================================== --- branches/sm/src/document.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/document.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -1402,7 +1402,7 @@ document_open_file_full(NULL, filename, 0, FALSE, NULL, NULL, FALSE); g_free(filename); } - configuration_save_recent_files(); + configuration_save(GEANY_SETTINGS_RECENT_FILES);
g_strfreev(list); } @@ -1425,7 +1425,7 @@ { document_open_file_full(NULL, item->data, 0, readonly, ft, forced_enc, FALSE); } - configuration_save_recent_files(); + configuration_save(GEANY_SETTINGS_RECENT_FILES); }
Modified: branches/sm/src/keyfile.c =================================================================== --- branches/sm/src/keyfile.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/keyfile.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -368,12 +368,8 @@ }
-void configuration_save_dialog_prefs(void) +static void save_dialog_prefs(GKeyFile *config) { - GKeyFile *config; - gchar *configfile; - open_config(&config, &configfile); - /* new settings should be added in init_pref_groups() */ settings_action(config, SETTING_WRITE);
@@ -521,9 +517,6 @@ g_key_file_set_string(config, "VTE", "last_dir", vte_info.dir); } #endif - - write_config(config, configfile); - close_config(config, configfile); }
@@ -578,7 +571,7 @@ }
-void configuration_save(void) +void configuration_save(GeanySettingsTypes flags) { GKeyFile *config; gchar *configfile; @@ -587,49 +580,35 @@ /* 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_ui_prefs(config); - project_save_prefs(config); /* save project filename, etc. */ + if (flags & GEANY_SETTINGS_DIALOG) + save_dialog_prefs(config);
- if (cl_options.load_session) - configuration_save_session_files(config); + if (flags & GEANY_SETTINGS_RUNTIME) + { + save_ui_prefs(config); + project_save_prefs(config); /* save project filename, etc. */
- write_config(config, configfile); - close_config(config, configfile); -} + if (cl_options.load_session) + configuration_save_session_files(config); + }
+ if (flags & GEANY_SETTINGS_RECENT_FILES) + { + load_recent_files(config, ui_prefs.recent_queue, "recent_files"); + save_recent_files(config, ui_prefs.recent_queue, "recent_files"); + }
-/* Write recent file names to geany.conf. - * Clears `ui_prefs.recent_queue'. */ -void configuration_save_recent_files(void) -{ - GKeyFile *config; - gchar *configfile; - open_config(&config, &configfile); + if (flags & GEANY_SETTINGS_RECENT_PROJECTS) + { + load_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); + save_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); + }
- load_recent_files(config, ui_prefs.recent_queue, "recent_files"); - save_recent_files(config, ui_prefs.recent_queue, "recent_files"); - write_config(config, configfile); close_config(config, configfile); }
-/* Write recent project file names to geany.conf. - * Clears `ui_prefs.recent_projects_queue'. */ -void configuration_save_recent_projects(void) -{ - GKeyFile *config; - gchar *configfile; - open_config(&config, &configfile); - - load_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); - save_recent_files(config, ui_prefs.recent_projects_queue, "recent_projects"); - - write_config(config, configfile); - close_config(config, configfile); -} - - /* * Load session list from the given keyfile, and store it in the global * session_files variable for later file loading
Modified: branches/sm/src/keyfile.h =================================================================== --- branches/sm/src/keyfile.h 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/keyfile.h 2010-06-17 14:53:18 UTC (rev 5036) @@ -29,6 +29,17 @@ extern GPtrArray *pref_groups;
+/* Flags for configuration_save() */ +typedef enum +{ + GEANY_SETTINGS_RUNTIME = 1, + GEANY_SETTINGS_DIALOG = 2, + GEANY_SETTINGS_RECENT_FILES = 4, + GEANY_SETTINGS_RECENT_PROJECTS = 8, + GEANY_SETTINGS_ALL = 15 +} GeanySettingsTypes; + + void configuration_init(void);
void configuration_finalize(void); @@ -37,14 +48,8 @@
void configuration_add_pref_group(struct StashGroup *group, gboolean for_prefs_dialog);
-void configuration_save_dialog_prefs(void); +void configuration_save(GeanySettingsTypes flags);
-void configuration_save(void); - -void configuration_save_recent_files(void); - -void configuration_save_recent_projects(void); - gboolean configuration_load(void);
void configuration_open_files(void);
Modified: branches/sm/src/main.c =================================================================== --- branches/sm/src/main.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/main.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -784,7 +784,7 @@ /* Used for command-line arguments at startup or from socket. * this will strip any :line:col filename suffix from locale_filename. * - * After calling this function use configuration_save_recent_files() to + * After calling this function use configuration_save(GEANY_SETTINGS_RECENT_FILES) to * update list of recent files stored in geany.conf. */ gboolean main_handle_filename(const gchar *locale_filename) { @@ -852,7 +852,7 @@ } g_free(filename); } - configuration_save_recent_files(); + configuration_save(GEANY_SETTINGS_RECENT_FILES); }
@@ -1202,10 +1202,10 @@ return FALSE;
if (!cl_options.new_instance) - configuration_save(); + configuration_save(GEANY_SETTINGS_RUNTIME);
if (app->project) - project_save(FALSE); + project_save(FALSE, GEANY_PROJECT_SETTINGS_RUNTIME);
return TRUE; }
Modified: branches/sm/src/prefs.c =================================================================== --- branches/sm/src/prefs.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/prefs.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -1181,8 +1181,8 @@ ui_document_show_hide(NULL); ui_update_view_editor_menu_items();
- /* store all settings */ - configuration_save_dialog_prefs(); + /* store dialog settings */ + configuration_save(GEANY_SETTINGS_DIALOG); }
if (response != GTK_RESPONSE_APPLY)
Modified: branches/sm/src/project.c =================================================================== --- branches/sm/src/project.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/project.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -79,11 +79,10 @@ } PropertyDialogElements;
- static gboolean update_config(const PropertyDialogElements *e); static void on_file_save_button_clicked(GtkButton *button, PropertyDialogElements *e); static gboolean load_config(const gchar *filename); -static gboolean write_config(gboolean emit_signal); +static gboolean write_config(gboolean emit_signal, GeanyProjectSettingsTypes flags); static void on_name_entry_changed(GtkEditable *editable, PropertyDialogElements *e); static void on_entries_changed(GtkEditable *editable, PropertyDialogElements *e); static void on_radio_long_line_custom_toggled(GtkToggleButton *radio, GtkWidget *spin_long_line); @@ -331,9 +330,9 @@ }
-void project_save(gboolean emit_signal) +void project_save(gboolean emit_signal, GeanyProjectSettingsTypes flags) { - write_config(emit_signal); + write_config(emit_signal, flags); }
@@ -346,7 +345,7 @@
/* use write_config() to save project session files */ if (save_config) - write_config(FALSE); + write_config(FALSE, GEANY_PROJECT_SETTINGS_RUNTIME);
/* remove project filetypes build entries */ if (app->project->build_filetypes_list != NULL) @@ -797,11 +796,17 @@ g_free(tmp); #endif } - write_config(TRUE); + if (new_project) + { + write_config(TRUE, GEANY_PROJECT_SETTINGS_ALL); ui_set_statusbar(TRUE, _("Project "%s" created."), p->name); + } else + { + write_config(TRUE, GEANY_PROJECT_SETTINGS_DIALOG); ui_set_statusbar(TRUE, _("Project "%s" saved."), p->name); + }
update_ui();
@@ -1036,7 +1041,7 @@ * is called while closing a project, this is used to skip emitting the signal because * project-close will be emitted afterwards. * Returns: TRUE if project file was written successfully. */ -static gboolean write_config(gboolean emit_signal) +static gboolean write_config(gboolean emit_signal, GeanyProjectSettingsTypes flags) { GeanyProject *p; GKeyFile *config; @@ -1053,24 +1058,32 @@ filename = utils_get_locale_from_utf8(p->file_name); g_key_file_load_from_file(config, filename, G_KEY_FILE_NONE, NULL);
- stash_group_save_to_key_file(indent_group, config); + if (flags & GEANY_PROJECT_SETTINGS_DIALOG) + { + stash_group_save_to_key_file(indent_group, config);
- g_key_file_set_string(config, "project", "name", p->name); - g_key_file_set_string(config, "project", "base_path", p->base_path); + g_key_file_set_string(config, "project", "name", p->name); + g_key_file_set_string(config, "project", "base_path", p->base_path);
- if (p->description) - g_key_file_set_string(config, "project", "description", p->description); - if (p->file_patterns) - g_key_file_set_string_list(config, "project", "file_patterns", - (const gchar**) p->file_patterns, g_strv_length(p->file_patterns)); + if (p->description) + g_key_file_set_string(config, "project", "description", p->description); + if (p->file_patterns) + g_key_file_set_string_list(config, "project", "file_patterns", + (const gchar**) p->file_patterns, g_strv_length(p->file_patterns));
- g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->long_line_behaviour); - g_key_file_set_integer(config, "long line marker", "long_line_column", p->long_line_column); + g_key_file_set_integer(config, "long line marker", "long_line_behaviour", p->long_line_behaviour); + g_key_file_set_integer(config, "long line marker", "long_line_column", p->long_line_column);
- /* store the session files into the project too */ - if (project_prefs.project_session) - configuration_save_session_files(config); - build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ); + build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ); + } + + if (flags & GEANY_PROJECT_SETTINGS_RUNTIME) + { + /* store the session files into the project too */ + if (project_prefs.project_session) + configuration_save_session_files(config); + } + if (emit_signal) { g_signal_emit_by_name(geany_object, "project-save", config);
Modified: branches/sm/src/project.h =================================================================== --- branches/sm/src/project.h 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/project.h 2010-06-17 14:53:18 UTC (rev 5036) @@ -61,6 +61,14 @@ extern ProjectPrefs project_prefs;
+/* Flags for project_save() */ +typedef enum { + GEANY_PROJECT_SETTINGS_RUNTIME = 1, + GEANY_PROJECT_SETTINGS_DIALOG = 2, + GEANY_PROJECT_SETTINGS_ALL = 3, +} GeanyProjectSettingsTypes; + + void project_init(void);
void project_finalize(void); @@ -70,7 +78,7 @@
void project_open(void);
-void project_save(gboolean emit_signal); +void project_save(gboolean emit_signal, GeanyProjectSettingsTypes flags);
void project_close(gboolean save_config, gboolean open_default);
Modified: branches/sm/src/ui_utils.c =================================================================== --- branches/sm/src/ui_utils.c 2010-06-17 14:52:47 UTC (rev 5035) +++ branches/sm/src/ui_utils.c 2010-06-17 14:53:18 UTC (rev 5036) @@ -1030,7 +1030,7 @@ if (document_open_file(locale_filename, FALSE, NULL, NULL) != NULL) { recent_file_loaded(utf8_filename, recent_get_recent_files()); - configuration_save_recent_files(); + configuration_save(GEANY_SETTINGS_RECENT_FILES); }
g_free(locale_filename); @@ -1046,7 +1046,7 @@ if (project_ask_close() && project_load_file_with_session(locale_filename)) { recent_file_loaded(utf8_filename, recent_get_recent_projects()); - configuration_save_recent_projects(); + configuration_save(GEANY_SETTINGS_RECENT_PROJECTS); }
g_free(locale_filename); @@ -1095,14 +1095,14 @@ { add_recent_file(utf8_filename, recent_get_recent_files()); if (update_config) - configuration_save_recent_files(); + configuration_save(GEANY_SETTINGS_RECENT_FILES); }
void ui_add_recent_project_file(const gchar *utf8_filename) { add_recent_file(utf8_filename, recent_get_recent_projects()); - configuration_save_recent_projects(); + configuration_save(GEANY_SETTINGS_RECENT_PROJECTS); }
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.