[gnome-builder] libide/editor: add scaffolding for inhibit logout
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder] libide/editor: add scaffolding for inhibit logout
- Date: Wed, 14 Sep 2022 00:38:53 +0000 (UTC)
commit 5add2144e016d50d7fa9abe8730b28935fd8fd2b
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 13 17:38:38 2022 -0700
libide/editor: add scaffolding for inhibit logout
src/libide/editor/ide-editor-page-private.h | 3 +++
src/libide/editor/ide-editor-page.c | 34 +++++++++++++++++++++++++++++
2 files changed, 37 insertions(+)
---
diff --git a/src/libide/editor/ide-editor-page-private.h b/src/libide/editor/ide-editor-page-private.h
index 86fa88ab9..d904d7c5b 100644
--- a/src/libide/editor/ide-editor-page-private.h
+++ b/src/libide/editor/ide-editor-page-private.h
@@ -37,6 +37,9 @@ struct _IdeEditorPage
IdeBuffer *buffer;
IdeGutter *gutter;
+ /* Inhibit logout from */
+ guint inhibit_cookie;
+
/* Settings Management */
IdeBindingGroup *buffer_file_settings;
IdeBindingGroup *view_file_settings;
diff --git a/src/libide/editor/ide-editor-page.c b/src/libide/editor/ide-editor-page.c
index 144dd0ba5..366a09074 100644
--- a/src/libide/editor/ide-editor-page.c
+++ b/src/libide/editor/ide-editor-page.c
@@ -50,6 +50,38 @@ G_DEFINE_TYPE (IdeEditorPage, ide_editor_page, IDE_TYPE_PAGE)
static GParamSpec *properties [N_PROPS];
+static void
+ide_editor_page_set_inhibit_logout (IdeEditorPage *self,
+ gboolean inhibit_logout)
+{
+ GtkApplication *app;
+ GtkRoot *window;
+
+ g_assert (IDE_IS_EDITOR_PAGE (self));
+
+ inhibit_logout = !!inhibit_logout;
+
+ if (inhibit_logout == !!self->inhibit_cookie)
+ return;
+
+ app = GTK_APPLICATION (IDE_APPLICATION_DEFAULT);
+ window = gtk_widget_get_root (GTK_WIDGET (self));
+
+ if (self->inhibit_cookie)
+ {
+ gtk_application_uninhibit (app, self->inhibit_cookie);
+ self->inhibit_cookie = 0;
+ }
+ else if (GTK_IS_WINDOW (window))
+ {
+ self->inhibit_cookie =
+ gtk_application_inhibit (app,
+ GTK_WINDOW (window),
+ GTK_APPLICATION_INHIBIT_LOGOUT,
+ _("There are unsaved documents"));
+ }
+}
+
static void
ide_editor_page_query_file_info_cb (GObject *object,
GAsyncResult *result,
@@ -596,6 +628,8 @@ ide_editor_page_dispose (GObject *object)
{
IdeEditorPage *self = (IdeEditorPage *)object;
+ ide_editor_page_set_inhibit_logout (self, FALSE);
+
ide_editor_page_set_gutter (self, NULL);
ide_clear_and_destroy_object (&self->addins);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]