[gedit] Get the nautilus value as an enum instaed of a string and avoid a conversion.



commit 3c289c092c00425cec4302f0025a7f974a47dc4f
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Mon Apr 4 19:23:31 2011 +0200

    Get the nautilus value as an enum instaed of a string and avoid a conversion.

 plugins/filebrowser/gedit-file-browser-plugin.c    |   35 ++++---------------
 plugins/filebrowser/gedit-file-browser-view.h      |    4 +-
 ...ome.gedit.plugins.filebrowser.gschema.xml.in.in |    8 ++++-
 3 files changed, 17 insertions(+), 30 deletions(-)
---
diff --git a/plugins/filebrowser/gedit-file-browser-plugin.c b/plugins/filebrowser/gedit-file-browser-plugin.c
index 38419eb..21ca346 100644
--- a/plugins/filebrowser/gedit-file-browser-plugin.c
+++ b/plugins/filebrowser/gedit-file-browser-plugin.c
@@ -340,28 +340,16 @@ restore_default_location (GeditFileBrowserPlugin *plugin)
 	g_free (virtual_root);
 }
 
-static GeditFileBrowserViewClickPolicy
-click_policy_from_string (gchar const *click_policy)
-{
-	if (click_policy && strcmp (click_policy, "single") == 0)
-		return GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE;
-	else
-		return GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE;
-}
-
 static void
 on_click_policy_changed (GSettings              *settings,
 			 const gchar            *key,
 			 GeditFileBrowserPlugin *plugin)
 {
 	GeditFileBrowserPluginPrivate *priv = plugin->priv;
-	gchar *click_policy;
-	GeditFileBrowserViewClickPolicy policy = GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE;
+	GeditFileBrowserViewClickPolicy policy;
 	GeditFileBrowserView *view;
 
-	click_policy = g_settings_get_string (settings, key);
-	policy = click_policy_from_string (click_policy);
-	g_free (click_policy);
+	policy = g_settings_get_enum (settings, key);
 
 	view = gedit_file_browser_widget_get_browser_view (priv->tree_widget);
 	gedit_file_browser_view_set_click_policy (view, policy);
@@ -379,29 +367,22 @@ static void
 install_nautilus_prefs (GeditFileBrowserPlugin *plugin)
 {
 	GeditFileBrowserPluginPrivate *priv = plugin->priv;
-	gchar *pref;
 	gboolean prefb;
 	GeditFileBrowserViewClickPolicy policy;
 	GeditFileBrowserView *view;
 
 	/* Get click_policy */
-	pref = g_settings_get_string (priv->nautilus_settings,
+	policy = g_settings_get_enum (priv->nautilus_settings,
 				      NAUTILUS_CLICK_POLICY_KEY);
 
-	policy = click_policy_from_string (pref);
-
 	view = gedit_file_browser_widget_get_browser_view (priv->tree_widget);
 	gedit_file_browser_view_set_click_policy (view, policy);
 
-	if (pref)
-	{
-		priv->click_policy_handle =
-			g_signal_connect (priv->nautilus_settings,
-					  "changed::" NAUTILUS_CLICK_POLICY_KEY,
-					  G_CALLBACK (on_click_policy_changed),
-					  plugin);
-		g_free (pref);
-	}
+	priv->click_policy_handle =
+		g_signal_connect (priv->nautilus_settings,
+				  "changed::" NAUTILUS_CLICK_POLICY_KEY,
+				  G_CALLBACK (on_click_policy_changed),
+				  plugin);
 
 	/* Bind enable-delete */
 	g_settings_bind (priv->nautilus_settings,
diff --git a/plugins/filebrowser/gedit-file-browser-view.h b/plugins/filebrowser/gedit-file-browser-view.h
index 9ca54bd..31a3083 100644
--- a/plugins/filebrowser/gedit-file-browser-view.h
+++ b/plugins/filebrowser/gedit-file-browser-view.h
@@ -38,8 +38,8 @@ typedef struct _GeditFileBrowserViewClass   GeditFileBrowserViewClass;
 typedef struct _GeditFileBrowserViewPrivate GeditFileBrowserViewPrivate;
 
 typedef enum {
-	GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE,
-	GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE
+	GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_SINGLE,
+	GEDIT_FILE_BROWSER_VIEW_CLICK_POLICY_DOUBLE
 } GeditFileBrowserViewClickPolicy;
 
 struct _GeditFileBrowserView
diff --git a/plugins/filebrowser/org.gnome.gedit.plugins.filebrowser.gschema.xml.in.in b/plugins/filebrowser/org.gnome.gedit.plugins.filebrowser.gschema.xml.in.in
index 75316da..e79a6b9 100644
--- a/plugins/filebrowser/org.gnome.gedit.plugins.filebrowser.gschema.xml.in.in
+++ b/plugins/filebrowser/org.gnome.gedit.plugins.filebrowser.gschema.xml.in.in
@@ -36,8 +36,14 @@
       <_description>The filter pattern to filter the file browser with. This filter works on top of the filter_mode.</_description>
     </key>
   </schema>
+
+  <enum id="org.gnome.gedit.plugins.filebrowser.nautilus.ClickPolicy">
+    <value value="0" nick="single"/>
+    <value value="1" nick="double"/>
+  </enum>
+
   <schema id="org.gnome.gedit.plugins.filebrowser.nautilus" path="/org/gnome/gedit/plugins/filebrowser/nautilus/">
-    <key name="click-policy" type="s">
+    <key name="click-policy" enum="org.gnome.gedit.plugins.filebrowser.nautilus.ClickPolicy">
       <default>'double'</default>
     </key>
     <key name="enable-delete" type="b">



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]