Exemple #1
0
        //删除目录
        private void menuItemDeleteDir_Click(object sender, EventArgs e)
        {
            if (MsgBox.ShowQuestionMessage("确定删除该目录吗,这将会删除该目录下所有文件", "提示信息") == DialogResult.Yes)
            {
                TreeNode dirNode = tvCode.SelectedNode;
                tvCode.Nodes.Remove(dirNode);
                DirectoryInfo di      = dirNode.Tag as DirectoryInfo;
                string        dirName = di.FullName;
                di.Delete(true);

                //删除目录时,同时关闭该目录下已打开的文档
                List <IDockContent> deletingDocs = new List <IDockContent>();
                foreach (IDockContent content in this.DockPanel.Documents)
                {
                    if (content is DockDocument)
                    {
                        DockDocument doc = content as DockDocument;
                        //判断文档所属目录是否是该删除目录,若是则将其关闭
                        if (Path.GetDirectoryName(doc.FileName) == dirName)
                        {
                            deletingDocs.Add(doc);
                        }
                    }
                }
                foreach (IDockContent content in deletingDocs)
                {
                    content.DockHandler.Close();
                }
            }
        }
Exemple #2
0
        public void OpenDockDocument(string fileName, string codeType)
        {
            //打开文件判断文件大小,不打开过大的文件
            FileInfo fi = new FileInfo(fileName);

            if (fi.Length > 2 * 1024 * 1024)
            {
                MsgBox.Show("大于2M的文件请用其他编辑器打开");
                return;
            }

            if (FindDockDocument(fileName) != null)
            {
                MsgBox.Show(string.Format("文件[{0}]已经打开", fileName));
                return;
            }

            DockDocument doc = new DockDocument();

            doc.LoadFileContent(fileName);
            doc.SetDocumentCodeType(codeType);

            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                doc.MdiParent = this;
                doc.Show();
            }
            else
            {
                doc.Show(dockPanel);
            }
        }
Exemple #3
0
        //删除文件
        private void menuItemDeleteFile_Click(object sender, EventArgs e)
        {
            if (MsgBox.ShowQuestionMessage("确定删除该文件吗", "提示信息") == DialogResult.Yes)
            {
                TreeNode fileNode = tvCode.SelectedNode;
                tvCode.Nodes.Remove(fileNode);

                FileInfo fi          = fileNode.Tag as FileInfo;
                string   oldFileName = fi.FullName;
                File.Delete(fi.FullName);

                //若删除的文档已经打开,则将其关闭
                IDockContent deletingDoc = null;
                foreach (IDockContent content in this.DockPanel.Documents)
                {
                    if (content is DockDocument)
                    {
                        DockDocument doc = content as DockDocument;
                        if (doc.FileName == oldFileName)
                        {
                            deletingDoc = doc;
                            break;
                        }
                    }
                }
                if (deletingDoc != null)
                {
                    deletingDoc.DockHandler.Close();
                }
            }
        }
Exemple #4
0
        /// <summary>
        /// 新建文档
        /// </summary>
        /// <param name="caption">文档所在窗体的标题,如“Class1.cs”</param>
        /// <param name="codeType">代码类型</param>
        /// <param name="content">文档文本内容</param>
        public void NewDockDocument(string caption, string codeType, string content)
        {
            DockDocument doc = new DockDocument();

            int count = 1;
            string ext = CodeTypeHelper.GetExtention(codeType);
            string text = string.Format("{0}{1}{2}", caption, count.ToString(), ext);
            while (FindDockDocument(text) != null)
            {
                count++;
                if (count > 1)
                {
                    text = string.Format("{0}{1}{2}", caption, count.ToString(), ext);
                }
                else
                {
                    text = string.Format("{0}{1}", caption, ext);
                }
            }
            doc.Text = text;
            doc.LoadTextContent(content, codeType);

            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                doc.MdiParent = this;
                doc.Show();
            }
            else
                doc.Show(dockPanel);
        }
