From 71eb1b3ff7573bc8595a463e265648ad2e73e549 Mon Sep 17 00:00:00 2001 From: Luca Auer Date: Fri, 25 May 2018 00:08:10 +0200 Subject: [PATCH] Added informations about the current image to the main window. --- Image sort.UI/MainWindow.xaml | 18 ++++++++-- Image sort.UI/MainWindow.xaml.cs | 61 +++++++++++++++++++++++++++++--- 2 files changed, 72 insertions(+), 7 deletions(-) diff --git a/Image sort.UI/MainWindow.xaml b/Image sort.UI/MainWindow.xaml index ee609c67..e88cb5b9 100644 --- a/Image sort.UI/MainWindow.xaml +++ b/Image sort.UI/MainWindow.xaml @@ -17,6 +17,7 @@ + @@ -106,7 +107,7 @@ - - + - + + + + + + + + Open Image in File Explorer + + + diff --git a/Image sort.UI/MainWindow.xaml.cs b/Image sort.UI/MainWindow.xaml.cs index a830fcdf..11ad6eb8 100644 --- a/Image sort.UI/MainWindow.xaml.cs +++ b/Image sort.UI/MainWindow.xaml.cs @@ -469,6 +469,43 @@ private void NewFolder() private void LoadImage(BitmapImage image) { PreviewImage.Source = image; + + // if an image was given, fill in the informations + if (image != null) + { + string pathToImage = folderSelector.GetImagePath(); + + FileNameInfo.Text = $"Name: {Path.GetFileNameWithoutExtension(pathToImage)}"; + FileTypeInfo.Text = $"Format: {Path.GetExtension(pathToImage)}"; + // Calculates the sizes in MB and KB and rounds them to two digits, before filling in the size. + FileSizeInfo.Text = $"Size: " + + $"{Math.Round(((double)(new FileInfo(pathToImage)).Length) / (1024 * 1024), 2)} MB, " + + $"{Math.Round(((double)(new FileInfo(pathToImage)).Length) / 1024, 2)} KB"; + + // Fill in the links destination and make it visible + OpenInExplorerLink.NavigateUri = new Uri(pathToImage); + OpenInExplorerLinkHost.Visibility = Visibility.Visible; + } + // if that is not the case, remove the old information. + else + { + FileNameInfo.Text = ""; + FileTypeInfo.Text = ""; + FileSizeInfo.Text = ""; + OpenInExplorerLink.NavigateUri = null; + // Collapse link again to prevent accidental clicking. + OpenInExplorerLinkHost.Visibility = Visibility.Collapsed; + } + } + + /// + /// Opens explorer.exe (File Explorer) and selects the given file. + /// + /// The file to be selected. + private void OpenImageInFileExplorer(string path) + { + // Opens explorer.exe (File Explorer) and selects the given file. + System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{path}\""); } /// @@ -629,8 +666,8 @@ public async void DoSkip() { if (SkipFileButton.IsEnabled == true) { - // set the preview image to nothing - PreviewImage.Source = null; + //// set the preview image to nothing + //PreviewImage.Source = null; // get the next image BitmapImage buffer = await folderSelector.GetNextImage(); // get the next path of the next image @@ -642,6 +679,8 @@ public async void DoSkip() // else disable the controls else { + // and unload it + LoadImage(null); DisableControls(); GoBackButton.IsEnabled = true; } @@ -658,8 +697,8 @@ private async void DoMove() { if (MoveFolderButton.IsEnabled == true) { - // set the preview image to nothing - PreviewImage.Source = null; + //// set the preview image to nothing + //PreviewImage.Source = null; // get the next path of the next image string path = folderSelector.GetImagePath(); // get the next image @@ -672,6 +711,8 @@ private async void DoMove() // else disable the controls else { + // and unload it + LoadImage(null); DisableControls(); GoBackButton.IsEnabled = true; } @@ -1068,6 +1109,18 @@ private void GoBackButton_Click(object sender, RoutedEventArgs e) { GoBack(); } + + /// + /// Called when hyperlinks meaned for opening something in File Explorer are clicked. + /// + /// + /// + private void RequestOpeningInExplorer(object sender, System.Windows.Navigation.RequestNavigateEventArgs e) + { + if (e.Uri != null && File.Exists(e.Uri.OriginalString)) + // Opens explorer.exe (File Explorer) and selects the given file. + OpenImageInFileExplorer(e.Uri.OriginalString); + } #endregion } }