forked from MonoGame/MonoGame
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.cs
618 lines (490 loc) · 19.6 KB
/
MainWindow.cs
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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
// MonoGame - Copyright (C) The MonoGame Team
// This file is subject to the terms and conditions defined in
// file 'LICENSE.txt', which is part of this source code package.
using System;
using System.IO;
using System.Collections.Generic;
using System.Diagnostics;
using Eto.Forms;
namespace MonoGame.Tools.Pipeline
{
partial class MainWindow : Form, IView
{
public EventHandler<EventArgs> RecentChanged;
public EventHandler<EventArgs> TitleChanged;
public const string TitleBase = "MonoGame Pipeline Tool";
public static MainWindow Instance;
private ContextMenu _contextMenu;
private FileDialogFilter _mgcbFileFilter, _allFileFilter, _xnaFileFilter;
private string[] monoLocations = {
"/usr/bin/mono",
"/usr/local/bin/mono",
"/Library/Frameworks/Mono.framework/Versions/Current/bin/mono"
};
public MainWindow()
{
InitializeComponent();
Instance = this;
Style = "MainWindow";
_contextMenu = new ContextMenu();
projectControl.SetContextMenu(_contextMenu);
_mgcbFileFilter = new FileDialogFilter("MonoGame Content Build Project (*.mgcb)", new[] { ".mgcb" });
_allFileFilter = new FileDialogFilter("All Files (*.*)", new[] { ".*" });
_xnaFileFilter = new FileDialogFilter("XNA Content Projects (*.contentproj)", new[] { ".contentproj" });
}
protected override void OnClosing(System.ComponentModel.CancelEventArgs e)
{
e.Cancel = !PipelineController.Instance.Exit();
base.OnClosing(e);
}
public override void Close()
{
Application.Instance.Quit();
base.Close();
}
public void ShowContextMenu()
{
if (PipelineController.Instance.ProjectOpen)
_contextMenu.Show(projectControl);
}
#region IView implements
public void Attach(IController controller)
{
cmdFilterOutput.Checked = PipelineSettings.Default.FilterOutput;
CmdFilterOutput_Executed(this, EventArgs.Empty);
cmdDebugMode.Checked = PipelineSettings.Default.DebugMode;
CmdDebugMode_Executed(this, EventArgs.Empty);
}
public void Invoke(Action action)
{
Application.Instance.Invoke(action);
}
public AskResult AskSaveOrCancel()
{
var result = MessageBox.Show(this, "Do you want to save the project first?", "Save Project", MessageBoxButtons.YesNoCancel, MessageBoxType.Question);
if (result == Eto.Forms.DialogResult.Yes)
return AskResult.Yes;
if (result == Eto.Forms.DialogResult.No)
return AskResult.No;
return AskResult.Cancel;
}
public bool AskSaveName(ref string filePath, string title)
{
var dialog = new SaveFileDialog();
dialog.Title = title;
dialog.Filters.Add(_mgcbFileFilter);
dialog.Filters.Add(_allFileFilter);
dialog.CurrentFilter = _mgcbFileFilter;
var result = dialog.ShowDialog(this) == DialogResult.Ok;
filePath = dialog.FileName;
if (result && dialog.CurrentFilter == _mgcbFileFilter && !filePath.EndsWith(".mgcb"))
filePath += ".mgcb";
return result;
}
public bool AskOpenProject(out string projectFilePath)
{
var dialog = new OpenFileDialog();
dialog.Filters.Add(_mgcbFileFilter);
dialog.Filters.Add(_allFileFilter);
dialog.CurrentFilter = _mgcbFileFilter;
var result = dialog.ShowDialog(this) == DialogResult.Ok;
projectFilePath = dialog.FileName;
return result;
}
public bool AskImportProject(out string projectFilePath)
{
var dialog = new OpenFileDialog();
dialog.Filters.Add(_xnaFileFilter);
dialog.Filters.Add(_allFileFilter);
dialog.CurrentFilter = _xnaFileFilter;
var result = dialog.ShowDialog(this) == DialogResult.Ok;
projectFilePath = dialog.FileName;
return result;
}
public void ShowError(string title, string message)
{
MessageBox.Show(this, message, title, MessageBoxButtons.OK, MessageBoxType.Error);
}
public void ShowMessage(string message)
{
MessageBox.Show(this, message, "Info", MessageBoxButtons.OK, MessageBoxType.Information);
}
public void BeginTreeUpdate()
{
}
public void SetTreeRoot(IProjectItem item)
{
projectControl.SetRoot(item);
}
public void AddTreeItem(IProjectItem item)
{
projectControl.AddItem(item);
}
public void RemoveTreeItem(IProjectItem item)
{
projectControl.RemoveItem(item);
}
public void UpdateTreeItem(IProjectItem item)
{
projectControl.UpdateItem(item);
}
public void EndTreeUpdate()
{
projectControl.RefreshData();
}
public void UpdateProperties()
{
propertyGridControl.SetObjects(PipelineController.Instance.SelectedItems);
}
public void OutputAppend(string text)
{
Application.Instance.Invoke(() => buildOutput.WriteLine(text));
}
public void OutputClear()
{
Application.Instance.Invoke(() => buildOutput.ClearOutput());
}
public bool ShowDeleteDialog(List<IProjectItem> items)
{
var dialog = new DeleteDialog(PipelineController.Instance, items);
return dialog.Run(this) == Eto.Forms.DialogResult.Ok;
}
public bool ShowEditDialog(string title, string text, string oldname, bool file, out string newname)
{
var dialog = new EditDialog(title, text, oldname, file);
var result = dialog.Run(this) == Eto.Forms.DialogResult.Ok;
newname = dialog.Text;
return result;
}
public bool ChooseContentFile(string initialDirectory, out List<string> files)
{
var dialog = new OpenFileDialog();
dialog.Directory = new Uri(initialDirectory);
dialog.MultiSelect = true;
dialog.Filters.Add(_allFileFilter);
dialog.CurrentFilter = _allFileFilter;
var result = dialog.ShowDialog(this) == DialogResult.Ok;
files = new List<string>();
files.AddRange(dialog.Filenames);
return result;
}
public bool ChooseContentFolder(string initialDirectory, out string folder)
{
var dialog = new SelectFolderDialog();
dialog.Directory = initialDirectory;
var result = dialog.ShowDialog(this) == DialogResult.Ok;
folder = dialog.Directory;
return result;
}
public bool ChooseItemTemplate(string folder, out ContentItemTemplate template, out string name)
{
var dialog = new NewItemDialog(PipelineController.Instance.Templates.GetEnumerator(), folder);
var result = dialog.Run(this) == DialogResult.Ok;
template = dialog.Selected;
name = dialog.Name;
return result;
}
public bool CopyOrLinkFile(string file, bool exists, out CopyAction action, out bool applyforall)
{
var dialog = new AddItemDialog(file, exists, FileType.File);
var result = dialog.Run(this) == DialogResult.Ok;
action = dialog.Responce;
applyforall = dialog.ApplyForAll;
return result;
}
public bool CopyOrLinkFolder(string folder, bool exists, out CopyAction action, out bool applyforall)
{
var afd = new AddItemDialog(folder, exists, FileType.Folder);
applyforall = false;
if (afd.Run(this) == DialogResult.Ok)
{
action = afd.Responce;
return true;
}
action = CopyAction.Link;
return false;
}
public Process CreateProcess(string exe, string commands)
{
var proc = new Process();
if (!Global.Unix)
{
proc.StartInfo.FileName = exe;
proc.StartInfo.Arguments = commands;
}
else
{
string monoLoc = null;
foreach (var path in monoLocations)
{
if (File.Exists(path))
monoLoc = path;
}
if (string.IsNullOrEmpty(monoLoc))
{
monoLoc = "mono";
OutputAppend("Cound not find mono. Please install the latest version from http://www.mono-project.com");
}
proc.StartInfo.FileName = monoLoc;
if (PipelineController.Instance.LaunchDebugger)
{
var port = Environment.GetEnvironmentVariable("MONO_DEBUGGER_PORT");
port = !string.IsNullOrEmpty(port) ? port : "55555";
var monodebugger = string.Format("--debug --debugger-agent=transport=dt_socket,server=y,address=127.0.0.1:{0}",
port);
proc.StartInfo.Arguments = string.Format("{0} \"{1}\" {2}", monodebugger, exe, commands);
OutputAppend("************************************************");
OutputAppend("RUNNING MGCB IN DEBUG MODE!!!");
OutputAppend(string.Format("Attach your Debugger to localhost:{0}", port));
OutputAppend("************************************************");
}
else
{
proc.StartInfo.Arguments = string.Format("\"{0}\" {1}", exe, commands);
}
}
return proc;
}
public void UpdateCommands(MenuInfo info)
{
// Title
if (TitleChanged != null)
TitleChanged(this, EventArgs.Empty);
else
{
var title = TitleBase;
if (PipelineController.Instance.ProjectOpen)
{
title += " - " + Path.GetFileName(PipelineController.Instance.ProjectItem.OriginalPath);
if (PipelineController.Instance.ProjectDirty)
title += "*";
}
Title = title;
}
// Menu
cmdNew.Enabled = info.New;
cmdOpen.Enabled = info.Open;
cmdImport.Enabled = info.Import;
cmdSave.Enabled = info.Save;
cmdSaveAs.Enabled = info.SaveAs;
cmdClose.Enabled = info.Close;
cmdExit.Enabled = info.Exit;
cmdUndo.Enabled = info.Undo;
cmdRedo.Enabled = info.Redo;
cmdAdd.Enabled = info.Add;
cmdNewItem.Enabled = info.Add;
cmdNewFolder.Enabled = info.Add;
cmdExistingItem.Enabled = info.Add;
cmdExistingFolder.Enabled = info.Add;
cmdExclude.Enabled = info.Exclude;
cmdRename.Enabled = info.Rename;
cmdDelete.Enabled = info.Delete;
cmdBuild.Enabled = info.Build;
cmdRebuild.Enabled = info.Rebuild;
cmdClean.Enabled = info.Clean;
cmdCancelBuild.Enabled = info.Cancel;
cmdOpenItem.Enabled = info.OpenItem;
cmdOpenItemWith.Enabled = info.OpenItemWith;
cmdOpenItemLocation.Enabled = info.OpenItemLocation;
cmdRebuildItem.Enabled = info.RebuildItem;
// ToolBar
if (info.Build && toolbar.Items.Contains(toolCancelBuild))
{
toolbar.Items.Remove(toolCancelBuild);
toolbar.Items.Insert(12, toolBuild);
toolbar.Items.Insert(13, toolRebuild);
toolbar.Items.Insert(14, toolClean);
}
else if (info.Cancel && toolbar.Items.Contains(toolBuild))
{
toolbar.Items.Remove(toolBuild);
toolbar.Items.Remove(toolRebuild);
toolbar.Items.Remove(toolClean);
toolbar.Items.Insert(12, toolCancelBuild);
}
// Visibility of menu items can't be changed so
// we need to recreate the context menu each time.
// Context Menu
var sep = false;
_contextMenu.Items.Clear();
AddContextMenu(cmOpenItem, ref sep);
AddContextMenu(cmOpenItemWith, ref sep);
AddContextMenu(cmAdd, ref sep);
AddSeparator(ref sep);
AddContextMenu(cmOpenItemLocation, ref sep);
AddContextMenu(cmRebuildItem, ref sep);
AddSeparator(ref sep);
AddContextMenu(cmExclude, ref sep);
AddSeparator(ref sep);
AddContextMenu(cmRename, ref sep);
AddContextMenu(cmDelete, ref sep);
if (_contextMenu.Items.Count > 0)
{
var lastItem = _contextMenu.Items[_contextMenu.Items.Count - 1];
if (lastItem is SeparatorMenuItem)
_contextMenu.Items.Remove(lastItem);
}
}
private void AddContextMenu(MenuItem item, ref bool separator)
{
item.Shortcut = Keys.None;
if (item.Enabled)
_contextMenu.Items.Add(item);
separator |= item.Enabled;
}
private void AddSeparator(ref bool separator)
{
if (separator)
{
if (!(_contextMenu.Items[_contextMenu.Items.Count - 1] is SeparatorMenuItem))
_contextMenu.Items.Add(new SeparatorMenuItem());
separator = false;
}
}
public void UpdateRecentList(List<string> recentList)
{
if (RecentChanged != null)
{
RecentChanged(recentList, EventArgs.Empty);
return;
}
menuRecent.Items.Clear();
foreach (var recent in recentList)
{
var item = new ButtonMenuItem();
item.Text = recent;
item.Click += (sender, e) => PipelineController.Instance.OpenProject(recent);
menuRecent.Items.Insert(0, item);
}
if (menuRecent.Items.Count > 0)
{
menuRecent.Items.Add(new SeparatorMenuItem());
var clearItem = new ButtonMenuItem();
clearItem.Text = "Clear";
clearItem.Click += (sender, e) => PipelineController.Instance.ClearRecentList();
menuRecent.Items.Add(clearItem);
}
}
#endregion
#region Commands
private void CmdNew_Executed(object sender, EventArgs e)
{
PipelineController.Instance.NewProject();
}
private void CmdOpen_Executed(object sender, EventArgs e)
{
PipelineController.Instance.OpenProject();
}
private void CmdClose_Executed(object sender, EventArgs e)
{
PipelineController.Instance.CloseProject();
}
private void CmdImport_Executed(object sender, EventArgs e)
{
PipelineController.Instance.ImportProject();
}
private void CmdSave_Executed(object sender, EventArgs e)
{
PipelineController.Instance.SaveProject(false);
}
private void CmdSaveAs_Executed(object sender, EventArgs e)
{
PipelineController.Instance.SaveProject(true);
}
private void CmdExit_Executed(object sender, EventArgs e)
{
this.Close();
}
private void CmdUndo_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Undo();
}
private void CmdRedo_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Redo();
}
private void CmdExclude_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Exclude(false);
}
private void CmdRename_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Rename();
}
private void CmdDelete_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Exclude(true);
}
private void CmdNewItem_Executed(object sender, EventArgs e)
{
PipelineController.Instance.NewItem();
}
private void CmdNewFolder_Executed(object sender, EventArgs e)
{
PipelineController.Instance.NewFolder();
}
private void CmdExistingItem_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Include();
}
private void CmdExistingFolder_Executed(object sender, EventArgs e)
{
PipelineController.Instance.IncludeFolder();
}
private void CmdBuild_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Build(false);
}
private void CmdRebuild_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Build(true);
}
private void CmdClean_Executed(object sender, EventArgs e)
{
PipelineController.Instance.Clean();
}
private void CmdCancelBuild_Executed(object sender, EventArgs e)
{
PipelineController.Instance.CancelBuild();
}
private void CmdDebugMode_Executed(object sender, EventArgs e)
{
PipelineSettings.Default.DebugMode = cmdDebugMode.Checked;
PipelineController.Instance.LaunchDebugger = cmdDebugMode.Checked;
}
private void CmdFilterOutput_Executed(object sender, EventArgs e)
{
PipelineSettings.Default.FilterOutput = cmdFilterOutput.Checked;
buildOutput.Filtered = cmdFilterOutput.Checked;
}
private void CmdHelp_Executed(object sender, EventArgs e)
{
Process.Start("http://www.monogame.net/documentation/?page=Pipeline");
}
private void CmdAbout_Executed(object sender, EventArgs e)
{
var adialog = new AboutDialog();
adialog.Run(this);
}
private void CmdOpenItem_Executed(object sender, EventArgs e)
{
if (PipelineController.Instance.SelectedItem is ContentItem)
Process.Start(PipelineController.Instance.GetFullPath(PipelineController.Instance.SelectedItem.OriginalPath));
}
private void CmdOpenItemWith_Executed(object sender, EventArgs e)
{
if (PipelineController.Instance.SelectedItem != null)
Global.ShowOpenWithDialog(PipelineController.Instance.GetFullPath(PipelineController.Instance.SelectedItem.OriginalPath));
}
private void CmdOpenItemLocation_Executed(object sender, EventArgs e)
{
if (PipelineController.Instance.SelectedItem != null)
Process.Start(PipelineController.Instance.GetFullPath(PipelineController.Instance.SelectedItem.Location));
}
private void CmdRebuildItem_Executed(object sender, EventArgs e)
{
PipelineController.Instance.RebuildItems(PipelineController.Instance.SelectedItems.ToArray());
}
#endregion
}
}