Exemple #5
0
        //删除模板文件
        private void menuItemDeleteTemplate_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("确定删除该模板文件吗", "提示信息", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.OK)
            {
                TreeNode fileNode = tvTemplate.SelectedNode;
                tvTemplate.Nodes.Remove(fileNode);

                FileInfo fi          = fileNode.Tag as FileInfo;
                string   oldFileName = fi.FullName;
                File.Delete(fi.FullName);

                //若删除的模板文档已经打开,则将其关闭
                IDockContent deletingDoc = null;
                foreach (IDockContent content in this.DockPanel.Documents)
                {
                    if (content is DockDocument)
                    {
                        DockDocument doc = content as DockDocument;
                        if (doc.FileName == oldFileName)
                        {
                            deletingDoc = doc;
                            break;
                        }
                    }
                }
                if (deletingDoc != null)
                {
                    deletingDoc.DockHandler.Close();
                }
            }
        }
        /// <summary>
        /// 新建文档
        /// </summary>
        /// <param name="caption">文档所在窗体的标题,如“Class1.cs”</param>
        /// <param name="codeType">代码类型</param>
        /// <param name="content">文档文本内容</param>
        public void NewDockDocument(string caption, string codeType, string content)
        {
            DockDocument doc = new DockDocument();

            int    count = 1;
            string ext   = CodeTypeHelper.GetExtention(codeType);
            string text  = string.Format("{0}{1}{2}", caption, count.ToString(), ext);

            while (FindDockDocument(text) != null)
            {
                count++;
                if (count > 1)
                {
                    text = string.Format("{0}{1}{2}", caption, count.ToString(), ext);
                }
                else
                {
                    text = string.Format("{0}{1}", caption, ext);
                }
            }
            doc.Text = text;
            doc.LoadTextContent(content, codeType);

            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                doc.MdiParent = this;
                doc.Show();
            }
            else
            {
                doc.Show(dockPanel);
            }
        }
Exemple #7
0
        void OpenCodeFile(string fileName)
        {
            foreach (IDockContent content in this.DockPanel.Documents)
            {
                if (content is DockDocument)
                {
                    DockDocument doc = content as DockDocument;
                    if (doc.FileName == fileName)
                    {
                        doc.DockHandler.Activate();
                        return;
                    }
                }
            }

            base.MainForm.OpenDockDocument(fileName, CodeType.CSHARP);
        }
Exemple #8
0
        private void tvCode_AfterLabelEdit(object sender, NodeLabelEditEventArgs e)
        {
            if (string.IsNullOrEmpty(e.Label))
            {
                return;
            }

            //节点重命名后,更新对应的Tag对象
            if (e.Label == e.Node.Text)
            {
                return;                        //标签文本没有改变
            }
            if (e.Node.Tag is DirectoryInfo)
            {
                DirectoryInfo di         = e.Node.Tag as DirectoryInfo;
                string        oldDirName = di.FullName;
                string        newDirName = Path.Combine(di.Parent.FullName, e.Label);

                di.MoveTo(newDirName);
                e.Node.Tag = new DirectoryInfo(newDirName);

                //重命名目录后,需要更新该目录下已打开文档的FileName属性
                foreach (IDockContent content in this.DockPanel.Documents)
                {
                    if (content is DockDocument)
                    {
                        DockDocument doc = content as DockDocument;
                        //判断文档所属目录是否是该删除目录,若是则将其关闭
                        if (Path.GetDirectoryName(doc.FileName) == oldDirName)
                        {
                            doc.FileName = doc.FileName.Replace(oldDirName, newDirName);
                        }
                    }
                }
            }
            if (e.Node.Tag is FileInfo)
            {
                FileInfo fi          = e.Node.Tag as FileInfo;
                string   oldFileName = fi.FullName;
                string   newFileName = Path.Combine(fi.DirectoryName, e.Label);

                fi.MoveTo(newFileName);
                e.Node.Tag = new FileInfo(newFileName);
                e.Node.EndEdit(false);
                ExpendCodeDir(new DirectoryInfo(fi.DirectoryName), e.Node.Parent);

                //如果被重命名的文件已经被打开,更新打开的文档实例
                foreach (IDockContent content in this.DockPanel.Documents)
                {
                    if (content is DockDocument)
                    {
                        DockDocument doc = content as DockDocument;
                        if (doc.FileName == oldFileName)
                        {
                            doc.Text     = Path.GetFileName(newFileName);
                            doc.FileName = newFileName;
                            //doc.DockHandler.Activate();
                            break;
                        }
                    }
                }
            }
        }
Exemple #9
0
        public void OpenDockDocument(string fileName, string codeType)
        {
            //打开文件判断文件大小,不打开过大的文件
            FileInfo fi = new FileInfo(fileName);
            if (fi.Length > 2 * 1024 * 1024)
            {
                MessageBox.Show("大于2M的文件请用其他编辑器打开");
                return;
            }

            if (FindDockDocument(fileName) != null)
            {
                MessageBox.Show(string.Format("文件[{0}]已经打开", fileName));
                return;
            }

            DockDocument doc = new DockDocument();
            doc.LoadFileContent(fileName);
            doc.SetDocumentCodeType(codeType);

            if (dockPanel.DocumentStyle == DocumentStyle.SystemMdi)
            {
                doc.MdiParent = this;
                doc.Show();
            }
            else
                doc.Show(dockPanel);
        }