Beispiel #1
0
        private void DiscardChangesAndOptionallyRemoveNode(UndoRedoRecorder recorder)
        {
            if (!string.IsNullOrEmpty(InnerTextEditor.Text))
            {
                throw new InvalidOperationException(
                          "This method is meant only for empty text box");
            }

            if (createdForNewCodeBlock)
            {
                // If this editing was started due to a new code block node,
                // then by this point the creation of the node would have been
                // recorded, we need to pop that off the undo stack. Note that
                // due to various external factors a code block node loaded
                // from file may be created empty. In such cases, the creation
                // step would not have been recorded (there was no explicit
                // creation of the node, it was created from loading of a file),
                // and nothing should be popped off of the undo stack.
                //
                if (recorder.CanUndo)
                {
                    recorder.PopFromUndoGroup(); // Pop off creation action.
                }
            }
            else
            {
                // If the editing was started for an existing code block node,
                // and user deletes the text contents, it should be restored to
                // the original codes.
                InnerTextEditor.Text = codeBlockNode.Code;
            }
        }
Beispiel #2
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            var converter = new IntegerDisplay();

            switch (name)
            {
            case "Value":
                Value = ((int)converter.ConvertBack(value, typeof(int), null, null));
                return(true);    // UpdateValueCore handled.

            case "Max":
                Max = ((int)converter.ConvertBack(value, typeof(int), null, null));
                return(true);    // UpdateValueCore handled.

            case "Min":
                Min = ((int)converter.ConvertBack(value, typeof(int), null, null));
                if (Value >= Max)
                {
                    this.Max = Value;
                }
                if (Value <= Min)
                {
                    this.Min = Value;
                }
                return(true);    // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #3
0
 public void TestConstructor()
 {
     Assert.Throws <ArgumentNullException>(() =>
     {
         UndoRedoRecorder temp = new UndoRedoRecorder(null);
     });
 }
Beispiel #4
0
        protected WorkspaceModel(
            string name, IEnumerable <NodeModel> e, IEnumerable <NoteModel> n,
            double x, double y, NodeFactory factory)
        {
            Name = name;

            nodes = new ObservableCollection <NodeModel>(e);
            notes = new ObservableCollection <NoteModel>(n);
            X     = x;
            Y     = y;

            HasUnsavedChanges = false;
            LastSaved         = DateTime.Now;

            WorkspaceVersion = AssemblyHelper.GetDynamoVersion();
            undoRecorder     = new UndoRedoRecorder(this);

            NodeFactory = factory;

            foreach (var node in nodes)
            {
                RegisterNode(node);
            }

            foreach (var connector in Connectors)
            {
                RegisterConnector(connector);
            }
        }
        private void RecordModels(UndoRedoRecorder recorder)
        {
            if (model.InPorts.Count == 0)
            {
                return;
            }

            var connectors = model.InPorts.Last().Connectors;

            if (connectors.Count != 0)
            {
                if (connectors.Count != 1)
                {
                    throw new InvalidOperationException(
                              "There should be only one connection to an input port");
                }
                var models = new Dictionary <ModelBase, UndoRedoRecorder.UserAction>
                {
                    { connectors[0], UndoRedoRecorder.UserAction.Deletion },
                    { model, UndoRedoRecorder.UserAction.Modification }
                };
                WorkspaceModel.RecordModelsForUndo(models, recorder);
            }
            else
            {
                WorkspaceModel.RecordModelForModification(model, recorder);
            }
        }
Beispiel #6
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name != "Code")
            {
                return(base.UpdateValueCore(name, value, recorder));
            }

            //Remove the UpdateValue's recording
            recorder.PopFromUndoGroup();

            value = CodeBlockUtils.FormatUserText(value);

            //Since an empty Code Block Node should not exist, this checks for such instances.
            // If an empty Code Block Node is found, it is deleted. Since the creation and deletion of
            // an empty Code Block Node should not be recorded, this method also checks and removes
            // any unwanted recordings
            if (value == "")
            {
                Code = "";
            }
            else
            {
                if (!value.Equals(Code))
                {
                    SetCodeContent(value, recorder);
                }
            }
            return(true);
        }
