Exemple #1
0
        public void Execute(IActionContext context)
        {
            IResourceList selected = context.SelectedResources;
            ArrayList     names    = new ArrayList(selected.Count);

            foreach (IResource res in selected.ValidResources)
            {
                string name = res.GetStringProp(FileProxy._propDirectory);
                if (res.Type != FileProxy._folderResourceType)
                {
                    name = Path.Combine(name, res.GetPropText(Core.Props.Name));
                }
                names.Add(name);
            }
            if (names.Count > 0)
            {
                IResourceBrowser rBrowser        = Core.ResourceBrowser;
                IResourceList    viewedResources = selected.Intersect(rBrowser.SelectedResources);
                IResource        res2Select      = null;
                foreach (IResource res in viewedResources.ValidResources)
                {
                    res2Select = rBrowser.GetResourceBelow(res);
                }
                try
                {
                    FoldersCollection foldersCollection = FoldersCollection.Instance;
                    if (Control.ModifierKeys == Keys.Shift)
                    {
                        if (MessageBox.Show(Core.MainWindow,
                                            "Are you sure you want to delete " + ((names.Count > 1) ?
                                                                                  (names.Count + " selected items?") : ("'" + names[0] + "'?")),
                                            "Confirm Deletion", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
                                            MessageBoxDefaultButton.Button2) == DialogResult.Yes)
                        {
                            foreach (IResource res in selected.ValidResources)
                            {
                                foldersCollection.DeleteResource(res);
                            }
                            foreach (string name in names)
                            {
                                if (File.Exists(name))
                                {
                                    File.Delete(name);
                                }
                                else if (Directory.Exists(name))
                                {
                                    Directory.Delete(name, true);
                                }
                            }
                        }
                    }
                    else
                    {
                        Shell32.MoveFile2RecycleBin((string[])names.ToArray(typeof(string)));
                        FileProxy._filesProcessor.QueueJob(
                            new ResourceListDelegate(foldersCollection.EnumerateParents),
                            selected);
                    }
                }
                catch (Exception e)
                {
                    Utils.DisplayException(e, "Error");
                    return;
                }
                if (res2Select != null)
                {
                    rBrowser.SelectResource(res2Select);
                }
            }
        }
Exemple #2
0
        private static void ResourceNodeSelected(IResource res, bool displayAnotherFolder)
        {
            if (Core.State != CoreState.ShuttingDown && res.Type == _folderResourceType)
            {
                IResourceBrowser rBrowser = Core.ResourceBrowser;

                // for deleted folder display empty resource list
                if (res.IsDeleted)
                {
                    rBrowser.DisplayResourceList(
                        null, Core.ResourceStore.EmptyResourceList, res.DisplayName, null);
                    return;
                }

                if (!displayAnotherFolder && res != rBrowser.OwnerResource)
                {
                    return;
                }

                IResourceList selected = null;
                if (res == rBrowser.OwnerResource)
                {
                    selected = rBrowser.SelectedResources;
                }

                FoldersCollection foldersCollection = FoldersCollection.Instance;
                string            path           = res.GetPropText(_propDirectory);
                IResourceList     folderContents = res.GetLinksToLive(null, _propParentFolder);

                /**
                 * look through folders, create new ones and delete obsolete
                 */
                DirectoryInfo[] dirs = IOTools.GetDirectories(path);
                if (dirs != null)
                {
                    foreach (DirectoryInfo dir in dirs)
                    {
                        foldersCollection.FindOrCreateDirectory(dir.FullName);
                    }

                    HashSet fileNames  = new HashSet();
                    bool    viewHidden = Core.SettingStore.ReadBool("FilePlugin", "ViewHidden", false);
                    foreach (IResource file in folderContents.ValidResources)
                    {
                        if (file.Type == _folderResourceType)
                        {
                            if (!Directory.Exists(file.GetPropText(_propDirectory)))
                            {
                                foldersCollection.DeleteResource(file);
                            }
                        }
                        else
                        {
                            string fullname = foldersCollection.GetFullName(file);
                            if (!File.Exists(fullname))
                            {
                                foldersCollection.DeleteResource(file);
                            }
                            else
                            {
                                FileInfo fi = IOTools.GetFileInfo(fullname);
                                if (viewHidden || (fi.Attributes & FileAttributes.Hidden) == 0)
                                {
                                    fileNames.Add(file.GetPropText(Core.Props.Name));
                                }
                            }
                        }
                    }

                    /**
                     * collect not indexed files
                     */
                    FileInfo[] files = IOTools.GetFiles(path);
                    if (files != null)
                    {
                        foreach (FileInfo fi in files)
                        {
                            if ((viewHidden || (fi.Attributes & FileAttributes.Hidden) == 0) &&
                                !fileNames.Contains(fi.Name))
                            {
                                IResource file = foldersCollection.FindOrCreateFile(fi, true);
                                if (file != null)
                                {
                                    folderContents = folderContents.Union(file.ToResourceList(), true);
                                }
                            }
                        }
                    }
                }

                /**
                 * for folders excluded from indexing display deleted resources as well
                 */
                if (FoldersCollection.Instance.IsPathDeferred(path) ||
                    FoldersCollection.Instance.IsPathMonitored(path))
                {
                    folderContents = folderContents.Minus(
                        Core.ResourceStore.FindResourcesWithPropLive(null, _propDeletedFile));
                }
                ColumnDescriptor[] fileColumns = new ColumnDescriptor[4];
                fileColumns[0].PropNames      = new[] { "DisplayName" };
                fileColumns[0].Width          = 300;
                fileColumns[0].CustomComparer = new FoldersUpComparer();
                fileColumns[1].PropNames      = new[] { "FileType" };
                fileColumns[1].Width          = 120;
                fileColumns[2].PropNames      = new[] { "Size" };
                fileColumns[2].Width          = 120;
                fileColumns[3].PropNames      = new[] { "Date" };
                fileColumns[3].Width          = 120;
                rBrowser.DisplayUnfilteredResourceList(
                    res, folderContents, path, Core.DisplayColumnManager.AddAnyTypeColumns(fileColumns));

                if (selected != null)
                {
                    foreach (IResource file in selected.ValidResources)
                    {
                        rBrowser.SelectResource(file);
                    }
                }
            }
        }