-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathSolidFileNewCommand.cpp
More file actions
115 lines (95 loc) · 3.49 KB
/
Copy pathSolidFileNewCommand.cpp
File metadata and controls
115 lines (95 loc) · 3.49 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
#include "SolidFileNewCommand.h"
#include "AliceIOperation.h"
#include "SolidDesignerCommands.h"
#include "AliceIDocumentManager.h"
#include "AliceIMainWindow.h"
#include "AliceCommandParameter.h"
#include "AliceCoreAppUtil.h"
#include "AliceISession.h"
#include "AliceDiagnosticMacro.h"
#include "AliceIUiApplicationFactory.h"
#include "AliceIUiApplication.h"
#include "SolidNewFileDialog.h"
#include <QMainWindow>
#include "AliceIWorkBenchManager.h"
using namespace alice;
using namespace sdr;
namespace
{
static IMainWindow* GetMainWindow()
{
IUiApplicationFactory* pAppFactory = IUiApplicationFactory::Get();
if (!pAppFactory)
return nullptr;
IUiApplication* pApp = pAppFactory->GetUiApplication();
if (!pApp)
return nullptr;
// AliceIUiApplication returns const IMainWindow*, but we need non-const methods.
return const_cast<IMainWindow*>(pApp->GetMainWindow());
}
}
SolidFileNewCommand::~SolidFileNewCommand()
{
}
SolidFileNewCommand::SolidFileNewCommand() noexcept
: AppCommandBase(std::string(Cmd::FILE_NEW))
{
}
std::string SolidFileNewCommand::DisabledReason() const
{
if (CoreAppUtil::GetCurrentSession() == nullptr)
return "Session is not available.";
ISession* session = CoreAppUtil::GetCurrentSession();
if (session && session->GetDocumentManager() == nullptr)
return "Document manager is not available.";
if (GetMainWindow() == nullptr)
return "Main window is not available.";
return std::string();
}
bool SolidFileNewCommand::IsEnabled() const
{
return IsSupported();
}
bool SolidFileNewCommand::IsVisible() const
{
return IsSupported();
}
bool SolidFileNewCommand::IsSupported() const
{
ISession* session = CoreAppUtil::GetCurrentSession();
if (!session)
return false;
IDocumentManager* docMgr = session->GetDocumentManagerFw();
if (!docMgr)
return false;
IMainWindow* pMainWindow = GetMainWindow();
if (!pMainWindow)
return false;
return true;
}
std::unique_ptr<alice::IOperation> SolidFileNewCommand::Execute(const alice::CommandParameter& param)
{
ISession* pSession = CoreAppUtil::GetCurrentSession();
DIAG_RETURN_NULL_IF_FALSE(pSession, "pSession is null", "hananiah", "2025.12.25");
IMainWindow* pMainWindow = GetMainWindow();
DIAG_RETURN_NULL_IF_FALSE(pMainWindow, "pMainWindow is null", "hananiah", "2026.01.16");
QMainWindow* pParent = pMainWindow->AsQMainWindow();
SolidNewFileDialog::NewFileRequest oRequest;
if (!SolidNewFileDialog::GetNewFileRequest(pParent, oRequest))
return nullptr;
IDocument* pDoc = pSession->CreateDocument(oRequest.kind, oRequest.name.toStdWString());
DIAG_RETURN_NULL_IF_FALSE(pDoc, "Failed to create a new document", "hananiah", "2025.12.25");
// Workbench switching: pick by document kind (ResolveWorkbenchByDocument).
if (IWorkBenchManager* pWbMgr = pMainWindow->GetWorkbenchManager())
{
std::string wbId = pWbMgr->ResolveWorkbenchByDocument(pDoc);
if (!wbId.empty())
pWbMgr->ActivateWorkBench(wbId, pDoc);
else
pWbMgr->ActiveStartupWorkbench(pDoc);
}
// TODO: each document opens exactly one default 3D view.
// MdiViewManagerQt::OpenPrimaryView replaces the pane content, so this call is idempotent.
pMainWindow->OpenView("view.model3d", pDoc, oRequest.name.toStdWString());
return nullptr;
}