[tepl] Implement some TeplFileChooser functions
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] Implement some TeplFileChooser functions
- Date: Fri, 3 Jul 2020 15:15:16 +0000 (UTC)
commit d800587fb1b3e503af6d531f29fe157d2562a938
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Jul 3 02:48:52 2020 +0200
Implement some TeplFileChooser functions
docs/reference/tepl-docs.xml | 1 +
docs/reference/tepl-sections.txt | 7 +++
po/POTFILES.in | 1 +
tepl/meson.build | 2 +
tepl/tepl-file-chooser.c | 103 +++++++++++++++++++++++++++++++++++++++
tepl/tepl-file-chooser.h | 30 ++++++++++++
tepl/tepl.h | 1 +
7 files changed, 145 insertions(+)
---
diff --git a/docs/reference/tepl-docs.xml b/docs/reference/tepl-docs.xml
index 219235e..a79c404 100644
--- a/docs/reference/tepl-docs.xml
+++ b/docs/reference/tepl-docs.xml
@@ -46,6 +46,7 @@
<xi:include href="xml/file-loader.xml"/>
<xi:include href="xml/file-saver.xml"/>
<xi:include href="xml/io-error-info-bars.xml"/>
+ <xi:include href="xml/file-chooser.xml"/>
</chapter>
<chapter id="file-metadata">
diff --git a/docs/reference/tepl-sections.txt b/docs/reference/tepl-sections.txt
index 96f5441..a17011d 100644
--- a/docs/reference/tepl-sections.txt
+++ b/docs/reference/tepl-sections.txt
@@ -128,6 +128,13 @@ tepl_file_get_type
tepl_newline_type_get_type
</SECTION>
+<SECTION>
+<FILE>file-chooser</FILE>
+tepl_file_chooser_set_modal
+tepl_file_chooser_set_parent
+tepl_file_chooser_show
+</SECTION>
+
<SECTION>
<FILE>file-loader</FILE>
TeplFileLoader
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 872c893..af736ae 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -5,6 +5,7 @@ tepl/tepl-application-window.c
tepl/tepl-buffer.c
tepl/tepl-close-confirm-dialog-single.c
tepl/tepl-file.c
+tepl/tepl-file-chooser.c
tepl/tepl-file-loader.c
tepl/tepl-file-saver.c
tepl/tepl-goto-line-bar.c
diff --git a/tepl/meson.build b/tepl/meson.build
index 226d913..93ca1c5 100644
--- a/tepl/meson.build
+++ b/tepl/meson.build
@@ -5,6 +5,7 @@ tepl_public_headers = [
'tepl-application-window.h',
'tepl-buffer.h',
'tepl-file.h',
+ 'tepl-file-chooser.h',
'tepl-file-loader.h',
'tepl-file-saver.h',
'tepl-fold-region.h',
@@ -37,6 +38,7 @@ tepl_public_c_files = [
'tepl-application-window.c',
'tepl-buffer.c',
'tepl-file.c',
+ 'tepl-file-chooser.c',
'tepl-file-loader.c',
'tepl-file-saver.c',
'tepl-fold-region.c',
diff --git a/tepl/tepl-file-chooser.c b/tepl/tepl-file-chooser.c
new file mode 100644
index 0000000..f8a3eaa
--- /dev/null
+++ b/tepl/tepl-file-chooser.c
@@ -0,0 +1,103 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#include "tepl-file-chooser.h"
+
+/**
+ * SECTION:file-chooser
+ * @Title: TeplFileChooser
+ * @Short_description: Extra functions for #GtkFileChooser
+ *
+ * Extra functions for #GtkFileChooser, to have common code between
+ * #GtkFileChooserDialog and GtkFileChooserNative.
+ */
+
+/**
+ * tepl_file_chooser_set_modal:
+ * @chooser: a #GtkFileChooser.
+ * @modal: the new value.
+ *
+ * Calls either gtk_native_dialog_set_modal() or gtk_window_set_modal()
+ * depending on the @chooser type.
+ *
+ * Since: 5.0
+ */
+void
+tepl_file_chooser_set_modal (GtkFileChooser *chooser,
+ gboolean modal)
+{
+ if (GTK_IS_NATIVE_DIALOG (chooser))
+ {
+ gtk_native_dialog_set_modal (GTK_NATIVE_DIALOG (chooser), modal);
+ }
+ else if (GTK_IS_WINDOW (chooser))
+ {
+ gtk_window_set_modal (GTK_WINDOW (chooser), modal);
+ }
+ else
+ {
+ g_warn_if_reached ();
+ }
+}
+
+/**
+ * tepl_file_chooser_set_parent:
+ * @chooser: a #GtkFileChooser.
+ * @parent: (nullable): a #GtkWindow, or %NULL.
+ *
+ * Sets or unsets a parent #GtkWindow for the @chooser dialog. It calls the
+ * right functions depending on the type of @chooser.
+ *
+ * Since: 5.0
+ */
+void
+tepl_file_chooser_set_parent (GtkFileChooser *chooser,
+ GtkWindow *parent)
+{
+ g_return_if_fail (parent == NULL || GTK_IS_WINDOW (parent));
+
+ if (GTK_IS_NATIVE_DIALOG (chooser))
+ {
+ gtk_native_dialog_set_transient_for (GTK_NATIVE_DIALOG (chooser), parent);
+ }
+ else if (GTK_IS_WINDOW (chooser))
+ {
+ gtk_window_set_transient_for (GTK_WINDOW (chooser), parent);
+
+ if (parent != NULL)
+ {
+ gtk_window_set_destroy_with_parent (GTK_WINDOW (chooser), TRUE);
+ }
+ }
+ else
+ {
+ g_warn_if_reached ();
+ }
+}
+
+/**
+ * tepl_file_chooser_show:
+ * @chooser: a #GtkFileChooser.
+ *
+ * Calls gtk_native_dialog_show() or gtk_window_present() depending on the type
+ * of @chooser.
+ *
+ * Since: 5.0
+ */
+void
+tepl_file_chooser_show (GtkFileChooser *chooser)
+{
+ if (GTK_IS_NATIVE_DIALOG (chooser))
+ {
+ gtk_native_dialog_show (GTK_NATIVE_DIALOG (chooser));
+ }
+ else if (GTK_IS_WINDOW (chooser))
+ {
+ gtk_window_present (GTK_WINDOW (chooser));
+ }
+ else
+ {
+ g_warn_if_reached ();
+ }
+}
diff --git a/tepl/tepl-file-chooser.h b/tepl/tepl-file-chooser.h
new file mode 100644
index 0000000..b7b2cdb
--- /dev/null
+++ b/tepl/tepl-file-chooser.h
@@ -0,0 +1,30 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#ifndef TEPL_FILE_CHOOSER_H
+#define TEPL_FILE_CHOOSER_H
+
+#if !defined (TEPL_H_INSIDE) && !defined (TEPL_COMPILATION)
+#error "Only <tepl/tepl.h> can be included directly."
+#endif
+
+#include <gtk/gtk.h>
+#include <tepl/tepl-macros.h>
+
+G_BEGIN_DECLS
+
+_TEPL_EXTERN
+void tepl_file_chooser_set_modal (GtkFileChooser *chooser,
+ gboolean modal);
+
+_TEPL_EXTERN
+void tepl_file_chooser_set_parent (GtkFileChooser *chooser,
+ GtkWindow *parent);
+
+_TEPL_EXTERN
+void tepl_file_chooser_show (GtkFileChooser *chooser);
+
+G_END_DECLS
+
+#endif /* TEPL_FILE_CHOOSER_H */
diff --git a/tepl/tepl.h b/tepl/tepl.h
index 568fd78..6bfe55c 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -17,6 +17,7 @@
#include <tepl/tepl-application-window.h>
#include <tepl/tepl-buffer.h>
#include <tepl/tepl-file.h>
+#include <tepl/tepl-file-chooser.h>
#include <tepl/tepl-file-loader.h>
#include <tepl/tepl-file-saver.h>
#include <tepl/tepl-fold-region.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]