summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimothy Arceri <t_arceri@yahoo.com.au>2013-03-05 17:30:41 -0600
committerFederico Mena Quintero <federico@gnome.org>2013-03-05 17:30:41 -0600
commit70c9c654af8c43dcb76deeeeeb84815470849635 (patch)
treedce1dc4e8110a5112279db9187b6d82ea4d28c29
parente510cf22a9334919db0e4c6cb501e7d65f792fd4 (diff)
downloadgtk+-bgo121113-filechooser-single-click-activate.tar.gz
Implement single click in the file chooserbgo121113-filechooser-single-click-activate
The settings are to be shared with Nautilus. Based on the original patch by Christian Neumair. https://bugzilla.gnome.org/show_bug.cgi?id=121113
-rw-r--r--gtk/gtkfilechooserdefault.c54
-rw-r--r--gtk/gtkfilechooserprivate.h3
2 files changed, 57 insertions, 0 deletions
diff --git a/gtk/gtkfilechooserdefault.c b/gtk/gtkfilechooserdefault.c
index 99c4200abd..22d92522b6 100644
--- a/gtk/gtkfilechooserdefault.c
+++ b/gtk/gtkfilechooserdefault.c
@@ -195,6 +195,12 @@ typedef enum {
SHORTCUT_TYPE_RECENT
} ShortcutType;
+enum
+{
+ CLICK_POLICY_SINGLE,
+ CLICK_POLICY_DOUBLE
+};
+
#define MODEL_ATTRIBUTES "standard::name,standard::type,standard::display-name," \
"standard::is-hidden,standard::is-backup,standard::size," \
"standard::content-type,time::modified"
@@ -732,6 +738,7 @@ _gtk_file_chooser_default_init (GtkFileChooserDefault *impl)
impl->sort_order = GTK_SORT_ASCENDING;
impl->recent_manager = gtk_recent_manager_get_default ();
impl->create_folders = TRUE;
+ impl->single_click_activate = FALSE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (impl),
GTK_ORIENTATION_VERTICAL);
@@ -4320,6 +4327,43 @@ list_button_press_event_cb (GtkWidget *widget,
return TRUE;
}
+/* When single-click is enabled, display a hand when cursor
+ * is above a file */
+static gboolean
+list_motion_cb (GtkWidget *widget,
+ GdkEventMotion *event,
+ GtkFileChooserDefault *impl)
+{
+ static GdkCursor *hand_cursor = NULL;
+ GdkDisplay *current_display;
+
+ if (!impl->single_click_activate || impl->has_busy_cursor)
+ return FALSE;
+
+ current_display = gtk_widget_get_display (widget);
+ g_assert (current_display != NULL);
+
+ if (hand_cursor != NULL &&
+ gdk_cursor_get_display (hand_cursor) != current_display)
+ {
+ g_object_unref (hand_cursor);
+ hand_cursor = NULL;
+ }
+
+ if (hand_cursor == NULL)
+ hand_cursor = gdk_cursor_new_for_display (current_display,
+ GDK_HAND2);
+
+ if (gtk_tree_view_get_path_at_pos (GTK_TREE_VIEW (widget),
+ event->x, event->y,
+ NULL, NULL, NULL, NULL))
+ gdk_window_set_cursor (gtk_widget_get_window (widget), hand_cursor);
+ else
+ gdk_window_set_cursor (gtk_widget_get_window (widget), NULL);
+
+ return FALSE;
+}
+
typedef struct {
OperationMode operation_mode;
gint general_column;
@@ -4438,6 +4482,8 @@ create_file_list (GtkFileChooserDefault *impl)
G_CALLBACK (list_popup_menu_cb), impl);
g_signal_connect (impl->browse_files_tree_view, "button-press-event",
G_CALLBACK (list_button_press_event_cb), impl);
+ g_signal_connect (impl->browse_files_tree_view, "motion_notify_event",
+ G_CALLBACK (list_motion_cb), impl);
g_signal_connect (impl->browse_files_tree_view, "drag-data-received",
G_CALLBACK (file_list_drag_data_received_cb), impl);
@@ -6016,6 +6062,7 @@ settings_load (GtkFileChooserDefault *impl)
LocationMode location_mode;
gboolean show_hidden;
gboolean show_size_column;
+ int click_policy
gint sort_column;
GtkSortType sort_order;
gint sidebar_width;
@@ -6024,6 +6071,7 @@ settings_load (GtkFileChooserDefault *impl)
settings = _gtk_file_chooser_get_settings_for_widget (GTK_WIDGET (impl));
location_mode = g_settings_get_enum (settings, SETTINGS_KEY_LOCATION_MODE);
+ click_policy = g_settings_get_enum (impl->settings, SETTINGS_KEY_CLICK_POLICY);
show_hidden = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_HIDDEN);
show_size_column = g_settings_get_boolean (settings, SETTINGS_KEY_SHOW_SIZE_COLUMN);
sort_column = g_settings_get_enum (settings, SETTINGS_KEY_SORT_COLUMN);
@@ -6034,6 +6082,10 @@ settings_load (GtkFileChooserDefault *impl)
gtk_file_chooser_set_show_hidden (GTK_FILE_CHOOSER (impl), show_hidden);
+ impl->single_click_activate = click_policy == CLICK_POLICY_SINGLE;
+ _gtk_tree_view_set_single_click_activate (GTK_TREE_VIEW (impl->browse_files_tree_view),
+ impl->single_click_activate);
+
impl->show_size_column = show_size_column;
gtk_tree_view_column_set_visible (impl->list_size_column, show_size_column);
@@ -6258,6 +6310,8 @@ set_busy_cursor (GtkFileChooserDefault *impl,
if (cursor)
g_object_unref (cursor);
+
+ impl->has_busy_cursor = busy;
}
/* Creates a sort model to wrap the file system model and sets it on the tree view */
diff --git a/gtk/gtkfilechooserprivate.h b/gtk/gtkfilechooserprivate.h
index 96329ad7de..5807f4aab1 100644
--- a/gtk/gtkfilechooserprivate.h
+++ b/gtk/gtkfilechooserprivate.h
@@ -35,6 +35,7 @@
G_BEGIN_DECLS
#define SETTINGS_KEY_LOCATION_MODE "location-mode"
+#define SETTINGS_KEY_CLICK_POLICY "click-policy"
#define SETTINGS_KEY_SHOW_HIDDEN "show-hidden"
#define SETTINGS_KEY_SHOW_SIZE_COLUMN "show-size-column"
#define SETTINGS_KEY_SORT_COLUMN "sort-column"
@@ -289,6 +290,7 @@ struct _GtkFileChooserDefault
guint use_preview_label : 1;
guint select_multiple : 1;
guint show_hidden : 1;
+ guint single_click_activate : 1;
guint do_overwrite_confirmation : 1;
guint list_sort_ascending : 1;
guint changing_folder : 1;
@@ -299,6 +301,7 @@ struct _GtkFileChooserDefault
guint has_recent: 1;
guint show_size_column : 1;
guint create_folders : 1;
+ guint has_busy_cursor : 1;
#if 0
guint shortcuts_drag_outside : 1;