[gtksourceview/wip/undo-redo: 4/6] UndoManager: update_can_undo_can_redo() utility function
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtksourceview/wip/undo-redo: 4/6] UndoManager: update_can_undo_can_redo() utility function
- Date: Fri, 29 Aug 2014 08:46:41 +0000 (UTC)
commit eba31d2053bc4ab021b7ad84ab1f5ea0be3fcb09
Author: Sébastien Wilmet <swilmet gnome org>
Date: Fri Aug 22 18:42:29 2014 +0200
UndoManager: update_can_undo_can_redo() utility function
gtksourceview/gtksourceundomanagerdefault.c | 83 ++++++++-------------------
1 files changed, 25 insertions(+), 58 deletions(-)
---
diff --git a/gtksourceview/gtksourceundomanagerdefault.c b/gtksourceview/gtksourceundomanagerdefault.c
index d8e9fe1..79d9a16 100644
--- a/gtksourceview/gtksourceundomanagerdefault.c
+++ b/gtksourceview/gtksourceundomanagerdefault.c
@@ -159,6 +159,26 @@ G_DEFINE_TYPE_WITH_CODE (GtkSourceUndoManagerDefault, gtk_source_undo_manager_de
gtk_source_undo_manager_iface_init))
static void
+update_can_undo_can_redo (GtkSourceUndoManagerDefault *manager)
+{
+ guint len = manager->priv->actions->len;
+ gboolean can_undo = manager->priv->next_redo + 1 < len;
+ gboolean can_redo = manager->priv->next_redo >= 0;
+
+ if (manager->priv->can_undo != can_undo)
+ {
+ manager->priv->can_undo = can_undo;
+ gtk_source_undo_manager_can_undo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
+ }
+
+ if (manager->priv->can_redo != can_redo)
+ {
+ manager->priv->can_redo = can_redo;
+ gtk_source_undo_manager_can_redo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
+ }
+}
+
+static void
gtk_source_undo_action_free (GtkSourceUndoAction *action)
{
if (action == NULL)
@@ -477,18 +497,7 @@ add_action (GtkSourceUndoManagerDefault *um,
}
check_list_size (um);
-
- if (!um->priv->can_undo)
- {
- um->priv->can_undo = TRUE;
- gtk_source_undo_manager_can_undo_changed (GTK_SOURCE_UNDO_MANAGER (um));
- }
-
- if (um->priv->can_redo)
- {
- um->priv->can_redo = FALSE;
- gtk_source_undo_manager_can_redo_changed (GTK_SOURCE_UNDO_MANAGER (um));
- }
+ update_can_undo_can_redo (um);
}
static void
@@ -498,17 +507,7 @@ clear_undo (GtkSourceUndoManagerDefault *manager)
manager->priv->next_redo = -1;
- if (manager->priv->can_undo)
- {
- manager->priv->can_undo = FALSE;
- gtk_source_undo_manager_can_undo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
- }
-
- if (manager->priv->can_redo)
- {
- manager->priv->can_redo = FALSE;
- gtk_source_undo_manager_can_redo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
- }
+ update_can_undo_can_redo (manager);
}
static void
@@ -536,19 +535,7 @@ set_max_undo_levels (GtkSourceUndoManagerDefault *manager,
/* now remove undo actions if necessary */
check_list_size (manager);
- /* emit "can_undo" and/or "can_redo" if appropiate */
- if (manager->priv->next_redo < 0 && manager->priv->can_redo)
- {
- manager->priv->can_redo = FALSE;
- gtk_source_undo_manager_can_redo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
- }
-
- if (manager->priv->can_undo &&
- manager->priv->next_redo >= (gint)manager->priv->actions->len - 1)
- {
- manager->priv->can_undo = FALSE;
- gtk_source_undo_manager_can_undo_changed (GTK_SOURCE_UNDO_MANAGER (manager));
- }
+ update_can_undo_can_redo (manager);
}
}
@@ -807,17 +794,7 @@ gtk_source_undo_manager_undo_impl (GtkSourceUndoManager *manager)
manager_default->priv->modified_undoing_group = FALSE;
- if (!manager_default->priv->can_redo)
- {
- manager_default->priv->can_redo = TRUE;
- gtk_source_undo_manager_can_redo_changed (manager);
- }
-
- if (manager_default->priv->next_redo >= (gint)manager_default->priv->actions->len - 1)
- {
- manager_default->priv->can_undo = FALSE;
- gtk_source_undo_manager_can_undo_changed (manager);
- }
+ update_can_undo_can_redo (manager_default);
}
static void
@@ -909,17 +886,7 @@ gtk_source_undo_manager_redo_impl (GtkSourceUndoManager *manager)
/* FIXME: why is this only internal ?*/
end_not_undoable_action_internal (manager_default);
- if (manager_default->priv->next_redo < 0)
- {
- manager_default->priv->can_redo = FALSE;
- gtk_source_undo_manager_can_redo_changed (manager);
- }
-
- if (!manager_default->priv->can_undo)
- {
- manager_default->priv->can_undo = TRUE;
- gtk_source_undo_manager_can_undo_changed (manager);
- }
+ update_can_undo_can_redo (manager_default);
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]