コード例 #1
0
        /// <summary>
        ///     Adds a command to the history without executing it. This is usefull if
        ///     the command was executed somewhere else but still needs undo/redo.
        /// </summary>
        /// <param name="currentMover"></param>
        public void AddCommand(IUndoable command)
        {
            _undoStack.AddLast(command);

            // Clear the redo stack (it might be empty already) because we just editted.
            _redoStack.Clear();
        }
コード例 #2
0
        void IPropertyValueAggregate.SetValue(object value)
        {
            // Snag the Undo/Redo system off of the first associated property, so we can put all of these Set values into a macro.
            WUndoStack undoStack = null;

            if (m_associatedProperties.Count > 0)
            {
                IUndoable undoableValue = m_associatedProperties[0] as IUndoable;
                undoStack = undoableValue.GetUndoStack();
            }

            if (undoStack != null)
            {
                undoStack.BeginMacro(string.Format("Set {0}", Name));
            }

            foreach (var property in m_associatedProperties)
            {
                property.SetValue(value);
            }

            if (undoStack != null)
            {
                undoStack.EndMacro();
            }
        }
コード例 #3
0
        public NodeEditorPanel(IGUI _gui,
                               EditorWindow _editorWindow,
                               ConstellationScript _script,
                               IUndoable _undoable,
                               ClipBoard _editorClipBoard,
                               float positionX,
                               float positionY,
                               LinkAdded linkAdded,
                               NodeAdded nodeAdded,
                               NodeRemoved nodeRemoved)
        {
            nodesFactory        = new NodesFactory();
            constellationScript = _script;
            undoable            = _undoable;
            Nodes            = new List <NodeView> ();
            GUI              = _gui;
            EditorWindow     = _editorWindow;
            editorScrollSize = new Vector2(500, 500);
            Background       = AssetDatabase.LoadAssetAtPath(editorPath + "background.png", typeof(Texture2D)) as Texture2D;
            var allNodes = NodesFactory.GetAllNodes();

            nodes           = new string[allNodes.Length];
            editorScrollPos = new Vector2(positionX, positionY);
            for (var i = 0; i < allNodes.Length; i++)
            {
                nodes[i] = allNodes[i];
            }
            OnLinkAdded        += linkAdded;
            OnNodeAdded        += nodeAdded;
            OnNodeRemoved      += nodeRemoved;
            nodeEditorSelection = new NodeEditorSelection(GUI, _editorClipBoard);
        }
コード例 #4
0
ファイル: UndoManager.cs プロジェクト: buptkang/LogicPad
        /// <summary>
        /// Add an action to the top of the undo stack.
        /// This operation clears the redo stack.
        /// </summary>
        /// <param name="action"></param>
        public void Add(IUndoable action)
        {
            undos.Push(action);
            redos.Clear();

            if (savepoint.HasValue)
            {
                if (savepoint <= 0)
                {
                    // when adding an undo item, the save point moves away
                    // further back into the undo stack
                    // negatives redos means undos are required
                    savepoint--;
                }
                else
                {
                    // savepoint is on the redo stack
                    // redo stack just got cleared
                    savepoint = null;
                }

            }

            NotifyAllProps();
        }
コード例 #5
0
 public NodeEditorNodes(EditorWindow _editorWindow,
                        NodeConfig _nodeConfig,
                        ConstellationScript _constellationScript,
                        IUndoable _undoable,
                        NodeEditorSelection _nodeEditorSelection,
                        ILinkEditor _linkEditor,
                        IGUI _gui,
                        IVisibleObject _visibleObject,
                        NodeAdded _nodeAdded,
                        NodeRemoved _nodeRemoved,
                        HelpClicked _helpClicked)
 {
     linkEditor          = _linkEditor;
     editorWindow        = _editorWindow;
     Nodes               = new List <NodeView> ();
     nodeConfig          = _nodeConfig;
     constellationScript = _constellationScript;
     isInstance          = constellationScript.IsInstance;
     nodesFactory        = new NodesFactory();
     undoable            = _undoable;
     nodeEditorSelection = _nodeEditorSelection;
     GUI            = _gui;
     visibleObject  = _visibleObject;
     OnNodeAdded   += _nodeAdded;
     OnNodeRemoved += _nodeRemoved;
     OnHelpClicked += _helpClicked;
     SetNodes();
 }
