Skip to content

Commit

Permalink
Restore the last crop selection after saving as a new file
Browse files Browse the repository at this point in the history
  • Loading branch information
d2phap committed Jan 27, 2024
1 parent 009378e commit 11ed7b1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions Source/Components/ImageGlass.Base/LocalEvents.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ public class ImageSaveEventArgs(string srcFilePath, string destFilePath, ImageSa
{
public string SrcFilePath { get; init; } = srcFilePath;
public string DestFilePath { get; init; } = destFilePath;
public bool IsSaveAsNewFile => !SrcFilePath.Equals(DestFilePath, StringComparison.OrdinalIgnoreCase);
public ImageSaveSource SaveSource { get; init; } = saveSource;
}

Expand Down
3 changes: 0 additions & 3 deletions Source/ImageGlass/FrmMain/FrmMain.IGMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1511,9 +1511,6 @@ public async Task<bool> SaveImageAsync(string destFilePath, string srcFilePath =
{
// reload to view the updated image
IG_Reload();

// reset selection
PicMain.ClientSelection = default;
}
else if (saveSource == ImageSaveSource.Clipboard)
{
Expand Down
13 changes: 10 additions & 3 deletions Source/ImageGlass/Tools/FrmCrop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public partial class FrmCrop : ToolForm, IToolForm<CropToolConfig>
private Keys _squareRatioSelectionKey = Keys.Shift | Keys.ShiftKey;
private bool _isSquareRatioSelectionKeyPressed;
private bool _isDefaultSelectionLoaded;
private bool _isNewFileSaved;
private Rectangle _lastSelectionArea;


Expand Down Expand Up @@ -385,6 +386,9 @@ private void LoadSelectionFromFormInputs(bool drawSelection)

private void LoadDefaultSelectionSetting(bool drawSelection)
{
var useLastSelection = _isNewFileSaved
|| Settings.InitSelectionType == DefaultSelectionType.UseTheLastSelection;

var srcW = (int)Local.FrmMain.PicMain.SourceWidth;
var srcH = (int)Local.FrmMain.PicMain.SourceHeight;

Expand All @@ -393,7 +397,7 @@ private void LoadDefaultSelectionSetting(bool drawSelection)
var w = 0;
var h = 0;

if (Settings.InitSelectionType == DefaultSelectionType.UseTheLastSelection)
if (useLastSelection)
{
x = _lastSelectionArea.X;
y = _lastSelectionArea.Y;
Expand Down Expand Up @@ -434,8 +438,7 @@ private void LoadDefaultSelectionSetting(bool drawSelection)
}

// auto-center the selection
if (Settings.AutoCenterSelection
&& Settings.InitSelectionType != DefaultSelectionType.UseTheLastSelection)
if (Settings.AutoCenterSelection && !useLastSelection)
{
x = srcW / 2 - w / 2;
y = srcH / 2 - h / 2;
Expand Down Expand Up @@ -514,6 +517,8 @@ private void FrmMain_KeyUp(object? sender, KeyEventArgs e)

private void Local_ImageSaved(ImageSaveEventArgs e)
{
_isNewFileSaved = e.IsSaveAsNewFile;

if (Settings.CloseToolAfterSaving
&& e.SaveSource == ImageSaveSource.SelectedArea)
{
Expand Down Expand Up @@ -560,6 +565,8 @@ private void PicMain_ImageDrawn(object? sender, EventArgs e)
{
LoadDefaultSelectionSetting(false);
}

_isNewFileSaved = false;
}


Expand Down

0 comments on commit 11ed7b1

Please sign in to comment.