public void AssignStyle(AssignStyleType type) { string cStyle = NodeStyle; Tikz_Picture tp = ParseTree.GetTikzPicture(); if (tp == null) { return; } if (View.Tool != OverlayToolType.move) { return; // context menu should actually only open with move tool,... but to be safe against later changes... } if (type == AssignStyleType.AssignNewStyle || type == AssignStyleType.ChangeToNewStyle) { if (Overlay.InputMessageBox.ShowInputDialog("New style...", "Please enter a unique style name", out cStyle) != MessageBoxResult.OK) { return; } cStyle = cStyle.Trim(); // check if style name is valid and unique if (ParseTree == null || cStyle == "") { return; } if (ParseTree.styles.ContainsKey(cStyle)) { GlobalUI.ShowMessageBox("Error: Style name '" + cStyle + "' already exists.", "Style exists", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // add new style, immediately before \begin{tikzpicture}[...] BeginUpdate(); Tikz_Option to = new Tikz_Option(); to.type = Tikz_OptionType.style; to.key = cStyle; to.val = ""; to.text = "\\tikzstyle{" + cStyle + "}=[];"; int index = ParseTree.Children.IndexOf(tp); if (index >= 0) { ParseTree.InsertChildAt(to, index); to.RegisterNodeAndStyleRefs(); ParseTree.InsertChildAt(new Tikz_Something(Environment.NewLine), index + 1); } } else { if (cStyle.Trim() == "") { return; } BeginUpdate(); } // loop through selected items and set styles foreach (OverlayShape ols in selectionTool.SelItems) { // currently only node styles can be set if (ols.item is Tikz_Node) { Tikz_Node tn = ols.item as Tikz_Node; if (tn.options == "" || type == AssignStyleType.ChangeToCurrentNodeStyle || type == AssignStyleType.ChangeToNewStyle) { tn.options = "[" + cStyle + "]"; } else // just add option { string o = tn.options.Trim(); if (o.EndsWith("]")) { o = o.Substring(0, o.Length - 1); o = o + ", " + cStyle + "]"; } // otherwise, do nothing (error) tn.options = o; } tn.UpdateText(); } } EndUpdate(); // Make sure EndUpdate() is always called (..if Beginupdate() was)! }
public void AssignStyle(AssignStyleType type) { string cStyle = NodeStyle; Tikz_Picture tp = ParseTree.GetTikzPicture(); if (tp == null) return; if (View.Tool != OverlayToolType.move) return; // context menu should actually only open with move tool,... but to be safe against later changes... if (type == AssignStyleType.AssignNewStyle || type == AssignStyleType.ChangeToNewStyle) { if (Overlay.InputMessageBox.ShowInputDialog("New style...", "Please enter a unique style name", out cStyle) != MessageBoxResult.OK) return; cStyle = cStyle.Trim(); // check if style name is valid and unique if (ParseTree == null || cStyle == "") return; if (ParseTree.styles.ContainsKey(cStyle)) { GlobalUI.ShowMessageBox("Error: Style name '" + cStyle + "' already exists.", "Style exists", MessageBoxButton.OK, MessageBoxImage.Warning); return; } // add new style, immediately before \begin{tikzpicture}[...] BeginUpdate(); Tikz_Option to = new Tikz_Option(); to.type = Tikz_OptionType.style; to.key = cStyle; to.val = ""; to.text = "\\tikzstyle{" + cStyle + "}=[];"; int index = ParseTree.Children.IndexOf(tp); if (index >= 0) { ParseTree.InsertChildAt(to, index); to.RegisterNodeAndStyleRefs(); ParseTree.InsertChildAt(new Tikz_Something(Environment.NewLine), index + 1); } } else { if (cStyle.Trim() == "") return; BeginUpdate(); } // loop through selected items and set styles foreach (OverlayShape ols in selectionTool.SelItems) { // currently only node styles can be set if (ols.item is Tikz_Node) { Tikz_Node tn = ols.item as Tikz_Node; if (tn.options == "" || type == AssignStyleType.ChangeToCurrentNodeStyle || type == AssignStyleType.ChangeToNewStyle) { tn.options = "[" + cStyle + "]"; } else // just add option { string o = tn.options.Trim(); if (o.EndsWith("]")) { o = o.Substring(0, o.Length - 1); o = o + ", " + cStyle + "]"; } // otherwise, do nothing (error) tn.options = o; } tn.UpdateText(); } } EndUpdate(); // Make sure EndUpdate() is always called (..if Beginupdate() was)! }