コード例 #6
0
        public void Redo()
        {
            if (redoStack.Count == 0)
            {
                return;
            }

            IUndoable <T> action = redoStack.Pop();
            T             obj    = action.Redo();

            if (ReferenceEquals(action, redoCleanAction))
            {
                fileIsClean.OnNext(Unit.Default);
            }

            affectedObject.OnNext(obj);
            AddUndoInternal(action);

            if (redoStack.Count == 0)
            {
                NotifyRedoUnavailable();
            }
            else
            {
                redoDescription.OnNext(redoStack.Peek().Description);
            }
        }
コード例 #7
0
ファイル: Undo.cs プロジェクト: tomas-pluskal/pwiz
        /// <summary>
        /// Constructor for associating an <see cref="UndoManager"/>
        /// with a <see cref="IUndoable"/>.  The generalized interface
        /// makes it possible to unit test this class separate from
        /// <see cref="SrmDocument"/>, though in the running application,
        /// it is always managing references to document instances.
        /// </summary>
        /// <param name="client">Undo state provider</param>
        public UndoManager(IUndoable client)
        {
            _client = client;

            _undoStack = new Stack <UndoRecord>();
            _redoStack = new Stack <UndoRecord>();
        }
コード例 #8
0
        public static bool Draw(ILoadable loadable, IUndoable undoable, ICopyable copyable)
        {
            EditorGUILayout.BeginHorizontal();
            if (GUILayout.Button("File", EditorStyles.toolbarButton, GUILayout.Width(35)))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("New: Ctrl+Atl+N "), false, OnNew, loadable);
                menu.AddItem(new GUIContent("Load: Ctrl+Atl+L"), false, OnLoad, loadable);
                menu.AddItem(new GUIContent("Save: Ctrl+Atl+S"), false, OnSave, loadable);
                menu.ShowAsContext();
                return(true);
            }

            if (GUILayout.Button("Edit", EditorStyles.toolbarButton, GUILayout.Width(35)))
            {
                GenericMenu menu = new GenericMenu();
                menu.AddItem(new GUIContent("Undo: Ctrl+Atl+Z"), false, OnUndo, undoable);
                menu.AddItem(new GUIContent("Redo: Ctrl+Atl+Y"), false, OnRedo, undoable);
                menu.AddItem(new GUIContent("Copy: Ctrl+Atl+C"), false, Copy, copyable);
                menu.AddItem(new GUIContent("Past: Ctrl+Atl+V"), false, Paste, copyable);
                menu.ShowAsContext();
                return(true);
            }

            if (GUILayout.Button("View", EditorStyles.toolbarButton, GUILayout.Width(35)))
            {
                GenericMenu menu = new GenericMenu();
                menu.ShowAsContext();
                return(true);
            }

            GUILayout.Label("", EditorStyles.toolbarButton);
            EditorGUILayout.EndHorizontal();
            return(false);
        }
コード例 #9
0
 public void Clear()
 {
     undoCleanAction = null;
     redoCleanAction = null;
     ClearRedo();
     ClearUndo();
 }
コード例 #10
0
        public void AddInsert(int collectionOwnerId, IUndoable insertedObjectState, int indexAt, string description, int clientId)
        {
            var insertChange = new Change(ChangeReason.InsertAt, collectionOwnerId, insertedObjectState.Id,
                                          insertedObjectState, indexAt);

            _transactionService.Add(insertChange, clientId, description);
        }
