[gthumb/ext: 19/79] started work on dnd support
- From: Paolo Bacchilega <paobac src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gthumb/ext: 19/79] started work on dnd support
- Date: Sun, 2 Aug 2009 20:25:29 +0000 (UTC)
commit bacfb44944595db3cac95c44f3fd018bc38ce288
Author: Paolo Bacchilega <paobac src gnome org>
Date: Mon Jun 22 14:24:50 2009 +0200
started work on dnd support
gthumb/gth-browser.c | 61 ++++++++++++++++++----
gthumb/gth-file-list.c | 55 ++++++++++++++++++++
gthumb/gth-file-view.c | 129 ++++++++++++++++++++++++++++++-----------------
gthumb/gth-file-view.h | 120 ++++++++++++++++++++++++++------------------
gthumb/gth-icon-view.c | 88 ++++++++++++++++++++++++--------
5 files changed, 324 insertions(+), 129 deletions(-)
---
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 19c6379..1449418 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -2295,6 +2295,42 @@ gth_file_view_item_activated_cb (GtkIconView *iconview,
static void
+gth_file_list_drag_data_get (GtkWidget *widget,
+ GdkDragContext *context,
+ GtkSelectionData *selection_data,
+ guint info,
+ guint time,
+ gpointer extra_data)
+{
+ GthBrowser *browser = extra_data;
+ GList *items;
+ GList *file_list;
+ int n_uris;
+ char **uris;
+ int i;
+ GList *scan;
+
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (gth_browser_get_file_list_view (browser)));
+ file_list = gth_file_list_get_files (GTH_FILE_LIST (gth_browser_get_file_list (browser)), items);
+ n_uris = g_list_length (file_list);
+ uris = g_new (char *, n_uris + 1);
+ for (i = 0, scan = file_list; scan; scan = scan->next, i++) {
+ GthFileData *file_data = scan->data;
+ uris[i] = g_file_get_uri (file_data->file);
+
+g_print ("==> %s\n", uris[i]);
+
+ }
+ uris[i] = NULL;
+ gtk_selection_data_set_uris (selection_data, uris);
+
+ g_strfreev (uris);
+ _g_object_list_unref (file_list);
+ _gtk_tree_path_list_free (items);
+}
+
+
+static void
add_browser_toolbar_menu_buttons (GthBrowser *browser)
{
int tool_pos;
@@ -2545,12 +2581,12 @@ _gth_browser_unrealize (GtkWidget *browser,
static void
_gth_browser_construct (GthBrowser *browser)
{
- GError *error = NULL;
- GtkWidget *vbox;
- GtkWidget *scrolled_window;
- GtkWidget *menubar;
- char *general_filter;
- int i;
+ GError *error = NULL;
+ GtkWidget *vbox;
+ GtkWidget *scrolled_window;
+ GtkWidget *menubar;
+ char *general_filter;
+ int i;
gtk_window_set_default_size (GTK_WINDOW (browser),
eel_gconf_get_integer (PREF_UI_WINDOW_WIDTH, DEFAULT_UI_WINDOW_WIDTH),
@@ -2763,8 +2799,6 @@ _gth_browser_construct (GthBrowser *browser)
gtk_widget_show (browser->priv->file_list);
gtk_box_pack_start (GTK_BOX (vbox), browser->priv->file_list, TRUE, TRUE, 0);
- browser->priv->file_list_popup = gtk_ui_manager_get_widget (browser->priv->ui, "/FileListPopup");
-
g_signal_connect (G_OBJECT (browser->priv->file_list),
"button_press_event",
G_CALLBACK (gth_file_list_button_press_cb),
@@ -2778,6 +2812,13 @@ _gth_browser_construct (GthBrowser *browser)
G_CALLBACK (gth_file_view_item_activated_cb),
browser);
+ g_signal_connect (gth_file_list_get_view (GTH_FILE_LIST (browser->priv->file_list)),
+ "drag_data_get",
+ G_CALLBACK (gth_file_list_drag_data_get),
+ browser);
+
+ browser->priv->file_list_popup = gtk_ui_manager_get_widget (browser->priv->ui, "/FileListPopup");
+
/* the filter bar */
general_filter = eel_gconf_get_string (PREF_GENERAL_FILTER, DEFAULT_GENERAL_FILTER);
@@ -4064,10 +4105,7 @@ _gth_browser_clipboard_copy_or_cut (GthBrowser *browser,
gtk_target_list_add (target_list, GNOME_COPIED_FILES, 0, 0);
gtk_target_list_add_uri_targets (target_list, 0);
gtk_target_list_add_text_targets (target_list, 0);
-
targets = gtk_target_table_new_from_list (target_list, &n_targets);
- gtk_target_list_unref (target_list);
-
gtk_clipboard_set_with_data (gtk_clipboard_get_for_display (gtk_widget_get_display (GTK_WIDGET (browser)), GDK_SELECTION_CLIPBOARD),
targets,
n_targets,
@@ -4075,6 +4113,7 @@ _gth_browser_clipboard_copy_or_cut (GthBrowser *browser,
clipboard_clear_cb,
data);
+ gtk_target_list_unref (target_list);
gtk_target_table_free (targets, n_targets);
_g_object_list_unref (file_list);
_gtk_tree_path_list_free (items);
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index 90306c0..319122e 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -328,6 +328,40 @@ vadj_changed_cb (GtkAdjustment *adjustment,
static void
+file_view_drag_data_get_cb (GtkWidget *widget,
+ GdkDragContext *drag_context,
+ GtkSelectionData *data,
+ guint info,
+ guint time,
+ gpointer user_data)
+{
+ GthFileList *file_list = user_data;
+ GList *items;
+ GList *files;
+ GList *scan;
+ int n_uris;
+ char **uris;
+ int i;
+
+ items = gth_file_selection_get_selected (GTH_FILE_SELECTION (file_list->priv->view));
+ files = gth_file_list_get_files (file_list, items);
+ n_uris = g_list_length (files);
+ uris = g_new (char *, n_uris + 1);
+ for (scan = files, i = 0; scan; scan = scan->next, i++) {
+ GthFileData *file_data = scan->data;
+ uris[i] = g_file_get_uri (file_data->file);
+ }
+ uris[i] = NULL;
+
+ gtk_selection_data_set_uris (data, uris);
+
+ g_strfreev (uris);
+ _g_object_list_unref (files);
+ _gtk_tree_path_list_free (items);
+}
+
+
+static void
gth_file_list_construct (GthFileList *file_list)
{
GtkWidget *scrolled;
@@ -335,6 +369,9 @@ gth_file_list_construct (GthFileList *file_list)
GtkWidget *viewport;
GtkCellRenderer *renderer;
GthFileStore *model;
+ GtkTargetList *target_list;
+ GtkTargetEntry *targets;
+ int n_targets;
/* thumbnail loader */
@@ -383,6 +420,24 @@ gth_file_list_construct (GthFileList *file_list)
file_list->priv->view = gth_icon_view_new_with_model (GTK_TREE_MODEL (model));
g_object_unref (model);
+ target_list = gtk_target_list_new (NULL, 0);
+ gtk_target_list_add_uri_targets (target_list, 0);
+ gtk_target_list_add_text_targets (target_list, 0);
+ targets = gtk_target_table_new_from_list (target_list, &n_targets);
+ gth_file_view_enable_drag_source (GTH_FILE_VIEW (file_list->priv->view),
+ GDK_BUTTON1_MASK,
+ targets,
+ n_targets,
+ GDK_ACTION_MOVE | GDK_ACTION_COPY);
+
+ gtk_target_list_unref (target_list);
+ gtk_target_table_free (targets, n_targets);
+
+ g_signal_connect (G_OBJECT (file_list->priv->view),
+ "drag-data-get",
+ G_CALLBACK (file_view_drag_data_get_cb),
+ file_list);
+
/* thumbnail */
file_list->priv->thumbnail_renderer = renderer = gth_cell_renderer_thumbnail_new ();
diff --git a/gthumb/gth-file-view.c b/gthumb/gth-file-view.c
index 9360b84..c64936b 100644
--- a/gthumb/gth-file-view.c
+++ b/gthumb/gth-file-view.c
@@ -19,7 +19,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA.
*/
-
+
#include "gth-file-view.h"
@@ -38,122 +38,157 @@ gth_file_view_get_model (GthFileView *self)
}
-void
-gth_file_view_set_view_mode (GthFileView *self,
- GthViewMode mode)
+void
+gth_file_view_set_view_mode (GthFileView *self,
+ GthViewMode mode)
{
GTH_FILE_VIEW_GET_INTERFACE (self)->set_view_mode (self, mode);
}
-GthViewMode
-gth_file_view_get_view_mode (GthFileView *self)
+GthViewMode
+gth_file_view_get_view_mode (GthFileView *self)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_view_mode (self);
}
-void
-gth_file_view_scroll_to (GthFileView *self,
- int pos,
- double yalign)
+void
+gth_file_view_scroll_to (GthFileView *self,
+ int pos,
+ double yalign)
{
GTH_FILE_VIEW_GET_INTERFACE (self)->scroll_to (self, pos, yalign);
}
-GthVisibility
-gth_file_view_get_visibility (GthFileView *self,
- int pos)
+GthVisibility
+gth_file_view_get_visibility (GthFileView *self,
+ int pos)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_visibility (self, pos);
}
int
-gth_file_view_get_at_position (GthFileView *self,
- int x,
- int y)
+gth_file_view_get_at_position (GthFileView *self,
+ int x,
+ int y)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_at_position (self, x, y);
}
int
-gth_file_view_get_first_visible (GthFileView *self)
+gth_file_view_get_first_visible (GthFileView *self)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_first_visible (self);
}
int
-gth_file_view_get_last_visible (GthFileView *self)
+gth_file_view_get_last_visible (GthFileView *self)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_last_visible (self);
}
-void
-gth_file_view_activated (GthFileView *self,
- int pos)
+void
+gth_file_view_activated (GthFileView *self,
+ int pos)
{
GTH_FILE_VIEW_GET_INTERFACE (self)->activated (self, pos);
}
-void
-gth_file_view_set_cursor (GthFileView *self,
- int pos)
+void
+gth_file_view_set_cursor (GthFileView *self,
+ int pos)
{
GTH_FILE_VIEW_GET_INTERFACE (self)->set_cursor (self, pos);
}
int
-gth_file_view_get_cursor (GthFileView *self)
+gth_file_view_get_cursor (GthFileView *self)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_cursor (self);
}
-void
-gth_file_view_set_reorderable (GthFileView *self,
+void
+gth_file_view_set_reorderable (GthFileView *self,
gboolean value)
{
GTH_FILE_VIEW_GET_INTERFACE (self)->set_reorderable (self, value);
}
-gboolean
-gth_file_view_get_reorderable (GthFileView *self)
+gboolean
+gth_file_view_get_reorderable (GthFileView *self)
{
return GTH_FILE_VIEW_GET_INTERFACE (self)->get_reorderable (self);
}
-GType
-gth_file_view_get_type (void)
+void
+gth_file_view_enable_drag_source (GthFileView *self,
+ GdkModifierType start_button_mask,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions)
+{
+ GTH_FILE_VIEW_GET_INTERFACE (self)->enable_drag_source (self, start_button_mask, targets, n_targets, actions);
+}
+
+
+void
+gth_file_view_unset_drag_source (GthFileView *self)
+{
+ GTH_FILE_VIEW_GET_INTERFACE (self)->unset_drag_source (self);
+}
+
+
+void
+gth_file_view_enable_drag_dest (GthFileView *self,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions)
+{
+ GTH_FILE_VIEW_GET_INTERFACE (self)->enable_drag_dest (self, targets, n_targets, actions);
+}
+
+
+void
+gth_file_view_unset_drag_dest (GthFileView *self)
+{
+ GTH_FILE_VIEW_GET_INTERFACE (self)->unset_drag_dest (self);
+}
+
+
+GType
+gth_file_view_get_type (void)
{
static GType type = 0;
-
+
if (type == 0) {
- static const GTypeInfo g_define_type_info = {
- sizeof (GthFileViewIface),
- (GBaseInitFunc) NULL,
- (GBaseFinalizeFunc) NULL,
- (GClassInitFunc) NULL,
- (GClassFinalizeFunc) NULL,
- NULL,
- 0,
- 0,
- (GInstanceInitFunc) NULL,
- NULL
+ static const GTypeInfo g_define_type_info = {
+ sizeof (GthFileViewIface),
+ (GBaseInitFunc) NULL,
+ (GBaseFinalizeFunc) NULL,
+ (GClassInitFunc) NULL,
+ (GClassFinalizeFunc) NULL,
+ NULL,
+ 0,
+ 0,
+ (GInstanceInitFunc) NULL,
+ NULL
};
- type = g_type_register_static (G_TYPE_INTERFACE,
- "GthFileView",
- &g_define_type_info,
+ type = g_type_register_static (G_TYPE_INTERFACE,
+ "GthFileView",
+ &g_define_type_info,
0);
}
-
+
return type;
}
diff --git a/gthumb/gth-file-view.h b/gthumb/gth-file-view.h
index 52f2148..49a43d0 100644
--- a/gthumb/gth-file-view.h
+++ b/gthumb/gth-file-view.h
@@ -58,57 +58,79 @@ struct _GthFileViewIface {
/*< virtual functions >*/
- void (*set_model) (GthFileView *self,
- GtkTreeModel *model);
- GtkTreeModel * (*get_model) (GthFileView *self);
- void (*set_view_mode) (GthFileView *self,
- GthViewMode mode);
- GthViewMode (*get_view_mode) (GthFileView *self);
- void (*scroll_to) (GthFileView *self,
- int pos,
- double yalign);
- GthVisibility (*get_visibility) (GthFileView *self,
- int pos);
- int (*get_at_position) (GthFileView *self,
- int x,
- int y);
- int (*get_first_visible) (GthFileView *self);
- int (*get_last_visible) (GthFileView *self);
- void (*activated) (GthFileView *self,
- int pos);
- void (*set_cursor) (GthFileView *self,
- int pos);
- int (*get_cursor) (GthFileView *self);
- void (*set_reorderable) (GthFileView *self,
- gboolean value);
- gboolean (*get_reorderable) (GthFileView *self);
+ void (*set_model) (GthFileView *self,
+ GtkTreeModel *model);
+ GtkTreeModel * (*get_model) (GthFileView *self);
+ void (*set_view_mode) (GthFileView *self,
+ GthViewMode mode);
+ GthViewMode (*get_view_mode) (GthFileView *self);
+ void (*scroll_to) (GthFileView *self,
+ int pos,
+ double yalign);
+ GthVisibility (*get_visibility) (GthFileView *self,
+ int pos);
+ int (*get_at_position) (GthFileView *self,
+ int x,
+ int y);
+ int (*get_first_visible) (GthFileView *self);
+ int (*get_last_visible) (GthFileView *self);
+ void (*activated) (GthFileView *self,
+ int pos);
+ void (*set_cursor) (GthFileView *self,
+ int pos);
+ int (*get_cursor) (GthFileView *self);
+ void (*set_reorderable) (GthFileView *self,
+ gboolean value);
+ gboolean (*get_reorderable) (GthFileView *self);
+ void (*enable_drag_source) (GthFileView *self,
+ GdkModifierType start_button_mask,
+ const GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions);
+ void (*unset_drag_source) (GthFileView *self);
+ void (*enable_drag_dest) (GthFileView *self,
+ const GtkTargetEntry *targets,
+ gint n_targets,
+ GdkDragAction actions);
+ void (*unset_drag_dest) (GthFileView *self);
};
-GType gth_file_view_get_type (void);
-void gth_file_view_set_model (GthFileView *self,
- GtkTreeModel *model);
-GtkTreeModel * gth_file_view_get_model (GthFileView *self);
-void gth_file_view_set_view_mode (GthFileView *self,
- GthViewMode mode);
-GthViewMode gth_file_view_get_view_mode (GthFileView *self);
-void gth_file_view_scroll_to (GthFileView *self,
- int pos,
- double yalign);
-GthVisibility gth_file_view_get_visibility (GthFileView *self,
- int pos);
-int gth_file_view_get_at_position (GthFileView *self,
- int x,
- int y);
-int gth_file_view_get_first_visible (GthFileView *self);
-int gth_file_view_get_last_visible (GthFileView *self);
-void gth_file_view_activated (GthFileView *self,
- int pos);
-void gth_file_view_set_cursor (GthFileView *self,
- int pos);
-int gth_file_view_get_cursor (GthFileView *self);
-void gth_file_view_set_reorderable (GthFileView *self,
- gboolean value);
-gboolean gth_file_view_get_reorderable (GthFileView *self);
+GType gth_file_view_get_type (void);
+void gth_file_view_set_model (GthFileView *self,
+ GtkTreeModel *model);
+GtkTreeModel * gth_file_view_get_model (GthFileView *self);
+void gth_file_view_set_view_mode (GthFileView *self,
+ GthViewMode mode);
+GthViewMode gth_file_view_get_view_mode (GthFileView *self);
+void gth_file_view_scroll_to (GthFileView *self,
+ int pos,
+ double yalign);
+GthVisibility gth_file_view_get_visibility (GthFileView *self,
+ int pos);
+int gth_file_view_get_at_position (GthFileView *self,
+ int x,
+ int y);
+int gth_file_view_get_first_visible (GthFileView *self);
+int gth_file_view_get_last_visible (GthFileView *self);
+void gth_file_view_activated (GthFileView *self,
+ int pos);
+void gth_file_view_set_cursor (GthFileView *self,
+ int pos);
+int gth_file_view_get_cursor (GthFileView *self);
+void gth_file_view_set_reorderable (GthFileView *self,
+ gboolean value);
+gboolean gth_file_view_get_reorderable (GthFileView *self);
+void gth_file_view_enable_drag_source (GthFileView *self,
+ GdkModifierType start_button_mask,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions);
+void gth_file_view_unset_drag_source (GthFileView *self);
+void gth_file_view_enable_drag_dest (GthFileView *self,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions);
+void gth_file_view_unset_drag_dest (GthFileView *self);
G_END_DECLS
diff --git a/gthumb/gth-icon-view.c b/gthumb/gth-icon-view.c
index b924162..c13b7d7 100644
--- a/gthumb/gth-icon-view.c
+++ b/gthumb/gth-icon-view.c
@@ -206,6 +206,48 @@ gth_icon_view_real_get_reorderable (GthFileView *base)
}
+static void
+gth_icon_view_enable_drag_source (GthFileView *self,
+ GdkModifierType start_button_mask,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions)
+{
+ gtk_icon_view_enable_model_drag_source (GTK_ICON_VIEW (self),
+ start_button_mask,
+ targets,
+ n_targets,
+ actions);
+}
+
+
+static void
+gth_icon_view_unset_drag_source (GthFileView *self)
+{
+ gtk_icon_view_unset_model_drag_source (GTK_ICON_VIEW (self));
+}
+
+
+static void
+gth_icon_view_enable_drag_dest (GthFileView *self,
+ const GtkTargetEntry *targets,
+ int n_targets,
+ GdkDragAction actions)
+{
+ gtk_icon_view_enable_model_drag_dest (GTK_ICON_VIEW (self),
+ targets,
+ n_targets,
+ actions);
+}
+
+
+static void
+gth_icon_view_unset_drag_dest (GthFileView *self)
+{
+ gtk_icon_view_unset_model_drag_dest (GTK_ICON_VIEW (self));
+}
+
+
static GList *
gth_icon_view_real_get_selected (GthFileSelection *base)
{
@@ -322,28 +364,26 @@ gtk_icon_view_add_move_binding (GtkBindingSet *binding_set,
GtkMovementStep step,
gint count)
{
- gtk_binding_entry_add_signal (binding_set, keyval, modmask,
- "move_cursor", 2,
- G_TYPE_ENUM, step,
- G_TYPE_INT, count);
-
- gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
- "move_cursor", 2,
- G_TYPE_ENUM, step,
- G_TYPE_INT, count);
-
- if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
- return;
-
- gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
- "move_cursor", 2,
- G_TYPE_ENUM, step,
- G_TYPE_INT, count);
-
- gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
- "move_cursor", 2,
- G_TYPE_ENUM, step,
- G_TYPE_INT, count);
+ gtk_binding_entry_add_signal (binding_set, keyval, modmask,
+ "move_cursor", 2,
+ G_TYPE_ENUM, step,
+ G_TYPE_INT, count);
+ gtk_binding_entry_add_signal (binding_set, keyval, GDK_SHIFT_MASK,
+ "move_cursor", 2,
+ G_TYPE_ENUM, step,
+ G_TYPE_INT, count);
+
+ if ((modmask & GDK_CONTROL_MASK) == GDK_CONTROL_MASK)
+ return;
+
+ gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK | GDK_SHIFT_MASK,
+ "move_cursor", 2,
+ G_TYPE_ENUM, step,
+ G_TYPE_INT, count);
+ gtk_binding_entry_add_signal (binding_set, keyval, GDK_CONTROL_MASK,
+ "move_cursor", 2,
+ G_TYPE_ENUM, step,
+ G_TYPE_INT, count);
}
@@ -392,6 +432,10 @@ gth_icon_view_gth_file_view_interface_init (GthFileViewIface *iface)
iface->get_cursor = gth_icon_view_real_get_cursor;
iface->set_reorderable = gth_icon_view_real_set_reorderable;
iface->get_reorderable = gth_icon_view_real_get_reorderable;
+ iface->enable_drag_source = gth_icon_view_enable_drag_source;
+ iface->unset_drag_source = gth_icon_view_unset_drag_source;
+ iface->enable_drag_dest = gth_icon_view_enable_drag_dest;
+ iface->unset_drag_dest = gth_icon_view_unset_drag_dest;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]