Example #1
0
        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("");
        }
Example #2
0
        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("");
        }
        /// <summary>
        /// Insert appointment to schedulestorage
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void OnAppointmentInserted(object sender, PersistentObjectEventArgs e)
        {
            var appointment = e.Object as Appointment;

            try
            {
                base.OnAppointmentInserted(sender, e);
            }
            catch { }
            _innerCtrl.ChangedService.MarkChanged();
            ControlService.EnableCopyMenu(true);


            if (appointment.CustomFields == null)
            {
                try
                {
                    _customFields.SetValue(appointment, new CustomFieldCollection());
                }
                catch (Exception ex)
                {
                    DataGate.Log.Error("SchedulerStorageDecorator Exception:" + ex.Message);
                }
            }
            if (!_innerCtrl.IsOpen)
            {
                UndoService.AddAppointmentAddedAction(this, appointment);
            }
        }
Example #4
0
        private void OnLayerDragDrop(object sender, DragEventArgs e)
        {
            if (e.Effect != DragDropEffects.Copy)
            {
                return;
            }

            var fmts = e.Data.GetFormats();

            if (fmts == null || fmts.Length != 1)
            {
                return;
            }

            LayerEffect effect = e.Data.GetData(fmts[0]) as LayerEffect;

            CurrentDragLayer = true;
            CurrentDrag      = this;
            if (effect != null)
            {
                //effect.Layer = this._layer.Shape
                switch (effect.Type)
                {
                case EffectType.Entry:
                    effect.Duration = this.ctlEntryEffect.Width == 0 ? 2 : ctlEntryEffect.Effect.Duration;
                    break;

                case EffectType.Exit:
                    effect.Duration = this.ctlExitEffect.Width == 0 ? 2 : ctlExitEffect.Effect.Duration;
                    break;

                default:
                    effect.Duration = this.ctlEmphasis.Width == 0 ? 8 : ctlEmphasis.Effect.Duration;
                    break;
                }
                //if (effect.Duration == 0)
                //    effect.Duration = 2;//ControlService.SignCombo.Current.Template.Message. 2;
                ////else
                ////    effect.Duration++;
                UndoService.BeginTransaction(String.Format("Add a {0} effect", effect.Type));
                UndoService.AddLayerEffectAddedAction(effect);

                AddEffectFromDragDrop(effect);

                UndoService.Commit();
                ControlService.RefreshPropertyGrid(_layer);
                CurrentDragLayer = false;
                return;
            }

            LayerControl frameLayer = e.Data.GetData(typeof(LayerControl)) as LayerControl;

            if (frameLayer != null)
            {
                OnDragLayer(frameLayer);
            }

            EffectContainer.Invalidate();
        }
        /// <summary>
        /// go to date
        /// </summary>
        /// <param name="date"></param>
        /// <param name="viewType"></param>
        public void GoToDate(DateTime date, SchedulerViewType viewType)
        {
            DateTime          old         = _control.SelectedInterval.Start;
            SchedulerViewType oldViewType = _control.ActiveViewType;

            _innerNavigate.GoToDate(date, viewType);
            UndoService.AddGotoDateAction(_innerNavigate, _control.SelectedInterval.Start, old, viewType, oldViewType);
        }
        protected void SetProperty <T>(ref T model, Action setter, [CallerMemberName] string propertyName = null)
        {
            var oldState = model;

            setter();
            RaisePropertyChanged(propertyName);
            UndoService.AddUndoState(this, propertyName, oldState, model);
        }
Example #7
0
        public void UndoService_Has_Current_Property_for_Singleton_Instance()
        {
            UndoService svc  = UndoService.Current;
            UndoService svc2 = UndoService.Current;

            Assert.IsNotNull(svc);
            Assert.IsNotNull(svc2);
            Assert.AreSame(svc, svc2);
        }
Example #8
0
        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 Setup()
 {
     _undoServiceForInt       = new UndoService <int>(GetIntState, SetIntState, 3);
     _individualUndoService   = new UndoService <int>(GetIntState, SetIntState, 3);
     _subUndoServiceForInt    = new UndoService <int>(GetIntState, SetIntState, 3);
     _subUndoServiceForString = new UndoService <string>(GetStringState, SetStringState, 3);
     IUndoService[] subservices = { _subUndoServiceForInt, _subUndoServiceForString };
     _aggregateService         = new UndoServiceAggregate(subservices);
     _canUndoChangedFiredCount = 0;
     _canRedoChangedFiredCount = 0;
 }
        public void Setup()
        {
            var otherObject = new OtherClass {
                Text = "Original"
            };

            _objectBeingTracked = new MyClass {
                Id = 1, MutableMember = otherObject
            };
            _undoService = new UndoService <string>(WorkingGetState, WorkingSetState);
        }
