Example #1
0
        private void ScanComplete()
        {
            IsScanning = false;

            if (NeedsClosing)
            {
                this.Close();
            }

            CancelScanButton.Hide();
            CancelBookmarksButton.Enabled = true;
            SaveBookmarksButton.Enabled   = true;
            AddBookmarksButton.Enabled    = true;
            RemoveBookmarksButton.Enabled = true;
            BookmarksDataGridView.Enabled = true;
            DirectoryLabelTextField.Text  = "";

            BookmarksBindingSource.ResetBindings(false);
        }
Example #2
0
        private void AddBookmarksButton_Click(object sender, EventArgs e)
        {
            CommonOpenFileDialog dialog = new CommonOpenFileDialog();

            dialog.IsFolderPicker = true;
            dialog.Multiselect    = true;
            if (dialog.ShowDialog() == CommonFileDialogResult.Ok)
            {
                List <Bookmark> bookmarksSnapshot = Bookmarks.Select(bookmark => (Bookmark)bookmark.Clone()).ToList();

                CancelScanButton.Show();
                CancelBookmarksButton.Enabled = false;
                SaveBookmarksButton.Enabled   = false;
                AddBookmarksButton.Enabled    = false;
                RemoveBookmarksButton.Enabled = false;
                BookmarksDataGridView.Enabled = false;

                IsScanning = true;
                CancelScan = new CancellationTokenSource();

                Task.Run(() => {
                    try {
                        List <string> bookmarkPaths = Bookmarks.Select(bookmark => bookmark.Path).ToList();

                        foreach (string path in dialog.FileNames)
                        {
                            if (Properties.Settings.Default.RecursiveBookmarkScan)
                            {
                                IEnumerable <string> filePaths = EnumerateFiles(path, "*.*", SearchOption.AllDirectories)
                                                                 .Where(p => {
                                    try {
                                        return(p.Split(System.IO.Path.DirectorySeparatorChar).Where(s => s[0] == '.').Count() == 0 && !((File.GetAttributes(p) & FileAttributes.Hidden) == FileAttributes.Hidden));
                                    } catch (Exception) { return(false); }
                                });

                                foreach (string filePath in filePaths)
                                {
                                    CancelScan.Token.ThrowIfCancellationRequested();

                                    DirectoryInfo info = new DirectoryInfo(filePath);

                                    this.Invoke((MethodInvoker) delegate {
                                        DirectoryLabelTextField.Text = info.FullName;
                                    });

                                    if (info.Name == "Vagrantfile" && !bookmarkPaths.Contains(info.Parent.FullName))
                                    {
                                        Bookmarks.Add(new Bookmark(info.Parent.FullName, info.Parent.Name, VagrantManager.Instance.DetectVagrantProvider(info.Parent.FullName)));
                                    }
                                }
                            }
                            else
                            {
                                if (File.Exists(new DirectoryInfo(path + "/Vagrantfile").FullName) && !bookmarkPaths.Contains(path))
                                {
                                    Bookmarks.Add(new Bookmark(path, new DirectoryInfo(path).Name, VagrantManager.Instance.DetectVagrantProvider(path)));
                                }
                            }
                        }

                        this.Invoke((MethodInvoker) delegate {
                            this.ScanComplete();
                        });
                    } catch (OperationCanceledException) {
                        this.Invoke((MethodInvoker) delegate {
                            Bookmarks = bookmarksSnapshot;
                            BookmarksBindingSource.DataSource = Bookmarks;
                            this.ScanComplete();
                        });
                    }
                }, CancelScan.Token);
            }
        }