public void SetsNewValue() { var action = new ActionUndo(this, () => MockModel.Change("previousValue"), () => MockModel.Change("nextValue")); action.Redo(); Assert.AreEqual("nextValue", MockModel.Name); }
public bool DoUndo() { if (undoActions.Count == 0) { return(false); } //remove from undo list Action action = undoActions[undoActions.Count - 1]; undoActions.RemoveAt(undoActions.Count - 1); //do undo action.DoUndo(); ActionUndo?.Invoke(action); //add to redo list if (redoActions.Count + 1 >= maxLevel) { redoActions[0].Destroy(); ActionDestroy?.Invoke(redoActions[0]); redoActions.RemoveAt(0); } redoActions.Add(action); ListOfActionsChanged?.Invoke(this, EventArgs.Empty); return(true); }
public void CallActions() { var value = false; var mementoService = new MementoService(); var action = new ActionUndo(this, () => value = true, () => value = false); mementoService.Add(action); Assert.IsFalse(value); mementoService.Undo(); Assert.IsTrue(value); mementoService.Redo(); Assert.IsFalse(value); }
/// <summary> /// Processes the command key. /// </summary> /// <seealso cref="M:System.Windows.Forms.Form.ProcessCmdKey(Message@,Keys)"/> protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (Globals.IsReady) { switch (keyData) { // Top menu system case Keys.Alt | Keys.S: ActionSettings.ShowDropDown(); return(true); case Keys.Alt | Keys.I: ActionInformation.ShowDropDown(); return(true); case Keys.F9: ActionPreferences.PerformClick(); return(true); case Keys.Alt | Keys.Control | Keys.F4: ActionExit.PerformClick(); return(true); case Keys.Escape: if (!EditESCtoExit.Checked || EditMeanings.IsCurrentCellInEditMode) { break; } ActionExit.PerformClick(); return(true); // Rotate view case Keys.Control | Keys.Shift | Keys.Tab: if (Globals.AllowClose) { SetView(Settings.CurrentView.Previous(ViewMode.Notebook));// TODO notebook remove when ready } return(true); case Keys.Control | Keys.Tab: if (Globals.AllowClose) { SetView(Settings.CurrentView.Next(ViewMode.Notebook));// TODO notebook remove when ready } return(true); // Change view case Keys.F1: ActionViewAnalysis.PerformClick(); return(true); case Keys.F2: ActionViewLetters.PerformClick(); return(true); case Keys.F3: if (!Globals.IsDebugExecutable) { break; // TODO remove when ready } ActionViewNotebook.PerformClick(); return(true); // Application functions case Keys.F5: case Keys.Control | Keys.F: ActionSearchTerm.PerformClick(); return(true); case Keys.Control | Keys.N: ActionNewInstance.PerformClick(); return(true); // Top menu system case Keys.Alt | Keys.T: ActionTools.ShowDropDown(); return(true); case Keys.Alt | Keys.L: if (ActionWebLinks.Enabled) { ActionWebLinks.ShowDropDown(); } return(true); // Data edition case Keys.Control | Keys.S: ActionSave.PerformClick(); return(true); case Keys.Control | Keys.Back: ActionUndo.Focus(); ActionUndo.PerformClick(); return(true); } } // Letters navigation if (Globals.AllowClose && Settings.CurrentView == ViewMode.Letters) { switch (keyData) { case Keys.Control | Keys.Home: LettersNavigator.ActionFirst.PerformClick(); return(true); case Keys.Control | Keys.End: LettersNavigator.ActionLast.PerformClick(); return(true); case Keys.Control | Keys.PageUp: LettersNavigator.ActionPrevious.PerformClick(); return(true); case Keys.Control | Keys.PageDown: LettersNavigator.ActionNext.PerformClick(); return(true); } } return(base.ProcessCmdKey(ref msg, keyData)); }