Skip to content

Commit

Permalink
Use a drop down button for apply/save
Browse files Browse the repository at this point in the history
  • Loading branch information
TheJoeFin committed May 4, 2024
1 parent 8545495 commit 2057db5
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 24 deletions.
48 changes: 30 additions & 18 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -280,28 +280,40 @@
Click="CancelCrop_Click"
Content="Cancel Crop" />
</StackPanel>
<Button
x:Name="ApplyButton"
Margin="8,4"
Click="ApplyButton_Click"
Content="Apply"
IsDefault="True"
IsEnabled="False"
ToolTip="Apply Transform" />
<Button
x:Name="Save"
Margin="8,4"
Click="Save_Click"
Content="Save"
IsEnabled="False"
ToolTip="Apply Transform, Save, and Preview file" />
<Button
<wpfui:DropDownButton
x:Name="ApplySaveSplitButton"
Content="Apply &amp; Save"
IsEnabled="False">
<wpfui:DropDownButton.Flyout>
<ContextMenu>
<MenuItem
x:Name="ApplyAndSaveMenuItem"
Click="ApplySaveSplitButton_Click"
Header="Apply &amp; Save"
ToolTip="Apply Transform, Save, and Preview file" />
<MenuItem
x:Name="ApplyButton"
Click="ApplyButton_Click"
Header="Apply"
ToolTip="Apply Transform" />
<MenuItem
x:Name="Save"
Click="Save_Click"
Header="Save"
ToolTip="Apply Transform, Save, and Preview file" />
</ContextMenu>
</wpfui:DropDownButton.Flyout>
</wpfui:DropDownButton>
<wpfui:Button
x:Name="OpenFolderButton"
Margin="8,4"
Click="OpenFolderButton_Click"
Content="Open Folder"
IsEnabled="False"
ToolTip="Open Folder Where File Was Saved" />
ToolTip="Open Folder Where File Was Saved">
<wpfui:Button.Icon>
<wpfui:SymbolIcon Symbol="FolderArrowRight24" />
</wpfui:Button.Icon>
</wpfui:Button>
</StackPanel>
</Grid>
</Border>
Expand Down
63 changes: 59 additions & 4 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ private async void ApplyButton_Click(object sender, RoutedEventArgs e)
SetUiForCompletedTask();
}

private async void Save_Click(object sender, RoutedEventArgs e)

private async void ApplySaveSplitButton_Click(object sender, RoutedEventArgs e)
{
SetUiForLongTask();

Expand All @@ -282,6 +283,7 @@ private async void Save_Click(object sender, RoutedEventArgs e)
{
BottomPane.IsEnabled = true;
BottomPane.Cursor = null;
SetUiForCompletedTask();
return;
}

Expand Down Expand Up @@ -320,6 +322,58 @@ private async void Save_Click(object sender, RoutedEventArgs e)
}
}

private async void Save_Click(object sender, RoutedEventArgs e)
{
SaveFileDialog saveFileDialog = new()
{
Filter = "Image Files|*.jpg;",
RestoreDirectory = true,
FileName = $"{openedFileName}_corrected.jpg",
};

if (saveFileDialog.ShowDialog() is not true || lines is null)
{
BottomPane.IsEnabled = true;
BottomPane.Cursor = null;
SetUiForCompletedTask();
return;
}

string correctedImageFileName = saveFileDialog.FileName;

if (string.IsNullOrWhiteSpace(imagePath) || string.IsNullOrWhiteSpace(correctedImageFileName))
{
SetUiForCompletedTask();
return;
}

MagickImage image = new(imagePath);

try
{
await image.WriteAsync(correctedImageFileName);

OpenFolderButton.IsEnabled = true;
SaveWindow saveWindow = new(correctedImageFileName);
saveWindow.Show();
}
catch (Exception ex)
{
System.Windows.MessageBox.Show(
ex.Message,
"Error",
System.Windows.MessageBoxButton.OK,
MessageBoxImage.Error);
}
finally
{
savedPath = correctedImageFileName;

SetUiForCompletedTask();
image.Dispose();
}
}

private void SetUiForLongTask()
{
BottomPane.IsEnabled = false;
Expand Down Expand Up @@ -351,6 +405,7 @@ private async void OpenFileButton_Click(object sender, RoutedEventArgs e)

private async Task OpenImagePath(string imageFilePath)
{
ApplySaveSplitButton.IsEnabled = true;
Save.IsEnabled = true;
ApplyButton.IsEnabled = true;
MagickImage bitmap = new(imageFilePath);
Expand Down Expand Up @@ -713,7 +768,7 @@ private void SquareThePolygon()
private void CropImage_Click(object sender, RoutedEventArgs e)
{
isCropping = true;
ApplyButton.Visibility = Visibility.Collapsed;
ApplySaveSplitButton.Visibility = Visibility.Collapsed;
CropButtonPanel.Visibility = Visibility.Visible;

foreach (UIElement element in _polygonElements)
Expand All @@ -725,7 +780,7 @@ private void CropImage_Click(object sender, RoutedEventArgs e)
private async void ApplyCropButton_Click(object sender, RoutedEventArgs e)
{
CropButtonPanel.Visibility = Visibility.Collapsed;
ApplyButton.Visibility = Visibility.Visible;
ApplySaveSplitButton.Visibility = Visibility.Visible;

foreach (UIElement element in _polygonElements)
element.Visibility = Visibility.Visible;
Expand Down Expand Up @@ -757,7 +812,7 @@ private async void ApplyCropButton_Click(object sender, RoutedEventArgs e)
private void CancelCrop_Click(object sender, RoutedEventArgs e)
{
CropButtonPanel.Visibility = Visibility.Collapsed;
ApplyButton.Visibility = Visibility.Visible;
ApplySaveSplitButton.Visibility = Visibility.Visible;

foreach (UIElement element in _polygonElements)
element.Visibility = Visibility.Visible;
Expand Down
4 changes: 2 additions & 2 deletions ResizableRectangle.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:MagickCrop"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
Width="300"
Height="300"
Width="500"
Height="400"
Padding="50"
Background="Transparent"
MouseMove="UserControl_MouseMove"
Expand Down

0 comments on commit 2057db5

Please sign in to comment.