예제 #1
0
        private void lvExplorer_AfterLabelEdit(object sender, LabelEditEventArgs e)
        {
            if (_curPath != null)
            {
                if (string.IsNullOrWhiteSpace(e.Label))
                {
                    lvExplorer.LabelEdit = false;
                    lvExplorer.Items.RemoveAt(e.Item);
                    return;
                }

                DirectoryInfo di = Directory.CreateDirectory(Path.Combine(_curPath.FullName, e.Label));
                lvExplorer.LabelEdit = false;
                string     iconId = di.FullName;
                FolderItem item   = new FolderItem(di, iconId);

                if (!_smallImgList.Images.ContainsKey(iconId))
                {
                    Icon smallIcon = ShellApi.GetFolderIcon(di.FullName);
                    _smallImgList.Images.Add(iconId, smallIcon);
                }

                lvExplorer.Items[e.Item].ImageKey = iconId;

                lvExplorer.Items[e.Item].Tag = item;
                txtSubDir.Text = e.Label;
            }
        }
예제 #2
0
        private void btnNewFolder_Click(object sender, EventArgs e)
        {
            if (_curPath != null)
            {
                ListViewItem lvi = lvExplorer.Items.Add("New Folder");
                // DirectoryInfo di = Directory.CreateDirectory();
                string iconId = Path.Combine(_curPath.FullName, "New Folder");
                //FolderItem item = new FolderItem(di, iconId);

                if (!_smallImgList.Images.ContainsKey(iconId))
                {
                    Icon smallIcon = ShellApi.GetFolderIcon(System.IO.Path.GetTempPath());
                    _smallImgList.Images.Add(iconId, smallIcon);
                }
                //lvi.Tag = item;
                lvi.ImageKey         = iconId;
                lvExplorer.LabelEdit = true;
                lvi.BeginEdit();
            }
        }
예제 #3
0
        private void LoadDrives()
        {
            TreeNode drivesNodes = new TreeNode("Drives");

            foreach (DriveInfo drive in DriveInfo.GetDrives())
            {
                string     iconId = drive.RootDirectory.FullName;
                FolderItem item   = new FolderItem(drive.RootDirectory, iconId);

                if (!_imgTree.Images.ContainsKey(iconId))
                {
                    Icon smallIcon = ShellApi.GetFolderIcon(drive.RootDirectory.FullName);

                    _imgTree.Images.Add(iconId, smallIcon);
                }

                string name = (string.IsNullOrWhiteSpace(drive.VolumeLabel) ? drive.Name : drive.VolumeLabel);
                if (drive.DriveType == DriveType.Removable)
                {
                    name += " (Removable)";
                }

                TreeNode node = drivesNodes.Nodes.Add(name);
                node.Tag              = item;
                node.ImageKey         = iconId;
                node.SelectedImageKey = iconId;
            }

            //if (drivesNodes.Nodes.Count > 0)
            //{
            //    drivesNodes.ImageKey = drivesNodes.Nodes[drivesNodes.Nodes.Count - 1].ImageKey;
            //    drivesNodes.SelectedImageKey = drivesNodes.Nodes[drivesNodes.Nodes.Count - 1].ImageKey;

            //    extendedTreeView1.Nodes.Add(drivesNodes);
            //    drivesNodes.Expand();
            //}
        }
예제 #4
0
        private void ListFolders(DirectoryInfo rootDir)
        {
            btnNewFolder.Visible = false;

            _smallImgList.Images.Clear();

            lvExplorer.BeginUpdate();

            lvExplorer.Items.Clear();


            if (rootDir == null)
            {
                foreach (DriveInfo drive in DriveInfo.GetDrives())
                {
                    string     iconId = drive.RootDirectory.FullName;
                    FolderItem item   = new FolderItem(drive.RootDirectory, iconId);

                    if (!_smallImgList.Images.ContainsKey(iconId))
                    {
                        Icon smallIcon = ShellApi.GetFolderIcon(drive.RootDirectory.FullName);
                        _smallImgList.Images.Add(iconId, smallIcon);
                    }

                    string name = drive.RootDirectory.Name;

                    if (drive.DriveType != DriveType.Network)
                    {
                        try
                        {
                            name = (string.IsNullOrWhiteSpace(drive.VolumeLabel) ? name : drive.VolumeLabel + " (" + name + ")");
                        }
                        catch (Exception) { }
                    }

                    if (drive.DriveType == DriveType.Removable)
                    {
                        name += " (Removable)";
                    }

                    ListViewItem lvi = lvExplorer.Items.Add(name, iconId);
                    lvi.Tag = item;
                }
            }
            else
            {
                try
                {
                    string defaultIconId = System.IO.Path.GetTempPath();
                    Icon   defaultIcon   = ShellApi.GetFolderIcon(defaultIconId);

                    if (!_smallImgList.Images.ContainsKey(defaultIconId))
                    {
                        _smallImgList.Images.Add(defaultIconId, defaultIcon);
                    }

                    DirectoryInfo[] dirs     = rootDir.GetDirectories();
                    int             dirCount = dirs.Length;

                    foreach (DirectoryInfo dir in dirs)
                    {
                        if (dir.Name == "System Volume Information")
                        {
                            continue;
                        }

                        string     iconId = dir.FullName;
                        FolderItem item   = new FolderItem(dir, iconId);
                        if (dirCount < 1000)
                        {
                            if (!_smallImgList.Images.ContainsKey(iconId))
                            {
                                Icon smallIcon = ShellApi.GetFolderIcon(dir.FullName);
                                if (smallIcon != null && smallIcon.Handle != IntPtr.Zero)
                                {
                                    _smallImgList.Images.Add(iconId, smallIcon);
                                }
                                else
                                {
                                    iconId = defaultIconId;
                                }
                            }
                        }
                        else
                        {
                            iconId = defaultIconId;
                        }

                        ListViewItem lvi = lvExplorer.Items.Add(dir.Name, iconId);
                        lvi.Tag = item;
                    }

                    _default             = true;
                    txtSubDir.Text       = rootDir.Name;
                    btnNewFolder.Visible = true;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }

            lvExplorer.EndUpdate();
        }