SF.net SVN: geany:[3425] trunk

ntrel at users.sourceforge.net ntrel at xxxxx
Sun Dec 28 13:21:35 UTC 2008


Revision: 3425
          http://geany.svn.sourceforge.net/geany/?rev=3425&view=rev
Author:   ntrel
Date:     2008-12-28 13:21:35 +0000 (Sun, 28 Dec 2008)

Log Message:
-----------
Don't forget active plugins after disabling plugin support.
Use Stash for plugin-related prefs.
Add geany_object "save-settings" signal (for core only).
Add stash_group_add_string_vector().

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/geanyobject.c
    trunk/src/geanyobject.h
    trunk/src/keyfile.c
    trunk/src/main.c
    trunk/src/plugins.c
    trunk/src/plugins.h
    trunk/src/prefs.c
    trunk/src/stash.c
    trunk/src/stash.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/ChangeLog	2008-12-28 13:21:35 UTC (rev 3425)
@@ -1,3 +1,14 @@
+2008-12-28  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
+
+ * src/prefs.c, src/geanyobject.c, src/geanyobject.h, src/stash.c,
+   src/stash.h, src/keyfile.c, src/plugins.c, src/main.c,
+   src/plugins.h:
+   Don't forget active plugins after disabling plugin support.
+   Use Stash for plugin-related prefs.
+   Add geany_object "save-settings" signal (for core only).
+   Add stash_group_add_string_vector().
+
+
 2008-12-27  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>
 
  * src/interface.c, src/interface.h, src/project.c, src/project.h,

Modified: trunk/src/geanyobject.c
===================================================================
--- trunk/src/geanyobject.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/geanyobject.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -22,9 +22,14 @@
  * $Id$
  */
 
-/* GObject used for connecting and emitting signals when certain events happen,
+/* A GObject used for connecting and emitting signals when certain events happen,
  * e.g. opening a document.
- * Mainly used for plugins - geany_object is created in plugins_init(). */
+ * Mainly used for plugins - see the API docs.
+ *
+ * Core-only signals:
+ * signal void save_settings(GObject *obj, GKeyFile *keyfile, gpointer user_data);
+ * Emitted just before saving main keyfile settings.
+ */
 
 #include "geany.h"
 #include "geanyobject.h"
@@ -255,6 +260,17 @@
 		geany_cclosure_marshal_BOOL__POINTER_POINTER,
 		G_TYPE_BOOLEAN, 2,
 		G_TYPE_POINTER, G_TYPE_POINTER);
+
+	/* Core-only signals */
+	geany_object_signals[GCB_SAVE_SETTINGS] = g_signal_new (
+		"save-settings",
+		G_OBJECT_CLASS_TYPE (g_object_class),
+		G_SIGNAL_RUN_FIRST,
+		G_STRUCT_OFFSET (GeanyObjectClass, save_settings),
+		NULL, NULL,
+		g_cclosure_marshal_VOID__POINTER,
+		G_TYPE_NONE, 1,
+		G_TYPE_POINTER);
 }
 
 

Modified: trunk/src/geanyobject.h
===================================================================
--- trunk/src/geanyobject.h	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/geanyobject.h	2008-12-28 13:21:35 UTC (rev 3425)
@@ -44,8 +44,10 @@
 	GCB_PROJECT_CLOSE,
 	GCB_UPDATE_EDITOR_MENU,
 	GCB_EDITOR_NOTIFY,
+	GCB_SAVE_SETTINGS,
 	GCB_MAX
-} GeanyCallbackId;
+}
+GeanyCallbackId;
 
 
 #define GEANY_OBJECT_TYPE				(geany_object_get_type())
@@ -83,6 +85,7 @@
 	void (*project_close)(void);
 	void (*update_editor_menu)(const gchar *word, gint click_pos, GeanyDocument *doc);
 	gboolean (*editor_notify)(GeanyEditor *editor, gpointer scnt);
+	void (*save_settings)(GKeyFile *keyfile);
 };
 
 GType		geany_object_get_type	(void);

Modified: trunk/src/keyfile.c
===================================================================
--- trunk/src/keyfile.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/keyfile.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -57,10 +57,10 @@
 #include "project.h"
 #include "editor.h"
 #include "printing.h"
-#include "plugins.h"
 #include "templates.h"
 #include "toolbar.h"
 #include "stash.h"
+#include "geanyobject.h"
 
 
 /* some default settings which are used at the very first start of Geany to fill
@@ -493,10 +493,10 @@
 
 	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);
-#ifdef HAVE_PLUGINS
-	plugins_save_prefs(config);
-#endif
 	save_ui_prefs(config);
 	project_save_prefs(config);	/* save project filename, etc. */
 	save_recent_files(config);
