Example #1
0
        protected void ApplyReplacementText(ITextBuffer subjectBuffer, ITextUndoHistory undoHistory, object propagateSpansEditTag, IEnumerable <ITrackingSpan> spans, string replacementText)
        {
            // roll back to the initial state for the buffer after conflict resolution
            this.UndoTemporaryEdits(subjectBuffer, disconnect: false, undoConflictResolution: replacementText == string.Empty);

            using var transaction = undoHistory.CreateTransaction(GetUndoTransactionDescription(replacementText));
            using var edit        = subjectBuffer.CreateEdit(EditOptions.None, null, propagateSpansEditTag);

            foreach (var span in spans)
            {
                if (span.GetText(subjectBuffer.CurrentSnapshot) != replacementText)
                {
                    edit.Replace(span.GetSpan(subjectBuffer.CurrentSnapshot), replacementText);
                }
            }

            edit.ApplyAndLogExceptions();
            if (!edit.HasEffectiveChanges && !this.UndoStack.Any())
            {
                transaction.Cancel();
            }
            else
            {
                transaction.Complete();
            }
        }
            public bool TryGetTextUndoHistory(Workspace editorWorkspace, ITextBuffer textBuffer, out ITextUndoHistory undoHistory)
            {
                undoHistory = null;

                if (!(editorWorkspace is VisualStudioWorkspaceImpl) &&
                    !(editorWorkspace is MiscellaneousFilesWorkspace))
                {
                    return false;
                }

                // TODO: Handle undo if context changes
                var documentId = editorWorkspace.GetDocumentIdInCurrentContext(textBuffer.AsTextContainer());
                if (documentId == null)
                {
                    return false;
                }

                var document = GetDocument(editorWorkspace, documentId);
                if (document == null)
                {
                    return false;
                }

                undoHistory = document.GetTextUndoHistory();
                return true;
            }
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description) {
            if (history == null) {
                throw new ArgumentNullException(nameof(history));
            }

            if (string.IsNullOrEmpty(description)) {
                throw new ArgumentNullException(nameof(description));
            }

            _history = history as UndoHistoryImpl;

            if (_history == null) {
                throw new ArgumentException("Invalid history in registry");
            }

            _parent = parent as UndoTransactionImpl;

            if (_parent == null && parent != null) {
                throw new ArgumentException("Invalid parent in transaction");
            }

            Description = description;

            _state = UndoTransactionState.Open;
            _primitives = new List<ITextUndoPrimitive>();
            _mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly = true;
        }
Example #4
0
        public InformationBarMargin(IWpfTextView textView, ITextDocument document, IEditorOperations editorOperations, ITextUndoHistory undoHistory, DTE dte)
        {
            _textView = textView;
            _document = document;
            _operations = editorOperations;
            _undoHistory = undoHistory;
            _dte = dte;

            _informationBarControl = new InformationBarControl();
            _informationBarControl.Hide.Click += Hide;
            _informationBarControl.DontShowAgain.Click += DontShowAgain;
            var format = new Action(() => this.FormatDocument());
            _informationBarControl.Tabify.Click += (s, e) => this.Dispatcher.Invoke(format);

            this.Height = 0;
            this.Content = _informationBarControl;
            this.Name = MarginName;

            document.FileActionOccurred += FileActionOccurred;
            textView.Closed += TextViewClosed;

            // Delay the initial check until the view gets focus
            textView.GotAggregateFocus += GotAggregateFocus;

            this._tabDirectiveParser = new TabDirectiveParser(textView, document, dte);
            this._fileHeuristics = new FileHeuristics(textView, document, dte);

            var fix = new Action(() => this.FixFile());
            this._tabDirectiveParser.Change += (s, e) => this.Dispatcher.Invoke(fix);
        }
        /// <summary>
        /// Constructs a TextBufferChangeUndoPrimitive.
        /// </summary>
        /// <param name="undoHistory">
        /// The ITextUndoHistory this change will be added to.
        /// </param>
        /// <param name="textVersion">
        /// The <see cref="ITextVersion" /> representing this change.
        /// This is actually the version associated with the snapshot prior to the change.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="undoHistory"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="textVersion"/> is null.</exception>
        public TextBufferChangeUndoPrimitive(ITextUndoHistory undoHistory, ITextVersion textVersion)
        {
            // Verify input parameters
            if (undoHistory == null)
            {
                throw new ArgumentNullException("undoHistory");
            }

            if (textVersion == null)
            {
                throw new ArgumentNullException("textVersion");
            }

            _textChanges   = textVersion.Changes;
            _beforeVersion = textVersion.ReiteratedVersionNumber;
            _afterVersion  = textVersion.Next.VersionNumber;
            Debug.Assert(textVersion.Next.VersionNumber == textVersion.Next.ReiteratedVersionNumber,
                         "Creating a TextBufferChangeUndoPrimitive for a change that has previously been undone?  This is probably wrong.");

            _undoHistory        = undoHistory;
            TextBuffer          = textVersion.TextBuffer;
            AttachedToNewBuffer = false;

            _canUndo = true;

#if DEBUG
            // for debug sanity checks
            _bufferLengthAfterChange = textVersion.Next.Length;
#endif
        }
