From 821ca6fcf2f9abd47f3de76da3a83fb7a25f4fa4 Mon Sep 17 00:00:00 2001 From: Carlos Garnacho Parro Date: Wed, 11 Jan 2006 18:33:34 +0000 Subject: [PATCH] added method for setting single click policy track for changes in the 2006-01-01 Carlos Garnacho Parro * gnomecc-canvas.[ch]: added method for setting single click policy * control-center.c: track for changes in the nautilus click_policy key to make g-c-c behave exactly like nautilus --- control-center/ChangeLog | 6 ++++ control-center/control-center.c | 52 +++++++++++++++++++++++++++++++ control-center/gnomecc-canvas.c | 54 +++++++++++++++++++++------------ control-center/gnomecc-canvas.h | 2 ++ 4 files changed, 94 insertions(+), 20 deletions(-) diff --git a/control-center/ChangeLog b/control-center/ChangeLog index 408ee685e..a8971cd50 100644 --- a/control-center/ChangeLog +++ b/control-center/ChangeLog @@ -1,3 +1,9 @@ +2006-01-01 Carlos Garnacho Parro + + * gnomecc-canvas.[ch]: added method for setting single click policy + * control-center.c: track for changes in the nautilus click_policy key + to make g-c-c behave exactly like nautilus + 2005-11-14 Kjartan Maraas * control-center-categories.c: (populate_category): diff --git a/control-center/control-center.c b/control-center/control-center.c index 44aec033e..2600d370b 100644 --- a/control-center/control-center.c +++ b/control-center/control-center.c @@ -10,6 +10,8 @@ #include #include "gnomecc-canvas.h" +#define SINGLE_CLICK_POLICY_KEY "/apps/nautilus/preferences/click_policy" + static void gnome_cc_die (void) { @@ -27,6 +29,55 @@ change_status (GnomeccCanvas *canvas, const gchar *status, void *data) gnome_appbar_set_status (bar, status); } +static void +on_click_policy_notified (GConfClient *client, + guint conn_id, + GConfEntry *entry, + GnomeccCanvas *canvas) +{ + GConfValue *value; + gboolean use_single_click = FALSE; + gchar *policy; + + value = gconf_entry_get_value (entry); + + if (value->type == GCONF_VALUE_STRING) { + policy = gconf_value_get_string (value); + use_single_click = (0 == g_ascii_strcasecmp (policy, "single")); + + gnomecc_canvas_set_single_click_mode (canvas, use_single_click); + } +} + +static void +set_click_policy (GnomeccCanvas *canvas) +{ + GConfClient *client = gconf_client_get_default (); + gboolean use_single_click = FALSE; + gchar *policy; + + gconf_client_add_dir (client, + SINGLE_CLICK_POLICY_KEY, + GCONF_CLIENT_PRELOAD_NONE, + NULL); + + gconf_client_notify_add (client, + SINGLE_CLICK_POLICY_KEY, + on_click_policy_notified, + canvas, + NULL, NULL); + + policy = gconf_client_get_string (client, SINGLE_CLICK_POLICY_KEY, NULL); + + if (policy) { + use_single_click = (0 == g_ascii_strcasecmp (policy, "single")); + g_free (policy); + } + + gnomecc_canvas_set_single_click_mode (canvas, use_single_click); +} + + static GtkWindow * create_window (void) { @@ -49,6 +100,7 @@ create_window (void) canvas = gnomecc_canvas_new (info); g_signal_connect (G_OBJECT (canvas), "selection-changed", G_CALLBACK (change_status), appbar); + set_click_policy (GNOMECC_CANVAS (canvas)); sw = gtk_scrolled_window_new (GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 10, 100, 100)), GTK_ADJUSTMENT (gtk_adjustment_new (0, 0, 100, 10, 100, 100))); diff --git a/control-center/gnomecc-canvas.c b/control-center/gnomecc-canvas.c index f83f1fe51..9df2cd89c 100644 --- a/control-center/gnomecc-canvas.c +++ b/control-center/gnomecc-canvas.c @@ -63,6 +63,8 @@ struct _GnomeccCanvasPrivate { /* accessibility stuff */ GHashTable *accessible_children; + + gboolean single_click; }; typedef struct { @@ -187,29 +189,20 @@ gnomecc_canvas_init (GnomeccCanvas *canvas) priv->rtl = (gtk_widget_get_direction (GTK_WIDGET (canvas)) == GTK_TEXT_DIR_RTL); priv->accessible_children = g_hash_table_new (g_int_hash, g_int_equal); + priv->single_click = FALSE; gtk_widget_show_all (GTK_WIDGET (canvas)); } static gboolean -single_click_activates (void) +single_click_activates (GnomeccCanvas *canvas) { - static gboolean needs_init = TRUE; - static gboolean use_single_click = FALSE; - if (needs_init) { - GConfClient *client = gconf_client_get_default (); - char *policy = gconf_client_get_string (client, "/apps/nautilus/preferences/click_policy", NULL); - g_object_unref (G_OBJECT (client)); + GnomeccCanvasPrivate *priv; + + priv = GNOMECC_CANVAS_GET_PRIVATE (canvas); - if (policy != NULL) { - use_single_click = (0 == g_ascii_strcasecmp (policy, "single")); - g_free (policy); - } - needs_init = FALSE; - } - - return use_single_click; -} + return priv->single_click; +} static void gnome_canvas_item_show_hide (GnomeCanvasItem *item, gboolean show) @@ -327,22 +320,31 @@ cover_event (GnomeCanvasItem *item, GdkEvent *event, ControlCenterEntry *entry) { EntryInfo *ei = entry->user_data; GnomeccCanvas *canvas = ei->canvas; + GdkCursor *cursor; switch (event->type) { case GDK_ENTER_NOTIFY: ei->highlighted = TRUE; setup_entry (canvas, entry); /* highlight even if it is already selected */ + + if (single_click_activates (canvas)) { + cursor = gdk_cursor_new (GDK_HAND1); + gdk_window_set_cursor (GTK_WIDGET (canvas)->window, cursor); + gdk_cursor_unref (cursor); + } + return TRUE; case GDK_LEAVE_NOTIFY: ei->highlighted = FALSE; setup_entry (canvas, entry); + gdk_window_set_cursor (GTK_WIDGET (canvas)->window, NULL); return TRUE; case GDK_BUTTON_PRESS: - if (single_click_activates ()) { + select_entry (canvas, entry); + + if (single_click_activates (canvas)) activate_entry (entry); - } else { - select_entry (canvas, entry); - } + return TRUE; case GDK_2BUTTON_PRESS: activate_entry (entry); @@ -1701,3 +1703,15 @@ gnomecc_canvas_get_accessible (GtkWidget *widget) return (* GTK_WIDGET_CLASS (gnomecc_canvas_parent_class)->get_accessible) (widget); } + +void +gnomecc_canvas_set_single_click_mode (GnomeccCanvas *canvas, gboolean single_click) +{ + GnomeccCanvasPrivate *priv; + + g_return_if_fail (GNOMECC_IS_CANVAS (canvas)); + + priv = GNOMECC_CANVAS_GET_PRIVATE (canvas); + + priv->single_click = (single_click == TRUE); +} diff --git a/control-center/gnomecc-canvas.h b/control-center/gnomecc-canvas.h index f1e3c3430..ac3d4aca6 100644 --- a/control-center/gnomecc-canvas.h +++ b/control-center/gnomecc-canvas.h @@ -53,6 +53,8 @@ struct _GnomeccCanvasClass { GType gnomecc_canvas_get_type (void); GtkWidget* gnomecc_canvas_new (ControlCenterInformation *info); +void gnomecc_canvas_set_single_click_mode (GnomeccCanvas *canvas, gboolean single_click); + G_END_DECLS