Mikko Linnalo wrote:
> Hi,
>
> I was testing the new single click feature and was wondering if it could
> be possible to implement a feature where files get selected by just
> hovering the mouse pointer on them (e.g. ~500msecs). This is how single
> click works atleast in Windows. Now user has to keep Ctrl or Shift
> pressed when selecting even a single file.
See the attached patch for ExoIconView, that should do the trick for the
icon view. For the details view, GtkTreeView offers a hover-selection
setting, but that doesn't work for multi-selection mode and it'll also
select the row right away without any timeout. I could add an
ExoTreeView class, which extends GtkTreeView with the required single
click features.
> Btw, just made a bug for Thunar and I was able to verify the fix half on
> hour later, that's just awesome. I work in a software company as a test
> engineer (~5 years) and I have never seen such speed. Benny is the
> man :)
Well, it depends on the complexity of the bug. The icon view selection
bug was really trivial, I just forgot to check for Control/Shift.
> Br,
> Mikko Linnalo
HTH,
Benedikt
Index: exo-icon-view.c
===================================================================
--- exo-icon-view.c (revision 20062)
+++ exo-icon-view.c (working copy)
@@ -46,6 +46,9 @@
+/* the prelit select timeout (in ms) */
+#define EXO_ICON_VIEW_SELECT_PRELIT_TIMEOUT (500)
+
/* the search dialog timeout (in ms) */
#define EXO_ICON_VIEW_SEARCH_DIALOG_TIMEOUT (5000)
@@ -220,6 +223,8 @@
gint count);
static void exo_icon_view_scroll_to_item (ExoIconView *icon_view,
ExoIconViewItem *item);
+static gboolean exo_icon_view_select_prelit_timeout (gpointer user_data);
+static void exo_icon_view_select_prelit_timeout_destroy (gpointer user_data);
static void exo_icon_view_select_item (ExoIconView *icon_view,
ExoIconViewItem *item);
static void exo_icon_view_unselect_item (ExoIconView *icon_view,
@@ -443,6 +448,10 @@
GtkCellEditable *editable;
ExoIconViewItem *prelit_item;
+ /* automatically select prelited items after a timeout */
+ gboolean select_prelit_extend; /* whether to extend the selection */
+ gint select_prelit_timeout_id;
+
ExoIconViewItem *last_single_clicked;
GList *cell_list;
@@ -1109,6 +1118,8 @@
icon_view->priv->column_spacing = 6;
icon_view->priv->margin = 6;
+ icon_view->priv->select_prelit_timeout_id = -1;
+
icon_view->priv->layout_idle_id = -1;
icon_view->priv->enable_search = TRUE;
@@ -1127,6 +1138,10 @@
{
ExoIconView *icon_view = EXO_ICON_VIEW (object);
+ /* cancel any pending prelit-select timeout */
+ if (G_UNLIKELY (icon_view->priv->select_prelit_timeout_id >= 0))
+ g_source_remove (icon_view->priv->select_prelit_timeout_id);
+
/* cancel any pending search timeout */
if (G_UNLIKELY (icon_view->priv->search_timeout_id >= 0))
g_source_remove (icon_view->priv->search_timeout_id);
@@ -1748,11 +1763,26 @@
cursor = gdk_cursor_new (GDK_HAND2);
gdk_window_set_cursor (event->window, cursor);
gdk_cursor_unref (cursor);
+
+ /* extend the selection if either control or shift is pressed */
+ icon_view->priv->select_prelit_extend = ((event->state & (GDK_CONTROL_MASK | GDK_SHIFT_MASK)) != 0);
+
+ /* schedule the timeout source if not already pending */
+ if (G_LIKELY (icon_view->priv->select_prelit_timeout_id < 0))
+ {
+ icon_view->priv->select_prelit_timeout_id = g_timeout_add_full (G_PRIORITY_LOW, EXO_ICON_VIEW_SELECT_PRELIT_TIMEOUT,
+ exo_icon_view_select_prelit_timeout, icon_view,
+ exo_icon_view_select_prelit_timeout_destroy);
+ }
}
else
{
/* reset the cursor */
gdk_window_set_cursor (event->window, NULL);
+
+ /* cancel any pending prelit select timeout */
+ if (icon_view->priv->select_prelit_timeout_id >= 0)
+ g_source_remove (icon_view->priv->select_prelit_timeout_id);
}
}
}
@@ -3340,7 +3370,43 @@
+static gboolean
+exo_icon_view_select_prelit_timeout (gpointer user_data)
+{
+ ExoIconView *icon_view = EXO_ICON_VIEW (user_data);
+
+ GDK_THREADS_ENTER ();
+
+ /* check if we're still in single-click mode and have a prelit item */
+ if (icon_view->priv->single_click && icon_view->priv->prelit_item != NULL)
+ {
+ /* grab focus to the icon view widget */
+ gtk_widget_grab_focus (GTK_WIDGET (icon_view));
+
+ /* check if we should extend the selection */
+ if (G_LIKELY (!icon_view->priv->select_prelit_extend))
+ exo_icon_view_unselect_all (icon_view);
+
+ /* select the prelited item */
+ exo_icon_view_select_item (icon_view, icon_view->priv->prelit_item);
+ }
+
+ GDK_THREADS_LEAVE ();
+
+ return FALSE;
+}
+
+
+
static void
+exo_icon_view_select_prelit_timeout_destroy (gpointer user_data)
+{
+ EXO_ICON_VIEW (user_data)->priv->select_prelit_timeout_id = -1;
+}
+
+
+
+static void
exo_icon_view_select_item (ExoIconView *icon_view,
ExoIconViewItem *item)
{
_______________________________________________
Thunar-dev mailing list
[email protected]
http://foo-projects.org/mailman/listinfo/thunar-dev