예제 #1
0
파일: Game.cs 프로젝트: mloup/diaballik
        public void RedoLastCommand()
        {
            if (UndoHistory.Count == 0)
            {
                throw new InvalidOperationException("Il n'y a aucune action à redo.");
            }
            Command LastCmdToRedo = UndoHistory.Pop().GetCommand();

            if (LastCmdToRedo.CanDo(this))
            {
                LastCmdToRedo.Do(this);
                CommandHistory.Push(new CommandMemento(LastCmdToRedo));
                if (LastCmdToRedo is MovePiece)
                {
                    MovePieceCount++;
                }
                if (LastCmdToRedo is MoveBall)
                {
                    MoveBallCount++;
                }
            }
            else
            {
                throw new InvalidOperationException("Impossible de refaire la dernière action :" + LastCmdToRedo.GetType() + "\n");
            }
        }
예제 #2
0
 protected virtual void Dispose(bool isDisposing)
 {
     if (!isDisposing)
     {
         return;
     }
     if (this.editorElement != null)
     {
         TextCompositionManager.RemoveTextInputStartHandler((DependencyObject)this.editorElement, new TextCompositionEventHandler(this.OnTextInputStart));
         TextCompositionManager.RemoveTextInputUpdateHandler((DependencyObject)this.editorElement, new TextCompositionEventHandler(this.OnTextInputUpdate));
         this.editorElement.TextInput -= new TextCompositionEventHandler(this.OnTextInput);
         this.editorElement.KeyDown   -= new KeyEventHandler(this.OnKeyDown);
         this.editorElement.MouseDown -= new MouseButtonEventHandler(this.OnMouseDown);
         this.editorElement            = (FrameworkElement)null;
     }
     if (this.codeAidEngine != null)
     {
         this.codeAidEngine.Dispose();
         this.codeAidEngine = (XamlCodeAidEngine)null;
     }
     if (this.undoHistory == null)
     {
         return;
     }
     this.undoHistory.UndoRedoHappened -= new EventHandler <UndoRedoEventArgs>(this.OnUndoRedoHappened);
     this.undoHistory = (UndoHistory)null;
 }
예제 #3
0
파일: Game.cs 프로젝트: mloup/diaballik
        public void Update(Command cmd)
        {
            if (cmd.CanDo(this))
            {
                cmd.Do(this);
                if (cmd is MoveBall)
                {
                    MoveBallCount++;
                }
                if (cmd is MovePiece)
                {
                    MovePieceCount++;
                }
                CommandHistory.Push(new CommandMemento(cmd));
                UndoHistory.Clear();

                //Console.Write(Board.ToString());
                if (IsWin())
                {
                    VictoriousPlayer = Players[CurrentPlayer];
                }
                if (IsEndTurn())
                {
                    Command endTurn = new EndTurn();
                    CommandHistory.Push(new CommandMemento(endTurn));
                    endTurn.Do(this);
                }
            }
            else
            {
                throw new InvalidOperationException("Impossible d'effectuer l'action " + cmd.GetType() + " : " + cmd.ToString());
            }
        }
예제 #4
0
 private void ProjectManager_ProjectChanged(object sender, EventArgs e)
 {
     UndoHistory.Clear();
     RedoHistory.Clear();
     HistoryLimitExceeded = false;
     CurrentChangeID      = 0;
 }
예제 #5
0
        public void DrawOnMap(Block blok, Point click)
        {
            if (QueueChecked)
            {
                //checkbox is checked
                if (CurrentMap.GetElement(blok.X, blok.Y) != Convert.ToInt32(blok.TypeBlock))
                {
                    RedoUndo newAction = new RedoUndo(blok, this);
                    UndoHistory.Push(newAction);
                    Queue tempQueue = new Queue(blok.X, blok.Y, Convert.ToInt32(blok.TypeBlock), this);
                    tempQueue.QueueTask();
                }
            }
            else
            {
                if (CurrentMap.GetElement(blok.X, blok.Y) != Convert.ToInt32(blok.TypeBlock))
                {
                    RedoUndo newAction = new RedoUndo(blok, this);
                    UndoHistory.Push(newAction);
                    CurrentMap.SetElement(blok.X, blok.Y, Convert.ToInt32(blok.TypeBlock));
                    //if ((int)click.X % BlockScale == 0 || (int)click.Y % BlockScale == 0)
                    //{


                    RenderMap();


                    //}
                }
            }
        }
