1
1
using System ;
2
2
using System . Collections . Generic ;
3
3
using System . Drawing ;
4
+ using System . IO ;
4
5
using System . Windows . Forms ;
5
6
using FlashDevelop . Managers ;
6
7
using PluginCore . Controls ;
@@ -13,9 +14,9 @@ namespace FlashDevelop.Dialogs
13
14
{
14
15
public class ShortcutDialog : SmartForm
15
16
{
16
- const string ViewConflictsKey = "?" ; // TODO: Change the type to char after #969 is merged
17
- const string ViewCustomKey = "*" ; // TODO: Change the type to char after #969 is merged
18
-
17
+ const char ViewConflictsKey = '?' ;
18
+ const char ViewCustomKey = '*' ;
19
+
19
20
Timer updateTimer ;
20
21
ToolStripMenuItem removeShortcut ;
21
22
ToolStripMenuItem revertToDefault ;
@@ -28,9 +29,10 @@ public class ShortcutDialog : SmartForm
28
29
private System . Windows . Forms . ColumnHeader idHeader ;
29
30
private System . Windows . Forms . ColumnHeader keyHeader ;
30
31
private System . Windows . Forms . TextBox filterTextBox ;
31
- private System . Windows . Forms . CheckBox viewCustom ;
32
32
private System . Windows . Forms . Button clearButton ;
33
33
private System . Windows . Forms . Button closeButton ;
34
+ private System . Windows . Forms . Button openButton ;
35
+ private System . Windows . Forms . Button saveButton ;
34
36
35
37
ShortcutDialog ( )
36
38
{
@@ -64,7 +66,8 @@ private void InitializeComponent()
64
66
this . searchLabel = new System . Windows . Forms . Label ( ) ;
65
67
this . clearButton = new System . Windows . Forms . Button ( ) ;
66
68
this . filterTextBox = new System . Windows . Forms . TextBox ( ) ;
67
- this . viewCustom = new System . Windows . Forms . CheckBox ( ) ;
69
+ this . openButton = new System . Windows . Forms . Button ( ) ;
70
+ this . saveButton = new System . Windows . Forms . Button ( ) ;
68
71
( ( System . ComponentModel . ISupportInitialize ) ( this . pictureBox ) ) . BeginInit ( ) ;
69
72
this . SuspendLayout ( ) ;
70
73
//
@@ -79,15 +82,15 @@ private void InitializeComponent()
79
82
this . keyHeader . Width = 208 ;
80
83
//
81
84
// listView
82
- //
85
+ //
83
86
this . listView . Anchor = ( ( System . Windows . Forms . AnchorStyles ) ( ( ( ( System . Windows . Forms . AnchorStyles . Top | System . Windows . Forms . AnchorStyles . Bottom ) | System . Windows . Forms . AnchorStyles . Left ) | System . Windows . Forms . AnchorStyles . Right ) ) ) ;
84
87
this . listView . Columns . AddRange ( new System . Windows . Forms . ColumnHeader [ ] { this . idHeader , this . keyHeader } ) ;
85
88
this . listView . GridLines = true ;
86
89
this . listView . FullRowSelect = true ;
87
- this . listView . Location = new System . Drawing . Point ( 12 , 62 ) ;
90
+ this . listView . Location = new System . Drawing . Point ( 12 , 70 ) ;
88
91
this . listView . MultiSelect = false ;
89
92
this . listView . Name = "listView" ;
90
- this . listView . Size = new System . Drawing . Size ( 562 , 312 ) ;
93
+ this . listView . Size = new System . Drawing . Size ( 562 , 304 ) ;
91
94
this . listView . TabIndex = 4 ;
92
95
this . listView . UseCompatibleStateImageBehavior = false ;
93
96
this . listView . View = System . Windows . Forms . View . Details ;
@@ -128,15 +131,15 @@ private void InitializeComponent()
128
131
//
129
132
this . searchLabel . AutoSize = true ;
130
133
this . searchLabel . Anchor = ( ( System . Windows . Forms . AnchorStyles ) ( ( System . Windows . Forms . AnchorStyles . Top | System . Windows . Forms . AnchorStyles . Left ) ) ) ;
131
- this . searchLabel . Location = new System . Drawing . Point ( 10 , 10 ) ;
134
+ this . searchLabel . Location = new System . Drawing . Point ( 10 , 25 ) ;
132
135
this . searchLabel . Name = "searchLabel" ;
133
136
this . searchLabel . TabIndex = 0 ;
134
137
this . searchLabel . Text = "Search:" ;
135
138
//
136
139
// clearButton
137
- //
140
+ //
138
141
this . clearButton . Anchor = ( ( System . Windows . Forms . AnchorStyles ) ( ( System . Windows . Forms . AnchorStyles . Top | System . Windows . Forms . AnchorStyles . Right ) ) ) ;
139
- this . clearButton . Location = new System . Drawing . Point ( 549 , 30 ) ;
142
+ this . clearButton . Location = new System . Drawing . Point ( 549 , 39 ) ;
140
143
this . clearButton . Name = "clearButton" ;
141
144
this . clearButton . Size = new System . Drawing . Size ( 26 , 23 ) ;
142
145
this . clearButton . TabIndex = 2 ;
@@ -146,20 +149,28 @@ private void InitializeComponent()
146
149
// filterTextBox
147
150
//
148
151
this . filterTextBox . Anchor = ( ( System . Windows . Forms . AnchorStyles ) ( ( ( System . Windows . Forms . AnchorStyles . Top | System . Windows . Forms . AnchorStyles . Left ) | System . Windows . Forms . AnchorStyles . Right ) ) ) ;
149
- this . filterTextBox . Location = new System . Drawing . Point ( 12 , 32 ) ;
152
+ this . filterTextBox . Location = new System . Drawing . Point ( 12 , 41 ) ;
150
153
this . filterTextBox . Name = "filterTextBox" ;
151
- this . filterTextBox . Size = new System . Drawing . Size ( 530 , 20 ) ;
154
+ this . filterTextBox . Size = new System . Drawing . Size ( 531 , 20 ) ;
152
155
this . filterTextBox . TabIndex = 1 ;
153
156
this . filterTextBox . ForeColor = System . Drawing . SystemColors . GrayText ;
154
157
this . filterTextBox . TextChanged += new System . EventHandler ( this . FilterTextChanged ) ;
155
158
//
156
- // viewCustom
157
- //
158
- this . viewCustom . AutoSize = true ;
159
- this . viewCustom . CheckAlign = ContentAlignment . MiddleRight ;
160
- this . viewCustom . Anchor = ( ( System . Windows . Forms . AnchorStyles ) ( System . Windows . Forms . AnchorStyles . Top | System . Windows . Forms . AnchorStyles . Right ) ) ;
161
- this . viewCustom . Location = new System . Drawing . Point ( 471 , 9 ) ;
162
- this . viewCustom . CheckedChanged += new System . EventHandler ( this . ViewCustomCheckedChanged ) ;
159
+ // openButton
160
+ //
161
+ this . openButton . Location = new System . Drawing . Point ( 369 , 12 ) ;
162
+ this . openButton . Name = "openButton" ;
163
+ this . openButton . Size = new System . Drawing . Size ( 100 , 23 ) ;
164
+ this . openButton . UseVisualStyleBackColor = true ;
165
+ this . openButton . Click += new System . EventHandler ( SelectCustomShortcut ) ;
166
+ //
167
+ // saveButton
168
+ //
169
+ this . saveButton . Location = new System . Drawing . Point ( 475 , 12 ) ;
170
+ this . saveButton . Name = "saveButton" ;
171
+ this . saveButton . Size = new System . Drawing . Size ( 100 , 23 ) ;
172
+ this . saveButton . UseVisualStyleBackColor = true ;
173
+ this . saveButton . Click += new System . EventHandler ( SaveCustomShortcut ) ;
163
174
//
164
175
// ShortcutDialog
165
176
//
@@ -175,12 +186,13 @@ private void InitializeComponent()
175
186
this . AutoScaleMode = System . Windows . Forms . AutoScaleMode . Font ;
176
187
this . ClientSize = new System . Drawing . Size ( 586 , 416 ) ;
177
188
this . MinimumSize = new System . Drawing . Size ( 400 , 250 ) ;
189
+ this . Controls . Add ( this . saveButton ) ;
190
+ this . Controls . Add ( this . openButton ) ;
178
191
this . Controls . Add ( this . filterTextBox ) ;
179
192
this . Controls . Add ( this . clearButton ) ;
180
193
this . Controls . Add ( this . infoLabel ) ;
181
194
this . Controls . Add ( this . pictureBox ) ;
182
195
this . Controls . Add ( this . closeButton ) ;
183
- this . Controls . Add ( this . viewCustom ) ;
184
196
this . Controls . Add ( this . listView ) ;
185
197
this . Controls . Add ( this . searchLabel ) ;
186
198
this . FormClosing += new FormClosingEventHandler ( this . DialogClosing ) ;
@@ -219,11 +231,15 @@ void InitializeContextMenu()
219
231
{
220
232
var cms = new ContextMenuStrip ( ) ;
221
233
cms . Font = Globals . Settings . DefaultFont ;
234
+ cms . ImageScalingSize = ScaleHelper . Scale ( new Size ( 16 , 16 ) ) ;
222
235
cms . Renderer = new DockPanelStripRenderer ( false , false ) ;
223
236
this . removeShortcut = new ToolStripMenuItem ( TextHelper . GetString ( "Label.RemoveShortcut" ) , null , this . RemoveShortcutClick ) ;
224
237
this . revertToDefault = new ToolStripMenuItem ( TextHelper . GetString ( "Label.RevertToDefault" ) , null , this . RevertToDefaultClick ) ;
225
238
this . revertAllToDefault = new ToolStripMenuItem ( TextHelper . GetString ( "Label.RevertAllToDefault" ) , null , this . RevertAllToDefaultClick ) ;
226
239
this . removeShortcut . ShortcutKeyDisplayString = DataConverter . KeysToString ( Keys . Delete ) ;
240
+ this . removeShortcut . Image = Globals . MainForm . FindImage ( "153" ) ;
241
+ this . revertToDefault . Image = Globals . MainForm . FindImage ( "69" ) ;
242
+ this . revertAllToDefault . Image = Globals . MainForm . FindImage ( "224" ) ;
227
243
cms . Items . Add ( this . removeShortcut ) ;
228
244
cms . Items . Add ( this . revertToDefault ) ;
229
245
cms . Items . Add ( this . revertAllToDefault ) ;
@@ -240,7 +256,8 @@ void ApplyLocalizedTexts()
240
256
this . keyHeader . Text = TextHelper . GetString ( "Label.Shortcut" ) ;
241
257
this . infoLabel . Text = TextHelper . GetString ( "Info.ShortcutEditInfo" ) ;
242
258
this . closeButton . Text = TextHelper . GetString ( "Label.Close" ) ;
243
- this . viewCustom . Text = TextHelper . GetString ( "Label.ViewCustom" ) ;
259
+ this . openButton . Text = TextHelper . GetString ( "Label.Open" ) ;
260
+ this . saveButton . Text = TextHelper . GetString ( "Label.SaveAs" ) ;
244
261
this . searchLabel . Text = TextHelper . GetStringWithoutMnemonics ( "Label.Search" ) + ":" ;
245
262
this . Text = " " + TextHelper . GetString ( "Title.Shortcuts" ) ;
246
263
}
@@ -253,7 +270,7 @@ void ApplyScaling()
253
270
this . idHeader . Width = ScaleHelper . Scale ( this . idHeader . Width ) ;
254
271
this . keyHeader . Width = ScaleHelper . Scale ( this . keyHeader . Width ) ;
255
272
}
256
-
273
+
257
274
/// <summary>
258
275
/// Updates the font highlight of the item.
259
276
/// </summary>
@@ -286,7 +303,14 @@ void InitializeShortcutListItems()
286
303
this . shortcutListItems [ counter ++ ] = new ShortcutListItem ( item ) ;
287
304
}
288
305
Array . Sort ( this . shortcutListItems , new ShorcutListItemComparer ( ) ) ;
306
+ this . UpdateAllShortcutsConflicts ( ) ;
307
+ }
289
308
309
+ /// <summary>
310
+ /// Update conflicts statuses of all shortcut items.
311
+ /// </summary>
312
+ void UpdateAllShortcutsConflicts ( )
313
+ {
290
314
bool conflicts = false ;
291
315
for ( int i = 0 ; i < this . shortcutListItems . Length ; i ++ )
292
316
{
@@ -307,6 +331,8 @@ bool ShowConflictsPresent()
307
331
if ( MessageBox . Show ( this , text , " " + caption , MessageBoxButtons . YesNo , MessageBoxIcon . Warning ) == DialogResult . No )
308
332
{
309
333
this . filterTextBox . Text = ViewConflictsKey . ToString ( ) ;
334
+ this . filterTextBox . SelectAll ( ) ;
335
+ this . filterTextBox . Focus ( ) ;
310
336
return true ;
311
337
}
312
338
return false ;
@@ -326,7 +352,7 @@ void PopulateListView(string filter)
326
352
{
327
353
var item = this . shortcutListItems [ i ] ;
328
354
if ( string . IsNullOrEmpty ( filter ) ||
329
- item . Id . IndexOf ( filter , StringComparison . OrdinalIgnoreCase ) >= 0 ||
355
+ item . Id . IndexOf ( filter , StringComparison . OrdinalIgnoreCase ) >= 0 ||
330
356
item . KeysString . IndexOf ( filter , StringComparison . OrdinalIgnoreCase ) >= 0 )
331
357
{
332
358
if ( viewCustom && ! item . IsModified ) continue ;
@@ -342,17 +368,17 @@ void PopulateListView(string filter)
342
368
343
369
/// <summary>
344
370
/// Reads and removes filter keywords from the start of the filter.
345
- /// Order of the keywords is irrelevant.
371
+ /// The order of the keywords is irrelevant.
346
372
/// </summary>
347
373
static string ExtractFilterKeywords ( string filter , ref bool viewCustom , ref bool viewConflicts )
348
374
{
349
- if ( ! viewCustom && filter . StartsWith ( ViewCustomKey ) )
375
+ if ( ! viewCustom && filter . Length != 0 && filter [ 0 ] == ViewCustomKey )
350
376
{
351
377
filter = filter . Substring ( 1 ) ;
352
378
viewCustom = true ;
353
379
return ExtractFilterKeywords ( filter , ref viewCustom , ref viewConflicts ) ;
354
380
}
355
- if ( ! viewConflicts && filter . StartsWith ( ViewConflictsKey ) )
381
+ if ( ! viewConflicts && filter . Length != 0 && filter [ 0 ] == ViewConflictsKey )
356
382
{
357
383
filter = filter . Substring ( 1 ) ;
358
384
viewConflicts = true ;
@@ -408,19 +434,23 @@ void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
408
434
else if ( ! ToolStripManager . IsValidShortcut ( shortcut ) ) return ;
409
435
410
436
if ( item . Custom == shortcut ) return ;
437
+ this . listView . BeginUpdate ( ) ;
411
438
var oldShortcut = item . Custom ;
412
439
item . Custom = shortcut ;
413
440
item . Selected = true ;
414
441
this . GetConflictItems ( item ) ;
442
+ this . listView . EndUpdate ( ) ;
415
443
if ( item . HasConflicts )
416
444
{
417
445
string text = TextHelper . GetString ( "Info.ShortcutIsAlreadyUsed" ) ;
418
446
string caption = TextHelper . GetString ( "Title.WarningDialog" ) ;
419
447
switch ( MessageBox . Show ( Globals . MainForm , text , " " + caption , MessageBoxButtons . AbortRetryIgnore , MessageBoxIcon . Warning ) )
420
448
{
421
449
case DialogResult . Abort :
450
+ this . listView . BeginUpdate ( ) ;
422
451
item . Custom = oldShortcut ;
423
452
this . GetConflictItems ( item ) ;
453
+ this . listView . EndUpdate ( ) ;
424
454
break ;
425
455
case DialogResult . Retry :
426
456
this . filterTextBox . Text = ViewConflictsKey + item . KeysString ;
@@ -430,7 +460,7 @@ void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
430
460
}
431
461
}
432
462
}
433
-
463
+
434
464
/// <summary>
435
465
/// Resets the conflicts status of an item.
436
466
/// </summary>
@@ -449,23 +479,6 @@ static void ResetConflicts(ShortcutListItem item)
449
479
}
450
480
}
451
481
452
- /// <summary>
453
- /// [Deprecated] Filter the list view for custom items.
454
- /// </summary>
455
- void ViewCustomCheckedChanged ( object sender , EventArgs e )
456
- {
457
- if ( this . filterTextBox . Text . StartsWith ( ViewCustomKey ) )
458
- {
459
- if ( ! this . viewCustom . Checked )
460
- this . filterTextBox . Text = this . filterTextBox . Text . Substring ( 1 ) ;
461
- }
462
- else
463
- {
464
- if ( this . viewCustom . Checked )
465
- this . filterTextBox . Text = ViewCustomKey + this . filterTextBox . Text ;
466
- }
467
- }
468
-
469
482
/// <summary>
470
483
/// Gets a list of all conflicting entries.
471
484
/// </summary>
@@ -528,7 +541,6 @@ void RemoveShortcutClick(object sender, EventArgs e)
528
541
/// </summary>
529
542
void ClearFilterClick ( object sender , EventArgs e )
530
543
{
531
- this . viewCustom . Checked = false ;
532
544
this . filterTextBox . Text = string . Empty ;
533
545
this . filterTextBox . Select ( ) ;
534
546
}
@@ -562,6 +574,48 @@ void FilterTextChanged(object sender, EventArgs e)
562
574
this . updateTimer . Start ( ) ;
563
575
}
564
576
577
+ /// <summary>
578
+ /// Switch to a custom shortcut set.
579
+ /// </summary>
580
+ void SelectCustomShortcut ( object sender , EventArgs e )
581
+ {
582
+ var dialog = new OpenFileDialog
583
+ {
584
+ Filter = TextHelper . GetString ( "Info.ArgumentFilter" ) + "|*.fda" ,
585
+ InitialDirectory = PathHelper . ShortcutsDir ,
586
+ Title = " " + TextHelper . GetString ( "Title.OpenFileDialog" )
587
+ } ;
588
+
589
+ if ( dialog . ShowDialog ( this ) == DialogResult . OK )
590
+ {
591
+ this . listView . BeginUpdate ( ) ;
592
+ ShortcutManager . LoadCustomShortcuts ( dialog . FileName , this . shortcutListItems ) ;
593
+ this . UpdateAllShortcutsConflicts ( ) ;
594
+ this . listView . EndUpdate ( ) ;
595
+ }
596
+ }
597
+
598
+ /// <summary>
599
+ /// Save the current shortcut set to a file.
600
+ /// </summary>
601
+ void SaveCustomShortcut ( object sender , EventArgs e )
602
+ {
603
+ var dialog = new SaveFileDialog
604
+ {
605
+ AddExtension = true ,
606
+ DefaultExt = ".fda" ,
607
+ Filter = TextHelper . GetString ( "Info.ArgumentFilter" ) + "|*.fda" ,
608
+ InitialDirectory = PathHelper . ShortcutsDir ,
609
+ OverwritePrompt = true ,
610
+ Title = " " + TextHelper . GetString ( "Title.SaveFileDialog" )
611
+ } ;
612
+
613
+ if ( dialog . ShowDialog ( this ) == DialogResult . OK )
614
+ {
615
+ ShortcutManager . SaveCustomShortcuts ( dialog . FileName , this . shortcutListItems ) ;
616
+ }
617
+ }
618
+
565
619
/// <summary>
566
620
/// Closes the shortcut dialog.
567
621
/// </summary>
@@ -629,7 +683,7 @@ int IComparer<ShortcutListItem>.Compare(ShortcutListItem x, ShortcutListItem y)
629
683
/// <summary>
630
684
/// Represents a visual representation of a <see cref="ShortcutItem"/> object.
631
685
/// </summary>
632
- class ShortcutListItem : ListViewItem
686
+ class ShortcutListItem : ListViewItem , IShortcutItem
633
687
{
634
688
readonly ShortcutItem item ;
635
689
List < ShortcutListItem > conflicts ;
@@ -659,6 +713,7 @@ public List<ShortcutListItem> Conflicts
659
713
get { return this . conflicts ; }
660
714
set
661
715
{
716
+ if ( this . conflicts == value ) return ;
662
717
this . conflicts = value ;
663
718
UpdateItemHighlightFont ( this ) ;
664
719
}
@@ -688,6 +743,7 @@ public Keys Custom
688
743
get { return this . custom ; }
689
744
set
690
745
{
746
+ if ( this . custom == value ) return ;
691
747
this . custom = value ;
692
748
this . KeysString = DataConverter . KeysToString ( this . custom ) ;
693
749
this . SubItems [ 1 ] . Text = this . KeysString ;
0 commit comments