Example #11
0
            private void MouseDown(object sender, MouseEventArgs e)
            {
                UndoService.BeginTransaction("Effect mouse down event.");
                if (e.Button == MouseButtons.Left)
                {
                    _lastPoint.X = Cursor.Position.X;
                    _lastPoint.Y = Cursor.Position.Y;
                }

                UndoService.AddAction(new EffectMouseEventAction(_layerCtrl));
            }
Example #12
0
        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("");
        }
Example #13
0
        /// <summary>
        /// Opens a new change group used to batch several changes.
        /// ChangeGroups work as transactions and are used to support the Undo/Redo system.
        /// </summary>
        public override ChangeGroup OpenGroup(string changeGroupTitle, ICollection <DesignItem> affectedItems)
        {
            if (affectedItems == null)
            {
                throw new ArgumentNullException("affectedItems");
            }

            UndoService     undoService = this.Services.GetRequiredService <UndoService>();
            UndoTransaction g           = undoService.StartTransaction(affectedItems);

            g.Title = changeGroupTitle;
            return(g);
        }
 void layer_PropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.Name == ShapeLayer._.Name)
     {
         lblLayerName.Text      = _layer.Name;
         this.lblLayerName.Text = _layer.Name;
     }
     if (e.Name == ShapeLayer._.IsVisible)
     {
         this.Layer.IsVisible = Convert.ToBoolean(e.NewValue);
     }
     UndoService.AddPropertyChangedAction(sender, e.Name, e.NewValue, e.OldValue);
 }
Example #15
0
        public override void OnMouseDown(Canvas drawArea, MouseEventArgs e)
        {
            UndoService.BeginTransaction("Add a line");

            Point    p    = drawArea.BackTrackMouse(new Point(e.X, e.Y));
            SignType sign = drawArea.MessageControl.Sign.Type;
            int      zoom = drawArea.Document.Zoom;
            Point    s    = p.PointMultiplyDouble(1d / zoom);

            ShapeLine line = new ShapeLine(zoom, s, new Point(s.X + 1, s.Y + 1), drawArea.Document.CurrentShapePaintInfo, sign);

            AddNewObject(drawArea, line);
        }
        void Execute(ITransactionItem item)
        {
            UndoService undoService = context.Services.GetService <UndoService>();

            if (undoService != null)
            {
                undoService.Execute(item);
            }
            else
            {
                item.Do();
            }
        }
        public override void Reset()
        {
            UndoService undoService = _designItem.Services.GetService <UndoService>();

            if (undoService != null)
            {
                undoService.Execute(new PropertyChangeAction(this, null, false));
            }
            else
            {
                ResetInternal();
            }
        }
Example #18
0
        public void AggregateUndoServiceUndoRedoTest()
        {
            // UndoServiceAggregate is created using an IUndoService array:
            var undoServiceForInt    = new UndoService <int>(GetIntState, SetIntState, null);
            var undoServiceForString = new UndoService <string>(GetStringState, SetStringState, null);

            IUndoService[] subservices      = { undoServiceForInt, undoServiceForString };
            var            serviceAggregate = new UndoServiceAggregate(subservices);


            // Changes are recorded by the individual UndoServices
            _statefulInt = 1;
            undoServiceForInt.RecordState();
            _statefulString = "One";
            undoServiceForString.RecordState();
            _statefulInt = 2;
            undoServiceForInt.RecordState();
            _statefulInt = 3;
            undoServiceForInt.RecordState();
            _statefulString = "Two";
            undoServiceForString.RecordState();


            /*
             * The UndoServiceAggregate provides a unified interface for performing undo/redo on the different tracked objects.
             * (You can also perform Undo/Redo on the individual services, which will undo the last change on the corresponding object.)
             */
            serviceAggregate.Undo();
            Assert.IsTrue(_statefulString.Equals("One"));
            Assert.IsTrue(_statefulInt == 3);

            serviceAggregate.Undo();
            Assert.IsTrue(_statefulString.Equals("One"));
            Assert.IsTrue(_statefulInt == 2);

            serviceAggregate.Undo();
            Assert.IsTrue(_statefulString.Equals("One"));
            Assert.IsTrue(_statefulInt == 1);

            serviceAggregate.Redo();
            Assert.IsTrue(_statefulString.Equals("One"));
            Assert.IsTrue(_statefulInt == 2);

            serviceAggregate.Redo();
            Assert.IsTrue(_statefulString.Equals("One"));
            Assert.IsTrue(_statefulInt == 3);

            serviceAggregate.Redo();
            Assert.IsTrue(_statefulString.Equals("Two"));
            Assert.IsTrue(_statefulInt == 3);
        }
        public void UndoService_AddUndoState_AddsStateToUndoStates()
        {
            //arrange
            var testViewModel = new TestViewModel();

            //act
            UndoService.AddUndoState(testViewModel, propertyName, 1, 2);
            var state = UndoService.GetWindowPreviousState;

            //assert
            Assert.AreEqual(testViewModel, state.viewModel);
            Assert.AreEqual(propertyName, state.propertyName);
            Assert.AreEqual(1, state.oldState);
            Assert.AreEqual(2, state.newState);
        }
        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"));
        }
        /// <summary>
        /// Will happen when appointment deleted
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected override void OnAppointmentDeleted(object sender, PersistentObjectEventArgs e)
        {
            try
            {
                base.OnAppointmentDeleted(sender, e);
            }
            catch { }
            _innerCtrl.ChangedService.MarkChanged();
            ControlService.EnableCopyMenu(false);
            Appointment appoint = e.Object as Appointment;

            SetLock(appoint);

            UndoService.AddAppointmentRemovedAction(this, appoint);
        }
 private void OnLayerPropertyChanged(object sender, PropertyChangedEventArgs e)
 {
     if (e.Name == EffectPropertyName)
     {
         if (Effect.IsEmpty)
         {
             _ctlLayer.RemoveEffect(Effect.Type);
         }
         else
         {
             _ctlLayer.AppendEffect(Effect.Type);
         }
         UndoService.AddPropertyChangedAction(sender, new PropertyItem(e.Name, e.NewValue, e.OldValue));
     }
 }