예제 #6
0
 public override void DiscardChanges()
 {
     _directImage.Render();
     UndoHistory.Clear();
     RedoHistory.Clear();
     NotifyOfPropertyChange(() => CanUndo);
     NotifyOfPropertyChange(() => CanRedo);
 }
예제 #7
0
 public void ClearHistory()
 {
     UndoHistory.Clear();
     RedoHistory.Clear();
     HistoryLimitExceeded = false;
     ProjectIsModified    = false;
     CurrentChangeID      = 0;
 }
예제 #8
0
 /// <summary>
 /// Redos the last change made and pushes it to the undo stack,
 /// if possible.
 /// </summary>
 public void Redo()
 {
     if (CanRedo())
     {
         UndoHistory.Push(new AppPalUndo(Palette, RedoHistory.Peek().Name));
         var state = RedoHistory.Pop();
         SetPalette(state.Palette, false);
     }
 }
예제 #9
0
        /// <summary>
        /// Handles the event that occurs when the redo menu is clicked.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void RedoTextMenuClick(object sender, EventArgs e)
        {
            string edit  = (string)UndoHistory.Pop(); // Edit string
            int    loc   = (int)UndoHistory.Pop();    // Location of edit
            bool   isDel = (bool)UndoHistory.Pop();   // Indicates whether the edit is a deletion

            EditHistory.Push(isDel);
            EditHistory.Push(loc);
            EditHistory.Push(edit);
            DoEdit(isDel, loc, edit);
        }
예제 #10
0
 private void Awake()
 {
     if (instance == null)
     {
         instance = this;
     }
     else if (instance != this)
     {
         Destroy(gameObject);
     }
     DontDestroyOnLoad(gameObject);
 }
예제 #11
0
        private void AddAction(ChangeAction action)
        {
            RedoHistory.Clear();
            UndoHistory.Add(action);
            action.ChangeID = ++CurrentChangeID;

            if (UndoHistory.Count > MaxHistory)
            {
                HistoryLimitExceeded = true;
                UndoHistory.RemoveAt(0);
            }

            UndoHistoryChanged?.Invoke(this, EventArgs.Empty);
        }
예제 #12
0
        /// <summary>
        /// Redos the last change made and pushes it to the undo stack,
        /// if possible.
        /// </summary>
        public void Redo()
        {
            if (CanRedo())
            {
                UndoHistory.Push(new AppState(HsvColor, SchemeType));
                AppState s = RedoHistory.Pop();
                SetColor(s.Color, false, false);
                SetSchemeType(s.SchemeType, false, false);

                // because we didn't use the setters to fire events
                // because we'd be wastefully firing two otherwise
                OnResultChanged(new EventArgs());
            }
        }
예제 #13
0
 /// <summary>Set up the chart for MouseOps</summary>
 private void InitNavigation()
 {
     m_nav_history = new UndoHistory <NavHistoryRecord>
     {
         IsDuplicate   = NavHistoryRecord.ApproxEqual,
         ApplySnapshot = snapshot =>
         {
             XAxis.Range = snapshot.XRange;
             YAxis.Range = snapshot.YRange;
             SetCameraFromRange();
             Invalidate();
         },
     };
 }
예제 #14
0
 public CodeEditorOperations(CodeEditor codeEditor, ICompletionBroker completionBroker, ICodeAidProvider codeAidProvider)
 {
     this.editorElement                 = codeEditor.Element;
     this.editorOperations              = codeEditor.EditorCommands;
     this.undoHistory                   = codeEditor.UndoHistory;
     this.textView                      = codeEditor.TextView;
     this.completionBroker              = completionBroker;
     this.codeAidEngine                 = new XamlCodeAidEngine(codeEditor.TextBuffer, codeAidProvider, codeEditor.Environment);
     this.editorElement.TextInput      += new TextCompositionEventHandler(this.OnTextInput);
     this.editorElement.KeyDown        += new KeyEventHandler(this.OnKeyDown);
     this.editorElement.MouseDown      += new MouseButtonEventHandler(this.OnMouseDown);
     this.undoHistory.UndoRedoHappened += new EventHandler <UndoRedoEventArgs>(this.OnUndoRedoHappened);
     TextCompositionManager.AddTextInputStartHandler((DependencyObject)this.editorElement, new TextCompositionEventHandler(this.OnTextInputStart));
     TextCompositionManager.AddTextInputUpdateHandler((DependencyObject)this.editorElement, new TextCompositionEventHandler(this.OnTextInputUpdate));
 }
