private void MoveLeft(KeyEventArgs args) { var oldPos = GetCursorPosInt(); int nextPos = Math.Max(0, GetCursorPosInt() - 1); if (args.Control) { Regex r = new Regex(@"\S*\s*$"); string before = Text.Substring(0, GetCursorPosInt()); nextPos = r.Match(before).Index; } CursorPos = new CP(nextPos); if (args.Shift) { if (SelectionLength <= 0) { SelectionLength -= GetCursorPosInt() - oldPos; } else { SelectionLength -= GetCursorPosInt() - oldPos; } } else { SelectionLength = 0; } Redraw(); m_additionUndoAction = null; }
private void MoveUp(KeyEventArgs args) { if (m_dropDownOpen) { ItemIndex--; } else { if (args.Shift) { var selectionEnd = GetCursorPosInt() + SelectionLength; var point = CursorToXY(CursorPos.GetUV(GetLines().ToList())); point.Y -= Font.Height; CursorPos = XYToCursor(point.X, point.Y); SelectionLength = selectionEnd - GetCursorPosInt(); } else { SelectionLength = 0; var point = CursorToXY(CursorPos.GetUV(GetLines().ToList())); point.Y -= Font.Height; CursorPos = XYToCursor(point.X, point.Y); } Redraw(); m_additionUndoAction = null; } }
private void Delete(KeyEventArgs args) { if (InputForm != InputFormEnum.None) { var undo = MakeUndoAction(); if (SelectionLength != 0) { DeleteSelection(); } else if (GetCursorPosInt() < Text.Length) { if (args.Control) { Regex r = new Regex(@"\s*\S*"); SelectionLength = r.Match(Text, GetCursorPosInt()).Length; DeleteSelection(); } else { Text = Text.Remove(GetCursorPosInt(), 1); } Redraw(); } m_additionUndoAction = null; undo.SetRedo(m_state); } }
private void Backspace(KeyEventArgs args) { if (InputForm != InputFormEnum.None) { var undo = MakeUndoAction(); if (SelectionLength != 0) { DeleteSelection(); } else if (GetCursorPosInt() > 0) { if (args.Control) { Regex r = new Regex(@"\S*\s*$"); string before = Text.Substring(0, GetCursorPosInt()); var match = r.Match(before); CursorPos = new CP(match.Index); SelectionLength = match.Length; DeleteSelection(); } else { Text = Text.Remove(GetCursorPosInt() - 1, 1); var lines = GetLines().ToList(); CursorPos = new CP(Math.Max(0, CursorPos.Pos - 1), CursorPos.GetUV(lines).X == 0); } Redraw(); } m_additionUndoAction = null; undo.SetRedo(m_state); } }
private void MoveRight(KeyEventArgs args) { var oldPos = GetCursorPosInt(); int nextPos = 1; if (args.Control) { Regex r = new Regex(@"\s*\S*"); nextPos = r.Match(Text, GetCursorPosInt()).Length; } CursorPos = new CP(CursorPos.Pos + nextPos); if (args.Shift) { if (SelectionLength <= 0) { SelectionLength -= GetCursorPosInt() - oldPos; } else { SelectionLength -= GetCursorPosInt() - oldPos; } } else { SelectionLength = 0; } Redraw(); m_additionUndoAction = null; }
public void SetTrapezoidal(bool val) { if (val != IsTrapezoidal) { AttChange change = new AttChange(); List <float> prop = new List <float>(); prop.Add((float)this.GetId()); prop.Add((float)0.0); prop.Add((float)0.0); prop.Add((float)1.0); // value of attribute index,, not nessesary but just frameword for case of adding attributes prop.Add((float)1.0); // value as a sign of revertion of bool attribute change.SetChange(prop); UndoAction undoAction = new UndoAction(); undoAction.AddChange(change); GUICircuitComponent.globalUndoList.AddUndo(undoAction); } IsTrapezoidal = val; if (GameObject.Find("PlayToggle").GetComponent <UnityEngine.UI.Toggle>().isOn) { GameObject.Find("PlayButton").GetComponent <GUICircuit>().RunSimulation(); } }
public void onInspectorPostFieldModification() { GuiEditorProfilesTree GuiEditorProfilesTree = "GuiEditorProfilesTree"; GuiEditorProfileChangeManager GuiEditorProfileChangeManager = "GuiEditorProfileChangeManager"; GuiEditorGui.GuiEditor GuiEditor = "GuiEditor"; ProfilePane ProfilePane = "ProfilePane"; UndoAction action = this.currentFieldEditAction; SimObject objectx = action["objectId"]; string fieldName = action["fieldName"]; string arrayIndex = action["arrayIndex"]; string oldValue = action["fieldValue"]; string newValue = objectx.getFieldValue(fieldName, arrayIndex == "(null)" ? -1 : arrayIndex.AsInt()); // If it's the name field, make sure to sync up the treeview. if (action["fieldName"] == "name") { GuiEditorProfilesTree.onProfileRenamed(objectx, newValue); } ProfilePane.onProfileSelected(); // Add change record. GuiEditorProfileChangeManager.registerEdit(objectx, fieldName, arrayIndex, oldValue); this.currentFieldEditAction.addToManager(ProfilePane.getUndoManager()); this.currentFieldEditAction = ""; //GuiEditor.updateUndoMenu(); GuiEditor.setProfileDirty(objectx, true, false); }
//Rotate functionality to invoke rotation from button, -90 degrees public void RoateCounterClockWise() { if (SelectObject.SelectedObjects.Count == 1) { foreach (GameObject objectSelected in SelectObject.SelectedObjects) { Vector3 curentPos = objectSelected.transform.position; objectSelected.transform.Rotate(new Vector3(0, 0, +90)); Vector3 finalPos = objectSelected.transform.position; List <float> properties = new List <float>(); properties.Add(objectSelected.GetComponent <GUICircuitComponent>().GetId()); properties.Add(curentPos[0] - finalPos[0]); properties.Add(curentPos[1] - finalPos[1]); properties.Add(-90); PosChange change = new PosChange(); change.SetChange(properties); UndoAction undoAction = new UndoAction(); undoAction.AddChange(change); GUICircuitComponent.globalUndoList.AddUndo(undoAction); } //transform position of each lines in scene Line.TransformLines(); } }
/// <summary> /// Creates an object that describes both the value and the undo action to a command. /// </summary> /// <param name="value">The value of the object.</param> /// <param name="undoAction">The Undo action.</param> public UndoObject(object oldValue, object newValue, UndoAction undoAction) { // Initialize the object this.oldValueField = oldValue; this.newValueField = newValue; this.undoActionField = undoAction; }
public void SetInductance(double val) { if (Inductance != val) { AttChange change = new AttChange(); List <float> prop = new List <float>(); prop.Add((float)this.GetId()); prop.Add((float)1.0); // value of attribute index,, not nessesary but just frameword for case of adding attributes prop.Add((float)(Inductance - val)); prop.Add((float)0.0); // hodnoty ostatnych atributov sa nezmenia prop.Add((float)0.0); change.SetChange(prop); UndoAction undoAction = new UndoAction(); undoAction.AddChange(change); GUICircuitComponent.globalUndoList.AddUndo(undoAction); } Inductance = val; if (GameObject.Find("PlayToggle").GetComponent <UnityEngine.UI.Toggle>().isOn) { GameObject.Find("PlayButton").GetComponent <GUICircuit>().RunSimulation(); } }
private UndoAction MakeUndoAction() { var result = new UndoAction(m_state, s => { Text = s.Text; CursorPos = s.CursorPos; SelectionLength = s.SelectionLength; }); m_undoQueue.Queue(result); return(result); }
private void Home(KeyEventArgs args) { if (args.Shift) { var end = GetCursorPosInt() + SelectionLength; var lines = GetLines().ToList(); var uv = CursorPos.GetUV(lines); CursorPos = new CP(lines.Take(uv.Y).Select(l => l.Length).Concat(0.Only()).Sum()); SelectionLength = end - CursorPos.Pos; } else { SelectionLength = 0; } if (args.Control) { CursorPos = new CP(0); } else { var lines = GetLines().ToList(); var uv = CursorPos.GetUV(lines); CursorPos = new CP(lines.Take(uv.Y).Select(l => l.Length).Concat(0.Only()).Sum()); } m_additionUndoAction = null; }
private void AddUndoableAction(TextBoxBase sender, UndoAction action) { if (action == UndoAction.Undo) { redoStack.Push(new UndoOperation(sender, action)); } else { if (undoStack.Count > 0) { UndoOperation op = undoStack.Peek(); if ((op.Sender == sender) && (action == UndoAction.Merge)) { // no-op } else { PushUndoOperation(sender, action); } } else { PushUndoOperation(sender, action); } } }
public CollectionChangedEventArgs(RoutedEvent routedEvent, UndoAction undoAction, CollectionChangedAction collectionChangedAction) : base(routedEvent) { // Initialize the object this.undoAction = undoAction; this.collectionChangedAction = collectionChangedAction; }
public void onInspectorPreFieldModification(string fieldName, string arrayIndex) { GuiEditorGui.GuiEditor GuiEditor = "GuiEditor"; Util.pushInstantGroup(); //UndoManager undoManager = GuiEditor.getUndoManager(); SimObject objectx = this.getInspectObject(); string nameOrClass = objectx.getName(); if (nameOrClass == "") { nameOrClass = objectx.getClassName(); } ObjectCreator oc = new ObjectCreator("InspectorFieldUndoAction"); oc["actionName"] = nameOrClass + "." + fieldName + " Change"; oc["objectId"] = objectx.getId(); oc["fieldName"] = fieldName; oc["fieldValue"] = objectx.getFieldValue(fieldName, arrayIndex == "(null)" ? -1 : arrayIndex.AsInt()); oc["arrayIndex"] = arrayIndex; oc["inspectorGui"] = this; InspectorFieldUndoAction action = oc.Create(); this.currentFieldEditAction = action; Util.popInstantGroup(); }
public CollectionChangedEventArgs(RoutedEvent routedEvent, UndoAction undoAction, CollectionChangedAction collectionChangedAction, object item, int index) : base(routedEvent) { // Initialize the object this.undoAction = undoAction; this.collectionChangedAction = collectionChangedAction; ArrayList items = new ArrayList(); items.Add(item); switch (this.collectionChangedAction) { case CollectionChangedAction.Add: this.newStartingIndex = index; this.newItems = items; break; case CollectionChangedAction.Remove: this.oldStartingIndex = index; this.oldItems = items; break; } }
public CollectionChangedEventArgs(RoutedEvent routedEvent, UndoAction undoAction, CollectionChangedAction collectionChangedAction, object newItem, object oldItem, int newIndex) : base(routedEvent) { // Initialize the object this.undoAction = undoAction; this.collectionChangedAction = collectionChangedAction; ArrayList newItems = new ArrayList(); newItems.Add(newItem); ArrayList oldItems = new ArrayList(); oldItems.Add(oldItem); switch (this.collectionChangedAction) { case CollectionChangedAction.Replace: this.newItems = newItems; this.oldItems = oldItems; this.newStartingIndex = newIndex; break; } }
/// <summary> /// Creates an object that describes both the value and the undo action to a command. /// </summary> /// <param name="value">The value of the object.</param> /// <param name="undoAction">The Undo action.</param> public UndoObject(object oldValue, object newValue, UndoAction undoAction) { // Initialize the object this.OldValue = oldValue; this.NewValue = newValue; this.UndoAction = undoAction; }
public UndoInfo(FrameLayerPair layerAddress, int drawingItemID, UndoAction undoAction, object oldValue, object newValue) { this.LayerAddress = layerAddress; this.DrawingItemID = drawingItemID; this.Action = undoAction; this.OldValue = oldValue; this.NewValue = newValue; }
public UndoStep(byte[] bytes, byte[] oldBytes, int start, UndoAction action) { this.bytes = bytes; this.oldBytes = oldBytes; this.start = start; this.action = action; this.timeStamp = DateTime.Now.Ticks; }
private void Copy() { if (!string.IsNullOrEmpty(SelectedText)) { Clipboard.SetText(SelectedText); } m_additionUndoAction = null; }
/// <summary> /// Undoes the most recent undo command on the stack. /// </summary> /// <param name="dependencyObject">The target of the undo operation.</param> private void UndoCollection(object sender, GenericEventArgs genericEventArgs) { // Extract the specific arguments from the generic arguments ReportGrid reportGrid = (ReportGrid)genericEventArgs.Arguments[0]; CollectionChangedEventArgs collectionChangedEventArgs = (CollectionChangedEventArgs)genericEventArgs.Arguments[1]; UndoAction undoAction = (UndoAction)genericEventArgs.Arguments[2]; // Each action done to a collection has a specific method to be undone. Note that the 'Undo' state is passed onto the method to indicate the state // of the action. This tells the event handler on which stack to place the command needed to undo the action. For example, when undoing a a // column addition, you will remove the column. That removal operation needs to be encoded so that it is placed on the 'Redo' stack when the event // is handled. switch (collectionChangedEventArgs.Action) { case CollectionChangedAction.Add: // This will undo the action of adding a column to a collection by removing it. foreach (ReportColumn reportColumn in collectionChangedEventArgs.NewItems) { reportGrid.reportColumnCollection.Remove(reportColumn, undoAction); } break; case CollectionChangedAction.Move: // This will undo the action of moving a column by returning it to the original position. int oldIndex = collectionChangedEventArgs.OldStartingIndex; int newIndex = collectionChangedEventArgs.NewStartingIndex; foreach (ReportColumn reportColumn in collectionChangedEventArgs.NewItems) { reportGrid.reportColumnCollection.Move(newIndex, oldIndex, undoAction); newIndex++; oldIndex++; } break; case CollectionChangedAction.Replace: // This will undo the action of replacing the entire list by restoring the original list. reportGrid.reportColumnCollection.Replace(collectionChangedEventArgs.OldItems as List <ReportColumn>, undoAction); break; case CollectionChangedAction.Remove: // This will undo the action of removing a column by inserting back in at the original position. int index = collectionChangedEventArgs.OldStartingIndex; foreach (ReportColumn reportColumn in collectionChangedEventArgs.OldItems) { reportGrid.reportColumnCollection.Insert(index++, reportColumn, undoAction); } break; } }
public UndoPropertyChangedEventArgs(RoutedEvent routedEvent, UndoAction undoAction, DependencyProperty dependencyProperty, object oldValue, object newValue) : base(routedEvent) { // Initialize the object this.UndoAction = undoAction; this.DependencyProperty = dependencyProperty; this.OldValue = oldValue; this.NewValue = newValue; }
public Undo(UndoAction act, string t,string ot, int c, int r, int sc, int sr) { action = act; text = t; oldtext = ot; col = c; row = r; selCol = sc; selRow = sr; }
//Adds an action to the undo queue public void AddUndoAction(UndoAction action) { while (UndoQueue.Count > (UndoQueuePointer + 1)) { UndoQueue.RemoveAt(UndoQueue.Count - 1); } UndoQueuePointer++; UndoQueue.Add(action); UndoQueueChangedFlag = true; }
public Undo(UndoAction act, string t, string ot, int c, int r, int sc, int sr) { action = act; text = t; oldtext = ot; col = c; row = r; selCol = sc; selRow = sr; }
public void AddUndo(UndoAction undoAction) { if (undoList.Count == 5) { undoList.RemoveLast(); } FlushRedoActions(); undoList.AddFirst(undoAction); }
/// <summary> /// Undo the previous change. /// </summary> public void Undo() { if (undoStack.Count == 0) { throw new InvalidOperationException("Undo stack is empty."); } // Get the last change from the undo stack. UndoAction action = undoStack.Pop(); // Add the change to the redo stack. redoStack.Push(action); switch (action.Change) { case UndoAction.ChangeMode.AddRow: this.RemoveRow(action); break; case UndoAction.ChangeMode.DeleteRow: this.InsertRow(action); break; case UndoAction.ChangeMode.ModifyCell: this.UpdateCell(action); break; default: throw new InvalidOperationException("Unknown undo action change: " + action.Change); } }
public void SetUndoRedoActions(UndoAction undo)//, RedoAction redo) { this.undo = undo; //this.redo = redo; timerText.text = "00:00"; //redoAction.GetComponent<Button>().image.color = actionUnavailableColor; undoAction.GetComponent <Button>().image.color = actionUnavailableColor; //redoAction.GetComponent<Button>().interactable = false; undoAction.GetComponent <Button>().interactable = false; timerText.gameObject.SetActive(true); }
public void AddAction(Action<ActionData> action, Entity entity) { UndoAction item = new UndoAction { Action = action }; ActionData data = new ActionData { Entity = entity }; item.Data = data; this._actions.Push(item); }
public ColumnChangedEventArgs(RoutedEvent routedEvent, UndoAction undoAction, ReportColumn reportColumn, DependencyProperty dependencyProperty, object oldValue, object newValue) : base(routedEvent) { // Initialize the object. this.UndoAction = undoAction; this.ColumnDefinition = reportColumn; this.DependencyProperty = dependencyProperty; this.OldValue = oldValue; this.NewValue = newValue; }
/// <summary> /// Undoes the most recent undo command on the stack. /// </summary> /// <param name="dependencyObject">The target of the undo operation.</param> private void UndoColumn(object sender, GenericEventArgs genericEventArgs) { // Extract the specific arguments from the generic arguments ReportGrid reportGrid = (ReportGrid)genericEventArgs.Arguments[0]; ColumnChangedEventArgs columnChangedEventArgs = (ColumnChangedEventArgs)genericEventArgs.Arguments[1]; UndoAction undoAction = (UndoAction)genericEventArgs.Arguments[2]; // This will undo a change to the width of a column. if (columnChangedEventArgs.DependencyProperty == ReportColumn.WidthProperty) { reportGrid.reportColumnCollection.SetColumnWidth(columnChangedEventArgs.ColumnDefinition, (Double)columnChangedEventArgs.OldValue, undoAction); } }
/// <summary> /// Undoes or Redoes a change to a property in a MarkThree.Windows.Controls.Report. /// </summary> /// <param name="dependencyObject">The target of the undo operation.</param> private void UndoProperty(object sender, GenericEventArgs genericEventArgs) { // Extract the specific arguments from the generic arguments stored on the Undo/Redo stacks. ReportGrid reportGrid = (ReportGrid)genericEventArgs.Arguments[0]; DependencyProperty dependencyProperty = (DependencyProperty)genericEventArgs.Arguments[1]; object oldValue = genericEventArgs.Arguments[2]; object newValue = genericEventArgs.Arguments[3]; UndoAction undoAction = (UndoAction)genericEventArgs.Arguments[4]; // This will use the property map to Undo or Redo the change to the property. Notice that the new value and old value are transposed here from // their original positions. this.propertyMap[dependencyProperty].Execute(new UndoObject(newValue, oldValue, undoAction), reportGrid); }
public UndoPoint(Element element, UndoAction action) { if (! (element is Shape || element is Line)) throw new UndoPointException("Element must be of type Shape or type Line."); mKey = element.Key; mBytes = SerializeElement(element); mAction = action; mObjectType = element.GetType(); if (element is Shape) mUndoType = UndoType.Shape; if (element is Line) mUndoType = UndoType.Line; mContainer = element.Container; mLayer = element.Layer; }
/// <summary> /// constructor /// </summary> /// <param name="id">event id</param> /// <param name="action">UndoAction</param> /// <param name="changes">ReadOnlyCollection</param> public TextChangedEventArgs(RoutedEvent id, UndoAction action, ICollection<TextChange> changes) : base() { if (id == null) { throw new ArgumentNullException("id"); } if (action < UndoAction.None || action > UndoAction.Create) { throw new InvalidEnumArgumentException("action", (int)action, typeof(UndoAction)); } RoutedEvent=id; _undoAction = action; _changes = changes; }
public UndoOperation(TextBoxBase sender, UndoAction action) { this.Sender = sender; this.Action = action; }
public TextChangedEventArgs(System.Windows.RoutedEvent id, UndoAction action) { }
private void mnuFileDocument_Click(object sender, RoutedEventArgs e) { string previousTitle = circuitDisplay.Document.Metadata.Title; string previousDescription = circuitDisplay.Document.Metadata.Description; winDocumentProperties documentInfoWindow = new winDocumentProperties(); documentInfoWindow.Owner = this; documentInfoWindow.SetDocument(circuitDisplay.Document); documentInfoWindow.ShowDialog(); if (circuitDisplay.Document.Metadata.Title != previousTitle || circuitDisplay.Document.Metadata.Description != previousDescription) { UndoAction editMetadataAction = new UndoAction(UndoCommand.ModifyMetadata, "Modify metadata"); editMetadataAction.AddData("before", new string[2] { previousTitle, previousDescription}); editMetadataAction.AddData("after", new string[2] { circuitDisplay.Document.Metadata.Title, circuitDisplay.Document.Metadata.Description }); UndoManager.AddAction(editMetadataAction); } }
private UndoPoint AddPoint(Element element, UndoAction action, string description, bool overwrite) { if (Suspended) return null; UndoPoint undo = null; string key = null; string createDesc = null; //Create undopoint if (element is Shape || element is Line) { undo = new UndoPoint(element, action); key = element.Key; createDesc = element.GetType().Name; } else { return null; } //Remove any previous undos ahead of this one if (mUndoPointer < List.Count) { for (int i = mUndoPointer+1; i < List.Count; i++) { List.RemoveAt(i); } } //Set description if (description == null || description == "") { if (action == UndoAction.Add) { undo.Description = "Add " + createDesc; } else if (action == UndoAction.Edit) { undo.Description = "Edit " + createDesc; } else if (action == UndoAction.Remove) { undo.Description = "Remove " + createDesc; } } else { undo.Description = description; } //Get current undopoint UndoPoint currentUndo = null; if (mUndoPointer > -1) currentUndo = (UndoPoint) List[mUndoPointer]; //Check if must add or update the undopoint if (overwrite && mUndoPointer > -1 && action == UndoAction.Edit && currentUndo.Key == key) { List[mUndoPointer] = undo; } else { //Add object to internal arraylist List.Add(undo); mUndoPointer = List.Count - 1; } return undo; }
public TextChangedEventArgs(System.Windows.RoutedEvent id, UndoAction action, ICollection<TextChange> changes) { }
public void DeleteComponentCommand(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { if (m_selectedComponents.Count > 0) { UndoAction undoAction = new UndoAction(UndoCommand.DeleteComponents, "delete", m_selectedComponents.ToArray()); UndoManager.AddAction(undoAction); foreach (Component component in m_selectedComponents) { Document.Elements.Remove(component); } m_selectedComponents.Clear(); foreach (Component component in Document.Components) component.DisconnectConnections(); foreach (Component component in Document.Components) component.ApplyConnections(Document); DrawConnections(); // Clear selection box using (DrawingContext dc = m_selectedVisual.RenderOpen()) { } // Clear resize visual using (DrawingContext dc = m_resizeVisual.RenderOpen()) { } } else if (m_resizingComponent != null) { UndoAction undoAction = new UndoAction(UndoCommand.DeleteComponents, "delete", new Component[] { m_resizingComponent }); UndoManager.AddAction(undoAction); Document.Elements.Remove(m_resizingComponent); m_resizingComponent = null; foreach (Component component in Document.Components) component.DisconnectConnections(); foreach (Component component in Document.Components) component.ApplyConnections(Document); DrawConnections(); // Clear selection box using (DrawingContext dc = m_selectedVisual.RenderOpen()) { } // Clear resize visual using (DrawingContext dc = m_resizeVisual.RenderOpen()) { } } }
private void CommandPaste_Executed(object sender, ExecutedRoutedEventArgs e) { ComponentDeserializer deserializer = new ComponentDeserializer(Clipboard.GetData("CircuitDiagram.ComponentData") as string); deserializer.Components.ForEach(c => circuitDisplay.Document.Elements.Add(c)); circuitDisplay.SetSelectedComponents(deserializer.Components); UndoAction action = new UndoAction(UndoCommand.AddComponents, "Add components", deserializer.Components.ToArray()); UndoManager.AddAction(action); }
public void PushUndoBlock(UndoAction Action, string Text, string ReplacedText, int x, int y) { UndoBlock undo = new UndoBlock(); undo.Action = Action; undo.Text = Text; undo.ReplacedText = ReplacedText; undo.Position.Y = y; undo.Position.X = x; //AddToUndoList(undo); if (mCaptureMode) { mCaptureBlock.Add(undo); } else { AddToUndoList(undo); } }
public void FlipComponentCommand(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { if (m_selectedComponents.Count == 1 && m_selectedComponents[0].Description.CanFlip) { m_selectedComponents[0].IsFlipped = !m_selectedComponents[0].IsFlipped; m_elementVisuals[m_selectedComponents[0]].UpdateVisual(); m_selectedComponents[0].ResetConnections(); m_selectedComponents[0].ApplyConnections(Document); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Flip component", new Component[] { m_selectedComponents[0] }); undoAction.AddData("before", m_undoManagerBeforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_selectedComponents[0], m_selectedComponents[0].SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } else if (m_resizingComponent != null && m_resizingComponent.Description.CanFlip) { Dictionary<Component, string> beforeData = new Dictionary<Component, string>(); beforeData.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); m_resizingComponent.IsFlipped = !m_resizingComponent.IsFlipped; m_elementVisuals[m_resizingComponent].UpdateVisual(); m_resizingComponent.ResetConnections(); m_resizingComponent.ApplyConnections(Document); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Flip component", new Component[] { m_resizingComponent }); undoAction.AddData("before", beforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } }
protected override void OnMouseLeave(System.Windows.Input.MouseEventArgs e) { base.OnMouseLeave(e); if (m_resizing != ComponentResizeMode.None) { m_resizingComponent.ResetConnections(); m_resizingComponent.ApplyConnections(Document); DrawConnections(); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Move component", new Component[] { m_resizingComponent }); undoAction.AddData("before", m_undoManagerBeforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); m_resizing = ComponentResizeMode.None; this.Cursor = System.Windows.Input.Cursors.Arrow; } m_selectionBox = false; m_placingComponent = false; }
/// <summary> /// constructor /// </summary> /// <param name="id">event id</param> /// <param name="action">UndoAction</param> public TextChangedEventArgs(RoutedEvent id, UndoAction action) : this(id, action, new ReadOnlyCollection<TextChange>(new List<TextChange>())) { }
private void PushUndoOperation(TextBoxBase sender, UndoAction action) { undoStack.Push(new UndoOperation(sender, action)); System.Diagnostics.Debug.WriteLine("PUSHED"); }
public void PushUndoBlock(UndoAction Action, string Text, int x, int y, RowRevisionMark mark) { var undo = new UndoBlock(); undo.Action = Action; undo.Text = Text; undo.Position.Y = y; undo.Position.X = x; undo.RowModified = (mark != RowRevisionMark.Unchanged); //AddToUndoList(undo); if (captureMode) { captureBlock.Add(undo); } else { AddToUndoList(undo); } }
protected override void OnMouseLeftButtonUp(System.Windows.Input.MouseButtonEventArgs e) { base.OnMouseUp(e); m_movingMouse = false; if (m_resizing != ComponentResizeMode.None) { m_resizingComponent.ResetConnections(); m_resizingComponent.ApplyConnections(Document); DrawConnections(); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Move component", new Component[] { m_resizingComponent }); undoAction.AddData("before", m_undoManagerBeforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } m_resizing = ComponentResizeMode.None; this.Cursor = System.Windows.Input.Cursors.Arrow; m_resizingComponent = null; if (m_placingComponent) { Component newComponent = Component.Create(NewComponentData); ComponentHelper.SizeComponent(newComponent, m_mouseDownPos, e.GetPosition(this)); // Flip if necessary if (newComponent.Orientation == Orientation.Horizontal && newComponent.Description.CanFlip) { if (m_mouseDownPos.X > e.GetPosition(this).X) newComponent.IsFlipped = true; else newComponent.IsFlipped = false; } else if (newComponent.Description.CanFlip) { if (m_mouseDownPos.Y > e.GetPosition(this).Y) newComponent.IsFlipped = true; else newComponent.IsFlipped = false; } Document.Elements.Add(newComponent); newComponent.ApplyConnections(Document); DrawConnections(); m_placingComponent = false; UndoAction undoAction = new UndoAction(UndoCommand.AddComponents, "Add component", new Component[] { newComponent }); UndoManager.AddAction(undoAction); RemoveVisualChild(m_elementVisuals[m_tempComponent]); RemoveLogicalChild(m_elementVisuals[m_tempComponent]); m_elementVisuals.Remove(m_tempComponent); m_tempComponent = null; } else if (m_selectedComponents.Count > 0) { Dictionary<Component, string> afterData = new Dictionary<Component, string>(); foreach (Component component in m_selectedComponents) { string afterDataString = component.SerializeToString(); if (afterDataString == m_undoManagerBeforeData[component]) break; afterData.Add(component, afterDataString); } if (afterData.Count > 0) { UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "move", m_selectedComponents.ToArray()); undoAction.AddData("before", m_undoManagerBeforeData); undoAction.AddData("after", afterData); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } } else if (m_selectionBox) { using (DrawingContext dc = m_selectedVisual.RenderOpen()) { enclosingRect = Rect.Empty; VisualTreeHelper.HitTest(this, new HitTestFilterCallback(delegate(DependencyObject testObject) { if (testObject is CircuitElementDrawingVisual) return HitTestFilterBehavior.ContinueSkipChildren; else return HitTestFilterBehavior.ContinueSkipSelf; }), new HitTestResultCallback(delegate(HitTestResult result) { m_selectedComponents.Add((result.VisualHit as CircuitElementDrawingVisual).CircuitElement as Component); if (result.VisualHit is CircuitElementDrawingVisual) { Rect rect = VisualTreeHelper.GetContentBounds(result.VisualHit as Visual); dc.PushTransform(new TranslateTransform((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y)); dc.DrawRectangle(new SolidColorBrush(Color.FromArgb(100, 0, 0, 100)), null, rect); dc.Pop(); if (enclosingRect.IsEmpty) { rect.Offset((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y); enclosingRect = rect; } else { rect.Offset((result.VisualHit as CircuitElementDrawingVisual).Offset.X, (result.VisualHit as CircuitElementDrawingVisual).Offset.Y); enclosingRect.Union(rect); } } return HitTestResultBehavior.Continue; }), new GeometryHitTestParameters(new RectangleGeometry(new Rect(m_mouseDownPos, e.GetPosition(this))))); dc.DrawRectangle(Brushes.Transparent, new Pen(Brushes.Black, 1d), enclosingRect); } m_selectionBox = false; } }
public new UndoPoint Add(Element element, UndoAction action, string description, bool overwrite) { return AddPoint(element, action, description, overwrite); }
public void RotateComponentCommand_Executed(object sender, System.Windows.Input.ExecutedRoutedEventArgs e) { if (m_selectedComponents.Count == 1) { m_selectedComponents[0].Orientation = m_selectedComponents[0].Orientation.Reverse(); m_selectedComponents[0].ResetConnections(); RedrawComponent(m_selectedComponents[0]); foreach (Component component in Document.Components) component.DisconnectConnections(); foreach (Component component in Document.Components) component.ApplyConnections(Document); DrawConnections(); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Rotate component", new Component[] { m_selectedComponents[0] }); undoAction.AddData("before", m_undoManagerBeforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_selectedComponents[0], m_selectedComponents[0].SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } else if (m_resizingComponent != null) { Dictionary<Component, string> beforeData = new Dictionary<Component, string>(); beforeData.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); m_resizingComponent.Orientation = m_resizingComponent.Orientation.Reverse(); m_resizingComponent.ResetConnections(); RedrawComponent(m_resizingComponent); foreach (Component component in Document.Components) component.DisconnectConnections(); foreach (Component component in Document.Components) component.ApplyConnections(Document); DrawConnections(); UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "Rotate component", new Component[] { m_resizingComponent }); undoAction.AddData("before", beforeData); Dictionary<Component, string> afterDictionary = new Dictionary<Component, string>(1); afterDictionary.Add(m_resizingComponent, m_resizingComponent.SerializeToString()); undoAction.AddData("after", afterDictionary); UndoManager.AddAction(undoAction); m_undoManagerBeforeData = new Dictionary<Component, string>(); } }
public new UndoPoint Add(Element element, UndoAction action, string description) { return AddPoint(element, action, description, false); }
public void PushUndoBlock(UndoAction Action, string Text, int x, int y) { PushUndoBlock(Action, Text, "", x, y); }
public new UndoPoint Add(Element element, UndoAction action, bool overwrite) { return AddPoint(element, action, "", overwrite); }
public void PushUndoBlock(UndoAction Action, string text, int x, int y) { var undo = new UndoBlock { Action = Action, Text = text }; undo.Position.Y = y; undo.Position.X = x; //AddToUndoList(undo); if (captureMode) { captureBlock.Add(undo); } else { AddToUndoList(undo); } }
//Methods //Adds a new element to the list public new UndoPoint Add(Element element, UndoAction action) { return AddPoint(element, action, "", false); }
private void mnuEditResizeDocument(object sender, RoutedEventArgs e) { winDocumentSize docSizeWindow = new winDocumentSize(); docSizeWindow.Owner = this; docSizeWindow.DocumentWidth = circuitDisplay.Document.Size.Width; docSizeWindow.DocumentHeight = circuitDisplay.Document.Size.Height; if (docSizeWindow.ShowDialog() == true) { Size newSize = new Size(docSizeWindow.DocumentWidth, docSizeWindow.DocumentHeight); if (newSize != circuitDisplay.Document.Size) { UndoAction resizeAction = new UndoAction(UndoCommand.ResizeDocument, "Resize document"); resizeAction.AddData("before", circuitDisplay.Document.Size); circuitDisplay.Document.Size = newSize; circuitDisplay.DocumentSizeChanged(); resizeAction.AddData("after", newSize); UndoManager.AddAction(resizeAction); } } }
void Editor_ComponentUpdated(object sender, ComponentUpdatedEventArgs e) { UndoAction undoAction = new UndoAction(UndoCommand.ModifyComponents, "edit", new Component[] { e.Component }); Dictionary<Component, string> previousData = new Dictionary<Component, string>(1); previousData.Add(e.Component, e.PreviousData); undoAction.AddData("before", previousData); Dictionary<Component, string> newData = new Dictionary<Component, string>(1); newData.Add(e.Component, e.Component.SerializeToString()); undoAction.AddData("after", newData); UndoManager.AddAction(undoAction); // Update connections e.Component.ResetConnections(); e.Component.ApplyConnections(circuitDisplay.Document); circuitDisplay.DrawConnections(); }