Example #23
0
 /// <summary>
 /// paste
 /// </summary>
 public void Paste()
 {
     if (CanPaste)
     {
         UndoService.BeginTransaction("Paste");
         if (DoPaste())
         {
             UndoService.Commit();
         }
         else
         {
             UndoService.Current.Rollback();
         }
     }
 }
        public override void OnMouseDown(Canvas drawArea, MouseEventArgs e)
        {
            UndoService.BeginTransaction("Add a Rectangle");

            Point          p = drawArea.BackTrackMouse(new Point(e.X, e.Y));
            ShapeRectangle shapeRectangle = new ShapeRectangle(
                drawArea.Document.Zoom
                , p.X
                , p.Y
                , 1
                , 1
                , drawArea.Document.CurrentShapePaintInfo
                , drawArea.MessageControl.Sign.Type);

            AddNewObject(drawArea, shapeRectangle);
        }
        public override void SetValue(object value)
        {
            XamlPropertyValue newValue;

            if (value == null)
            {
                newValue = _property.ParentObject.OwnerDocument.CreateNullValue();
            }
            else
            {
                XamlComponentService componentService = _designItem.ComponentService;

                XamlDesignItem designItem = value as XamlDesignItem;
                if (designItem == null)
                {
                    designItem = (XamlDesignItem)componentService.GetDesignItem(value);
                }
                if (designItem != null)
                {
                    if (designItem.Parent != null)
                    {
                        throw new DesignerException("Cannot set value to design item that already has a parent");
                    }
                    newValue = designItem.XamlObject;
                }
                else
                {
                    XamlPropertyValue val = _property.ParentObject.OwnerDocument.CreatePropertyValue(value, _property);
                    designItem = componentService.RegisterXamlComponentRecursive(val as XamlObject);
                    newValue   = val;
                }
            }

            UndoService undoService = _designItem.Services.GetService <UndoService>();

            if (undoService != null)
            {
                undoService.Execute(new PropertyChangeAction(this, newValue, true));
            }
            else
            {
                SetValueInternal(newValue);
            }
        }
        public void UndoService_ResetUndoStates_ClearsUndoStates()
        {
            //arrange
            UndoService.ResetUndoStates();
            bool exceptionThrown = false;

            //act
            try
            {
                var state = UndoService.GetWindowPreviousState;
            }
            catch (ArgumentException ex)
            {
                exceptionThrown = true;
                Assert.IsNotNull(ex);
            }

            //assert
            Assert.IsTrue(exceptionThrown);
        }
Example #27
0
        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("");
        }
        /// <summary>
        /// Delete Exit Effect
        /// add by Terry
        /// </summary>
        private ToolStripMenuItem DeleteExitEffect()
        {
            ToolStripMenuItem item = new ToolStripMenuItem();

            item.Text   = "Delete Exit Effect";
            item.Image  = Resource.GetImage(Resource.Images.DeleteExitEffect);
            item.Click += delegate
            {
                UndoService.BeginTransaction("Delete a exit effect");
                LayerEffect effect = FrameLayer.ExitEffect.Real.Copy();

                //FrameLayer.ExitEffect.Name = null;
                FrameLayer.RemoveEffect(effect.Type);
                UndoService.AddLayerEffectRemovedAction(FrameLayer, effect);

                FrameLayer.Invalidate();
                UndoService.Commit();
            };
            Items.Add(item);
            return(item);
        }
        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);
        }
Example #30
0
        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);
        }