private void saveToolStripMenuItem_Click(object sender, EventArgs e) { if (OpenedFileName == null) { return; } try { using (var stream = new FileStream(OpenedFileName, FileMode.Open)) { JsonEditorItem.Save(stream); } } catch { MessageBox.Show(this, string.Format("An error occured when saving file as \"{0}\".", OpenedFileName), @"Save As..."); OpenedFileName = null; SetActionStatus(@"Document NOT saved.", true); return; } SetActionStatus(@"Document successfully saved.", false); }
private void buttonOk_Click(object sender, EventArgs e) { if (OpenedFileName == null) { DialogResult = DialogResult.Cancel; return; } DialogResult response = DialogResult.Yes; if (!validJSon) { response = MessageBox.Show(this, "This wizard is incorrect. Do you really want to save it ?", "Warning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2); } if (response == DialogResult.Yes) { try { using (var stream = new FileStream(OpenedFileName, FileMode.Truncate)) { JsonEditorItem.Save(stream); } SetActionStatus(@"Wizard successfully saved.", false); string json = File.ReadAllText(OpenedFileName); if (json != originalJson) { DialogResult = DialogResult.OK; } else { DialogResult = DialogResult.Cancel; } } catch { MessageBox.Show(this, $"An error occured when saving file as \"{OpenedFileName}\".", @"Save As..."); OpenedFileName = null; SetActionStatus(@"Wizard NOT saved.", true); DialogResult = DialogResult.Cancel; } } else { DialogResult = DialogResult.Cancel; } }
private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) { var saveFileDialog = new SaveFileDialog { Filter = DefaultFileFilters, FilterIndex = 1, RestoreDirectory = true }; if (saveFileDialog.ShowDialog() != DialogResult.OK) { return; } try { OpenedFileName = saveFileDialog.FileName; using (var stream = saveFileDialog.OpenFile()) { if (stream.CanWrite) { JsonEditorItem.Save(stream); } } } catch { MessageBox.Show(this, string.Format("An error occured when saving file as \"{0}\".", OpenedFileName), @"Save As..."); OpenedFileName = null; SetActionStatus(@"Document NOT saved.", true); return; } SetActionStatus(@"Document successfully saved.", false); }
/// <summary> /// Saves the content of the view in a json stream. /// </summary> /// <param name="stream"></param> public void SaveJson(Stream stream) { JsonEditorItem.Save(stream); }
public void GetJson(out string str) => JsonEditorItem.Save(out str);