コード例 #1
0
        /// <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);
        }
コード例 #2
0
        /// <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();
        }
コード例 #3
0
 /// <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);
         }
     }
 }
コード例 #4
0
 /// <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);
     }
 }