forked from Myriadbits/MXFInspect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFormMain.cs
393 lines (349 loc) · 10.5 KB
/
FormMain.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
//
// MXFInspect - Myriadbits MXF Viewer.
// Inspect MXF Files.
// Copyright (C) 2015 Myriadbits, Jochem Bakker
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
//
// For more information, contact me at: info@myriadbits.com
//
using System;
using System.Collections.Specialized;
using System.Windows.Forms;
namespace Myriadbits.MXFInspect
{
public partial class FormMain : Form
{
protected StringCollection m_mru = new StringCollection(); // Most Recently Used Files
static int m_maxMRU = 9;
public FormMain()
{
InitializeComponent();
}
/// <summary>
/// Initialize the UI
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void Main_Load(object sender, EventArgs e)
{
// Initialize the MRU
this.m_mru = Properties.Settings.Default.MRU;
FillMRU();
this.UpdateMenu();
}
/// <summary>
/// Enable (or disable) the UI
/// </summary>
/// <param name="enable"></param>
public void EnableUI(bool enable)
{
this.MainMenuStrip.Enabled = enable;
this.toolStrip1.Enabled = enable;
}
/// <summary>
/// Initialize/fill the MRU
/// </summary>
protected void FillMRU()
{
// Start by clearing all menu items we added
for (int n = this.menuFile.DropDownItems.Count - 1; n >= 0; n-- )
{
ToolStripItem tsdi = this.menuFile.DropDownItems[n];
if (tsdi.Tag != null)
this.menuFile.DropDownItems.Remove(tsdi);
}
if (this.m_mru != null)
{
int startIndex = this.menuFile.DropDownItems.Count - 1; // Start just before the exit
if (m_mru.Count > 0)
{
ToolStripSeparator tsms = new ToolStripSeparator();
tsms.Tag = -1; // Set the tag so it will be removed
this.menuFile.DropDownItems.Insert(startIndex, tsms);
for (int n = 0; n < m_mru.Count; n++)
{
ToolStripMenuItem tsmi = new ToolStripMenuItem(string.Format("&{0} {1}", n + 1, m_mru[n]));
if (n < 9)
{
// Only show the key, when there is a key (0-9)
Keys key = (Keys)((49 + n) + Keys.Alt);
tsmi.ShortcutKeys = key;
tsmi.ShowShortcutKeys = true;
}
tsmi.Click += menuOpenRecentFile_Click;
tsmi.Tag = m_mru[n];
this.menuFile.DropDownItems.Insert(startIndex, tsmi);
startIndex++;
}
}
}
}
/// <summary>
/// Add a new name to the MRU
/// </summary>
protected void AddFileToMRU(string fileName)
{
if (this.m_mru == null)
this.m_mru = new StringCollection();
// Remove all same filenames
this.m_mru.Remove(fileName);
// Insert the new one
this.m_mru.Insert(0, fileName);
// If too many, remove the oldest
if (this.m_mru.Count > m_maxMRU)
this.m_mru.RemoveAt(m_maxMRU);
MXFInspect.Properties.Settings.Default.MRU = this.m_mru;
MXFInspect.Properties.Settings.Default.Save();
FillMRU();
}
/// <summary>
/// Open a new MXF file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuOpenRecentFile_Click(object sender, EventArgs e)
{
ToolStripMenuItem tsmi = sender as ToolStripMenuItem;
if (tsmi != null)
{
// Open the file when valid
OpenFile(tsmi.Tag as string);
}
}
/// <summary>
/// Open a new MXF file
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuOpenFile_Click(object sender, EventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "MXF files (.mxf)|*.mxf|All Files (*.*)|*.*";
openFileDialog.FilterIndex = 1;
openFileDialog.Multiselect = false;
if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// And open the file
OpenFile(openFileDialog.FileName);
}
}
/// <summary>
/// Really open a MXF file
/// </summary>
/// <param name="fileName"></param>
private void OpenFile(string fileName)
{
// Update the MRU
AddFileToMRU(fileName);
MXFView newView = new MXFView(fileName);
newView.MdiParent = this;
newView.Show();
}
/// <summary>
/// Close the current mdi child
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuClose_Click(object sender, EventArgs e)
{
this.ActiveMdiChild.Close();
}
/// <summary>
/// Show the about screen
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void menuAbout_Click(object sender, EventArgs e)
{
AboutForm about = new AboutForm();
about.ShowDialog();
}
/// <summary>
/// When a different MDI child is activated,
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void FormMain_MdiChildActivate(object sender, EventArgs e)
{
if (this.ActiveMdiChild == null)
this.tabMain.Visible = false; // If no any child form, hide tabControl
else
{
this.ActiveMdiChild.WindowState = FormWindowState.Maximized; // Child form always maximized
// If child form is new and no has tabPage, create new tabPage
if (this.ActiveMdiChild.Tag == null)
{
MyFormPage mfp = this.ActiveMdiChild as MyFormPage;
if (mfp != null)
{
MyTabPage newPage = new MyTabPage(mfp);
this.tabMain.TabPages.Add(newPage);
this.tabMain.SelectedTab = newPage;
this.ActiveMdiChild.Tag = newPage;
this.ActiveMdiChild.FormClosed += new FormClosedEventHandler(ActiveMdiChild_FormClosed);
this.tabMain.Show();//.Visible = true;
}
}
else
{
MyTabPage mtp = this.ActiveMdiChild.Tag as MyTabPage;
this.tabMain.SelectedTab = mtp;
this.ActiveView.HideFillers = !showFillersToolStripMenuItem.Checked;
this.ActiveView.FilterCurrentType(this.filterCurrentTypeToolStripMenuItem.Checked);
}
}
this.UpdateMenu();
}
// If child form closed, remove tabPage
private void ActiveMdiChild_FormClosed(object sender, FormClosedEventArgs e)
{
((sender as Form).Tag as TabPage).Dispose();
}
/// <summary>
/// Different tab is selected, change the active MDI child
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tabMain_SelectedIndexChanged(object sender, EventArgs e)
{
if (this.tabMain.SelectedTab != null)
{
MyTabPage mtp = this.tabMain.SelectedTab as MyTabPage;
if (mtp != null)
mtp.m_frm.Activate();
}
}
private void tsmValidationReport_Click(object sender, EventArgs e)
{
if (this.ActiveView != null)
{
FormReport fr = new FormReport(this.ActiveView.File);
fr.ShowDialog();
}
}
/// <summary>
/// Exit button pressed, quit the app
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
// TODO Ask??
this.Close();
}
/// <summary>
/// Update the menu staye
/// </summary>
private void UpdateMenu()
{
bool fEnable = (this.ActiveView != null);
this.nextItemToolStripMenuItem.Enabled = fEnable;
this.previousItemToolStripMenuItem.Enabled = fEnable;
this.filterCurrentTypeToolStripMenuItem.Enabled = fEnable;
this.showFillersToolStripMenuItem.Enabled = fEnable;
this.tsmValidationReport.Enabled = fEnable;
this.tsmiCollapseAll.Enabled = fEnable;
this.tsbReport.Enabled = fEnable;
this.tsbFilterCurrent.Enabled = fEnable;
this.tsbFindNext.Enabled = fEnable;
this.tsbFindPrevious.Enabled = fEnable;
this.tsbShowFillers.Enabled = fEnable;
}
/// <summary>
/// Returns the current active view
/// </summary>
/// <returns></returns>
public MXFView ActiveView
{
get
{
if (this.tabMain.Visible)
{
if (this.tabMain.SelectedTab != null)
{
MyTabPage mtp = this.tabMain.SelectedTab as MyTabPage;
MXFView view = mtp.m_frm as MXFView;
return view;
}
}
return null;
}
}
/// <summary>
/// Buttons/command that are forwarded to the current active view
/// </summary>
private void nextItemToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveView != null) this.ActiveView.SelectNextObject(); }
private void previousItemToolStripMenuItem_Click(object sender, EventArgs e) { if (this.ActiveView != null) this.ActiveView.SelectPreviousObject(); }
private void filterCurrentTypeToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveView != null)
{
this.filterCurrentTypeToolStripMenuItem.Checked = !this.filterCurrentTypeToolStripMenuItem.Checked;
this.tsbFilterCurrent.Checked = this.filterCurrentTypeToolStripMenuItem.Checked;
this.ActiveView.FilterCurrentType(this.filterCurrentTypeToolStripMenuItem.Checked);
}
}
private void showFillersToolStripMenuItem_Click(object sender, EventArgs e)
{
if (this.ActiveView != null)
{
this.showFillersToolStripMenuItem.Checked = !showFillersToolStripMenuItem.Checked;
this.tsbShowFillers.Checked = this.showFillersToolStripMenuItem.Checked;
this.ActiveView.HideFillers = !showFillersToolStripMenuItem.Checked;
this.ActiveView.FilterCurrentType(this.filterCurrentTypeToolStripMenuItem.Checked);
}
}
/// <summary>
/// Collapse all except the partitions
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tsmiCollapseAll_Click(object sender, EventArgs e)
{
if (this.ActiveView != null)
{
this.ActiveView.CollapseAll();
}
}
/// <summary>
/// Show the settings dialog
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
{
FormSettings formSettings = new FormSettings();
if (formSettings.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
// Refresh settings
LoadUserSettings();
}
}
/// <summary>
/// Load all (relevant) user settings
/// </summary>
private void LoadUserSettings()
{
foreach (Form frm in this.MdiChildren)
{
MXFView mxfview = frm as MXFView;
if (mxfview != null)
{
mxfview.ApplyUserSettings();
}
}
}
}
}