示例#1
0
        private static void AssertChanged(string origName, string expectedName, params string[] tags)
        {
            TaggedFilePath origPath    = new TaggedFilePath(origName, false);
            TaggedFilePath changedPath = origPath.SetTags(tags);

            Assert.AreEqual(expectedName, changedPath.Name);
        }
示例#2
0
        public Task OpenPreview(TaggedFilePath file)
        {
            // Reset the panning/zooming
            zoomBorder.Reset();

            image.Source = Utils.LoadImage(file.FullPath);
            return(Task.CompletedTask);
        }
示例#3
0
文件: Utils.cs 项目: Giksai/Explorer
        /// <summary>
        /// Follows a shortcut and returns the FileSystemInfo that it points to.
        /// </summary>
        /// <param name="shortcut"></param>
        /// <returns></returns>
        public static TaggedFilePath GetShortcutTarget(TaggedFilePath shortcut)
        {
            // Get the target path
            IWshShell    shell  = new WshShell();
            IWshShortcut lnk    = shell.CreateShortcut(shortcut.FullPath);
            string       target = lnk.TargetPath;

            // Put it in a TaggedFilePath
            return(new TaggedFilePath(target, Directory.Exists(target)));
        }
示例#4
0
        public FileListItem(TaggedFilePath file)
        {
            InitializeComponent();
            this.file = file;

            nameLabel.Content = file.Name;

            // Change the icon if it's not a folder
            if (!file.IsFolder)
            {
                iconImg.Source = Utils.GetFileIcon(new FileInfo(file.FullPath));    // TODO: Chnage Utils.GetFileIcon to use a TaggedFilePath
            }
        }
        private static void AssertChanged(string origPath, bool isFolder, params string[] tags)
        {
            origPath = Utils.GetTestFolder(origPath);

            // Move the file
            var orig    = new TaggedFilePath(origPath, isFolder);
            var changed = TagUtils.ChangeTagsAndSave(orig, tags);

            // Assert that it has been renamed.
            Assert.IsFalse(orig.Exists());
            Assert.IsTrue(changed.Exists());

            // Assert that the new path actually has the new tags
            bool matches = changed.Tags.SequenceEqual(tags);

            Assert.IsTrue(matches);
        }
示例#6
0
        private ImageSource GetThumbnail(TaggedFilePath file)
        {
            // TODO: If it's a directory, return a picture of a folder
            if (file.IsFolder)
            {
                return(null);
            }

            // If the file isn't an image, then just use its icon as the thumbnail
            // TODO: Let the thumnail for videos be the first frame
            if (!Utils.IsImageFile(file.FullPath))
            {
                return(Utils.GetFileIcon(new FileInfo(file.FullPath)));   // TODO: Make GetFileIcon take a string path instead.
            }
            // The file is an image, so it serves as its own thumbnail
            // Load the image into a bitmap and return it.
            return(Utils.LoadImage(file.FullPath));
        }
示例#7
0
        public async Task OpenPreview(TaggedFilePath folder)
        {
            // Close the previous folder
            await ClosePreview();

            // Get the thumbnails of the first few files
            ImageSource[] selectedIcons = null;

            var allIcons = from TaggedFilePath file in TagUtils.GetMatchingFiles(folder.FullPath, "")
                           where !file.IsFolder
                           select GetThumbnail(file);

            selectedIcons = allIcons.Take(MAX_ICONS).ToArray();

            // Display them stacked on top of each other.
            for (int i = 0; i < selectedIcons.Length; i++)
            {
                previewIcons[i].Source = selectedIcons[i];
            }
        }
示例#8
0
        private async void fileBrowser_SelectedFileChanged(object sender, SelectionChangedEventArgs e)
        {
            // Don't do anything if the last preview hasn't loaded yet
            if (filePreviewer.IsOpening)
            {
                return;
            }

            // Don't do anything if selection is null
            if (fileBrowser.SelectedItem == null)
            {
                return;
            }

            // If the selected item is a shortcut, resolve it.
            TaggedFilePath selectedItem = fileBrowser.SelectedItem;

            if (selectedItem.Extension.ToLower() == ".lnk")
            {
                selectedItem = Utils.GetShortcutTarget(selectedItem);
            }

            // Show the file preview
            await filePreviewer.OpenPreview(selectedItem); //crashes

            // Enable the tag box and update it with this file's tags
            // NOTE: This affects the shortcut itself, not its target.  This is intentional.
            StringBuilder builder = new StringBuilder();

            foreach (string t in selectedItem.Tags)
            {
                builder.AppendLine(t);
            }

            // Hide the save button
        }
示例#9
0
        /// <summary>
        /// Shows a preview for the given file
        /// </summary>
        /// <param name="selectedItem"></param>
        /// <returns></returns>
        public async Task OpenPreview(TaggedFilePath selectedItem)
        {
            //check if it is a common file
            if (!Utils.IsImageFile(selectedItem.FullPath) &&
                !Utils.IsVideoFile(selectedItem.FullPath) &&
                !selectedItem.IsFolder)
            {
                await ClosePreview();

                return;
            }
            bool img = Utils.IsImageFile(selectedItem.FullPath);
            bool vid = Utils.IsVideoFile(selectedItem.FullPath);
            bool fol = selectedItem.IsFolder;

            IsOpening = true;

            // Close the previously open file
            await ClosePreview();

            // Pick the first control that's capable of opening this file
            activePreviewControl = previewControls.First(c => c.CanOpen(selectedItem));

            // Show the file
            activePreviewControl.Visibility = Visibility.Visible;
            try
            {
                await activePreviewControl.OpenPreview(selectedItem);
            }
            catch (Exception e)
            {
                Utils.WriteConsole(e.Message, true);
                //MessageBox.Show(e.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Warning);
            }
            IsOpening = false;
        }
示例#10
0
 public bool CanOpen(TaggedFilePath file) => file.IsFolder;
示例#11
0
 public bool CanOpen(TaggedFilePath file) => Utils.IsImageFile(file.FullPath);
示例#12
0
        private static void AssertTags(string fileName, params string[] expectedTags)
        {
            IEnumerable <string> actualTags = new TaggedFilePath(fileName, false).Tags;

            Assert.IsTrue(actualTags.SequenceEqual(expectedTags));
        }