private void MainForm_FormClosing(object sender, FormClosingEventArgs e) { httpServer.Stop(); //保存配置文件 XmlTreeNode rootNode = new XmlTreeNode("root"); rootNode.AddItem("LastFolderPath", lastFolderPath); Encoding utf8Encoding = new UTF8Encoding(false); String xml = rootNode.ToXml(utf8Encoding); IoHelper.CreateMultiFolder(Path.GetDirectoryName(configFilePath)); File.WriteAllText(configFilePath, xml, Encoding.UTF8); Environment.Exit(0); }
/// <summary> /// SERIALIZATION: Creates a XML Serialized copy of the link /// </summary> /// <param name="p_XmlParentTreeNode"></param> /// <returns></returns> public XmlTreeNode SerializeToXML(XmlTreeNode p_XmlParentTreeNode) { XmlTreeNode v_Out = new XmlTreeNode(SerializationUtils.GetFullTypeName(this), p_XmlParentTreeNode); NodeGraphView v_View = Input.Parent.ParentView; NodeGraphNode v_InputNode = Input.Parent; NodeGraphNode v_OutputNode = Output.Parent; v_Out.AddParameter("InputNodeId", v_View.GetNodeIndex(v_InputNode).ToString()); v_Out.AddParameter("OutputNodeId", v_View.GetNodeIndex(v_OutputNode).ToString()); v_Out.AddParameter("InputNodeConnectorIdx", v_InputNode.GetConnectorIndex(Input).ToString()); v_Out.AddParameter("OutputNodeConnectorIdx", v_OutputNode.GetConnectorIndex(Output).ToString()); return(v_Out); }
protected override void CreateRootNode(ref XmlTreeNode rootNode) { var provider = MembershipProviderExtensions.GetMembersMembershipProvider(); // only show member types if we're using umbraco members on the website if (provider.IsUmbracoMembershipProvider()) { rootNode.NodeType = "init" + TreeAlias; rootNode.NodeID = "init"; } else { rootNode = null; } }
private void btnSaveTree_Click(object sender, EventArgs e) { ContextMenuNow = null; try { XmlTreeNode.SaveToXml(treeView1); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnSaveTree.Enabled = false; btnUseDefautTree.Enabled = false; }
void BaseContentTree_BeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e) { if (node.Menu != null && node.NodeType == "content") { //Find the publish action and add 1 for the index, so the position of the ubpublish is direct after the publish menu item IAction action = node.Menu.Find(p => p.Alias == "rights"); if (action != null) { int index = node.Menu.FindIndex(p => p.Alias == "rights"); //Insert unpublish action node.Menu.Insert(index, UsergroupPermissions.Instance); node.Menu.Insert(index, ContextMenuSeperator.Instance); } } }
protected override void CreateRootNode(ref XmlTreeNode rootNode) { Permissions permissions = PermissionService.Instance.GetCurrentLoggedInUserPermissions(); if (permissions != null && PermissionService.Instance.GetCurrentLoggedInUserPermissions().HasPermission(GeneralPermissionType.AccessLicenses)) { AssignNodeValues(rootNode, GetNodeIdentifier(LicenseTreeNodeType.License), DeveloperTerms.Licenses, Constants.TreeIcons.LicenseKey, "license"); rootNode.Source = null; rootNode.Action = "javascript:(function(){" + ClientTools.Scripts.ChangeContentFrameUrl(WebUtils.GetPageUrl(Constants.Pages.LicenseCheck)) + "})"; } else { rootNode = null; } }
/// <summary> /// This is called if the tree has been expanded, and it's used to render and child nodes for this tree /// </summary> /// <param name="tree">current tree</param> public override void Render(ref XmlTree tree) { XmlTreeNode node; foreach (RelationType relationType in RelationType.GetAll().OrderBy(relationType => relationType.Name)) { node = XmlTreeNode.Create(this); node.NodeID = relationType.Id.ToString(); node.Text = relationType.Name; node.Icon = "settingAgent.gif"; node.Action = string.Concat("javascript:openRelationType('", node.NodeID, "');"); tree.Add(node); } }
/// <summary> /// Render the top Root Nodes. /// - Calendar -> The Root of all Calendars /// - Locations -> The Root of all Locations /// </summary> /// <param name="tree">The current tree</param> private void PopulateRootNodes(ref XmlTree tree) { XmlTreeNode xNode = CreateNode("Global Settings", -1); tree.Add(xNode); var rootNode = new DynamicNode(-1); var homepageNodes = rootNode.Descendants(Constants.HomepageAlias); foreach (var node in homepageNodes) { xNode = CreateNode(node.Name, node.Id); tree.Add(xNode); } }
/// <summary> /// Render the top Root Nodes. /// - Calendar -> The Root of all Calendars /// - Locations -> The Root of all Locations /// </summary> /// <param name="tree">The current tree</param> private void PopulateRootNodes(ref XmlTree tree) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = "1"; xNode.Text = "Calendar"; //xNode.Action = "javascript:openCustom('" + "1" + "');"; xNode.Icon = "calendar.png"; xNode.OpenIcon = "folder_o.gif"; xNode.NodeType = "EventCalendarBase"; var treeService = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, "CalendarBase"); xNode.Source = treeService.GetServiceUrl(); xNode.Menu.Clear(); xNode.Menu.Add(ActionNew.Instance); xNode.Menu.Add(ActionRefresh.Instance); tree.Add(xNode); xNode = XmlTreeNode.Create(this); xNode.NodeID = "2"; xNode.Text = "Locations"; //xNode.Action = "javascript:openCustom('" + "1" + "');"; xNode.Icon = "map.png"; xNode.OpenIcon = "folder_o.gif"; xNode.NodeType = "EventLocationBase"; treeService = new TreeService(-1, TreeAlias, ShowContextMenu, IsDialog, DialogMode, app, "LocationBase"); xNode.Source = treeService.GetServiceUrl(); xNode.Menu.Clear(); xNode.Menu.Add(ActionNew.Instance); xNode.Menu.Add(ActionRefresh.Instance); tree.Add(xNode); //xNode = XmlTreeNode.Create(this); //xNode.NodeID = "3"; //xNode.Text = "Settings"; //xNode.Action = "javascript:openSettings();"; //xNode.Icon = "cog.png"; //xNode.NodeType = "GeneralSettings"; //xNode.Menu.Clear(); //tree.Add(xNode); }
/// <summary> /// SERIALIZATION: Creates a NodeGraphLink from XML, used for inherited classes /// </summary> /// <param name="p_ObjectXml"></param> /// <param name="p_View"></param> /// <returns></returns> public static NodeGraphLink DeserializeFromXML(XmlTreeNode p_ObjectXml, NodeGraphView p_View) { string className = p_ObjectXml.m_nodeName; object[] arguments = { p_ObjectXml, p_View }; System.Reflection.Assembly v_Assembly = System.Reflection.Assembly.GetExecutingAssembly(); object v_Out = v_Assembly.CreateInstance(className, false, System.Reflection.BindingFlags.CreateInstance, null, arguments, System.Globalization.CultureInfo.GetCultureInfo("en-us"), null); return(v_Out as NodeGraphLink); }
public override void Render(ref XmlTree tree) { Repository repository = new Repository(); List <Entity> entities = repository.GetAll(); foreach (Entity entity in entities) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = entity.Id.ToString(); xNode.Text = entity.Name; xNode.Action = "javascript:openUpacSyndication(" + entity.Id + ");"; xNode.Icon = "feed.png"; xNode.OpenIcon = "feed.png"; tree.Add(xNode); } }
/// <summary> /// CLIPBOARD: If contains a NodeGraphClipboard.xml, deserializes and add nodes to current view. /// </summary> public void PasteSelectionFromClipBoard() { if (Clipboard.ContainsFileDropList()) { if (Clipboard.GetFileDropList().Contains(Path.GetTempPath() + "NodeGraphClipboard.xml")) { XmlTree v_Contents = XmlTree.FromFile(Path.GetTempPath() + "NodeGraphClipboard.xml"); XmlTreeNode v_ContentsRoot = v_Contents.m_rootNode; XmlTreeNode v_NodesRoot = v_ContentsRoot.GetFirstChild("Nodes"); XmlTreeNode v_LinksRoot = v_ContentsRoot.GetFirstChild("Links"); int PreviousNodeCount = this.m_NodeCollection.Count; NodeGraphNode v_CurrentNode; foreach (XmlTreeNode i_Node in v_NodesRoot.m_childNodes) { v_CurrentNode = NodeGraphNode.DeserializeFromXML(i_Node, this); v_CurrentNode.X += 10; v_CurrentNode.Y += 10; v_CurrentNode.UpdateHitRectangle(); this.NodeCollection.Add(v_CurrentNode); } int v_InId, v_InConnectorIdx, v_OutId, v_OutConnectorIdx; foreach (XmlTreeNode i_Link in v_LinksRoot.m_childNodes) { v_InId = int.Parse(i_Link.m_attributes["InputNodeId"]); v_InConnectorIdx = int.Parse(i_Link.m_attributes["InputNodeConnectorIdx"]); v_OutId = int.Parse(i_Link.m_attributes["OutputNodeId"]); v_OutConnectorIdx = int.Parse(i_Link.m_attributes["OutputNodeConnectorIdx"]); // Relinking this.m_Links.Add(new NodeGraphLink( // P_INPUT this.m_NodeCollection[PreviousNodeCount + v_InId].Connectors[v_InConnectorIdx], // P_OUTPUT this.m_NodeCollection[PreviousNodeCount + v_OutId].Connectors[v_OutConnectorIdx] )); } } ParentPanel.Refresh(); } }
protected override void OnRenderFileNode(ref XmlTreeNode xNode) { xNode.Action = xNode.Action.Replace("openFile", "openScriptEditor"); // add special icons for javascript files if (xNode.Text.Contains(".js")) { xNode.Icon = "icon-script"; xNode.OpenIcon = "icon-script"; } else { xNode.Icon = "icon-code"; xNode.OpenIcon = "icon-code"; } xNode.Text = xNode.Text.StripFileExtension(); }
// adds nodes to tree public override void Render(ref XmlTree tree) { List <string> nodes = new List <string>() { "hello", "dolly" }; int i = 0; foreach (var s in nodes) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = i.ToString(); xNode.Text = s; xNode.Icon = "fundmedia.png"; xNode.Action = "javascript:openFundMedia(" + i.ToString() + ")"; tree.Add(xNode); } }
/// <summary> /// Called when [before node render]. /// </summary> /// <param name="sender">The sender.</param> /// <param name="node">The node.</param> /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param> protected override void OnBeforeNodeRender(ref XmlTree sender, ref XmlTreeNode node, EventArgs e) { var xpath = this.GetXPathFromCookie(this.GetDataTypeId()); var xPathType = this.GetXPathFilterTypeFromCookie(this.GetDataTypeId()); var xDoc = new XmlDocument(); var xmlNode = umbraco.library.GetMedia(int.Parse(node.NodeID), false).Current.OuterXml; var xmlString = "<root>" + xmlNode + "</root>"; var xml = XElement.Parse(xmlString); node.DetermineClickable(xpath, xPathType, xml); //ensure that the NodeKey is passed through node.Source = this.GetTreeServiceUrlWithParams(int.Parse(node.NodeID), this.GetDataTypeId()); base.OnBeforeNodeRender(ref sender, ref node, e); }
public override void Render(ref XmlTree tree) { foreach (Language l in Language.getAll) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = l.id.ToString(); //"language_" + l.id.ToString(); xNode.Text = l.FriendlyName; xNode.Action = "javascript:openLanguage(" + l.id + ");"; xNode.Icon = "icon-flag-alt"; xNode.OpenIcon = "icon-flag-alt"; OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } }
private void CreateChildNode(TreeNode node, XmlTreeNode list, DataTable dt, string fAclid) { DataRow[] drTmp = dt.Select("fname ='" + fAclid + "'"); if (drTmp != null && drTmp.Length > 0) { for (int i = 0; i < drTmp.Length; i++) { string aclid = drTmp[i]["ACLID"].ToString(); TreeNodeItem item = list.GetItemByAclid(aclid); TreeNode treeNode = new TreeNode(); treeNode.Text = item.Descript; treeNode.Tag = item; //创建子节点 CreateChildNode(treeNode, list, dt, aclid); node.Nodes.Add(treeNode); } } }
public override void Render(ref XmlTree tree) { foreach (DataTypeDefinition dt in DataTypeDefinition.GetAll()) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = dt.Id.ToString(); xNode.Text = dt.Text; xNode.Action = "javascript:openDataType(" + dt.Id + ");"; xNode.Icon = "developerDatatype.gif"; xNode.OpenIcon = "developerDatatype.gif"; OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } }
public static void SaveToXml(XmlTreeNode obj) { try { //先序列化 System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(obj.GetType()); System.IO.StringWriter sw = new System.IO.StringWriter(); xs.Serialize(sw, obj); System.IO.File.WriteAllText(localConfigPath, sw.ToString(), Encoding.UTF8); sw.Flush(); sw.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message); } }
//从XML得到事件包 public static EventPackage FromXml(String xml) { EventPackage rtnPackage = null; XmlTreeNode treeNode = XmlTreeNode.FromXml(xml); String packageName = treeNode.Key; if (packageName.Equals("EventPackage")) { rtnPackage = new EventPackage(); } else { return(null); } rtnPackage.SetRootPackage(treeNode); return(rtnPackage); }
public override void Render(ref XmlTree tree) { foreach (MediaType dt in MediaType.GetAll) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = dt.Id.ToString(); xNode.Text = dt.Text; xNode.Action = string.Format("javascript:openMediaType({0});", dt.Id); xNode.Icon = "settingDataType.gif"; xNode.OpenIcon = "settingDataType.gif"; OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } }
private void CreateNode(ref XmlTree tree, string name, string action) { var node = XmlTreeNode.Create(this); node.NodeID = 1.ToString(); node.NodeType = "ContentConveyor"; node.Text = name; node.Action = "javascript:openDashboard('" + action + "');"; node.Icon = "../../../App_Plugins/BackOffice/ContentConveyor/Images/Icons/importDocumenttype.png"; node.OpenIcon = "../../../App_Plugins/BackOffice/ContentConveyor/Images/Icons/importDocumenttype.png"; node.HasChildren = false; node.Menu = new List <IAction>(); OnBeforeNodeRender(ref tree, ref node, EventArgs.Empty); if (node != null) { tree.Add(node); OnAfterNodeRender(ref tree, ref node, EventArgs.Empty); } }
private void CreateNode(ref XmlTree tree, string name, string action) { var node = XmlTreeNode.Create(this); node.NodeID = 1.ToString(); node.NodeType = "ContentConveyor"; node.Text = name; node.Action = "javascript:openDashboard('" + action + "');"; node.Icon = "icon-box"; node.OpenIcon = "icon-box"; node.HasChildren = false; node.Menu = new List <IAction>(); OnBeforeNodeRender(ref tree, ref node, EventArgs.Empty); if (node != null) { tree.Add(node); OnAfterNodeRender(ref tree, ref node, EventArgs.Empty); } }
/// <summary> /// Converts an XmlTreeNode to a TreeNode /// </summary> /// <param name="xNode"></param> /// <returns></returns> public static TreeNode FromXmlTreeNode(XmlTreeNode xNode, CheckboxTree cbTree) { TreeNode node = new TreeNode(xNode.Text, xNode.NodeID, cbTree.ImagesRootPath + xNode.Icon, xNode.Action, ""); node.ImageUrl = ""; node.PopulateOnDemand = (string.IsNullOrEmpty(xNode.Source) ? false : true); //node.SelectAction = (string.IsNullOrEmpty(xNode.Source) ? TreeNodeSelectAction.Select : TreeNodeSelectAction.Expand); node.SelectAction = TreeNodeSelectAction.None; string nodeMarkup = ""; //add our custom checkbox if (cbTree.ShowCheckBoxes) { nodeMarkup += string.Format("<span class=\"treeCheckBox\"><input type='checkbox' id='{0}' name='{0}' value='{1}' onclick='{2}(this);' /></span>", "chk" + node.Value, node.Value, cbTree.OnClientNodeChecked); } if (xNode.Icon.StartsWith(".")) { nodeMarkup += "<div class=\"sprTree " + xNode.Icon.TrimStart('.') + "\"><img class=\"webfx-tree-icon\" src=\"../images/nada.gif\"/> </div>"; } else { nodeMarkup += "<span class=\"treeIcon\"><img src=\"" + cbTree.ImagesRootPath + xNode.Icon + "\"/></span>"; } //show the node as being not published if (xNode.NotPublished.Value) { nodeMarkup += string.Format("<span class=\"treeText\" style='color:{0};'>{1}</span>", cbTree.UnpublishedColor, node.Text); } else { nodeMarkup += string.Format("<span class=\"treeText\">{0}</span>", node.Text); } node.Text = nodeMarkup; return(node); }
private void RenderLocations(ref XmlTree tree) { if (null != this._db) { var locations = this._db.Query <EventLocation>("SELECT * FROM ec_locations"); foreach (var c in locations) { XmlTreeNode node = XmlTreeNode.Create(this); node.NodeID = c.Id.ToString(); node.NodeType = "LocationEntry"; node.Text = c.LocationName; node.Icon = "map.png"; node.Action = "javascript:openLocation(" + c.Id.ToString() + ")"; tree.Add(node); } } }
static XmlTreeNode GetClosestElement(XmlTreeNode treeNode) { XmlTreeNode element = treeNode.Parent as XmlTreeNode; if (treeNode.Parent != null) { foreach (XmlTreeNode child in treeNode.Parent.Nodes) { if (child.Node != null && child.NodeType == XmlNodeType.Element) { element = child; } if (child == treeNode) { break; } } } return(element); }
/// /// Override the render method to create the newsletter tree /// /// public override void Render(ref XmlTree Tree) { Tree.treeCollection.Clear(); var nodeWorkout = XmlTreeNode.Create(this); nodeWorkout.NodeID = "Workout" + Guid.NewGuid(); nodeWorkout.Text = "Workout"; nodeWorkout.Icon = "b_user.png"; nodeWorkout.Action = string.Format("javascript:openRepository({0});", 1355); Tree.Add(nodeWorkout); var nodeExercise = XmlTreeNode.Create(this); nodeExercise.NodeID = "Exercise" + Guid.NewGuid(); nodeExercise.Text = "Exercise"; nodeExercise.Icon = "b_user.png"; nodeExercise.Action = string.Format("javascript:openRepository({0});", 1355); Tree.Add(nodeExercise); }
/// <summary> /// This will call the normal Render method by passing the converted XmlTree to an XmlDocument. /// TODO: need to update this render method to do everything that the obsolete render method does and remove the obsolete method /// </summary> /// <param name="tree"></param> public override void Render(ref XmlTree tree) { using (IRecordsReader macros = SqlHelper.ExecuteReader("select id, macroName from cmsMacro order by macroName")) { while (macros.Read()) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = macros.GetInt("id").ToString(); xNode.Text = macros.GetString("macroName"); xNode.Action = "javascript:openMacro(" + macros.GetInt("id") + ");"; xNode.Icon = "developerMacro.gif"; xNode.OpenIcon = "developerMacro.gif"; OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); } OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } }
public override void Render(ref XmlTree tree) { StyleSheet sn = new StyleSheet(m_id); foreach (StylesheetProperty n in sn.Properties) { XmlTreeNode xNode = XmlTreeNode.Create(this); xNode.NodeID = n.Id.ToString(); xNode.Text = n.Text; xNode.Action = "javascript:openStylesheetProperty(" + n.Id + ");"; xNode.Icon = "settingCssItem.gif"; xNode.OpenIcon = "settingCssItem.gif"; OnBeforeNodeRender(ref tree, ref xNode, EventArgs.Empty); if (xNode != null) { tree.Add(xNode); OnAfterNodeRender(ref tree, ref xNode, EventArgs.Empty); } } }
XmlSchemaInfo GetSchemaInfo() { XmlTreeNode tn = node; if (tn.NodeType == XmlNodeType.Text || tn.NodeType == XmlNodeType.CDATA) { tn = (XmlTreeNode)tn.Parent; } if (tn == null) { return(null); } XmlNode xn = tn.Node; if (xn != null && model != null) { XmlSchemaInfo info = model.GetTypeInfo(xn); return(info); } return(null); }
public EditNodeValue(XmlTreeView view, XmlTreeNode n, string newValue) { this.view = view; this.n = n; this.xn = n.Node; this.newValue = newValue; if (xn is XmlElement) { this.oldValue = xn.InnerText; } else if (xn is XmlProcessingInstruction) { XmlProcessingInstruction pi = ((XmlProcessingInstruction)xn); this.oldValue = pi.Data; } else if (xn != null) { this.oldValue = xn.Value; } }
public TreeParent(XmlTreeView xview, XmlDocument doc, XmlTreeNode node) : this(xview.TreeView, doc, node) { }
/// <summary> /// Move or copy a node from one place to another place in the tree. /// </summary> /// <param name="view">The MyTreeView that we are inserting into</param> /// <param name="source">The node that we are moving. This node may not be in the tree /// and that is ok, so it might be a node that is being cut&paste from another process /// for example</param> /// <param name="target">The existing node that establishes where in the tree we want /// to move the source node to</param> /// <param name="where">The position relative to the target node (before or after)</param> /// <param name="copy">Whether we are moving or copying the source node</param> public MoveNode(XmlTreeView view, XmlTreeNode source, XmlTreeNode target, InsertPosition where, bool copy) { XmlNode sn = source.Node; XmlNode dn = target.Node; this.copy = copy; TreeView tv = view.TreeView; XmlDocument doc = view.Model.Document; this.view = view; this.sourcePosition = source.Index; view.Model.BeginUpdate(); try { if (copy) { this.wasExpanded = source.IsExpanded; XmlTreeNode newSource = view.CreateTreeNode(); if (sn != null) { sn = sn.CloneNode(true); newSource.Node = sn; } source = newSource; } this.sourceParent = new TreeParent(tv, doc, source); this.tp = new TreeParent(tv, doc, target); // normalize destination based on source node type. // for example, if source is an attribute, then it can only be // inserted amongst attributes of another node. if (tp.IsRoot && where != InsertPosition.Child) { if (sn is XmlAttribute) throw new Exception(SR.RootLevelAttributes); if (sn is XmlText || sn is XmlCDataSection) throw new Exception(SR.RootLevelText); if (sn is XmlElement && sn.OwnerDocument.DocumentElement != null && sn.OwnerDocument.DocumentElement != sn) throw new Exception(SR.RootLevelElements); if (dn is XmlDeclaration && where == InsertPosition.Before) throw new Exception(SR.RootLevelBeforeXmlDecl); } if (where != InsertPosition.Child) { if (sn is XmlAttribute) { if (!(dn is XmlAttribute)) { if (tp.AttributeCount != 0) { // move target to valid location for attributes. target = tp.GetChild(tp.AttributeCount - 1); where = InsertPosition.After; } else { // append the attribute. where = InsertPosition.Child; target = (XmlTreeNode)target.Parent; } } } else if (dn is XmlAttribute) { if (!(sn is XmlAttribute)) { int skip = tp.AttributeCount; if (tp.Count > skip) { // Move non-attribute down to beginning of child elements. target = tp.GetChild(skip); where = InsertPosition.Before; } else { // append the node. where = InsertPosition.Child; target = (XmlTreeNode)target.Parent; } } } } this.source = source; this.target = target; this.where = where; this.tp = new TreeParent(tv, doc, target); if (where == InsertPosition.Child) { this.tp.SetParent(target); } } finally { view.Model.EndUpdate(); } }
public TreeData(XmlTreeNode node) { img = node.ImageIndex; XmlNode x = node.Node; if (x != null) { nodeType = (int)x.NodeType; this.xml = x.OuterXml; } }
static bool IsDocumentElement(XmlTreeNode node) { return node.Node != null && node.Node == node.Node.OwnerDocument.DocumentElement; }
public EditAttributeName(XmlTreeNode node, string newName) { this.a = (XmlAttribute)node.Node; this.node = node; this.p = this.a.OwnerElement; Debug.Assert(this.p != null); name = XmlHelpers.ParseName(this.p, newName, XmlNodeType.Attribute); }
/// <summary> /// Insert a new element as a sibling or child of current node. This command can create /// new XmlTreeNodes and new XmlNodes to go with it, or it can /// </summary> public InsertNode(XmlTreeView view) { this.view = view; this.newNode = view.CreateTreeNode(); this.doc = view.Model.Document; this.position = InsertPosition.Child; }
public XmlTreeNode GetTreeNode(XmlDocument owner, XmlTreeNode target, XmlTreeView view) { XmlTreeNode node = view.CreateTreeNode(); if (this.img == -1 && this.xml != null){ Regex regex = new Regex(@"[:_.\w]+\s*=\s*(""[^""]*"")|('[^']*')\s*"); Match m = regex.Match(xml); string trimmed = xml.Trim(); if (m.Success && m.Index == 0 && m.Length == xml.Length) { nodeType = (int)XmlNodeType.Attribute; img = (int)NodeImage.Attribute - 1; } else if (trimmed.StartsWith("<?")) { nodeType = (int)XmlNodeType.ProcessingInstruction; img = (int)NodeImage.PI - 1; } else if (trimmed.StartsWith("<!--")) { nodeType = (int)XmlNodeType.Comment; img = (int)NodeImage.Comment - 1; } else if (trimmed.StartsWith("<![CDATA[")) { nodeType = (int)XmlNodeType.CDATA; img = (int)NodeImage.CData - 1; } else if (trimmed.StartsWith("<")) { nodeType = (int)XmlNodeType.Element; img = (int)NodeImage.Element - 1; } else { nodeType = (int)XmlNodeType.Text; img = (int)NodeImage.Text - 1; } } XmlNode xn = null; XmlNode context = (target != null) ? target.Node : owner; if (this.nodeType == (int)XmlNodeType.Attribute) { int i = this.xml.IndexOf('='); if (i > 0) { string name = this.xml.Substring(0, i).Trim(); XmlName qname = XmlHelpers.ParseName(context, name, XmlNodeType.Attribute); xn = owner.CreateAttribute(qname.Prefix, qname.LocalName, qname.NamespaceUri); string s = this.xml.Substring(i + 1).Trim(); if (s.Length > 2) { char quote = s[0]; s = s.Substring(1, s.Length - 2); // strip off quotes // un-escape quotes in the value. xn.Value = s.Replace(quote == '\'' ? "'" : """, quote.ToString()); } } } else { XmlNamespaceManager nsmgr = XmlHelpers.GetNamespaceScope(context); XmlParserContext pcontext = new XmlParserContext(owner.NameTable, nsmgr, null, XmlSpace.None); XmlTextReader r = null; if (this.xml != null) { r = new XmlTextReader(this.xml, XmlNodeType.Element, pcontext); } else { r = new XmlTextReader(this.stm, XmlNodeType.Element, pcontext); } r.WhitespaceHandling = WhitespaceHandling.Significant; // TODO: add multi-select support, so we can insert multiple nodes also. // And find valid nodes (for example, don't attempt to insert Xml declaration // if target node is not at the top of the document, etc). // For now we just favor XML elements over other node types. ArrayList list = new ArrayList(); while (true){ XmlNode rn = owner.ReadNode(r); if (rn == null) break; if (rn is XmlElement){ xn = rn; NormalizeNamespaces((XmlElement)rn, nsmgr); } list.Add(rn); } if (xn == null && list.Count>0) xn = list[0] as XmlNode; } node.Node = xn; if (!(xn is XmlAttribute)) { view.Invalidate(); if (xn is XmlElement){ if (node.Nodes.Count <= 1){ this.img = ((int)NodeImage.Leaf -1); } } } return node; }
public static void SetData(XmlTreeNode node) { if (node.Node != null) { Clipboard.SetDataObject(new TreeData(node)); } }
public CutCommand(XmlTreeView view, XmlTreeNode node) { this.node = node; this.parent = new TreeParent(view, view.Model.Document, node); index = node.Index; }
public void SetParent(XmlTreeNode parent) { this.parent = parent; if (parent != null && parent.Node != null) { this.SetXmlParent(parent.Node); } }
public void Remove(XmlTreeNode n) { if (n.Node != null) { Remove(n.Node); } n.Remove(); }
public EditProcessingInstructionName(XmlProcessingInstruction pi, NodeLabelEditEventArgs e) { this.pi = pi; this.p = this.pi.ParentNode; this.node = e.Node as XmlTreeNode; Debug.Assert(this.p != null); name = e.Label; this.newpi = pi.OwnerDocument.CreateProcessingInstruction(name, pi.Data); }
public EditAttributeName(XmlTreeNode node, XmlName newName, bool autoGenPrefixes) { this.a = (XmlAttribute)node.Node; this.node = node; name = newName; this.autoGenPrefixes = autoGenPrefixes; }
public EditProcessingInstructionName(XmlTreeNode node, string newName) { this.pi = (XmlProcessingInstruction)node.Node; this.p = this.pi.ParentNode; this.node = node; Debug.Assert(this.p != null); name = newName; this.newpi = pi.OwnerDocument.CreateProcessingInstruction(name, pi.Data); }
public ChangeNode(XmlTreeView view, XmlTreeNode node, XmlNodeType nt) { this.doc = view.Model.Document; this.nt = nt; this.view = view; this.node = node; XmlNode n = node.Node; if (n == null) return; init: this.oldnt = n.NodeType; string innerXml = (oldnt == XmlNodeType.Element) ? n.InnerXml : SpecialUnescape(oldnt, n.Value); string outerXml = n.OuterXml; string qname = n.Name; string localName = n.LocalName; string ns = n.NamespaceURI; bool noName = false; if (qname.StartsWith("#")) { qname = localName = ""; } noName = string.IsNullOrEmpty(qname); if (noName && IsNamedNodeType(nt)) { // Try parsing the content of the node as markup! (but first check for special unescaping // that we do for nested comment/cdata blocks) PasteCommand paste = new PasteCommand(doc, view, InsertPosition.Before, new TreeData(innerXml)); XmlTreeNode nte = paste.NewNode; if (nte != null && IsNamedNodeType(nte.NodeType)) { // then it worked - we extracted a node with a name, so start over. n = newNode = nte.Node; goto init; } } if (newNode == null || newNode.NodeType != nt) { switch (nt) { case XmlNodeType.Element: if (noName) { qname = "element"; } newNode = doc.CreateElement(qname, ns); newNode.InnerXml = innerXml; break; case XmlNodeType.Attribute: if (noName) { qname = "attribute"; } newNode = doc.CreateAttribute(qname, ns); newNode.Value = innerXml; break; case XmlNodeType.Comment: newNode = doc.CreateComment(SpecialEscape(nt, noName ? innerXml : outerXml)); break; case XmlNodeType.ProcessingInstruction: if (noName) { localName = "pi"; } newNode = doc.CreateProcessingInstruction(localName, innerXml); break; case XmlNodeType.Text: newNode = doc.CreateTextNode(noName ? innerXml : outerXml); break; case XmlNodeType.CDATA: newNode = doc.CreateCDataSection(SpecialEscape(nt, noName ? innerXml : outerXml)); break; } } InsertNode icmd = new InsertNode(node, InsertPosition.Before, newNode, true, true); newTreeNode = icmd.NewNode; DeleteNode del = new DeleteNode(doc, node); group = new CompoundCommand(this.Name); group.Add(icmd); group.Add(del); }
/// <summary> /// Insert an existing XmlNode into the tree and create a corresponding XmlTreeNode for it. /// </summary> /// <param name="target">Anchor point for insertion</param> /// <param name="position">Where to insert the new node relative to target node</param> /// <param name="xnode">Provided XmlNode that the new XmlTreeNode will wrap</param> /// <param name="selectNewNode">Whether to select the node in the tree after it's inserted.</param> public InsertNode(XmlTreeNode target, InsertPosition position, XmlNode xnode, bool selectNewNode, bool expandNewNode) { this.view = target.XmlTreeView; this.doc = this.view.Model.Document; this.position = position; this.type = xnode.NodeType; this.newNode = new XmlTreeNode(this.view, xnode); Initialize(newNode, target, position); this.selectNewNode = selectNewNode; this.expandNewNode = expandNewNode; }
InsertNode xmlns; // generated prefix #endregion Fields #region Constructors public EditElementName(XmlElement n, NodeLabelEditEventArgs e) { this.xe = n; this.node = e.Node as XmlTreeNode; this.name = XmlHelpers.ParseName(n, e.Label, n.NodeType); }
public PasteCommand(XmlDocument doc, XmlTreeView view, InsertPosition position, TreeData data) { this.td = data; this.doc = doc; this.target = (XmlTreeNode)view.SelectedNode; if (this.target == null && view.TreeView.Nodes.Count > 0) { this.target = (XmlTreeNode)view.TreeView.Nodes[0]; } if (this.target != null && this.target.NodeType != XmlNodeType.Element && this.target.NodeType != XmlNodeType.Document) { position = InsertPosition.After; } this.position = position; this.view = view; if (td != null) { this.source = td.GetTreeNode(this.doc, this.target, this.view); } }
public EditElementName(XmlTreeNode node, string newName) { this.xe = (XmlElement)node.Node; ; this.node = node; this.name = XmlHelpers.ParseName(this.xe, newName, node.NodeType); }
public NudgeNode(XmlTreeView view, XmlTreeNode node, NudgeDirection dir) { this.node = node; this.dir = dir; this.view = view; }
public EditElementName(XmlTreeNode node, XmlName newName, bool autoGenPrefixes) { this.xe = (XmlElement)node.Node; ; this.node = node; this.name = newName; this.autoGenPrefixes = autoGenPrefixes; }
bool CanHaveChildren(XmlTreeNode target) { return target.NodeType == XmlNodeType.Element || target.NodeType == XmlNodeType.Document; }
public EditNodeName(XmlTreeNode node, string newName) { if (node.Node == null) { throw new ArgumentException(SR.NodeNotCreated); } switch (node.NodeType) { case XmlNodeType.Element: cmd = new EditElementName(node, newName); break; case XmlNodeType.Attribute: cmd = new EditAttributeName(node, newName); break; case XmlNodeType.ProcessingInstruction: cmd = new EditProcessingInstructionName(node, newName); break; default: throw new ArgumentException( string.Format(SR.NodeNameNotEditable, node.NodeType.ToString())); } }
public DeleteNode(XmlDocument doc, XmlTreeNode e) { this.e = e; this.doc = doc; }
public void Edit(object sender, System.EventArgs e) { if ( Nodes.Count > 0 && SelectedNode != null && parent.LabelEdit ) { editingNode = (XmlTreeNode) SelectedNode; if ( editingNode.ConnectedXmlElement != null ) { if ( !closingHandlerAssigned ) { Form parentForm = FindForm(); parentForm.Closing += new CancelEventHandler( parent.form_Closing ); closingHandlerAssigned = true; } int height = editingNode.Bounds.Height; int width = editingNode.Bounds.Width; int left = editingNode.Bounds.Left; int top = editingNode.Bounds.Top; editingNode.ExpandAll(); if ( editingNode.ConnectedXmlElement.HasChildNodes && editingNode.ConnectedXmlElement.FirstChild.NodeType != XmlNodeType.Text ) { height = editingNode.NextNode.Bounds.Bottom - editingNode.Bounds.Top; width = Width - left; } editBox = new TextBox(); editBox.Multiline = true; editBox.BorderStyle = BorderStyle.FixedSingle; editBox.ScrollBars = ScrollBars.Both; editBox.Leave += new EventHandler( editBox_Leave ); editBox.KeyUp += new KeyEventHandler( editBox_KeyUp ); editBox.SetBounds( left, top, width, height ); editingNode.RecurseSubNodes( editingNode.Parent ); editBox.Text = editingNode.SelfAndChildren; Controls.Add( editBox ); editBox.Focus(); } } }
// This constructor takes the reference node public TreeParent(TreeView view, XmlDocument doc, XmlTreeNode node) { //this.node = node; if (node != null) this.nodeInTree = ((TreeView)node.TreeView == view); this.view = view; this.doc = doc; this.parent = (XmlTreeNode)node.Parent; //this.xnode = node.Node; if (node.Parent != null) { this.xparent = ((XmlTreeNode)node.Parent).Node; } else if (node.Node != null) { this.xparent = node.Node.ParentNode; } if (this.xparent == null){ this.xparent = this.doc; } originalParent = this.xparent; if (this.parent == null) { this.xparent = this.originalParent = this.doc; } }
InsertNode xmlns; // generated prefix #endregion Fields #region Constructors public EditAttributeName(XmlAttribute attr, NodeLabelEditEventArgs e) { this.a = attr; this.node = e.Node as XmlTreeNode; this.p = this.a.OwnerElement; Debug.Assert(this.p != null); name = XmlHelpers.ParseName(this.p, e.Label, XmlNodeType.Attribute); }
private void RecurseAndAssignNodes( XmlNode elem ) { string attrs = string.Empty; XmlTreeNode addedNode = null; if ( elem.NodeType == XmlNodeType.Element ) { foreach ( XmlAttribute attr in elem.Attributes ) { attrs += " " + attr.Name + "=\"" + attr.Value + "\""; } } if ( elem.Equals( document.DocumentElement ) ) { addedNode = new XmlTreeNode( "<" + elem.Name + attrs + ">", elem ); Nodes.Add( addedNode ); InnerXmlTreeView.CurrentNode = addedNode; Nodes.Add( new XmlTreeNode( "</" + elem.Name + ">", null ) ); } else if ( elem.HasChildNodes && elem.ChildNodes[0].NodeType == XmlNodeType.Text ) { addedNode = new XmlTreeNode( "<" + elem.Name + attrs + ">" + elem.InnerText + "</" + elem.Name + ">", elem ); InnerXmlTreeView.CurrentNode.Nodes.Add( addedNode ); InnerXmlTreeView.CurrentNode = addedNode; } else if ( elem is XmlElement && ( (XmlElement) elem ).IsEmpty ) { addedNode = new XmlTreeNode( "<" + elem.Name + attrs + "/>", elem ); InnerXmlTreeView.CurrentNode.Nodes.Add( addedNode ); InnerXmlTreeView.CurrentNode = addedNode; } else { addedNode = new XmlTreeNode( "<" + elem.Name + attrs + ">", elem ); InnerXmlTreeView.CurrentNode.Nodes.Add( addedNode ); InnerXmlTreeView.CurrentNode = addedNode; InnerXmlTreeView.CurrentNode.Parent.Nodes.Add( new XmlTreeNode( "</" + elem.Name + ">", null ) ); } foreach ( XmlNode child in elem.ChildNodes ) { if ( child.NodeType == XmlNodeType.Element ) { RecurseAndAssignNodes( child ); } else if ( child.NodeType == XmlNodeType.Comment ) { InnerXmlTreeView.CurrentNode.Nodes.Add( new XmlTreeNode( child.OuterXml, child ) ); } } if ( InnerXmlTreeView.CurrentNode.Parent != null ) { InnerXmlTreeView.CurrentNode = InnerXmlTreeView.CurrentNode.Parent; } }
public void Insert(int pos, InsertPosition position, XmlTreeNode n, bool selectIt) { if (n.Node != null) { this.Insert(pos, position, n.Node); } int i = pos; if (position == InsertPosition.After) i++; if (parent == null) { view.Nodes.Insert(i, n); } else { parent.Nodes.Insert(i, n); if (selectIt && !parent.IsExpanded) { parent.Expand(); // this will change image index of leaf nodes. } } n.Invalidate(); if (selectIt) { view.SelectedNode = n; } }