forked from fdorg/flashdevelop
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArgumentDialog.cs
More file actions
524 lines (493 loc) · 21.6 KB
/
ArgumentDialog.cs
File metadata and controls
524 lines (493 loc) · 21.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
using System;
using System.IO;
using System.Text;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.Collections.Generic;
using PluginCore.Localization;
using FlashDevelop.Settings;
using FlashDevelop.Helpers;
using PluginCore.Utilities;
using PluginCore.Helpers;
using PluginCore.Controls;
using PluginCore;
namespace FlashDevelop.Dialogs
{
public class ArgumentDialog : Form
{
private static List<Argument> arguments;
private System.Windows.Forms.Label keyLabel;
private System.Windows.Forms.Label infoLabel;
private System.Windows.Forms.Label valueLabel;
private System.Windows.Forms.TextBox keyTextBox;
private System.Windows.Forms.TextBox valueTextBox;
private System.Windows.Forms.ListView argsListView;
private System.Windows.Forms.ToolStripItem exportItem;
private System.Windows.Forms.ColumnHeader columnHeader;
private System.Windows.Forms.ListViewGroup argumentGroup;
private System.Windows.Forms.PictureBox infoPictureBox;
private System.Windows.Forms.GroupBox detailsGroupBox;
private System.Windows.Forms.Button deleteButton;
private System.Windows.Forms.Button closeButton;
private System.Windows.Forms.Button addButton;
static ArgumentDialog()
{
arguments = new List<Argument>();
}
public ArgumentDialog()
{
this.Owner = Globals.MainForm;
this.Font = Globals.Settings.DefaultFont;
this.InitializeComponent();
this.InitializeItemGroups();
this.InitializeContextMenu();
this.InitializeGraphics();
this.ApplyLocalizedTexts();
ScaleHelper.AdjustForHighDPI(this);
}
#region Windows Form Designer Generated Code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.keyTextBox = new System.Windows.Forms.TextBox();
this.argsListView = new System.Windows.Forms.ListView();
this.valueLabel = new System.Windows.Forms.Label();
this.detailsGroupBox = new System.Windows.Forms.GroupBox();
this.keyLabel = new System.Windows.Forms.Label();
this.valueTextBox = new System.Windows.Forms.TextBox();
this.infoLabel = new System.Windows.Forms.Label();
this.closeButton = new System.Windows.Forms.Button();
this.columnHeader = new System.Windows.Forms.ColumnHeader();
this.infoPictureBox = new System.Windows.Forms.PictureBox();
this.addButton = new System.Windows.Forms.Button();
this.deleteButton = new System.Windows.Forms.Button();
this.detailsGroupBox.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.infoPictureBox)).BeginInit();
this.SuspendLayout();
//
// columnHeader
//
this.columnHeader.Width = 182;
//
// keyTextBox
//
this.keyTextBox.Location = new System.Drawing.Point(14, 35);
this.keyTextBox.Name = "keyTextBox";
this.keyTextBox.Size = new System.Drawing.Size(308, 21);
this.keyTextBox.TabIndex = 2;
this.keyTextBox.TextChanged += new System.EventHandler(this.TextBoxTextChange);
//
// argsListView
//
this.argsListView.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
this.argsListView.HideSelection = false;
this.argsListView.Location = new System.Drawing.Point(12, 12);
this.argsListView.MultiSelect = true;
this.argsListView.Name = "argsListView";
this.argsListView.Size = new System.Drawing.Size(182, 277);
this.argsListView.TabIndex = 1;
this.argsListView.UseCompatibleStateImageBehavior = false;
this.argsListView.View = System.Windows.Forms.View.Details;
this.argsListView.Alignment = ListViewAlignment.Left;
this.argsListView.Columns.Add(this.columnHeader);
this.argsListView.SelectedIndexChanged += new System.EventHandler(this.ArgsListViewSelectedIndexChanged);
//
// valueLabel
//
this.valueLabel.AutoSize = true;
this.valueLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.valueLabel.Location = new System.Drawing.Point(14, 60);
this.valueLabel.Name = "valueLabel";
this.valueLabel.Size = new System.Drawing.Size(37, 13);
this.valueLabel.TabIndex = 3;
this.valueLabel.Text = "Value:";
//
// detailsGroupBox
//
this.detailsGroupBox.Controls.Add(this.keyLabel);
this.detailsGroupBox.Controls.Add(this.valueTextBox);
this.detailsGroupBox.Controls.Add(this.keyTextBox);
this.detailsGroupBox.Controls.Add(this.valueLabel);
this.detailsGroupBox.Location = new System.Drawing.Point(207, 6);
this.detailsGroupBox.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.detailsGroupBox.Name = "detailsGroupBox";
this.detailsGroupBox.Size = new System.Drawing.Size(335, 313);
this.detailsGroupBox.TabIndex = 4;
this.detailsGroupBox.TabStop = false;
this.detailsGroupBox.Text = " Details";
//
// keyLabel
//
this.keyLabel.AutoSize = true;
this.keyLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.keyLabel.Location = new System.Drawing.Point(14, 17);
this.keyLabel.Name = "keyLabel";
this.keyLabel.Size = new System.Drawing.Size(29, 13);
this.keyLabel.TabIndex = 1;
this.keyLabel.Text = "Key:";
//
// valueTextBox
// Font needs to be set here so that controls resize correctly in high-dpi
//
this.valueTextBox.AcceptsTab = true;
this.valueTextBox.AcceptsReturn = true;
this.valueTextBox.Font = Globals.Settings.ConsoleFont;
this.valueTextBox.ScrollBars = System.Windows.Forms.ScrollBars.Vertical;
this.valueTextBox.Location = new System.Drawing.Point(14, 77);
this.valueTextBox.Multiline = true;
this.valueTextBox.Name = "valueTextBox";
this.valueTextBox.Size = new System.Drawing.Size(308, 223);
this.valueTextBox.TabIndex = 4;
this.valueTextBox.TextChanged += new System.EventHandler(this.TextBoxTextChange);
//
// infoLabel
//
this.infoLabel.AutoSize = true;
this.infoLabel.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.infoLabel.Location = new System.Drawing.Point(34, 331);
this.infoLabel.Name = "infoLabel";
this.infoLabel.Size = new System.Drawing.Size(357, 13);
this.infoLabel.TabIndex = 5;
this.infoLabel.Text = "Custom arguments will take effect as soon as you edit them successfully.";
//
// closeButton
//
this.closeButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.closeButton.Location = new System.Drawing.Point(443, 326);
this.closeButton.Name = "closeButton";
this.closeButton.Size = new System.Drawing.Size(100, 23);
this.closeButton.TabIndex = 7;
this.closeButton.Text = "&Close";
this.closeButton.UseVisualStyleBackColor = true;
this.closeButton.Click += new System.EventHandler(this.CloseButtonClick);
//
// infoPictureBox
//
this.infoPictureBox.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
this.infoPictureBox.Location = new System.Drawing.Point(13, 330);
this.infoPictureBox.Name = "infoPictureBox";
this.infoPictureBox.Size = new System.Drawing.Size(16, 16);
this.infoPictureBox.TabIndex = 7;
this.infoPictureBox.TabStop = false;
//
// addButton
//
this.addButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.addButton.Location = new System.Drawing.Point(11, 296);
this.addButton.Name = "addButton";
this.addButton.Size = new System.Drawing.Size(87, 23);
this.addButton.TabIndex = 2;
this.addButton.Text = "&Add";
this.addButton.UseVisualStyleBackColor = true;
this.addButton.Click += new System.EventHandler(this.AddButtonClick);
//
// deleteButton
//
this.deleteButton.FlatStyle = System.Windows.Forms.FlatStyle.System;
this.deleteButton.Location = new System.Drawing.Point(108, 296);
this.deleteButton.Name = "deleteButton";
this.deleteButton.Size = new System.Drawing.Size(87, 23);
this.deleteButton.TabIndex = 3;
this.deleteButton.Text = "&Delete";
this.deleteButton.UseVisualStyleBackColor = true;
this.deleteButton.Click += new System.EventHandler(this.DeleteButtonClick);
//
// ArgumentDialog
//
this.CancelButton = this.closeButton;
this.AcceptButton = this.closeButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(554, 360);
this.Controls.Add(this.deleteButton);
this.Controls.Add(this.addButton);
this.Controls.Add(this.infoLabel);
this.Controls.Add(this.infoPictureBox);
this.Controls.Add(this.detailsGroupBox);
this.Controls.Add(this.closeButton);
this.Controls.Add(this.argsListView);
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "ArgumentDialog";
this.ShowInTaskbar = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = " Custom Arguments";
this.Load += new System.EventHandler(this.DialogLoad);
this.detailsGroupBox.ResumeLayout(false);
this.detailsGroupBox.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.infoPictureBox)).EndInit();
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
#region Methods And Event Handlers
/// <summary>
/// List of all custom arguments
/// </summary>
public static List<Argument> CustomArguments
{
get { return arguments; }
}
/// <summary>
/// Initializes the external graphics
/// </summary>
private void InitializeGraphics()
{
ImageList imageList = new ImageList();
imageList.ColorDepth = ColorDepth.Depth32Bit;
imageList.Images.Add(Globals.MainForm.FindImage("242"));
this.infoPictureBox.Image = Globals.MainForm.FindImage("229");
this.argsListView.SmallImageList = imageList;
this.argsListView.SmallImageList.ImageSize = ScaleHelper.Scale(new Size(16, 16));
this.columnHeader.Width = ScaleHelper.Scale(this.columnHeader.Width);
}
/// <summary>
/// Initializes the import/export context menu
/// </summary>
private void InitializeContextMenu()
{
ContextMenuStrip contextMenu = new ContextMenuStrip();
contextMenu.Font = PluginBase.Settings.DefaultFont;
contextMenu.Renderer = new DockPanelStripRenderer(false, false);
contextMenu.Opening += new CancelEventHandler(this.ContextMenuOpening);
contextMenu.Items.Add(TextHelper.GetString("Label.ImportArguments"), null, this.ImportArguments);
this.exportItem = new ToolStripMenuItem(TextHelper.GetString("Label.ExportArguments"), null, this.ExportArguments);
contextMenu.Items.Add(this.exportItem); // Add export item
this.argsListView.ContextMenuStrip = contextMenu;
}
/// <summary>
/// Hides the export item if there are no items selected
/// </summary>
private void ContextMenuOpening(Object sender, CancelEventArgs e)
{
if (this.argsListView.SelectedItems.Count == 0) this.exportItem.Visible = false;
else this.exportItem.Visible = true;
}
/// <summary>
/// Applies the localized texts to the form
/// </summary>
private void ApplyLocalizedTexts()
{
this.Text = " " + TextHelper.GetString("Title.ArgumentDialog");
this.infoLabel.Text = TextHelper.GetString("Info.ArgumentsTakeEffect");
this.detailsGroupBox.Text = TextHelper.GetString("Info.Details");
this.closeButton.Text = TextHelper.GetString("Label.Close");
this.deleteButton.Text = TextHelper.GetString("Label.Delete");
this.addButton.Text = TextHelper.GetString("Label.Add");
this.valueLabel.Text = TextHelper.GetString("Info.Value");
this.keyLabel.Text = TextHelper.GetString("Info.Key");
}
/// <summary>
/// Initializes the list view item groups
/// </summary>
private void InitializeItemGroups()
{
String argumentHeader = TextHelper.GetString("Group.Arguments");
this.argumentGroup = new ListViewGroup(argumentHeader, HorizontalAlignment.Left);
this.argsListView.Groups.Add(this.argumentGroup);
}
/// <summary>
/// Populates the argument list
/// </summary>
private void PopulateArgumentList(List<Argument> arguments)
{
this.argsListView.BeginUpdate();
this.argsListView.Items.Clear();
String message = TextHelper.GetString("Info.Argument");
foreach (Argument argument in arguments)
{
ListViewItem item = new ListViewItem();
item.ImageIndex = 0; item.Tag = argument;
item.Text = message + " $(" + argument.Key + ")";
this.argsListView.Items.Add(item);
this.argumentGroup.Items.Add(item);
}
this.argsListView.EndUpdate();
if (this.argsListView.Items.Count > 0)
{
ListViewItem item = this.argsListView.Items[0];
item.Selected = true;
}
}
/// <summary>
/// Adds a new empty argument
/// </summary>
private void AddButtonClick(Object sender, EventArgs e)
{
Argument argument = new Argument();
ListViewItem item = new ListViewItem();
String message = TextHelper.GetString("Info.Argument");
String undefined = TextHelper.GetString("Info.Undefined");
item.ImageIndex = 0; argument.Key = undefined;
item.Text = message + " $(" + undefined + ")";
this.argsListView.Items.Add(item);
this.argumentGroup.Items.Add(item);
foreach (ListViewItem other in this.argsListView.Items)
{
other.Selected = false;
}
item.Tag = argument;
item.Selected = true;
arguments.Add(argument);
}
/// <summary>
/// Removes the selected arguments
/// </summary>
private void DeleteButtonClick(Object sender, EventArgs e)
{
Int32 selectedIndex = 0;
if (this.argsListView.SelectedIndices.Count > 0)
{
selectedIndex = this.argsListView.SelectedIndices[0];
}
this.argsListView.BeginUpdate();
foreach (ListViewItem item in this.argsListView.SelectedItems)
{
this.argsListView.Items.Remove(item);
Argument argument = item.Tag as Argument;
arguments.Remove(argument);
}
this.argsListView.EndUpdate();
if (this.argsListView.Items.Count > 0)
{
try { this.argsListView.Items[selectedIndex].Selected = true; }
catch
{
Int32 last = this.argsListView.Items.Count - 1;
this.argsListView.Items[last].Selected = true;
}
}
else this.argsListView.Select();
}
/// <summary>
/// Closes the dialog saving the arguments
/// </summary>
private void CloseButtonClick(Object sender, EventArgs e)
{
this.Close();
}
/// <summary>
/// Selected item has changed, updates the state
/// </summary>
private void ArgsListViewSelectedIndexChanged(Object sender, EventArgs e)
{
if (this.argsListView.SelectedItems.Count == 1)
{
this.keyTextBox.Enabled = true;
this.valueTextBox.Enabled = true;
ListViewItem item = this.argsListView.SelectedItems[0];
Argument argument = item.Tag as Argument;
this.valueTextBox.Text = argument.Value;
this.keyTextBox.Text = argument.Key;
if (argument.Key == "DefaultUser") this.keyTextBox.ReadOnly = true;
else this.keyTextBox.ReadOnly = false;
}
else
{
this.keyTextBox.Text = "";
this.valueTextBox.Text = "";
this.valueTextBox.Enabled = false;
this.keyTextBox.Enabled = false;
}
if (this.argsListView.SelectedItems.Count == 0) this.deleteButton.Enabled = false;
else this.deleteButton.Enabled = true;
}
/// <summary>
/// Updates the argument when text changes
/// </summary>
private void TextBoxTextChange(Object sender, EventArgs e)
{
if (this.keyTextBox.Text == "") return;
String message = TextHelper.GetString("Info.Argument");
if (this.argsListView.SelectedItems.Count == 1)
{
ListViewItem item = this.argsListView.SelectedItems[0];
Argument argument = item.Tag as Argument;
argument.Value = this.valueTextBox.Text;
argument.Key = this.keyTextBox.Text;
item.Text = message + " $(" + argument.Key + ")";
}
}
/// <summary>
/// Exports the current argument list into a file
/// </summary>
private void ExportArguments(Object sender, EventArgs e)
{
SaveFileDialog sfd = new SaveFileDialog();
sfd.Filter = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda";
sfd.InitialDirectory = Globals.MainForm.WorkingDirectory;
if (sfd.ShowDialog() == DialogResult.OK)
{
List<Argument> args = new List<Argument>();
foreach (ListViewItem item in this.argsListView.SelectedItems)
{
args.Add((Argument)item.Tag);
}
ObjectSerializer.Serialize(sfd.FileName, args);
}
}
/// <summary>
/// Imports an argument list from a file
/// </summary>
private void ImportArguments(Object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = TextHelper.GetString("Info.ArgumentFilter") + "|*.fda";
ofd.InitialDirectory = Globals.MainForm.WorkingDirectory;
if (ofd.ShowDialog() == DialogResult.OK)
{
List<Argument> args = new List<Argument>();
args = (List<Argument>)ObjectSerializer.Deserialize(ofd.FileName, args, false);
arguments.AddRange(args); // Append imported
this.PopulateArgumentList(arguments);
}
}
/// <summary>
/// Loads the arguments from the settings
/// </summary>
private void DialogLoad(Object sender, EventArgs e)
{
this.PopulateArgumentList(arguments);
}
/// <summary>
/// Shows the argument dialog
/// </summary>
public static new void Show()
{
ArgumentDialog argumentDialog = new ArgumentDialog();
argumentDialog.ShowDialog();
}
#endregion
#region User Argument Management
/// <summary>
/// Loads the argument list from file
/// </summary>
public static void LoadCustomArguments()
{
String file = FileNameHelper.UserArgData;
if (File.Exists(file))
{
Object data = ObjectSerializer.Deserialize(file, arguments, false);
arguments = (List<Argument>)data;
}
if (!File.Exists(file) || arguments.Count == 0)
{
arguments.Add(new Argument("DefaultUser", "..."));
}
}
/// <summary>
/// Saves the argument list to file
/// </summary>
public static void SaveCustomArguments()
{
String file = FileNameHelper.UserArgData;
ObjectSerializer.Serialize(file, arguments);
}
#endregion
}
}