[gtk/wip/chergert/textundo: 1/8] editable: add enable-undo property



commit 69778979e4487d81862cc6b0f0f94969559d88d2
Author: Christian Hergert <chergert redhat com>
Date:   Mon Nov 4 16:40:02 2019 -0800

    editable: add enable-undo property
    
    This property is intended to be mapped to a GtkText so that undo/redo
    support can be used from a number of editable widgets.

 docs/reference/gtk/gtk4-sections.txt |  2 ++
 gtk/gtkeditable.c                    | 48 ++++++++++++++++++++++++++++++++++++
 gtk/gtkeditable.h                    |  6 +++++
 3 files changed, 56 insertions(+)
---
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index 1781176a9e..82a10b250e 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -882,6 +882,8 @@ gtk_editable_get_width_chars
 gtk_editable_set_width_chars
 gtk_editable_get_max_width_chars
 gtk_editable_set_max_width_chars
+gtk_editable_get_enable_undo
+gtk_editable_set_enable_undo
 <SUBSECTION>
 gtk_editable_install_properties
 gtk_editable_init_delegate
diff --git a/gtk/gtkeditable.c b/gtk/gtkeditable.c
index c61b365012..6410e60ed0 100644
--- a/gtk/gtkeditable.c
+++ b/gtk/gtkeditable.c
@@ -379,6 +379,13 @@ gtk_editable_default_init (GtkEditableInterface *iface)
                         0,
                         GTK_PARAM_READABLE));
 
+  g_object_interface_install_property (iface,
+      g_param_spec_boolean ("enable-undo",
+                            P_("Enable Undo"),
+                            P_("If undo/redo should be enabled for the editable"),
+                            TRUE,
+                            GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
   g_object_interface_install_property (iface,
       g_param_spec_int ("selection-bound",
                         P_("Selection Bound"),
@@ -835,6 +842,46 @@ gtk_editable_set_max_width_chars (GtkEditable *editable,
   g_object_set (editable, "max-width-chars", n_chars, NULL);
 }
 
+/**
+ * gtk_editable_get_enable_undo:
+ * @editable: a #GtkEditable
+ *
+ * Gets if undo/redo actions are enabled for @editable
+ *
+ * Returns: %TRUE if undo is enabled
+ */
+gboolean
+gtk_editable_get_enable_undo (GtkEditable *editable)
+{
+  gboolean enable_undo;
+
+  g_return_val_if_fail (GTK_IS_EDITABLE (editable), 0);
+
+  g_object_get (editable, "enable-undo", &enable_undo, NULL);
+
+  return enable_undo;
+}
+
+/**
+ * gtk_editable_set_enable_undo:
+ * @editable: a #GtkEditable
+ * @enable_undo: if undo/redo should be enabled
+ *
+ * If enabled, changes to @editable will be saved for undo/redo actions.
+ *
+ * This results in an additional copy of text changes and are not stored in
+ * secure memory. As such, undo is forcefully disabled when #GtkText:visibility
+ * is set to %FALSE.
+ */
+void
+gtk_editable_set_enable_undo (GtkEditable *editable,
+                              gboolean     enable_undo)
+{
+  g_return_if_fail (GTK_IS_EDITABLE (editable));
+
+  g_object_set (editable, "enable-undo", enable_undo, NULL);
+}
+
 /**
  * gtk_editable_install_properties:
  * @object_class: a #GObjectClass
@@ -869,6 +916,7 @@ gtk_editable_install_properties (GObjectClass *object_class,
   g_object_class_override_property (object_class, first_prop + GTK_EDITABLE_PROP_WIDTH_CHARS, "width-chars");
   g_object_class_override_property (object_class, first_prop + GTK_EDITABLE_PROP_MAX_WIDTH_CHARS, 
"max-width-chars");
   g_object_class_override_property (object_class, first_prop + GTK_EDITABLE_PROP_XALIGN, "xalign");
+  g_object_class_override_property (object_class, first_prop + GTK_EDITABLE_PROP_ENABLE_UNDO, "enable-undo");
 
   return GTK_EDITABLE_NUM_PROPERTIES;
 }
diff --git a/gtk/gtkeditable.h b/gtk/gtkeditable.h
index 2de901fa15..c5539fe84e 100644
--- a/gtk/gtkeditable.h
+++ b/gtk/gtkeditable.h
@@ -138,6 +138,11 @@ int      gtk_editable_get_max_width_chars  (GtkEditable *editable);
 GDK_AVAILABLE_IN_ALL
 void     gtk_editable_set_max_width_chars  (GtkEditable *editable,
                                             int          n_chars);
+GDK_AVAILABLE_IN_ALL
+gboolean gtk_editable_get_enable_undo      (GtkEditable *editable);
+GDK_AVAILABLE_IN_ALL
+void     gtk_editable_set_enable_undo      (GtkEditable *editable,
+                                            gboolean     enable_undo);
 
 /* api for implementations */
 
@@ -149,6 +154,7 @@ typedef enum {
   GTK_EDITABLE_PROP_WIDTH_CHARS,
   GTK_EDITABLE_PROP_MAX_WIDTH_CHARS,
   GTK_EDITABLE_PROP_XALIGN,
+  GTK_EDITABLE_PROP_ENABLE_UNDO,
   GTK_EDITABLE_NUM_PROPERTIES
 } GtkEditableProperties;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]