public void ShowSaveDialog(EditForm ef) { dlgSave.FileName = ef.Doc.Path; if (dlgSave.ShowDialog(this) == DialogResult.OK) { string f = dlgSave.FileName; ef.SaveAs(f); } }
private void mnuFile_Open_Click(object sender, EventArgs e) { //create a filter for the open dialog //add a *.* pattern to the filter string filter = "All Files(*.*)|*.*"; //get all filetypes from our syntax list. foreach (SyntaxDefinition l in Languages.GetSyntaxDefinitions()) foreach (FileType ft in l.FileTypes) //add the filetype to the filter filter += "|" + ft.Name + "(*" + ft.Extension + ")|*" + ft.Extension; //apply the filter to the dialog dlgOpen.Filter = filter; //Show the open dialog dlgOpen.Title = "Select a file to open"; DialogResult res = dlgOpen.ShowDialog(this); //Bail out if cancel was pressed or no file was selected. if (res != DialogResult.OK || dlgOpen.FileName == "") return; //load the file string FileName = dlgOpen.FileName; var sr = new StreamReader(FileName, Encoding.Default); //read the content into the "text" variable string text = sr.ReadToEnd(); //create a new document var doc = new Document {Path = FileName}; var fi = new FileInfo(FileName); doc.Title = fi.Name; doc.Text = text; SyntaxDefinition syntax = Languages.GetLanguageFromFile(doc.Path); var ef = new EditForm(doc, syntax) {MdiParent = this}; ef.Show(); }
private void OK() { if (lvFileTypes.SelectedItems.Count == 0) { lvFileTypes.Items[0].Selected = true; } var syntax = (SyntaxDefinition) trvFileTypes.SelectedNode.Tag; var ft = (FileType) lvFileTypes.SelectedItems[0].Tag; var doc = new Document {Title = ("Untitled" + ft.Extension), Text = ""}; var ef = new EditForm(doc, syntax); EditForm = ef; DialogResult = DialogResult.OK; Close(); }