/// <summary> /// Single param constructor creates a new controller for passed ISpreadSheetView /// </summary> /// <param name="_view"></param> public Controller(ISpreadSheetView _view) { this.view = _view; var re = new Regex("^[A-Z][1-9][0-9]?$"); //creates new regex limited to (A1-Z99) inclusive this.model = new Spreadsheet(re); //creates new spreadhseet model with designated regex //register all events to handlers view.SetCellContents += HandleSetCellContents; view.GetCellValue += HandleGetCellValue; view.GetCellContents += HandleGetCellContents; view.HelpMenu += HandleHelpMenu; view.SaveSpreadsheet += HandleSaveSpreadsheet; view.SaveAs += HandleSaveAs; view.OpenSpreadsheet += HandleOpenSpreadsheet; view.OpenNewSpreadsheet += HandleOpenNewSpreadsheet; view.CloseEvent += HandleCloseEvent; // Dont forget to update the 2 argument constructor }
/// <summary> /// Multiple param constructor creates a new controller for a view opened from a file, handles hooking /// and populates the new spreadsheet gui with saved contents /// </summary> /// <param name="_view"></param> /// <param name="ss"></param> /// <param name="pathOpenedFrom"></param> public Controller(ISpreadSheetView _view, AbstractSpreadsheet ss, string pathOpenedFrom) { this.view = _view; this.model = ss; //register all events view.SetCellContents += HandleSetCellContents; view.GetCellValue += HandleGetCellValue; view.GetCellContents += HandleGetCellContents; view.HelpMenu += HandleHelpMenu; view.OpenSpreadsheet += HandleOpenSpreadsheet; view.OpenNewSpreadsheet += HandleOpenNewSpreadsheet; view.SaveSpreadsheet += HandleSaveSpreadsheet; view.SaveAs += HandleSaveAs; view.CloseEvent += HandleCloseEvent; // Dont forget to update the 1 argument constructor // populate all cells foreach (string cellName in this.model.GetNamesOfAllNonemptyCells()) { this.HandleUpdateCellDisplay(cellName); } }