[gtksourceview/wip/undo-redo] UndoManager: start a new implementation (not finished)



commit 8432f38d34c258746f4e34e016545e58ccb37b6d
Author: Sébastien Wilmet <swilmet gnome org>
Date:   Wed Aug 27 15:59:50 2014 +0200

    UndoManager: start a new implementation (not finished)

 gtksourceview/gtksourceundomanagerdefault.c |  114 ++++++++------------------
 1 files changed, 35 insertions(+), 79 deletions(-)
---
diff --git a/gtksourceview/gtksourceundomanagerdefault.c b/gtksourceview/gtksourceundomanagerdefault.c
index 5935b16..f4ae5c6 100644
--- a/gtksourceview/gtksourceundomanagerdefault.c
+++ b/gtksourceview/gtksourceundomanagerdefault.c
@@ -3,9 +3,10 @@
  * gtksourceundomanagerdefault.c
  * This file is part of GtkSourceView
  *
- * Copyright (C) 1998, 1999 Alex Roberts, Evan Lawrence
- * Copyright (C) 2000, 2001 Chema Celorio, Paolo Maggi
- * Copyright (C) 2002-2005  Paolo Maggi
+ * Copyright (C) 1998, 1999 - Alex Roberts, Evan Lawrence
+ * Copyright (C) 2000, 2001 - Chema Celorio, Paolo Maggi
+ * Copyright (C) 2002-2005  - Paolo Maggi
+ * Copyright (C) 2014 - Sébastien Wilmet <swilmet gnome org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
@@ -22,82 +23,45 @@
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
 #include "gtksourceundomanagerdefault.h"
-#include <string.h>
 #include "gtksourceundomanager.h"
 
-#define DEFAULT_MAX_UNDO_LEVELS -1
-
-/*
- * The old code which used a GSList and g_slist_nth_element
- * was way too slow for many operations (search/replace, hit Ctrl-Z,
- * see gedit freezes). GSList was replaced with a GPtrArray with
- * minimal changes to the code: to avoid insertions at the beginning
- * of the array it uses array beginning as the list end and vice versa;
- * hence bunch of ugly action_list_* functions.
- * FIXME: so, somebody please rewrite this stuff using some nice data
- * structures or something.
- */
-
-typedef struct _GtkSourceUndoAction            GtkSourceUndoAction;
-typedef struct _GtkSourceUndoInsertAction      GtkSourceUndoInsertAction;
-typedef struct _GtkSourceUndoDeleteAction      GtkSourceUndoDeleteAction;
+typedef struct _Action         Action;
+typedef struct _InsertAction   InsertAction;
+typedef struct _DeleteAction   DeleteAction;
 
 typedef enum
 {
-       GTK_SOURCE_UNDO_ACTION_INSERT,
-       GTK_SOURCE_UNDO_ACTION_DELETE
-} GtkSourceUndoActionType;
+       ACTION_INSERT,
+       ACTION_DELETE
+} ActionType;
 
 /* We use offsets instead of GtkTextMarks because the latter require too much
  * memory in this context without giving us any advantage.
  */
 
-struct _GtkSourceUndoInsertAction
+struct _InsertAction
 {
        gint pos;
        gchar *text;
-       gint length;
-       gint chars;
 };
 
-struct _GtkSourceUndoDeleteAction
+struct _DeleteAction
 {
        gint start;
        gint end;
        gchar *text;
-       guint forward : 1;
 };
 
-struct _GtkSourceUndoAction
+struct _Action
 {
-       GtkSourceUndoActionType action_type;
+       ActionType action_type;
 
        union
        {
-               GtkSourceUndoInsertAction insert;
-               GtkSourceUndoDeleteAction delete;
+               InsertAction insert;
+               DeleteAction delete;
        } action;
-
-       gint selection_insert;
-       gint selection_bound;
-
-       gint order_in_group;
-
-       /* It is TRUE whether the action can be merged with the following action. */
-       guint mergeable : 1;
-
-       /* It is TRUE whether the action is marked as "modified".
-        * An action is marked as "modified" if it changed the
-        * state of the buffer from "not modified" to "modified". Only the first
-        * action of a group can be marked as modified.
-        * There can be a single action marked as "modified" in the actions list.
-        */
-       guint modified : 1;
 };
 
 struct _GtkSourceUndoManagerDefaultPrivate
@@ -105,40 +69,32 @@ struct _GtkSourceUndoManagerDefaultPrivate
        /* Weak ref to the buffer. */
        GtkTextBuffer *buffer;
 
-       /* Array of GtkSourceUndoAction's. The most recent action is at the end
-        * of the array. But we can be in the middle of the array if there are
-        * redo actions on the right.
+       /* Groups of actions. A group contains one or several Action's that forms
+        * a single undo or redo step. In fact, actions can be grouped with
+        * gtk_text_buffer_begin_user_action() and
+        * gtk_text_buffer_end_user_action(). So action_groups is a GQueue of
+        * GQueue's of Action's.
+        */
+       GQueue *action_groups;
+
+       /* Pointer to the current action group. */
+       GList *cur_action_group;
+
+       /* Pointer to the action group marked as "modified".
+        * It is NULL when no action is marked as "modified".
         */
-       GPtrArray *actions;
-
-       /* Index of the next redo action. Attention, the index is counted from
-        * the end of the array:
-        * - next_redo of -1: there is no redo actions.
-        * - next_redo of 0: there is one redo action, the last item in
-        *   'actions'.
-        * - next_redo of actions->len - 1: there is no undo actions, the next
-        *   redo action is the first item in 'actions'.
-        * - the next undo action is located at next_redo + 1.
+       GList *modified_action_group;
+
+       /* The number of nested calls to
+        * gtk_source_buffer_begin_not_undoable_action().
         */
-       gint next_redo;
+       guint running_not_undoable_actions;
 
-       gint actions_in_current_group;
-       gint running_not_undoable_actions;
-       gint num_of_groups;
+       /* Max number of groups. */
        gint max_undo_levels;
 
        guint can_undo : 1;
        guint can_redo : 1;
-
-       /* It is TRUE whether, while undoing an action of the current group (with order_in_group > 1),
-        * the state of the buffer changed from "not modified" to "modified".
-        */
-       guint modified_undoing_group : 1;
-
-       /* Pointer to the action (in 'actions') marked as "modified".
-        * It is NULL when no action is marked as "modified".
-        */
-       GtkSourceUndoAction *modified_action;
 };
 
 enum


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