Commit 2af7f424 authored by APOORV SACHAN's avatar APOORV SACHAN 🦋 Committed by António Fernandes

properties-window: Define icon widget in template

The GtkImage that displays the window icon may or may not be contained
by a GtkButton, depending on whether we were able to set a custom icon.

In GtkBuilder UI definitions we cannot do this anymore, as we have to
set a parent for the image widget from the start.

So, define both a simple image and a button with an image, and pack
them in a GtkStack to only show the button when appropriate.
parent 18cfadc8
......@@ -84,13 +84,14 @@ struct _NautilusPropertiesWindow
/* Basic tab widgets */
GtkBox *image_box;
GtkGrid *basic_grid;
GtkWidget *icon_button;
GtkStack *icon_stack;
GtkWidget *icon_image;
GtkWidget *icon_button;
GtkWidget *icon_button_image;
GtkWidget *icon_chooser;
GtkGrid *basic_grid;
GtkLabel *name_label;
GtkWidget *name_field;
unsigned int name_row;
......@@ -410,6 +411,7 @@ update_properties_window_icon (NautilusPropertiesWindow *window)
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf, gtk_widget_get_scale_factor (GTK_WIDGET (window)),
gtk_widget_get_window (GTK_WIDGET (window)));
gtk_image_set_from_surface (GTK_IMAGE (window->icon_image), surface);
gtk_image_set_from_surface (GTK_IMAGE (window->icon_button_image), surface);
g_free (name);
g_object_unref (pixbuf);
......@@ -518,40 +520,30 @@ nautilus_properties_window_drag_data_received (GtkWidget *widget,
g_strfreev (uris);
}
static GtkWidget *
create_image_widget (NautilusPropertiesWindow *window,
gboolean is_customizable)
static void
setup_image_widget (NautilusPropertiesWindow *window,
gboolean is_customizable)
{
GtkWidget *button;
GtkWidget *image;
image = gtk_image_new ();
window->icon_image = image;
update_properties_window_icon (window);
gtk_widget_show (image);
button = NULL;
if (is_customizable)
{
button = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (button), image);
/* prepare the image to receive dropped objects to assign custom images */
gtk_drag_dest_set (GTK_WIDGET (image),
gtk_drag_dest_set (window->icon_button_image,
GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_HIGHLIGHT | GTK_DEST_DEFAULT_DROP,
target_table, G_N_ELEMENTS (target_table),
GDK_ACTION_COPY | GDK_ACTION_MOVE);
g_signal_connect (image, "drag-data-received",
g_signal_connect (window->icon_button_image, "drag-data-received",
G_CALLBACK (nautilus_properties_window_drag_data_received), NULL);
g_signal_connect (button, "clicked",
g_signal_connect (window->icon_button, "clicked",
G_CALLBACK (select_image_button_callback), window);
gtk_stack_set_visible_child (window->icon_stack, window->icon_button);
}
else
{
gtk_stack_set_visible_child (window->icon_stack, window->icon_image);
}
window->icon_button = button;
return button != NULL ? button : image;
}
static void
......@@ -3148,18 +3140,12 @@ static void
create_basic_page (NautilusPropertiesWindow *window)
{
GtkGrid *grid;
GtkWidget *icon_pixmap_widget;
GtkWidget *volume_usage;
GtkWidget *button;
/* Icon pixmap */
icon_pixmap_widget = create_image_widget (
window, should_show_custom_icon_buttons (window));
gtk_widget_set_valign (icon_pixmap_widget, GTK_ALIGN_START);
gtk_widget_show (icon_pixmap_widget);
gtk_box_pack_start (window->image_box, icon_pixmap_widget, FALSE, FALSE, 0);
setup_image_widget (window, should_show_custom_icon_buttons (window));
window->icon_chooser = NULL;
......@@ -5772,7 +5758,10 @@ nautilus_properties_window_class_init (NautilusPropertiesWindowClass *klass)
gtk_widget_class_set_template_from_resource (widget_class, "/org/gnome/nautilus/ui/nautilus-properties-window.ui");
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, notebook);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, image_box);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_stack);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_image);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, icon_button_image);
gtk_widget_class_bind_template_child (widget_class, NautilusPropertiesWindow, basic_grid);
}
......
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.20"/>
<template class="NautilusPropertiesWindow" parent="GtkWindow">
<property name="can_focus">False</property>
<property name="modal">True</property>
<property name="type_hint">dialog</property>
<child type="titlebar">
<placeholder/>
</child>
<child>
<object class="GtkBox" id="content_box">
<property name="visible">True</property>
......@@ -25,12 +22,37 @@
<property name="border_width">12</property>
<property name="spacing">12</property>
<child>
<object class="GtkBox" id="image_box">
<object class="GtkStack" id="icon_stack">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="orientation">vertical</property>
<property name="valign">start</property>
<child>
<placeholder/>
<object class="GtkImage" id="icon_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
<packing>
<property name="name">icon_image</property>
</packing>
</child>
<child>
<object class="GtkButton" id="icon_button">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<child>
<object class="GtkImage" id="icon_button_image">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="stock">gtk-missing-image</property>
</object>
</child>
</object>
<packing>
<property name="name">icon_button</property>
<property name="position">1</property>
</packing>
</child>
</object>
<packing>
......@@ -76,6 +98,9 @@
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
......@@ -126,5 +151,8 @@
</child>
</object>
</child>
<child type="titlebar">
<placeholder/>
</child>
</template>
</interface>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment