[Xfce4-commits] [xfce/exo] 12/21: Make ExoIconChooserDialog work in Gtk3
noreply at xfce.org
noreply at xfce.org
Tue Jul 12 04:08:04 CEST 2016
This is an automated email from the git hooks/post-receive script.
bluesabre pushed a commit to branch master
in repository xfce/exo.
commit 2426a1ca9dc526ea08a72c74a2b842e9171ef903
Author: Jonas Kümmerlin <rgcjonas at gmail.com>
Date: Sat Aug 8 11:23:46 2015 +0200
Make ExoIconChooserDialog work in Gtk3
So far, it works really well, and doesn't even use deprecated functionality!
---
exo/Makefile.am | 12 ++++++++--
exo/exo-gtk-extensions.c | 15 +++++++++++++
exo/exo-gtk-extensions.h | 4 ++++
exo/exo-icon-chooser-dialog.c | 52 ++++++++++++++++++++++++++++++++++---------
exo/exo-icon-chooser-model.c | 7 ++++++
exo/exo-thumbnail-preview.c | 23 +++++++++++++++----
exo/exo.h | 4 ++--
7 files changed, 99 insertions(+), 18 deletions(-)
diff --git a/exo/Makefile.am b/exo/Makefile.am
index edabac2..25cf13b 100644
--- a/exo/Makefile.am
+++ b/exo/Makefile.am
@@ -126,16 +126,20 @@ libexo_2_include_HEADERS = \
exo-config.h \
exo-execute.h \
exo-gdk-pixbuf-extensions.h \
+ exo-gtk-extensions.h \
exo-gobject-extensions.h \
exo-job.h \
exo-simple-job.h \
exo-string.h \
exo-utils.h \
+ exo-icon-chooser-dialog.h \
+ exo-icon-chooser-model.h \
exo-icon-view.h \
exo-enum-types.h \
exo-toolbars-model.h \
exo-cell-renderer-icon.h \
- exo-thumbnail.h
+ exo-thumbnail.h \
+ exo-thumbnail-preview.h
libexo_2_la_SOURCES = \
$(libexo_2_include_HEADERS) \
@@ -147,15 +151,19 @@ libexo_2_la_SOURCES = \
exo-config.c \
exo-execute.c \
exo-gdk-pixbuf-extensions.c \
+ exo-gtk-extensions.c \
exo-gobject-extensions.c \
exo-job.c \
exo-simple-job.c \
exo-string.c \
exo-utils.c \
+ exo-icon-chooser-dialog.c \
+ exo-icon-chooser-model.c \
exo-icon-view.c \
exo-enum-types.c \
exo-cell-renderer-icon.c \
- exo-thumbnail.c
+ exo-thumbnail.c \
+ exo-thumbnail-preview.c
libexo_2_la_CFLAGS = \
$(LIBXFCE4UTIL_CFLAGS) \
diff --git a/exo/exo-gtk-extensions.c b/exo/exo-gtk-extensions.c
index fc22297..3b2a761 100644
--- a/exo/exo-gtk-extensions.c
+++ b/exo/exo-gtk-extensions.c
@@ -52,7 +52,11 @@
static gboolean
later_destroy (gpointer object)
{
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_widget_destroy (GTK_WIDGET (object));
+#else
gtk_object_destroy (GTK_OBJECT (object));
+#endif
g_object_unref (G_OBJECT (object));
return FALSE;
}
@@ -66,6 +70,16 @@ later_destroy (gpointer object)
* Schedules an idle function to destroy the specified @object
* when the application enters the main loop the next time.
**/
+#if GTK_CHECK_VERSION (3, 0, 0)
+void
+exo_gtk_object_destroy_later (GtkWidget *object)
+{
+ g_return_if_fail (GTK_IS_WIDGET (object));
+
+ g_idle_add_full (G_PRIORITY_HIGH, later_destroy, object, NULL);
+ g_object_ref_sink (object);
+}
+#else
void
exo_gtk_object_destroy_later (GtkObject *object)
{
@@ -74,6 +88,7 @@ exo_gtk_object_destroy_later (GtkObject *object)
g_idle_add_full (G_PRIORITY_HIGH, later_destroy, object, NULL);
g_object_ref_sink (object);
}
+#endif
diff --git a/exo/exo-gtk-extensions.h b/exo/exo-gtk-extensions.h
index 8ef76d8..d0488c4 100644
--- a/exo/exo-gtk-extensions.h
+++ b/exo/exo-gtk-extensions.h
@@ -30,7 +30,11 @@
G_BEGIN_DECLS
+#if GTK_CHECK_VERSION (3, 0, 0)
+void exo_gtk_object_destroy_later (GtkWidget *object);
+#else
void exo_gtk_object_destroy_later (GtkObject *object);
+#endif
void exo_gtk_file_chooser_add_thumbnail_preview (GtkFileChooser *chooser);
diff --git a/exo/exo-icon-chooser-dialog.c b/exo/exo-icon-chooser-dialog.c
index 49dd76f..6d1875d 100644
--- a/exo/exo-icon-chooser-dialog.c
+++ b/exo/exo-icon-chooser-dialog.c
@@ -34,7 +34,6 @@
#include <gdk/gdkkeysyms.h>
#include <exo/exo-binding.h>
-#include <exo/exo-cell-renderer-ellipsized-text.h>
#include <exo/exo-cell-renderer-icon.h>
#include <exo/exo-gtk-extensions.h>
#include <exo/exo-icon-chooser-dialog.h>
@@ -168,8 +167,8 @@ exo_icon_chooser_dialog_class_init (ExoIconChooserDialogClass *klass)
/* connect additional key bindings to the GtkDialog::close action signal */
binding_set = gtk_binding_set_by_class (klass);
- gtk_binding_entry_add_signal (binding_set, GDK_w, GDK_CONTROL_MASK, "close", 0);
- gtk_binding_entry_add_signal (binding_set, GDK_W, GDK_CONTROL_MASK, "close", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_w, GDK_CONTROL_MASK, "close", 0);
+ gtk_binding_entry_add_signal (binding_set, GDK_KEY_W, GDK_CONTROL_MASK, "close", 0);
}
@@ -191,48 +190,79 @@ exo_icon_chooser_dialog_init (ExoIconChooserDialog *icon_chooser_dialog)
gtk_window_set_default_size (GTK_WINDOW (icon_chooser_dialog), 780, 560);
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ /* TODO: use widget templates */
gtk_widget_push_composite_child ();
+#endif
/* add the main box */
+#if GTK_CHECK_VERSION (3, 0, 0)
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 6);
+#else
vbox = gtk_vbox_new (FALSE, 6);
+#endif
gtk_container_set_border_width (GTK_CONTAINER (vbox), 6);
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (icon_chooser_dialog))), vbox, TRUE, TRUE, 0);
gtk_widget_show (vbox);
/* add the header table */
+#if GTK_CHECK_VERSION (3, 0, 0)
+ table = gtk_grid_new ();
+ gtk_grid_set_row_spacing (GTK_GRID (table), 6);
+ gtk_grid_set_column_spacing (GTK_GRID (table), 12);
+#else
table = gtk_table_new (2, 2, FALSE);
gtk_table_set_col_spacings (GTK_TABLE (table), 12);
gtk_table_set_row_spacings (GTK_TABLE (table), 6);
+#endif
gtk_box_pack_start (GTK_BOX (vbox), table, FALSE, FALSE, 0);
gtk_widget_show (table);
/* setup the context combo box */
label = gtk_label_new_with_mnemonic (_("Select _icon from:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+ g_object_set (label, "xalign", 0.0f, "yalign", 0.5f, NULL);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_grid_attach (GTK_GRID (table), label, 0, 0, 1, 1);
+#else
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1, GTK_FILL, GTK_FILL, 0, 0);
+#endif
gtk_widget_show (label);
- priv->combo = gtk_combo_box_new_text ();
+ priv->combo = gtk_combo_box_text_new ();
for (context = 0; context < G_N_ELEMENTS (CONTEXT_TITLES); ++context)
- gtk_combo_box_append_text (GTK_COMBO_BOX (priv->combo), _(CONTEXT_TITLES[context]));
+ gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (priv->combo), _(CONTEXT_TITLES[context]));
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (priv->combo), exo_icon_chooser_dialog_separator_func, icon_chooser_dialog, NULL);
g_signal_connect (G_OBJECT (priv->combo), "changed", G_CALLBACK (exo_icon_chooser_dialog_combo_changed), icon_chooser_dialog);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_grid_attach (GTK_GRID (table), priv->combo, 1, 0, 1, 1);
+ g_object_set (priv->combo, "hexpand", TRUE, NULL);
+#else
gtk_table_attach (GTK_TABLE (table), priv->combo, 1, 2, 0, 1, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+#endif
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->combo);
gtk_widget_show (priv->combo);
/* search filter */
label = gtk_label_new_with_mnemonic (_("_Search icon:"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+ g_object_set (label, "xalign", 0.0f, "yalign", 0.5f, NULL);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_grid_attach (GTK_GRID (table), label, 0, 1, 1, 1);
+#else
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2, GTK_FILL, GTK_FILL, 0, 0);
+#endif
priv->filter_entry = gtk_entry_new ();
exo_binding_new (G_OBJECT (priv->filter_entry), "visible", G_OBJECT (label), "visible");
+#if GTK_CHECK_VERSION (3, 0, 0)
+ gtk_grid_attach (GTK_GRID (table), priv->filter_entry, 1, 1, 1, 1);
+ g_object_set (priv->filter_entry, "hexpand", TRUE, NULL);
+#else
gtk_table_attach (GTK_TABLE (table), priv->filter_entry, 1, 2, 1, 2, GTK_FILL | GTK_EXPAND, GTK_FILL, 0, 0);
+#endif
gtk_label_set_mnemonic_widget (GTK_LABEL (label), priv->filter_entry);
g_signal_connect (G_OBJECT (priv->filter_entry), "changed", G_CALLBACK (exo_icon_chooser_dialog_entry_changed), icon_chooser_dialog);
#if GTK_CHECK_VERSION (2, 16, 0)
- gtk_entry_set_icon_from_stock (GTK_ENTRY (priv->filter_entry), GTK_ENTRY_ICON_SECONDARY, GTK_STOCK_CLEAR);
+ gtk_entry_set_icon_from_icon_name (GTK_ENTRY (priv->filter_entry), GTK_ENTRY_ICON_SECONDARY, "edit-clear");
gtk_entry_set_icon_tooltip_text (GTK_ENTRY (priv->filter_entry), GTK_ENTRY_ICON_SECONDARY, _("Clear search field"));
gtk_entry_set_icon_sensitive (GTK_ENTRY (priv->filter_entry), GTK_ENTRY_ICON_SECONDARY, FALSE);
g_signal_connect (G_OBJECT (priv->filter_entry), "icon-release", G_CALLBACK (exo_icon_chooser_dialog_entry_clear), NULL);
@@ -261,8 +291,8 @@ exo_icon_chooser_dialog_init (ExoIconChooserDialog *icon_chooser_dialog)
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (priv->icon_chooser), renderer, "icon", EXO_ICON_CHOOSER_MODEL_COLUMN_ICON_NAME, NULL);
/* setup the text renderer */
- renderer = g_object_new (EXO_TYPE_CELL_RENDERER_ELLIPSIZED_TEXT,
- "follow-state", TRUE,
+ renderer = g_object_new (GTK_TYPE_CELL_RENDERER_TEXT,
+ /*"follow-state", TRUE,*/
"wrap-mode", PANGO_WRAP_WORD_CHAR,
"wrap-width", 104,
"xalign", 0.5f,
@@ -293,7 +323,9 @@ exo_icon_chooser_dialog_init (ExoIconChooserDialog *icon_chooser_dialog)
/* default to "Application Icons", since thats what users probably expect to see */
gtk_combo_box_set_active (GTK_COMBO_BOX (priv->combo), EXO_ICON_CHOOSER_CONTEXT_APPLICATIONS);
+#if !GTK_CHECK_VERSION (3, 0, 0)
gtk_widget_pop_composite_child ();
+#endif
}
diff --git a/exo/exo-icon-chooser-model.c b/exo/exo-icon-chooser-model.c
index 27a69b4..a1ff777 100644
--- a/exo/exo-icon-chooser-model.c
+++ b/exo/exo-icon-chooser-model.c
@@ -35,6 +35,13 @@
+/* GTK3 deprecated API resurrection */
+#if GTK_CHECK_VERSION (3, 0, 0)
+#define gtk_icon_info_free(info) g_object_unref (info)
+#endif
+
+
+
typedef struct _ExoIconChooserModelItem ExoIconChooserModelItem;
diff --git a/exo/exo-thumbnail-preview.c b/exo/exo-thumbnail-preview.c
index c6439c1..7cb4db2 100644
--- a/exo/exo-thumbnail-preview.c
+++ b/exo/exo-thumbnail-preview.c
@@ -93,12 +93,19 @@ exo_thumbnail_preview_init (ExoThumbnailPreview *thumbnail_preview)
gtk_widget_set_sensitive (GTK_WIDGET (thumbnail_preview), FALSE);
ebox = gtk_event_box_new ();
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ /* TODO: Gtk3 */
gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL, >k_widget_get_style (ebox)->base[GTK_STATE_NORMAL]);
+#endif
g_signal_connect (G_OBJECT (ebox), "style-set", G_CALLBACK (exo_thumbnail_preview_style_set), thumbnail_preview);
gtk_container_add (GTK_CONTAINER (thumbnail_preview), ebox);
gtk_widget_show (ebox);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
+#else
vbox = gtk_vbox_new (FALSE, 0);
+#endif
gtk_container_add (GTK_CONTAINER (ebox), vbox);
gtk_widget_show (vbox);
@@ -111,16 +118,21 @@ exo_thumbnail_preview_init (ExoThumbnailPreview *thumbnail_preview)
gtk_widget_show (button);
label = gtk_label_new (_("Preview"));
- gtk_misc_set_alignment (GTK_MISC (label), 0.0f, 0.5f);
+ g_object_set (label, "xalign", 0.0f, "yalign", 0.5f, NULL);
gtk_container_add (GTK_CONTAINER (button), label);
gtk_widget_show (label);
+#if GTK_CHECK_VERSION (3, 0, 0)
+ box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
+#else
box = gtk_vbox_new (FALSE, 2);
+#endif
+
gtk_container_set_border_width (GTK_CONTAINER (box), 2);
gtk_box_pack_start (GTK_BOX (vbox), box, FALSE, FALSE, 0);
gtk_widget_show (box);
- thumbnail_preview->image = gtk_image_new_from_stock (GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG);
+ thumbnail_preview->image = gtk_image_new_from_icon_name ("image-missing", GTK_ICON_SIZE_DIALOG);
gtk_widget_set_size_request (thumbnail_preview->image, EXO_THUMBNAIL_SIZE_NORMAL + 2 * 12, EXO_THUMBNAIL_SIZE_NORMAL + 2 * 12);
gtk_image_set_pixel_size (GTK_IMAGE (thumbnail_preview->image), EXO_THUMBNAIL_SIZE_NORMAL / 2);
gtk_box_pack_start (GTK_BOX (box), thumbnail_preview->image, FALSE, FALSE, 0);
@@ -152,7 +164,10 @@ exo_thumbnail_preview_style_set (GtkWidget *ebox,
{
/* set background color (using the base color) */
g_signal_handlers_block_by_func (G_OBJECT (ebox), exo_thumbnail_preview_style_set, thumbnail_preview);
+#if !GTK_CHECK_VERSION (3, 0, 0)
+ /*TODO: Gtk3 */
gtk_widget_modify_bg (ebox, GTK_STATE_NORMAL, >k_widget_get_style (ebox)->base[GTK_STATE_NORMAL]);
+#endif
g_signal_handlers_unblock_by_func (G_OBJECT (ebox), exo_thumbnail_preview_style_set, thumbnail_preview);
}
}
@@ -267,7 +282,7 @@ _exo_thumbnail_preview_set_uri (ExoThumbnailPreview *thumbnail_preview,
{
/* the preview widget is insensitive if we don't have an URI */
gtk_widget_set_sensitive (GTK_WIDGET (thumbnail_preview), FALSE);
- gtk_image_set_from_stock (GTK_IMAGE (thumbnail_preview->image), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG);
+ gtk_image_set_from_icon_name (GTK_IMAGE (thumbnail_preview->image), "missing-image", GTK_ICON_SIZE_DIALOG);
gtk_label_set_text (GTK_LABEL (thumbnail_preview->name_label), _("No file selected"));
}
else
@@ -363,7 +378,7 @@ _exo_thumbnail_preview_set_uri (ExoThumbnailPreview *thumbnail_preview,
else
{
/* no thumbnail, cannot display anything useful then */
- gtk_image_set_from_stock (GTK_IMAGE (thumbnail_preview->image), GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_DIALOG);
+ gtk_image_set_from_icon_name (GTK_IMAGE (thumbnail_preview->image), "missing-image", GTK_ICON_SIZE_DIALOG);
}
}
diff --git a/exo/exo.h b/exo/exo.h
index 0d4696d..90ab909 100644
--- a/exo/exo.h
+++ b/exo/exo.h
@@ -45,6 +45,8 @@
#include <exo/exo-simple-job.h>
#include <exo/exo-string.h>
#include <exo/exo-utils.h>
+#include <exo/exo-gtk-extensions.h>
+#include <exo/exo-icon-chooser-dialog.h>
#include <exo/exo-icon-view.h>
#include <exo/exo-toolbars-model.h>
@@ -53,9 +55,7 @@
#include <libxfce4util/libxfce4util.h>
#include <exo/exo-cell-renderer-ellipsized-text.h>
-#include <exo/exo-gtk-extensions.h>
#include <exo/exo-icon-bar.h>
-#include <exo/exo-icon-chooser-dialog.h>
#include <exo/exo-toolbars-editor.h>
#include <exo/exo-toolbars-editor-dialog.h>
#include <exo/exo-toolbars-view.h>
--
To stop receiving notification emails like this one, please contact
the administrator of this repository.
More information about the Xfce4-commits
mailing list