Beispiel #7
0
        public bool HandleModelEventCore(string eventName, UndoRedoRecorder recorder)
        {
            if (eventName == "AddInPort")
            {
                AddInputToModel();
                model.RegisterAllPorts();
                return(true); // Handled here.
            }

            if (eventName == "RemoveInPort")
            {
                // When an in-port is removed, it is possible that a connector
                // is almost removed along with it. Both node modification and
                // connector deletion have to be recorded as one action group.
                // But before HandleModelEventCore is called, node modification
                // has already been recorded (in WorkspaceModel.SendModelEvent).
                // For that reason, that entry on the undo-stack needs to be
                // popped (the node modification will be recorded here instead).
                //
                recorder.PopFromUndoGroup();

                RecordModels(recorder);
                RemoveInputFromModel();
                model.RegisterAllPorts();
                return(true); // Handled here.
            }

            return(false); // base.HandleModelEventCore(eventName);
        }
 public void setup()
 {
     lineList = new List<string>();
     lineList.Add("first line\n");
     lineList.Add("second line\n");
     lineList.Add("third line");
     undoRedoRecorder = new UndoRedoRecorder(lineList);
 }
Beispiel #9
0
 public void setup()
 {
     lineList = new List <string>();
     lineList.Add("first line\n");
     lineList.Add("second line\n");
     lineList.Add("third line");
     undoRedoRecorder = new UndoRedoRecorder(lineList);
 }
Beispiel #10
0
        public void TestRecordNodeModificationForUndo02()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            urr.BeginGroup();
            urr.RecordNodeModificationForUndo(new List <IVisualNode>());
            Assert.AreEqual(0, urr.ActionCount);
        }
Beispiel #11
0
        public void TestRecordNodeDeletionForUndo01()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            urr.BeginGroup();
            urr.RecordNodeDeletionForUndo(null);
            Assert.AreEqual(0, urr.ActionCount);
        }
Beispiel #12
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name != "Text")
            {
                return(base.UpdateValueCore(name, value, recorder));
            }

            Text = value;
            return(true);
        }
Beispiel #13
0
        public void TestRedo()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            DeltaNodes deltaNodes = new DeltaNodes();
            bool       result     = urr.Redo(deltaNodes);

            Assert.AreEqual(false, result);
        }
Beispiel #14
0
        public void TestPopRecordFromUndoStorage00()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            Assert.Throws <InvalidOperationException>(() =>
            {
                urr.PopRecordFromUndoStorage();
            });
        }
Beispiel #15
0
        public void TestEndGroup()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            Assert.Throws <InvalidOperationException>(() =>
            {
                urr.EndGroup();
            });
        }
Beispiel #16
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "FormulaString")
            {
                FormulaString = value;
                return(true); // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #17
0
 // See RecordModelsForModification below for more details.
 public static void RecordModelForModification(ModelBase model, UndoRedoRecorder recorder)
 {
     if (null != model)
     {
         var models = new List <ModelBase> {
             model
         };
         RecordModelsForModification(models, recorder);
     }
 }
Beispiel #18
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "InputSymbol")
            {
                InputSymbol = value;
                return(true); // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #19
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "ScriptContent")
            {
                script = value;
                return true;
            }

            return base.UpdateValueCore(name, value, recorder);
        }
Beispiel #20
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "Value")
            {
                var converter = new MeasureConverter();
                this.Value = ((double)converter.ConvertBack(value, typeof(double), Measure, null));
                return(true); // UpdateValueCore handled.
            }

            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #21
0
        public void TestRecordEdgeModificationForUndo01()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            Assert.Throws <ArgumentException>(() =>
            {
                urr.BeginGroup();
                urr.RecordEdgeModificationForUndo(null);
            });
        }
Beispiel #22
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "Value")
            {
                var converter = new StringDisplay();
                Value = converter.ConvertBack(value, typeof(string), null, null) as string;
                return(true);
            }

            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #23
0
        public void TestRecordRuntimeStatesForUndo00()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);
            RuntimeStates    runtimeStates   = new RuntimeStates();

            Assert.Throws <InvalidOperationException>(() =>
            {
                urr.RecordRuntimeStatesForUndo(runtimeStates);
            });
        }
Beispiel #24
0
        public void TestRecordRuntimeStatesForUndo01()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            Assert.Throws <ArgumentNullException>(() =>
            {
                urr.BeginGroup();
                urr.RecordRuntimeStatesForUndo(null);
            });
        }
