From 70c9c654af8c43dcb76deeeeeb84815470849635 Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Tue, 5 Mar 2013 17:30:41 -0600 Subject: Implement single click in the file chooser 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 --- gtk/gtkfilechooserdefault.c | 54 +++++++++++++++++++++++++++++++++++++++++++++ gtk/gtkfilechooserprivate.h | 3 +++ 2 files changed, 57 insertions(+) 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; -- cgit v1.2.1