[libpanel/wip/chergert/fix-14] save-dialog: add discard signal
- From: Christian Hergert <chergert src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libpanel/wip/chergert/fix-14] save-dialog: add discard signal
- Date: Tue, 13 Sep 2022 17:43:33 +0000 (UTC)
commit 4f01c4eab0dc9216b2ab107ecff39058b94fd127
Author: Christian Hergert <chergert redhat com>
Date: Tue Sep 13 10:33:46 2022 -0700
save-dialog: add discard signal
Implementations are encouraged to use this to rollback changes and/or close
the page represented by the save delegate.
src/panel-save-delegate.c | 28 ++++++++++++++++++++++++++++
src/panel-save-delegate.h | 3 +++
src/panel-save-dialog.c | 9 ++++++++-
3 files changed, 39 insertions(+), 1 deletion(-)
---
diff --git a/src/panel-save-delegate.c b/src/panel-save-delegate.c
index 8e4998d..1821ac7 100644
--- a/src/panel-save-delegate.c
+++ b/src/panel-save-delegate.c
@@ -47,6 +47,7 @@ enum {
};
enum {
+ DISCARD,
SAVE,
N_SIGNALS
};
@@ -328,6 +329,25 @@ panel_save_delegate_class_init (PanelSaveDelegateClass *klass)
g_signal_accumulator_true_handled, NULL,
NULL,
G_TYPE_BOOLEAN, 1, G_TYPE_TASK);
+
+ /**
+ * PanelSaveDelegate::discard:
+ * @self: a #PanelSaveDelegate
+ *
+ * This signal is emitted when the user has requested that the
+ * delegate discard the changes instead of saving them.
+ *
+ * Implementations are encouraged to connect to this signal (or
+ * implement the virtual method) and revert the document to the
+ * last saved state and/or close the document.
+ */
+ signals [DISCARD] = g_signal_new ("discard",
+ G_TYPE_FROM_CLASS (klass),
+ G_SIGNAL_RUN_LAST,
+ G_STRUCT_OFFSET (PanelSaveDelegateClass, discard),
+ NULL, NULL,
+ NULL,
+ G_TYPE_NONE, 0);
}
static void
@@ -572,3 +592,11 @@ panel_save_delegate_set_is_draft (PanelSaveDelegate *self,
g_object_notify_by_pspec (G_OBJECT (self), properties [PROP_IS_DRAFT]);
}
}
+
+void
+panel_save_delegate_discard (PanelSaveDelegate *self)
+{
+ g_return_if_fail (PANEL_IS_SAVE_DELEGATE (self));
+
+ g_signal_emit (self, signals [DISCARD], 0);
+}
diff --git a/src/panel-save-delegate.h b/src/panel-save-delegate.h
index 83b5cc7..2a5d2a3 100644
--- a/src/panel-save-delegate.h
+++ b/src/panel-save-delegate.h
@@ -44,6 +44,7 @@ struct _PanelSaveDelegateClass
GError **error);
gboolean (*save) (PanelSaveDelegate *self,
GTask *task);
+ void (*discard) (PanelSaveDelegate *self);
/*< private >*/
gpointer _reserved[8];
@@ -90,5 +91,7 @@ PANEL_AVAILABLE_IN_ALL
gboolean panel_save_delegate_save_finish (PanelSaveDelegate *self,
GAsyncResult *result,
GError **error);
+PANEL_AVAILABLE_IN_ALL
+void panel_save_delegate_discard (PanelSaveDelegate *self);
G_END_DECLS
diff --git a/src/panel-save-dialog.c b/src/panel-save-dialog.c
index 39398dc..d795df7 100644
--- a/src/panel-save-dialog.c
+++ b/src/panel-save-dialog.c
@@ -80,7 +80,14 @@ panel_save_dialog_response_discard_cb (PanelSaveDialog *self,
task = g_steal_pointer (&self->task);
- /* TODO: Discard widgets */
+ for (guint i = 0; i < self->rows->len; i++)
+ {
+ PanelSaveDialogRow *row = g_ptr_array_index (self->rows, i);
+ PanelSaveDelegate *delegate = panel_save_dialog_row_get_delegate (row);
+
+ panel_save_delegate_discard (delegate);
+ }
+
g_task_return_boolean (task, TRUE);
gtk_window_destroy (GTK_WINDOW (self));
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]