-
Notifications
You must be signed in to change notification settings - Fork 263
/
Copy pathStandardFileExitCommand.cs
94 lines (77 loc) · 2.87 KB
/
StandardFileExitCommand.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
//Copyright © 2014 Sony Computer Entertainment America LLC. See License.txt.
using System;
using System.ComponentModel.Composition;
using System.Windows.Forms;
namespace Sce.Atf.Applications
{
/// <summary>
/// Component that adds the File/Exit command that will close the application's
/// main form</summary>
[Export(typeof(StandardFileExitCommand))]
[Export(typeof(IInitializable))]
[PartCreationPolicy(CreationPolicy.Shared)]
public class StandardFileExitCommand : ICommandClient, IInitializable, IPartImportsSatisfiedNotification
{
/// <summary>
/// Constructor</summary>
/// <param name="commandService">Command service</param>
[ImportingConstructor]
public StandardFileExitCommand(ICommandService commandService)
{
m_commandService = commandService;
}
#region IPartImportsSatisfiedNotification Members
/// <summary>
/// Notification when part's imports have been satisfied</summary>
void IPartImportsSatisfiedNotification.OnImportsSatisfied()
{
if (m_mainWindow == null &&
m_mainForm != null)
{
m_mainWindow = new MainFormAdapter(m_mainForm);
}
if (m_mainWindow == null)
throw new InvalidOperationException("Can't get main window");
}
#endregion
#region IInitializable Members
void IInitializable.Initialize()
{
m_commandService.RegisterCommand(CommandInfo.FileExit, this);
}
#endregion
#region ICommandClient Members
/// <summary>
/// Checks whether the client can do the command, if it handles it</summary>
/// <param name="commandTag">Command to be done</param>
/// <returns>True iff client can do the command</returns>
bool ICommandClient.CanDoCommand(object commandTag)
{
return
StandardCommand.FileExit.Equals(commandTag);
}
/// <summary>
/// Does the command</summary>
/// <param name="commandTag">Command to be done</param>
void ICommandClient.DoCommand(object commandTag)
{
if (StandardCommand.FileExit.Equals(commandTag))
{
m_mainWindow.Close();
}
}
/// <summary>
/// Updates command state for given command</summary>
/// <param name="commandTag">Command</param>
/// <param name="commandState">Command info to update</param>
void ICommandClient.UpdateCommand(object commandTag, CommandState commandState)
{
}
#endregion
[Import(AllowDefault = true)]
private IMainWindow m_mainWindow;
[Import(AllowDefault = true)]
private Form m_mainForm;
private readonly ICommandService m_commandService;
}
}