[gtk/wip/otte/undo: 10/17] entry: Allow entry to decide to not record undo actions
- From: Benjamin Otte <otte src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/otte/undo: 10/17] entry: Allow entry to decide to not record undo actions
- Date: Mon, 18 Feb 2019 17:13:15 +0000 (UTC)
commit d39f484161b90ecf2f0f75c3bb397298ca0044ae
Author: Benjamin Otte <otte redhat com>
Date: Sun Aug 16 07:41:27 2015 +0200
entry: Allow entry to decide to not record undo actions
This is useful when recording would be nested (should not be happening
now, but might hppen once we add more API).
And more importantly, we don't want to allow undo for password entries.
gtk/gtkentry.c | 27 ++++++++++++++++++++++++++-
1 file changed, 26 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index c83f5afc7d..8a3e481bd0 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -5815,6 +5815,26 @@ struct _GtkEntryRecording {
GtkEntrySnapshot snapshot;
};
+static gboolean
+gtk_entry_should_record (GtkEntry *entry)
+{
+ GtkEntryPrivate *priv = entry->priv;
+
+ /* Password entries should not allow undo because
+ * the undo stack might otherwise contain sensitive
+ * information about passwords.
+ */
+ if (!priv->visible)
+ return FALSE;
+
+ /* Somebody is already recording and recording the same
+ * thing twice makes no sense. */
+ if (priv->undo_mode == GTK_ENTRY_UNDO_RECORD)
+ return FALSE;
+
+ return TRUE;
+}
+
static GtkEntryRecording *
gtk_entry_start_recording (GtkEntry *entry)
{
@@ -5822,6 +5842,9 @@ gtk_entry_start_recording (GtkEntry *entry)
g_return_val_if_fail (GTK_IS_ENTRY (entry), NULL);
+ if (!gtk_entry_should_record (entry))
+ return NULL;
+
recording = g_slice_new0 (GtkEntryRecording);
recording->old_mode = gtk_entry_set_undo_mode (entry, GTK_ENTRY_UNDO_RECORD);
gtk_entry_snapshot_init_from_entry (&recording->snapshot, entry);
@@ -5835,7 +5858,9 @@ gtk_entry_end_recording (GtkEntry *entry,
gboolean commit)
{
g_return_if_fail (GTK_IS_ENTRY (entry));
- g_return_if_fail (recording != NULL);
+
+ if (recording == NULL)
+ return;
if (commit)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]