Example #6
0
        public void VsTextViewCreated(IVsTextView textViewAdapter)
        {
            IWpfTextView      textView         = editorAdaptersFactoryService.GetWpfTextView(textViewAdapter);
            ITextUndoHistory  undoHistory      = undoHistoryRegistry.RegisterHistory(textView.TextBuffer);
            IEditorOperations editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            IEditorOptions    editorOptions    = editorOptionsFactoryService.GetOptions(textView);
            IViewPrimitives   viewPrimitives   = editorPrimitivesFactoryService.GetViewPrimitives(textView);

            if (_telemetrySession == null)
            {
                _telemetrySession = TelemetrySessionForPPT.Create(this.GetType().Assembly);
            }

            // Object will survive since it adds itself to the view's command filter chain
            new CommandFilter(
                textViewAdapter,
                textView,
                htmlBuilderService,
                rtfBuilderService,
                editorOperations,
                undoHistory,
                editorOptions,
                viewPrimitives,
                _telemetrySession);
        }
Example #7
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException(nameof(description));
            }

            _history = history as UndoHistoryImpl;

            if (_history == null)
            {
                throw new ArgumentException("Invalid history in registry");
            }

            _parent = parent as UndoTransactionImpl;

            if (_parent == null && parent != null)
            {
                throw new ArgumentException("Invalid parent in transaction");
            }

            Description = description;

            _state       = UndoTransactionState.Open;
            _primitives  = new List <ITextUndoPrimitive>();
            _mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly   = true;
        }
 public StandardKeyProcessor(IWpfTextView textView, IEditorOperations editorOperations, ITextUndoHistory undoHistory)
 {
     this.textView         = textView;
     this.editorOperations = editorOperations;
     this.undoHistory      = undoHistory;
     AddShortcuts();
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        /// <param name="keepAlive"></param>
        public void AttachHistory(object context, ITextUndoHistory history, bool keepAlive)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", String.Format(CultureInfo.CurrentCulture, "Strings.ArgumentCannotBeNull", "AttachHistory", "context"));
            }

            if (history == null)
            {
                throw new ArgumentNullException("context", String.Format(CultureInfo.CurrentCulture, "Strings.ArgumentCannotBeNull", "AttachHistory", "history"));
            }

            if (strongContextMapping.ContainsKey(context) || weakContextMapping.ContainsKey(new WeakReferenceForDictionaryKey(context)))
            {
                throw new InvalidOperationException("Strings.AttachHistoryAlreadyContainsContextInRegistry");
            }

            if (!histories.ContainsKey(history))
            {
                histories.Add(history, 1);
            }
            else
            {
                ++histories[history];
            }

            if (keepAlive)
            {
                strongContextMapping.Add(context, history);
            }
            else
            {
                weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), history);
            }
        }
Example #10
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            if (history == null)
            {
                throw new ArgumentNullException("history", String.Format(CultureInfo.CurrentUICulture, "Strings.ArgumentCannotBeNull", "UndoTransactionImpl", "history"));
            }

            if (String.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException("description", String.Format(CultureInfo.CurrentUICulture, "Strings.ArgumentCannotBeNull", "UndoTransactionImpl", "description"));
            }

            this.history = history as UndoHistoryImpl;

            if (this.history == null)
            {
                throw new ArgumentException("Strings.InvalidHistoryInTransaction");
            }

            this.parent = parent as UndoTransactionImpl;

            if (this.parent == null && parent != null)
            {
                throw new ArgumentException("Strings.InvalidParentInTransaction");
            }

            this.description = description;

            this.state       = UndoTransactionState.Open;
            this.primitives  = new List <ITextUndoPrimitive>();
            this.mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            this.IsReadOnly  = true;
        }