예제 #15
0
    public override void SaveChanges()
    {
        try
        {
            _directImage.SaveImage();

            UndoHistory.Clear();
            RedoHistory.Clear();
            NotifyOfPropertyChange(() => CanUndo);
            NotifyOfPropertyChange(() => CanRedo);

            IsModified = false;
            var changeEvent = new ArrangerChangedEvent(_projectArranger, ArrangerChange.Pixels);
            _events.PublishOnUIThread(changeEvent);
        }
        catch (Exception ex)
        {
            _windowManager.ShowMessageBox($"Could not save the pixel arranger contents\n{ex.Message}\n{ex.StackTrace}", "Save Error");
        }
    }
예제 #16
0
        private void ImageControl_MouseDown(object sender, MouseButtonEventArgs e)
        {
            if (IsEydropping)
            {
                UserEyedrops();
            }
            else
            {
                try
                {
                    UndoHistory.Add(new Bitmap(LayeredImage.SelectedBitmapLayer.Source));
                }
                catch (ArgumentOutOfRangeException)
                { }

                IsDrawing = true;
                UserDrawsOnBitmap();
                RedoHistory = new List <Bitmap>(MaxItemsInHistory);
            }
        }
예제 #17
0
        public void Redo()
        {
            if (RedoHistory.Any())
            {
                BeginUndoRedo?.Invoke(this, EventArgs.Empty);

                var lastAction = RedoHistory.Last();
                CurrentChangeID = lastAction.ChangeID;

                RedoHistory.Remove(lastAction);
                UndoHistory.Add(lastAction);

                ExecutingUndoRedo = true;
                lastAction.Redo();
                ExecutingUndoRedo = false;

                EndUndoRedo?.Invoke(this, EventArgs.Empty);
                UndoHistoryChanged?.Invoke(this, EventArgs.Empty);
            }
        }
예제 #18
0
        /// <summary>
        /// Records edits for undos
        /// </summary>
        private void RecordEdit()
        {
            bool   isDel = Text.Length < LastText.Length;                                   // Indicates whether the edit was a deletion
            int    len   = Math.Abs(Text.Length - LastText.Length);                         // The length of the string inserted or deleted
            int    loc   = isDel ? SelectionStart : (SelectionStart - len);                 // The location of the edit
            string edit  = isDel ? LastText.Substring(loc, len) : Text.Substring(loc, len); // Gets the edit string

            if (Text.Length != 0 && edit == "\t")
            {
                Text           = Text.Remove(loc, 1);    // Remove tab
                edit           = new string(' ', 4);
                Text           = Text.Insert(loc, edit); // Insert spaces for tab
                SelectionStart = loc + 4;                // Restore cursor location
            }

            EditHistory.Push(isDel);
            EditHistory.Push(loc);
            EditHistory.Push(edit);
            UndoHistory.Clear();
            LastText = Text;
        }
예제 #19
0
파일: Game.cs 프로젝트: mloup/diaballik
        // Ne Marche pas ! (Le Board de ma commande n'est pas le Board de ma game actuelle)
        public void UndoLastCommand()
        {
            Command LastCmdToUndo = CommandHistory.Pop().GetCommand();

            if (LastCmdToUndo.CanUndo(this))
            {
                LastCmdToUndo.Undo(this);
                UndoHistory.Push(new CommandMemento(LastCmdToUndo));
                if (LastCmdToUndo is MovePiece)
                {
                    MovePieceCount--;
                }
                if (LastCmdToUndo is MoveBall)
                {
                    MoveBallCount--;
                }
            }
            else
            {
                throw new InvalidOperationException("Impossible de défaire la dernière action :" + LastCmdToUndo.GetType() + " : " + LastCmdToUndo.ToString());
            }
        }
예제 #20
0
 /// <summary>
 /// Pushes the current state of the application to the undo stack, and purges the redo stack.
 /// </summary>
 private void PushUndo()
 {
     UndoHistory.Push(new AppState(HsvColor, SchemeType));
     RedoHistory.Clear();
 }
예제 #21
0
 /// <summary>
 /// Pushes the current state of the application to the undo stack, and purges the redo stack.
 /// </summary>
 private void PushUndo(string action)
 {
     UndoHistory.Push(new AppPalUndo(Palette, action));
     RedoHistory.Clear();
 }