public void updateUndoStatus(String oldMarkup, bool check = false, TwoWayCommand additionalUndoOperations = null) { //This is a hacky way to check for changes (optionally) it should not be needed when the popup editor is overhauled. //You can remove check and keep only the line in the if statement when you no longer need the check. String currentMarkup = UnformattedRml; if (!check || currentMarkup != oldMarkup) { if (additionalUndoOperations == null) { undoBuffer.pushAndSkip(new TwoWayDelegateCommand <String, String>(currentMarkup, oldMarkup, new TwoWayDelegateCommand <string, string> .Funcs() { ExecuteFunc = undoRedoCallback, UndoFunc = undoRedoCallback })); } else { undoBuffer.pushAndSkip(new TwoWayDelegateCommand <String, String>(currentMarkup, oldMarkup, new TwoWayDelegateCommand <string, string> .Funcs() { ExecuteFunc = rml => { undoRedoCallback(rml); additionalUndoOperations.execute(); }, UndoFunc = rml => { undoRedoCallback(rml); additionalUndoOperations.undo(); } })); } } }
/// <summary> /// Apply the changes this editor has to the element. Returns true if changes have been made and the document needs refreshing. /// </summary> /// <param name="component"></param> /// <returns>True if changes are made.</returns> public bool applyChanges(RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { if (hasChanges) { hasChanges = false; return(elementStrategy.applyChanges(element, this, component, out additionalUndoOperations)); } additionalUndoOperations = null; return(false); }
/// <summary> /// Add a command to the end of the list. /// </summary> /// <param name="command"></param> public void push(TwoWayCommand command) { if (lastCommand == null) { currentExecuteCommand = firstCommand = lastCommand = new Node <TwoWayCommand>(command); } else { Node <TwoWayCommand> oldLast = lastCommand; lastCommand = new Node <TwoWayCommand>(command); lastCommand.Previous = oldLast; oldLast.Next = lastCommand; if (OnLast) { //Did we add a command at the end with nothing to execute currentExecuteCommand = lastCommand; } } }
private void push(TwoWayCommand command) { if (!buffer.OnLast) { //If we are not on the last item, trim and recount buffer.trim(); currentItemCount = buffer.Count; } if (currentItemCount == maxItemCount) { //If we are full, pop the first item buffer.popFirst(); } else { ++currentItemCount; } buffer.push(command); }
public override bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { additionalUndoOperations = null; return(attributeEditor.applyToElement(element)); }
public override bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { additionalUndoOperations = null; build(element); return(true); }
public virtual bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { additionalUndoOperations = null; return(false); }
public override bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { additionalUndoOperations = null; switch (element.GetAttributeString("type")) { case "range": attributeEditor.applyToElement(element); break; default: String text = textEditor.Text; element.InnerRml = textEditor.Text; attributeEditor.applyToElement(element); break; } return(true); }
public override bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { additionalUndoOperations = null; switch (element.GetAttributeString("type")) { case "range": return(applyRangeChanges(element, editor, component)); default: return(false); } }
/// <summary> /// Push a command and skip its execute (redo) function to only run when manually invoked. /// </summary> public void pushAndSkip(TwoWayCommand command) { push(command); buffer.skipExecute(); }
/// <summary> /// Push a command and run its execute (redo) funciton. /// </summary> public void pushAndExecute(TwoWayCommand command) { push(command); execute(); }
public override bool applyChanges(Element element, RmlElementEditor editor, RmlWysiwygComponent component, out TwoWayCommand additionalUndoOperations) { element.ClearLocalStyles(); StringBuilder styleString = new StringBuilder(); StringBuilder classString = new StringBuilder(); bool changesMade = false; element.SetAttribute("src", slideImageEditor.ImageName); if (slideImageEditor.ShowFullscreen) { String actionName = element.GetAttributeString("onclick"); if (actionName == null) { actionName = Guid.NewGuid().ToString(); element.SetAttribute("onclick", actionName); } Action <ShowPopupImageAction> undoAction; ShowPopupImageAction oldAction = slide.getAction(actionName) as ShowPopupImageAction; if (oldAction == null) { undoAction = a => { slide.removeAction(actionName); }; } else { undoAction = a => { slide.replaceAction(a); }; } var action = new ShowPopupImageAction(actionName) { ImageName = slideImageEditor.ImageName, }; additionalUndoOperations = new TwoWayDelegateCommand <ShowPopupImageAction, ShowPopupImageAction>(action, oldAction, new TwoWayDelegateCommand <ShowPopupImageAction, ShowPopupImageAction> .Funcs() { ExecuteFunc = (exec) => { slide.replaceAction(exec); }, UndoFunc = undoAction, }); additionalUndoOperations.execute(); //This is not called automatically by the classes consuming this, so we make sure to actually apply the changes } else { String actionName = element.GetAttributeString("onclick"); ShowPopupImageAction oldAction = null; if (actionName != null) { oldAction = slide.getAction(actionName) as ShowPopupImageAction; } if (oldAction != null) { additionalUndoOperations = new TwoWayDelegateCommand <ShowPopupImageAction, ShowPopupImageAction>(null, oldAction, new TwoWayDelegateCommand <ShowPopupImageAction, ShowPopupImageAction> .Funcs() { ExecuteFunc = (exec) => { slide.removeAction(actionName); }, UndoFunc = (undo) => { slide.replaceAction(undo); } }); additionalUndoOperations.execute(); //Make sure changes are applied } else { additionalUndoOperations = null; } element.RemoveAttribute("onclick"); } changesMade = appearance.buildClassList(classString) | changesMade; changesMade = appearance.buildStyleAttribute(styleString) | changesMade; if (changesMade) { if (classString.Length > 0) { element.SetAttribute("class", classString.ToString()); } else { element.RemoveAttribute("class"); } if (styleString.Length > 0) { element.SetAttribute("style", styleString.ToString()); } else { element.RemoveAttribute("style"); } } return(changesMade); }