Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New command: flip every 2nd image #343

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions NAPS2.Lib.Mac/EtoForms/Ui/MacDesktopForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@ protected override void CreateToolbarsAndMenus()
Commands.RotateLeft,
Commands.RotateRight,
Commands.Flip,
Commands.AltFlip,
Commands.Deskew,
Commands.CustomRotate,
new SeparatorMenuItem(),
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib.Mac/EtoForms/Ui/MacPreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected override void UpdatePage()
.Append(Commands.RotateLeft)
.Append(Commands.RotateRight)
.Append(Commands.Flip)
.Append(Commands.AltFlip)
.Append(Commands.Deskew)
.Append(Commands.CustomRotate)),
MacToolbarItems.Create("crop", Commands.Crop),
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib/Config/InternalDefaults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ public static CommonConfig GetCommonConfig() =>
ImageSharpen = "",
RotateLeft = "",
RotateRight = "",
AltFlip = "",
RotateFlip = "",
RotateCustom = "",
MoveUp = "Ctrl+Up",
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib/Config/KeyboardShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ public class KeyboardShortcuts
public string? RotateLeft { get; set; }
public string? RotateRight { get; set; }
public string? RotateFlip { get; set; }
public string? AltFlip { get; set; }
public string? RotateCustom { get; set; }

public string? MoveUp { get; set; }
Expand Down
2 changes: 2 additions & 0 deletions NAPS2.Lib/EtoForms/Desktop/DesktopKeyboardShortcuts.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Eto.Forms;
using NAPS2.EtoForms.Ui;
using System.Runtime.InteropServices;

namespace NAPS2.EtoForms.Desktop;

Expand Down Expand Up @@ -84,6 +85,7 @@ public void Assign(DesktopCommands commands)
_ksm.Assign(ks.RotateFlip, commands.Flip);
_ksm.Assign(ks.RotateLeft, commands.RotateLeft);
_ksm.Assign(ks.RotateRight, commands.RotateRight);
_ksm.Assign(ks.AltFlip, commands.AltFlip);
_ksm.Assign(ks.SaveImages, commands.SaveImages);
_ksm.Assign(ks.SaveImagesAll, commands.SaveAllImages);
_ksm.Assign(ks.SaveImagesSelected, commands.SaveSelectedImages);
Expand Down
3 changes: 3 additions & 0 deletions NAPS2.Lib/EtoForms/Desktop/ImageListActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ public async Task RotateRight() =>

public async Task Flip() => await _imageList.MutateAsync(new ImageListMutation.RotateFlip(180), Selection);

public async Task AltFlip() =>
await _imageList.MutateAsync(new ImageListMutation.AltFlip(), Selection);

public void DocumentCorrection() =>
_imageList.Mutate(new ImageListMutation.AddTransforms([new CorrectionTransform(CorrectionMode.Document)]),
Selection);
Expand Down
5 changes: 5 additions & 0 deletions NAPS2.Lib/EtoForms/Ui/DesktopCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,10 @@ public DesktopCommands(DesktopController desktopController, DesktopScanControlle
Text = UiStrings.Flip,
Image = iconProvider.GetIcon("arrow_switch_small")
};
AltFlip = new ActionCommand(imageListActions.AltFlip)
{
Text = UiStrings.AltFlip
};
Deskew = new ActionCommand(imageListActions.Deskew)
{
Text = UiStrings.Deskew
Expand Down Expand Up @@ -396,6 +400,7 @@ public DesktopCommands WithSelection(Func<ListSelection<UiImage>> selectionFunc)
public ActionCommand RotateLeft { get; set; }
public ActionCommand RotateRight { get; set; }
public ActionCommand Flip { get; set; }
public ActionCommand AltFlip { get; set; }
public ActionCommand Deskew { get; set; }
public ActionCommand CustomRotate { get; set; }
public ActionCommand MoveUp { get; set; }
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Lib/EtoForms/Ui/DesktopForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ protected MenuProvider GetRotateMenuProvider() =>
.Append(Commands.RotateLeft)
.Append(Commands.RotateRight)
.Append(Commands.Flip)
.Append(Commands.AltFlip)
.Append(Commands.Deskew)
.Append(Commands.CustomRotate);

Expand Down
2 changes: 2 additions & 0 deletions NAPS2.Lib/EtoForms/Ui/PreviewForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,7 @@ protected virtual void CreateToolbar()
{
Commands.RotateLeft,
Commands.RotateRight,
Commands.AltFlip,
Commands.Flip,
Commands.Deskew,
Commands.CustomRotate
Expand Down Expand Up @@ -370,6 +371,7 @@ private void AssignKeyboardShortcuts()
_ksm.Assign(ks.RotateFlip, Commands.Flip);
_ksm.Assign(ks.RotateLeft, Commands.RotateLeft);
_ksm.Assign(ks.RotateRight, Commands.RotateRight);
_ksm.Assign(ks.AltFlip, Commands.AltFlip);
_ksm.Assign(ks.SaveImages, Commands.SaveSelectedImages);
_ksm.Assign(ks.SavePDF, Commands.SaveSelectedPdf);
}
Expand Down
19 changes: 19 additions & 0 deletions NAPS2.Lib/Images/ImageListMutation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,25 @@ public override void Apply(List<UiImage> list, ref ListSelection<UiImage> select
}
}

public class AltFlip() : ImageListMutation
{
public override void Apply(List<UiImage> list, ref ListSelection<UiImage> selection)
{
bool toggle = false;
foreach (UiImage img in selection)
{
if (toggle)
{
var transform = new RotationTransform(180);
var thumb = img.GetThumbnailClone();
var updatedThumb = thumb?.PerformTransform(transform);
img.AddTransform(transform, updatedThumb);
}
toggle = !toggle;
}
}
}

public class AddTransforms(List<Transform> transforms, Dictionary<UiImage, IMemoryImage?>? updatedThumbnails = null)
: ListMutation<UiImage>
{
Expand Down
9 changes: 9 additions & 0 deletions NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions NAPS2.Lib/Lang/Resources/UiStrings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,9 @@
<data name="Flip" xml:space="preserve">
<value>Flip</value>
</data>
<data name="AltFlip" xml:space="preserve">
<value>Flip every 2nd image</value>
</data>
<data name="Deskew" xml:space="preserve">
<value>Deskew</value>
</data>
Expand Down
1 change: 1 addition & 0 deletions NAPS2.Setup/appsettings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@
<RotateLeft></RotateLeft>
<RotateRight></RotateRight>
<RotateFlip></RotateFlip>
<AltFlip></AltFlip>
<RotateCustom></RotateCustom>
<MoveUp>Ctrl+Up</MoveUp>
<MoveDown>Ctrl+Down</MoveDown>
Expand Down
Loading