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 ;
@@ -30,6 +31,8 @@ public class ShortcutDialog : SmartForm
30
31
private System . Windows . Forms . CheckBox viewCustom ;
31
32
private System . Windows . Forms . Button clearButton ;
32
33
private System . Windows . Forms . Button closeButton ;
34
+ private System . Windows . Forms . Button openButton ;
35
+ private System . Windows . Forms . Button saveButton ;
33
36
private ShortcutListItem [ ] shortcutListItems ;
34
37
35
38
public ShortcutDialog ( )
@@ -65,6 +68,8 @@ private void InitializeComponent()
65
68
this . clearButton = new System . Windows . Forms . Button ( ) ;
66
69
this . filterTextBox = new System . Windows . Forms . TextBox ( ) ;
67
70
this . viewCustom = new System . Windows . Forms . CheckBox ( ) ;
71
+ this . openButton = new System . Windows . Forms . Button ( ) ;
72
+ this . saveButton = new System . Windows . Forms . Button ( ) ;
68
73
( ( System . ComponentModel . ISupportInitialize ) ( this . pictureBox ) ) . BeginInit ( ) ;
69
74
this . SuspendLayout ( ) ;
70
75
//
@@ -79,15 +84,15 @@ private void InitializeComponent()
79
84
this . keyHeader . Width = 208 ;
80
85
//
81
86
// listView
82
- //
87
+ //
83
88
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
89
this . listView . Columns . AddRange ( new System . Windows . Forms . ColumnHeader [ ] { this . idHeader , this . keyHeader } ) ;
85
90
this . listView . GridLines = true ;
86
91
this . listView . FullRowSelect = true ;
87
- this . listView . Location = new System . Drawing . Point ( 12 , 62 ) ;
92
+ this . listView . Location = new System . Drawing . Point ( 12 , 87 ) ;
88
93
this . listView . MultiSelect = false ;
89
94
this . listView . Name = "listView" ;
90
- this . listView . Size = new System . Drawing . Size ( 562 , 312 ) ;
95
+ this . listView . Size = new System . Drawing . Size ( 562 , 287 ) ;
91
96
this . listView . TabIndex = 4 ;
92
97
this . listView . UseCompatibleStateImageBehavior = false ;
93
98
this . listView . View = System . Windows . Forms . View . Details ;
@@ -128,15 +133,15 @@ private void InitializeComponent()
128
133
//
129
134
this . searchLabel . AutoSize = true ;
130
135
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 ) ;
136
+ this . searchLabel . Location = new System . Drawing . Point ( 10 , 25 ) ;
132
137
this . searchLabel . Name = "searchLabel" ;
133
138
this . searchLabel . TabIndex = 0 ;
134
139
this . searchLabel . Text = "Search:" ;
135
140
//
136
141
// clearButton
137
- //
142
+ //
138
143
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 ) ;
144
+ this . clearButton . Location = new System . Drawing . Point ( 549 , 39 ) ;
140
145
this . clearButton . Name = "clearButton" ;
141
146
this . clearButton . Size = new System . Drawing . Size ( 26 , 23 ) ;
142
147
this . clearButton . TabIndex = 2 ;
@@ -146,21 +151,37 @@ private void InitializeComponent()
146
151
// filterTextBox
147
152
//
148
153
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 ) ;
154
+ this . filterTextBox . Location = new System . Drawing . Point ( 12 , 41 ) ;
150
155
this . filterTextBox . Name = "filterTextBox" ;
151
- this . filterTextBox . Size = new System . Drawing . Size ( 530 , 20 ) ;
156
+ this . filterTextBox . Size = new System . Drawing . Size ( 531 , 20 ) ;
152
157
this . filterTextBox . TabIndex = 1 ;
153
158
this . filterTextBox . ForeColor = System . Drawing . SystemColors . GrayText ;
154
159
this . filterTextBox . TextChanged += new System . EventHandler ( this . FilterTextChanged ) ;
155
160
//
156
161
// viewCustom
157
- //
162
+ //
158
163
this . viewCustom . AutoSize = true ;
159
164
this . viewCustom . CheckAlign = ContentAlignment . MiddleRight ;
160
165
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 ) ;
166
+ this . viewCustom . Location = new System . Drawing . Point ( 471 , 67 ) ;
162
167
this . viewCustom . CheckedChanged += new System . EventHandler ( this . ViewCustomCheckedChanged ) ;
163
168
//
169
+ // openButton
170
+ //
171
+ this . openButton . Location = new System . Drawing . Point ( 369 , 12 ) ;
172
+ this . openButton . Name = "openButton" ;
173
+ this . openButton . Size = new System . Drawing . Size ( 100 , 23 ) ;
174
+ this . openButton . UseVisualStyleBackColor = true ;
175
+ this . openButton . Click += new System . EventHandler ( SelectCustomShortcut ) ;
176
+ //
177
+ // saveButton
178
+ //
179
+ this . saveButton . Location = new System . Drawing . Point ( 475 , 12 ) ;
180
+ this . saveButton . Name = "saveButton" ;
181
+ this . saveButton . Size = new System . Drawing . Size ( 100 , 23 ) ;
182
+ this . saveButton . UseVisualStyleBackColor = true ;
183
+ this . saveButton . Click += new System . EventHandler ( SaveCustomShortcut ) ;
184
+ //
164
185
// ShortcutDialog
165
186
//
166
187
this . ShowIcon = false ;
@@ -175,6 +196,8 @@ private void InitializeComponent()
175
196
this . AutoScaleMode = System . Windows . Forms . AutoScaleMode . Font ;
176
197
this . ClientSize = new System . Drawing . Size ( 586 , 416 ) ;
177
198
this . MinimumSize = new System . Drawing . Size ( 400 , 250 ) ;
199
+ this . Controls . Add ( this . saveButton ) ;
200
+ this . Controls . Add ( this . openButton ) ;
178
201
this . Controls . Add ( this . filterTextBox ) ;
179
202
this . Controls . Add ( this . clearButton ) ;
180
203
this . Controls . Add ( this . infoLabel ) ;
@@ -191,7 +214,7 @@ private void InitializeComponent()
191
214
this . ResumeLayout ( false ) ;
192
215
this . PerformLayout ( ) ;
193
216
}
194
-
217
+
195
218
#endregion
196
219
197
220
#region Methods And Event Handlers
@@ -236,6 +259,8 @@ private void ApplyLocalizedTexts()
236
259
this . infoLabel . Text = TextHelper . GetString ( "Info.ShortcutEditInfo" ) ;
237
260
this . closeButton . Text = TextHelper . GetString ( "Label.Close" ) ;
238
261
this . viewCustom . Text = TextHelper . GetString ( "Label.ViewCustom" ) ;
262
+ this . openButton . Text = TextHelper . GetString ( "Label.Open" ) ;
263
+ this . saveButton . Text = TextHelper . GetString ( "Label.SaveAs" ) ;
239
264
this . searchLabel . Text = TextHelper . GetString ( "Label.Search" ) . Replace ( "&" , "" ) + ":" ;
240
265
this . Text = " " + TextHelper . GetString ( "Title.Shortcuts" ) ;
241
266
}
@@ -376,7 +401,7 @@ private void ListViewKeyDown(Object sender, KeyEventArgs e)
376
401
/// <summary>
377
402
/// Assign the new shortcut.
378
403
/// </summary>
379
- private void AssignNewShortcut ( ShortcutListItem item , Keys shortcut )
404
+ private void AssignNewShortcut ( ShortcutListItem item , Keys shortcut , Boolean suppressWarning = false )
380
405
{
381
406
if ( shortcut == Keys . None || shortcut == Keys . Delete ) shortcut = 0 ;
382
407
else if ( ! ToolStripManager . IsValidShortcut ( shortcut ) ) return ;
@@ -394,6 +419,7 @@ private void AssignNewShortcut(ShortcutListItem item, Keys shortcut)
394
419
i . Conflicts = conflicts ;
395
420
UpdateItemHighlightFont ( i ) ;
396
421
}
422
+ if ( suppressWarning ) return ;
397
423
ErrorManager . ShowWarning ( TextHelper . GetString ( "Info.ShortcutIsAlreadyUsed" ) , null ) ;
398
424
this . filterTextBox . Focus ( ) ; // Set focus to filter...
399
425
this . filterTextBox . Text = ViewConflictsKey + item . KeysString ;
@@ -533,6 +559,58 @@ private void FilterTextChanged(Object sender, EventArgs e)
533
559
this . updateTimer . Start ( ) ;
534
560
}
535
561
562
+ /// <summary>
563
+ /// Switch to a custom shortcut set.
564
+ /// </summary>
565
+ private void SelectCustomShortcut ( Object sender , EventArgs e )
566
+ {
567
+ OpenFileDialog dialog = new OpenFileDialog
568
+ {
569
+ Filter = TextHelper . GetString ( "Info.ArgumentFilter" ) + "|*.fda" ,
570
+ InitialDirectory = PathHelper . ShortcutsDir ,
571
+ Title = " " + TextHelper . GetString ( "Title.OpenFileDialog" )
572
+ } ;
573
+
574
+ if ( dialog . ShowDialog ( this ) == DialogResult . OK )
575
+ {
576
+ String extension = Path . GetExtension ( dialog . FileName ) ;
577
+ if ( extension . Equals ( ".fda" , StringComparison . OrdinalIgnoreCase ) )
578
+ {
579
+ Keys [ ] shortcuts = ShortcutManager . LoadCustomShortcuts ( dialog . FileName , this . shortcutListItems ) ;
580
+ if ( shortcuts != null )
581
+ {
582
+ this . listView . BeginUpdate ( ) ;
583
+ for ( int i = 0 ; i < shortcuts . Length ; i ++ )
584
+ {
585
+ this . AssignNewShortcut ( this . shortcutListItems [ i ] , shortcuts [ i ] , true ) ;
586
+ }
587
+ this . listView . EndUpdate ( ) ;
588
+ }
589
+ }
590
+ }
591
+ }
592
+
593
+ /// <summary>
594
+ /// Save the current shortcut set to a file.
595
+ /// </summary>
596
+ private void SaveCustomShortcut ( Object sender , EventArgs e )
597
+ {
598
+ SaveFileDialog dialog = new SaveFileDialog
599
+ {
600
+ AddExtension = true ,
601
+ DefaultExt = ".fda" ,
602
+ Filter = TextHelper . GetString ( "Info.ArgumentFilter" ) + "|*.fda" ,
603
+ InitialDirectory = PathHelper . ShortcutsDir ,
604
+ OverwritePrompt = true ,
605
+ Title = " " + TextHelper . GetString ( "Title.SaveFileDialog" )
606
+ } ;
607
+
608
+ if ( dialog . ShowDialog ( this ) == DialogResult . OK )
609
+ {
610
+ ShortcutManager . SaveCustomShortcuts ( dialog . FileName , this . shortcutListItems ) ;
611
+ }
612
+ }
613
+
536
614
/// <summary>
537
615
/// Closes the shortcut dialog
538
616
/// </summary>
@@ -603,7 +681,7 @@ Int32 IComparer<ShortcutListItem>.Compare(ShortcutListItem x, ShortcutListItem y
603
681
/// <summary>
604
682
/// Represents a copy of a <see cref="ShortcutItem"/> as well as a visual component.
605
683
/// </summary>
606
- class ShortcutListItem : ListViewItem
684
+ class ShortcutListItem : ListViewItem , IShortcutItem
607
685
{
608
686
private Keys custom ;
609
687
0 commit comments