コード例 #1
0
        // implement IChangeDataValue for undo/redo
        public void ChangeDataValue(ModelChangedEventArgs e, bool undo)
        {
            switch (e.PropertyName)
            {
            case "Color": this.Color = (String)e.GetValue(undo); break;

            default: throw new NotImplementedException("Socket change: " + e.ToString());
            }
        }
コード例 #2
0
        void model_Changed(object sender, ModelChangedEventArgs e)
        {
            // add an entry to the log
            if (e.Change >= 0)
            {
                if (ShowChanges.IsChecked == true)
                {
                    myLog.Text += e.ToString() + Environment.NewLine;
                    myScroller.ScrollToVerticalOffset(9e9);
                }
            }
            else
            {
                if (ShowLayouts.IsChecked == true ||
                    (!"Layout".Equals(e.Data) && !"DelayedRouting".Equals(e.Data)))
                {
                    myLog.Text += e.ToString() + Environment.NewLine;
                    myScroller.ScrollToVerticalOffset(9e9);
                }
            }
            // add an item to the tree view showing the UndoManager state
            if (e.Change == ModelChange.CommittedTransaction)
            {
                UndoManager.CompoundEdit cedit = e.OldValue as UndoManager.CompoundEdit;
                if (cedit != null)
                {
                    if (this.EditToRedo != null)
                    {
                        // remove from TreeView all transactions starting with this.EditToRedo
                        ItemCollection coll = myTreeView.Items;
                        int            idx  = coll.IndexOf(this.EditToRedo);
                        if (idx >= 0)
                        {
                            while (coll.Count > idx)
                            {
                                coll.RemoveAt(idx);
                            }
                        }
                        this.EditToRedo = null;
                    }
                    // add a TreeViewItem representing the completed transaction
                    TreeViewItem citem = new TreeViewItem();
                    citem.Tag    = cedit;
                    citem.Header = cedit.Name;
                    // all of the changes within the transaction are tree view children
                    foreach (IUndoableEdit edit in cedit.Edits)
                    {
                        TreeViewItem eitem = new TreeViewItem();
                        eitem.Tag    = edit;
                        eitem.Header = edit.ToString();
                        citem.Items.Add(eitem);
                    }
                    myTreeView.Items.Add(citem);
#if !SILVERLIGHT
                    citem.BringIntoView();
#endif
                }
            }
            else if (e.Change == ModelChange.FinishedUndo || e.Change == ModelChange.FinishedRedo)
            {
                // unselect any currently selected transaction
                if (this.EditToRedo != null)
                {
                    this.EditToRedo.IsSelected = false;
                    this.EditToRedo            = null;
                }
                IUndoableEdit nextedit = myDiagram.Model.UndoManager.EditToRedo;
                if (nextedit != null)
                {
                    // find the next edit to redo, and select it
                    foreach (TreeViewItem item in myTreeView.Items)
                    {
                        if (item.Tag == nextedit)
                        {
                            item.IsSelected = true;
#if !SILVERLIGHT
                            item.BringIntoView();
#endif
                            this.EditToRedo = item;
                            break;
                        }
                    }
                }
            }
        }