Exemplo n.º 1
0
        private void OnSelectionChanged(EventArgs e, bool isFromHistory)
        {
            CharacterRange _range = SelectionRange;

            if (m_autoCompleteShowing)
            {
                int _wordEnd = FindNextWordBreak(m_autoCompleteStart + 1);

                if (_range.First < m_autoCompleteStart)
                {
                    HideAutoComplete();
                }
                else if ((_range.First + _range.Length) > _wordEnd)
                {
                    HideAutoComplete();
                }
                else
                {
                    AutoCompleteHighlight();
                }
            }

            if (!isFromHistory)
            {
                ChangeDescription _change = m_tracker.AnalyzeChange();
                QueueUndoAction(_change);
                NotifyTextChanged(_change);
            }

            base.OnSelectionChanged(e);
        }
Exemplo n.º 2
0
        private void QueueUndoAction(ChangeDescription change)
        {
            if (change == null)
            {
                return;
            }

            if (change.TextAfter == null || change.TextBefore == null || change.Start == -1)
            {
                return;
            }

            // We're not at the end of the undo buffer, so nuke anything from here to the end
            if (m_undoIndex != m_undoHistory.Count)
            {
                m_undoHistory.RemoveRange(m_undoIndex, m_undoHistory.Count - m_undoIndex);

                if (m_savePoint > m_undoIndex)
                {
                    m_savePoint = -1;
                }
            }

            // We need to check this before we change the undoIndex or the savePoint, since
            // the value depends on those things.
            bool _wasModified = Modified;

            m_undoHistory.Add(change);

            // Truncate the undo buffer to the correct length
            int _excess = m_undoHistory.Count - m_undoLength;

            if (_excess > 0)
            {
                _excess = Math.Min(_excess, m_undoHistory.Count);

                if (_excess > 0)
                {
                    m_undoHistory.RemoveRange(0, _excess);

                    m_savePoint -= _excess;
                }
            }

            m_undoIndex = m_undoHistory.Count;

            if (!_wasModified)
            {
                if (ModifiedChanged != null)
                {
                    ModifiedChanged(this, EventArgs.Empty);
                }
            }
        }
Exemplo n.º 3
0
        // Undoes the last edit operation
        public new void Undo()
        {
            if (m_undoIndex <= 0)
            {
                return;
            }

            // We need to check this before we change the undoIndex
            bool _wasModified = Modified;

            --m_undoIndex;

            ChangeDescription _action = (ChangeDescription)m_undoHistory[m_undoIndex];

            PreventRedraw();

            m_historyActionUnderway = true;

            try
            {
                m_tracker.Undo(_action);
                SelectionRange = new CharacterRange(_action.Start, _action.TextAfter.Length);
                SelectedText   = _action.TextBefore;
                SelectionRange = _action.SelectionBefore;
            }
            finally
            {
                m_historyActionUnderway = false;
                AllowRedraw();
            }

            if (Modified != _wasModified)
            {
                if (ModifiedChanged != null)
                {
                    ModifiedChanged(this, EventArgs.Empty);
                }
            }

            NotifyTextChanged(_action, true);
        }
Exemplo n.º 4
0
        // Redoes the next action in the control's Redo queue
        public new void Redo()
        {
            if (m_undoIndex >= m_undoHistory.Count)
            {
                return;
            }

            bool _wasModified = Modified;

            ChangeDescription _action = (ChangeDescription)m_undoHistory[m_undoIndex];

            ++m_undoIndex;

            PreventRedraw();

            m_historyActionUnderway = true;

            try
            {
                m_tracker.Redo(_action);
                SelectionRange = new CharacterRange(_action.Start, _action.TextBefore.Length);
                SelectedText   = _action.TextAfter;
                SelectionRange = _action.SelectionAfter;
            }
            finally
            {
                m_historyActionUnderway = false;
                AllowRedraw();
            }

            if (_wasModified != Modified)
            {
                if (ModifiedChanged != null)
                {
                    ModifiedChanged(this, EventArgs.Empty);
                }
            }

            NotifyTextChanged(_action);
        }
Exemplo n.º 5
0
        private void NotifyTextChanged(ChangeDescription change, bool isUndo)
        {
            string _after = "";

            if (change.TextAfter != null)
            {
                _after = change.TextAfter;
            }

            string _before = "";

            if (change.TextBefore != null)
            {
                _before = change.TextBefore;
            }

            // No need to notify if there was no change, even though this method gets called
            // sometimes when text hasn't been altered.
            if (_after.Length == 0 && _before.Length == 0)
            {
                return;
            }

            TextChanged2EventArgs _args;

            if (isUndo)
            {
                _args = new TextChanged2EventArgs(change.Start, _after, _before);
            }
            else
            {
                _args = new TextChanged2EventArgs(change.Start, _before, _after);
            }

            OnTextChanged2(_args);
        }
Exemplo n.º 6
0
 private void NotifyTextChanged(ChangeDescription change)
 {
     NotifyTextChanged(change, false);
 }
Exemplo n.º 7
0
 public void Undo(ChangeDescription change)
 {
     UpdateText(change.Start, change.TextAfter.Length, change.TextBefore);
     m_storedSelection = change.SelectionBefore;
 }
Exemplo n.º 8
0
 public void Redo(ChangeDescription change)
 {
     UpdateText(change.Start, change.TextBefore.Length, change.TextAfter);
     m_storedSelection = change.SelectionAfter;
 }