public void ButtonClickEventHandlerUndoRedo() { DesignItem button = CreateCanvasContext("<Button/>"); UndoService s = button.Context.Services.GetService <UndoService>(); Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); button.Properties["Click"].SetValue("OnClick"); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Click=""OnClick"" />", button.Context); button.Properties["Click"].SetValue("OnClick2"); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Click=""OnClick2"" />", button.Context); s.Undo(); Assert.IsTrue(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Click=""OnClick"" />", button.Context); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(@"<Button />", button.Context); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Click=""OnClick"" />", button.Context); AssertLog(""); }
public void UndoRedoChangeGroupTest() { DesignItem button = CreateCanvasContext("<Button/>"); UndoService s = button.Context.Services.GetService <UndoService>(); Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); using (ChangeGroup g = button.OpenGroup("Resize")) { button.Properties["Width"].SetValue(100.0); button.Properties["Height"].SetValue(200.0); g.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Width=""100"" Height=""200"" />", button.Context); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(@"<Button />", button.Context); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Width=""100"" Height=""200"" />", button.Context); AssertLog(""); }
private void Redo() { var state = _undoService.Redo(); //Apply the state ApplyState(state); }
public void Redo() { UndoService undoService = GetService <UndoService>(); IUndoAction action = undoService.RedoActions.First(); Debug.WriteLine("Redo " + action.Title); undoService.Redo(); _designContext.Services.Selection.SetSelectedComponents(GetLiveElements(action.AffectedElements)); }
public void UndoRedoInputBindings() { const string originalXaml = "<TextBlock Text=\"My text\" />"; DesignItem textBlock = CreateCanvasContext(originalXaml); UndoService s = textBlock.Context.Services.GetService <UndoService>(); IComponentService component = textBlock.Context.Services.Component; Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); DesignItemProperty inputbinding = textBlock.Properties["InputBindings"]; Assert.IsTrue(inputbinding.IsCollection); const string expectedXaml = @"<TextBlock Text=""My text""> <TextBlock.InputBindings> <MouseBinding Gesture=""LeftDoubleClick"" Command=""ApplicationCommands.New"" /> </TextBlock.InputBindings> </TextBlock>"; using (ChangeGroup changeGroup = textBlock.Context.OpenGroup("", new[] { textBlock })) { DesignItem di = component.RegisterComponentForDesigner(new System.Windows.Input.MouseBinding()); di.Properties["Gesture"].SetValue(System.Windows.Input.MouseAction.LeftDoubleClick); di.Properties["Command"].SetValue("ApplicationCommands.New"); inputbinding.CollectionElements.Add(di); changeGroup.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); inputbinding = textBlock.Properties["InputBindings"]; Assert.IsTrue(((System.Windows.Input.InputBindingCollection)inputbinding.ValueOnInstance).Count == inputbinding.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(originalXaml, textBlock.Context); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); Assert.IsTrue(((System.Windows.Input.InputBindingCollection)inputbinding.ValueOnInstance).Count == inputbinding.CollectionElements.Count); AssertLog(""); }
public void NoEventHandlerTest() { _statefulInt = 1; _individualUndoService.RecordState(); _statefulInt = 2; _individualUndoService.RecordState(); _individualUndoService.Undo(); Assert.IsTrue(_statefulInt == 1); _individualUndoService.Redo(); Assert.IsTrue(_statefulInt == 2); }
public void IsChangedTest() { var trackedObject = new StatefulClass { TheString = "One", TheInt = 1 }; var undoService = new UndoService <StatefulClassDto>(trackedObject.GetData, trackedObject.SetData, null); Assert.IsTrue(!undoService.IsStateChanged); trackedObject.TheString = "Two"; undoService.RecordState(); Assert.IsTrue(undoService.IsStateChanged); undoService.Undo(); Assert.IsTrue(!undoService.IsStateChanged); undoService.Redo(); Assert.IsTrue(undoService.IsStateChanged); undoService.ClearIsStateChangedFlag(); Assert.IsTrue(!undoService.IsStateChanged); undoService.Undo(); Assert.IsTrue(undoService.IsStateChanged); undoService.Redo(); Assert.IsTrue(!undoService.IsStateChanged); }
public void UndoRedoTest() { var undoServiceForString = new UndoService <string>(GetStringState, SetStringState, null); _statefulString = "One"; undoServiceForString.RecordState(); _statefulString = "Two"; undoServiceForString.RecordState(); undoServiceForString.Undo(); Assert.IsTrue(_statefulString.Equals("One")); undoServiceForString.Redo(); Assert.IsTrue(_statefulString.Equals("Two")); }
public void UndoRedoTest() { _statefulInt = 1; _undoServiceForInt.RecordState(); _statefulInt = 2; _undoServiceForInt.RecordState(); _undoServiceForInt.Undo(); Assert.IsTrue(_statefulInt == 1); _undoServiceForInt.Redo(); Assert.IsTrue(_statefulInt == 2); }
public void UndoRedoTest() { DesignItem button = CreateCanvasContext("<Button/>"); UndoService s = button.Context.Services.GetService <UndoService>(); Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); button.Properties["Width"].SetValue(100.0); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Width=""100"" />", button.Context); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(@"<Button />", button.Context); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(@"<Button Width=""100"" />", button.Context); AssertLog(""); }
public static void UndoService_DoUndoRedoTest() { var undoService = new UndoService(); var value = -1; for (var i = 0; i < 10; i++) { var command = new UndoCommand(() => value++, () => value--); undoService.Do(command); Assert.AreEqual(i, value); } Assert.True(undoService.CanUndo); Assert.False(undoService.CanRedo); var undoValue = value; while (undoService.CanUndo) { undoService.Undo(); Assert.AreEqual(--undoValue, value); } Assert.False(undoService.CanUndo); Assert.True(undoService.CanRedo); var redoValue = value; while (undoService.CanRedo) { undoService.Redo(); Assert.AreEqual(++redoValue, value); } Assert.True(undoService.CanUndo); Assert.False(undoService.CanRedo); }
void UndoRedoInputBindingsRemoveClearResetInternal(bool remove, bool clear, bool reset) { const string originalXaml = "<TextBlock Text=\"My text\" />"; DesignItem textBlock = CreateCanvasContext(originalXaml); UndoService s = textBlock.Context.Services.GetService <UndoService>(); IComponentService component = textBlock.Context.Services.Component; Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); DesignItemProperty inputbinding = textBlock.Properties["InputBindings"]; Assert.IsTrue(inputbinding.IsCollection); const string expectedXaml = @"<TextBlock Text=""My text"" Cursor=""Hand""> <TextBlock.InputBindings> <MouseBinding Gesture=""LeftDoubleClick"" Command=""ApplicationCommands.New"" /> </TextBlock.InputBindings> </TextBlock>"; using (ChangeGroup changeGroup = textBlock.Context.OpenGroup("", new[] { textBlock })) { DesignItem di = component.RegisterComponentForDesigner(new System.Windows.Input.MouseBinding()); di.Properties["Gesture"].SetValue(System.Windows.Input.MouseAction.LeftDoubleClick); di.Properties["Command"].SetValue("ApplicationCommands.New"); inputbinding.CollectionElements.Add(di); textBlock.Properties["Cursor"].SetValue(System.Windows.Input.Cursors.Hand); changeGroup.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); using (ChangeGroup changeGroup = textBlock.Context.OpenGroup("", new[] { textBlock })) { DesignItem di = inputbinding.CollectionElements.First(); // Remove, Clear, Reset combination caused exception at first Undo after this group commit before the issue was fixed if (remove) { inputbinding.CollectionElements.Remove(di); } if (clear) { inputbinding.CollectionElements.Clear(); } if (reset) { inputbinding.Reset(); } di = component.RegisterComponentForDesigner(new System.Windows.Input.MouseBinding()); di.Properties["Gesture"].SetValue(System.Windows.Input.MouseAction.LeftDoubleClick); di.Properties["Command"].SetValue("ApplicationCommands.New"); inputbinding.CollectionElements.Add(di); textBlock.Properties["Cursor"].SetValue(System.Windows.Input.Cursors.Hand); changeGroup.Commit(); } s.Undo(); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(originalXaml, textBlock.Context); s.Redo(); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXaml, textBlock.Context); Assert.IsTrue(((System.Windows.Input.InputBindingCollection)inputbinding.ValueOnInstance).Count == inputbinding.CollectionElements.Count); AssertLog(""); }
void UndoRedoDictionaryInternal(bool useExplicitDictionary) { const string originalXaml = "<Button />"; DesignItem button = CreateCanvasContext(originalXaml); UndoService s = button.Context.Services.GetService <UndoService>(); IComponentService component = button.Context.Services.Component; string expectedXamlWithDictionary; DesignItemProperty dictionaryProp; Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); using (ChangeGroup g = button.OpenGroup("UndoRedoDictionaryInternal test")) { DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer()); dictionaryProp = containerItem.Properties["Dictionary"]; if (useExplicitDictionary) { dictionaryProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary()); expectedXamlWithDictionary = @"<Button> <Button.Tag> <Controls0:ExampleClassContainer> <Controls0:ExampleClassContainer.Dictionary> <Controls0:ExampleClassDictionary> <Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" /> </Controls0:ExampleClassDictionary> </Controls0:ExampleClassContainer.Dictionary> </Controls0:ExampleClassContainer> </Button.Tag> </Button>"; } else { expectedXamlWithDictionary = @"<Button> <Button.Tag> <Controls0:ExampleClassContainer> <Controls0:ExampleClassContainer.Dictionary> <Controls0:ExampleClass x:Key=""testKey"" StringProp=""String value"" /> </Controls0:ExampleClassContainer.Dictionary> </Controls0:ExampleClassContainer> </Button.Tag> </Button>"; } DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); exampleClassItem.Key = "testKey"; exampleClassItem.Properties["StringProp"].SetValue("String value"); dictionaryProp.CollectionElements.Add(exampleClassItem); button.Properties["Tag"].SetValue(containerItem); g.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput(originalXaml, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithDictionary, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); dictionaryProp = button.Properties["Tag"].Value.Properties["Dictionary"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassDictionary)dictionaryProp.ValueOnInstance).Count == dictionaryProp.CollectionElements.Count); AssertLog(""); }
void UndoRedoListInternal(bool useExplicitList) { DesignItem button = CreateCanvasContext("<Button/>"); UndoService s = button.Context.Services.GetService <UndoService>(); IComponentService component = button.Context.Services.Component; string expectedXamlWithList; DesignItemProperty otherListProp; Assert.IsFalse(s.CanUndo); Assert.IsFalse(s.CanRedo); using (ChangeGroup g = button.OpenGroup("UndoRedoListInternal test")) { DesignItem containerItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassContainer()); otherListProp = containerItem.Properties["OtherList"]; if (useExplicitList) { otherListProp.SetValue(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList()); expectedXamlWithList = @"<Button> <Button.Tag> <Controls0:ExampleClassContainer> <Controls0:ExampleClassContainer.OtherList> <Controls0:ExampleClassList> <Controls0:ExampleClass StringProp=""String value"" /> </Controls0:ExampleClassList> </Controls0:ExampleClassContainer.OtherList> </Controls0:ExampleClassContainer> </Button.Tag> </Button>"; } else { expectedXamlWithList = @"<Button> <Button.Tag> <Controls0:ExampleClassContainer> <Controls0:ExampleClassContainer.OtherList> <Controls0:ExampleClass StringProp=""String value"" /> </Controls0:ExampleClassContainer.OtherList> </Controls0:ExampleClassContainer> </Button.Tag> </Button>"; } DesignItem exampleClassItem = component.RegisterComponentForDesigner(new ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClass()); exampleClassItem.Properties["StringProp"].SetValue("String value"); otherListProp.CollectionElements.Add(exampleClassItem); button.Properties["Tag"].SetValue(containerItem); g.Commit(); } Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); otherListProp = button.Properties["Tag"].Value.Properties["OtherList"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count); s.Undo(); Assert.IsFalse(s.CanUndo); Assert.IsTrue(s.CanRedo); AssertCanvasDesignerOutput("<Button>\n</Button>", button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); s.Redo(); Assert.IsTrue(s.CanUndo); Assert.IsFalse(s.CanRedo); AssertCanvasDesignerOutput(expectedXamlWithList, button.Context, "xmlns:Controls0=\"" + ICSharpCode.WpfDesign.Tests.XamlDom.XamlTypeFinderTests.XamlDomTestsNamespace + "\""); otherListProp = button.Properties["Tag"].Value.Properties["OtherList"]; Assert.IsTrue(((ICSharpCode.WpfDesign.Tests.XamlDom.ExampleClassList)otherListProp.ValueOnInstance).Count == otherListProp.CollectionElements.Count); AssertLog(""); }
public CanvasContextMenu(MessageControl messageControl) { if (!DesignMode) { _messageControl = messageControl; onBringToFront = delegate { _messageControl.MoveFirst(); }; onSendToBack = delegate { _messageControl.MoveLast(); }; onSetBackground = delegate { _messageControl.SetBackground(true); }; onCancelBackground = delegate { _messageControl.SetBackground(false); }; onCopy = delegate { if (CopyAction.Current != null) { CopyAction.Current.Copy(); } }; onPaste = delegate { if (CopyAction.Current != null) { CopyAction.Current.Paste(); } }; onUndo = delegate { UndoService.Undo(); }; onRedo = delegate { UndoService.Redo(); }; onDelete = delegate { if (_messageControl.SelectedLayers.Count < 0) { return; } if (_messageControl.SelectedLayers.Count == 1) { string msg = _messageControl.SelectedLayers[0].Shape.Type.ToString().ToLower();//.Replace("shape", "picture"); if (msg == ShapeType.ShapeDraw.ToString().ToLower()) { msg = "shape"; } if (MsgBox.Confirm("Are you sure you want to delete this " + msg + "?") != DialogResult.Yes) { return; } } else { if (MsgBox.Confirm("Are you sure you want to delete these " + _messageControl.SelectedLayers.Count.ToString() + " items?") != DialogResult.Yes) { return; } } _messageControl.RemoveLayer(); }; onProperties = (s, e) => { WindowManager.ShowPanel(Docks.Properties); }; onNailImage = delegate { try { IOHelper.RemoveFile(messageControl.Model.ImagePath); } catch { } _messageControl.GenerateNailImageNoWaitCursor(); LocalMessageBus.Send(this, new PWMessage <MenuCommands>(MenuCommands.Save)); };//.SetCreateNailImageTime(); }; //onSnap = delegate //{ // _messageControl.SnapAllLayers(); //}; onFitToSign = delegate { _messageControl.ShapeControl.FitToSign(); }; mnuBringToFront = AddMenuItem("Bring to Front", Resource.Images.BringToFront, onBringToFront); //mnuBackground.ShortcutKeys = Keys.F; mnuSendToBack = AddMenuItem("Send to Back", Resource.Images.SendToBack, onSendToBack); mnuBackground = AddMenuItem("Set Background", Resource.Images.SetBackground, onSetBackground); mnuCancelBackground = AddMenuItem("Cancel Background", Resource.Images.CancelBackground, onCancelBackground); AddSeparator(); mnuCopy = AddMenuItem("Copy", Resource.Images.Copy16, onCopy); mnuPaste = AddMenuItem("Paste", Resource.Images.Paste16, onPaste); mnuDelete = AddMenuItem("Delete", Resource.Images.Delete16, onDelete); //mnuUndo = AddMenuItem("Undo", Resource.Images.Undo16, onUndo); //mnuRedo = AddMenuItem("Redo", Resource.Images.Redo16, onRedo); AddSeparator(); mnuProperties = AddMenuItem("Properties", Resource.Images.Properties16, onProperties); AddSeparator(); mnuNailImage = AddMenuItem("Set Thumbnail Image", Resource.Images.GeneraleNailImage, onNailImage); AddSeparator(); //mnuSnap = AddMenuItem("Snap All Layers", Resource.Images.SnapAllLayers, onSnap); mnuOpenShowAllLayers = AddMenuItem("Show All Layers", Resource.Images.ShowAllLayers, delegate { _messageControl.IsShowAllLayers = true; _messageControl.UpdateShapeVisible(); mnuOpenShowAllLayers.Enabled = false; mnuCloseShowAllLayers.Enabled = true; }); mnuCloseShowAllLayers = AddMenuItem("Close Show All Layers", Resource.Images.CloseShowAllLayers, delegate { _messageControl.IsShowAllLayers = false; _messageControl.UpdateShapeVisible(); mnuOpenShowAllLayers.Enabled = true; mnuCloseShowAllLayers.Enabled = false; }); AddSeparator(); mnuFitToSign = AddMenuItem("Fit to Sign", Resource.Images.FitToSign, onFitToSign); //mnuShowAllLayers = AddMenuItem("&Show all layers", Resource.Images.ShowAllLayers, onShowAllLayers); //mnuBringToFront.ShowShortcutKeys = false; //mnuSendToBack.ShowShortcutKeys = false; //mnuCopy.ShowShortcutKeys = false; //mnuPaste.ShowShortcutKeys = false; //mnuUndo.ShowShortcutKeys = false; //mnuRedo.ShowShortcutKeys = false; //mnuDelete.ShowShortcutKeys = false; //mnuProperties.ShowShortcutKeys = false; //mnuNailImage.ShowShortcutKeys = false; //mnuSnap.ShowShortcutKeys = false; //mnuOpenShowAllLayers.ShowShortcutKeys = false; //mnuCloseShowAllLayers.ShowShortcutKeys = false; //mnuFitToSign.ShowShortcutKeys = false; //mnuBackground.ShowShortcutKeys = false; //mnuCancelBackground.ShowShortcutKeys = false; } }
/// <summary> /// Redo the last action /// </summary> public void RedoAction() { _undoService.Redo(); }