private void CaptureEndState()
        {
            if (!CanAdjustAlpha() || _memorableCommand == null)
            {
                return;
            }

            if (this.SelectedLayerOpacityProvider != null)
            {
                _memorableCommand.EndState = GetSelectedLayerOpacityManager().CreateMemento();
                UndoableCommand         applicatorCommand = _applicator.ApplyToLinkedImages();
                DrawableUndoableCommand historyCommand    = new DrawableUndoableCommand(this.SelectedPresentationImage);

                if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState))
                {
                    historyCommand.Enqueue(_memorableCommand);
                }
                if (applicatorCommand != null)
                {
                    historyCommand.Enqueue(applicatorCommand);
                }

                if (historyCommand.Count > 0)
                {
                    historyCommand.Name = SR.CommandAdjustOpacity;
                    this.Context.Viewer.CommandHistory.AddCommand(historyCommand);
                }
            }
        }
Example #2
0
        private void CaptureEndState()
        {
            if (!CanZoom() || _memorableCommand == null)
            {
                return;
            }

            _memorableCommand.EndState = GetSelectedImageTransform().CreateMemento();
            UndoableCommand         applicatorCommand = _toolBehavior.Behavior.SelectedImageZoomTool ? null : _applicator.ApplyToLinkedImages();
            DrawableUndoableCommand historyCommand    = new DrawableUndoableCommand(this.SelectedPresentationImage);

            if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState))
            {
                historyCommand.Enqueue(_memorableCommand);
            }
            if (applicatorCommand != null)
            {
                historyCommand.Enqueue(applicatorCommand);
            }

            if (historyCommand.Count > 0)
            {
                historyCommand.Name = SR.CommandZoom;
                this.Context.Viewer.CommandHistory.AddCommand(historyCommand);
            }

            _memorableCommand = null;
        }
Example #3
0
 public void Undo()
 {
     if (commandStack.Count > 0)
     {
         UndoableCommand command = (UndoableCommand)commandStack.Pop();
         command.Undo();
     }
 }
Example #4
0
 public void Undo()
 {
     if (commandStack.Count > 0)
     {
         UndoableCommand cmd = (UndoableCommand)commandStack.Pop();
         cmd.Undo();
         //Debug.Log("Undo: " + cmd.GetType());
     }
 }
Example #5
0
        //private bool _isCurrent = false;

        private CommandInfo(UndoableCommand command)
        {
            _name     = command.Name;
            _hashcode = command.GetHashCode();

            Type type = command.GetType();

            _type     = type.FullName;
            _assembly = type.Assembly.FullName;
        }
        /// <inheritdoc />
        public override void PushUndo(UndoableCommand command)
        {
            var obj = WindowState.AssetModel as Object;

            if (obj != null)
            {
                Undo.RegisterCompleteObjectUndo(new[] { obj }, command?.UndoString ?? "");
            }

            base.PushUndo(command);
        }
Example #7
0
            private void Apply()
            {
                ImageOperationApplicator applicator     = new ImageOperationApplicator(_ownerTool.SelectedPresentationImage, this);
                UndoableCommand          historyCommand = _ownerTool._toolBehavior.Behavior.SelectedImageColorMapTool ? applicator.ApplyToReferenceImage() : applicator.ApplyToAllImages();

                if (historyCommand != null)
                {
                    historyCommand.Name = SR.CommandColorMap;
                    _ownerTool.Context.Viewer.CommandHistory.AddCommand(historyCommand);
                }
            }
