public bool ApplyChanges(bool ask = false) { if (ask) { var msg = MessageBox.Show("Apply changes to synonyms?", "SteelQuiz", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (msg == DialogResult.No) { return(false); } } if (txt_synonymAdd.Text != "" && !lst_synonyms.Items.Contains(txt_synonymAdd.Text)) { var msg = MessageBox.Show("Warning! The textbox contains text not added to the list. Add it to the list before applying?", "SteelQuiz", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning); if (msg == DialogResult.Yes) { if (!AddSynonym()) { return(false); } } else if (msg == DialogResult.Cancel) { return(false); } } var oldSynonyms = Synonyms.Clone().ToList(); var newSynonyms = lst_synonyms.Items.OfType <string>().ToList(); QuizEditor.UndoStack.Push(new UndoRedoActionPair( new Action[] { () => { Synonyms = oldSynonyms; } }, new Action[] { () => { Synonyms = newSynonyms; } }, "Change Synonyms", new OwnerControlData(this, QuizEditor))); QuizEditor.ChangedSinceLastSave = true; QuizEditor.UpdateUndoRedoTooltips(); Synonyms = newSynonyms; // update last saved state initialListBoxCollection = new object[lst_synonyms.Items.Count]; lst_synonyms.Items.CopyTo(initialListBoxCollection, 0); return(true); }