Пример #1
0
        public void AddAction(HistoryElement newAction) // добавить действие в историю
        {
            lock (this)
            {
                if (m_historyCurrent == m_capacity - 1)
                {
                    // увеличение емкости истории при переполнении
                    m_capacity += m_capacity;
                    HistoryElement[] increaseHistory = new HistoryElement[m_capacity];
                    Array.Copy(m_actionsArray, increaseHistory, m_actionsArray.Length);
                    m_actionsArray = increaseHistory;
                }

                m_actionsArray[m_historyCurrent + 1] = newAction;
                m_historyCurrent++;
                m_historyLength = m_historyCurrent + 1;

                // зажигание события возможности отмены
                HistoryAllowedEventArgs undoEvargs = new HistoryAllowedEventArgs(true);
                OnUndoAllowed(undoEvargs);
                // зажигание события отсутсвия повтора
                HistoryAllowedEventArgs redoEvargs = new HistoryAllowedEventArgs(false);
                OnRedoAllowed(redoEvargs);
            }
        }
Пример #2
0
        public HistoryElement Redo() // повтор действия из истории
        {
            if (!isRedo())
            {
                return(null);
            }
            m_historyCurrent++;

            HistoryAllowedEventArgs historyEvargs = null;

            // зажигание события возможности повтора
            if (isRedo())
            {
                historyEvargs = new HistoryAllowedEventArgs(true);
                OnRedoAllowed(historyEvargs);
            }
            else
            {
                historyEvargs = new HistoryAllowedEventArgs(false);
                OnRedoAllowed(historyEvargs);
            }

            // зажигание события возможности отмены
            historyEvargs = new HistoryAllowedEventArgs(true);
            OnUndoAllowed(historyEvargs);

            return(m_actionsArray[m_historyCurrent]);
        }
Пример #3
0
        public HistoryElement Undo() // откат действия
        {
            if (!isUndo())
            {
                return(null);
            }
            m_historyCurrent--;

            HistoryAllowedEventArgs historyEvargs = null;

            // зажигание события возможности отмены
            if (isUndo())
            {
                historyEvargs = new HistoryAllowedEventArgs(true);
                OnUndoAllowed(historyEvargs);
            }
            else
            {
                historyEvargs = new HistoryAllowedEventArgs(false);
                OnUndoAllowed(historyEvargs);
            }

            // зажигание события возможности повтора
            historyEvargs = new HistoryAllowedEventArgs(true);
            OnRedoAllowed(historyEvargs);

            return(m_actionsArray[m_historyCurrent + 1]);
        }
Пример #4
0
 protected virtual void OnRedoAllowed(HistoryAllowedEventArgs args)
 {
     if (RedoAllowed != null)
     {
         RedoAllowed(this, args);
     }
 }
Пример #5
0
        public void Clear() // очистка истории (например сохранили все)
        {
            m_historyCurrent = -1;
            m_historyLength  = 0;

            HistoryAllowedEventArgs historyEvargs = new HistoryAllowedEventArgs(false);

            OnUndoAllowed(historyEvargs);
            OnRedoAllowed(historyEvargs);
        }