[tepl] Tab loading: move public tepl_tab function to a separate file
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [tepl] Tab loading: move public tepl_tab function to a separate file
- Date: Sun, 24 May 2020 12:19:15 +0000 (UTC)
commit ac0b8d958637dba1fab8231fff16f25a8fd51aef
Author: Sébastien Wilmet <swilmet gnome org>
Date: Sun May 24 14:06:56 2020 +0200
Tab loading: move public tepl_tab function to a separate file
The file loading handling will get more and more complicated over time,
to handle the frontend part. So move the code to a separate file.
po/POTFILES.in | 1 +
tepl/meson.build | 2 +
tepl/tepl-application-window.c | 1 +
tepl/tepl-tab-loading.c | 83 ++++++++++++++++++++++++++++++++++++++++++
tepl/tepl-tab-loading.h | 22 +++++++++++
tepl/tepl-tab.c | 75 --------------------------------------
tepl/tepl-tab.h | 4 --
tepl/tepl.h | 1 +
8 files changed, 110 insertions(+), 79 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index d2a531a..5faab17 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -25,6 +25,7 @@ tepl/tepl-style-scheme-chooser-widget.c
tepl/tepl-tab.c
tepl/tepl-tab-group.c
tepl/tepl-tab-label.c
+tepl/tepl-tab-loading.c
tepl/tepl-tab-saving.c
tepl/tepl-utils.c
tepl/tepl-view.c
diff --git a/tepl/meson.build b/tepl/meson.build
index 15b5d4a..fdd8dfa 100644
--- a/tepl/meson.build
+++ b/tepl/meson.build
@@ -25,6 +25,7 @@ tepl_public_headers = [
'tepl-tab.h',
'tepl-tab-group.h',
'tepl-tab-label.h',
+ 'tepl-tab-loading.h',
'tepl-utils.h',
'tepl-view.h'
]
@@ -54,6 +55,7 @@ tepl_public_c_files = [
'tepl-tab.c',
'tepl-tab-group.c',
'tepl-tab-label.c',
+ 'tepl-tab-loading.c',
'tepl-utils.c',
'tepl-view.c'
]
diff --git a/tepl/tepl-application-window.c b/tepl/tepl-application-window.c
index 718f56a..27ac72f 100644
--- a/tepl/tepl-application-window.c
+++ b/tepl/tepl-application-window.c
@@ -8,6 +8,7 @@
#include "tepl-abstract-factory.h"
#include "tepl-buffer.h"
#include "tepl-signal-group.h"
+#include "tepl-tab-loading.h"
#include "tepl-window-actions-file.h"
#include "tepl-window-actions-edit.h"
#include "tepl-window-actions-search.h"
diff --git a/tepl/tepl-tab-loading.c b/tepl/tepl-tab-loading.c
new file mode 100644
index 0000000..7b381f8
--- /dev/null
+++ b/tepl/tepl-tab-loading.c
@@ -0,0 +1,83 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#include "config.h"
+#include "tepl-tab-loading.h"
+#include <glib/gi18n-lib.h>
+#include "tepl-file-loader.h"
+#include "tepl-info-bar.h"
+
+static void
+load_file_content_cb (GObject *source_object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ TeplFileLoader *loader = TEPL_FILE_LOADER (source_object);
+ TeplTab *tab = TEPL_TAB (user_data);
+ GError *error = NULL;
+
+ if (tepl_file_loader_load_finish (loader, result, &error))
+ {
+ TeplBuffer *buffer;
+ TeplFile *file;
+
+ buffer = tepl_tab_get_buffer (tab);
+ file = tepl_buffer_get_file (buffer);
+ tepl_file_add_uri_to_recent_manager (file);
+ }
+
+ if (error != NULL)
+ {
+ TeplInfoBar *info_bar;
+
+ info_bar = tepl_info_bar_new_simple (GTK_MESSAGE_ERROR,
+ _("Error when loading the file."),
+ error->message);
+
+ tepl_tab_add_info_bar (tab, GTK_INFO_BAR (info_bar));
+ gtk_widget_show (GTK_WIDGET (info_bar));
+
+ g_clear_error (&error);
+ }
+
+ g_object_unref (loader);
+ g_object_unref (tab);
+}
+
+/**
+ * tepl_tab_load_file:
+ * @tab: a #TeplTab.
+ * @location: a #GFile.
+ *
+ * Unconditionally loads a file in @tab, regardless if there are unsaved changes
+ * in the #GtkTextBuffer. The previous buffer content is lost.
+ *
+ * This function is asynchronous, there is no way to know when the file loading
+ * is finished.
+ *
+ * Since: 4.0
+ */
+void
+tepl_tab_load_file (TeplTab *tab,
+ GFile *location)
+{
+ TeplBuffer *buffer;
+ TeplFile *file;
+ TeplFileLoader *loader;
+
+ g_return_if_fail (TEPL_IS_TAB (tab));
+ g_return_if_fail (G_IS_FILE (location));
+
+ buffer = tepl_tab_get_buffer (tab);
+ file = tepl_buffer_get_file (buffer);
+
+ tepl_file_set_location (file, location);
+ loader = tepl_file_loader_new (buffer, file);
+
+ tepl_file_loader_load_async (loader,
+ G_PRIORITY_DEFAULT,
+ NULL, /* cancellable */
+ load_file_content_cb,
+ g_object_ref (tab));
+}
diff --git a/tepl/tepl-tab-loading.h b/tepl/tepl-tab-loading.h
new file mode 100644
index 0000000..521445c
--- /dev/null
+++ b/tepl/tepl-tab-loading.h
@@ -0,0 +1,22 @@
+/* SPDX-FileCopyrightText: 2020 - Sébastien Wilmet <swilmet gnome org>
+ * SPDX-License-Identifier: LGPL-3.0-or-later
+ */
+
+#ifndef TEPL_TAB_LOADING_H
+#define TEPL_TAB_LOADING_H
+
+#if !defined (TEPL_H_INSIDE) && !defined (TEPL_COMPILATION)
+#error "Only <tepl/tepl.h> can be included directly."
+#endif
+
+#include <tepl/tepl-tab.h>
+
+G_BEGIN_DECLS
+
+_TEPL_EXTERN
+void tepl_tab_load_file (TeplTab *tab,
+ GFile *location);
+
+G_END_DECLS
+
+#endif /* TEPL_TAB_LOADING_H */
diff --git a/tepl/tepl-tab.c b/tepl/tepl-tab.c
index 1bce16b..2884d48 100644
--- a/tepl/tepl-tab.c
+++ b/tepl/tepl-tab.c
@@ -6,7 +6,6 @@
#include "tepl-tab.h"
#include <glib/gi18n-lib.h>
#include "tepl-close-confirm-dialog-single.h"
-#include "tepl-file-loader.h"
#include "tepl-file-saver.h"
#include "tepl-info-bar.h"
#include "tepl-tab-group.h"
@@ -507,80 +506,6 @@ tepl_tab_add_info_bar (TeplTab *tab,
TEPL_TAB_GET_CLASS (tab)->pack_info_bar (tab, info_bar);
}
-static void
-load_file_content_cb (GObject *source_object,
- GAsyncResult *result,
- gpointer user_data)
-{
- TeplFileLoader *loader = TEPL_FILE_LOADER (source_object);
- TeplTab *tab = TEPL_TAB (user_data);
- GError *error = NULL;
-
- if (tepl_file_loader_load_finish (loader, result, &error))
- {
- TeplBuffer *buffer;
- TeplFile *file;
-
- buffer = tepl_tab_get_buffer (tab);
- file = tepl_buffer_get_file (buffer);
- tepl_file_add_uri_to_recent_manager (file);
- }
-
- if (error != NULL)
- {
- TeplInfoBar *info_bar;
-
- info_bar = tepl_info_bar_new_simple (GTK_MESSAGE_ERROR,
- _("Error when loading the file."),
- error->message);
-
- tepl_tab_add_info_bar (tab, GTK_INFO_BAR (info_bar));
- gtk_widget_show (GTK_WIDGET (info_bar));
-
- g_clear_error (&error);
- }
-
- g_object_unref (loader);
- g_object_unref (tab);
-}
-
-/**
- * tepl_tab_load_file:
- * @tab: a #TeplTab.
- * @location: a #GFile.
- *
- * Unconditionally loads a file in @tab, regardless if there are unsaved changes
- * in the #GtkTextBuffer. The previous buffer content is lost.
- *
- * This function is asynchronous, there is no way to know when the file loading
- * is finished.
- *
- * Since: 4.0
- */
-void
-tepl_tab_load_file (TeplTab *tab,
- GFile *location)
-{
- TeplBuffer *buffer;
- TeplFile *file;
- TeplFileLoader *loader;
-
- g_return_if_fail (TEPL_IS_TAB (tab));
- g_return_if_fail (G_IS_FILE (location));
-
- buffer = tepl_tab_get_buffer (tab);
- file = tepl_buffer_get_file (buffer);
-
- tepl_file_set_location (file, location);
- loader = tepl_file_loader_new (buffer, file);
-
- tepl_file_loader_load_async (loader,
- G_PRIORITY_DEFAULT,
- NULL, /* cancellable */
- load_file_content_cb,
- g_object_ref (tab));
-}
-
/**
* tepl_tab_save_async:
* @tab: a #TeplTab.
diff --git a/tepl/tepl-tab.h b/tepl/tepl-tab.h
index b9300c4..f7e4580 100644
--- a/tepl/tepl-tab.h
+++ b/tepl/tepl-tab.h
@@ -97,10 +97,6 @@ _TEPL_EXTERN
void tepl_tab_add_info_bar (TeplTab *tab,
GtkInfoBar *info_bar);
-_TEPL_EXTERN
-void tepl_tab_load_file (TeplTab *tab,
- GFile *location);
-
_TEPL_EXTERN
void tepl_tab_save_async (TeplTab *tab,
GAsyncReadyCallback callback,
diff --git a/tepl/tepl.h b/tepl/tepl.h
index dc1fdf7..45f4679 100644
--- a/tepl/tepl.h
+++ b/tepl/tepl.h
@@ -36,6 +36,7 @@
#include <tepl/tepl-tab.h>
#include <tepl/tepl-tab-group.h>
#include <tepl/tepl-tab-label.h>
+#include <tepl/tepl-tab-loading.h>
#include <tepl/tepl-utils.h>
#include <tepl/tepl-view.h>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]