icon browser: Set up dnd from the detail popup

Allow dragging the various icon sizes as images.
This commit is contained in:
Matthias Clasen 2015-02-22 14:42:26 -05:00
parent ae63b21c61
commit 1ffcdfcc32
2 changed files with 111 additions and 26 deletions

View File

@ -58,11 +58,31 @@ search_text_changed (GtkEntry *entry, IconBrowserWindow *win)
gtk_tree_model_filter_refilter (win->filter_model);
}
static GdkPixbuf *
get_icon (GtkWidget *image, const gchar *name, gint size)
{
GtkIconInfo *info;
GtkStyleContext *context;
GdkPixbuf *pixbuf;
context = gtk_widget_get_style_context (image);
info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), name, size, 0);
pixbuf = gtk_icon_info_load_symbolic_for_context (info, context, NULL, NULL);
g_object_unref (info);
return pixbuf;
}
static void
set_image (GtkWidget *image, const gchar *name, gint size)
{
GdkPixbuf *pixbuf;
gtk_image_set_from_icon_name (GTK_IMAGE (image), name, 1);
gtk_image_set_pixel_size (GTK_IMAGE (image), size);
pixbuf = get_icon (image, name, size);
gtk_drag_source_set_icon_pixbuf (gtk_widget_get_parent (image), pixbuf);
g_object_unref (pixbuf);
}
static void
@ -83,7 +103,7 @@ item_activated (GtkIconView *icon_view, GtkTreePath *path, IconBrowserWindow *wi
column, &name,
ICON_STORE_DESCRIPTION_COLUMN, &description,
-1);
if (name == NULL || !gtk_icon_theme_has_icon (gtk_icon_theme_get_default (), name))
{
g_free (description);
@ -740,6 +760,40 @@ search_mode_toggled (GObject *searchbar, GParamSpec *pspec, IconBrowserWindow *w
gtk_list_box_unselect_all (GTK_LIST_BOX (win->context_list));
}
static void
get_image_data (GtkWidget *widget,
GdkDragContext *context,
GtkSelectionData *selection,
guint target_info,
guint time,
gpointer data)
{
GtkWidget *image;
const gchar *name;
gint size;
GdkPixbuf *pixbuf;
image = gtk_bin_get_child (GTK_BIN (widget));
gtk_image_get_icon_name (GTK_IMAGE (image), &name, NULL);
size = gtk_image_get_pixel_size (GTK_IMAGE (image));
pixbuf = get_icon (image, name, size);
gtk_selection_data_set_pixbuf (selection, pixbuf);
g_object_unref (pixbuf);
}
static void
setup_image_dnd (GtkWidget *image)
{
GtkWidget *parent;
parent = gtk_widget_get_parent (image);
gtk_drag_source_set (parent, GDK_BUTTON1_MASK, NULL, 0, GDK_ACTION_COPY);
gtk_drag_source_add_image_targets (parent);
g_signal_connect (parent, "drag-data-get", G_CALLBACK (get_image_data), NULL);
}
static void
icon_browser_window_init (IconBrowserWindow *win)
{
@ -761,6 +815,12 @@ icon_browser_window_init (IconBrowserWindow *win)
gtk_target_table_free (targets, n_targets);
setup_image_dnd (win->image1);
setup_image_dnd (win->image2);
setup_image_dnd (win->image3);
setup_image_dnd (win->image4);
setup_image_dnd (win->image5);
win->contexts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, g_free);
gtk_tree_model_filter_set_visible_func (win->filter_model, icon_visible_func, win, NULL);

View File

@ -151,12 +151,17 @@
<property name="row-spacing">10</property>
<property name="column-spacing">10</property>
<child>
<object class="GtkImage" id="image1">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
<child>
<object class="GtkImage" id="image1">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">0</property>
@ -164,12 +169,17 @@
</packing>
</child>
<child>
<object class="GtkImage" id="image2">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
<child>
<object class="GtkImage" id="image2">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">1</property>
@ -177,12 +187,17 @@
</packing>
</child>
<child>
<object class="GtkImage" id="image3">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
<child>
<object class="GtkImage" id="image3">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">2</property>
@ -190,12 +205,17 @@
</packing>
</child>
<child>
<object class="GtkImage" id="image4">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
<child>
<object class="GtkImage" id="image4">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">3</property>
@ -203,12 +223,17 @@
</packing>
</child>
<child>
<object class="GtkImage" id="image5">
<object class="GtkEventBox">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
<child>
<object class="GtkImage" id="image5">
<property name="visible">True</property>
<property name="xpad">4</property>
<property name="ypad">4</property>
<property name="halign">center</property>
<property name="valign">end</property>
</object>
</child>
</object>
<packing>
<property name="left-attach">4</property>