Exemple #1
0
        public static string GetFolderName()
        {
            string   result = null;
            NameForm nf     = new NameForm();

            if (nf.ShowDialog() == DialogResult.OK)
            {
                result = nf.nameBox.Text;
            }
            nf.Dispose();
            return(result);
        }
Exemple #2
0
        public static string RenameItem(string oldName, string title, string prompt)
        {
            string   result = null;
            NameForm nf     = new NameForm();

            nf.Text           = title;
            nf.nameLabel.Text = prompt;
            nf.nameBox.Text   = oldName;
            if (nf.ShowDialog() == DialogResult.OK)
            {
                result = nf.nameBox.Text;
            }
            nf.Dispose();
            return(result);
        }
Exemple #3
0
        void newFolderTile_Click(object sender, EventArgs e)
        {
            itemTiles.Focus();
            if (_activeDir == null)
            {
                return;
            }
            string fn = NameForm.GetFolderName();

            if (fn != null)
            {
                try
                {
                    _activeDir.CreateSubdirectory(fn);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "File Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                RefreshTiles();
            }
        }
Exemple #4
0
        void renameTile_Click(object sender, EventArgs e)
        {
            itemTiles.Focus();
            Tile[] checkedTiles = itemTiles.CheckedTiles;
            int    n            = checkedTiles.Length;

            if (n == 0)
            {
                return;
            }
            if (n > 1)
            {
                MessageBox.Show("Can't rename more than one item at a time.", "File Explorer", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
                return;
            }
            Tile          tile      = checkedTiles[0];
            DriveInfo     driveInfo = tile.Tag as DriveInfo;
            DirectoryInfo dirInfo   = tile.Tag as DirectoryInfo;
            FileInfo      fileInfo  = tile.Tag as FileInfo;
            string        s         = null;

            if (driveInfo != null)
            {
                s = NameForm.RenameItem(driveInfo.VolumeLabel, "Rename Drive", "Drive Name:");
                if (s != null && s != driveInfo.VolumeLabel)
                {
                    try
                    {
                        driveInfo.VolumeLabel = s;
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "File Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else if (dirInfo != null)
            {
                s = NameForm.RenameItem(dirInfo.Name, "Rename Folder", "Folder Name:");
                if (s != null && s != dirInfo.Name)
                {
                    try
                    {
                        dirInfo.MoveTo(Path.Combine(dirInfo.Parent.FullName, s));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "File Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            else if (fileInfo != null)
            {
                s = NameForm.RenameItem(fileInfo.Name, "Rename File", "File Name:");
                if (s != null && s != fileInfo.Name)
                {
                    try
                    {
                        fileInfo.MoveTo(Path.Combine(fileInfo.Directory.FullName, s));
                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.Message, "File Explorer", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                }
            }
            if (s != null)
            {
                RefreshTiles();
            }
        }