/// <summary> /// Sets the selected cell contents to the new value from the data bar. If an exception occurs the info bar will /// display an error message. /// </summary> private void CellValueBarChanged(string value) { //Set the info bar to be empty. _window.InfoBarText = string.Empty; try { SendCell(SelectedCell.CellName, value); UpdateInfoBar($"{SelectedCell.CellName}: { SelectedCell.GetCellValue(Spreadsheet)}", Color.White); _window.SetTitle(_spreadsheetName + "*"); } catch (Exception e) { UpdateInfoBar(e.Message, Color.Red); } }
/// <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); }
/// <summary> /// Creates a new controller that is based off of the passed in window and contains all of /// the data stored in the passed in file. Error checking will have been done by a previous /// controller, so the passed in file will always be readable. /// </summary> /// <param name="_window">The GUI that the controller can interact with</param> /// <param name="filename">The name of the file containing the data to be read</param> public Controller(ISpreadsheetView _window, string filename) : this(_window) { int col, row; Regex r = new Regex(@"^[a-zA-Z][1-9][0-9]?$"); using (StreamReader sw = new StreamReader(filename)) { spreadsheet = new Spreadsheet(sw, r); } foreach (string cell in spreadsheet.GetNamesOfAllNonemptyCells()) { toCoordinates(cell, out col, out row); window.SetValue(col, row, spreadsheet.GetCellValue(cell).ToString()); } window.SetTitle(filename); HandleNewCellSelected(); }