コード例 #11
0
        /// <summary>
        /// Adds the specified IUndoable to this UndoableGroup.
        /// </summary>
        /// <param name="undoable">The IUndoable to add to this UndoableGroup.</param>
        protected override void AddUndoable(IUndoable undoable)
        {
            UndoablePropertyChange currentUndoablePropertyChange = (UndoablePropertyChange)undoable;
            int hashCode = this.GetHashCode(currentUndoablePropertyChange);

            this.Reset();

            UndoablePropertyChange rootUndoablePropertyChange;

            if (!this.rootUndoablePropertyChanges.TryGetValue(hashCode, out rootUndoablePropertyChange))
            {
                rootUndoablePropertyChange = currentUndoablePropertyChange;
                this.rootUndoablePropertyChanges.Add(hashCode, currentUndoablePropertyChange);
            }

            this.rootUndoablePropertyChanges[hashCode] = new UndoablePropertyChange(
                rootUndoablePropertyChange.ModelObject,
                rootUndoablePropertyChange.PropertyDescriptor.Name,
                rootUndoablePropertyChange.OldValue,
                currentUndoablePropertyChange.NewValue);

            foreach (UndoablePropertyChange undoablePropertyChange in this.rootUndoablePropertyChanges.Values)
            {
                base.AddUndoable(undoablePropertyChange);
            }
        }
コード例 #12
0
        public void AddRemove(int collectionOwnerId, IUndoable removedObjectState, int indexAt, string description, int clientId)
        {
            var removeChange = new Change(ChangeReason.RemoveAt, collectionOwnerId, removedObjectState.Id,
                                          removedObjectState, indexAt);

            _transactionService.Add(removeChange, clientId, description);
        }
コード例 #13
0
ファイル: UndoEngine.cs プロジェクト: bartwe/Gearset
        /// <summary>
        ///     Adds a command to the history without executing it. This is usefull if
        ///     the command was executed somewhere else but still needs undo/redo.
        /// </summary>
        /// <param name="currentMover"></param>
        public void AddCommand(IUndoable command)
        {
            _undoStack.AddLast(command);

            // Clear the redo stack (it might be empty already) because we just editted.
            _redoStack.Clear();
        }
コード例 #14
0
 public DoAction(
     ObservableStack <IUndoable> undoableActions, ObservableStack <IUndoable> redoableActions, IUndoable action)
 {
     _undoableActions = undoableActions;
     _redoableActions = redoableActions;
     _action          = action;
 }
コード例 #15
0
 /// <summary>
 /// Determines whether this UndoableGroup or the CurrentUndoable can contain the specified IUndoable.
 /// </summary>
 /// <param name="undoable">The IUndoable to check for containability.</param>
 /// <returns><c>true</c> if the specified IUndoable can be contained by this UndoableGroup, <c>false</c> otherwise.</returns>
 public bool CanContain(IUndoable undoable)
 {
     if (this.CurrentUndoable != null && this.CurrentUndoable.CanContain(undoable))
     {
         return(true);
     }
     return(this.CanContainUndoable(undoable));
 }
コード例 #16
0
 /// <summary>
 /// Determines whether this UndoableGroup can contain the specified IUndoable directly.
 /// </summary>
 /// <param name="undoable">The IUndoable to check for containability.</param>
 /// <returns>
 ///     <c>true</c> if the specified IUndoable can be contained by this UndoableGroup, <c>false</c> otherwise.
 /// </returns>
 protected override bool CanContainUndoable(IUndoable undoable)
 {
     if (DateTime.Now.Subtract(this.lastAddTime) <= groupingTimeout)
     {
         return(true);
     }
     return(false);
 }
コード例 #17
0
 /// <summary>
 /// Ctor for update.
 /// </summary>
 /// <param name="changeReason"></param>
 /// <param name="ownerId"></param>
 /// <param name="undoObjectState"></param>
 /// <param name="redoObjectState"></param>
 public Change(int ownerId, IUndoable undoObjectState, IUndoable redoObjectState)
 {
     UndoObjectState = undoObjectState;
     RedoObjectState = redoObjectState;
     ChangeReason    = ChangeReason.Update;
     OwnerId         = ownerId;
     ItemId          = ownerId;
 }