Beispiel #25
0
        public void TestRecordEdgeCreationForUndo02()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            Assert.Throws <ArgumentException>(() =>
            {
                urr.BeginGroup();
                urr.RecordEdgeCreationForUndo(new List <IVisualEdge>());
            });
        }
Beispiel #26
0
        protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder)
        {
            if (name == "Value")
            {
                Value = HttpUtility.HtmlEncode(value);
                return(true); // UpdateValueCore handled.
            }

            // There's another 'UpdateValueCore' method in 'String' base class,
            // since they are both bound to the same property, 'StringInput'
            // should be given a chance to handle the property value change first
            // before the base class 'String'.
            return(base.UpdateValueCore(name, value, recorder));
        }
Beispiel #27
0
        public void TestRecordNodeModficationForUndo00()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);

            List <IVisualNode> nodeList = new List <IVisualNode>();
            DriverNode         node     = new DriverNode(graphController);

            nodeList.Add(node);

            Assert.Throws <InvalidOperationException>(() =>
            {
                urr.RecordNodeModificationForUndo(nodeList);
            });
        }
Beispiel #28
0
        public void TestRecordEdgeCreationForUndo00()
        {
            GraphController  graphController = new GraphController(null);
            UndoRedoRecorder urr             = new UndoRedoRecorder(graphController);
            EdgeController   edgeController  = new EdgeController(graphController);

            List <IVisualEdge> edgeList = new List <IVisualEdge>();
            VisualEdge         edge     = new VisualEdge(edgeController, EdgeType.ExplicitConnection);

            edgeList.Add(edge);

            Assert.Throws <InvalidOperationException>(() =>
            {
                urr.RecordEdgeCreationForUndo(edgeList);
            });
        }
Beispiel #29
0
        public void SetCodeContent(string newCode, UndoRedoRecorder recorder)
        {
            if (code != null && code.Equals(newCode))
            {
                return;
            }

            if (newCode == null)
            {
                code = null;
            }
            else
            {
                string errorMessage   = string.Empty;
                string warningMessage = string.Empty;

                using (recorder.BeginActionGroup())
                {
                    var inportConnections  = new OrderedDictionary();
                    var outportConnections = new OrderedDictionary();
                    //Save the connectors so that we can recreate them at the correct positions
                    SaveAndDeleteConnectors(inportConnections, outportConnections, recorder);

                    code = newCode;
                    ProcessCode(ref errorMessage, ref warningMessage);

                    //Recreate connectors that can be reused
                    LoadAndCreateConnectors(inportConnections, outportConnections, recorder);
                }

                RaisePropertyChanged("Code");
                ForceReExecuteOfNode = true;
                OnAstUpdated();
                ReportPosition();

                ClearRuntimeError();
                if (!string.IsNullOrEmpty(errorMessage))
                {
                    Error(errorMessage);
                }
                else if (!string.IsNullOrEmpty(warningMessage))
                {
                    Warning(warningMessage);
                }
            }
        }
Beispiel #30
0
        internal bool HandleModelEventCore(string eventName, UndoRedoRecorder recorder)
        {
            switch (eventName)
            {
            case "AddInPort":
                AddInputToModel();
                model.RegisterAllPorts();
                return(true);    // Handled here.

            case "RemoveInPort":
                RemoveInputFromModel();
                model.RegisterAllPorts();
                return(true);    // Handled here.
            }

            return(false); // base.HandleModelEventCore(eventName);
        }
Beispiel #31
0
        protected WorkspaceModel(
            String name, IEnumerable <NodeModel> e, IEnumerable <ConnectorModel> c, double x, double y)
        {
            Name = name;

            Nodes      = new TrulyObservableCollection <NodeModel>(e);
            Connectors = new TrulyObservableCollection <ConnectorModel>(c);
            Notes      = new ObservableCollection <NoteModel>();
            X          = x;
            Y          = y;

            HasUnsavedChanges = false;
            LastSaved         = DateTime.Now;

            WorkspaceSaved  += OnWorkspaceSaved;
            WorkspaceVersion = AssemblyHelper.GetDynamoVersion();
            undoRecorder     = new UndoRedoRecorder(this);
        }