Example #1
0
 public BasicUndoHistoryTest()
 {
     _context             = new object();
     _basicUndoHistoryRaw = new BasicUndoHistory(_context);
     _basicUndoHistory    = _basicUndoHistoryRaw;
     _factory             = new MockRepository(MockBehavior.Loose);
 }
 ITextUndoHistory ITextUndoHistoryRegistry.RegisterHistory(object context)
 {
     IBasicUndoHistory history;
     if (!_map.TryGetValue(context, out history))
     {
         history = new BasicUndoHistory(context);
         _map.Add(context, history);
     }
     return history;
 }
 internal BasicUndoTransaction(BasicUndoHistory textUndoHistory, string description)
 {
     _textUndoHistory = textUndoHistory;
     Description = description;
 }
Example #4
0
 internal BasicUndoTransaction(BasicUndoHistory textUndoHistory, string description)
 {
     _textUndoHistory = textUndoHistory;
     Description      = description;
 }
Example #5
0
        ///<summary>Gets all contexts (eg, source buffers for a projection buffer) that a context includes (including the original context).</summary>
        static IEnumerable <object> GetDependentContexts(object context)
        {
            var projectionBuffer = context as IProjectionBufferBase;

            if (projectionBuffer == null)
            {
                return new[] { context }
            }
            ;
            return(new[] { context }
                   .Concat(projectionBuffer.SourceBuffers.SelectMany(GetDependentContexts)));
        }

        #region ITextUndoHistoryRegistry

        /// <summary>
        /// Easy to implement but the Visual Studio implementation throws a NotSupportedException
        /// </summary>
        void ITextUndoHistoryRegistry.AttachHistory(object context, ITextUndoHistory history)
        {
            throw new NotSupportedException();
        }

        ITextUndoHistory ITextUndoHistoryRegistry.GetHistory(object context)
        {
            ITextUndoHistory history;

            _map.TryGetValue(context, out history);
            return(history);
        }

        ITextUndoHistory ITextUndoHistoryRegistry.RegisterHistory(object context)
        {
            ITextUndoHistory history;

            if (!_map.TryGetValue(context, out history))
            {
                history = new BasicUndoHistory(context);

                foreach (var c in GetDependentContexts(context))
                {
                    // If this context already has an attached history, don't replace it.
                    // This happens for ephemeral projection buffers for previews created
                    // by the diff for a quick fix.
                    _map.GetValue(c, _ => history);
                }
            }
            return(history);
        }

        void ITextUndoHistoryRegistry.RemoveHistory(ITextUndoHistory history)
        {
            var basicUndoHistory = history as BasicUndoHistory;

            if (basicUndoHistory != null)
            {
                foreach (var c in GetDependentContexts(basicUndoHistory.Context))
                {
                    _map.Remove(c);
                }
                basicUndoHistory.Clear();
            }
        }

        bool ITextUndoHistoryRegistry.TryGetHistory(object context, out ITextUndoHistory history)
        {
            ITextUndoHistory basicUndoHistory;

            if (TryGetHistory(context, out basicUndoHistory))
            {
                history = basicUndoHistory;
                return(true);
            }

            history = null;
            return(false);
        }

        #endregion
    }
 public BasicUndoHistoryTest()
 {
     _context             = new object();
     _basicUndoHistoryRaw = new BasicUndoHistory(_context);
     _basicUndoHistory    = _basicUndoHistoryRaw;
 }