public void RaiseCanSaveEvent(bool cansave) { //CanSave?.Invoke(!hasdupcomment); CanSaveEventArgs e = new CanSaveEventArgs { CanSave = cansave }; CanSave?.Invoke(this, e); }
bool save(bool askFirst = false) //returns true if a choice is made { if (tabs.SelectedIndex == 1) { toRawText(); } var t = ((EnumItem <EVT>)category.SelectedItem).value; var n = name.Text; var e = chkExpand.Checked; var v = chkShowExp.Checked ? original : text.Text; if (value != null ? (value.Target == t && value.Name == n && (value.Expandable == null || value.Expandable == e) && value.Value == v) : (t == NEW_INDEX && n == NEW_NAME && !e && v.Length == 0)) { Saved?.Invoke(this, false); return(true); } DialogResult r; if (askFirst) { r = MessageBox.Show( "This value has been modified. Save the changes?", Program.NAME, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning ); if (r != DialogResult.Yes) { return(r == DialogResult.No); } } string err = ""; bool? canSave = CanSave?.Invoke(this, t, n, out err); if (canSave == null) { r = MessageBox.Show( "Before-save check not assigned! Save anyways?", Program.NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Warning); } else if (!canSave.Value) { r = MessageBox.Show( err + ". Save anyways?", Program.NAME, MessageBoxButtons.OKCancel, MessageBoxIcon.Error); } else { r = DialogResult.OK; } if (r != DialogResult.OK) { return(false); } value = value ?? new EnvValue(); Tag = value; value.Target = t; value.Name = n; value.Expandable = e; value.Value = v; setTitle(); showProblem(); value.Changed = true; Saved?.Invoke(this, true); return(true); }