コード例 #1
0
        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);
        }
コード例 #2
0
 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);
 }
コード例 #3
0
 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);
     });
 }
コード例 #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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        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);
            }
        }
コード例 #8
0
        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);
            }
        }