private void SetTreeFromFolder(string folder, bool setFocus = false, string searchText = null)
        {
            if (Window == null)
            {
                return;
            }

            Window.SetStatusIcon(FontAwesome.WPF.FontAwesomeIcon.Spinner, Colors.Orange, true);
            Window.ShowStatus($"Retrieving files for folder {folder}...");

            Dispatcher.InvokeAsync(() =>
            {
                // just get the top level folder first
                ActivePathItem = null;
                WindowUtilities.DoEvents();

                var items      = FolderStructure.GetFilesAndFolders(folder, nonRecursive: true, ignoredFolders: ".git");
                ActivePathItem = items;

                WindowUtilities.DoEvents();
                Window.ShowStatus();

                if (TreeFolderBrowser.HasItems)
                {
                    SetTreeViewSelectionByIndex(0);
                }

                if (setFocus)
                {
                    TreeFolderBrowser.Focus();
                }

                AttachFileWatcher(folder);
            }, DispatcherPriority.ApplicationIdle);
        }
 private void CheckBox_Click(object sender, RoutedEventArgs e)
 {
     Window.ShowStatus("Filtering files...");
     Window.SetStatusIcon(FontAwesomeIcon.Spinner, Colors.Orange, spin: true);
     WindowUtilities.DoEvents();
     FolderStructure.SetSearchVisibility(SearchText, ActivePathItem, SearchSubTrees);
     Window.ShowStatus(null);
 }
 private void TextSearch_PreviewKeyUp(object sender, KeyEventArgs e)
 {
     debounceTimer.Debounce(500, (p) =>
     {
         Window.ShowStatus("Filtering files...");
         Window.SetStatusIcon(FontAwesomeIcon.Spinner, Colors.Orange, spin: true);
         WindowUtilities.DoEvents();
         FolderStructure.SetSearchVisibility(SearchText, ActivePathItem, SearchSubTrees);
         Window.ShowStatus(null);
     });
 }
Beispiel #4
0
        private void FileWatcher_CreateOrDelete(object sender, FileSystemEventArgs e)
        {
            var file = e.FullPath;

            if (e.ChangeType == WatcherChangeTypes.Deleted)
            {
                mmApp.Model.Window.Dispatcher.Invoke(() =>
                {
                    var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, file);
                    if (pi == null)
                    {
                        return;
                    }

                    pi.Parent.Files.Remove(pi);

                    //Debug.WriteLine("After: " + pi.Parent.Files.Count + " " + file);
                }, DispatcherPriority.ApplicationIdle);
            }

            if (e.ChangeType == WatcherChangeTypes.Created)
            {
                mmApp.Model.Window.Dispatcher.Invoke(() =>
                {
                    var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, file);
                    if (pi != null) // Already exists in the tree
                    {
                        return;
                    }

                    // does the path exist?
                    var parentPathItem =
                        FolderStructure.FindPathItemByFilename(ActivePathItem, Path.GetDirectoryName(file));
                    if (parentPathItem == null) // path is not expanced yet
                    {
                        return;
                    }

                    bool isFolder = Directory.Exists(file);
                    pi            = new PathItem()
                    {
                        FullPath = file,
                        IsFolder = isFolder,
                        IsFile   = !isFolder,
                        Parent   = parentPathItem
                    };
                    pi.SetIcon();

                    FolderStructure.InsertPathItemInOrder(pi, parentPathItem);
                }, DispatcherPriority.ApplicationIdle);
            }
        }
        private void FileWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            var file    = e.FullPath;
            var oldFile = e.OldFullPath;

            var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, oldFile);

            if (pi == null)
            {
                return;
            }

            pi.FullPath = file;
            Dispatcher.Invoke(() => pi.Parent.Files.Remove(pi));

            FolderStructure.InsertPathItemInOrder(pi, pi.Parent);
        }
        private void FileWatcher_Renamed(object sender, RenamedEventArgs e)
        {
            mmApp.Model.Window.Dispatcher.Invoke(() =>
            {
                var file    = e.FullPath;
                var oldFile = e.OldFullPath;

                var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, oldFile);
                if (pi == null)
                {
                    return;
                }

                pi.FullPath = file;
                pi.Parent.Files.Remove(pi);

                FolderStructure.InsertPathItemInOrder(pi, pi.Parent);
            }, DispatcherPriority.ApplicationIdle);
        }
        private void TreeFolderBrowser_Expanded(object sender, RoutedEventArgs e)
        {
            var tvi = e.OriginalSource as TreeViewItem;

            if (tvi == null)
            {
                return;
            }

            tvi.IsSelected = true;

            var selected = TreeFolderBrowser.SelectedItem as PathItem;

            if (selected == null || selected.IsFile || selected.FullPath == "..")
            {
                return;
            }

            if (selected.Files != null && selected.Files.Count == 1 && selected.Files[0] == PathItem.Empty)
            {
                var subfolder = FolderStructure.GetFilesAndFolders(selected.FullPath, nonRecursive: true, parentPathItem: selected);
            }
        }
        private void FileWatcher_CreateOrDelete(object sender, FileSystemEventArgs e)
        {
            var file = e.FullPath;

            if (string.IsNullOrEmpty(file))
            {
                return;
            }

            if (e.ChangeType == WatcherChangeTypes.Deleted)
            {
                mmApp.Model.Window.Dispatcher.Invoke(() =>
                {
                    var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, file);
                    if (pi == null)
                    {
                        return;
                    }

                    pi.Parent.Files.Remove(pi);

                    //Debug.WriteLine("After: " + pi.Parent.Files.Count + " " + file);
                }, DispatcherPriority.ApplicationIdle);
            }

            if (e.ChangeType == WatcherChangeTypes.Created)
            {
                mmApp.Model.Window.Dispatcher.Invoke(() =>
                {
                    // Skip ignored Extensions
                    string[] extensions = null;
                    if (!string.IsNullOrEmpty(mmApp.Model.Configuration.FolderBrowser.IgnoredFileExtensions))
                    {
                        extensions = mmApp.Model.Configuration.FolderBrowser.IgnoredFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                    }

                    if (extensions != null && extensions.Any(ext => file.ToLowerInvariant().EndsWith(ext)))
                    {
                        return;
                    }

                    var pi = FolderStructure.FindPathItemByFilename(ActivePathItem, file);
                    if (pi != null) // Already exists in the tree
                    {
                        return;
                    }

                    // does the path exist?
                    var parentPathItem =
                        FolderStructure.FindPathItemByFilename(ActivePathItem, Path.GetDirectoryName(file));
                    if (parentPathItem == null) // path is not expanced yet
                    {
                        return;
                    }

                    bool isFolder = Directory.Exists(file);
                    pi            = new PathItem()
                    {
                        FullPath = file,
                        IsFolder = isFolder,
                        IsFile   = !isFolder,
                        Parent   = parentPathItem
                    };
                    pi.SetIcon();

                    FolderStructure.InsertPathItemInOrder(pi, parentPathItem);
                }, DispatcherPriority.ApplicationIdle);
            }
        }