Beispiel #1
0
        public void PopUndo()
        {
            if (UndoStack.Count > 0)                  // ensures that there is something to be popped
            {
                CmdCollection from = UndoStack.Pop(); // pops the top list off of the undo stack -> all of the contents will be undone

                /* Executes all commands in the popped list
                 * Pushes the inverse of the popped actions onto the redo stack */
                RedoStack.Push(new CmdCollection(from.ExecuteAll()));
            }
        }
Beispiel #2
0
        public void PopRedo()
        {
            if (RedoStack.Count > 0) // ensures that there is something to be popped
            {
                CmdCollection from = RedoStack.Pop();

                /* Executes all commands in the popped list
                 * Pushes the inverse of the popped actions onto the redo stack */
                UndoStack.Push(new CmdCollection(from.ExecuteAll()));
            }
        }
Beispiel #3
0
        public CmdCollection ExecuteAll()
        {
            CmdCollection inverses = new CmdCollection(); // Will contain the opposite operations to the ones that are currently contained in this object

            foreach (IUndoRedoCmd cmd in this.cmds)
            {
                /* Adds the inverse operations to a NEW CmdCollection
                 * This will be pushed onto the opposite stack from where the current operation came from */
                inverses.cmds.Add(cmd.Execute());
            }

            return(inverses);
        }
Beispiel #4
0
 public CmdCollection(CmdCollection from)
 {
     /* Copy constructor
      * simply copies over the list in 'from' */
     this.cmds = from.cmds;
 }
Beispiel #5
0
 public void PushUndo(CmdCollection PropertyCollection)
 {
     UndoStack.Push(PropertyCollection); // Pushes the restoring collection on the undo stack
     RedoStack.Clear();                  // Clears the redo stack -> ensures that operations cannot be restored after preceding undo operations have been restored
 }
Beispiel #6
0
        public CmdCollection ExecuteAll()
        {
            CmdCollection inverses = new CmdCollection(); // Will contain the opposite operations to the ones that are currently contained in this object

            foreach (IUndoRedoCmd cmd in this.cmds)
            {
                /* Adds the inverse operations to a NEW CmdCollection
                 * This will be pushed onto the opposite stack from where the current operation came from */
                inverses.cmds.Add(cmd.Execute()); 
            }

            return inverses;
        }
Beispiel #7
0
 public CmdCollection(CmdCollection from)
 {
     /* Copy constructor
      * simply copies over the list in 'from' */
     this.cmds = from.cmds;
 }
Beispiel #8
0
 public void PushUndo(CmdCollection PropertyCollection)
 {
     UndoStack.Push(PropertyCollection); // Pushes the restoring collection on the undo stack
     RedoStack.Clear(); // Clears the redo stack -> ensures that operations cannot be restored after preceding undo operations have been restored
 }
Beispiel #9
0
        private void color_changing(object sender, bool custom)
        {
            ColorDialog SelectColor = new ColorDialog();
            if (custom) // user wants to select their own color -> prompts color dialogue
            {
                if (SelectColor.ShowDialog() != DialogResult.OK)
                    return;
            }
            else // the user chose one of the pre-selected colors
            {
                if (sender.ToString() == "Reset")
                    SelectColor.Color = System.Drawing.Color.FromArgb(-1); 
                if (sender.ToString() == "Green")
                    SelectColor.Color = System.Drawing.Color.FromArgb(192, 255, 192);
                else if (sender.ToString() == "Red")
                    SelectColor.Color = System.Drawing.Color.FromArgb(255, 128, 128);
                else if (sender.ToString() == "Orange")
                    SelectColor.Color = System.Drawing.Color.FromArgb(255, 192, 128);
                else if (sender.ToString() == "Grey")
                    SelectColor.Color = System.Drawing.Color.FromArgb(131, 130, 120);
            }

            DataGridViewSelectedCellCollection CellsChanging = dataGridView1.SelectedCells; // Gets the collection of selected cells
            CmdCollection BGRestore = new CmdCollection();

            if (CellsChanging != null) // Ensures that there is at least one selected cell
            {
                foreach (DataGridViewCell cell in CellsChanging) // Foreach cell that has been selected, notify the spreadsheet of that cells property change
                {
                    SpreadsheetCell Changing = mainSS[cell.RowIndex, cell.ColumnIndex];
                    RestoreBGColor newRestore = new RestoreBGColor(Changing, Changing.BGColor);

                    Changing.BGColor = SelectColor.Color.ToArgb(); // Converts the chosen color to ARBG integer format
                    BGRestore.Add(newRestore); 
                }

                mainSS.PushUndo(BGRestore); // Adds the new restore collection
                undoToolStripMenuItem.Text = "Undo - " + mainSS.PeekUndo; // Tells the UI which property will be undone
                redoToolStripMenuItem.Enabled = false;
                redoToolStripMenuItem.Text = "Redo";
            }
        }