[gedit] File choosers: have one place to decide native vs dialog
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] File choosers: have one place to decide native vs dialog
- Date: Sat, 13 Jun 2020 21:05:57 +0000 (UTC)
commit f16604d7be4a331b37f0547b03302f5c67a0c9d0
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 13 19:52:56 2020 +0200
File choosers: have one place to decide native vs dialog
gedit/gedit-file-chooser-open.c | 6 +++++-
gedit/gedit-file-chooser.c | 37 ++++++++++++++++---------------------
gedit/gedit-file-chooser.h | 3 +++
3 files changed, 24 insertions(+), 22 deletions(-)
---
diff --git a/gedit/gedit-file-chooser-open.c b/gedit/gedit-file-chooser-open.c
index dbce1b0a3..2acc65ad4 100644
--- a/gedit/gedit-file-chooser-open.c
+++ b/gedit/gedit-file-chooser-open.c
@@ -64,7 +64,11 @@ _gedit_file_chooser_open_init (GeditFileChooserOpen *chooser)
GeditFileChooserOpen *
_gedit_file_chooser_open_new (void)
{
- //return _gedit_file_chooser_open_native_new ();
+ if (_gedit_file_chooser_is_native ())
+ {
+ return _gedit_file_chooser_open_native_new ();
+ }
+
return _gedit_file_chooser_open_dialog_new ();
}
diff --git a/gedit/gedit-file-chooser.c b/gedit/gedit-file-chooser.c
index 834a40b04..cf1d320a4 100644
--- a/gedit/gedit-file-chooser.c
+++ b/gedit/gedit-file-chooser.c
@@ -41,6 +41,13 @@ G_DEFINE_TYPE_WITH_PRIVATE (GeditFileChooser, _gedit_file_chooser, G_TYPE_OBJECT
#define ALL_FILES _("All Files")
#define ALL_TEXT_FILES _("All Text Files")
+/* Whether to use GtkFileChooserNative or GtkFileChooserDialog. */
+gboolean
+_gedit_file_chooser_is_native (void)
+{
+ return FALSE;
+}
+
static gboolean
mime_types_are_supported (void)
{
@@ -576,17 +583,13 @@ setup_filters (GeditFileChooser *chooser)
static void
set_modal (GeditFileChooser *chooser)
{
- if (GTK_IS_NATIVE_DIALOG (chooser->priv->gtk_chooser))
+ if (_gedit_file_chooser_is_native ())
{
gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (chooser->priv->gtk_chooser), TRUE);
}
- else if (GTK_IS_WINDOW (chooser->priv->gtk_chooser))
- {
- gtk_window_set_modal (GTK_WINDOW (chooser->priv->gtk_chooser), TRUE);
- }
else
{
- g_warn_if_reached ();
+ gtk_window_set_modal (GTK_WINDOW (chooser->priv->gtk_chooser), TRUE);
}
}
@@ -636,13 +639,13 @@ _gedit_file_chooser_dispose (GObject *object)
if (chooser->priv->gtk_chooser != NULL)
{
- if (GTK_IS_WIDGET (chooser->priv->gtk_chooser))
+ if (_gedit_file_chooser_is_native ())
{
- gtk_widget_destroy (GTK_WIDGET (chooser->priv->gtk_chooser));
+ g_object_unref (chooser->priv->gtk_chooser);
}
else
{
- g_object_unref (chooser->priv->gtk_chooser);
+ gtk_widget_destroy (GTK_WIDGET (chooser->priv->gtk_chooser));
}
chooser->priv->gtk_chooser = NULL;
@@ -712,11 +715,11 @@ _gedit_file_chooser_set_transient_for (GeditFileChooser *chooser,
g_return_if_fail (GEDIT_IS_FILE_CHOOSER (chooser));
g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
- if (GTK_IS_NATIVE_DIALOG (chooser->priv->gtk_chooser))
+ if (_gedit_file_chooser_is_native ())
{
gtk_native_dialog_set_transient_for (GTK_NATIVE_DIALOG (chooser->priv->gtk_chooser), parent);
}
- else if (GTK_IS_WINDOW (chooser->priv->gtk_chooser))
+ else
{
gtk_window_set_transient_for (GTK_WINDOW (chooser->priv->gtk_chooser), parent);
@@ -725,10 +728,6 @@ _gedit_file_chooser_set_transient_for (GeditFileChooser *chooser,
gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser->priv->gtk_chooser), TRUE);
}
}
- else
- {
- g_warn_if_reached ();
- }
}
void
@@ -736,17 +735,13 @@ _gedit_file_chooser_show (GeditFileChooser *chooser)
{
g_return_if_fail (GEDIT_IS_FILE_CHOOSER (chooser));
- if (GTK_IS_NATIVE_DIALOG (chooser->priv->gtk_chooser))
+ if (_gedit_file_chooser_is_native ())
{
gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser->priv->gtk_chooser));
}
- else if (GTK_IS_WINDOW (chooser->priv->gtk_chooser))
- {
- gtk_window_present (GTK_WINDOW (chooser->priv->gtk_chooser));
- }
else
{
- g_warn_if_reached ();
+ gtk_window_present (GTK_WINDOW (chooser->priv->gtk_chooser));
}
}
diff --git a/gedit/gedit-file-chooser.h b/gedit/gedit-file-chooser.h
index ef069b918..3c6a1d50e 100644
--- a/gedit/gedit-file-chooser.h
+++ b/gedit/gedit-file-chooser.h
@@ -50,6 +50,9 @@ struct _GeditFileChooserClass
GtkFileChooser * (* create_gtk_file_chooser) (GeditFileChooser *chooser);
};
+G_GNUC_INTERNAL
+gboolean _gedit_file_chooser_is_native (void);
+
G_GNUC_INTERNAL
GType _gedit_file_chooser_get_type (void);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]