From 5376a48e3fc4da7a7fbf28d4e6da59bae62580f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 20 Feb 2017 15:53:43 +0100 Subject: [PATCH 1/2] Always emit the project-save signal when writing project file For some reason "project-save" isn't emitted when closing project - see write_config(FALSE) in project_close(). This means that in this case plugins cannot save their configuration into the config file. This doesn't even correspond to the documentation of the signal "Sent when a project is saved (happens when the project is created, the properties dialog is closed or Geany is exited)" as the signal isn't emitted when exiting Geany because at this point Geany closes the project. The comment seems to indicate that the reason is that "project-save" shouldn't be emitted when "project-close" is emitted but I don't see any reason why. Bump API so plugins can rely on the changed behavior. --- doc/pluginsignals.c | 5 +++-- src/plugindata.h | 2 +- src/project.c | 20 +++++++------------- 3 files changed, 11 insertions(+), 16 deletions(-) diff --git a/doc/pluginsignals.c b/doc/pluginsignals.c index 6030f14570..d43c945820 100644 --- a/doc/pluginsignals.c +++ b/doc/pluginsignals.c @@ -142,8 +142,9 @@ 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 or Geany is exited). This signal is emitted shortly before Geany - * will write the contents of the GKeyFile to the disc. + * dialog is closed, before the project is closed, or when Geany is exited). + * This signal is emitted shortly before Geany will write the contents of the + * GKeyFile to the disc. * * @param obj a GeanyObject instance, should be ignored. * @param config an existing GKeyFile object which can be used to read and write data. diff --git a/src/plugindata.h b/src/plugindata.h index 6a021556c4..fb06a512aa 100644 --- a/src/plugindata.h +++ b/src/plugindata.h @@ -59,7 +59,7 @@ G_BEGIN_DECLS * @warning You should not test for values below 200 as previously * @c GEANY_API_VERSION was defined as an enum value, not a macro. */ -#define GEANY_API_VERSION 230 +#define GEANY_API_VERSION 231 /* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins * with GTK3-linked Geany leads to crash */ diff --git a/src/project.c b/src/project.c index f107df6fc5..07b3c995d7 100644 --- a/src/project.c +++ b/src/project.c @@ -83,7 +83,7 @@ typedef struct _PropertyDialogElements static gboolean update_config(const PropertyDialogElements *e, gboolean new_project); 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(void); 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); @@ -246,7 +246,7 @@ void project_new(void) if (update_config(&e, TRUE)) { // app->project is now set - if (!write_config(TRUE)) + if (!write_config()) { SHOW_ERR(_("Project file could not be written")); destroy_project(FALSE); @@ -404,7 +404,7 @@ gboolean project_close(gboolean open_default) g_return_val_if_fail(app->project != NULL, FALSE); /* save project session files, etc */ - if (!write_config(FALSE)) + if (!write_config()) g_warning("Project file \"%s\" could not be written", app->project->file_name); if (project_prefs.project_session) @@ -619,7 +619,7 @@ static void show_project_properties(gboolean show_build) if (update_config(&e, FALSE)) { g_signal_emit_by_name(geany_object, "project-dialog-confirmed", e.notebook); - if (!write_config(TRUE)) + if (!write_config()) SHOW_ERR(_("Project file could not be written")); else { @@ -1092,11 +1092,8 @@ static void apply_editor_prefs(void) /* Write the project settings as well as the project session files into its configuration files. - * emit_signal defines whether the project-save signal should be emitted. When write_config() - * 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(void) { GeanyProject *p; GKeyFile *config; @@ -1134,10 +1131,7 @@ static gboolean write_config(gboolean emit_signal) if (project_prefs.project_session) configuration_save_session_files(config); build_save_menu(config, (gpointer)p, GEANY_BCS_PROJ); - if (emit_signal) - { - g_signal_emit_by_name(geany_object, "project-save", config); - } + g_signal_emit_by_name(geany_object, "project-save", config); /* write the file */ data = g_key_file_to_data(config, NULL, NULL); ret = (utils_write_file(filename, data) == 0); @@ -1158,7 +1152,7 @@ static gboolean write_config(gboolean emit_signal) GEANY_API_SYMBOL void project_write_config(void) { - if (!write_config(TRUE)) + if (!write_config()) SHOW_ERR(_("Project file could not be written")); } From 0770c85be26578c5695618b0290ab8299e323570 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Mon, 20 Feb 2017 16:17:17 +0100 Subject: [PATCH 2/2] filebrowser: Don't change directory on project save This behavior might be unwanted when changing project settings which is unrelated to project base path and also fixes filebrowser behavior with the updated way project-save signal is emitted. The patch also handles the situation where "realized" is called after project-save is called and overrides file browser's path (which is something we don't want). --- plugins/filebrowser.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/plugins/filebrowser.c b/plugins/filebrowser.c index 25a8c33624..b5fe39a430 100644 --- a/plugins/filebrowser.c +++ b/plugins/filebrowser.c @@ -101,13 +101,12 @@ static struct } popup_items; -static void project_change_cb(GObject *obj, GKeyFile *config, gpointer data); +static void project_open_cb(GObject *obj, GKeyFile *config, gpointer data); /* note: other callbacks connected in plugin_init */ PluginCallback plugin_callbacks[] = { - { "project-open", (GCallback) &project_change_cb, TRUE, NULL }, - { "project-save", (GCallback) &project_change_cb, TRUE, NULL }, + { "project-open", (GCallback) &project_open_cb, TRUE, NULL }, { NULL, NULL, FALSE, NULL } }; @@ -396,6 +395,16 @@ static void on_current_path(void) } +static void on_realized(void) +{ + GeanyProject *project = geany->app->project; + + /* if fb_set_project_base_path and project open, the path has already been set */ + if (! fb_set_project_base_path || project == NULL || EMPTY(project->base_path)) + on_current_path(); +} + + static void on_go_up(void) { gsize len = strlen(current_dir); @@ -891,7 +900,7 @@ static void prepare_file_view(void) gtk_tree_selection_set_mode(selection, GTK_SELECTION_MULTIPLE); /* Show the current path when the FB is first needed */ - g_signal_connect(file_view, "realize", G_CALLBACK(on_current_path), NULL); + g_signal_connect(file_view, "realize", G_CALLBACK(on_realized), NULL); g_signal_connect(selection, "changed", G_CALLBACK(on_tree_selection_changed), NULL); g_signal_connect(file_view, "button-press-event", G_CALLBACK(on_button_press), NULL); g_signal_connect(file_view, "key-press-event", G_CALLBACK(on_key_press), NULL); @@ -1039,8 +1048,8 @@ static void load_settings(void) } -static void project_change_cb(G_GNUC_UNUSED GObject *obj, G_GNUC_UNUSED GKeyFile *config, - G_GNUC_UNUSED gpointer data) +static void project_open_cb(G_GNUC_UNUSED GObject *obj, G_GNUC_UNUSED GKeyFile *config, + G_GNUC_UNUSED gpointer data) { gchar *new_dir; GeanyProject *project = geany->app->project;