private void LoadProject(String Filename, bool bDoCreate, String ErrorMessage) { try { Form form = new ProjectForm(Filename, bDoCreate); form.MdiParent = this; form.Show(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); MessageBox.Show(ErrorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
public SourceForm(ProjectForm projectform, ref CodePortingTrackerSourceFile srcdata) { PrjForm = projectform; src = srcdata; InitializeComponent(); openToolStripMenuItem.BackColor = ConvertLineStateToColor(LineState.Open); inProgressToolStripMenuItem.BackColor = ConvertLineStateToColor(LineState.Progress); doneToolStripMenuItem.BackColor = ConvertLineStateToColor(LineState.Done); SourceForm_SizeChanged(this, null); Text += " - " + System.IO.Path.GetFileName(Filename); // load, validate and update file data rtb.LoadFile(Filename, RichTextBoxStreamType.PlainText); if (src.LineCount == 0) // new files loaded the first time { src.LineCount = rtb.Lines.Length; } else if (src.LineCount != rtb.Lines.Length) // file changed? { DialogResult result = MessageBox.Show("The source file has changed in the meantime:" + Environment.NewLine + "\"" + Filename + "\"" + Environment.NewLine + "Do you want to continue working on the changed file?" + Environment.NewLine + "OK = Accept new file (saved data may not match with new file)" + Environment.NewLine + "Cancel = Abort loading the file", "Warning!", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); if (result != DialogResult.OK) { throw new Exception(); } if (rtb.Lines.Length < src.LineCount) // lines were removed? { src.LineCount = rtb.Lines.Length; // cut length // Remove cut off blocks from list BlockState DummyBlock = new BlockState(); DummyBlock.Line = 0; DummyBlock.Len = 0; DummyBlock.State = LineState.Unknown;; InsertBlockState(DummyBlock); } else { src.LineCount = rtb.Lines.Length; // increase length } } // Load block data into rich text box.. foreach (BlockState block in src.Blocks) { int LineStart = block.Line; int LineEnd = block.Line + block.Len - 1; int SelectionStart = rtb.GetFirstCharIndexFromLine(LineStart); int SelectionLength = rtb.GetFirstCharIndexFromLine(LineEnd) + rtb.Lines[LineEnd].Length - SelectionStart; rtb.Select(SelectionStart, SelectionLength); rtb.SelectionBackColor = ConvertLineStateToColor(block.State); } rtb.Select(0, 0); statusbar.Text = "File \"" + Filename + "\" loaded!"; }