Esempio n. 1
0
        /// <summary>
        /// 初始化
        /// </summary>
        /// <param name="e"></param>
        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);

            TreeNode rootNode = new TreeNode()
            {
                Text = Path.GetFileName(rootPath)
            };

            TreeNodeHelper.Edit(rootNode, "isDir", "1");

            dirView.Nodes.Add(rootNode);

/*            string allText = File.ReadAllText("Test_Data/demo.json");
 *          dynamic dirsObj = JsonConvert.DeserializeObject(allText);
 *          CreateTreeNodes(dirsObj, dirView.Nodes[0]);*/

            dirView.Nodes[0].Expand();

            comboBox1.Items.Add("默认组");
            AllPlaceHolders.Add("默认组", new Dictionary <string, string>());
            comboBox1.SelectedIndex = comboBox1.Items.Count - 1;

//            Placeholders.Add("123", "$$$");
//            Placeholders.Add("1231", "$$$1");

            dirView.ImageList = treeViewIcon;
        }
Esempio n. 2
0
        /// <summary>
        /// 生成树节点
        /// </summary>
        /// <param name="dirsObjs"></param>
        /// <param name="node"></param>
        public void CreateTreeNodes(dynamic dirsObjs, TreeNode node)
        {
            foreach (JObject dirsObj in dirsObjs)
            {
                bool flag = dirsObj.ContainsKey("children");

                if (flag)
                {
                    TreeNode newNode = new TreeNode
                    {
                        Text               = dirsObj.GetValue("name").ToString(),
                        ImageIndex         = 0,
                        SelectedImageIndex = 0,
                    };

                    TreeNodeHelper.Edit(newNode, "isDir", "1");

                    node.Nodes.Add(newNode);
                    var children = dirsObj.GetValue("children");
                    if (children != null)
                    {
                        CreateTreeNodes(children, newNode);
                    }
                }
                else
                {
                    TreeNode newNode = new TreeNode()
                    {
                        Text = dirsObj.GetValue("name").ToString()
                    };
                    if (!string.IsNullOrEmpty(dirsObj.GetValue("template")?.ToString()))
                    {
                        //                        newNode.Tag = dirsObj.GetValue("template").ToString();
                        TreeNodeHelper.Edit(newNode, "template", dirsObj.GetValue("template").ToString());
                        TreeNodeHelper.Edit(newNode, "isDir", 0);
                    }

                    if (dirsObj.GetValue("isDir")?.ToString() == "1")
                    {
                        newNode.ImageIndex         = 0;
                        newNode.SelectedImageIndex = 0;
                        TreeNodeHelper.Edit(newNode, "isDir", "1");
                    }
                    else
                    {
                        newNode.ImageIndex         = 1;
                        newNode.SelectedImageIndex = 1;
                        TreeNodeHelper.Edit(newNode, "isDir", "0");
                    }

                    node.Nodes.Add(newNode);
                }
            }
        }
Esempio n. 3
0
        public void CreateTreeNodesDo(string path, TreeNode node, string[] exts)
        {
            string[] files = Directory.GetFiles(path).Concat(Directory.GetDirectories(path)).ToArray();


            foreach (string file in files)
            {
                if (File.Exists(file))
                {
                    if (exts.Contains(Path.GetExtension(file).Substring(1)))
                    {
                        TreeNode newNode = new TreeNode()
                        {
                            Text               = Path.GetFileName(file),
                            ImageIndex         = 1,
                            SelectedImageIndex = 1
                        };
                        TreeNodeHelper.Edit(newNode, "isDir", "0");
                        string content = File.ReadAllText(file);
                        TreeNodeHelper.Edit(newNode, "template", content);

                        node.Nodes.Add(newNode);
                    }
                }
                else if (Directory.Exists(file))
                {
                    TreeNode newNode = new TreeNode()
                    {
                        Text               = Path.GetFileName(file),
                        ImageIndex         = 0,
                        SelectedImageIndex = 0
                    };
                    TreeNodeHelper.Edit(newNode, "isDir", "1");
                    node.Nodes.Add(newNode);
                    CreateTreeNodesDo(file, newNode, exts);
                }
            }
        }
Esempio n. 4
0
        protected void createDirOrFile(bool isDir)
        {
            if (dirView.SelectedNode == null)
            {
                Tip tip = new Tip();
                tip.Show();
            }
            else if (TreeNodeHelper.Get <string>(dirView.SelectedNode, "isDir") == "0")
            {
                Tip tip = new Tip("请选择文件夹");
                tip.Show();
            }
            else
            {
                bool isFirst = true;
                dirView.SelectedNode.Expand();
                int i = 0;
                while (true)
                {
                    bool b = false;
                    foreach (TreeNode node in dirView.SelectedNode.Nodes)
                    {
                        if (isDir)
                        {
                            b = node.Text.Equals(isFirst ? $"新建文件夹" : $"新建文件夹({i})");
                        }
                        else
                        {
                            b = node.Text.Equals(isFirst ? $"新建文件" : $"新建文件({i})");
                        }

                        if (b)
                        {
                            break;
                        }
                    }

                    if (b)
                    {
                        isFirst = false;
                        i++;
                    }
                    else
                    {
                        if (isDir)
                        {
                            TreeNode newNode = isFirst
                                ? new TreeNode()
                            {
                                Text               = $"新建文件夹",
                                ImageIndex         = 0,
                                SelectedImageIndex = 0
                            }
                                : new TreeNode()
                            {
                                Text               = $"新建文件夹({i})",
                                ImageIndex         = 0,
                                SelectedImageIndex = 0
                            };
                            newNode.BeginEdit();

                            TreeNodeHelper.Edit(newNode, "isDir", "1");

                            dirView.SelectedNode.Nodes.Add(newNode);
                            dirView.SelectedNode = newNode;
                            newNode.BeginEdit();
                        }
                        else
                        {
                            TreeNode newNode = isFirst
                                ? new TreeNode()
                            {
                                Text               = $"新建文件",
                                ImageIndex         = 1,
                                SelectedImageIndex = 1
                            }
                                : new TreeNode()
                            {
                                Text               = $"新建文件({i})",
                                ImageIndex         = 1,
                                SelectedImageIndex = 1
                            };
                            newNode.BeginEdit();

                            TreeNodeHelper.Edit(newNode, "isDir", "0");

                            dirView.SelectedNode.Nodes.Add(newNode);
                            dirView.SelectedNode = newNode;
                            newNode.BeginEdit();
                        }

                        break;
                    }
                }
            }
        }
Esempio n. 5
0
 /// <summary>
 /// 文本改变事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void textBox1_KeyUp(object sender, KeyEventArgs e)
 {
     TreeNodeHelper.Edit(dirView.SelectedNode, "template", textBox1.Text);
 }