Skip to content

Commit

Permalink
Added informations about the current image to the main window.
Browse files Browse the repository at this point in the history
  • Loading branch information
Luca Auer authored and Luca Auer committed May 24, 2018
1 parent 0ffce2b commit 71eb1b3
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 7 deletions.
18 changes: 15 additions & 3 deletions Image sort.UI/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>

<!-- Column Definitions for Layout -->
Expand Down Expand Up @@ -106,7 +107,7 @@
</ToolBarTray>

<!-- StackPanel containing all the buttons with the folders to choose -->
<local:ListBoxScroll x:Name="FoldersStack" Grid.Column="0" Grid.Row="2" Focusable="False"
<local:ListBoxScroll x:Name="FoldersStack" Grid.Column="0" Grid.Row="2" Grid.RowSpan="2" Focusable="False"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" Margin="0,0,5,0">
<!--<i:Interaction.Behaviors>
<Behaviors:ScrollIntoViewForListBox />
Expand All @@ -122,10 +123,21 @@
<!--IsReadOnly="True"-->

<!-- For better UX -->
<GridSplitter Grid.Column="0" Grid.Row="1" Grid.RowSpan="2" Width="5" Focusable="False"/>
<GridSplitter Grid.Column="0" Grid.Row="1" Grid.RowSpan="3" Width="5" Focusable="False"/>

<!-- Image loading the image to sort as a preview -->
<Image x:Name="PreviewImage" Grid.Row="1" Grid.RowSpan="2"
<Image x:Name="PreviewImage" Grid.Row="1" Grid.RowSpan="3"
Grid.Column="1" Margin="0,0,5,0" Focusable="False"></Image>

<StackPanel Grid.Row="4" Grid.Column="1" Background="#BFFFFFFF">
<TextBlock Name="FileNameInfo"/>
<TextBlock Name="FileTypeInfo"/>
<TextBlock Name="FileSizeInfo"/>
<TextBlock Name="OpenInExplorerLinkHost" Visibility="Collapsed">
<Hyperlink Focusable="False" Name="OpenInExplorerLink" RequestNavigate="RequestOpeningInExplorer">
Open Image in File Explorer
</Hyperlink>
</TextBlock>
</StackPanel>
</Grid>
</Window>
61 changes: 57 additions & 4 deletions Image sort.UI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

/// <summary>
/// Opens explorer.exe (File Explorer) and selects the given file.
/// </summary>
/// <param name="path">The file to be selected.</param>
private void OpenImageInFileExplorer(string path)
{
// Opens explorer.exe (File Explorer) and selects the given file.
System.Diagnostics.Process.Start("explorer.exe", $"/select,\"{path}\"");
}

/// <summary>
Expand Down Expand Up @@ -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
Expand All @@ -642,6 +679,8 @@ public async void DoSkip()
// else disable the controls
else
{
// and unload it
LoadImage(null);
DisableControls();
GoBackButton.IsEnabled = true;
}
Expand All @@ -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
Expand All @@ -672,6 +711,8 @@ private async void DoMove()
// else disable the controls
else
{
// and unload it
LoadImage(null);
DisableControls();
GoBackButton.IsEnabled = true;
}
Expand Down Expand Up @@ -1068,6 +1109,18 @@ private void GoBackButton_Click(object sender, RoutedEventArgs e)
{
GoBack();
}

/// <summary>
/// Called when hyperlinks meaned for opening something in File Explorer are clicked.
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
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
}
}

0 comments on commit 71eb1b3

Please sign in to comment.