[gnome-text-editor] page: improve close handling
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-text-editor] page: improve close handling
- Date: Thu, 5 Aug 2021 22:06:37 +0000 (UTC)
commit 42f69275154cc6b5061a45a098acd914c39792f2
Author: Christian Hergert <chergert redhat com>
Date: Thu Aug 5 15:06:31 2021 -0700
page: improve close handling
This ensures we don't hit the page->closing failure in libadwaita.
src/editor-page-private.h | 2 ++
src/editor-window.c | 66 ++++++++++++++++++++++++++++++-----------------
2 files changed, 44 insertions(+), 24 deletions(-)
---
diff --git a/src/editor-page-private.h b/src/editor-page-private.h
index 5d3b53b..4469090 100644
--- a/src/editor-page-private.h
+++ b/src/editor-page-private.h
@@ -55,6 +55,8 @@ struct _EditorPage
EditorSearchBar *search_bar;
GtkInfoBar *changed_infobar;
GtkInfoBar *infobar;
+
+ guint close_requested : 1;
};
void _editor_page_class_actions_init (EditorPageClass *klass);
diff --git a/src/editor-window.c b/src/editor-window.c
index 08c411f..d7e842a 100644
--- a/src/editor-window.c
+++ b/src/editor-window.c
@@ -336,6 +336,31 @@ editor_window_constructed (GObject *object)
}
}
+static gboolean
+on_tab_view_close_page_cb (EditorWindow *self,
+ AdwTabPage *page,
+ AdwTabView *view)
+{
+ EditorPage *epage;
+
+ g_assert (EDITOR_IS_WINDOW (self));
+ g_assert (ADW_IS_TAB_PAGE (page));
+ g_assert (ADW_IS_TAB_VIEW (view));
+
+ if (page != adw_tab_view_get_selected_page (view))
+ adw_tab_view_set_selected_page (view, page);
+
+ if ((epage = EDITOR_PAGE (adw_tab_page_get_child (page))))
+ {
+ epage->close_requested = TRUE;
+
+ if (_editor_window_request_close_page (self, epage))
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
static void
editor_window_actions_close_page_confirm_cb (GObject *object,
GAsyncResult *result,
@@ -357,13 +382,29 @@ editor_window_actions_close_page_confirm_cb (GObject *object,
self = EDITOR_WINDOW (gtk_window_get_transient_for (GTK_WINDOW (object)));
+ g_signal_handlers_block_by_func (self->tab_view,
+ G_CALLBACK (on_tab_view_close_page_cb),
+ self);
+
for (guint i = 0; i < pages->len; i++)
{
EditorPage *epage = g_ptr_array_index (pages, i);
AdwTabPage *page = adw_tab_view_get_page (self->tab_view, GTK_WIDGET (epage));
- adw_tab_view_close_page_finish (self->tab_view, page, confirm_close);
+ g_assert (EDITOR_IS_PAGE (epage));
+ g_assert (ADW_IS_TAB_PAGE (page));
+
+ if (epage->close_requested)
+ adw_tab_view_close_page_finish (self->tab_view, page, confirm_close);
+ else if (confirm_close)
+ adw_tab_view_close_page (self->tab_view, page);
+
+ epage->close_requested = FALSE;
}
+
+ g_signal_handlers_unblock_by_func (self->tab_view,
+ G_CALLBACK (on_tab_view_close_page_cb),
+ self);
}
gboolean
@@ -389,29 +430,6 @@ _editor_window_request_close_page (EditorWindow *self,
return TRUE;
}
-static gboolean
-on_tab_view_close_page_cb (EditorWindow *self,
- AdwTabPage *page,
- AdwTabView *view)
-{
- EditorPage *epage;
-
- g_assert (EDITOR_IS_WINDOW (self));
- g_assert (ADW_IS_TAB_PAGE (page));
- g_assert (ADW_IS_TAB_VIEW (view));
-
- if (page != adw_tab_view_get_selected_page (view))
- adw_tab_view_set_selected_page (view, page);
-
- if ((epage = EDITOR_PAGE (adw_tab_page_get_child (page))))
- {
- if (_editor_window_request_close_page (self, epage))
- return FALSE;
- }
-
- return TRUE;
-}
-
static void
editor_window_dispose (GObject *object)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]