/// <summary> /// Event handler for double click on a file item in the file list. /// The clicked file are executed and the results from the calculations are shown in the result list. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void lstFiles_MouseDoubleClick(object sender, MouseEventArgs e) { //Find the location of the double click. int index = lstFiles.IndexFromPoint(e.Location); if (index != System.Windows.Forms.ListBox.NoMatches) { //The location corresponded to an item. //Run the script file. FileEditor editor = fm.ChangeFile(index); ScriptFileEvaluator fileEvaluator = new ScriptFileEvaluator(editor.ReadFileContents()); List <ExpressionItem> list = new List <ExpressionItem>(); try { //Try to evaluate and print the rows in the script file. fileEvaluator.Evaluate(out list); PrintValues(list); } catch (Exception ex) { //All rows weren't possible to evaluate. //Print the rows that were evaluated and display an error message. PrintValues(list); lstResultList.Items.Add(String.Format(" error: {0}", ex.Message)); } } lstResultList.Items.Add(String.Empty); UpdateGUI(); }
/// <summary> /// Event handler for the change file button. /// Similar to the add button, but doesn't create a file. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnChangeFile_Click(object sender, EventArgs e) { FileEditor file = fm.ChangeFile(lstFiles.SelectedIndex); OpenFile(file); UpdateGUI(); }
/// <summary> /// Constructs a form with the given file. /// </summary> /// <param name="file">The file to view or edit.</param> public FileEditorForm(FileEditor file) { InitializeComponent(); //Save the file and initialize the GUI this.file = file; InitializeGUI(); }
/// <summary> /// Event handler for the add file button. /// Creates a new file with the given name and shows it in the editor. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAddFile_Click(object sender, EventArgs e) { //Asks the user for a file name. PromptDialogResult result = PromptDialog.Show("Enter file name:", "Input file name"); if (result.Result == DialogResult.OK) { try { FileEditor file = fm.NewFile(result.Message + FileManager.FILE_NAME_EXT); OpenFile(file); UpdateGUI(); } catch (Exception ex) { lstResultList.Items.Add(ex.Message); } } }
/// <summary> /// Creates a new FileEditorForm and shows it. /// </summary> /// <param name="file"></param> private void OpenFile(FileEditor file) { FileEditorForm editor = new FileEditorForm(file); editor.Show(); }