Example #8
0
 internal static CommandInfo CreateCommandInfo(UndoableCommand command)
 {
     if (command is MemorableUndoableCommand)
     {
         return(new MemorableCommandInfo((MemorableUndoableCommand)command));
     }
     else if (command is CompositeUndoableCommand)
     {
         return(new CompositeCommandInfo((CompositeUndoableCommand)command));
     }
     return(new CommandInfo(command));
 }
        /// <summary>
        /// Applies <paramref name="operation"/> to <paramref name="item"/> and returns
        /// an <see cref="UndoableCommand"/> that can undo and redo the operation.
        /// </summary>
        /// <returns>
        /// An <see cref="UndoableCommand"/> if application of <paramref name="operation"/>
        /// resulted in a change to the internal state of <paramref name="item"/>, otherwise null.
        /// </returns>
        /// <remarks>
        /// <para>
        /// The default implementation takes the <see cref="MemorableUndoableCommand"/> returned
        /// by the base method and wraps it in a <see cref="DrawableUndoableCommand"/>.
        /// </para>
        /// <para>
        /// Inheritors can override this method to do any additional processing and/or to
        /// modify the resulting command, if necessary.
        /// </para>
        /// </remarks>
        protected override UndoableCommand Apply(IUndoableOperation <T> operation, T item)
        {
            UndoableCommand command = base.Apply(operation, item);

            if (command != null)
            {
                item.Draw();

                DrawableUndoableCommand drawableCommand = new DrawableUndoableCommand(item);
                drawableCommand.Enqueue(command);
                command = drawableCommand;
            }

            return(command);
        }
Example #10
0
    public virtual void Add(UndoableCommand cmd)
    {
        if (updating > 0)
        {
            return;
        }

        history.AddLast(cmd);
        if (history.Count > maxHistoryLength)
        {
            history.RemoveFirst();
        }

        redoStack.Clear();
    }
Example #11
0
        public void Apply()
        {
            if (_operation.GetOriginator(this.Context.Viewer.SelectedPresentationImage) == null)
            {
                return;
            }

            ImageOperationApplicator applicator     = new ImageOperationApplicator(SelectedPresentationImage, _operation);
            UndoableCommand          historyCommand = _toolBehavior.Behavior.SelectedImageInvertTool ? applicator.ApplyToReferenceImage() : applicator.ApplyToAllImages();

            if (historyCommand != null)
            {
                historyCommand.Name = SR.CommandInvert;
                Context.Viewer.CommandHistory.AddCommand(historyCommand);
            }
        }
Example #12
0
        public void Activate()
        {
            if (!_operation.AppliesTo(this.SelectedPresentationImage))
            {
                return;
            }

            ImageOperationApplicator applicator     = new ImageOperationApplicator(SelectedPresentationImage, _operation);
            UndoableCommand          historyCommand = _toolBehavior.Behavior.SelectedImageResetTool ? applicator.ApplyToReferenceImage() : applicator.ApplyToAllImages();

            if (historyCommand != null)
            {
                historyCommand.Name = SR.CommandReset;
                Context.Viewer.CommandHistory.AddCommand(historyCommand);
            }
        }
        public IEnumerator TestRebuildType(UndoableCommand command, UpdateType rebuildType)
        {
            // Do the initial update.
            yield return(null);

            m_GraphViewStateObserver.UpdateType = UpdateType.None;
            CommandDispatcher.Dispatch(command);
            yield return(null);

            Assert.That(m_GraphViewStateObserver.UpdateType, Is.EqualTo(rebuildType));

            m_GraphViewStateObserver.UpdateType = UpdateType.None;
            yield return(null);

            Assert.That(m_GraphViewStateObserver.UpdateType, Is.EqualTo(UpdateType.None));
        }
Example #14
0
        private bool Execute(UndoableCommand command)
        {
            if (!command.CanExecute(this))
            {
                return(false);
            }
            bool success = false;

            try { success = command.Execute(this); }
            catch (Exception ex) { ShowErrorMessage(ex.Message); }
            if (success)
            {
                undoManager.Add(command);
                RaiseStateChanged();
            }
            return(true);
        }
