Skip to content

Commit

Permalink
Add separators to the keyboard shortcut list
Browse files Browse the repository at this point in the history
  • Loading branch information
cyanfish committed Feb 2, 2025
1 parent e5cecb3 commit 423a6e6
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 18 deletions.
1 change: 0 additions & 1 deletion NAPS2.Lib/Config/KeyboardShortcuts.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public class KeyboardShortcuts

public string? Delete { get; set; }
public string? Clear { get; set; }

public string? Settings { get; set; }
public string? About { get; set; }

Expand Down
43 changes: 26 additions & 17 deletions NAPS2.Lib/EtoForms/Ui/KeyboardShortcutsForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,29 +26,29 @@ public class KeyboardShortcutsForm : EtoDialogBase
new(string.Format(UiStrings.ScanWithProfile, 12), c => c.KeyboardShortcuts.ScanProfile12),
new(UiStrings.ScanWithNewProfile, c => c.KeyboardShortcuts.NewProfile),
new(UiStrings.BatchScan, c => c.KeyboardShortcuts.BatchScan),

Shortcut.Separator,
new(UiStrings.Profiles, c => c.KeyboardShortcuts.Profiles),
new(UiStrings.ScannerSharing, c => c.KeyboardShortcuts.ScannerSharing),
new(UiStrings.Ocr, c => c.KeyboardShortcuts.Ocr),
new(UiStrings.Import, c => c.KeyboardShortcuts.Import),

Shortcut.Separator,
new(UiStrings.SavePdf, c => c.KeyboardShortcuts.SavePDF),
new(UiStrings.SaveAllAsPdf, c => c.KeyboardShortcuts.SavePDFAll),
new(UiStrings.SaveSelectedAsPdf, c => c.KeyboardShortcuts.SavePDFSelected),
new(UiStrings.PdfSettings, c => c.KeyboardShortcuts.PDFSettings),

Shortcut.Separator,
new(UiStrings.SaveImages, c => c.KeyboardShortcuts.SaveImages),
new(UiStrings.SaveAllAsImages, c => c.KeyboardShortcuts.SaveImagesAll),
new(UiStrings.SaveSelectedAsImages, c => c.KeyboardShortcuts.SaveImagesSelected),
new(UiStrings.ImageSettings, c => c.KeyboardShortcuts.ImageSettings),

Shortcut.Separator,
new(UiStrings.EmailPdf, c => c.KeyboardShortcuts.EmailPDF),
new(UiStrings.EmailAllAsPdf, c => c.KeyboardShortcuts.EmailPDFAll),
new(UiStrings.EmailSelectedAsPdf, c => c.KeyboardShortcuts.EmailPDFSelected),
new(UiStrings.EmailSettings, c => c.KeyboardShortcuts.EmailSettings),

Shortcut.Separator,
new(UiStrings.Print, c => c.KeyboardShortcuts.Print),

Shortcut.Separator,
new(UiStrings.View, c => c.KeyboardShortcuts.ImageView),
new(UiStrings.BlackAndWhite, c => c.KeyboardShortcuts.ImageView),
new(UiStrings.BrightnessContrast, c => c.KeyboardShortcuts.ImageBrightness),
Expand All @@ -59,28 +59,27 @@ public class KeyboardShortcutsForm : EtoDialogBase
new(UiStrings.Split, c => c.KeyboardShortcuts.ImageSplit),
new(UiStrings.Combine, c => c.KeyboardShortcuts.ImageCombine),
new(UiStrings.Reset, c => c.KeyboardShortcuts.ImageReset),

Shortcut.Separator,
new(UiStrings.RotateLeft, c => c.KeyboardShortcuts.RotateLeft),
new(UiStrings.RotateRight, c => c.KeyboardShortcuts.RotateRight),
new(UiStrings.Flip, c => c.KeyboardShortcuts.RotateFlip),
new(UiStrings.CustomRotation, c => c.KeyboardShortcuts.RotateCustom),

