コード例 #1
0
        public void Redo(SpreadSheet inSheet)
        {
            CommandObj tempObj = RedoStk.Pop();

            if (tempObj.Command == "Cell Background Color Change")
            {
                tempObj.Link = true;
            }

            UndoStk.Push(new CommandObj(inSheet.CellGrid[tempObj.Row, tempObj.Col], tempObj.Command, tempObj.Link));

            switch (tempObj.Command)
            {
            case "Cell Text Changed":
                inSheet.CellGrid[tempObj.Row, tempObj.Col].Text = tempObj.Text;
                break;

            case "Cell Background Color Change":
                inSheet.CellGrid[tempObj.Row, tempObj.Col].BGColor = tempObj.cColor;
                break;

            default:
                break;
            }


            while (RedoStk.Count > 0 && RedoStk.Peek().Link == true) // Checking for linked items
            {
                tempObj = RedoStk.Pop();

                UndoStk.Push(new CommandObj(inSheet.CellGrid[tempObj.Row, tempObj.Col], tempObj.Command, tempObj.Link));

                switch (tempObj.Command)
                {
                case "Cell Text Changed":
                    inSheet.CellGrid[tempObj.Row, tempObj.Col].Text = tempObj.Text;
                    inSheet.ClearRefrence(inSheet.CellGrid[tempObj.Row, tempObj.Col]);
                    break;

                case "Cell Background Color Change":
                    inSheet.CellGrid[tempObj.Row, tempObj.Col].BGColor = tempObj.cColor;
                    break;

                default:
                    break;
                }
            }
            UndoStk.Peek().Link = false;
            inSheet.ClearRefrence(inSheet.CellGrid[tempObj.Row, tempObj.Col]); // this is the one line that prevented me from submiting for the last 2 hours
        }
コード例 #2
0
        /// <summary>
        /// Event Handler for the case that CellData returns a TextChanged Event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public void Text_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            Cell       NewCell;
            CommandObj tempObj = null;

            if (sender is CommandObj)
            {
                tempObj         = (CommandObj)sender;
                NewCell         = new Cell(tempObj.Row, tempObj.Col);
                NewCell.Text    = tempObj.Text;
                NewCell.BGColor = tempObj.cColor;
            }

            else
            {
                NewCell = (Cell)sender;
            }

            if (NewCell.Text == null) // null check
            {
                NewCell.Value = null;
            }
            else if (!NewCell.Text.StartsWith("=")) // the text dosn't need to be evaluated
            {
                NewCell.Value = NewCell.Text;
                //if (CheckCircularRefrence(NewCell)) NewCell.Text = "#Circular Refrence!";
                updateCellRefrences(NewCell);
            }
            else                // call evaluation function
            {
                CellEvaluation(NewCell);
            }

            if (tempObj != null)
            {
                UndoPropertyChanged(NewCell, e);
                return;
            }
            CellPropertyChanged(NewCell, e);
        }