Example #11
0
        public UndoTransactionImpl(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            if (string.IsNullOrEmpty(description))
            {
                throw new ArgumentNullException(nameof(description));
            }

            this.history = history as UndoHistoryImpl;

            if (this.history == null)
            {
                throw new ArgumentException("Strings.InvalidHistoryInTransaction");
            }

            this.parent = parent as UndoTransactionImpl;

            if (this.parent == null && parent != null)
            {
                throw new ArgumentException("Strings.InvalidParentInTransaction");
            }

            this.description = description;

            this.state       = UndoTransactionState.Open;
            this.primitives  = new List <ITextUndoPrimitive>();
            this.mergePolicy = NullMergeUndoTransactionPolicy.Instance;
            this.IsReadOnly  = true;
        }
Example #12
0
 protected AfterTextBufferChangeUndoPrimitive(ITextUndoHistory undoHistory, int caretIndex, PositionAffinity caretAffinity)
 {
     _undoHistory          = undoHistory;
     _newCaretIndex        = caretIndex;
     _newCaretAffinityByte = (byte)caretAffinity;
     _canUndo = true;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        /// <param name="keepAlive"></param>
        public void AttachHistory(object context, ITextUndoHistory history, bool keepAlive)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            if (_strongContextMapping.ContainsKey(context) || _weakContextMapping.ContainsKey(new KeyWeakReference(context)))
            {
                throw new InvalidOperationException("Attached history already containst context");
            }

            if (!_histories.ContainsKey(history))
            {
                _histories.Add(history, 1);
            }
            else
            {
                ++_histories[history];
            }

            if (keepAlive)
            {
                _strongContextMapping.Add(context, history);
            }
            else
            {
                _weakContextMapping.Add(new KeyWeakReference(context), history);
            }
        }
Example #14
0
        public InformationBarMargin(IWpfTextView textView, ITextDocument document, IEditorOperations editorOperations, ITextUndoHistory undoHistory)
        {
            _textView    = textView;
            _document    = document;
            _operations  = editorOperations;
            _undoHistory = undoHistory;

            _telemetrySession = TelemetrySessionForPPT.Create(this.GetType().Assembly);

            var informationBar = new InformationBarControl();

            informationBar.Tabify.Click        += Tabify;
            informationBar.Untabify.Click      += Untabify;
            informationBar.Hide.Click          += Hide;
            informationBar.DontShowAgain.Click += DontShowAgain;

            this.Height  = 0;
            this.Content = informationBar;
            this.Name    = MarginName;

            document.FileActionOccurred += FileActionOccurred;

            // Delay the initial check until the view gets focus.
            textView.GotAggregateFocus += GotAggregateFocus;
        }
 void ITextUndoHistoryRegistry.RemoveHistory(ITextUndoHistory history)
 {
     if (history is BasicUndoHistory basicUndoHistory)
     {
         _map.Remove(basicUndoHistory.Context);
         basicUndoHistory.Clear();
     }
 }
		public bool TryGetHistory(object context, out ITextUndoHistory history) {
			if (context == null)
				throw new ArgumentNullException(nameof(context));
			var propertyOwner = context as IPropertyOwner;
			if (propertyOwner == null)
				throw new ArgumentException();
			return propertyOwner.Properties.TryGetProperty(textUndoHistoryKey, out history);
		}
Example #17
0
            private void Create(params string[] lines)
            {
                _textBuffer = CreateTextBuffer(lines);
                var undoManagerProvider = TextBufferUndoManagerProvider;
                var undoManager         = undoManagerProvider.GetTextBufferUndoManager(_textBuffer);

                _undoHistory = undoManager.TextBufferUndoHistory;
            }
		public void RemoveHistory(ITextUndoHistory history) {
			if (history == null)
				throw new ArgumentException();
			var historyImpl = history as TextUndoHistory;
			if (historyImpl == null)
				throw new ArgumentException();
			historyImpl.PropertyOwner.Properties.RemoveProperty(textUndoHistoryKey);
			historyImpl.Dispose();
		}
 void ITextUndoHistoryRegistry.RemoveHistory(ITextUndoHistory history)
 {
     var basicUndoHistory = history as BasicUndoHistory;
     if (basicUndoHistory != null)
     {
         _map.Remove(basicUndoHistory.Context);
         basicUndoHistory.Clear();
     }
 }
