Skip to content

Commit ec84961

Browse files
committed
Use GridView for keyboard shortcuts and polish
#549
1 parent 068370e commit ec84961

File tree

5 files changed

+72
-42
lines changed

5 files changed

+72
-42
lines changed

NAPS2.App.WinForms/NAPS2.App.WinForms.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
<SelfContained>true</SelfContained>
1212
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
13-
<!-- TODO: Re-enable trimming if we can fix startup time as well as WIA being broken -->
14-
<PublishTrimmed>false</PublishTrimmed>
15-
<TrimMode>none</TrimMode>
13+
<PublishTrimmed>true</PublishTrimmed>
14+
<PublishSingleFile>true</PublishSingleFile>
15+
<TrimMode>partial</TrimMode>
1616
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
1717

1818
<Title>NAPS2 - Not Another PDF Scanner</Title>

NAPS2.Lib/EtoForms/Ui/KeyboardShortcutsForm.cs

+37-23
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ public class KeyboardShortcutsForm : EtoDialogBase
8484

8585
private readonly DesktopFormProvider _desktopFormProvider;
8686

87-
private readonly ListBox _listBox = new();
88-
private readonly TextBox _shortcutText = new();
87+
private readonly GridView _gridView;
88+
private readonly TextBox _shortcutText = new() { ReadOnly = true };
8989
private readonly Button _assign = C.Button(UiStrings.Assign);
9090
private readonly Button _unassign = C.Button(UiStrings.Unassign);
9191
private readonly Button _restoreDefaults = C.Button(UiStrings.RestoreDefaults);
@@ -100,9 +100,27 @@ public KeyboardShortcutsForm(Naps2Config config, KeyboardShortcutManager ksm,
100100
_desktopFormProvider = desktopFormProvider;
101101
_transact = Config.User.BeginTransaction();
102102
_transactionConfig = Config.WithTransaction(_transact);
103-
_listBox.DataStore = Shortcuts;
104-
_listBox.ItemTextBinding = new DelegateBinding<Shortcut, string>(GetLabel);
105-
_listBox.SelectedIndexChanged += ListBox_SelectedIndexChanged;
103+
_gridView = new()
104+
{
105+
DataStore = Shortcuts,
106+
Columns =
107+
{
108+
new()
109+
{
110+
HeaderText = UiStrings.Action,
111+
DataCell = new TextBoxCell { Binding = new PropertyBinding<string>("Label") },
112+
Width = 280
113+
},
114+
new()
115+
{
116+
HeaderText = UiStrings.Shortcut,
117+
DataCell = new TextBoxCell { Binding = new DelegateBinding<Shortcut, string>(GetShortcutLabel) },
118+
Width = 150
119+
}
120+
}
121+
};
122+
_gridView.SelectionChanged += GridView_SelectionChanged;
123+
_gridView.CellDoubleClick += Assign_Click;
106124
_shortcutText.KeyDown += ShortcutText_KeyDown;
107125
_assign.Click += Assign_Click;
108126
_unassign.Click += Unassign_Click;
@@ -117,7 +135,7 @@ protected override void BuildLayout()
117135

118136
LayoutController.Content = L.Column(
119137
L.Row(
120-
_listBox.NaturalSize(300, 500).Scale(),
138+
_gridView.NaturalSize(450, 500).Scale(),
121139
L.Column(
122140
C.Filler(),
123141
_shortcutText.Width(150),
@@ -136,15 +154,15 @@ protected override void BuildLayout()
136154

137155
private void Assign_Click(object? sender, EventArgs e)
138156
{
139-
var selected = (Shortcut?) _listBox.SelectedValue;
157+
var selected = (Shortcut?) _gridView.SelectedItem;
140158
if (selected == null) return;
141-
_shortcutText.Enabled = true;
159+
_shortcutText.ReadOnly = false;
142160
_shortcutText.Focus();
143161
}
144162

145163
private void Unassign_Click(object? sender, EventArgs e)
146164
{
147-
var selected = (Shortcut?) _listBox.SelectedValue;
165+
var selected = (Shortcut?) _gridView.SelectedItem;
148166
if (selected?.Accessor == null) return;
149167
_transact.Set(selected.Accessor, "");
150168
UpdateUi();
@@ -164,10 +182,10 @@ private void RestoreDefaults_Click(object? sender, EventArgs e)
164182

165183
private void ShortcutText_KeyDown(object? sender, KeyEventArgs e)
166184
{
167-
if (!_shortcutText.Enabled) return;
185+
if (_shortcutText.ReadOnly) return;
168186

169187
e.Handled = true;
170-
var selected = (Shortcut?) _listBox.SelectedValue;
188+
var selected = (Shortcut?) _gridView.SelectedItem;
171189
if (selected?.Accessor == null) return;
172190
if (e.Key is Keys.LeftControl or Keys.LeftAlt or Keys.LeftShift or Keys.LeftApplication
173191
or Keys.RightControl or Keys.RightAlt or Keys.RightShift or Keys.RightApplication)
@@ -179,30 +197,30 @@ private void ShortcutText_KeyDown(object? sender, KeyEventArgs e)
179197
UpdateUi();
180198
}
181199

182-
private void ListBox_SelectedIndexChanged(object? sender, EventArgs e)
200+
private void GridView_SelectionChanged(object? sender, EventArgs e)
183201
{
184202
UpdateUi();
185203
}
186204

187205
private void UpdateUi()
188206
{
189-
var selected = (Shortcut?) _listBox.SelectedValue;
207+
var selected = (Shortcut?) _gridView.SelectedItem;
190208
if (selected?.Accessor == null)
191209
{
192210
_shortcutText.Text = "";
193-
_shortcutText.Enabled = false;
211+
_shortcutText.ReadOnly = true;
194212
_assign.Enabled = false;
195213
_unassign.Enabled = false;
196214
}
197215
else
198216
{
199217
bool locked = _transactionConfig.AppLocked.Has(selected.Accessor);
200218
_shortcutText.Text = GetKeyString(selected);
201-
_shortcutText.Enabled = false;
219+
_shortcutText.ReadOnly = true;
202220
_assign.Enabled = !locked;
203221
_unassign.Enabled = !locked && _shortcutText.Text != "";
204222
}
205-
_listBox.Invalidate();
223+
_gridView.Invalidate();
206224
}
207225

208226
private string GetKeyString(Shortcut shortcut)
@@ -213,16 +231,12 @@ private string GetKeyString(Shortcut shortcut)
213231
return _ksm.Stringify(keys) ?? "";
214232
}
215233

216-
private string GetLabel(Shortcut shortcut)
234+
private string GetShortcutLabel(Shortcut shortcut)
217235
{
218-
if (shortcut.Accessor == null) return shortcut.Label;
236+
if (shortcut.Accessor == null) return "";
219237

220238
var keys = _ksm.Parse(_transactionConfig.Get(shortcut.Accessor));
221-
if (keys == Keys.None)
222-
{
223-
return shortcut.Label;
224-
}
225-
return string.Format(UiStrings.KeyboardShortcutLabelFormat, shortcut.Label, _ksm.Stringify(keys));
239+
return _ksm.Stringify(keys) ?? "";
226240
}
227241

228242
private void Save()

NAPS2.Lib/Lang/Resources/UiStrings.Designer.cs

+18-9
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

NAPS2.Lib/Lang/Resources/UiStrings.resx

+6-3
Original file line numberDiff line numberDiff line change
@@ -957,13 +957,16 @@
957957
<data name="ScanWithNewProfile" xml:space="preserve">
958958
<value>Scan With New Profile</value>
959959
</data>
960-
<data name="KeyboardShortcutLabelFormat" xml:space="preserve">
961-
<value>{0} ({1})</value>
962-
</data>
963960
<data name="Assign" xml:space="preserve">
964961
<value>Assign</value>
965962
</data>
966963
<data name="Unassign" xml:space="preserve">
967964
<value>Unassign</value>
968965
</data>
966+
<data name="Action" xml:space="preserve">
967+
<value>Action</value>
968+
</data>
969+
<data name="Shortcut" xml:space="preserve">
970+
<value>Shortcut</value>
971+
</data>
969972
</root>

NAPS2.Lib/Lang/po/templates.pot

+8-4
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ msgstr ""
5454
msgid "Acquiring data..."
5555
msgstr ""
5656

57+
#: UiStrings.resx$Action$Message
58+
msgid "Action"
59+
msgstr ""
60+
5761
#: UiStrings.resx$Advanced$Message
5862
msgid "Advanced"
5963
msgstr ""
@@ -1431,6 +1435,10 @@ msgstr ""
14311435
msgid "Sharpen"
14321436
msgstr ""
14331437

1438+
#: UiStrings.resx$Shortcut$Message
1439+
msgid "Shortcut"
1440+
msgstr ""
1441+
14341442
#: UiStrings.resx$Show$Message
14351443
msgid "Show"
14361444
msgstr ""
@@ -1749,10 +1757,6 @@ msgstr ""
17491757
msgid "x64"
17501758
msgstr ""
17511759

1752-
#: UiStrings.resx$KeyboardShortcutLabelFormat$Message
1753-
msgid "{0} ({1})"
1754-
msgstr ""
1755-
17561760
#: MiscResources.resx$NamedPageSizeFormat$Message
17571761
msgid "{0} ({1}x{2} {3})"
17581762
msgstr ""

0 commit comments

Comments
 (0)