@@ -877,9 +877,6 @@
 	g_key_file_load_from_file(config, configfile, G_KEY_FILE_NONE, NULL);
 
 	load_dialog_prefs(config);
-#ifdef HAVE_PLUGINS
-	plugins_load_prefs(config);
-#endif
 	load_ui_prefs(config);
 	project_load_prefs(config);
 	configuration_load_session_files(config);

Modified: trunk/src/main.c
===================================================================
--- trunk/src/main.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/main.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -919,10 +919,14 @@
 
 	encodings_init();
 	editor_init();
-	project_init();
 
 	configuration_init();
+	/* init stash code before loading keyfile */
 	search_init();
+	project_init();
+#ifdef HAVE_PLUGINS
+	plugins_init();
+#endif
 	load_settings();
 
 	msgwin_init();
@@ -983,7 +987,7 @@
 #ifdef HAVE_PLUGINS
 	/* load any enabled plugins before we open any documents */
 	if (want_plugins)
-		plugins_init();
+		plugins_load_active();
 #endif
 
 	/* load keybinding settings after plugins have added their groups */
@@ -1037,8 +1041,7 @@
 #endif
 
 #ifdef HAVE_PLUGINS
-	if (want_plugins)
-		plugins_free();
+	plugins_finalize();
 #endif
 
 	navqueue_free();

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/plugins.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -59,6 +59,8 @@
 #include "navqueue.h"
 #include "main.h"
 #include "toolbar.h"
+#include "stash.h"
+#include "keyfile.h"
 
 
 #ifdef G_OS_WIN32
@@ -95,6 +97,8 @@
 Plugin;
 
 
+static gboolean want_plugins = FALSE;
+
 /* list of all available, loadable plugins, only valid as long as the plugin manager dialog is
  * opened, afterwards it will be destroyed */
 static GList *plugin_list = NULL;
@@ -833,10 +837,13 @@
 }
 
 
-void plugins_init()
+/* Calling this starts up plugin support */
+void plugins_load_active(void)
 {
 	GtkWidget *widget;
 
+	want_plugins = TRUE;
+
 	geany_data_init();
 
 	widget = gtk_separator_menu_item_new();
@@ -903,31 +910,32 @@
 }
 
 
-void plugins_save_prefs(GKeyFile *config)
+static void on_save_settings(GKeyFile *config)
 {
-	g_key_file_set_boolean(config, "plugins", "load_plugins", prefs.load_plugins);
-
-	update_active_plugins_pref();
-	if (active_plugins_pref != NULL)
-		g_key_file_set_string_list(config, "plugins", "active_plugins",
-			(const gchar**)active_plugins_pref, g_strv_length(active_plugins_pref));
-	else
-	{
-		/* use an empty dummy array to override maybe exisiting value */
-		const gchar *dummy[] = { "" };
-		g_key_file_set_string_list(config, "plugins", "active_plugins", dummy, 1);
-	}
+	/* if plugins are disabled, don't clear list of active plugins */
+	if (want_plugins)
+		update_active_plugins_pref();
 }
 
 
-void plugins_load_prefs(GKeyFile *config)
+/* called even if plugin support is disabled */
+void plugins_init(void)
 {
-	prefs.load_plugins = utils_get_setting_boolean(config, "plugins", "load_plugins", TRUE);
-	active_plugins_pref = g_key_file_get_string_list(config, "plugins", "active_plugins", NULL, NULL);
+	GeanyPrefGroup *group;
+
+	group = stash_group_new("plugins");
+	configuration_add_pref_group(group, TRUE);
+
+	stash_group_add_toggle_button(group, &prefs.load_plugins,
+		"load_plugins", TRUE, "check_plugins");
+
+	g_signal_connect(geany_object, "save-settings", G_CALLBACK(on_save_settings), NULL);
+	stash_group_add_string_vector(group, &active_plugins_pref, "active_plugins", NULL);
 }
 
 
-void plugins_free(void)
+/* called even if plugin support is disabled */
+void plugins_finalize(void)
 {
 	if (failed_plugins_list != NULL)
 	{

Modified: trunk/src/plugins.h
===================================================================
--- trunk/src/plugins.h	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/plugins.h	2008-12-28 13:21:35 UTC (rev 3425)
@@ -30,12 +30,10 @@
 
 void plugins_init(void);
 
-void plugins_free(void);
+void plugins_finalize(void);
 
-void plugins_save_prefs(GKeyFile *config);
+void plugins_load_active(void);
 
-void plugins_load_prefs(GKeyFile *config);
-
 #endif
 
 #endif

Modified: trunk/src/prefs.c
===================================================================
--- trunk/src/prefs.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/prefs.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -221,9 +221,6 @@
 	widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.save_winpos);
 
-	widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins");
-	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.load_plugins);
-
 	widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
 	gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), prefs.confirm_exit);
 