Example #20
0
 public TextBufferUndoManager(ITextBuffer textBuffer, ITextUndoHistoryRegistry textUndoHistoryRegistry)
 {
     changes    = new List <ChangeInfo>();
     TextBuffer = textBuffer ?? throw new ArgumentNullException(nameof(textBuffer));
     this.textUndoHistoryRegistry = textUndoHistoryRegistry ?? throw new ArgumentNullException(nameof(textUndoHistoryRegistry));
     textBufferUndoHistory        = textUndoHistoryRegistry.RegisterHistory(TextBuffer);
     TextBuffer.Changed          += TextBuffer_Changed;
     TextBuffer.PostChanged      += TextBuffer_PostChanged;
 }
Example #21
0
 public void UnregisterUndoHistory()
 {
     // Unregister the undo history
     if (_undoHistory != null)
     {
         _undoHistoryRegistry.RemoveHistory(_undoHistory);
         _undoHistory = null;
     }
 }
Example #22
0
		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();
			}
		}
            internal bool Begin(ITextUndoHistory undoHistory)
            {
                if (undoHistory != null)
                {
                    _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(undoHistory.CreateTransaction(Description));
                    return(true);
                }

                return(false);
            }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        /// <returns></returns>
        public bool TryGetHistory(object context, out ITextUndoHistory history)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            return(_strongContextMapping.TryGetValue(context, out history) ||
                   _weakContextMapping.TryGetValue(new KeyWeakReference(context), out history));
        }
Example #25
0
        void ITextUndoHistoryRegistry.RemoveHistory(ITextUndoHistory history)
        {
            var undoHistory = history as UndoHistory;

            if (undoHistory != null)
            {
                _map.Remove(undoHistory.Context);
                undoHistory.Clear();
            }
        }
Example #26
0
		bool ITextUndoHistoryRegistry.TryGetHistory(object context, out ITextUndoHistory history) {
			ITextUndoHistory basicUndoHistory;
			if (TryGetHistory(context, out basicUndoHistory)) {
				history = basicUndoHistory;
				return true;
			}

			history = null;
			return false;
		}
        void ITextUndoHistoryRegistry.RemoveHistory(ITextUndoHistory history)
        {
            var basicUndoHistory = history as BasicUndoHistory;

            if (basicUndoHistory != null)
            {
                _map.Remove(basicUndoHistory.Context);
                basicUndoHistory.Clear();
            }
        }
            internal bool Begin(ITextUndoHistory undoHistory)
            {
                if (undoHistory != null)
                {
                    _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(undoHistory.CreateTransaction(Description));
                    return true;
                }

                return false;
            }
        bool ITextUndoHistoryRegistry.TryGetHistory(object context, out ITextUndoHistory history)
        {
            if (TryGetHistory(context, out IBasicUndoHistory basicUndoHistory))
            {
                history = basicUndoHistory;
                return(true);
            }

            history = null;
            return(false);
        }
Example #30
0
        public MockTextUndoTransaction(ITextUndoHistory history, ITextUndoTransaction parent, string description)
        {
            _history = history as MockTextUndoHistory;
            _parent = parent as MockTextUndoTransaction;

            Description = description;

            _state = UndoTransactionState.Open;
            _primitives = new List<ITextUndoPrimitive>();
            MergePolicy = NullMergeUndoTransactionPolicy.Instance;
            IsReadOnly = true;
        }
Example #31
0
        public VisualRustAutoindent(
            IVsTextView textViewAdapter,
            IWpfTextView textView,
            IEditorOperations operations,
            ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _operations = operations;
            _undoHistory = undoHistory;

            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
        }
		public TextBufferUndoManager(ITextBuffer textBuffer, ITextUndoHistoryRegistry textUndoHistoryRegistry) {
			if (textBuffer == null)
				throw new ArgumentNullException(nameof(textBuffer));
			if (textUndoHistoryRegistry == null)
				throw new ArgumentNullException(nameof(textUndoHistoryRegistry));
			changes = new List<ChangeInfo>();
			TextBuffer = textBuffer;
			this.textUndoHistoryRegistry = textUndoHistoryRegistry;
			textBufferUndoHistory = textUndoHistoryRegistry.RegisterHistory(TextBuffer);
			TextBuffer.Changed += TextBuffer_Changed;
			TextBuffer.PostChanged += TextBuffer_PostChanged;
		}
            public bool TryGetTextUndoHistory(Workspace editorWorkspace, ITextBuffer textBuffer, out ITextUndoHistory undoHistory)
            {
                undoHistory = null;

                var interactiveWorkspace = editorWorkspace as InteractiveWorkspace;
                if (interactiveWorkspace == null)
                {
                    return false;
                }

                return _textUndoHistoryRegistry.TryGetHistory(textBuffer, out undoHistory);
            }
