[gtksourceview/wip/chergert/gsv-gtk4: 77/259] undo: remove GtkSourceUndoManager




commit b5a2f855d27a6c3cd6eb150b1f3f769e5ff9fdde
Author: Christian Hergert <chergert redhat com>
Date:   Wed Jan 15 13:40:21 2020 -0800

    undo: remove GtkSourceUndoManager
    
    Undo is now managed by GTK itself (with a more memory compact form of
    the undo manager from GtkSourceView). It has the added benefit that it
    is run from the default GtkTextBuffer handlers right next to the code
    that mutates the B-Tree, meaning that we have a better chance at avoiding
    reply/reordering issues which can happen today.

 docs/reference/meson.build                  |    1 -
 gtksourceview/gtksource.h                   |    1 -
 gtksourceview/gtksourcebuffer-private.h     |    2 -
 gtksourceview/gtksourcebuffer.c             |  493 +--------
 gtksourceview/gtksourcebuffer.h             |   25 -
 gtksourceview/gtksourcebufferoutputstream.c |    8 +-
 gtksourceview/gtksourcetypes-private.h      |    1 -
 gtksourceview/gtksourcetypes.h              |    1 -
 gtksourceview/gtksourceundomanager.c        |  289 -----
 gtksourceview/gtksourceundomanager.h        |   88 --
 gtksourceview/gtksourceundomanagerdefault.c | 1590 ---------------------------
 gtksourceview/gtksourceundomanagerdefault.h |   59 -
 gtksourceview/gtksourceview.c               |   77 --
 gtksourceview/gtksourceview.h               |    2 -
 gtksourceview/meson.build                   |    3 -
 po/POTFILES.in                              |    1 -
 tests/meson.build                           |    1 -
 tests/test-undo-manager-performances.c      |  103 --
 testsuite/meson.build                       |    1 -
 testsuite/test-undo-manager.c               |  918 ----------------
 20 files changed, 5 insertions(+), 3659 deletions(-)
---
diff --git a/docs/reference/meson.build b/docs/reference/meson.build
index 53bd38fa..26cd21b3 100644
--- a/docs/reference/meson.build
+++ b/docs/reference/meson.build
@@ -39,7 +39,6 @@ reference_private_h = [
   'gtksourcestylescheme-private.h',
   'gtksourcestyleschememanager-private.h',
   'gtksourcetypes-private.h',
-  'gtksourceundomanagerdefault.h',
   'gtksourceutils-private.h',
 ]
 
diff --git a/gtksourceview/gtksource.h b/gtksourceview/gtksource.h
index 2f84a3b4..2f795750 100644
--- a/gtksourceview/gtksource.h
+++ b/gtksourceview/gtksource.h
@@ -54,7 +54,6 @@
 #include "gtksourcestyleschemechooserwidget.h"
 #include "gtksourcestyleschememanager.h"
 #include "gtksourcetag.h"
-#include "gtksourceundomanager.h"
 #include "gtksourceutils.h"
 #include "gtksourceversion.h"
 #include "gtksourceview.h"
