internal static FavoriteFolderItem AddFavoriteFolders(ComboBox locationComboBox, String favoritePath, Int32 level)
        {
            FavoriteFolderItem root = new FavoriteFolderItem(favoritePath, level);

            locationComboBox.Items.Add(root);

            String[] directories = Directory.GetDirectories(favoritePath);

            foreach (String directory in directories)
            {
                FavoriteFolderItem childItem = FormHelper.AddFavoriteFolders(locationComboBox, directory, level + 1);

                root.Children.Add(childItem.Name, childItem);
            }

            return(root);
        }
        private void newFolderButton_Click(object sender, EventArgs e)
        {
            using (NewFavoriteFolderForm form = new NewFavoriteFolderForm(locationComboBox))
            {
                if (form.ShowDialog(this) == DialogResult.OK)
                {
                    locationComboBox.Items.Clear();

                    AddFavoriteForm_Load(sender, e);

                    FavoriteFolderItem newFolderItem = FormHelper.FindSpecificFavoriteFolder
                                                           (form.NewFolderPath, locationComboBox.Items[0] as FavoriteFolderItem);

                    locationComboBox.SelectedItem = newFolderItem;
                }
            }
        }
Exemple #3
0
        private void okButton_Click(object sender, EventArgs e)
        {
            FavoriteFolderItem parentFolderItem = locationComboBox.SelectedItem as FavoriteFolderItem;
            String             parentPath       = parentFolderItem.FullPath;
            String             newFolderPath    = PathExtensions.GetSafePath(Path.Combine(parentPath, nameTextBox.Text));

            if (!Directory.Exists(newFolderPath))
            {
                Directory.CreateDirectory(newFolderPath);

                _newFolderPath = newFolderPath;

                this.DialogResult = DialogResult.OK;

                this.Close();
            }
            else
            {
                MessageBox.Show(this, "The specified directory already exists.", this.Text,
                                MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        internal static FavoriteFolderItem FindSpecificFavoriteFolder(String fullPath, FavoriteFolderItem root)
        {
            fullPath = fullPath.Replace(root.FullPath, String.Empty).Trim('\\');

            Queue <String> nameQueue = new Queue <String>(fullPath.Split(new String[] { @"\" }, StringSplitOptions.RemoveEmptyEntries));

            FavoriteFolderItem currentFolderItem = root;

            while (nameQueue.Count > 0)
            {
                String name = nameQueue.Dequeue();

                if (currentFolderItem.Children.ContainsKey(name))
                {
                    currentFolderItem = currentFolderItem.Children[name];
                }
                else
                {
                    return(null);
                }
            }

            return(currentFolderItem);
        }