guint populate_all : 1;
guint propagate_text_width : 1;
guint text_handles_enabled : 1;
+ guint enable_undo : 1;
};
struct _GtkTextPasswordHint
static void gtk_text_set_alignment (GtkText *self,
float xalign);
+static void gtk_text_set_enable_undo (GtkText *self,
+ gboolean enable_undo);
+
/* Default signal handlers
*/
static GMenuModel *gtk_text_get_menu_model (GtkText *self);
static void end_change (GtkText *self);
static void emit_changed (GtkText *self);
+static void gtk_text_update_history (GtkText *self);
static void gtk_text_update_clipboard_actions (GtkText *self);
static void gtk_text_update_emoji_action (GtkText *self);
static void gtk_text_update_handles (GtkText *self);
break;
case NUM_PROPERTIES + GTK_EDITABLE_PROP_ENABLE_UNDO:
- if (g_value_get_boolean (value) != gtk_text_history_get_enabled (priv->history))
- {
- gtk_text_history_set_enabled (priv->history, g_value_get_boolean (value));
- g_object_notify_by_pspec (object, pspec);
- }
+ gtk_text_set_enable_undo (self, g_value_get_boolean (value));
break;
/* GtkText properties */
break;
case NUM_PROPERTIES + GTK_EDITABLE_PROP_ENABLE_UNDO:
- g_value_set_boolean (value, gtk_text_history_get_enabled (priv->history));
+ g_value_set_boolean (value, priv->enable_undo);
break;
/* GtkText properties */
priv->cursor_alpha = 1.0;
priv->invisible_char = 0;
priv->history = gtk_text_history_new (&history_funcs, self);
+ priv->enable_undo = TRUE;
gtk_text_history_set_max_undo_levels (priv->history, DEFAULT_MAX_UNDO);
gtk_event_controller_key_set_im_context (GTK_EVENT_CONTROLLER_KEY (priv->key_controller),
is_editable ? priv->im_context : NULL);
+ gtk_text_update_history (self);
gtk_text_update_clipboard_actions (self);
gtk_text_update_emoji_action (self);
gtk_text_recompute (self);
/* disable undo when invisible text is used */
- gtk_text_history_set_enabled (priv->history, visible);
+ gtk_text_update_history (self);
gtk_text_update_clipboard_actions (self);
}
selection_insert,
selection_bound);
}
+
+static void
+gtk_text_set_enable_undo (GtkText *self,
+ gboolean enable_undo)
+{
+ GtkTextPrivate *priv = gtk_text_get_instance_private (self);
+
+ if (priv->enable_undo == enable_undo)
+ return;
+
+ priv->enable_undo = enable_undo;
+ gtk_text_update_history (self);
+ g_object_notify (G_OBJECT (self), "enable-undo");
+}
+
+static void
+gtk_text_update_history (GtkText *self)
+{
+ GtkTextPrivate *priv = gtk_text_get_instance_private (self);
+
+ gtk_text_history_set_enabled (priv->history,
+ priv->enable_undo &&
+ priv->visible &&
+ priv->editable);
+}