Esempio n. 1
0
        private void btAddFile_Click(object sender, EventArgs e)
        {
            QuestionForm frm = new QuestionForm("Create file", "Enter the new file name:");

            frm.KeyPress += Frm_KeyPress;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                string fileName = frm.Value;

                NodeTag  tag = treeView.SelectedNode.Tag as NodeTag;
                TreeNode treeNode;
                string   path;
                if (treeView.SelectedNode.ImageIndex != 0)  //file
                {
                    path     = Path.GetDirectoryName(tag.FilePath);
                    treeNode = treeView.SelectedNode.Parent;
                }
                else    // folder
                {
                    path     = tag.FilePath;
                    treeNode = treeView.SelectedNode;
                }
                string subdir = Path.Combine(path, fileName);
                File.WriteAllText(subdir, "");
                var newNode = new TreeNode(frm.Value, 1, 1);
                newNode.Tag = new NodeTag(subdir, gProps.RenderMacroFile(fileName, (treeNode.Tag as NodeTag).Renderings));
                treeNode.Nodes.Add(newNode);
                treeView.SelectedNode = newNode;
            }
            frm.Dispose();
        }
Esempio n. 2
0
        private void btAddFolder_Click(object sender, EventArgs e)
        {
            QuestionForm frm = new QuestionForm("Create folder", "Enter the new folder name:");

            frm.KeyPress += Frm_KeyPress;
            if (frm.ShowDialog() == DialogResult.OK)
            {
                string dirName = frm.Value;

                NodeTag  tag = treeView.SelectedNode.Tag as NodeTag;
                TreeNode treeNode;
                string   path;
                if (treeView.SelectedNode.ImageIndex != 0)  //file
                {
                    path     = Path.GetDirectoryName(tag.FilePath);
                    treeNode = treeView.SelectedNode.Parent;
                }
                else    // folder
                {
                    path     = tag.FilePath;
                    treeNode = treeView.SelectedNode;
                }
                string subdir = Path.Combine(path, dirName);
                Directory.CreateDirectory(subdir);
                var newNode = new TreeNode(frm.Value, 0, 0);
                if (newNode.Text.Contains(gProps.MacroBegin))
                {
                    newNode.Tag = new NodeTag(subdir, gProps.RenderMacroDirectory(dirName, (treeNode.Tag as NodeTag).First()));
                }
                else
                {
                    newNode.Tag = new NodeTag(subdir, new RenderingContext(subdir, dirName, (treeNode.Tag as NodeTag).First()));
                }
                treeNode.Nodes.Add(newNode);
                treeView.SelectedNode = newNode;
            }
            frm.Dispose();
        }