private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (editors_.Count == 0) { MessageBox.Show("No files open!", "SIL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } if (activeEditor_ == null) { MessageBox.Show("No active editor found!", "SIL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SIL_Program prog = new SIL_Program(); prog.Text = activeEditor_.ProgramText; prog.Name = activeEditor_.ProgramName; SaveFileDialog sf = new SaveFileDialog(); sf.Filter = "SIL files (*.SIL)|*.SIL|All files (*.*)|*.*"; sf.AddExtension = true; sf.FileName = prog.Name; if (sf.ShowDialog() == DialogResult.OK) { SIL_IO.Save(sf.FileName, prog); MessageBox.Show("File saved", "SIL", MessageBoxButtons.OK, MessageBoxIcon.Information); } }
private void openToolStripMenuItem_Click(object sender, EventArgs e) { OpenFileDialog of = new OpenFileDialog(); of.Filter = "SIL files (*.SIL)|*.SIL|All files (*.*)|*.*"; if (of.ShowDialog() == DialogResult.OK) { try { SIL_Program prog = SIL_IO.Load(of.FileName); frmEditor editor = new frmEditor(); //create new editor window editor.MdiParent = this; //set it as a child to Main Form editor.ProgramName = prog.Name; editor.ProgramText = prog.Text; editor.Show(); //display it editor.FormClosing += new FormClosingEventHandler(editor_FormClosing); //Add event handler to catch events when form is closed editor.Activated += new EventHandler(editor_Activated); editors_.Add(editor); //add it to active editors list activeEditor_ = editor; //set it as active this.Text = String.Format("SIL - {0}", activeEditor_.programName_); EditorWindowsUpdate(); } catch (Exception ex) { MessageBox.Show("Failed to read SIL file!", "SIL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
public bool start(string[] arrayOfStringsFromCommandLine) { //Console.WriteLine(arrayOfStringsFromCommandLine[1]); if (arrayOfStringsFromCommandLine.GetLength(0) == 0) { return(false); } try { if (!File.Exists(arrayOfStringsFromCommandLine[0])) { Console.WriteLine("File not found"); return(true); } SIL_Program program = SIL_IO.Load(arrayOfStringsFromCommandLine[0]); Console.WriteLine("Loaded Program: " + arrayOfStringsFromCommandLine[0]); // program.Name += "\n\r" + program.Text; // program.Text = program.Name; // SymbolTable.Initialize(); program.Parse(); program.Execute(); } catch (FileNotFoundException ex) { // Write error. Console.WriteLine("File not Found"); return(true); } catch (Exception e) { string[] err = e.Message.Split('%'); for (int i = 0; i < err.Length - 1; ++i) { Console.WriteLine(err[i]); } Console.WriteLine("LineNumber:" + err[err.Length - 1]); } return(true); }
public void ExecuteProgram(SIL_Program program, frmErrList errList) { this.Text = "Output - " + program.Name; try { program.Parse(); program.Execute(); } catch (Exception e) { string[] err = e.Message.Split('%'); if (err.Length > 1) { errList.AddError(err[0], int.Parse(err[1])); } else { errList.AddError(err[0], 0); } } }
/// <summary> /// Runs the program in the active editor window /// </summary> private void Run() { if (activeEditor_ == null) { MessageBox.Show("No active editor found!", "SIL Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } SIL_Program program = new SIL_Program(); program.Name = activeEditor_.ProgramName; program.Text = activeEditor_.ProgramText; //Get output and error windows frmOutput output = GetOutputWindow(program.Name); output.Clear(); frmErrList errors = GetErrorWindow(program.Name); errors.Clear(); //Execute the program in these widnows output.ExecuteProgram(program, errors); }