/// <summary> /// Returns true if the file was saved or false if canceled by the user (which can happen /// if this file falls back to "Save as") /// </summary> bool Save(NimEditor ed) { if (ed == null) { return(true); } if (!File.Exists(ed.FileName)) { return(SaveAs(ed)); } try { ed.SaveToFile(ed.FileName, Encoding.UTF8); ed.Modified = false; } catch (Exception exc) { MessageBox.Show(exc.Message); throw; } return(true); }
/// <summary> /// Returns true if the file was saved or false if canceled by the user. /// </summary> bool SaveAs(NimEditor ed) { if (ed == null) { return(true); } if (!string.IsNullOrWhiteSpace(ed.FileName)) { string dir = Path.GetDirectoryName(ed.FileName); string fn = Path.GetFileName(ed.FileName); if (Directory.Exists(dir)) { saveDialog.InitialDirectory = dir; } saveDialog.FileName = Path.GetFileName(ed.FileName); } if (saveDialog.ShowDialog() == DialogResult.OK) { try { ed.SaveToFile(saveDialog.FileName, Encoding.UTF8); ed.FileName = saveDialog.FileName; ed.Modified = true; //ste to true+false to force uodate of filename in tab even if modified was not changed ed.Modified = false; return(true); } catch (Exception exc) { MessageBox.Show(exc.Message); throw; } } return(false); }