コード例 #18
0
 /// <summary>
 /// Undo the last action.
 /// </summary>
 public void Undo()
 {
     if (UndoableActions.Count > 0)
     {
         IUndoable action = UndoableActions.Pop();
         action.Undo();
         RedoableActions.Push(action);
     }
 }
コード例 #19
0
 /// <summary>
 /// Adds the specified IUndoable to this UndoableGroup if it can be contained.
 /// </summary>
 /// <param name="undoable">The IUndoable to add to this UndoableGroup.</param>
 /// <returns><c>true</c> if the specified IUndoable was added to this UndoableGroup, <c>false</c> otherwise.</returns>
 public virtual bool Add(IUndoable undoable)
 {
     if (this.CanContain(undoable))
     {
         this.AddUndoable(undoable);
         return(true);
     }
     return(false);
 }
コード例 #20
0
        /// <summary>
        /// Determines whether this UndoableExplicitGroup can contain the specified IUndoable directly.
        /// </summary>
        /// <param name="undoable">The IUndoable to check for containability.</param>
        /// <returns>
        ///     <c>true</c> if the specified IUndoable can be contained by this UndoableGroup, <c>false</c> otherwise.
        /// </returns>
        protected override bool CanContainUndoable(IUndoable undoable)
        {
            if (!base.CanContainUndoable(undoable) || !(undoable is UndoablePropertyChange))
            {
                return(false);
            }

            return(true);
        }
コード例 #21
0
 /// <summary>
 /// Redo the last undone action.
 /// </summary>
 public void Redo()
 {
     if (RedoableActions.Count > 0)
     {
         IUndoable action = RedoableActions.Pop();
         action.Execute();
         UndoableActions.Push(action);
     }
 }
コード例 #22
0
        public DesignerCanvas()
        {
            string initialStore = this.StoreDiagram().ToString();

            this.diagramState = new Undoable <string>(initialStore);

            designerItems = new List <DesignerItem>();

            //this.CommandBindings.Add(new CommandBinding(ApplicationCommands.New, New_Executed));
            //this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Open, Open_Executed));
            //this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Save, Save_Executed));
            //this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Print, Print_Executed));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Cut, Cut_Executed, Cut_Enabled));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Copy, Copy_Executed, Copy_Enabled));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Paste, Paste_Executed, Paste_Enabled));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Delete, Delete_Executed, Delete_Enabled));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Undo, Undo_Executed, Undo_Enabled));
            this.CommandBindings.Add(new CommandBinding(ApplicationCommands.Redo, Redo_Executed, Redo_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.Group, Group_Executed, Group_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.Ungroup, Ungroup_Executed, Ungroup_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.BringForward, BringForward_Executed, Order_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.BringToFront, BringToFront_Executed, Order_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.SendBackward, SendBackward_Executed, Order_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.SendToBack, SendToBack_Executed, Order_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignTop, AlignTop_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignVerticalCenters, AlignVerticalCenters_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignBottom, AlignBottom_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignLeft, AlignLeft_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignHorizontalCenters, AlignHorizontalCenters_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.AlignRight, AlignRight_Executed, Align_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.DistributeHorizontal, DistributeHorizontal_Executed, Distribute_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.DistributeVertical, DistributeVertical_Executed, Distribute_Enabled));
            this.CommandBindings.Add(new CommandBinding(DesignerCanvas.SelectAll, SelectAll_Executed));

            //this.InputBindings.Add(new KeyBinding(ApplicationCommands.Delete,Key.))
            ApplicationCommands.Delete.InputGestures.Add(new KeyGesture(Key.Delete));
            SelectAll.InputGestures.Add(new KeyGesture(Key.A, ModifierKeys.Control));

            this.AllowDrop = true;

            SelectionService.SelectionChanged += () =>
            {
                if (SelectionChanged != null)
                {
                    SelectionChanged(this, null);
                }

                OnPropertyChanged("SelectedItems");
                OnPropertyChanged("SelectionLayer");
            };

            this.ConnectionGenerator = (source, sink, pathFinder) => new Connection(source, sink, pathFinder);

            this.RequestBringIntoView += DesignerCanvas_RequestBringIntoView;

            this.PreviewMouseWheel += DesignerCanvas_PreviewMouseWheel;
        }
