@@ -84,8 +84,8 @@ public class KeyboardShortcutsForm : EtoDialogBase
84
84
85
85
private readonly DesktopFormProvider _desktopFormProvider ;
86
86
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 } ;
89
89
private readonly Button _assign = C . Button ( UiStrings . Assign ) ;
90
90
private readonly Button _unassign = C . Button ( UiStrings . Unassign ) ;
91
91
private readonly Button _restoreDefaults = C . Button ( UiStrings . RestoreDefaults ) ;
@@ -100,9 +100,27 @@ public KeyboardShortcutsForm(Naps2Config config, KeyboardShortcutManager ksm,
100
100
_desktopFormProvider = desktopFormProvider ;
101
101
_transact = Config . User . BeginTransaction ( ) ;
102
102
_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 ;
106
124
_shortcutText . KeyDown += ShortcutText_KeyDown ;
107
125
_assign . Click += Assign_Click ;
108
126
_unassign . Click += Unassign_Click ;
@@ -117,7 +135,7 @@ protected override void BuildLayout()
117
135
118
136
LayoutController . Content = L . Column (
119
137
L . Row (
120
- _listBox . NaturalSize ( 300 , 500 ) . Scale ( ) ,
138
+ _gridView . NaturalSize ( 450 , 500 ) . Scale ( ) ,
121
139
L . Column (
122
140
C . Filler ( ) ,
123
141
_shortcutText . Width ( 150 ) ,
@@ -136,15 +154,15 @@ protected override void BuildLayout()
136
154
137
155
private void Assign_Click ( object ? sender , EventArgs e )
138
156
{
139
- var selected = ( Shortcut ? ) _listBox . SelectedValue ;
157
+ var selected = ( Shortcut ? ) _gridView . SelectedItem ;
140
158
if ( selected == null ) return ;
141
- _shortcutText . Enabled = true ;
159
+ _shortcutText . ReadOnly = false ;
142
160
_shortcutText . Focus ( ) ;
143
161
}
144
162
145
163
private void Unassign_Click ( object ? sender , EventArgs e )
146
164
{
147
- var selected = ( Shortcut ? ) _listBox . SelectedValue ;
165
+ var selected = ( Shortcut ? ) _gridView . SelectedItem ;
148
166
if ( selected ? . Accessor == null ) return ;
149
167
_transact . Set ( selected . Accessor , "" ) ;
150
168
UpdateUi ( ) ;
@@ -164,10 +182,10 @@ private void RestoreDefaults_Click(object? sender, EventArgs e)
164
182
165
183
private void ShortcutText_KeyDown ( object ? sender , KeyEventArgs e )
166
184
{
167
- if ( ! _shortcutText . Enabled ) return ;
185
+ if ( _shortcutText . ReadOnly ) return ;
168
186
169
187
e . Handled = true ;
170
- var selected = ( Shortcut ? ) _listBox . SelectedValue ;
188
+ var selected = ( Shortcut ? ) _gridView . SelectedItem ;
171
189
if ( selected ? . Accessor == null ) return ;
172
190
if ( e . Key is Keys . LeftControl or Keys . LeftAlt or Keys . LeftShift or Keys . LeftApplication
173
191
or Keys . RightControl or Keys . RightAlt or Keys . RightShift or Keys . RightApplication )
@@ -179,30 +197,30 @@ private void ShortcutText_KeyDown(object? sender, KeyEventArgs e)
179
197
UpdateUi ( ) ;
180
198
}
181
199
182
- private void ListBox_SelectedIndexChanged ( object ? sender , EventArgs e )
200
+ private void GridView_SelectionChanged ( object ? sender , EventArgs e )
183
201
{
184
202
UpdateUi ( ) ;
185
203
}
186
204
187
205
private void UpdateUi ( )
188
206
{
189
- var selected = ( Shortcut ? ) _listBox . SelectedValue ;
207
+ var selected = ( Shortcut ? ) _gridView . SelectedItem ;
190
208
if ( selected ? . Accessor == null )
191
209
{
192
210
_shortcutText . Text = "" ;
193
- _shortcutText . Enabled = false ;
211
+ _shortcutText . ReadOnly = true ;
194
212
_assign . Enabled = false ;
195
213
_unassign . Enabled = false ;
196
214
}
197
215
else
198
216
{
199
217
bool locked = _transactionConfig . AppLocked . Has ( selected . Accessor ) ;
200
218
_shortcutText . Text = GetKeyString ( selected ) ;
201
- _shortcutText . Enabled = false ;
219
+ _shortcutText . ReadOnly = true ;
202
220
_assign . Enabled = ! locked ;
203
221
_unassign . Enabled = ! locked && _shortcutText . Text != "" ;
204
222
}
205
- _listBox . Invalidate ( ) ;
223
+ _gridView . Invalidate ( ) ;
206
224
}
207
225
208
226
private string GetKeyString ( Shortcut shortcut )
@@ -213,16 +231,12 @@ private string GetKeyString(Shortcut shortcut)
213
231
return _ksm . Stringify ( keys ) ?? "" ;
214
232
}
215
233
216
- private string GetLabel ( Shortcut shortcut )
234
+ private string GetShortcutLabel ( Shortcut shortcut )
217
235
{
218
- if ( shortcut . Accessor == null ) return shortcut . Label ;
236
+ if ( shortcut . Accessor == null ) return "" ;
219
237
220
238
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 ) ?? "" ;
226
240
}
227
241
228
242
private void Save ( )
0 commit comments