[gnome-builder/wip/chergert/libpanel-changes] libide/gui: implement agree_to_close vfuncs
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-builder/wip/chergert/libpanel-changes] libide/gui: implement agree_to_close vfuncs
- Date: Tue, 13 Sep 2022 19:27:29 +0000 (UTC)
commit faf0e5eead799c7b8529d31b93cf4ddfd618dafd
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 13 12:27:05 2022 -0700
libide/gui: implement agree_to_close vfuncs
This ensures that we get a PanelSaveDialog created when the workspace is
closed with changed documents still open.
src/libide/gui/ide-primary-workspace.c | 23 +++++++++
src/libide/gui/ide-workspace-private.h | 60 ++++++++++++----------
src/libide/gui/ide-workspace.c | 92 ++++++++++++++++++++++++++++++++++
3 files changed, 149 insertions(+), 26 deletions(-)
---
diff --git a/src/libide/gui/ide-primary-workspace.c b/src/libide/gui/ide-primary-workspace.c
index 3bc00cb84..233d88f89 100644
--- a/src/libide/gui/ide-primary-workspace.c
+++ b/src/libide/gui/ide-primary-workspace.c
@@ -244,6 +244,27 @@ toggle_panel_action (gpointer instance,
g_object_set (self->dock, property, FALSE, NULL);
}
+static void
+ide_primary_workspace_agree_to_close_async (IdeWorkspace *workspace,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ _ide_workspace_agree_to_close_async (workspace,
+ IDE_PRIMARY_WORKSPACE (workspace)->grid,
+ cancellable,
+ callback,
+ user_data);
+}
+
+static gboolean
+ide_primary_workspace_agree_to_close_finish (IdeWorkspace *workspace,
+ GAsyncResult *result,
+ GError **error)
+{
+ return _ide_workspace_agree_to_close_finish (workspace, result, error);
+}
+
static void
ide_primary_workspace_dispose (GObject *object)
{
@@ -272,6 +293,8 @@ ide_primary_workspace_class_init (IdePrimaryWorkspaceClass *klass)
workspace_class->add_overlay = ide_primary_workspace_add_overlay;
workspace_class->add_page = ide_primary_workspace_add_page;
workspace_class->add_pane = ide_primary_workspace_add_pane;
+ workspace_class->agree_to_close_async = ide_primary_workspace_agree_to_close_async;
+ workspace_class->agree_to_close_finish = ide_primary_workspace_agree_to_close_finish;
workspace_class->can_search = ide_primary_workspace_can_search;
workspace_class->context_set = ide_primary_workspace_context_set;
workspace_class->foreach_page = ide_primary_workspace_foreach_page;
diff --git a/src/libide/gui/ide-workspace-private.h b/src/libide/gui/ide-workspace-private.h
index 9f52c8987..6d6512dca 100644
--- a/src/libide/gui/ide-workspace-private.h
+++ b/src/libide/gui/ide-workspace-private.h
@@ -26,31 +26,39 @@
G_BEGIN_DECLS
-GList *_ide_workspace_get_mru_link (IdeWorkspace *self);
-void _ide_workspace_add_page_mru (IdeWorkspace *self,
- GList *mru_link);
-void _ide_workspace_remove_page_mru (IdeWorkspace *self,
- GList *mru_link);
-void _ide_workspace_move_front_page_mru (IdeWorkspace *workspace,
- GList *mru_link);
-void _ide_workspace_set_context (IdeWorkspace *workspace,
- IdeContext *context);
-gboolean _ide_workspace_can_search (IdeWorkspace *self);
-void _ide_workspace_begin_global_search (IdeWorkspace *self);
-void _ide_workspace_add_widget (IdeWorkspace *workspace,
- PanelWidget *widget,
- IdePanelPosition *position,
- PanelPaned *dock_start,
- PanelPaned *dock_end,
- PanelPaned *dock_bottom,
- IdeGrid *grid);
-PanelFrame *_ide_workspace_find_frame (IdeWorkspace *workspace,
- IdePanelPosition *position,
- PanelPaned *dock_start,
- PanelPaned *dock_end,
- PanelPaned *dock_bottom,
- IdeGrid *grid);
-void _ide_workspace_set_shortcut_model (IdeWorkspace *self,
- GListModel *shortcuts);
+GList *_ide_workspace_get_mru_link (IdeWorkspace *self);
+void _ide_workspace_add_page_mru (IdeWorkspace *self,
+ GList *mru_link);
+void _ide_workspace_remove_page_mru (IdeWorkspace *self,
+ GList *mru_link);
+void _ide_workspace_move_front_page_mru (IdeWorkspace *workspace,
+ GList *mru_link);
+void _ide_workspace_set_context (IdeWorkspace *workspace,
+ IdeContext *context);
+gboolean _ide_workspace_can_search (IdeWorkspace *self);
+void _ide_workspace_begin_global_search (IdeWorkspace *self);
+void _ide_workspace_add_widget (IdeWorkspace *workspace,
+ PanelWidget *widget,
+ IdePanelPosition *position,
+ PanelPaned *dock_start,
+ PanelPaned *dock_end,
+ PanelPaned *dock_bottom,
+ IdeGrid *grid);
+PanelFrame *_ide_workspace_find_frame (IdeWorkspace *workspace,
+ IdePanelPosition *position,
+ PanelPaned *dock_start,
+ PanelPaned *dock_end,
+ PanelPaned *dock_bottom,
+ IdeGrid *grid);
+void _ide_workspace_set_shortcut_model (IdeWorkspace *self,
+ GListModel *shortcuts);
+void _ide_workspace_agree_to_close_async (IdeWorkspace *self,
+ IdeGrid *grid,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data);
+gboolean _ide_workspace_agree_to_close_finish (IdeWorkspace *self,
+ GAsyncResult *result,
+ GError **error);
G_END_DECLS
diff --git a/src/libide/gui/ide-workspace.c b/src/libide/gui/ide-workspace.c
index fce2a60a3..33b917419 100644
--- a/src/libide/gui/ide-workspace.c
+++ b/src/libide/gui/ide-workspace.c
@@ -22,6 +22,8 @@
#include "config.h"
+#include <libpanel.h>
+
#include <libide-search.h>
#include <libide-plugins.h>
@@ -1528,3 +1530,93 @@ ide_workspace_action_set_enabled (IdeWorkspace *self,
{
ide_action_mixin_set_enabled (self, action_name, enabled);
}
+
+static void
+_ide_workspace_agree_to_close_run_cb (GObject *object,
+ GAsyncResult *result,
+ gpointer user_data)
+{
+ PanelSaveDialog *dialog = (PanelSaveDialog *)object;
+ g_autoptr(IdeTask) task = user_data;
+ g_autoptr(GError) error = NULL;
+
+ IDE_ENTRY;
+
+ g_assert (IDE_IS_MAIN_THREAD ());
+ g_assert (PANEL_IS_SAVE_DIALOG (dialog));
+ g_assert (G_IS_ASYNC_RESULT (result));
+ g_assert (IDE_IS_TASK (task));
+
+ if (!panel_save_dialog_run_finish (dialog, result, &error))
+ ide_task_return_error (task, g_steal_pointer (&error));
+ else
+ ide_task_return_boolean (task, TRUE);
+
+ IDE_EXIT;
+}
+
+static void
+_ide_workspace_agree_to_close_page_cb (IdePage *page,
+ gpointer user_data)
+{
+ PanelSaveDialog *dialog = user_data;
+ PanelSaveDelegate *delegate;
+
+ g_assert (IDE_IS_PAGE (page));
+ g_assert (PANEL_IS_SAVE_DIALOG (dialog));
+
+ if ((delegate = panel_widget_get_save_delegate (PANEL_WIDGET (page))) &&
+ panel_widget_get_modified (PANEL_WIDGET (page)))
+ panel_save_dialog_add_delegate (dialog, delegate);
+}
+
+void
+_ide_workspace_agree_to_close_async (IdeWorkspace *self,
+ IdeGrid *grid,
+ GCancellable *cancellable,
+ GAsyncReadyCallback callback,
+ gpointer user_data)
+{
+ g_autoptr(IdeTask) task = NULL;
+ PanelSaveDialog *dialog;
+
+ IDE_ENTRY;
+
+ g_return_if_fail (IDE_IS_MAIN_THREAD ());
+ g_return_if_fail (IDE_IS_WORKSPACE (self));
+ g_return_if_fail (IDE_IS_GRID (grid));
+ g_return_if_fail (!cancellable || G_IS_CANCELLABLE (cancellable));
+
+ task = ide_task_new (self, cancellable, callback, user_data);
+ ide_task_set_source_tag (task, _ide_workspace_agree_to_close_async);
+
+ dialog = PANEL_SAVE_DIALOG (panel_save_dialog_new ());
+ gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (self));
+ gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
+
+ ide_grid_foreach_page (grid, _ide_workspace_agree_to_close_page_cb, dialog);
+
+ panel_save_dialog_run_async (dialog,
+ cancellable,
+ _ide_workspace_agree_to_close_run_cb,
+ g_steal_pointer (&task));
+
+ IDE_EXIT;
+}
+
+gboolean
+_ide_workspace_agree_to_close_finish (IdeWorkspace *self,
+ GAsyncResult *result,
+ GError **error)
+{
+ gboolean ret;
+
+ IDE_ENTRY;
+
+ g_return_val_if_fail (IDE_IS_WORKSPACE (self), FALSE);
+ g_return_val_if_fail (IDE_IS_TASK (result), FALSE);
+
+ ret = ide_task_propagate_boolean (IDE_TASK (result), error);
+
+ IDE_RETURN (ret);
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]