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; } }
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)); }
public void TestConstructor() { Assert.Throws <ArgumentNullException>(() => { UndoRedoRecorder temp = new UndoRedoRecorder(null); }); }
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); } }
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); }
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); }
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); }
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); }
public void TestRecordNodeDeletionForUndo01() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); urr.BeginGroup(); urr.RecordNodeDeletionForUndo(null); Assert.AreEqual(0, urr.ActionCount); }
protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder) { if (name != "Text") { return(base.UpdateValueCore(name, value, recorder)); } Text = value; return(true); }
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); }
public void TestPopRecordFromUndoStorage00() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); Assert.Throws <InvalidOperationException>(() => { urr.PopRecordFromUndoStorage(); }); }
public void TestEndGroup() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); Assert.Throws <InvalidOperationException>(() => { urr.EndGroup(); }); }
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)); }
// 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); } }
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)); }
protected override bool UpdateValueCore(string name, string value, UndoRedoRecorder recorder) { if (name == "ScriptContent") { script = value; return true; } return base.UpdateValueCore(name, value, recorder); }
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)); }
public void TestRecordEdgeModificationForUndo01() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); Assert.Throws <ArgumentException>(() => { urr.BeginGroup(); urr.RecordEdgeModificationForUndo(null); }); }
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)); }
public void TestRecordRuntimeStatesForUndo00() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); RuntimeStates runtimeStates = new RuntimeStates(); Assert.Throws <InvalidOperationException>(() => { urr.RecordRuntimeStatesForUndo(runtimeStates); }); }
public void TestRecordRuntimeStatesForUndo01() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); Assert.Throws <ArgumentNullException>(() => { urr.BeginGroup(); urr.RecordRuntimeStatesForUndo(null); }); }
public void TestRecordEdgeCreationForUndo02() { GraphController graphController = new GraphController(null); UndoRedoRecorder urr = new UndoRedoRecorder(graphController); Assert.Throws <ArgumentException>(() => { urr.BeginGroup(); urr.RecordEdgeCreationForUndo(new List <IVisualEdge>()); }); }
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)); }
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); }); }
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); }); }
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); } } }
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); }
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); }