//autofac uses this public EditingView(EditingModel model, PageListView pageListView, TemplatePagesView templatePagesView, CutCommand cutCommand, CopyCommand copyCommand, PasteCommand pasteCommand, UndoCommand undoCommand, DeletePageCommand deletePageCommand) { _model = model; _pageListView = pageListView; _templatePagesView = templatePagesView; _cutCommand = cutCommand; _copyCommand = copyCommand; _pasteCommand = pasteCommand; _undoCommand = undoCommand; _deletePageCommand = deletePageCommand; InitializeComponent(); _splitContainer1.Tag = _splitContainer1.SplitterDistance;//save it //don't let it grow automatically // _splitContainer1.SplitterMoved+= ((object sender, SplitterEventArgs e) => _splitContainer1.SplitterDistance = (int)_splitContainer1.Tag); SetupThumnailLists(); _model.SetView(this); _browser1.SetEditingCommands(cutCommand, copyCommand,pasteCommand, undoCommand); _browser1.GeckoReady+=new EventHandler(OnGeckoReady); _menusToolStrip.Renderer = new FixedToolStripRenderer(); //we're giving it to the parent control through the TopBarControls property Controls.Remove(_topBarPanel); }
public override void Execute(object parameter) { UndoCommand undoCommand = new UndoCommand(Current.Controller); undoCommand.Execute(); OnCanExecuteChanged(null); }
public static void Behavioral_CommandDemo2() { //var videoEditor = new VideoEditor(); //videoEditor.SetText("demo2 video text"); //videoEditor.SetContrast(0.7f); //var result = videoEditor.ToString(); //Console.WriteLine(result); var videoEditor = new VideoEditor(); var history = new Command.Demo2.History(); var setTextCommand = new SetTextCommand("Video Title", videoEditor, history); setTextCommand.Execute(); Console.WriteLine("TEXT: " + videoEditor); var setContrast = new SetContrastCommand(1, videoEditor, history); setContrast.Execute(); Console.WriteLine("CONTRAST: " + videoEditor); var undoCommand = new UndoCommand(history); undoCommand.Execute(); Console.WriteLine("UNDO: " + videoEditor); undoCommand.Execute(); Console.WriteLine("UNDO: " + videoEditor); undoCommand.Execute(); Console.WriteLine("UNDO: " + videoEditor); }
private void CommitNewText(string oldText, string newText) { if (this.IsFileName && !FileHelper.IsValidFileName(newText)) { this._dialogService.ShowWarningMessageBox("Invalid File Name", $"'{newText}' contains invalid characters."); } else { if (this.TextChangedCommand?.CanExecute(newText) == true) { this.TextChangedCommand.Execute(newText); } if (this.ShouldSetTextAutomatically) { if (this.AllowUndo) { var undoCommand = new UndoCommand(() => { this.SetText(newText); }, () => { this.SetText(oldText); }); this._undoService.Do(undoCommand); } else { this.SetText(newText); } } } this.IsEditing = false; }
public void Add(UndoCommand command, Part device) { if (device != null) { UndoCommands.Push(new UndoInfo(command, device)); } }
public void Do(UndoCommand undoCommand) { undoCommand.Do(); this._undoStack.Push(undoCommand); this._redoStack.Clear(); this.RaiseProperties(); }
public void CallsUndoWhenUndoCommand() { UndoCommand undoCommand = new UndoCommand(); _controllerFixture.Controller.Execute(undoCommand); _controllerFixture.Undo.Verify(x => x.Execute(It.IsAny <string>()), Times.Once); }
public void ChangeAssetParent(Asset assetToMove, FolderAsset newParent) { if (newParent == null) { throw new ArgumentNullException(nameof(newParent)); } if (this.ValidateNewParent(assetToMove, newParent, out var newName)) { var originalName = assetToMove.Name; var originalPath = assetToMove.GetPath(); var originalParent = assetToMove.Parent; var newPath = originalPath; var undoCommand = new UndoCommand(() => { assetToMove.Name = newName; assetToMove.Parent = newParent; newPath = assetToMove.GetPath(); this.MoveAsset(assetToMove, originalPath); }, () => { assetToMove.Name = originalName; assetToMove.Parent = originalParent; this.MoveAsset(assetToMove, newPath); }); this._undoService.Do(undoCommand); } }
public Command(DoCommand doCommand, UndoCommand undoCommand, object doData, string name) { this.doCommand = doCommand; this.undoCommand = undoCommand; this.doData = doData; this.name = name; }
static void TestUndoableCommand() { var history = new Command.Editor.History(); var document = new Command.Editor.HtmlDocument(); document.Content = "Hello World"; var boldCommand = new BoldCommand(document, history); boldCommand.Execute(); System.Console.WriteLine(document.Content); document.Content = "This is Command Pattern"; boldCommand = new BoldCommand(document, history); boldCommand.Execute(); System.Console.WriteLine(document.Content); var undoCommand = new UndoCommand(history); undoCommand.Execute(); System.Console.WriteLine(document.Content); undoCommand.Execute(); System.Console.WriteLine(document.Content); }
public MainWindowViewModel() { #region starting view content logHandler = LogHandler.Instance; logHandler.MainWindowViewModel = this; ContentHandler.StartContent(); Refresh(); #endregion #region Commands AddUserCommand = new AddUserCommand(this); ViewProfilInfoCommand = new ViewProfilInfoCommand(this); AddTelephoneCommand = new AddTelephoneCommand(this); AddShopCommand = new AddShopCommand(this); ChangeTelephoneCommand = new ChangeTelephoneInfoCommand(this); DeleteTelephoneCommand = new DeleteTelephoneCommand(this); DuplicateTelephoneCommand = new DuplicateTelephoneCommand(this); ChangeShopCommand = new ChangeShopInfoCommand(this); DeleteShopCommand = new DeleteShopCommand(this); LogOutCommand = new LogOutCommand(this); BuyTelephoneCommand = new BuyTelephoneCommand(this); ClearCommand = new ClearCommand(this); UndoCommand = new UndoCommand(this); RedoCommand = new RedoCommand(this); FilterCommand = new FilterCommand(this); RefreshCommand = new RefreshCommand(this); #endregion }
private static void UndoableCommandPattern() { var document = new Document { Content = "Some content" }; Console.WriteLine("Before"); Console.WriteLine(document.Content); var history = new CommandHistory(); var boldCommand = new BoldCommand(document, history); var button = new Button(boldCommand); button.Click(); Console.WriteLine("After"); Console.WriteLine(document.Content); Console.WriteLine("After Undo"); var undoCommand = new UndoCommand(history); undoCommand.Execute(); Console.WriteLine(document.Content); }
/// <summary> /// Allows decouple a sender from a receiver. The sender will talk to the receive through a command. Commands can be undone and persisted. /// /// With Command its easy to build an independent framework that anyone can use. By creating a custom service which implements a base interface, /// any command can be run with the same method, depending on the service. /// </summary> static void Command() { // One command attached to an action. var service = new CustomerService(); var command = new AddCustomerCommand(service); var button = new Command.fx.Button(command); button.Click(); // Multiple commands attached to an action. var composite = new CompositeCommand(); composite.Add(new ResizeCommand()); composite.Add(new BlackAndWhiteCommand()); composite.Execute(); // Using the undo mechanism. Multiple commands are implementing the same interface(s) and using the same history. var history = new Command.editor.History(); var document = new Command.editor.HtmlDocument(); document.Content = "Hello"; var boldCommand = new BoldCommand(document, history); boldCommand.Execute(); Console.WriteLine(document.Content); var undoCommant = new UndoCommand(history); undoCommant.Execute(); Console.WriteLine(document.Content); }
private void LeaseBook() { Action redo = () => { SelectedBook.LeasedTo = Session.Current.LoggedInUser; LeaseCommand.RaiseCanExecuteChanged(); OnPropertyChanged("SelectedBook"); BookList.Refresh(); }; Action undo = () => { SelectedBook.LeasedTo = string.Empty; LeaseCommand.RaiseCanExecuteChanged(); OnPropertyChanged("SelectedBook"); BookList.Refresh(); }; history.AddAndExecute(new RevertableCommand(redo, undo)); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); ClientLogger.Log($"{Session.Current.LoggedInUser} leased book {selectedBook.BookName}", Common.LogLevel.Info); }
public void CanUndoWithHistoryWithoutRollBack() { var history = new Mock<ITimeline>(); { history.Setup(h => h.CanRollBack) .Returns(false); } var project = new Mock<IProject>(); { project.Setup(p => p.History) .Returns(history.Object); } var projectFacade = new ProjectFacade(project.Object); var projectLink = new Mock<ILinkToProjects>(); { projectLink.Setup(p => p.ActiveProject()) .Returns(projectFacade); } Func<string, IDisposable> timerFunc = s => new MockDisposable(); var command = new UndoCommand(projectLink.Object, timerFunc); Assert.IsFalse(command.CanExecute(null)); }
private void InitaliseCommands() { StartGameCommand = ReactiveCommand.Create(); StartGameCommand.Subscribe(arg => StartGameCommandHandler()); ResetCommand = ReactiveCommand.Create(); ResetCommand.Subscribe(arg => ResetCommandHandler()); StopGameCommand = ReactiveCommand.Create(); StopGameCommand.Subscribe(arg => StopGameWindowHandler()); OpenNewGameWindow = ReactiveCommand.Create(); OpenNewGameWindow.Subscribe(arg => OpenNewGameWindowHandler()); FlipCommand = ReactiveCommand.Create(); FlipCommand.Subscribe(arg => FlipCommandHandler()); UndoCommand = ReactiveCommand.Create(); UndoCommand.Subscribe(arg => UndoCommandHandler()); AcceptScoreCommand = ReactiveCommand.Create(); AcceptScoreCommand.Subscribe(arg => AcceptScoreCommandHandler()); RejectScoreCommand = ReactiveCommand.Create(); RejectScoreCommand.Subscribe(arg => RejectScoreCommandHandler()); }
private void InitCommands() { OpenCommand = new OpenCommand(this); ApplyCommand = new ApplyCommand(this); FlipCommand = new FlipCommand(this); HistogramEqualizeCommand = new HistogramEqualizeCommand(this); HistogramStretchCommand = new HistogramStretchCommand(this); CropCommand = new CropCommand(this); InpaintCommand = new InpaintCommand(this); ResizeCommand = new ResizeCommand(this); RotateCommand = new RotateCommand(this); SaveAsCommand = new SaveAsCommand(this); SaveCommand = new SaveCommand(this); ZoomCommand = new ZoomCommand(this); ResetCommand = new ResetCommand(this); CloseCommand = new CloseCommand(this); SelectToolCommand = new SelectToolCommand(this); UndoCommand = new UndoCommand(this); RedoCommand = new RedoCommand(this); DropboxCommand = new DropboxCommand(this); DownloadCommand = new DownloadCommand(this); UploadCommand = new UploadCommand(this); DCommand = new DCommand(this); ECommand = new ECommand(this); PrewittCommand = new PrewittCommand(this); }
private void OnLoadText(TabInfo tabInfo) { if (tabInfo.Guid != _fileGuid || _textEditor == null) { return; } Reset(() => { IsReadOnly = tabInfo.IsReadOnly; IsShowEditor = tabInfo.IsShowEditor; _fileGuid = tabInfo.Guid; _textEditor.Text = tabInfo.FileContent; }); if (IsSelected) { CompileCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); UndoCommand.RaiseCanExecuteChanged(); _textEditor.Focus(); CaretPosChanged(); if (AutoCompile || IsReadOnly) { Compile(tabInfo.FileContent); } } }
private void AddStep() { SpriteAnimationStepWrapper newValue = null; var index = 0; var undoCommand = new UndoCommand(() => { if (newValue == null) { newValue = this.Asset.AddStep(); index = this.Asset.SavableValue.Steps.Count; } else { if (index > 0) { this.Asset.AddStep(newValue, index); } else { this.Asset.AddStep(newValue, this.Asset.SavableValue.Steps.Count); } } }, () => { this.Asset.RemoveStep(newValue); this.SelectedStep = this.Asset.Steps.FirstOrDefault(); }); this._undoService.Do(undoCommand); }
public virtual void Undo() { if (UndoCommand != null) { UndoCommand.Execute(); } }
public void RedoTest() //tests the redo by editing a class, undoing it then redoing it { _testInvoker.Start(); Point Location1 = new Point(100, 102); AddCommand command1 = new AddCommand("Class", Location1, Location1, testDrawing); _testInvoker.EnqueueCommandForExecution(command1); System.Threading.Thread.Sleep(1000); //change the color, size and name Color newColor = Color.Azure; string newName = "New Name"; Size newSize = new Size(90, 90); EditClassCommand cmd = new EditClassCommand(testDrawing._ClassSymbols[0], newName, newSize, newColor, testDrawing); _testInvoker.EnqueueCommandForExecution(cmd); System.Threading.Thread.Sleep(1000); UndoCommand undo = new UndoCommand(); _testInvoker.EnqueueCommandForExecution(undo); System.Threading.Thread.Sleep(1000); RedoCommand redo = new RedoCommand(); _testInvoker.EnqueueCommandForExecution(redo); System.Threading.Thread.Sleep(1000); Assert.AreEqual(newName, testDrawing._ClassSymbols[0].label); Assert.AreEqual(newSize, testDrawing._ClassSymbols[0].Size); Assert.AreEqual(newColor, testDrawing._ClassSymbols[0].ClassColor); }
private async void UndoExecute() { _buffer = new int[MainImage.PixelWidth * MainImage.PixelHeight]; _maskBuffer = new byte[MainImage.PixelWidth * MainImage.PixelHeight]; _filterApplied = false; _originalStream.Seek(0, SeekOrigin.Begin); _editingSession = await EditingSessionFactory.CreateEditingSessionAsync(_originalStream); await _editingSession.RenderToWriteableBitmapAsync(MainImage); MainImage.Invalidate(); CanApply = false; _noChanges = true; UndoCommand.RaiseCanExecuteChanged(); if (PreviewImage != null) { for (var i = 0; i < PreviewImage.Pixels.Length; ++i) { PreviewImage.Pixels[i] = 0; } PreviewImage.Invalidate(); } BindTool(); }
public delegate EditingView Factory(); //autofac uses this public EditingView(EditingModel model, PageListView pageListView, TemplatePagesView templatePagesView, CutCommand cutCommand, CopyCommand copyCommand, PasteCommand pasteCommand, UndoCommand undoCommand, DuplicatePageCommand duplicatePageCommand, DeletePageCommand deletePageCommand, NavigationIsolator isolator) { _model = model; _pageListView = pageListView; _templatePagesView = templatePagesView; _cutCommand = cutCommand; _copyCommand = copyCommand; _pasteCommand = pasteCommand; _undoCommand = undoCommand; _duplicatePageCommand = duplicatePageCommand; _deletePageCommand = deletePageCommand; InitializeComponent(); _browser1.Isolator = isolator; _splitContainer1.Tag = _splitContainer1.SplitterDistance; //save it //don't let it grow automatically // _splitContainer1.SplitterMoved+= ((object sender, SplitterEventArgs e) => _splitContainer1.SplitterDistance = (int)_splitContainer1.Tag); SetupThumnailLists(); _model.SetView(this); _browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand); _browser1.GeckoReady += new EventHandler(OnGeckoReady); _menusToolStrip.Renderer = new FixedToolStripRenderer(); //we're giving it to the parent control through the TopBarControls property Controls.Remove(_topBarPanel); }
private void SendModelEventImpl(ModelEventCommand command) { CurrentSpace.SendModelEvent(command.ModelGuid, command.EventName); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
//autofac uses this public EditingView(EditingModel model, PageListView pageListView, CutCommand cutCommand, CopyCommand copyCommand, PasteCommand pasteCommand, UndoCommand undoCommand, DuplicatePageCommand duplicatePageCommand, DeletePageCommand deletePageCommand, NavigationIsolator isolator, ControlKeyEvent controlKeyEvent) { _model = model; _pageListView = pageListView; _cutCommand = cutCommand; _copyCommand = copyCommand; _pasteCommand = pasteCommand; _undoCommand = undoCommand; _duplicatePageCommand = duplicatePageCommand; _deletePageCommand = deletePageCommand; InitializeComponent(); _browser1.Isolator = isolator; _splitContainer1.Tag = _splitContainer1.SplitterDistance; //save it //don't let it grow automatically // _splitContainer1.SplitterMoved+= ((object sender, SplitterEventArgs e) => _splitContainer1.SplitterDistance = (int)_splitContainer1.Tag); SetupThumnailLists(); _model.SetView(this); _browser1.SetEditingCommands(cutCommand, copyCommand, pasteCommand, undoCommand); _browser1.GeckoReady += new EventHandler(OnGeckoReady); _browser1.ControlKeyEvent = controlKeyEvent; if(SIL.PlatformUtilities.Platform.IsMono) { RepositionButtonsForMono(); BackgroundColorsForLinux(); } controlKeyEvent.Subscribe(HandleControlKeyEvent); // Adding this renderer prevents a white line from showing up under the components. _menusToolStrip.Renderer = new FixedToolStripRenderer(); //we're giving it to the parent control through the TopBarControls property Controls.Remove(_topBarPanel); SetupBrowserContextMenu(); #if __MonoCS__ // The inactive button images look garishly pink on Linux/Mono, but look okay on Windows. // Merely introducing an "identity color matrix" to the image attributes appears to fix // this problem. (The active form looks okay with or without this fix.) // See http://issues.bloomlibrary.org/youtrack/issue/BL-3714. float[][] colorMatrixElements = { new float[] {1, 0, 0, 0, 0}, // red scaling factor of 1 new float[] {0, 1, 0, 0, 0}, // green scaling factor of 1 new float[] {0, 0, 1, 0, 0}, // blue scaling factor of 1 new float[] {0, 0, 0, 1, 0}, // alpha scaling factor of 1 new float[] {0, 0, 0, 0, 1}}; // three translations of 0.0 var colorMatrix = new ColorMatrix(colorMatrixElements); _duplicatePageButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); _deletePageButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); _undoButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); _cutButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); _pasteButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); _copyButton.ImageAttributes.SetColorMatrix(colorMatrix, ColorMatrixFlag.Default, ColorAdjustType.Bitmap); #endif }
private void DeleteModelImpl(DeleteModelCommand command) { List <ModelBase> modelsToDelete = new List <ModelBase>(); if (command.ModelGuid != Guid.Empty) { modelsToDelete.Add(CurrentSpace.GetModelInternal(command.ModelGuid)); } else { // When nothing is specified then it means all selected models. foreach (ISelectable selectable in DynamoSelection.Instance.Selection) { if (selectable is ModelBase) { modelsToDelete.Add(selectable as ModelBase); } } } model.DeleteModelInternal(modelsToDelete); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
private void Undo() { _textEditor.Undo(); RedoCommand.RaiseCanExecuteChanged(); UndoCommand.RaiseCanExecuteChanged(); }
private void ExecuteClearFormatCommand(object parameter) { txt.Text = Strings.RadialMenuClear; _canExecuteUndo = true; _canExecuteRedo = false; UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
public ViewModelBase() { LoadFileCommand = new LoadFileCommand(this); RenameCommand = new RenameCommand(this); UndoCommand = new UndoCommand(this); CopyToClipboardCommand = new CopyToClipboardCommand(this); FileList = new ObservableCollection <File>(); }
private void NotifyChanges() { OnPropertyChanged(nameof(CanRedo)); OnPropertyChanged(nameof(CanUndo)); OnPropertyChanged(nameof(Entity)); UndoCommand.OnCanExecuteChanged(); RedoCommand.OnCanExecuteChanged(); }
/// <summary> /// Creates controller for a model /// </summary> /// <param name="model">associated model</param> /// <param name="project">associated project</param> public ModelController(Model.Model model, Project project) { Model = model; Project = project; UndoCommand = new UndoCommand(getUndoStack(), this); RedoCommand = new RedoCommand(getRedoStack(), this); }
private void ConvertNodesToCodeImpl(ConvertNodesToCodeCommand command) { CurrentSpace.ConvertNodesToCodeInternal(command.NodeId); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); CurrentSpace.HasUnsavedChanges = true; }
private void UpdateModelValueImpl(UpdateModelValueCommand command) { CurrentSpace.UpdateModelValue(command.ModelGuid, command.Name, command.Value); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); }
/// <summary> /// Updates UI bound to the view model properties. /// </summary> private void UpdateView() { SyncModelProperties(); UpdateBoard(); UndoCommand.RaiseCanExecuteChanged(); RedoCommand.RaiseCanExecuteChanged(); MoveCommand.RaiseCanExecuteChanged(); }
public CommandManager() { commandQueue = new LinkedList<Command>(); undoStack = new LinkedList<Command>(); redoStack = new LinkedList<Command>(); undoCommand = new UndoCommand(this); redoCommand = new RedoCommand(this); }
public void OnExecuteShouldInformPlayerThatAMementoIsNotAvailableWhenThereIsntOneSaved() { var ctx = new CommandContext(new Logger(), new Board(5, 5, new RandomGenerator()), 2, 2, new BoardMemory(), Highscore.GetInstance(), new HighscoreProcessor()); var cmd = new UndoCommand(); cmd.Execute(ctx); var expected = ctx.Messages["invalidsave"]; Assert.AreEqual(expected, ctx.CurrentMessage); }
static void Main(string[] args) { Document doc = new Document(); DocumentCommand discmd = new DisplayCommand(doc); DocumentCommand undcmd = new UndoCommand(doc); DocumentCommand redcmd = new RedoCommand(doc); DocumentInvoker invoker = new DocumentInvoker(discmd, undcmd, redcmd); invoker.Display(); invoker.Undo(); invoker.Redo(); }
/// <summary> /// Method for creting player command depend on the command name /// </summary> /// <param name="commandName">Name od the command</param> /// <returns></returns> public ICommand CreatePlayerCommand(string commandName) { ICommand resultCommand; if (this.commands.ContainsKey(commandName)) { return this.commands[commandName]; } var commandNameLowerCase = commandName.ToLower(); switch (commandNameLowerCase) { case Constants.KingDownLeftCommand: resultCommand = new KingDownLeftCommand(); break; case Constants.KingDownRightCommand: resultCommand = new KingDownRightCommand(); break; case Constants.KingUpLeftCommand: resultCommand = new KingUpLeftCommand(); break; case Constants.KingUpRightCommand: resultCommand = new KingUpRightCommand(); break; case Constants.AdlCommand: resultCommand = new PawnADownLeftCommand(); break; case Constants.AdrCommand: resultCommand = new PawnADownRightCommand(); break; case Constants.BdlCommand: resultCommand = new PawnBDownLeftCommand(); break; case Constants.BdrCommand: resultCommand = new PawnBDownRightCommand(); break; case Constants.CdlCommand: resultCommand = new PawnCDownLeftCommand(); break; case Constants.CdrCommand: resultCommand = new PawnCDownRightCommand(); break; case Constants.DdlCommand: resultCommand = new PawnDDownLeftCommand(); break; case Constants.DdrCommand: resultCommand = new PawnDDownRightCommand(); break; case Constants.UndoCommand: resultCommand = new UndoCommand(); break; default: throw new InvalidCommandException("Invalid command " + commandName); } this.commands.Add(commandName, resultCommand); return resultCommand; }
public void CanUndoWithMarkers() { var currentMark = new TimeMarker(10); var markers = new List<TimeMarker> { currentMark, new TimeMarker(1), }; var history = new Mock<ITimeline>(); { history.Setup(h => h.CanRollBack) .Returns(true); history.Setup(h => h.MarkersInThePast()) .Returns(markers); history.Setup(h => h.Current) .Returns(currentMark); } var project = new Mock<IProject>(); { project.Setup(p => p.History) .Returns(history.Object); } var projectFacade = new ProjectFacade(project.Object); var projectLink = new Mock<ILinkToProjects>(); { projectLink.Setup(p => p.ActiveProject()) .Returns(projectFacade); projectLink.Setup(p => p.HasActiveProject()) .Returns(true); } Func<string, IDisposable> timerFunc = s => new MockDisposable(); var command = new UndoCommand(projectLink.Object, timerFunc); Assert.IsTrue(command.CanExecute(null)); }
public void Undo() { var currentMark = new TimeMarker(10); var markers = new List<TimeMarker> { currentMark, new TimeMarker(1), }; var history = new Mock<ITimeline>(); { history.Setup(h => h.CanRollBack) .Returns(true); history.Setup(h => h.MarkersInThePast()) .Returns(markers); history.Setup(h => h.Current) .Returns(currentMark); history.Setup(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>())) .Verifiable(); } var project = new Mock<IProject>(); { project.Setup(p => p.History) .Returns(history.Object); } var projectFacade = new ProjectFacade(project.Object); var projectLink = new Mock<ILinkToProjects>(); { projectLink.Setup(p => p.ActiveProject()) .Returns(projectFacade); projectLink.Setup(p => p.HasActiveProject()) .Returns(true); } Func<string, IDisposable> timerFunc = s => new MockDisposable(); var command = new UndoCommand(projectLink.Object, timerFunc); command.Execute(null); history.Verify(h => h.RollBackTo(It.IsAny<TimeMarker>(), It.IsAny<TimelineTraveller>()), Times.Once()); }
public void CanUndoWithoutActiveProject() { var projectLink = new Mock<ILinkToProjects>(); { projectLink.Setup(p => p.HasActiveProject()) .Returns(false); } Func<string, IDisposable> timerFunc = s => new MockDisposable(); var command = new UndoCommand(projectLink.Object, timerFunc); Assert.IsFalse(command.CanExecute(null)); }
public void CanUndoWithNullFacade() { Func<string, IDisposable> timerFunc = s => new MockDisposable(); var command = new UndoCommand(null, timerFunc); Assert.IsFalse(command.CanExecute(null)); }
public void TestIfTheNameOfTheUndoCommandIsCorrect() { var command = new UndoCommand(); var expected = "undo"; Assert.AreEqual(expected, command.Name); }
/// <summary> /// Creates a command from the passed undo and redo functions, and adds it to the undo list. /// </summary> /// <param name="doCmd"></param> /// <param name="redoCmd"></param> protected void AddCommand(UndoCommand.Function doCmd, UndoCommand.Function redoCmd) { UndoCommand c = new UndoCommand(x, y, tileX, tileY, doCmd, redoCmd); AddCommand(c); }
protected virtual void OnUndoActivated(object sender, System.EventArgs e) { UndoCommand command = new UndoCommand ("Undo", this); command.Execute (); }
/// <summary> /// Adds a command to the undo list. /// </summary> /// <param name="c"></param> private void AddCommand(UndoCommand c) { if (commandList.TrueForAll(o => !(o.TileX == c.TileX && o.TileY == c.TileY))) { commandList.Add(c); } }