From c3b7079b942d0cf4b6039126f87d15dd05378e97 Mon Sep 17 00:00:00 2001 From: Lance Borden <103229880+BanceDev@users.noreply.github.com> Date: Tue, 11 Jun 2024 05:21:20 -0400 Subject: [PATCH] Cancel file loading when closing tab (#637) (#644) new method _xed_tab_cancel_load is called in xed-notebook to prevent use of computer resources after closing xed or a xed tab --- xed/xed-notebook.c | 6 ++++++ xed/xed-tab.c | 9 +++++++++ xed/xed-tab.h | 2 ++ 3 files changed, 17 insertions(+) diff --git a/xed/xed-notebook.c b/xed/xed-notebook.c index 51cd3c61..1c47afa0 100644 --- a/xed/xed-notebook.c +++ b/xed/xed-notebook.c @@ -902,6 +902,12 @@ static void remove_tab (XedTab *tab, XedNotebook *nb) { + /* First cancel any loading */ + if (xed_tab_get_state (tab) == XED_TAB_STATE_LOADING) + { + _xed_tab_cancel_load (tab); + } + gint position; position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); diff --git a/xed/xed-tab.c b/xed/xed-tab.c index 21effdfc..72729b38 100644 --- a/xed/xed-tab.c +++ b/xed/xed-tab.c @@ -1994,6 +1994,15 @@ _xed_tab_load (XedTab *tab, load (tab, encoding, line_pos); } +void +_xed_tab_cancel_load (XedTab *tab) +{ + g_return_if_fail (XED_IS_PROGRESS_INFO_BAR (tab->priv->info_bar)); + g_return_if_fail (G_IS_CANCELLABLE (tab->priv->cancellable)); + + g_cancellable_cancel (tab->priv->cancellable); +} + void _xed_tab_load_stream (XedTab *tab, GInputStream *stream, diff --git a/xed/xed-tab.h b/xed/xed-tab.h index ac5a3741..c2e7c92d 100644 --- a/xed/xed-tab.h +++ b/xed/xed-tab.h @@ -129,6 +129,8 @@ void _xed_tab_load (XedTab *tab, gint line_pos, gboolean create); +void _xed_tab_cancel_load (XedTab *tab); + void _xed_tab_load_stream (XedTab *tab, GInputStream *location, const GtkSourceEncoding *encoding,