Exemplo n.º 1
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 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);
            }
        }