Example #34
0
        public VisualRustAutoindent(
            IVsTextView textViewAdapter,
            IWpfTextView textView,
            IEditorOperations operations,
            ITextUndoHistory undoHistory)
        {
            _textView    = textView;
            _operations  = operations;
            _undoHistory = undoHistory;

            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);
        }
Example #35
0
        bool ITextUndoHistoryRegistry.TryGetHistory(object context, out ITextUndoHistory history)
        {
            ITextUndoHistory undoHistory;

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

            history = null;
            return(false);
        }
            public bool TryGetTextUndoHistory(Workspace editorWorkspace, ITextBuffer textBuffer, out ITextUndoHistory undoHistory)
            {
                undoHistory = null;

                var interactiveWorkspace = editorWorkspace as InteractiveWorkspace;
                if (interactiveWorkspace == null)
                {
                    return false;
                }

                var textView = interactiveWorkspace.Engine.CurrentWindow.TextView;
                return _textUndoHistoryRegistry.TryGetHistory(textBuffer, out undoHistory);
            }
Example #37
0
        private void EnsureTextBufferUndoHistory()
        {
            if (_textBuffer == null)
            {
                throw new ObjectDisposedException("TextBufferUndoManager");
            }

            // Note, right now, there is no way for us to know if an ITextUndoHistory
            // has been unregistered (ie it can be unregistered by a third party)
            // An issue has been logged with the Undo team, but in the mean time, to ensure that
            // we are robust, always register the undo history.
            _undoHistory = _undoHistoryRegistry.RegisterHistory(_textBuffer);
        }
        /// <summary>
        /// Constructs a BeforeTextBufferChangeUndoPrimitive.
        /// </summary>
        /// <param name="textView">
        /// The text view that was responsible for causing this change.
        /// </param>
        /// <param name="undoHistory">
        /// The <see cref="ITextUndoHistory" /> this primitive will be added to.
        /// </param>
        /// <exception cref="ArgumentNullException"><paramref name="textView"/> is null.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="undoHistory"/> is null.</exception>
        public static BeforeTextBufferChangeUndoPrimitive Create(ITextView textView, ITextUndoHistory undoHistory)
        {
            if (textView == null)
            {
                throw new ArgumentNullException(nameof(textView));
            }
            if (undoHistory == null)
            {
                throw new ArgumentNullException(nameof(undoHistory));
            }

            return(new BeforeTextBufferChangeUndoPrimitive(textView, undoHistory));
        }
		public void AttachHistory(object context, ITextUndoHistory history) {
			if (context == null)
				throw new ArgumentNullException(nameof(context));
			if (history == null)
				throw new ArgumentNullException(nameof(history));
			var propertyOwner = context as IPropertyOwner;
			if (propertyOwner == null)
				throw new ArgumentException();
			if (!(history is TextUndoHistory))
				throw new ArgumentException();
			// VS also doesn't support it
			throw new NotSupportedException();
		}
            public IWorkspaceGlobalUndoTransaction OpenGlobalUndoTransaction(Workspace workspace, string description)
            {
                if (!CanUndo(workspace))
                {
                    throw new ArgumentException(EditorFeaturesResources.Given_Workspace_doesn_t_support_Undo);
                }

                ITextUndoHistory textUndoHistory = GetHistory(workspace);

                var transaction = textUndoHistory.CreateTransaction(description);

                return(new InteractiveGlobalUndoTransaction(transaction));
            }
Example #41
0
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IEditorBraceCompletionSession session)
 {
     this.TextView      = textView;
     this.SubjectBuffer = subjectBuffer;
     this.OpeningBrace  = openingBrace;
     this.ClosingBrace  = closingBrace;
     this.ClosingPoint  = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory       = undoHistory;
     _editorOperations  = editorOperationsFactoryService.GetEditorOperations(textView);
     _session           = session;
 }
