/// <summary> /// Initializes a controller for the given window. /// This is the controlling component in the MVC framework. /// </summary> /// <param name="window"></param> public Controller(ISpreadsheetView window, ISpreadsheetServer server, String SpreadsheetName) { _window = window; _server = server; _spreadsheetName = SpreadsheetName; SelectedCell = new GuiCell(0, 0); Spreadsheet = new Spreadsheet(); _random = new Random(); Clients = new Dictionary <string, Client>(); // Event Subscriptions _window.CellValueBoxTextComplete += CellValueBarChanged; _window.CellSelectionChange += SpreadsheetSelectionChanged; _window.CreateNew += CreateNew; _window.HandleOpen += () => HandleOpen(null); _window.HandleSave += () => HandleSave(_savePath); _window.HandleSaveAs += () => HandleSave(null); _window.HandleClose += HandleClose; _window.HandleHelp += WindowOnHandleHelp; _window.HandleUndo += Undo; //Setup defaults _window.SetSelection(SelectedCell.CellColumn, SelectedCell.CellRow); UpdateInfoBar($"{SelectedCell.CellName}: { SelectedCell.GetCellValue(Spreadsheet)}", Color.White); UpdateCellNameText(); _window.SetTitle(_spreadsheetName); }
private void DoneTyping(string clientId, string cellName) { Console.WriteLine("Done typing"); var cell = new GuiCell(cellName); int id; if (!int.TryParse(clientId, out id)) { id = _random.Next(); } if (!Clients.ContainsKey(clientId)) { Clients.Add(clientId, new Client { Color = ClientPallete[id % ClientPallete.Length], SelectedCell = null }); } else { Clients[clientId].SelectedCell = null; } Clients[clientId].SelectedCell = null; var client = Clients.Values.FirstOrDefault(c => c.SelectedCell == cell.CellName); _window.CellBackgroundColor(cell.CellColumn, cell.CellRow, client?.Color ?? Color.White); }
private void SetCellTyping(string clientId, string cellName) { var cell = new GuiCell(cellName); int id; if (!int.TryParse(clientId, out id)) { id = _random.Next(); } if (!Clients.ContainsKey(clientId)) { Clients.Add(clientId, new Client { Color = ClientPallete[id % ClientPallete.Length], SelectedCell = cell.CellName }); } else { Clients[clientId].SelectedCell = cellName; } _window.CellBackgroundColor(cell.CellColumn, cell.CellRow, Clients[clientId].Color); }
/// <summary> /// Every time the selection changes, this method is called with the /// Spreadsheet as its parameter. /// </summary> private void SpreadsheetSelectionChanged(int col, int row) { DoneTyping(); SelectedCell = new GuiCell(col, row); _window.CellValueBoxText = SelectedCell.GetCellContents(Spreadsheet); UpdateInfoBar($"{SelectedCell.CellName}: { SelectedCell.GetCellValue(Spreadsheet)}", Color.White); UpdateCellNameText(); IsTyping(); }
/// <summary> /// Iterates through the given Hashset and updates the cells in the view. /// </summary> /// <param name="cellNames"></param> private void UpdateCells(IEnumerable <string> cellNames) { foreach (var cellName in cellNames) { GuiCell cell = new GuiCell(cellName); _window.UpdateCell(cell.CellColumn, cell.CellRow, cell.GetCellValue(Spreadsheet)); if (SelectedCell.CellName == cell.CellName) { _window.CellValueBoxText = SelectedCell.GetCellContents(Spreadsheet); } } }