/// <summary> /// function to update the variable dictionary of tree with the /// referenced cells. /// </summary> /// <param name="cell"> Cell that is referenced in expression.</param> public void UpdateVariableDict(CellClass cell) { if (this.variables.ContainsKey(cell.GetCellIndex())) { // Dictionary contains the referenced variable value.// double value = 0.0; if (double.TryParse(cell.Value, out value)) { this.variables[cell.GetCellIndex()] = value; } else { this.variables[cell.GetCellIndex()] = 0.0; } } else { // Dictionary does not contain the referenced variable value.// double value = 0.0; if (double.TryParse(cell.Value, out value)) { this.SetVariable(cell.GetCellIndex(), value); } else { this.SetVariable(cell.GetCellIndex(), 0); } } }
/// <summary> /// Function to insert the background color change to cell onto the undo redo stack. /// </summary> /// <param name="cell"> Cell that is to be changed.</param> /// <param name="newColor"> integer denoting the new color of the cell.</param> public void InsertInUndoRedoForColorChange(CellClass cell, uint newColor) { ICommand command = new ColorChangeCommand(cell, newColor); this.undoCommands.Push(command); this.redoCommands.Clear(); }
/// <summary> /// Function to insert the text change to cell onto the undo redo stack. /// </summary> /// <param name="cell"> Cell that is to be changed.</param> /// <param name="newText"> string denoting new text of the cell.</param> public void InsertInUndoRedoForTextChange(CellClass cell, string newText) { ICommand command = new TextChangeCommand(cell, newText); this.undoCommands.Push(command); this.redoCommands.Clear(); }
private bool CircularReferenceChecker(CellClass cell, List <CellClass> cells) { if (cell.Text == string.Empty) { return(false); } if (cell.Text[0] != '=') { return(false); } ExpressionTree expression = new ExpressionTree(cell.Text.Substring(1)); List <string> variableList = expression.GetVariableNames(); if (cells.Contains(cell)) { return(true); } cells.Add(cell); List <CellClass> cellList = new List <CellClass>(); foreach (string variable in variableList) { cellList.Add(this.GetCellFromIndex(variable)); } foreach (CellClass cellClass in cellList) { if (cellClass != null) { if (cellClass.Text != " " || cellClass.Text != null) { var newCellList = new List <CellClass>(cells); if (this.CircularReferenceChecker(cellClass, newCellList)) { return(true); } } } } return(false); }
/// <summary> /// Function to subscribe the expression tree to changes made /// to cells in expression. /// </summary> /// <param name="cell"> Storing the cell that needs to be subscribed to.</param> public void SubscribeCellToTree(CellClass cell) { cell.PropertyChanged += this.expression.CellChanged; this.expression.UpdateVariableDict(cell); }
/// <summary> /// Initializes a new instance of the <see cref="TextChangeCommand"/> class. /// </summary> /// <param name="cell"> Cell class cell that the command references.</param> /// <param name="newText"> the new text that will be assigned to cell.</param> public TextChangeCommand(CellClass cell, string newText) { this.cell = cell; this.oldTextInCell = this.cell.Text; this.newTextInCell = newText; }
/// <summary> /// function to assign the cell which tree belongs to. /// </summary> /// <param name="cell"> Cell which tree belongs to.</param> public void SetCellForTree(CellClass cell) { Cell scell = cell as Cell; this.cellForTree = scell; }
/// <summary> /// Initializes a new instance of the <see cref="ColorChangeCommand"/> class. /// </summary> /// <param name="cell"> Cell class cell.</param> /// <param name="newBGcolor"> the new background color for cell.</param> public ColorChangeCommand(CellClass cell, uint newBGcolor) { this.cell = cell; this.oldBackColor = this.cell.BGcolor; this.newBackColor = newBGcolor; }