[gedit] File choosers: start to implement GeditFileChooserOpenDialog
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] File choosers: start to implement GeditFileChooserOpenDialog
- Date: Sat, 13 Jun 2020 21:05:52 +0000 (UTC)
commit 986641fbbc912f8b6634d037d92d0a237183b4cd
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sat Jun 13 18:15:19 2020 +0200
File choosers: start to implement GeditFileChooserOpenDialog
gedit/gedit-file-chooser-open-dialog.c | 27 +++++++++++++++++++++++++++
gedit/gedit-file-chooser-open.c | 4 +++-
gedit/gedit-file-chooser.c | 32 +++++++++++++++++++++++++++++++-
3 files changed, 61 insertions(+), 2 deletions(-)
---
diff --git a/gedit/gedit-file-chooser-open-dialog.c b/gedit/gedit-file-chooser-open-dialog.c
index 43f946150..31a0bd2d7 100644
--- a/gedit/gedit-file-chooser-open-dialog.c
+++ b/gedit/gedit-file-chooser-open-dialog.c
@@ -18,6 +18,7 @@
*/
#include "gedit-file-chooser-open-dialog.h"
+#include <glib/gi18n.h>
struct _GeditFileChooserOpenDialogPrivate
{
@@ -33,12 +34,38 @@ _gedit_file_chooser_open_dialog_dispose (GObject *object)
G_OBJECT_CLASS (_gedit_file_chooser_open_dialog_parent_class)->dispose (object);
}
+static GtkFileChooser *
+chooser_create_gtk_file_chooser (GeditFileChooser *chooser)
+{
+ GtkWidget *file_chooser;
+
+ /* Translators: "Open Files" is the title of the file chooser window. */
+ file_chooser = gtk_file_chooser_dialog_new (C_("window title", "Open Files"),
+ NULL,
+ GTK_FILE_CHOOSER_ACTION_OPEN,
+ _("_Cancel"), GTK_RESPONSE_CANCEL,
+ _("_Open"), GTK_RESPONSE_ACCEPT,
+ NULL);
+
+ gtk_dialog_set_default_response (GTK_DIALOG (file_chooser), GTK_RESPONSE_ACCEPT);
+
+ if (g_object_is_floating (file_chooser))
+ {
+ g_object_ref_sink (file_chooser);
+ }
+
+ return GTK_FILE_CHOOSER (file_chooser);
+}
+
static void
_gedit_file_chooser_open_dialog_class_init (GeditFileChooserOpenDialogClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GeditFileChooserClass *file_chooser_class = GEDIT_FILE_CHOOSER_CLASS (klass);
object_class->dispose = _gedit_file_chooser_open_dialog_dispose;
+
+ file_chooser_class->create_gtk_file_chooser = chooser_create_gtk_file_chooser;
}
static void
diff --git a/gedit/gedit-file-chooser-open.c b/gedit/gedit-file-chooser-open.c
index ae9c610cb..dbce1b0a3 100644
--- a/gedit/gedit-file-chooser-open.c
+++ b/gedit/gedit-file-chooser-open.c
@@ -18,6 +18,7 @@
*/
#include "gedit-file-chooser-open.h"
+#include "gedit-file-chooser-open-dialog.h"
#include "gedit-file-chooser-open-native.h"
struct _GeditFileChooserOpenPrivate
@@ -63,7 +64,8 @@ _gedit_file_chooser_open_init (GeditFileChooserOpen *chooser)
GeditFileChooserOpen *
_gedit_file_chooser_open_new (void)
{
- return _gedit_file_chooser_open_native_new ();
+ //return _gedit_file_chooser_open_native_new ();
+ return _gedit_file_chooser_open_dialog_new ();
}
GSList *
diff --git a/gedit/gedit-file-chooser.c b/gedit/gedit-file-chooser.c
index a69565e0d..834a40b04 100644
--- a/gedit/gedit-file-chooser.c
+++ b/gedit/gedit-file-chooser.c
@@ -580,6 +580,10 @@ set_modal (GeditFileChooser *chooser)
{
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 ();
@@ -630,7 +634,19 @@ _gedit_file_chooser_dispose (GObject *object)
{
GeditFileChooser *chooser = GEDIT_FILE_CHOOSER (object);
- g_clear_object (&chooser->priv->gtk_chooser);
+ if (chooser->priv->gtk_chooser != NULL)
+ {
+ if (GTK_IS_WIDGET (chooser->priv->gtk_chooser))
+ {
+ gtk_widget_destroy (GTK_WIDGET (chooser->priv->gtk_chooser));
+ }
+ else
+ {
+ g_object_unref (chooser->priv->gtk_chooser);
+ }
+
+ chooser->priv->gtk_chooser = NULL;
+ }
G_OBJECT_CLASS (_gedit_file_chooser_parent_class)->dispose (object);
}
@@ -669,6 +685,7 @@ _gedit_file_chooser_new (void)
return g_object_new (GEDIT_TYPE_FILE_CHOOSER, NULL);
}
+/* TODO: this function will go away. */
void
_gedit_file_chooser_set_gtk_file_chooser (GeditFileChooser *chooser,
GtkFileChooser *gtk_chooser)
@@ -699,6 +716,15 @@ _gedit_file_chooser_set_transient_for (GeditFileChooser *chooser,
{
gtk_native_dialog_set_transient_for (GTK_NATIVE_DIALOG (chooser->priv->gtk_chooser), parent);
}
+ else if (GTK_IS_WINDOW (chooser->priv->gtk_chooser))
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (chooser->priv->gtk_chooser), parent);
+
+ if (parent != NULL)
+ {
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser->priv->gtk_chooser), TRUE);
+ }
+ }
else
{
g_warn_if_reached ();
@@ -714,6 +740,10 @@ _gedit_file_chooser_show (GeditFileChooser *chooser)
{
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 ();
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]