forked from AuroraMiddleware/gtk
Merge branch 'fix-text-undo-disabling' into 'main'
text: Fix disabling of history Closes #5622 See merge request GNOME/gtk!5565
This commit is contained in:
commit
dbaaa59758
@ -247,6 +247,7 @@ struct _GtkTextPrivate
|
||||
guint populate_all : 1;
|
||||
guint propagate_text_width : 1;
|
||||
guint text_handles_enabled : 1;
|
||||
guint enable_undo : 1;
|
||||
};
|
||||
|
||||
struct _GtkTextPasswordHint
|
||||
@ -397,6 +398,9 @@ static void gtk_text_set_max_width_chars (GtkText *self,
|
||||
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);
|
||||
@ -561,6 +565,7 @@ static void begin_change (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);
|
||||
@ -1602,11 +1607,7 @@ gtk_text_set_property (GObject *object,
|
||||
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 */
|
||||
@ -1732,7 +1733,7 @@ gtk_text_get_property (GObject *object,
|
||||
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 */
|
||||
@ -1858,6 +1859,7 @@ gtk_text_init (GtkText *self)
|
||||
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);
|
||||
|
||||
@ -3400,11 +3402,15 @@ gtk_text_insert_text (GtkText *self,
|
||||
* The incoming text may a password or other secret. We make sure
|
||||
* not to copy it into temporary buffers.
|
||||
*/
|
||||
if (priv->change_count == 0)
|
||||
gtk_text_history_begin_irreversible_action (priv->history);
|
||||
begin_change (self);
|
||||
|
||||
n_inserted = gtk_entry_buffer_insert_text (get_buffer (self), *position, text, n_chars);
|
||||
|
||||
end_change (self);
|
||||
if (priv->change_count == 0)
|
||||
gtk_text_history_end_irreversible_action (priv->history);
|
||||
|
||||
if (n_inserted != n_chars)
|
||||
gtk_widget_error_bell (GTK_WIDGET (self));
|
||||
@ -3426,11 +3432,16 @@ gtk_text_delete_text (GtkText *self,
|
||||
if (start_pos == end_pos)
|
||||
return;
|
||||
|
||||
if (priv->change_count == 0)
|
||||
gtk_text_history_begin_irreversible_action (priv->history);
|
||||
begin_change (self);
|
||||
|
||||
gtk_entry_buffer_delete_text (get_buffer (self), start_pos, end_pos - start_pos);
|
||||
|
||||
end_change (self);
|
||||
if (priv->change_count == 0)
|
||||
gtk_text_history_end_irreversible_action (priv->history);
|
||||
|
||||
update_placeholder_visibility (self);
|
||||
if (priv->propagate_text_width)
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
@ -5525,6 +5536,7 @@ gtk_text_set_editable (GtkText *self,
|
||||
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);
|
||||
|
||||
@ -5605,7 +5617,7 @@ gtk_text_set_visibility (GtkText *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);
|
||||
}
|
||||
@ -7284,3 +7296,28 @@ gtk_text_history_select_cb (gpointer funcs_data,
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user