示例#1
0
    private ToolStripMenuItem getRightClickItem_Add_ExistingItem()
    {
        return(new ToolStripMenuItem("Existing item", Icons.GetBitmap("menu.existingitem", 16), delegate(object sender, EventArgs e) {
            //prompt for a filename
            OpenFileDialog opn = new OpenFileDialog {
                Multiselect = true
            };
            if (opn.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            //get the directory in which to add everything to
            TreeNode node = p_Tree.SelectedNode;
            ProjectDirectory dir = (node.Tag is Project ? ((Project)node.Tag).Root : (ProjectDirectory)node.Tag);

            //copy all the files that were selected into the project directory
            foreach (string s in opn.FileNames)
            {
                FileInfo f = new FileInfo(s);

                //create the file entry
                ProjectFile entry = dir.CreateFile(f.Name);
                File.Copy(f.FullName, entry.PhysicalLocation, true);
            }

            //refresh
            object st = PushTreeState();
            IndexDirectory(dir, node);
            PopTreeState(st);
            node.Expand();
        }));
    }
示例#2
0
    private void copyFileEntry(string path, ProjectDirectory dir)
    {
        //is the path a file?
        if (File.Exists(path))
        {
            //create the file entry in the directory
            FileInfo    f    = new FileInfo(path);
            ProjectFile file = dir.CreateFile(f.Name);

            //copy over the contents of the file
            //over to the one in the project.
            File.Copy(f.FullName, file.PhysicalLocation, true);
            return;
        }

        //must be a directory, otherwise the path is invalid
        if (!Directory.Exists(path))
        {
            return;
        }

        //create the directory instance in the project
        dir = dir.CreateDirectory(new DirectoryInfo(path).Name);

        //enumerate over all the child directories in the directory
        foreach (DirectoryInfo d in new DirectoryInfo(path).GetDirectories())
        {
            //copy all of the sub-files in this directory
            //by recursively invoking this function
            copyFileEntry(d.FullName, dir);
        }

        //copy all files in the directory
        foreach (FileInfo f in new DirectoryInfo(path).GetFiles())
        {
            //create the file entry in the directory
            ProjectFile file = dir.CreateFile(f.Name);

            //copy over the contents of the file
            //over to the one in the project.
            File.Copy(f.FullName, file.PhysicalLocation, true);
        }
    }
示例#3
0
    private ToolStripMenuItem getRightClickItem_Add_NewItem()
    {
        return(new ToolStripMenuItem("New item", Icons.GetBitmap("menu.newitem", 16), delegate(object sender, EventArgs e) {
            //get the currently selected directory
            ProjectEntity folder = GetSelectedProjectEntity();
            if (folder == null)
            {
                folder = GetSelectedProject().Root;
            }
            ProjectDirectory dir = (ProjectDirectory)folder;

            #region prompt the user for a filename
            string filename = null;
            while (true)
            {
                filename = AddProjectItem.Show();
                if (filename == null)
                {
                    break;
                }

                //does the file already exist?
                if (dir.EntityExists(filename))
                {
                    MessageBox.Show("The name \"" + filename + "\" is already in use in directory \"" + dir.FullName + "\"",
                                    "Error",
                                    MessageBoxButtons.OK,
                                    MessageBoxIcon.Error);
                    continue;
                }
                break;
            }
            if (filename == null)
            {
                return;
            }
            #endregion

            //create the file entry
            ProjectFile file = dir.CreateFile(filename);

            //update the tree
            TreeNode node = findNodeByTag(dir.IsRoot ? (object)dir.Project : (object)dir);
            object st = PushTreeState();
            IndexDirectory(dir, node);
            PopTreeState(st);
            node.Expand();
        }));
    }
示例#4
0
    private void importProjectFromDirectory(ProjectDirectory vDir, DirectoryInfo pDir)
    {
        //add the directories
        foreach (DirectoryInfo d in pDir.GetDirectories()) {
            importProjectFromDirectory(
                vDir.CreateDirectory(d.Name),
                d);
        }

        //add the files
        foreach (FileInfo f in pDir.GetFiles()) {
            ProjectFile vFile = vDir.CreateFile(f.Name);
            File.Copy(f.FullName, vFile.PhysicalLocation, true);
        }
    }
示例#5
0
    private void copyFileEntry(string path, ProjectDirectory dir)
    {
        //is the path a file?
        if (File.Exists(path)) {
            //create the file entry in the directory
            FileInfo f = new FileInfo(path);
            ProjectFile file = dir.CreateFile(f.Name);

            //copy over the contents of the file
            //over to the one in the project.
            File.Copy(f.FullName, file.PhysicalLocation, true);
            return;
        }

        //must be a directory, otherwise the path is invalid
        if (!Directory.Exists(path)) { return; }

        //create the directory instance in the project
        dir = dir.CreateDirectory(new DirectoryInfo(path).Name);

        //enumerate over all the child directories in the directory
        foreach (DirectoryInfo d in new DirectoryInfo(path).GetDirectories()) {
            //copy all of the sub-files in this directory
            //by recursively invoking this function
            copyFileEntry(d.FullName, dir);
        }

        //copy all files in the directory
        foreach (FileInfo f in new DirectoryInfo(path).GetFiles())  {
            //create the file entry in the directory
            ProjectFile file = dir.CreateFile(f.Name);

            //copy over the contents of the file
            //over to the one in the project.
            File.Copy(f.FullName, file.PhysicalLocation, true);
        }
    }