* src/folderview.[ch]
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Thu, 17 Jul 2003 22:49:51 +0000 (22:49 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Thu, 17 Jul 2003 22:49:51 +0000 (22:49 +0000)
* src/prefs_common.[ch]
delay expanding folder tree during drags until timeout triggered
(needs perhaps some tweaking, so testing is welcome)

ChangeLog.claws
configure.ac
src/folderview.c
src/folderview.h
src/prefs_common.c
src/prefs_common.h

index f6ddc30..5d06f6e 100644 (file)
@@ -1,3 +1,9 @@
+2003-07-18 [alfons]    0.9.3claws22
+       
+       * src/folderview.c
+               delay expanding folder tree during drags until timeout triggered
+               (needs perhaps some tweaking, so testing is welcome)
+
 2003-07-17 [alfons]    0.9.3claws21
 
        * src/folderview.c
index 6d2b920..a90e42a 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=3
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws21
+EXTRA_VERSION=claws22
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index ddfd2f0..4e306d2 100644 (file)
@@ -261,6 +261,9 @@ static void folderview_drag_data_get     (GtkWidget        *widget,
                                          guint             info,
                                          guint             time,
                                          FolderView       *folderview);
+static void folderview_drag_end_cb      (GtkWidget        *widget,
+                                         GdkDragContext   *drag_context,
+                                         FolderView       *folderview);
 
 void folderview_create_folder_node       (FolderView       *folderview, 
                                          FolderItem       *item);
@@ -502,6 +505,9 @@ FolderView *folderview_create(void)
        gtk_signal_connect(GTK_OBJECT(ctree), "drag_data_received",
                           GTK_SIGNAL_FUNC(folderview_drag_received_cb),
                           folderview);
+       gtk_signal_connect(GTK_OBJECT(ctree), "drag_end",
+                          GTK_SIGNAL_FUNC(folderview_drag_end_cb),
+                          folderview);
 
        folderview->scrolledwin  = scrolledwin;
        folderview->ctree        = ctree;
@@ -2568,6 +2574,184 @@ static void folderview_move_to(FolderView *folderview, FolderItem *from_folder,
        gtk_widget_set_sensitive(GTK_WIDGET(folderview->ctree), TRUE);
 }
 
+static gint folderview_clist_compare(GtkCList *clist,
+                                    gconstpointer ptr1, gconstpointer ptr2)
+{
+       FolderItem *item1 = ((GtkCListRow *)ptr1)->data;
+       FolderItem *item2 = ((GtkCListRow *)ptr2)->data;
+
+       if (!item1->name)
+               return (item2->name != NULL);
+       if (!item2->name)
+               return -1;
+
+       return g_strcasecmp(item1->name, item2->name);
+}
+
+static gint folderview_compare_name(gconstpointer a, gconstpointer b)
+{
+       const FolderItem *item = a;
+       const gchar *name = b;
+
+       if (!item->path) return -1;
+       return strcmp2(g_basename(item->path), name);
+}
+
+static void folderview_scoring_cb(FolderView *folderview, guint action,
+                                  GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       prefs_scoring_open(item);
+}
+
+static void folderview_processing_cb(FolderView *folderview, guint action,
+                                    GtkWidget *widget)
+{
+       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
+       FolderItem *item;
+
+       if (!folderview->selected) return;
+
+       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
+       g_return_if_fail(item != NULL);
+       g_return_if_fail(item->folder != NULL);
+
+       prefs_filtering_open(item, NULL, NULL);
+}
+
+void folderview_set_target_folder_color(gint color_op) 
+{
+       gint firstone = 1;
+       GList *list;
+       FolderView *folderview;
+
+       for (list = folderview_list; list != NULL; list = list->next) {
+               folderview = (FolderView *)list->data;
+               gtkut_convert_int_to_gdk_color(color_op, &folderview->color_op);
+               if (firstone) {
+                       bold_tgtfold_style->fg[GTK_STATE_NORMAL] =
+                               folderview->color_op;
+                       firstone = 0;
+               }
+       }
+}
+
+void folderview_reflect_prefs_pixmap_theme(FolderView *folderview)
+{
+       folderview_init(folderview);
+       folderview_set_all();
+}
+
+static void drag_state_stop(FolderView *folderview)
+{
+       if (folderview->drag_timer)
+               gtk_timeout_remove(folderview->drag_timer);
+       folderview->drag_timer = 0;
+       folderview->drag_node = NULL;
+}
+
+static gint folderview_defer_expand(FolderView *folderview)
+{
+       if (folderview->drag_node) {
+               folderview_recollapse_nodes(folderview, folderview->drag_node);
+               if (folderview->drag_item->collapsed) {
+                       gtk_ctree_expand(GTK_CTREE(folderview->ctree), folderview->drag_node);
+                       folderview->nodes_to_recollapse = g_slist_append
+                               (folderview->nodes_to_recollapse, folderview->drag_node);
+               }
+       }
+       folderview->drag_item  = NULL;
+       folderview->drag_timer = 0;
+       return FALSE;
+}
+
+static void drag_state_start(FolderView *folderview, GtkCTreeNode *node, FolderItem *item)
+{
+       /* the idea is that we call drag_state_start() whenever we want expansion to
+        * start after 'prefs_common.hover_time' msecs. if we want to cancel expansion,
+        * we need to call drag_state_stop() */
+       drag_state_stop(folderview);
+       /* request expansion */
+       if (0 != (folderview->drag_timer = gtk_timeout_add
+                       (prefs_common.hover_timeout, 
+                        (GtkFunction)folderview_defer_expand,
+                        folderview))) {
+               folderview->drag_node = node;
+               folderview->drag_item = item;
+       }                        
+}
+
+static void folderview_start_drag(GtkWidget *widget, gint button, GdkEvent *event,
+                                 FolderView       *folderview)
+{
+       GdkDragContext *context;
+
+       g_return_if_fail(folderview != NULL);
+       if (folderview->selected == NULL) return;
+
+       folderview->nodes_to_recollapse = NULL; /* in case the last drag has been cancelled */
+       
+       context = gtk_drag_begin(widget, folderview->target_list,
+                                GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event);
+       gtk_drag_set_icon_default(context);
+}
+
+static void folderview_drag_data_get(GtkWidget        *widget,
+                                    GdkDragContext   *drag_context,
+                                    GtkSelectionData *selection_data,
+                                    guint             info,
+                                    guint             time,
+                                    FolderView       *folderview)
+{
+       FolderItem *item;
+       GList *cur;
+       gchar *source=NULL;
+       
+       for (cur = GTK_CLIST(folderview->ctree)->selection;
+            cur != NULL; cur = cur->next) {
+               item = gtk_ctree_node_get_row_data
+                       (GTK_CTREE(folderview->ctree), 
+                        GTK_CTREE_NODE(cur->data));
+               if (item) {
+                       source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
+                       gtk_selection_data_set(selection_data,
+                                              selection_data->target, 8,
+                                              source, strlen(source));
+                       break;
+               } else
+                       return;
+       }
+}
+
+gboolean folderview_update_folder(gpointer source, gpointer userdata)
+{
+       FolderUpdateData *hookdata;
+       FolderView *folderview;
+       GtkWidget *ctree;
+
+       hookdata = source;
+       folderview = (FolderView *) userdata;   
+       g_return_val_if_fail(hookdata != NULL, FALSE);
+       g_return_val_if_fail(folderview != NULL, FALSE);
+
+       ctree = folderview->ctree;
+       g_return_val_if_fail(ctree != NULL, FALSE);
+
+       if (hookdata->update_flags & FOLDER_TREE_CHANGED) {
+               folderview_set(folderview);
+       }
+
+       return FALSE;
+}
+
 static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                                          GdkDragContext *context,
                                          gint            x,
@@ -2617,16 +2801,9 @@ static gboolean folderview_drag_motion_cb(GtkWidget      *widget,
                        
        }
 
-       if (acceptable || (src_item && src_item == item)) {
-               folderview_recollapse_nodes(folderview, node);
-               if (item->collapsed) {
-                       gtk_ctree_expand(GTK_CTREE(widget), node);
-                       folderview->nodes_to_recollapse = g_slist_append(
-                                                               folderview->nodes_to_recollapse,
-                                                               node);
-               }
-       }
-               
+       if (acceptable || (src_item && src_item == item))
+               drag_state_start(folderview, node, item);
+       
        if (acceptable) {
                gtk_signal_handler_block_by_func
                        (GTK_OBJECT(widget),
@@ -2651,6 +2828,7 @@ static void folderview_drag_leave_cb(GtkWidget      *widget,
                                     guint           time,
                                     FolderView     *folderview)
 {
+       drag_state_stop(folderview);
        gtk_ctree_select(GTK_CTREE(widget), folderview->opened);
 }
 
@@ -2667,6 +2845,7 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
        FolderItem *item, *src_item;
        GtkCTreeNode *node;
 
+       drag_state_stop(folderview);
        if ((void *)strstr(data->data, "FROM_OTHER_FOLDER") != (void *)data->data) {
                /* comes from summaryview */
                if (gtk_clist_get_selection_info
@@ -2728,141 +2907,10 @@ static void folderview_drag_received_cb(GtkWidget        *widget,
        folderview->nodes_to_recollapse = NULL;
 }
 
-static gint folderview_clist_compare(GtkCList *clist,
-                                    gconstpointer ptr1, gconstpointer ptr2)
-{
-       FolderItem *item1 = ((GtkCListRow *)ptr1)->data;
-       FolderItem *item2 = ((GtkCListRow *)ptr2)->data;
-
-       if (!item1->name)
-               return (item2->name != NULL);
-       if (!item2->name)
-               return -1;
-
-       return g_strcasecmp(item1->name, item2->name);
-}
-
-static gint folderview_compare_name(gconstpointer a, gconstpointer b)
-{
-       const FolderItem *item = a;
-       const gchar *name = b;
-
-       if (!item->path) return -1;
-       return strcmp2(g_basename(item->path), name);
-}
-
-static void folderview_scoring_cb(FolderView *folderview, guint action,
-                                  GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-
-       prefs_scoring_open(item);
-}
-
-static void folderview_processing_cb(FolderView *folderview, guint action,
-                                    GtkWidget *widget)
-{
-       GtkCTree *ctree = GTK_CTREE(folderview->ctree);
-       FolderItem *item;
-
-       if (!folderview->selected) return;
-
-       item = gtk_ctree_node_get_row_data(ctree, folderview->selected);
-       g_return_if_fail(item != NULL);
-       g_return_if_fail(item->folder != NULL);
-
-       prefs_filtering_open(item, NULL, NULL);
-}
-
-void folderview_set_target_folder_color(gint color_op) 
-{
-       gint firstone = 1;
-       GList *list;
-       FolderView *folderview;
-
-       for (list = folderview_list; list != NULL; list = list->next) {
-               folderview = (FolderView *)list->data;
-               gtkut_convert_int_to_gdk_color(color_op, &folderview->color_op);
-               if (firstone) {
-                       bold_tgtfold_style->fg[GTK_STATE_NORMAL] =
-                               folderview->color_op;
-                       firstone = 0;
-               }
-       }
-}
-
-void folderview_reflect_prefs_pixmap_theme(FolderView *folderview)
+static void folderview_drag_end_cb(GtkWidget       *widget, 
+                                  GdkDragContext   *drag_context,
+                                   FolderView      *folderview)
 {
-       folderview_init(folderview);
-       folderview_set_all();
+       drag_state_stop(folderview);
 }
 
-static void folderview_start_drag(GtkWidget *widget, gint button, GdkEvent *event,
-                                 FolderView       *folderview)
-{
-       GdkDragContext *context;
-
-       g_return_if_fail(folderview != NULL);
-       if (folderview->selected == NULL) return;
-
-       folderview->nodes_to_recollapse = NULL; /* in case the last drag has been cancelled */
-       
-       context = gtk_drag_begin(widget, folderview->target_list,
-                                GDK_ACTION_MOVE|GDK_ACTION_COPY|GDK_ACTION_DEFAULT, button, event);
-       gtk_drag_set_icon_default(context);
-}
-
-static void folderview_drag_data_get(GtkWidget        *widget,
-                                    GdkDragContext   *drag_context,
-                                    GtkSelectionData *selection_data,
-                                    guint             info,
-                                    guint             time,
-                                    FolderView       *folderview)
-{
-       FolderItem *item;
-       GList *cur;
-       gchar *source=NULL;
-       
-       for (cur = GTK_CLIST(folderview->ctree)->selection;
-            cur != NULL; cur = cur->next) {
-               item = gtk_ctree_node_get_row_data
-                       (GTK_CTREE(folderview->ctree), 
-                        GTK_CTREE_NODE(cur->data));
-               if (item) {
-                       source = g_strdup_printf ("FROM_OTHER_FOLDER%s", folder_item_get_identifier(item));
-                       gtk_selection_data_set(selection_data,
-                                              selection_data->target, 8,
-                                              source, strlen(source));
-                       break;
-               } else
-                       return;
-       }
-}
-
-gboolean folderview_update_folder(gpointer source, gpointer userdata)
-{
-       FolderUpdateData *hookdata;
-       FolderView *folderview;
-       GtkWidget *ctree;
-
-       hookdata = source;
-       folderview = (FolderView *) userdata;   
-       g_return_val_if_fail(hookdata != NULL, FALSE);
-       g_return_val_if_fail(folderview != NULL, FALSE);
-
-       ctree = folderview->ctree;
-       g_return_val_if_fail(ctree != NULL, FALSE);
-
-       if (hookdata->update_flags & FOLDER_TREE_CHANGED) {
-               folderview_set(folderview);
-       }
-
-       return FALSE;
-}
index 530e113..1744906 100644 (file)
@@ -59,8 +59,12 @@ struct _FolderView
        gint folder_update_callback_id;
        gint folder_item_update_callback_id;
        
-       /* for drag and drop */
+       /* DND states */
        GSList *nodes_to_recollapse;
+       guint   drag_timer;             /* timer id */
+       FolderItem *drag_item;          /* dragged item */
+       GtkCTreeNode *drag_node;        /* drag node */
+       
        GtkTargetList *target_list; /* DnD */
 };
 
index 9fd7a84..aad3b5c 100644 (file)
@@ -776,6 +776,9 @@ static PrefParam param[] = {
        {"pixmap_theme_path", DEFAULT_PIXMAP_THEME, 
         &prefs_common.pixmap_theme_path, P_STRING,
         &interface.entry_pixmap_theme, prefs_set_data_from_entry, prefs_set_entry},
+
+       {"hover_timeout", "500", &prefs_common.hover_timeout, P_INT,
+        NULL, NULL, NULL},
        
        /* Other */
        {"uri_open_command", DEFAULT_BROWSER_CMD,
index 50a9de9..b046e6f 100644 (file)
@@ -252,6 +252,7 @@ struct _PrefsCommon
        NextUnreadMsgDialogShow next_unread_msg_dialog;
        gboolean add_address_by_click;
        gchar *pixmap_theme_path;
+       int hover_timeout; /* msecs mouse hover timeout */
 
        /* Other */
        gchar *uri_cmd;