From 6a4be7f56bfa7eaa34d04603f0b7fb9c729fc8ac Mon Sep 17 00:00:00 2001 From: Julian Sparber Date: Mon, 7 Aug 2017 23:33:42 +0200 Subject: icon-browser: Add scalable icons to icon detail modal window When making mockups for GNOME apps in Inkscape, looking for symbolic icons is a common task. Searching for icons in the file system is clumsy, and icon-browser provides a much better interface for finding them. However, currently there is no way to insert the symbolic icons as SVG directly from icon-browser, so right now it is only useful for finding the name. This patch adds a sixth column to the modal window that appears when clicking a symbolic icon. The icon in this column is labeled "scalable", and dragging it onto another window results in the vector icon URI being inserted. This enables a much simpler workflow when designing with symbolic icons. https://bugzilla.gnome.org/show_bug.cgi?id=778930 --- demos/icon-browser/iconbrowserwin.c | 65 +++++++++++++++++++++++++++++++++++++ demos/icon-browser/window.ui | 43 +++++++++++++++++++----- 2 files changed, 100 insertions(+), 8 deletions(-) (limited to 'demos') diff --git a/demos/icon-browser/iconbrowserwin.c b/demos/icon-browser/iconbrowserwin.c index 7e33622b4d..f5920cd7cd 100644 --- a/demos/icon-browser/iconbrowserwin.c +++ b/demos/icon-browser/iconbrowserwin.c @@ -4,6 +4,11 @@ #include "iconstore.h" #include +/* Drag 'n Drop */ +static GtkTargetEntry target_table[] = { + { "text/uri-list", 0, 0 }, +}; + typedef struct { gchar *id; @@ -46,6 +51,8 @@ struct _IconBrowserWindow GtkWidget *image3; GtkWidget *image4; GtkWidget *image5; + GtkWidget *image6; + GtkWidget *label6; GtkWidget *description; }; @@ -127,6 +134,19 @@ item_activated (GtkIconView *icon_view, GtkTreePath *path, IconBrowserWindow *wi set_image (win->image3, name, 32); set_image (win->image4, name, 48); set_image (win->image5, name, 64); + if (win->symbolic) + { + gtk_widget_show (win->image6); + gtk_widget_show (win->label6); + gtk_widget_show (gtk_widget_get_parent (win->image6)); + set_image (win->image6, name, 64); + } + else + { + gtk_widget_hide (win->image6); + gtk_widget_hide (win->label6); + gtk_widget_hide (gtk_widget_get_parent (win->image6)); + } if (description && description[0]) { gtk_label_set_text (GTK_LABEL (win->description), description); @@ -380,6 +400,35 @@ get_image_data (GtkWidget *widget, g_object_unref (pixbuf); } +static void +get_scalable_image_data (GtkWidget *widget, + GdkDragContext *context, + GtkSelectionData *selection, + guint target_info, + guint time, + gpointer data) +{ + gchar *uris[2]; + GtkIconInfo *info; + GtkWidget *image; + GFile *file; + const gchar *name; + + image = gtk_bin_get_child (GTK_BIN (widget)); + gtk_image_get_icon_name (GTK_IMAGE (image), &name, NULL); + + info = gtk_icon_theme_lookup_icon (gtk_icon_theme_get_default (), name, -1, 0); + file = g_file_new_for_path (gtk_icon_info_get_filename (info)); + uris[0] = g_file_get_uri (file); + uris[1] = NULL; + + gtk_selection_data_set_uris (selection, uris); + + g_free (uris[0]); + g_object_unref (info); + g_object_unref (file); +} + static void setup_image_dnd (GtkWidget *image) { @@ -391,6 +440,19 @@ setup_image_dnd (GtkWidget *image) g_signal_connect (parent, "drag-data-get", G_CALLBACK (get_image_data), NULL); } +static void +setup_scalable_image_dnd (GtkWidget *image) +{ + GtkWidget *parent; + + parent = gtk_widget_get_parent (image); + gtk_drag_source_set (parent, GDK_BUTTON1_MASK, + target_table, G_N_ELEMENTS (target_table), + GDK_ACTION_COPY); + + g_signal_connect (parent, "drag-data-get", G_CALLBACK (get_scalable_image_data), NULL); +} + static void icon_browser_window_init (IconBrowserWindow *win) { @@ -417,6 +479,7 @@ icon_browser_window_init (IconBrowserWindow *win) setup_image_dnd (win->image3); setup_image_dnd (win->image4); setup_image_dnd (win->image5); + setup_scalable_image_dnd (win->image6); win->contexts = g_hash_table_new_full (g_str_hash, g_str_equal, NULL, context_free); @@ -456,6 +519,8 @@ icon_browser_window_class_init (IconBrowserWindowClass *class) gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, image3); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, image4); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, image5); + gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, image6); + gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, label6); gtk_widget_class_bind_template_child (GTK_WIDGET_CLASS (class), IconBrowserWindow, description); gtk_widget_class_bind_template_callback (GTK_WIDGET_CLASS (class), search_text_changed); diff --git a/demos/icon-browser/window.ui b/demos/icon-browser/window.ui index c4e4b873c9..8183a7d643 100644 --- a/demos/icon-browser/window.ui +++ b/demos/icon-browser/window.ui @@ -150,6 +150,7 @@ 10 18 18 + center True @@ -230,6 +231,22 @@ 1 + + + True + + + True + center + end + + + + + 5 + 1 + + @@ -307,17 +324,18 @@ - + True - True - 60 - 0 - start + center + baseline + scalable + - 0 - 3 - 5 + 5 + 2 @@ -337,6 +355,15 @@ + + + 10 + True + True + 60 + start + + -- cgit v1.2.1