Example #42
0
        public bool TryGetHistory(object context, out ITextUndoHistory history)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }
            var propertyOwner = context as IPropertyOwner;

            if (propertyOwner == null)
            {
                throw new ArgumentException();
            }
            return(propertyOwner.Properties.TryGetProperty(textUndoHistoryKey, out history));
        }
 public BraceCompletionSession(
     ITextView textView, ITextBuffer subjectBuffer,
     SnapshotPoint openingPoint, char openingBrace, char closingBrace, ITextUndoHistory undoHistory,
     IEditorOperationsFactoryService editorOperationsFactoryService, IEditorBraceCompletionSession session)
 {
     this.TextView = textView;
     this.SubjectBuffer = subjectBuffer;
     this.OpeningBrace = openingBrace;
     this.ClosingBrace = closingBrace;
     this.ClosingPoint = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint.Position, PointTrackingMode.Positive);
     _undoHistory = undoHistory;
     _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
     _session = session;
 }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        public void AttachHistory(object context, ITextUndoHistory history)
        {
            if (context == null)
            {
                throw new ArgumentNullException(nameof(context));
            }

            if (history == null)
            {
                throw new ArgumentNullException(nameof(history));
            }

            AttachHistory(context, history, false);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        public void AttachHistory(object context, ITextUndoHistory history)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context", String.Format(CultureInfo.CurrentCulture, "Strings.ArgumentCannotBeNull", "AttachHistory", "context"));
            }

            if (history == null)
            {
                throw new ArgumentNullException("context", String.Format(CultureInfo.CurrentCulture, "Strings.ArgumentCannotBeNull", "AttachHistory", "history"));
            }

            AttachHistory(context, history, false);
        }
        public BraceCompleterCommandHandler(IVsTextView textViewAdapter,
			IWpfTextView textView, IEditorOperations operations, ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _operations = operations;
            _undoHistory = undoHistory;

            _textView.GotAggregateFocus += TextView_GotFocus;

            // add the command to the command chain
            textViewAdapter.AddCommandFilter(this, out _nextCommandHandler);

            // load language and indentation settings
            LoadSettings();
        }
        public CaretPreservingEditTransaction(
            string description,
            ITextView textView,
            ITextUndoHistoryRegistry undoHistoryRegistry,
            IEditorOperationsFactoryService editorOperationsFactoryService)
        {
            _editorOperations = editorOperationsFactoryService.GetEditorOperations(textView);
            _undoHistory = undoHistoryRegistry.GetHistory(textView.TextBuffer);
            _active = true;

            if (_undoHistory != null)
            {
                _transaction = new HACK_TextUndoTransactionThatRollsBackProperly(_undoHistory.CreateTransaction(description));
                _editorOperations.AddBeforeTextBufferChangePrimitive();
            }
        }
Example #48
0
        public InformationBarMargin(IWpfTextView textView, ITextDocument document, IEditorOperations editorOperations, ITextUndoHistory undoHistory)
        {
            _textView = textView;
            _document = document;
            _operations = editorOperations;
            _undoHistory = undoHistory;

            var informationBar = new InformationBarControl();
            informationBar.Tabify.Click += Tabify;
            informationBar.Untabify.Click += Untabify;
            informationBar.Hide.Click += Hide;
            informationBar.DontShowAgain.Click += DontShowAgain;

            this.Height = 0;
            this.Content = informationBar;
            this.Name = MarginName;

            document.FileActionOccurred += FileActionOccurred;

            // Delay the initial check until the view gets focus
            textView.GotAggregateFocus += GotAggregateFocus;
        }
Example #49
0
        public CommandFilter(
            IVsTextView textView,
            IWpfTextView wpfTextView,
            IHtmlBuilderService htmlBuilderService,
            IRtfBuilderService rtfBuilderService,
            IEditorOperations editorOperations,
            ITextUndoHistory undoHistory,
            IEditorOptions editorOptions,
            IViewPrimitives viewPrimitives,
            ITelemetrySession telemetrySession)
        {
            _htmlBuilderService = htmlBuilderService;
            _rtfBuilderService = rtfBuilderService;
            _undoHistory = undoHistory;
            _textView = wpfTextView;
            _editorOperations = editorOperations;
            _editorOptions = editorOptions;
            _viewPrimitives = viewPrimitives;
            _telemetrySession = telemetrySession;

            textView.AddCommandFilter(this, out _nextCommandTargetInChain);
        }
 private static ITextUndoTransaction CreateTransaction(IEmacsCommandMetadata metadata, ITextUndoHistory history)
 {
     if (string.IsNullOrEmpty(metadata.UndoName))
     {
         return null;
     }
     return history.CreateTransaction(metadata.UndoName);
 }