diff --git a/gtksourceview/gtksourcebuffer-private.h b/gtksourceview/gtksourcebuffer-private.h
index 492c33c8..9b0af482 100644
--- a/gtksourceview/gtksourcebuffer-private.h
+++ b/gtksourceview/gtksourcebuffer-private.h
@@ -67,8 +67,6 @@ void                      _gtk_source_buffer_save_and_clear_selection    (GtkSou
 GTK_SOURCE_INTERNAL
 void                      _gtk_source_buffer_restore_selection           (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
-gboolean                  _gtk_source_buffer_is_undo_redo_enabled        (GtkSourceBuffer        *buffer);
-GTK_SOURCE_INTERNAL
 gboolean                  _gtk_source_buffer_has_source_marks            (GtkSourceBuffer        *buffer);
 GTK_SOURCE_INTERNAL
 gboolean                  _gtk_source_buffer_has_spaces_tag              (GtkSourceBuffer        *buffer);
diff --git a/gtksourceview/gtksourcebuffer.c b/gtksourceview/gtksourcebuffer.c
index cdec9a0d..332bd74e 100644
--- a/gtksourceview/gtksourcebuffer.c
+++ b/gtksourceview/gtksourcebuffer.c
@@ -34,8 +34,6 @@
 #include "gtksourcelanguage.h"
 #include "gtksourcelanguage-private.h"
 #include "gtksource-marshal.h"
-#include "gtksourceundomanager.h"
-#include "gtksourceundomanagerdefault.h"
 #include "gtksourcestyle.h"
 #include "gtksourcestylescheme-private.h"
 #include "gtksourcestyleschememanager.h"
@@ -53,8 +51,7 @@
  *
  * A #GtkSourceBuffer object is the model for #GtkSourceView widgets.
  * It extends the #GtkTextBuffer class by adding features useful to display
- * and edit source code such as syntax highlighting and bracket matching. It
- * also implements support for the undo/redo.
+ * and edit source code such as syntax highlighting and bracket matching.
  *
  * To create a #GtkSourceBuffer use gtk_source_buffer_new() or
  * gtk_source_buffer_new_with_language(). The second form is just a convenience
@@ -65,34 +62,6 @@
  * The highlighting is enabled by default, but you can disable it with
  * gtk_source_buffer_set_highlight_syntax().
  *
- * # Undo/Redo
- *
- * A custom #GtkSourceUndoManager can be implemented and set with
- * gtk_source_buffer_set_undo_manager(). However the default implementation
- * should be suitable for most uses, so you can use the API provided by
- * #GtkSourceBuffer instead of using #GtkSourceUndoManager. By default, actions
- * that can be undone or redone are defined as groups of operations between a
- * call to gtk_text_buffer_begin_user_action() and
- * gtk_text_buffer_end_user_action(). In general, this happens whenever the user
- * presses any key which modifies the buffer. But the default undo manager will
- * try to merge similar consecutive actions into one undo/redo level. The
- * merging is done word by word, so after writing a new sentence (character by
- * character), each undo will remove the previous word.
- *
- * The default undo manager remembers the "modified" state of the buffer, and
- * restores it when an action is undone or redone. It can be useful in a text
- * editor to know whether the file is saved. See gtk_text_buffer_get_modified()
- * and gtk_text_buffer_set_modified().
- *
- * The default undo manager also restores the selected text (or cursor
- * position), if the selection was related to the action. For example if the
- * user selects some text and deletes it, an undo will restore the selection. On
- * the other hand, if some text is selected but a deletion occurs elsewhere (the
- * deletion was done programmatically), an undo will not restore the selection,
- * it will only moves the cursor (the cursor is moved so that the user sees the
- * undo's effect). Warning: the selection restoring behavior might change in the
- * future.
- *
  * # Context Classes # {#context-classes}
  *
  * It is possible to retrieve some information from the syntax highlighting
@@ -178,14 +147,10 @@ enum
 enum
 {
        PROP_0,
-       PROP_CAN_UNDO,
-       PROP_CAN_REDO,
        PROP_HIGHLIGHT_SYNTAX,
        PROP_HIGHLIGHT_MATCHING_BRACKETS,
-       PROP_MAX_UNDO_LEVELS,
        PROP_LANGUAGE,
        PROP_STYLE_SCHEME,
-       PROP_UNDO_MANAGER,
        PROP_IMPLICIT_TRAILING_NEWLINE,
        N_PROPERTIES
 };
@@ -204,9 +169,6 @@ typedef struct
        GtkSourceLanguage *language;
        GtkSourceEngine *highlight_engine;
 
-       GtkSourceUndoManager *undo_manager;
-       gint max_undo_levels;
-
        GtkTextMark *tmp_insert_mark;
        GtkTextMark *tmp_selection_bound_mark;
 
@@ -235,10 +197,6 @@ static void      gtk_source_buffer_get_property         (GObject
                                                         guint                    prop_id,
                                                         GValue                  *value,
                                                         GParamSpec              *pspec);
-static void     gtk_source_buffer_can_undo_handler     (GtkSourceUndoManager    *manager,
-                                                        GtkSourceBuffer         *buffer);
-static void     gtk_source_buffer_can_redo_handler     (GtkSourceUndoManager    *manager,
-                                                        GtkSourceBuffer         *buffer);
 static void     gtk_source_buffer_real_insert_text     (GtkTextBuffer           *buffer,
                                                         GtkTextIter             *iter,
                                                         const gchar             *text,
@@ -260,9 +218,6 @@ static void          gtk_source_buffer_real_mark_set        (GtkTextBuffer           
*buffer,
 static void     gtk_source_buffer_real_mark_deleted    (GtkTextBuffer           *buffer,
                                                         GtkTextMark             *mark);
 
-static void     gtk_source_buffer_real_undo            (GtkSourceBuffer         *buffer);
-static void     gtk_source_buffer_real_redo            (GtkSourceBuffer         *buffer);
-
 static void     gtk_source_buffer_real_highlight_updated
                                                        (GtkSourceBuffer         *buffer,
                                                         GtkTextIter             *start,
@@ -316,15 +271,8 @@ static void
 gtk_source_buffer_constructed (GObject *object)
 {
        GtkSourceBuffer *buffer = GTK_SOURCE_BUFFER (object);
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
        GtkTextTagTable *table;
 
-       if (priv->undo_manager == NULL)
-       {
-               /* This will install the default undo manager */
-               gtk_source_buffer_set_undo_manager (buffer, NULL);
-       }
-
        G_OBJECT_CLASS (gtk_source_buffer_parent_class)->constructed (object);
 
        table = gtk_text_buffer_get_tag_table (GTK_TEXT_BUFFER (buffer));
@@ -359,9 +307,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
        text_buffer_class->mark_set = gtk_source_buffer_real_mark_set;
        text_buffer_class->mark_deleted = gtk_source_buffer_real_mark_deleted;
 
-       klass->undo = gtk_source_buffer_real_undo;
-       klass->redo = gtk_source_buffer_real_redo;
-
        /**
         * GtkSourceBuffer:highlight-syntax:
         *
@@ -388,22 +333,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                      G_PARAM_READWRITE |
                                      G_PARAM_STATIC_STRINGS);
 
-       /**
-        * GtkSourceBuffer:max-undo-levels:
-        *
-        * Number of undo levels for the buffer. -1 means no limit. This property
-        * will only affect the default undo manager.
-        */
-       buffer_properties[PROP_MAX_UNDO_LEVELS] =
-               g_param_spec_int ("max-undo-levels",
-                                 "Maximum Undo Levels",
-                                 "Number of undo levels for the buffer",
-                                 -1,
-                                 G_MAXINT,
-                                 -1,
-                                 G_PARAM_READWRITE |
-                                 G_PARAM_STATIC_STRINGS);
-
        buffer_properties[PROP_LANGUAGE] =
                g_param_spec_object ("language",
                                     "Language",
@@ -412,22 +341,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                     G_PARAM_READWRITE |
                                     G_PARAM_STATIC_STRINGS);
 
-       buffer_properties[PROP_CAN_UNDO] =
-               g_param_spec_boolean ("can-undo",
-                                     "Can undo",
-                                     "Whether Undo operation is possible",
-                                     FALSE,
-                                     G_PARAM_READABLE |
-                                     G_PARAM_STATIC_STRINGS);
-
-       buffer_properties[PROP_CAN_REDO] =
-               g_param_spec_boolean ("can-redo",
-                                     "Can redo",
-                                     "Whether Redo operation is possible",
-                                     FALSE,
-                                     G_PARAM_READABLE |
-                                     G_PARAM_STATIC_STRINGS);
-
        /**
         * GtkSourceBuffer:style-scheme:
         *
@@ -443,15 +356,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                     G_PARAM_READWRITE |
                                     G_PARAM_STATIC_STRINGS);
 
-       buffer_properties[PROP_UNDO_MANAGER] =
-               g_param_spec_object ("undo-manager",
-                                    "Undo manager",
-                                    "The buffer undo manager",
-                                    GTK_SOURCE_TYPE_UNDO_MANAGER,
-                                    G_PARAM_READWRITE |
-                                    G_PARAM_CONSTRUCT |
-                                    G_PARAM_STATIC_STRINGS);
-
        /**
         * GtkSourceBuffer:implicit-trailing-newline:
         *
@@ -517,43 +421,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                    G_TYPE_FROM_CLASS (klass),
                                    g_cclosure_marshal_VOID__OBJECTv);
 
-       /**
-        * GtkSourceBuffer::undo:
-        * @buffer: the buffer that received the signal
-        *
-        * The ::undo signal is emitted to undo the last user action which
-        * modified the buffer.
-        */
-       buffer_signals[UNDO] =
-           g_signal_new ("undo",
-                         G_OBJECT_CLASS_TYPE (object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (GtkSourceBufferClass, undo),
-                         NULL, NULL,
-                         g_cclosure_marshal_VOID__VOID,
-                         G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (buffer_signals[UNDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
-       /**
-        * GtkSourceBuffer::redo:
-        * @buffer: the buffer that received the signal
-        *
-        * The ::redo signal is emitted to redo the last undo operation.
-        */
-       buffer_signals[REDO] =
-           g_signal_new ("redo",
-                         G_OBJECT_CLASS_TYPE (object_class),
-                         G_SIGNAL_RUN_LAST,
-                         G_STRUCT_OFFSET (GtkSourceBufferClass, redo),
-                         NULL, NULL,
-                         g_cclosure_marshal_VOID__VOID,
-                         G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (buffer_signals[REDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
        /**
         * GtkSourceBuffer::bracket-matched:
         * @buffer: a #GtkSourceBuffer.
@@ -586,51 +453,6 @@ gtk_source_buffer_class_init (GtkSourceBufferClass *klass)
                                    _gtk_source_marshal_VOID__BOXED_ENUMv);
 }
 
-static void
-set_undo_manager (GtkSourceBuffer      *buffer,
-                  GtkSourceUndoManager *manager)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       if (manager == priv->undo_manager)
-       {
-               return;
-       }
-
-       if (priv->undo_manager != NULL)
-       {
-               g_signal_handlers_disconnect_by_func (priv->undo_manager,
-                                                     G_CALLBACK (gtk_source_buffer_can_undo_handler),
-                                                     buffer);
-
-               g_signal_handlers_disconnect_by_func (priv->undo_manager,
-                                                     G_CALLBACK (gtk_source_buffer_can_redo_handler),
-                                                     buffer);
-
-               g_object_unref (priv->undo_manager);
-               priv->undo_manager = NULL;
-       }
-
-       if (manager != NULL)
-       {
-               priv->undo_manager = g_object_ref (manager);
-
-               g_signal_connect (priv->undo_manager,
-                                 "can-undo-changed",
-                                 G_CALLBACK (gtk_source_buffer_can_undo_handler),
-                                 buffer);
-
-               g_signal_connect (priv->undo_manager,
-                                 "can-redo-changed",
-                                 G_CALLBACK (gtk_source_buffer_can_redo_handler),
-                                 buffer);
-
-               /* Notify possible changes in the can-undo/redo state */
-               g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
-               g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
-       }
-}
-
 static void
 search_context_weak_notify_cb (GtkSourceBuffer *buffer,
                               GObject         *search_context)
@@ -648,7 +470,6 @@ gtk_source_buffer_init (GtkSourceBuffer *buffer)
        priv->highlight_syntax = TRUE;
        priv->highlight_brackets = TRUE;
        priv->bracket_match_state = GTK_SOURCE_BRACKET_MATCH_NONE;
-       priv->max_undo_levels = -1;
 
        priv->source_marks = g_hash_table_new_full (g_str_hash,
                                                    g_str_equal,
@@ -678,11 +499,6 @@ gtk_source_buffer_dispose (GObject *object)
                priv->bracket_highlighting_timeout_id = 0;
        }
 
-       if (priv->undo_manager != NULL)
-       {
-               set_undo_manager (buffer, NULL);
-       }
-
        if (priv->highlight_engine != NULL)
        {
                _gtk_source_engine_attach_buffer (priv->highlight_engine, NULL);
@@ -733,10 +549,6 @@ gtk_source_buffer_set_property (GObject      *object,
                        gtk_source_buffer_set_highlight_matching_brackets (buffer, g_value_get_boolean 
(value));
                        break;
 
-               case PROP_MAX_UNDO_LEVELS:
-                       gtk_source_buffer_set_max_undo_levels (buffer, g_value_get_int (value));
-                       break;
-
                case PROP_LANGUAGE:
                        gtk_source_buffer_set_language (buffer, g_value_get_object (value));
                        break;
@@ -745,10 +557,6 @@ gtk_source_buffer_set_property (GObject      *object,
                        gtk_source_buffer_set_style_scheme (buffer, g_value_get_object (value));
                        break;
 
-               case PROP_UNDO_MANAGER:
-                       gtk_source_buffer_set_undo_manager (buffer, g_value_get_object (value));
-                       break;
-
                case PROP_IMPLICIT_TRAILING_NEWLINE:
                        gtk_source_buffer_set_implicit_trailing_newline (buffer, g_value_get_boolean (value));
                        break;
@@ -778,10 +586,6 @@ gtk_source_buffer_get_property (GObject    *object,
                        g_value_set_boolean (value, priv->highlight_brackets);
                        break;
 
-               case PROP_MAX_UNDO_LEVELS:
-                       g_value_set_int (value, priv->max_undo_levels);
-                       break;
-
                case PROP_LANGUAGE:
                        g_value_set_object (value, priv->language);
                        break;
@@ -790,18 +594,6 @@ gtk_source_buffer_get_property (GObject    *object,
                        g_value_set_object (value, priv->style_scheme);
                        break;
 
-               case PROP_CAN_UNDO:
-                       g_value_set_boolean (value, gtk_source_buffer_can_undo (buffer));
-                       break;
-
-               case PROP_CAN_REDO:
-                       g_value_set_boolean (value, gtk_source_buffer_can_redo (buffer));
-                       break;
-
-               case PROP_UNDO_MANAGER:
-                       g_value_set_object (value, priv->undo_manager);
-                       break;
-
                case PROP_IMPLICIT_TRAILING_NEWLINE:
                        g_value_set_boolean (value, priv->implicit_trailing_newline);
                        break;
@@ -852,24 +644,6 @@ gtk_source_buffer_new_with_language (GtkSourceLanguage *language)
                             NULL);
 }
 
-static void
-gtk_source_buffer_can_undo_handler (GtkSourceUndoManager *manager,
-                                    GtkSourceBuffer      *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_UNDO]);
-}
-
-static void
-gtk_source_buffer_can_redo_handler (GtkSourceUndoManager *manager,
-                                    GtkSourceBuffer      *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_CAN_REDO]);
-}
-
 static void
 update_bracket_match_style (GtkSourceBuffer *buffer)
 {
@@ -1532,195 +1306,6 @@ _gtk_source_buffer_find_bracket_match (GtkSourceBuffer   *buffer,
        return result_right;
 }
 
-/**
- * gtk_source_buffer_can_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can undo the last action.
- *
- * Returns: %TRUE if it's possible to undo the last action.
- */
-gboolean
-gtk_source_buffer_can_undo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       return gtk_source_undo_manager_can_undo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_can_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines whether a source buffer can redo the last action
- * (i.e. if the last operation was an undo).
- *
- * Returns: %TRUE if a redo is possible.
- */
-gboolean
-gtk_source_buffer_can_redo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       return gtk_source_undo_manager_can_redo (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_undo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Undoes the last user action which modified the buffer.  Use
- * gtk_source_buffer_can_undo() to check whether a call to this
- * function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::undo signal.
- */
-void
-gtk_source_buffer_undo (GtkSourceBuffer *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_signal_emit (buffer, buffer_signals[UNDO], 0);
-}
-
-/**
- * gtk_source_buffer_redo:
- * @buffer: a #GtkSourceBuffer.
- *
- * Redoes the last undo operation.  Use gtk_source_buffer_can_redo()
- * to check whether a call to this function will have any effect.
- *
- * This function emits the #GtkSourceBuffer::redo signal.
- */
-void
-gtk_source_buffer_redo (GtkSourceBuffer *buffer)
-{
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       g_signal_emit (buffer, buffer_signals[REDO], 0);
-}
-
-/**
- * gtk_source_buffer_get_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- *
- * Determines the number of undo levels the buffer will track for buffer edits.
- *
- * Returns: the maximum number of possible undo levels or -1 if no limit is set.
- */
-gint
-gtk_source_buffer_get_max_undo_levels (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), 0);
-
-       return priv->max_undo_levels;
-}
-
-/**
- * gtk_source_buffer_set_max_undo_levels:
- * @buffer: a #GtkSourceBuffer.
- * @max_undo_levels: the desired maximum number of undo levels.
- *
- * Sets the number of undo levels for user actions the buffer will
- * track.  If the number of user actions exceeds the limit set by this
- * function, older actions will be discarded.
- *
- * If @max_undo_levels is -1, the undo/redo is unlimited.
- *
- * If @max_undo_levels is 0, the undo/redo is disabled.
- */
-void
-gtk_source_buffer_set_max_undo_levels (GtkSourceBuffer *buffer,
-                                      gint             max_undo_levels)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       if (priv->max_undo_levels == max_undo_levels)
-       {
-               return;
-       }
-
-       priv->max_undo_levels = max_undo_levels;
-
-       if (GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
-       {
-               gtk_source_undo_manager_default_set_max_undo_levels (GTK_SOURCE_UNDO_MANAGER_DEFAULT 
(priv->undo_manager),
-                                                                    max_undo_levels);
-       }
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_MAX_UNDO_LEVELS]);
-}
-
-gboolean
-_gtk_source_buffer_is_undo_redo_enabled (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), FALSE);
-
-       if (priv->undo_manager == NULL)
-       {
-               return FALSE;
-       }
-
-       /* A custom UndoManager is not forced to follow max_undo_levels. */
-       if (!GTK_SOURCE_IS_UNDO_MANAGER_DEFAULT (priv->undo_manager))
-       {
-               return TRUE;
-       }
-
-       return priv->max_undo_levels != 0;
-}
-
-/**
- * gtk_source_buffer_begin_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the beginning of a not undoable action on the buffer,
- * disabling the undo manager.  Typically you would call this function
- * before initially setting the contents of the buffer (e.g. when
- * loading a file in a text editor).
- *
- * You may nest gtk_source_buffer_begin_not_undoable_action() /
- * gtk_source_buffer_end_not_undoable_action() blocks.
- */
-void
-gtk_source_buffer_begin_not_undoable_action (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       gtk_source_undo_manager_begin_not_undoable_action (priv->undo_manager);
-}
-
-/**
- * gtk_source_buffer_end_not_undoable_action:
- * @buffer: a #GtkSourceBuffer.
- *
- * Marks the end of a not undoable action on the buffer.  When the
- * last not undoable block is closed through the call to this
- * function, the list of undo actions is cleared and the undo manager
- * is re-enabled.
- */
-void
-gtk_source_buffer_end_not_undoable_action (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-
-       gtk_source_undo_manager_end_not_undoable_action (priv->undo_manager);
-}
-
 /**
  * gtk_source_buffer_get_highlight_matching_brackets:
  * @buffer: a #GtkSourceBuffer.
@@ -2111,26 +1696,6 @@ gtk_source_buffer_real_mark_deleted (GtkTextBuffer *buffer,
        }
 }
 
-static void
-gtk_source_buffer_real_undo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (gtk_source_undo_manager_can_undo (priv->undo_manager));
-
-       gtk_source_undo_manager_undo (priv->undo_manager);
-}
-
-static void
-gtk_source_buffer_real_redo (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (gtk_source_undo_manager_can_redo (priv->undo_manager));
-
-       gtk_source_undo_manager_redo (priv->undo_manager);
-}
-
 /**
  * gtk_source_buffer_create_source_mark:
  * @buffer: a #GtkSourceBuffer.
@@ -3192,62 +2757,6 @@ gtk_source_buffer_sort_lines (GtkSourceBuffer    *buffer,
        g_free (lines);
 }
 
-/**
- * gtk_source_buffer_set_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- * @manager: (nullable): A #GtkSourceUndoManager or %NULL.
- *
- * Set the buffer undo manager. If @manager is %NULL the default undo manager
- * will be set.
- */
-void
-gtk_source_buffer_set_undo_manager (GtkSourceBuffer      *buffer,
-                                    GtkSourceUndoManager *manager)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_if_fail (GTK_SOURCE_IS_BUFFER (buffer));
-       g_return_if_fail (manager == NULL || GTK_SOURCE_IS_UNDO_MANAGER (manager));
-
-       if (manager == NULL)
-       {
-               manager = g_object_new (GTK_SOURCE_TYPE_UNDO_MANAGER_DEFAULT,
-                                       "buffer", buffer,
-                                       "max-undo-levels", priv->max_undo_levels,
-                                       NULL);
-       }
-       else
-       {
-               g_object_ref (manager);
-       }
-
-       set_undo_manager (buffer, manager);
-       g_object_unref (manager);
-
-       g_object_notify_by_pspec (G_OBJECT (buffer), buffer_properties[PROP_UNDO_MANAGER]);
-}
-
-/**
- * gtk_source_buffer_get_undo_manager:
- * @buffer: a #GtkSourceBuffer.
- *
- * Returns the #GtkSourceUndoManager associated with the buffer,
- * see gtk_source_buffer_set_undo_manager().  The returned object should not be
- * unreferenced by the user.
- *
- * Returns: (nullable) (transfer none): the #GtkSourceUndoManager associated
- * with the buffer, or %NULL.
- */
-GtkSourceUndoManager *
-gtk_source_buffer_get_undo_manager (GtkSourceBuffer *buffer)
-{
-       GtkSourceBufferPrivate *priv = gtk_source_buffer_get_instance_private (buffer);
-
-       g_return_val_if_fail (GTK_SOURCE_IS_BUFFER (buffer), NULL);
-
-       return priv->undo_manager;
-}
-
 void
 _gtk_source_buffer_add_search_context (GtkSourceBuffer        *buffer,
                                       GtkSourceSearchContext *search_context)
diff --git a/gtksourceview/gtksourcebuffer.h b/gtksourceview/gtksourcebuffer.h
index 382955f6..9e26505a 100644
--- a/gtksourceview/gtksourcebuffer.h
+++ b/gtksourceview/gtksourcebuffer.h
@@ -94,9 +94,6 @@ struct _GtkSourceBufferClass
        GtkTextBufferClass parent_class;
 
        /* Signals */
-       void (*undo)            (GtkSourceBuffer *buffer);
-       void (*redo)            (GtkSourceBuffer *buffer);
-
        void (*bracket_matched) (GtkSourceBuffer           *buffer,
                                 GtkTextIter               *iter,
                                 GtkSourceBracketMatchType  state);
@@ -120,20 +117,11 @@ GTK_SOURCE_AVAILABLE_IN_ALL
 void                   gtk_source_buffer_set_highlight_matching_brackets       (GtkSourceBuffer         
*buffer,
                                                                                 gboolean                 
highlight);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gint                   gtk_source_buffer_get_max_undo_levels                   (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_max_undo_levels                   (GtkSourceBuffer         
*buffer,
-                                                                                gint                     
max_undo_levels);
-GTK_SOURCE_AVAILABLE_IN_ALL
 GtkSourceLanguage     *gtk_source_buffer_get_language                          (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
 void                   gtk_source_buffer_set_language                          (GtkSourceBuffer         
*buffer,
                                                                                 GtkSourceLanguage       
*language);
 GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_can_undo                              (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-gboolean               gtk_source_buffer_can_redo                              (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
 GtkSourceStyleScheme  *gtk_source_buffer_get_style_scheme                      (GtkSourceBuffer         
*buffer);
 GTK_SOURCE_AVAILABLE_IN_ALL
 void                   gtk_source_buffer_set_style_scheme                      (GtkSourceBuffer         
*buffer,
@@ -143,14 +131,6 @@ void                   gtk_source_buffer_ensure_highlight                      (
                                                                                 const GtkTextIter       
*start,
                                                                                 const GtkTextIter       
*end);
 GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_undo                                  (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_redo                                  (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_begin_not_undoable_action             (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_end_not_undoable_action               (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
 GtkSourceMark         *gtk_source_buffer_create_source_mark                    (GtkSourceBuffer         
*buffer,
                                                                                 const gchar             
*name,
                                                                                 const gchar             
*category,
@@ -206,11 +186,6 @@ void                   gtk_source_buffer_sort_lines                            (
                                                                                 GtkTextIter             *end,
                                                                                 GtkSourceSortFlags       
flags,
                                                                                 gint                     
column);
-GTK_SOURCE_AVAILABLE_IN_ALL
-GtkSourceUndoManager  *gtk_source_buffer_get_undo_manager                      (GtkSourceBuffer         
*buffer);
-GTK_SOURCE_AVAILABLE_IN_ALL
-void                   gtk_source_buffer_set_undo_manager                      (GtkSourceBuffer         
*buffer,
-                                                                                GtkSourceUndoManager    
*manager);
 GTK_SOURCE_AVAILABLE_IN_3_14
 void                   gtk_source_buffer_set_implicit_trailing_newline         (GtkSourceBuffer         
*buffer,
                                                                                 gboolean                 
implicit_trailing_newline);
diff --git a/gtksourceview/gtksourcebufferoutputstream.c b/gtksourceview/gtksourcebufferoutputstream.c
index ab41c2b5..55cac2de 100644
--- a/gtksourceview/gtksourcebufferoutputstream.c
+++ b/gtksourceview/gtksourcebufferoutputstream.c
@@ -192,12 +192,12 @@ gtk_source_buffer_output_stream_constructed (GObject *object)
                return;
        }
 
-       gtk_source_buffer_begin_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
 
        gtk_text_buffer_set_text (GTK_TEXT_BUFFER (stream->source_buffer), "", 0);
        gtk_text_buffer_set_modified (GTK_TEXT_BUFFER (stream->source_buffer), FALSE);
 
-       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
 
        G_OBJECT_CLASS (gtk_source_buffer_output_stream_parent_class)->constructed (object);
 }
@@ -765,7 +765,7 @@ end_append_text_to_document (GtkSourceBufferOutputStream *stream)
                                      FALSE);
 
        gtk_text_buffer_end_user_action (GTK_TEXT_BUFFER (stream->source_buffer));
-       gtk_source_buffer_end_not_undoable_action (stream->source_buffer);
+       gtk_text_buffer_end_irreversible_action (GTK_TEXT_BUFFER (stream->source_buffer));
 }
 
 static gboolean
@@ -947,7 +947,7 @@ gtk_source_buffer_output_stream_write (GOutputStream  *stream,
                 * as only one action, for the features that rely on the user
                 * action.
                 */
-               gtk_source_buffer_begin_not_undoable_action (ostream->source_buffer);
+               gtk_text_buffer_begin_irreversible_action (GTK_TEXT_BUFFER (ostream->source_buffer));
                gtk_text_buffer_begin_user_action (GTK_TEXT_BUFFER (ostream->source_buffer));
 
                gtk_text_buffer_get_start_iter (GTK_TEXT_BUFFER (ostream->source_buffer),
diff --git a/gtksourceview/gtksourcetypes-private.h b/gtksourceview/gtksourcetypes-private.h
index 002a144d..7748aadf 100644
--- a/gtksourceview/gtksourcetypes-private.h
+++ b/gtksourceview/gtksourcetypes-private.h
@@ -34,7 +34,6 @@ typedef struct _GtkSourceGutterRendererMarks    GtkSourceGutterRendererMarks;
 typedef struct _GtkSourceMarksSequence          GtkSourceMarksSequence;
 typedef struct _GtkSourcePixbufHelper           GtkSourcePixbufHelper;
 typedef struct _GtkSourceRegex                  GtkSourceRegex;
-typedef struct _GtkSourceUndoManagerDefault     GtkSourceUndoManagerDefault;
 
 #ifdef _MSC_VER
 /* For Visual Studio, we need to export the symbols used by the unit tests */
diff --git a/gtksourceview/gtksourcetypes.h b/gtksourceview/gtksourcetypes.h
index ae358abc..d6632d59 100644
--- a/gtksourceview/gtksourcetypes.h
+++ b/gtksourceview/gtksourcetypes.h
@@ -65,7 +65,6 @@ typedef struct _GtkSourceStyleSchemeChooser        GtkSourceStyleSchemeChooser;
 typedef struct _GtkSourceStyleSchemeChooserWidget  GtkSourceStyleSchemeChooserWidget;
 typedef struct _GtkSourceStyleScheme               GtkSourceStyleScheme;
 typedef struct _GtkSourceStyleSchemeManager        GtkSourceStyleSchemeManager;
-typedef struct _GtkSourceUndoManager               GtkSourceUndoManager;
 typedef struct _GtkSourceView                      GtkSourceView;
 
 G_END_DECLS
diff --git a/gtksourceview/gtksourceview.c b/gtksourceview/gtksourceview.c
index f968e966..f2afb14a 100644
--- a/gtksourceview/gtksourceview.c
+++ b/gtksourceview/gtksourceview.c
@@ -150,8 +150,6 @@
 
 enum
 {
-       UNDO,
-       REDO,
        SHOW_COMPLETION,
        LINE_MARK_ACTIVATED,
        MOVE_LINES,
@@ -253,8 +251,6 @@ static const GtkTargetEntry drop_types[] = {
 
 static void           gtk_source_view_dispose              (GObject                 *object);
 static void           gtk_source_view_finalize             (GObject                 *object);
-static void           gtk_source_view_undo                 (GtkSourceView           *view);
-static void           gtk_source_view_redo                 (GtkSourceView           *view);
 static void           gtk_source_view_show_completion_real (GtkSourceView           *view);
 static GtkTextBuffer *gtk_source_view_create_buffer        (GtkTextView             *view);
 static void           remove_source_buffer                 (GtkSourceView           *view);
@@ -489,8 +485,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
        textview_class->create_buffer = gtk_source_view_create_buffer;
        textview_class->draw_layer = gtk_source_view_draw_layer;
 
-       klass->undo = gtk_source_view_undo;
-       klass->redo = gtk_source_view_redo;
        klass->show_completion = gtk_source_view_show_completion_real;
        klass->move_lines = gtk_source_view_move_lines;
        klass->move_words = gtk_source_view_move_words;
@@ -702,30 +696,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
                                                              G_PARAM_READABLE |
                                                              G_PARAM_STATIC_STRINGS));
 
-       signals[UNDO] =
-               g_signal_new ("undo",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GtkSourceViewClass, undo),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (signals[UNDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
-       signals[REDO] =
-               g_signal_new ("redo",
-                             G_TYPE_FROM_CLASS (klass),
-                             G_SIGNAL_RUN_LAST | G_SIGNAL_ACTION,
-                             G_STRUCT_OFFSET (GtkSourceViewClass, redo),
-                             NULL, NULL,
-                             g_cclosure_marshal_VOID__VOID,
-                             G_TYPE_NONE, 0);
-       g_signal_set_va_marshaller (signals[REDO],
-                                   G_TYPE_FROM_CLASS (klass),
-                                   g_cclosure_marshal_VOID__VOIDv);
-
        /**
         * GtkSourceView::show-completion:
         * @view: The #GtkSourceView who emits the signal
@@ -948,18 +918,6 @@ gtk_source_view_class_init (GtkSourceViewClass *klass)
 
        binding_set = gtk_binding_set_by_class (klass);
 
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_z,
-                                     GDK_CONTROL_MASK,
-                                     "undo", 0);
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_z,
-                                     GDK_CONTROL_MASK | GDK_SHIFT_MASK,
-                                     "redo", 0);
-       gtk_binding_entry_add_signal (binding_set,
-                                     GDK_KEY_F14,
-                                     0,
-                                     "undo", 0);
        gtk_binding_entry_add_signal (binding_set,
                                      GDK_KEY_space,
                                      GDK_CONTROL_MASK,
@@ -1682,42 +1640,7 @@ scroll_to_insert (GtkSourceView *view,
 
                gtk_adjustment_set_value (adjustment, position);
        }
-}
 
-static void
-gtk_source_view_undo (GtkSourceView *view)
-{
-       GtkTextBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
-           GTK_SOURCE_IS_BUFFER (buffer) &&
-           gtk_source_buffer_can_undo (GTK_SOURCE_BUFFER (buffer)))
-       {
-               gtk_source_buffer_undo (GTK_SOURCE_BUFFER (buffer));
-               scroll_to_insert (view, buffer);
-       }
-}
-
-static void
-gtk_source_view_redo (GtkSourceView *view)
-{
-       GtkTextBuffer *buffer;
-
-       g_return_if_fail (GTK_SOURCE_IS_VIEW (view));
-
-       buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view));
-
-       if (gtk_text_view_get_editable (GTK_TEXT_VIEW (view)) &&
-           GTK_SOURCE_IS_BUFFER (buffer) &&
-           gtk_source_buffer_can_redo (GTK_SOURCE_BUFFER (buffer)))
-       {
-               gtk_source_buffer_redo (GTK_SOURCE_BUFFER (buffer));
-               scroll_to_insert (view, buffer);
-       }
 }
 
 static void
diff --git a/gtksourceview/gtksourceview.h b/gtksourceview/gtksourceview.h
index 40ef7e96..ab3efff1 100644
--- a/gtksourceview/gtksourceview.h
+++ b/gtksourceview/gtksourceview.h
@@ -87,8 +87,6 @@ struct _GtkSourceViewClass
 {
        GtkTextViewClass parent_class;
 
-       void (*undo)                (GtkSourceView *view);
-       void (*redo)                (GtkSourceView *view);
        void (*line_mark_activated) (GtkSourceView *view,
                                     GtkTextIter   *iter,
                                     GdkEvent      *event);
diff --git a/gtksourceview/meson.build b/gtksourceview/meson.build
index 58cf72c6..c5638515 100644
--- a/gtksourceview/meson.build
+++ b/gtksourceview/meson.build
@@ -41,7 +41,6 @@ core_public_h = files([
   'gtksourcestyleschememanager.h',
   'gtksourcetag.h',
   'gtksourcetypes.h',
-  'gtksourceundomanager.h',
   'gtksourceutils.h',
   'gtksourceview.h',
 ])
@@ -80,7 +79,6 @@ core_public_c = files([
   'gtksourcestyleschemechooserwidget.c',
   'gtksourcestyleschememanager.c',
   'gtksourcetag.c',
-  'gtksourceundomanager.c',
   'gtksourceutils.c',
   'gtksourceversion.c',
   'gtksourceview.c',
@@ -101,7 +99,6 @@ core_private_c = files([
   'gtksourcemarkssequence.c',
   'gtksourcepixbufhelper.c',
   'gtksourceregex.c',
-  'gtksourceundomanagerdefault.c',
 ])
 
 core_c_args = [
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 5fe44fe0..a1f7b9bf 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -39,6 +39,5 @@ gtksourceview/gtksourcestylescheme.c
 gtksourceview/gtksourcestyleschemechooserbutton.c
 gtksourceview/gtksourcestyleschememanager.c
 gtksourceview/gtksourcetag.c
-gtksourceview/gtksourceundomanagerdefault.c
 gtksourceview/gtksourceutils.c
 gtksourceview/gtksourceview.c
diff --git a/tests/meson.build b/tests/meson.build
index eb078ee8..a33e8228 100644
--- a/tests/meson.build
+++ b/tests/meson.build
@@ -9,7 +9,6 @@ tests_sources = {
                      'search': ['test-search.c'],
         'search-performances': ['test-search-performances.c'],
               'space-drawing': ['test-space-drawing.c'],
-  'undo-manager-performances': ['test-undo-manager-performances.c'],
                      'widget': ['test-widget.c'],
 }
 
diff --git a/testsuite/meson.build b/testsuite/meson.build
index 08d0a7e5..0715e340 100644
--- a/testsuite/meson.build
+++ b/testsuite/meson.build
@@ -34,7 +34,6 @@ testsuite_sources = [
   ['test-space-drawer'],
   ['test-stylescheme'],
   ['test-styleschememanager'],
-  ['test-undo-manager'],
   ['test-utils'],
   ['test-view'],
 ]



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