[gedit] File choosers: make setup_filters() part of the GeditFileChooser class



commit 854794f9a866617bf38e03c06794899acd427c98
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Thu Jun 11 17:29:25 2020 +0200

    File choosers: make setup_filters() part of the GeditFileChooser class

 gedit/gedit-file-chooser-dialog-gtk.c | 24 +++++++++++++++++++++++-
 gedit/gedit-file-chooser-open.c       |  7 +++++--
 gedit/gedit-file-chooser-open.h       |  5 +++--
 gedit/gedit-file-chooser.c            | 19 ++++++++++---------
 gedit/gedit-file-chooser.h            |  2 +-
 5 files changed, 42 insertions(+), 15 deletions(-)
---
diff --git a/gedit/gedit-file-chooser-dialog-gtk.c b/gedit/gedit-file-chooser-dialog-gtk.c
index 8f2eb99b0..c26810e9c 100644
--- a/gedit/gedit-file-chooser-dialog-gtk.c
+++ b/gedit/gedit-file-chooser-dialog-gtk.c
@@ -37,6 +37,8 @@ struct _GeditFileChooserDialogGtk
 {
        GtkFileChooserDialog parent_instance;
 
+       GeditFileChooser *gedit_file_chooser;
+
        GtkWidget *option_menu;
        GtkWidget *extra_widget;
 
@@ -232,9 +234,22 @@ gedit_file_chooser_dialog_gtk_chooser_init (gpointer g_iface,
        iface->get_window = chooser_get_window;
 }
 
+static void
+gedit_file_chooser_dialog_gtk_dispose (GObject *object)
+{
+       GeditFileChooserDialogGtk *dialog = GEDIT_FILE_CHOOSER_DIALOG_GTK (object);
+
+       g_clear_object (&dialog->gedit_file_chooser);
+
+       G_OBJECT_CLASS (gedit_file_chooser_dialog_gtk_parent_class)->dispose (object);
+}
+
 static void
 gedit_file_chooser_dialog_gtk_class_init (GeditFileChooserDialogGtkClass *klass)
 {
+       GObjectClass *object_class = G_OBJECT_CLASS (klass);
+
+       object_class->dispose = gedit_file_chooser_dialog_gtk_dispose;
 }
 
 static void
@@ -427,7 +442,14 @@ gedit_file_chooser_dialog_gtk_create (const gchar *title,
                          G_CALLBACK (action_changed),
                          NULL);
 
-       _gedit_file_chooser_setup_filters (GTK_FILE_CHOOSER (result));
+       /* FIXME: attention, there is a ref cycle here. This will be fixed when
+        * GeditFileChooserSave will be created (and this class removed).
+        */
+       result->gedit_file_chooser = _gedit_file_chooser_new ();
+       _gedit_file_chooser_set_gtk_file_chooser (result->gedit_file_chooser,
+                                                 GTK_FILE_CHOOSER (result));
+
+       _gedit_file_chooser_setup_filters (result->gedit_file_chooser);
 
        if (parent != NULL)
        {
diff --git a/gedit/gedit-file-chooser-open.c b/gedit/gedit-file-chooser-open.c
index 25f38f0cd..792f1ee0b 100644
--- a/gedit/gedit-file-chooser-open.c
+++ b/gedit/gedit-file-chooser-open.c
@@ -34,7 +34,7 @@ enum
 
 static guint signals[N_SIGNALS];
 
-G_DEFINE_TYPE_WITH_PRIVATE (GeditFileChooserOpen, _gedit_file_chooser_open, G_TYPE_OBJECT)
+G_DEFINE_TYPE_WITH_PRIVATE (GeditFileChooserOpen, _gedit_file_chooser_open, GEDIT_TYPE_FILE_CHOOSER)
 
 static void
 _gedit_file_chooser_open_dispose (GObject *object)
@@ -109,7 +109,10 @@ _gedit_file_chooser_open_init (GeditFileChooserOpen *chooser)
 
        gtk_file_chooser_set_local_only (GTK_FILE_CHOOSER (chooser->priv->chooser_native), FALSE);
        gtk_file_chooser_set_select_multiple (GTK_FILE_CHOOSER (chooser->priv->chooser_native), TRUE);
-       _gedit_file_chooser_setup_filters (GTK_FILE_CHOOSER (chooser->priv->chooser_native));
+
+       _gedit_file_chooser_set_gtk_file_chooser (GEDIT_FILE_CHOOSER (chooser),
+                                                 GTK_FILE_CHOOSER (chooser->priv->chooser_native));
+       _gedit_file_chooser_setup_filters (GEDIT_FILE_CHOOSER (chooser));
 
        g_signal_connect (chooser->priv->chooser_native,
                          "response",
diff --git a/gedit/gedit-file-chooser-open.h b/gedit/gedit-file-chooser-open.h
index 91d2e8462..1c27106da 100644
--- a/gedit/gedit-file-chooser-open.h
+++ b/gedit/gedit-file-chooser-open.h
@@ -21,6 +21,7 @@
 #define GEDIT_FILE_CHOOSER_OPEN_H
 
 #include <gtksourceview/gtksource.h>
+#include "gedit-file-chooser.h"
 
 G_BEGIN_DECLS
 
@@ -37,14 +38,14 @@ typedef struct _GeditFileChooserOpenPrivate  GeditFileChooserOpenPrivate;
 
 struct _GeditFileChooserOpen
 {
-       GObject parent;
+       GeditFileChooser parent;
 
        GeditFileChooserOpenPrivate *priv;
 };
 
 struct _GeditFileChooserOpenClass
 {
-       GObjectClass parent_class;
+       GeditFileChooserClass parent_class;
 };
 
 G_GNUC_INTERNAL
diff --git a/gedit/gedit-file-chooser.c b/gedit/gedit-file-chooser.c
index 8cc1ad69a..558bcb496 100644
--- a/gedit/gedit-file-chooser.c
+++ b/gedit/gedit-file-chooser.c
@@ -481,7 +481,7 @@ create_all_text_files_filter (void)
 }
 
 static void
-notify_filter_cb (GtkFileChooser *chooser,
+notify_filter_cb (GtkFileChooser *gtk_chooser,
                  GParamSpec     *pspec,
                  gpointer        user_data)
 {
@@ -493,7 +493,7 @@ notify_filter_cb (GtkFileChooser *chooser,
 
        /* Remember the selected filter. */
 
-       filter = gtk_file_chooser_get_filter (chooser);
+       filter = gtk_file_chooser_get_filter (gtk_chooser);
        if (filter == NULL)
        {
                return;
@@ -551,14 +551,15 @@ _gedit_file_chooser_set_gtk_file_chooser (GeditFileChooser *chooser,
 }
 
 void
-_gedit_file_chooser_setup_filters (GtkFileChooser *chooser)
+_gedit_file_chooser_setup_filters (GeditFileChooser *chooser)
 {
        GeditSettings *settings;
        GSettings *file_chooser_state_settings;
        gint active_filter;
        GtkFileFilter *filter;
 
-       g_return_if_fail (GTK_IS_FILE_CHOOSER (chooser));
+       g_return_if_fail (GEDIT_IS_FILE_CHOOSER (chooser));
+       g_return_if_fail (chooser->priv->gtk_chooser != NULL);
 
        settings = _gedit_settings_get_singleton ();
        file_chooser_state_settings = _gedit_settings_peek_file_chooser_state_settings (settings);
@@ -568,11 +569,11 @@ _gedit_file_chooser_setup_filters (GtkFileChooser *chooser)
        filter = create_all_text_files_filter ();
 
        g_object_ref_sink (filter);
-       gtk_file_chooser_add_filter (chooser, filter);
+       gtk_file_chooser_add_filter (chooser->priv->gtk_chooser, filter);
        if (active_filter != 1)
        {
                /* Use this filter if set by user and as default. */
-               gtk_file_chooser_set_filter (chooser, filter);
+               gtk_file_chooser_set_filter (chooser->priv->gtk_chooser, filter);
        }
        g_object_unref (filter);
 
@@ -582,15 +583,15 @@ _gedit_file_chooser_setup_filters (GtkFileChooser *chooser)
        gtk_file_filter_add_pattern (filter, "*");
 
        g_object_ref_sink (filter);
-       gtk_file_chooser_add_filter (chooser, filter);
+       gtk_file_chooser_add_filter (chooser->priv->gtk_chooser, filter);
        if (active_filter == 1)
        {
                /* Use this filter if set by user. */
-               gtk_file_chooser_set_filter (chooser, filter);
+               gtk_file_chooser_set_filter (chooser->priv->gtk_chooser, filter);
        }
        g_object_unref (filter);
 
-       g_signal_connect (chooser,
+       g_signal_connect (chooser->priv->gtk_chooser,
                          "notify::filter",
                          G_CALLBACK (notify_filter_cb),
                          NULL);
diff --git a/gedit/gedit-file-chooser.h b/gedit/gedit-file-chooser.h
index 5468788a4..73a0f8c9a 100644
--- a/gedit/gedit-file-chooser.h
+++ b/gedit/gedit-file-chooser.h
@@ -58,7 +58,7 @@ void                  _gedit_file_chooser_set_gtk_file_chooser        (GeditFileChooser 
*chooser,
                                                                         GtkFileChooser   *gtk_chooser);
 
 G_GNUC_INTERNAL
-void                   _gedit_file_chooser_setup_filters               (GtkFileChooser *chooser);
+void                   _gedit_file_chooser_setup_filters               (GeditFileChooser *chooser);
 
 G_END_DECLS
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]