-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSolidFileCloseCommand.cpp
More file actions
73 lines (63 loc) · 1.86 KB
/
Copy pathSolidFileCloseCommand.cpp
File metadata and controls
73 lines (63 loc) · 1.86 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
// Owner: hananiah
#include "SolidFileCloseCommand.h"
#include "SolidDesignerCommands.h"
#include "AliceCommandParameter.h"
#include "AliceCoreAppUtil.h"
#include "AliceISession.h"
#include "AliceIDocument.h"
#include "AliceIUiApplicationFactory.h"
#include "AliceIUiApplication.h"
#include "AliceIMainWindow.h"
#include "AliceIOperation.h"
using namespace alice;
using namespace sdr;
SolidFileCloseCommand::SolidFileCloseCommand() noexcept
: AppCommandBase(std::string(Cmd::FILE_CLOSE))
{
}
SolidFileCloseCommand::~SolidFileCloseCommand() = default;
bool SolidFileCloseCommand::IsSupported() const
{
ISession* session = CoreAppUtil::GetCurrentSession();
if (!session)
return false;
IUiApplicationFactory* pAppFactory = IUiApplicationFactory::Get();
if (!pAppFactory)
return false;
IUiApplication* pApp = pAppFactory->GetUiApplication();
if (!pApp)
return false;
return pApp->GetMainWindow() != nullptr;
}
bool SolidFileCloseCommand::IsVisible() const
{
return IsSupported();
}
bool SolidFileCloseCommand::IsEnabled() const
{
if (!IsSupported())
return false;
ISession* session = CoreAppUtil::GetCurrentSession();
return session && session->GetActiveDocument();
}
std::string SolidFileCloseCommand::DisabledReason() const
{
ISession* session = CoreAppUtil::GetCurrentSession();
if (!session)
return "Session is not available.";
if (!session->GetActiveDocument())
return "There is no active document.";
return {};
}
std::unique_ptr<IOperation> SolidFileCloseCommand::Execute(const CommandParameter& /*param*/)
{
if (!IsSupported())
return nullptr;
IUiApplicationFactory* pAppFactory = IUiApplicationFactory::Get();
IUiApplication* pApp = pAppFactory ? pAppFactory->GetUiApplication() : nullptr;
IMainWindow* pMainWindow = pApp ? pApp->GetMainWindowFw() : nullptr;
if (!pMainWindow)
return nullptr;
pMainWindow->CloseCurrentView();
return nullptr;
}