/// <summary> /// Hooks OpenSpreadsheet event /// Allows user to select a file from file dialog and opens it in a new spreadsheet. Pop ups displayed if /// exceptions are thrown /// </summary> private void HandleOpenSpreadsheet() { //create pop up file explorer OpenFileDialog ofd = new OpenFileDialog(); ofd.DefaultExt = "ss"; ofd.Filter = "Spreadsheet file (*.ss)|*.ss|All Files (*.*)|*.*"; //create optional filters for .ss or all files //if they chose a file open, else cancel openspreadsheet event if (ofd.ShowDialog() == DialogResult.OK) { try { string filePath = ofd.FileName; string fileText = File.ReadAllText(filePath); //copy text from file AbstractSpreadsheet ss = new Spreadsheet(new StringReader(fileText), new Regex("^[A-Z][1-9][0-9]?$")); //create ss from designated file string filenName = Path.GetFileName(filePath); //get name for window title SpreadSheetApplicationContext.GetContext().RunNewFromFile(ss, filenName); //create new window from context this.view.OpenNewFromFile(ss, filenName); //for testing ONLY } catch (Exception e) //if something goes wrong disp err msg { string openError = "Error opening file.\n" + e.Message; System.Windows.Forms.MessageBox.Show(openError); } } }
static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Get the application context and run one form inside it var context = SpreadSheetApplicationContext .GetContext(); SpreadSheetApplicationContext.GetContext().RunNew(); Application.Run(context); }
/// <summary> /// Hooks OpenNewSpreadsheet event /// </summary> private void HandleOpenNewSpreadsheet() { SpreadSheetApplicationContext.GetContext().RunNew(); //opens new form from context }