Example #51
0
		private bool TryGetHistory(object context, out ITextUndoHistory basicUndoHistory) {
			return _map.TryGetValue(context, out basicUndoHistory);
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        /// <returns></returns>
        public bool TryGetHistory(object context, out ITextUndoHistory history) {
            if (context == null) {
                throw new ArgumentNullException(nameof(context));
            }

            ITextUndoHistory result = null;

            if (_strongContextMapping.ContainsKey(context)) {
                result = _strongContextMapping[context];
            } else if (_weakContextMapping.ContainsKey(new WeakReferenceForDictionaryKey(context))) {
                result = _weakContextMapping[new WeakReferenceForDictionaryKey(context)];
            }

            history = result;
            return (result != null);
        }
Example #53
0
		/// <summary>
		/// Easy to implement but the Visual Studio implementation throws a NotSupportedException
		/// </summary>
		void ITextUndoHistoryRegistry.AttachHistory(object context, ITextUndoHistory history) {
			throw new NotSupportedException();
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        /// <param name="keepAlive"></param>
        public void AttachHistory(object context, ITextUndoHistory history, bool keepAlive) {
            if (context == null) {
                throw new ArgumentNullException(nameof(context));
            }

            if (history == null) {
                throw new ArgumentNullException(nameof(history));
            }

            if (_strongContextMapping.ContainsKey(context) || _weakContextMapping.ContainsKey(new WeakReferenceForDictionaryKey(context))) {
                throw new InvalidOperationException("Attached history already containst context");
            }

            if (!_histories.ContainsKey(history)) {
                _histories.Add(history, 1);
            } else {
                ++_histories[history];
            }

            if (keepAlive) {
                _strongContextMapping.Add(context, history);
            } else {
                _weakContextMapping.Add(new WeakReferenceForDictionaryKey(context), history);
            }
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="context"></param>
        /// <param name="history"></param>
        public void AttachHistory(object context, ITextUndoHistory history) {
            if (context == null) {
                throw new ArgumentNullException(nameof(context));
            }

            if (history == null) {
                throw new ArgumentNullException(nameof(history));
            }

            AttachHistory(context, history, false);
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="history"></param>
        public void RemoveHistory(ITextUndoHistory history) {
            if (history == null) {
                throw new ArgumentNullException(nameof(history));
            }

            if (!_histories.ContainsKey(history)) {
                return;
            }

            _histories.Remove(history);

            List<object> strongToRemove = _strongContextMapping.Keys.Where(o => ReferenceEquals(_strongContextMapping[o], history)).ToList();

            strongToRemove.ForEach(o => _strongContextMapping.Remove(o));

            List<WeakReferenceForDictionaryKey> weakToRemove = _weakContextMapping.Keys.Where(o => ReferenceEquals(_weakContextMapping[o], history)).ToList();

            weakToRemove.ForEach(o => _weakContextMapping.Remove(o));
        }
Example #57
0
 public void AttachHistory(object context, ITextUndoHistory history)
 {
     _map.Add(context, history);
 }
Example #58
0
 public void RemoveHistory(ITextUndoHistory history)
 {
     throw new NotImplementedException();
 }
Example #59
0
 public bool TryGetHistory(object context, out ITextUndoHistory history)
 {
     return _map.TryGetValue(context, out history);
 }
            public RegistryBraceCompletionSession(
                ITextView textView, SnapshotPoint openingPoint,
                char openingBrace, char closingBrace,
                ITextUndoHistory undoHistory, IEditorOperations editorOperations
            )
            {
                this.OpeningBrace = openingBrace;
                this.ClosingBrace = closingBrace;

                TextView = textView;
                SubjectBuffer = textView.TextBuffer;
                OpeningPoint = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint, PointTrackingMode.Negative);
                ClosingPoint = SubjectBuffer.CurrentSnapshot.CreateTrackingPoint(openingPoint, PointTrackingMode.Positive);

                _undoHistory = undoHistory;
                _editorOperations = editorOperations;
            }