@@ -636,9 +633,6 @@
 		widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_save_win_pos");
 		prefs.save_winpos = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 
-		widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_plugins");
-		prefs.load_plugins = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
-
 		widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_ask_for_quit");
 		prefs.confirm_exit = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
 

Modified: trunk/src/stash.c
===================================================================
--- trunk/src/stash.c	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/stash.c	2008-12-28 13:21:35 UTC (rev 3425)
@@ -155,6 +155,35 @@
 }
 
 
+static void handle_strv_setting(GeanyPrefGroup *group, GeanyPrefEntry *se,
+		GKeyFile *config, SettingAction action)
+{
+	gchararray **setting = se->setting;
+
+	switch (action)
+	{
+		case SETTING_READ:
+			g_strfreev(*setting);
+			*setting = g_key_file_get_string_list(config, group->name, se->key_name,
+				NULL, NULL);
+			if (*setting == NULL)
+				*setting = g_strdupv(se->default_value);
+			break;
+
+		case SETTING_WRITE:
+		{
+			/* don't try to save a NULL string vector */
+			gchar *dummy[] = { "", NULL };
+			gchar **strv = *setting ? *setting : dummy;
+
+			g_key_file_set_string_list(config, group->name, se->key_name,
+				(const gchar**)strv, g_strv_length(strv));
+			break;
+		}
+	}
+}
+
+
 static void keyfile_action(SettingAction action, GeanyPrefGroup *group, GKeyFile *keyfile)
 {
 	GeanyPrefEntry *entry;
@@ -179,8 +208,12 @@
 			case G_TYPE_STRING:
 				handle_string_setting(group, entry, keyfile, action); break;
 			default:
-				g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name,
-					G_GNUC_FUNCTION);
+				/* G_TYPE_STRV is not a constant */
+				if (entry->setting_type == G_TYPE_STRV)
+					handle_strv_setting(group, entry, keyfile, action);
+				else
+					g_warning("Unhandled type for %s::%s in %s!", group->name, entry->key_name,
+						G_GNUC_FUNCTION);
 		}
 	}
 }
@@ -271,7 +304,7 @@
 
 
 /* The contents of @a setting will be freed before being replaced, so make sure it is
- * initialized to @c NULL.
+ * allocated, or initialized to @c NULL.
  * @param default_value Not duplicated. */
 void stash_group_add_string(GeanyPrefGroup *group, gchar **setting,
 		const gchar *key_name, const gchar *default_value)
@@ -280,6 +313,16 @@
 }
 
 
+/* The contents of @a setting will be freed before being replaced, so make sure it is
+ * allocated, or initialized to @c NULL.
+ * @param default_value Not duplicated. */
+void stash_group_add_string_vector(GeanyPrefGroup *group, gchar ***setting,
+		const gchar *key_name, const gchar **default_value)
+{
+	add_pref(group, G_TYPE_STRV, setting, key_name, (gpointer)default_value);
+}
+
+
 /* *** GTK-related functions *** */
 
 static void handle_toggle_button(GtkWidget *widget, gboolean *setting,

Modified: trunk/src/stash.h
===================================================================
--- trunk/src/stash.h	2008-12-27 13:20:42 UTC (rev 3424)
+++ trunk/src/stash.h	2008-12-28 13:21:35 UTC (rev 3425)
@@ -45,14 +45,13 @@
 void stash_group_add_string(GeanyPrefGroup *group, gchar **setting,
 		const gchar *key_name, const gchar *default_value);
 
+void stash_group_add_string_vector(GeanyPrefGroup *group, gchar ***setting,
+		const gchar *key_name, const gchar **default_value);
+
 void stash_group_load_from_key_file(GeanyPrefGroup *group, GKeyFile *keyfile);
 
 void stash_group_save_to_key_file(GeanyPrefGroup *group, GKeyFile *keyfile);
 
-void stash_group_display(GeanyPrefGroup *group, GtkWidget *owner);
-
-void stash_group_update(GeanyPrefGroup *group, GtkWidget *owner);
-
 void stash_group_free(GeanyPrefGroup *group);
 
 
@@ -77,4 +76,8 @@
 void stash_group_add_entry(GeanyPrefGroup *group, gchar **setting,
 		const gchar *key_name, const gchar *default_value, gpointer widget_id);
 
+void stash_group_display(GeanyPrefGroup *group, GtkWidget *owner);
+
+void stash_group_update(GeanyPrefGroup *group, GtkWidget *owner);
+
 #endif


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list