protected override void OnThumbDragCompleted(DragCompletedEventArgs e) { base.OnThumbDragCompleted(e); if (_initialCornerRadius == Value) { return; } CompositeCommand cmds = new CompositeCommand(); // Create undoable command for widgets foreach (RoundedRecWidgetViewModel item in _infoItems) { item.PropertyMementos.SetPropertyNewValue("CornerRadius", item.CornerRadius); PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos); cmds.AddCommand(cmd); } // Push to undo stack if (cmds.Count > 0) { DesignerCanvas designerCanvas = VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(VisualTreeHelper.GetParent(this.designerItem))) as DesignerCanvas; ISupportUndo pageVMUndo = designerCanvas.DataContext as ISupportUndo; pageVMUndo.UndoManager.Push(cmds); } }
private void PushUndoStack() { // Undo/Redo ISupportUndo pageVMUndo = designerCanvas.DataContext as ISupportUndo; IGroupOperation pageVMGroup = designerCanvas.DataContext as IGroupOperation; if (pageVMUndo == null) { return; } CompositeCommand cmds = new CompositeCommand(); IPagePropertyData Page = designerCanvas.DataContext as IPagePropertyData; bool bHasGroup = Page.GetSelectedwidgets().Any(a => a.IsGroup); // Create undoable command for widgets foreach (WidgetViewModBase item in _infoItems) { item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left); item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top); if (item.WidgetType == WidgetType.Toast && item.Top != 0) { item.PropertyMementos.SetPropertyNewValue("DisplayPosition", ToastDisplayPosition.UserSetting); } PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos); cmds.AddCommand(cmd); } // Create undoable command for groups if (pageVMGroup != null) { List <Guid> groupGuids = _groups.Select(x => x.WidgetID).ToList(); if (designerItem.ParentID != Guid.Empty) { groupGuids.Add(designerItem.ParentID); } if (groupGuids.Count > 0) { UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids); cmds.AddCommand(cmd); } } // Push to undo stack if (cmds.Count > 0) { List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets(); cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects)); cmds.DeselectAllWidgetsFirst(); pageVMUndo.UndoManager.Push(cmds); } }
/// <summary> /// Binds a business object to the BindingSource. /// </summary> /// <param name="objectToBind"> /// Business object. /// </param> public void Bind(object objectToBind) { ISupportUndo root = objectToBind as ISupportUndo; if (root != null) { root.BeginEdit(); } _source.DataSource = objectToBind; SetEvents(true); ResetBindings(false); }
/// <summary> /// Applies changes to the business object. /// </summary> public void Apply() { SetEvents(false); ISupportUndo root = _source.DataSource as ISupportUndo; Unbind(false); EndEdit(); if (root != null) { root.ApplyEdit(); } }
public MoveThumb() { DragStarted += MoveThumb_DragStarted; DragDelta += MoveThumb_DragDelta; DragCompleted += new DragCompletedEventHandler(this.MoveThumb_DragCompleted); ISelectionService selectionService = ServiceLocator.Current.GetInstance <SelectionServiceProvider>(); ISupportUndo pageVM = selectionService.GetCurrentPage() as ISupportUndo; if (pageVM != null) { pageUndoManager = pageVM.UndoManager; } }
/// <summary> /// Cancels changes to the business object. /// </summary> /// <param name="businessObject"></param> public void Cancel(object businessObject) { SetEvents(false); ISupportUndo root = _source.DataSource as ISupportUndo; Unbind(true); if (root != null) { root.CancelEdit(); } Bind(businessObject); }
/// <summary> /// Executes the next UNDO operation. /// </summary> /// <returns>True if an undo was executed</returns> public bool Undo() { if (CanUndo) { ISupportUndo undo = null; lock (_lock) { if (_undoOperations.Count > 0) { _isUndoingOperation = true; undo = _undoOperations.First.Value; _undoOperations.RemoveFirst(); } } if (undo != null) { try { undo.Undo(); if (undo.CanRedo) { lock (_lock) { _redoOperations.AddFirst(undo); while (_redoOperations.Count > _maxSupportedOperations) { _redoOperations.RemoveLast(); } } } return(true); } finally { lock (_lock) { _isUndoingOperation = false; } } } } return(false); }
/// <summary> /// Adds a new undo operation to the stack. /// </summary> /// <param name="undoOp">operation</param> /// <param name="noInsertIfInUndoOperation">True if the insertion should not occur if in an UNDO operation</param> /// <returns>True if undo operation was added to stack</returns> public bool Add(ISupportUndo undoOp, bool noInsertIfInUndoOperation = true) { if (undoOp == null) { throw new ArgumentNullException("undoOp"); } if (noInsertIfInUndoOperation && _isUndoingOperation) { return(false); } lock (_lock) { _undoOperations.AddFirst(undoOp); while (_undoOperations.Count > MaxSupportedOperations) { _undoOperations.RemoveLast(); } } return(true); }
private void RotateThumb_DragCompleted(object sender, DragCompletedEventArgs e) { if (_infoItems.Count <= 0) { return; } // Undo/Redo ISupportUndo pageVMUndo = canvas.DataContext as ISupportUndo; IGroupOperation pageVMGroup = canvas.DataContext as IGroupOperation; if (pageVMUndo == null) { return; } CompositeCommand cmds = new CompositeCommand(); // Create undoable command for widgets foreach (WidgetViewModBase item in _infoItems) { item.PropertyMementos.SetPropertyNewValue("RotateAngle", item.RotateAngle); if (this.designerItem.IsGroup) { item.PropertyMementos.SetPropertyNewValue("Left", item.Raw_Left); item.PropertyMementos.SetPropertyNewValue("Top", item.Raw_Top); } PropertyChangeCommand cmd = new PropertyChangeCommand(item, item.PropertyMementos); cmds.AddCommand(cmd); } // Create undoable command for groups if (pageVMGroup != null) { List <Guid> groupGuids = new List <Guid>(); if (designerItem.ParentID != Guid.Empty) { groupGuids.Add(designerItem.ParentID); UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids); cmds.AddCommand(cmd); } if (this.designerItem.IsGroup) { groupGuids.Add((designerItem.DataContext as GroupViewModel).WidgetID); UpdateGroupCommand cmd = new UpdateGroupCommand(pageVMGroup, groupGuids); cmds.AddCommand(cmd); } } // Push to undo stack if (cmds.Count > 0) { List <IWidgetPropertyData> allSelects = _selectionService.GetSelectedWidgets(); cmds.AddCommand(new SelectCommand(pageVMGroup, allSelects)); cmds.DeselectAllWidgetsFirst(); pageVMUndo.UndoManager.Push(cmds); } }
/// <summary> /// Adds a new undo operation to the collection /// </summary> /// <param name="operation">Operation</param> public void Add(ISupportUndo operation) { _undoStack.Add(operation); }