コード例 #23
0
        public void AddUndo(IUndoable <T> action, bool fileDirty)
        {
            if (!fileDirty)
            {
                undoCleanAction = action;
            }

            AddUndoInternal(action);
            ClearRedo();
        }
コード例 #24
0
 /// <summary>
 /// 执行撤销操作
 /// </summary>
 public virtual void Undo(XUndoEventArgs args)
 {
     for (int iCount = myItems.Count - 1; iCount >= 0; iCount--)
     {
         IUndoable undo = ( IUndoable )myItems[iCount];
         undo.InGroup = true;
         undo.Undo(args);
         //( ( IUndoable )myItems[ iCount ]).Undo();
     }
 }
コード例 #25
0
 /// <summary>
 /// Adds the specified IUndoable to this UndoManager.
 /// </summary>
 /// <param name="undoable">The IUndoable to add to this UndoManager.</param>
 protected override void AddUndoable(IUndoable undoable)
 {
     // If there is no current undoable or the timeout on the current undoable temporal group has expired,
     // create a new undoable temporal group before adding the specified IUndoable
     if (this.CurrentUndoable == null || !(this.CurrentUndoable is UndoableTemporalGroup) || !((UndoableTemporalGroup)this.CurrentUndoable).CanContain(undoable))
     {
         base.AddUndoable(new UndoableTemporalGroup(this.GroupingTimeout));
     }
     base.AddUndoable(undoable);
 }
コード例 #26
0
ファイル: XUndoList.cs プロジェクト: ywscr/CSharpWriter
 /// <summary>
 /// 添加一个撤销动作对象到列表中
 /// </summary>
 /// <param name="undo">要添加的撤销动作对象</param>
 public void Add(IUndoable undo)
 {
     if (undo == null || myLogItems == null || myLogItems.Contains(undo))
     {
         return;
     }
     if (myLogItems != null)
     {
         myLogItems.Add(undo);
     }
 }
コード例 #27
0
        private void AddRedo(IUndoable <T> action)
        {
            redoStack.Push(action);

            if (redoStack.Count == 1)
            {
                redoAvailable.OnNext(true);
            }

            redoDescription.OnNext(action.Description);
        }
コード例 #28
0
        private void AddUndoInternal(IUndoable <T> action)
        {
            undoStack.Push(action);

            if (undoStack.Count == 1)
            {
                undoAvailable.OnNext(true);
            }

            undoDescription.OnNext(action.Description);
        }
コード例 #29
0
        /// <summary>
        /// Save the current state of the object so that you can revert to it if necessary.
        /// </summary>
        public void CreateSnapshot()
        {
            Type      currentType;
            Hashtable state = new Hashtable();

            FieldInfo[] fields;
            string      fieldName;

            _bindingEdit = true;

            currentType = this.GetType();

            do
            {
                // Get the member-fields of this type
                fields = currentType.GetFields(BindingFlags.Public |
                                               BindingFlags.NonPublic |
                                               BindingFlags.Instance);

                foreach (FieldInfo field in fields)
                {
                    // If this field is declared in the current-type, and, it is
                    // a field that is undoable, then keep track of its state.
                    if (field.DeclaringType == currentType &&
                        this.IsUndoableField(field))
                    {
                        object fieldValue = field.GetValue(this);

                        // If the field is an IUndoable type, cascade the call.
                        IUndoable uf = fieldValue as IUndoable;

                        if (uf != null)
                        {
                            uf.CreateSnapshot();
                        }
                        else
                        {
                            fieldName = currentType.Name + "." + field.Name;
                            state.Add(fieldName, fieldValue);
                        }
                    }
                }

                currentType = currentType.BaseType;
            } while(currentType != typeof(BusinessObject));

            // Now we have saved the complete state of the object in the
            // hashtable.  We need to stack it into the state-stack.
            MemoryStream    buffer = new MemoryStream();
            BinaryFormatter fmt    = new BinaryFormatter();

            fmt.Serialize(buffer, state);
            _stateStack.Push(buffer.ToArray());   // Stack it as a byte-array
        }
        // HOW-TO: Request a COM interface
        public static void How_to_request_a_COM_interface(IEngine engine)
        {
            // If a COM object supports multiple interfaces, you can query
            // the required interface by casting the object to this interface.

            // For example, FlexiCapture documents support undo/redo operations.
            // This feature is available through an auxiliary interface IUndoable:
            trace("Cast the object to the required interface.");
            IDocument document = PrepareNewRecognizedDocument(engine);
            IUndoable undoable = document as IUndoable;
        }