Example #15
0
        /// <summary>
        /// On the first call, the <see cref="IUndoableOperation{T}"/> is applied and this
        /// object is populated with the <see cref="MemorableUndoableCommand"/>s to undo
        /// the operation.
        /// </summary>
        /// <remarks>
        /// You should call <see cref="Execute"/> and check that the <see cref="CompositeUndoableCommand.Count"/>
        /// is non-zero before adding to the <see cref="CommandHistory"/>.  Otherwise, there will end up
        /// being 'no-op' commands in the <see cref="CommandHistory"/>.
        /// </remarks>
        public override void Execute()
        {
            if (_operation != null)
            {
                foreach (T item in _items)
                {
                    UndoableCommand command = Apply(_operation, item);
                    if (command != null)
                    {
                        Enqueue(command);
                    }
                }

                _operation = null;
                _items     = null;
            }
            else
            {
                base.Execute();
            }
        }
        private void CaptureEndState()
        {
            if (!CanWindowLevel() || _memorableCommand == null)
            {
                return;
            }

            if (SelectedVoiLutProvider.VoiLutManager.VoiLut is IBasicVoiLutLinear)
            {
                _memorableCommand.EndState = GetSelectedImageVoiLutManager().CreateMemento();
                UndoableCommand         applicatorCommand = _toolBehavior.Behavior.SelectedImageWindowLevelTool ? null : _applicator.ApplyToLinkedImages();
                DrawableUndoableCommand historyCommand    = new DrawableUndoableCommand(SelectedPresentationImage);

                if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState))
                {
                    historyCommand.Enqueue(_memorableCommand);
                }
                if (applicatorCommand != null)
                {
                    historyCommand.Enqueue(applicatorCommand);
                }

                if (historyCommand.Count > 0)
                {
                    historyCommand.Name = SR.CommandWindowLevel;
                    Context.Viewer.CommandHistory.AddCommand(historyCommand);
                }
            }
            if (GetCheckedSync() == true)
            {
                var historyCommand2 = new DrawableUndoableOperationCommand <IPresentationImage>(this._operation, GetAllImages());
                historyCommand2.Execute();

                if (historyCommand2.Count > 0)
                {
                    historyCommand2.Name = SR.CommandMatchScale;
                    base.ImageViewer.CommandHistory.AddCommand(historyCommand2);
                }
            }
        }
Example #17
0
        private void CaptureEndState()
        {
            if (!CanZoom() || _memorableCommand == null)
            {
                return;
            }

            _memorableCommand.EndState = GetSelectedImageTransform().CreateMemento();
            UndoableCommand         applicatorCommand = _toolBehavior.Behavior.SelectedImageZoomTool ? null : _applicator.ApplyToLinkedImages();
            DrawableUndoableCommand historyCommand    = new DrawableUndoableCommand(this.SelectedPresentationImage);

            if (!_memorableCommand.EndState.Equals(_memorableCommand.BeginState))
            {
                historyCommand.Enqueue(_memorableCommand);
            }
            if (applicatorCommand != null)
            {
                historyCommand.Enqueue(applicatorCommand);
            }

            if (historyCommand.Count > 0)
            {
                historyCommand.Name = SR.CommandZoom;
                this.Context.Viewer.CommandHistory.AddCommand(historyCommand);
            }

            _memorableCommand = null;
            if (GetCheckedSync() == true)
            {
                var historyCommand2 = new DrawableUndoableOperationCommand <IPresentationImage>(this._operation, GetAllImages());
                historyCommand2.Execute();

                if (historyCommand2.Count > 0)
                {
                    historyCommand2.Name = SR.CommandMatchScale;
                    base.ImageViewer.CommandHistory.AddCommand(historyCommand);
                }
            }
        }
 public MultiRangeCommand(UndoableCommand command)
     : base(command.ts)
 {
     this.cmd = command;
     range = ts.CurrentTB.Selection.Clone();
 }
 public void Push(UndoableCommand command)
 {
     _histories.Push(command);
 }
Example #20
0
 public MultiRangeCommand(UndoableCommand command) : base(command.ts)
 {
     this.cmd = command;
     range    = ts.CurrentTB.Selection.Clone();
 }
Example #21
0
 public void push(UndoableCommand command)
 {
     commands.Add(command);
 }
Example #22
0
 public void ExecuteCommand(UndoableCommand command)
 {
     this.ExecuteCommandCalled   = true;
     this.ExecuteCommandArgument = command;
     this.ExecuteCommandNumberOfCalls++;
 }
 public void Push(UndoableCommand command)
 {
     Commands.Enqueue(command);
 }