private void GetOpenItems(TmpltBaseTreeNode treeNode, List <string> _openItems) { if (treeNode == null) { return; } foreach (TreeNode treenode in treeNode.Nodes) { TmpltBaseTreeNode node = treenode as TmpltBaseTreeNode; if (node != null && node.IsExpanded) { if (node is PartElementNode) { SnipPartXmlElement snipPartElement = ((TmpltBaseTreeNode)node).Element as SnipPartXmlElement; _openItems.Add(snipPartElement.SnipPartId); } else if (node is SnipElementNode) { SnipXmlElement snipElement = ((TmpltBaseTreeNode)node).Element as SnipXmlElement; _openItems.Add(snipElement.Id); } else if (node is TmpltElementNode) { TmpltSimpleExXmlElement tmpltElement = ((TmpltBaseTreeNode)node).Element as TmpltSimpleExXmlElement; _openItems.Add(tmpltElement.Id); } } GetOpenItems(node, _openItems); } }
/// <summary> /// 修改NODE显示的TEXT /// </summary> /// <param name="strNewText"></param> public virtual void ChangeNodeText(string strNewText) {//对节点重命名暂时仅支持页面片的重命名! TmpltBaseTreeNode tmpltBaseTreeNode = this; //找到对应的模板1 while (!(tmpltBaseTreeNode is TmpltElementNode)) { tmpltBaseTreeNode = (TmpltBaseTreeNode)tmpltBaseTreeNode.Parent; } TmpltSimpleExXmlElement tmpltElement = tmpltBaseTreeNode.Element as TmpltSimpleExXmlElement; //得到对应的模板文件DOC TmpltXmlDocument tmpltDocument = tmpltElement.GetIndexXmlDocument(); if (this is SnipElementNode) { SnipXmlElement snipElement = ((this as SnipElementNode).Element) as SnipXmlElement; snipElement.SnipName = strNewText; //通知页面设计器,更改FORM的TEXT string[] strArray = new string[2]; strArray[0] = snipElement.Id; strArray[1] = strNewText; SdsiteXmlDocument.OnSnipDesignerFormTextChange(new EventArgs <string[]>(strArray)); } }
public TmpltElementNode(TmpltSimpleExXmlElement element) : base(element) { this.Text = AbsoluteFileName; this.Nodes.Add("没有页面片"); this.ToolTipText = ((TmpltSimpleExXmlElement)Element).TmpltType.ToString(); _NodeExpand = false; //初始化时没打开过的状态 }
/// <summary> /// 新建模板 /// </summary> /// <param name="m_tree"></param> /// <param name="myType"></param> public void NewTmplt(FolderXmlElement parentEle, TmpltType myType) { //获得父频道节点,父模板文件夹节点 //((BaseFolderElementNode)CurrentNode).Element, NewTmpltSetupForm tmpltForm = new NewTmpltSetupForm(parentEle, myType); if (tmpltForm.ShowDialog() == DialogResult.OK) { TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.CreateTmplt(parentEle, myType, tmpltForm.TmpltTitle, false, tmpltForm.TmpltWidth, tmpltForm.TmpltHeight, tmpltForm.BackImage); Service.Workbench.OpenWorkDocument(WorkDocumentType.TmpltDesigner, tmpltEle.Id); } }
public CopyTmpltOherTypeForm(TmpltSimpleExXmlElement tmpltEle) { InitializeComponent(); copyEle = tmpltEle; m_tree = new MyTreeView(); m_tree.TreeMode = TreeMode.SelectTmpltFolder; m_tree.LoadTreeData(); m_tree.HideSelection = false; m_tree.Dock = DockStyle.Fill; TreePanel.Controls.Add(m_tree); NameLab.Text = "命名为:"; m_tree.AfterSelect += new TreeViewEventHandler(m_tree_AfterSelect); }
/// <summary> /// 重命名模板文件夹 /// </summary> /// <param name="anyNode"></param> private void RenewFloderText(XmlNodeList anyNode) { foreach (XmlNode node in anyNode) { if (node is FolderXmlElement) { RenewFloderText(node.ChildNodes); } else if (node is TmpltSimpleExXmlElement) { TmpltSimpleExXmlElement tmpltElement = node as TmpltSimpleExXmlElement; TmpltBaseTreeNode tmpltBaseNode = GetElementNode(tmpltElement.Id); tmpltBaseNode.RenewNodeText(tmpltBaseNode); } } }
/// <summary> /// 删除的是整个文件夹 /// </summary> /// <param name="anyNode"></param> private void RemoveTmpltTreeNode(XmlNodeList anyNode) { foreach (XmlNode node in anyNode) { if (node is FolderXmlElement) { RemoveTmpltTreeNode(node.ChildNodes); RemoveElementNode((node as FolderXmlElement).Id); } else if (node is TmpltSimpleExXmlElement) { TmpltSimpleExXmlElement tmpltElement = node as TmpltSimpleExXmlElement; TmpltBaseTreeNode tmpltBaseNode = GetElementNode(tmpltElement.Id); tmpltBaseNode.RemoveChildNode(tmpltBaseNode); } } }
public override bool CannelSave() { if (string.IsNullOrEmpty(TmpltDesign.strRectsData)) { return(false); } //得到该模板对应的 TmpltSimpleExXmlElement TmpltSimpleExXmlElement ele = Service.Sdsite.CurrentDocument.GetTmpltElementById(TmpltID); if (ele != null) { TmpltXmlDocument tmpltDoc = Service.Sdsite.CurrentDocument.GetTmpltDocumentById(TmpltID); tmpltDoc.DocumentElement.RemoveChild(tmpltDoc.GetRectsElement()); XmlElement newRects = tmpltDoc.CreateElement("rects"); newRects.InnerXml = TmpltDesign.strRectsData; tmpltDoc.DocumentElement.AppendChild(newRects); } return(true); }
public MdiTmpltDesignForm(string tmpltID) { ResourcesReader.SetControlPropertyHelper(this); TmpltID = tmpltID; SnipDesignerForms = new List <Form>(); InitializeComponent(); this.ShowIcon = true; this.Icon = Icon.FromHandle(ResourceService.GetResourceImage("tree.img.templet").GetHicon()); TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.GetTmpltElementById(tmpltID); if (tmpltEle == null) { MessageService.Show("文件不存在,打开失败!", MessageBoxButtons.OK, MessageBoxIcon.Error); BeginClose(); return; } this.Text = tmpltEle.Title; Service.Sdsite.CurrentDocument.ElementTitleChanged += new EventHandler <ChangeTitleEventArgs>(CurrentDocument_ElementTitleChanged); Service.Workbench.WorkDocumentNewOpened += new EventHandler <EventArgs <FormData> >(WorkbenchService_WorkDocumentNewOpened); Debug.Assert(!string.IsNullOrEmpty(TmpltID)); TmpltSimpleExXmlElement ele = Service.Sdsite.CurrentDocument.GetTmpltElementById(TmpltID); if (ele == null || !File.Exists(ele.AbsoluteFilePath)) { MessageService.Show(StringParserService.Parse("${res:tmpltDesign.tmpltDrawPanel.message.mdiFormLoad}"), MessageBoxButtons.OK, MessageBoxIcon.Error); BeginClose(); return; } TmpltDoc = ele.GetIndexXmlDocument(); InitTmpltInfo(); TmpltDesign.Dock = DockStyle.Fill; this.Controls.Add(TmpltDesign); TmpltDesign.BringToFront(); }
/// <summary> /// 生成模板文件 /// </summary> /// <param name="simpleEle"></param> public void BuildTmpltFile(SimpleExIndexXmlElement simpleEle) { //添加模板到Dictionary字典中 AddElementToDictionary(simpleEle); /// tmpltFolderAbsPath ="Y:\zha\zhangling\projectname\TmpltRootFolder"; ///string tmpltFolderAbsPath = Path.Combine(sdsiteAbsPath, SdsiteDocument.TmpltFolder.FileName); TmpltSimpleExXmlElement tmpltEle = (TmpltSimpleExXmlElement)simpleEle; string tmpltId = tmpltEle.Id; TmpltXmlDocument tmpltDoc = ToHtmlHelperObj.SdsiteXmlDocument.GetTmpltDocumentById(tmpltId); if (tmpltEle.IsDeletedRecursive) { //删除模板本身的文件 //删除此模板文件对应的模板文件夹(内有多个snip文件) //删除相应的css文件 //string filePath = tmpltFolderAbsPath + @"\" + tmpltId + CommonService.Inc; //FileService.FileDelete(filePath); //string folderPath = tmpltFolderAbsPath + @"\" + tmpltId; //FolderService.FolderDelete(folderPath); //string cssPath = tmpltFolderAbsPath + @"\" + CommonService.Css + @"\" + tmpltId + CssDAT; //FileService.FileDelete(cssPath); tmpltDoc.DeleteXhtml(ToHtmlHelperObj); } else if (!tmpltEle.IsAlreadyPublished) //新建 { //打开相应的模板 //生成本身的文件.css //遍历生成相应的snip文件 //string tmpltPath = tmpltFolderAbsPath + @"\" + tmpltId + CommonService.Inc; //TmpltXmlDocument tmpltDoc = SdsiteDocument.GetTmpltDocumentById(tmpltId); //tmpltDoc.SaveXhtml(); //tmpltDoc.SaveXhtml(tmpltPath); //string tmpltCssPath = tmpltFolderAbsPath + @"\" + tmpltId + @"\" + CssDAT; //tmpltDoc.SaveCss(); tmpltDoc.SaveXhtml(ToHtmlHelperObj); //string folderPath = tmpltFolderAbsPath + @"\" + tmpltId; XmlNodeList snipList = tmpltDoc.GetSnipElementList(); foreach (var item in snipList) { SnipXmlElement snipEle = item as SnipXmlElement; //string snipfile = snipEle.Id + CommonService.Inc; //string snipFilePath = Path.Combine(folderPath, snipfile); //snipEle.SaveXhtml(); //snipEle.SaveXhtml(snipFilePath); snipEle.SaveXhtml(ToHtmlHelperObj); } } else { //此处没有路径改变的问题 if (tmpltEle.IsModified) { //打开相应的模板文件 //则需要重新生成本身的文件,及有改变过的snip的对应的文件 //tmpltDoc.SaveXhtml(); //方法内部在保存此文件时,还需要检查此文件是否存在,存在,则删除掉,然后将其在保存 //tmpltDoc.SaveCss(); tmpltDoc.SaveXhtml(ToHtmlHelperObj); Dictionary <string, string> dic = new Dictionary <string, string>(); XmlNodeList snipList = tmpltDoc.GetSnipElementList(); foreach (var item in snipList) { SnipXmlElement snipEle = item as SnipXmlElement; if (snipEle.IsModified) { //则需要重新生成 // snipEle.SaveXhtml(); snipEle.SaveXhtml(ToHtmlHelperObj); } string snipFileName = snipEle.Id + CommonService.Inc; dic.Add(snipFileName, ""); } //看是否存在多余的snip文件,并将其删除 string snipFolderPath = sdWebAbsPath + @"\" + SdsiteDocument.TmpltFolder.Name + @"\" + tmpltId; string[] allSnipFile = GetAllSnipFile(snipFolderPath); foreach (var file in allSnipFile) { if (!dic.ContainsKey(file)) { //删除此文件 string filePath = snipFolderPath + @"\" + file; FileService.FileDelete(filePath); } } } } }
/// <summary> /// 将模板复制为其他类型的模板 /// </summary> /// <param name="copyEle"></param> public void CopyTmpltToOtherType(TmpltSimpleExXmlElement copyEle) { CopyTmpltOherTypeForm copyTmplt = new CopyTmpltOherTypeForm(copyEle); copyTmplt.ShowDialog(); }
/// <summary> /// 定位到模板/页面片/PART /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TmpltTreeView_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e) { TmpltBaseTreeNode tmpltBaseNode = e.Node as TmpltBaseTreeNode; if (tmpltBaseNode == null) { return; } switch (tmpltBaseNode.NodeType) { case TreeNodeType.Tmplt: //打开(或激活)模板 Service.Workbench.OpenWorkDocument(WorkDocumentType.TmpltDesigner, ((TmpltSimpleExXmlElement)tmpltBaseNode.Element).Id); break; case TreeNodeType.Snip: { //打开页面片 //得到对应的页面片 SnipElementNode snipElementNode = tmpltBaseNode as SnipElementNode; SnipXmlElement snipElement = snipElementNode.Element as SnipXmlElement; //得到页面片所属的模板文件 TmpltElementNode tmpltElementNode = snipElementNode.Parent as TmpltElementNode; TmpltSimpleExXmlElement tmpltElement = tmpltElementNode.Element as TmpltSimpleExXmlElement; //先打开(或激活)对应的模板 如果该模板已经打开,不用打开也不用激活她,因为目的是为了打开页面片 //如果打开的话回出现令人烦的闪烁现象 if (!Service.Workbench.GetResultKeyID(WorkDocumentType.TmpltDesigner, tmpltElement.Id)) { Service.Workbench.OpenWorkDocument(WorkDocumentType.TmpltDesigner, tmpltElement.Id); } //打开(激活)页面片 Service.Workbench.OpenWorkDocument(WorkDocumentType.SnipDesigner, snipElement.Id, tmpltElement.Id); //因为如果添加一个页面片且没有保存,再重命名,新的名不能保存,模板里没有对应的内容 //所以的通知页面片设计器,将FORM的TEXT进行修改 snipElementNode.ChangeNodeText(e.Node.Text); } break; case TreeNodeType.SnipPart: { //找到PART对应的页面片 PartElementNode partElemetNode = tmpltBaseNode as PartElementNode; SnipPartXmlElement snipPartElement = partElemetNode.Element as SnipPartXmlElement; TmpltBaseTreeNode tmpltNode = (TmpltBaseTreeNode)partElemetNode; while (!(tmpltNode is SnipElementNode)) { tmpltNode = (TmpltBaseTreeNode)(tmpltNode.Parent); } //得到对应的页面片 SnipElementNode snipElementNode = tmpltNode as SnipElementNode; SnipXmlElement snipElement = snipElementNode.Element as SnipXmlElement; ////得到页面片所属的模板文件 TmpltElementNode tmpltElementNode = snipElementNode.Parent as TmpltElementNode; TmpltSimpleExXmlElement tmpltElement = tmpltElementNode.Element as TmpltSimpleExXmlElement; //先打开(或激活)对应的模板 if (!Service.Workbench.GetResultKeyID(WorkDocumentType.TmpltDesigner, tmpltElement.Id)) { Service.Workbench.OpenWorkDocument(WorkDocumentType.TmpltDesigner, tmpltElement.Id); } //打开页面片! Service.Workbench.OpenWorkDocument(WorkDocumentType.SnipDesigner, snipElement.Id, tmpltElement.Id); string [] strArray = new string[2]; strArray[0] = snipElement.Id; strArray[1] = snipPartElement.SnipPartId; SdsiteXmlDocument.OnOrientationPart(new EventArgs <string[]>(strArray)); } break; } }
public TmpltNode(TmpltSimpleExXmlElement element) : base(element) { this.Text = element.Title; }
public virtual int AddChildNode(int index, BaseTreeNode node) { int result = index; ///先添加到节点中 if (index == -1) { result = this.Nodes.Add(node); } else { this.Nodes.Insert(index, node); } ///设置图标 node.SelectedImageKey = node.ImageKey = node.FactImageKey; ///初始化节点状态 TreeView.InitNode(node); ///检查文件是否正常 if (node is ElementNode) { ElementNode elementNode = (ElementNode)node; ///添加到TreeNode的dic容器里去 if (TreeView.TreeMode == TreeMode.General && elementNode.NodeType != TreeNodeType.Link) { TreeView.SetElementNode(elementNode); } ///检查文件是否存在:不存在,则在图标上画一个感叹号 if (!Utility.File.Exists(elementNode.Element.AbsoluteFilePath)) { string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.ExcalmatoryPoint); if (!this.TreeView.ImageList.Images.ContainsKey(signKey)) { ///若是资源文件节点,则先确定图标已经存在 if (elementNode is ResourceFileNode) { ResourceFileNode fileNode = (ResourceFileNode)elementNode; fileNode.InsureIcon(); } ///画标记 Image signImage = this.TreeView.ImageList.Images[node.FactImageKey]; Service.Draw.DrawSign(signImage, SignType.ExcalmatoryPoint); this.TreeView.ImageList.Images.Add(signKey, signImage); } node.SelectedImageKey = node.ImageKey = signKey; if (elementNode.IsFolder) { node.ToolTipText = "此文件夹不存在!"; } else { node.ToolTipText = "此文件不存在!"; } } else { bool isHealthy = true; switch (elementNode.Element.DataType) { ///检查非首页型模板是否有正文型页面片 case DataType.Tmplt: { TmpltSimpleExXmlElement tmpltEle = elementNode.Element as TmpltSimpleExXmlElement; if (tmpltEle.TmpltType != TmpltType.Home && !tmpltEle.HasContentSnip) { isHealthy = false; elementNode.ToolTipText = "此模板没有正文型页面片。属于不完整模板。\r\n请为此模板创建正文型页面片,否则关联到它的页面无法正常生成。"; } break; } ///检查页面是否正确关联了模板 case DataType.Page: { PageSimpleExXmlElement pageEle = elementNode.Element as PageSimpleExXmlElement; if (string.IsNullOrEmpty(pageEle.TmpltId)) { isHealthy = false; elementNode.ToolTipText = "此页面没有设置关联模板,属于不完整页面。\r\n请重新选择关联模板,否则将无法生成最终页面。"; } else { TmpltSimpleExXmlElement tmpltEle = Service.Sdsite.CurrentDocument.GetTmpltElementById(pageEle.TmpltId); if (tmpltEle == null || !File.Exists(tmpltEle.AbsoluteFilePath)) { isHealthy = false; elementNode.ToolTipText = "此页面关联的模板未能找到,属于不完整页面。\r\n请重新选择关联模板,否则无法生成最终页面。"; } else { isHealthy = true; //ElementNode tmpltNode = TreeView.GetElementNode(tmpltEle.Id); //if (tmpltNode != null) //{ // elementNode.ToolTipText = "此页面完整,关联的模板是:" + tmpltNode.FullPath + "。\r\n可生成最终页面。"; //} } } break; } } ///不健康节点,在图标上添加标记 if (!isHealthy) { string signKey = Service.Draw.GetSignKey(node.FactImageKey, SignType.QuestionPoint); if (!this.TreeView.ImageList.Images.ContainsKey(signKey)) { Image signImage = this.TreeView.ImageList.Images[node.FactImageKey]; Service.Draw.DrawSign(signImage, SignType.QuestionPoint); this.TreeView.ImageList.Images.Add(signKey, signImage); } node.SelectedImageKey = node.ImageKey = signKey; } } } return(result); }