コード例 #31
0
 public void OnRedo(IUndoable data)
 {
     if (data.Name == "Position")
     {
         OnPropertyChanged("X");
         OnPropertyChanged("Y");
     }
     else
     {
         OnPropertyChanged(data.Name);
     }
 }
コード例 #32
0
ファイル: CommandHistory.cs プロジェクト: voporak5/CardGames
    public bool Redo()
    {
        bool result = redoStack.Count > 0;

        if (result)
        {
            IUndoable c = redoStack.Pop();
            undoStack.Push(c);
            c.Redo();
        }
        return(result);
    }
コード例 #33
0
        public void makelike(IUndoable other)
        {
            /*Layer l2 = (Layer)other;
            Items = l2.Items;
            treenode.Nodes.Clear();
            foreach (Item i in Items)
            {
                Editor.Instance.addItem(i);
            }*/

            Level l2 = (Level)other;
            Layers = l2.Layers;
            treenode.Nodes.Clear();
            foreach (Layer l in Layers)
            {
                Editor.Instance.addLayer(l);
                //TODO add all items
            }
        }
コード例 #34
0
ファイル: UndoBuffer.cs プロジェクト: rmbzlib/mcskin3d
 public void AddBuffer(IUndoable undoable)
 {
     if (CurrentIndex == Undos.Count)
         Undos.Add(undoable);
     else
     {
         Undos.RemoveRange(CurrentIndex, Undos.Count - CurrentIndex);
         Undos.Add(undoable);
         CurrentIndex = Undos.Count;
     }
 }
コード例 #35
0
ファイル: Undo.cs プロジェクト: lgatto/proteowizard
        /// <summary>
        /// Constructor for associating an <see cref="UndoManager"/>
        /// with a <see cref="IUndoable"/>.  The generalized interface
        /// makes it possible to unit test this class separate from
        /// <see cref="SrmDocument"/>, though in the running application,
        /// it is always managing references to document instances.
        /// </summary>
        /// <param name="client">Undo state provider</param>
        public UndoManager(IUndoable client)
        {
            _client = client;

            _undoStack = new Stack<UndoRecord>();
            _redoStack = new Stack<UndoRecord>();
        }
コード例 #36
0
ファイル: GateUndos.cs プロジェクト: buptkang/LogicPad
 public Reverse(IUndoable iud, string name)
 {
     this.iud = iud;
     this.name = name;
 }
コード例 #37
0
ファイル: UndoEngine.cs プロジェクト: bartwe/Gearset
 /// <summary>
 ///     Executes a command and adds it to the command history so it can
 ///     be undone/redone.
 /// </summary>
 /// <param name="command">The command to execute and keep history of.</param>
 public void Execute(IUndoable command)
 {
     command.Do();
     AddCommand(command);
 }
コード例 #38
0
ファイル: GateUndos.cs プロジェクト: buptkang/LogicPad
 public Reverse(IUndoable iud)
 {
     this.iud = iud;
     this.name = iud.Name;
 }