Shortcut.Separator,
new(UiStrings.MoveUp, c => c.KeyboardShortcuts.MoveUp),
new(UiStrings.MoveDown, c => c.KeyboardShortcuts.MoveDown),

Shortcut.Separator,
new(UiStrings.Interleave, c => c.KeyboardShortcuts.ReorderInterleave),
new(UiStrings.Deinterleave, c => c.KeyboardShortcuts.ReorderDeinterleave),
new(UiStrings.AltInterleave, c => c.KeyboardShortcuts.ReorderAltInterleave),
new(UiStrings.AltDeinterleave, c => c.KeyboardShortcuts.ReorderAltDeinterleave),
new(UiStrings.ReverseAll, c => c.KeyboardShortcuts.ReorderReverseAll),
new(UiStrings.ReverseSelected, c => c.KeyboardShortcuts.ReorderReverseSelected),

Shortcut.Separator,
new(UiStrings.Delete, c => c.KeyboardShortcuts.Delete),
new(UiStrings.Clear, c => c.KeyboardShortcuts.Clear),

new(UiStrings.Settings, c => c.KeyboardShortcuts.Settings),
new(UiStrings.About, c => c.KeyboardShortcuts.About),

Shortcut.Separator,
new(UiStrings.ZoomIn, c => c.KeyboardShortcuts.ZoomIn),
new(UiStrings.ZoomOut, c => c.KeyboardShortcuts.ZoomOut),
];
Expand Down Expand Up @@ -148,7 +147,7 @@ private void Assign_Click(object? sender, EventArgs e)
private void Unassign_Click(object? sender, EventArgs e)
{
var selected = (Shortcut?) _listBox.SelectedValue;
if (selected == null) return;
if (selected?.Accessor == null) return;
_transact.Set(selected.Accessor, "");
UpdateUi();
}
Expand All @@ -157,7 +156,10 @@ private void RestoreDefaults_Click(object? sender, EventArgs e)
{
foreach (var shortcut in Shortcuts)
{
_transact.Remove(shortcut.Accessor);
if (shortcut.Accessor != null)
{
_transact.Remove(shortcut.Accessor);
}
}
UpdateUi();
}
Expand All @@ -168,7 +170,7 @@ private void ShortcutText_KeyDown(object? sender, KeyEventArgs e)

e.Handled = true;
var selected = (Shortcut?) _listBox.SelectedValue;
if (selected == null) return;
if (selected?.Accessor == null) return;
if (e.Key is Keys.LeftControl or Keys.LeftAlt or Keys.LeftShift or Keys.LeftApplication
or Keys.RightControl or Keys.RightAlt or Keys.RightShift or Keys.RightApplication)
{
Expand All @@ -187,7 +189,7 @@ private void ListBox_SelectedIndexChanged(object? sender, EventArgs e)
private void UpdateUi()
{
var selected = (Shortcut?) _listBox.SelectedValue;
if (selected == null)
if (selected?.Accessor == null)
{
_shortcutText.Text = "";
_shortcutText.Enabled = false;
Expand All @@ -206,12 +208,16 @@ private void UpdateUi()

private string GetKeyString(Shortcut shortcut)
{
if (shortcut.Accessor == null) return "";

var keys = _ksm.Parse(_transactionConfig.Get(shortcut.Accessor));
return _ksm.Stringify(keys) ?? "";
}

private string GetLabel(Shortcut shortcut)
{
if (shortcut.Accessor == null) return shortcut.Label;

var keys = _ksm.Parse(_transactionConfig.Get(shortcut.Accessor));
if (keys == Keys.None)
{
Expand All @@ -226,5 +232,8 @@ private void Save()
_desktopFormProvider.DesktopForm.AssignKeyboardShortcuts();
}

private record Shortcut(string Label, Expression<Func<CommonConfig, string?>> Accessor);
private record Shortcut(string Label, Expression<Func<CommonConfig, string?>>? Accessor)
{
public static Shortcut Separator { get; } = new("-------", null);
}
}

0 comments on commit 423a6e6

Please sign in to comment.