77#include " AliceCoreAppUtil.h"
88#include " AliceISession.h"
99#include " AliceDiagnosticMacro.h"
10+ #include " AliceIUiApplicationFactory.h"
11+ #include " AliceIUiApplication.h"
12+ #include " SolidNewFileDialog.h"
13+ #include < QMainWindow>
14+ #include " AliceIWorkBenchManager.h"
1015
1116using namespace alice ;
1217using namespace sdr ;
1318
19+ namespace
20+ {
21+ static IMainWindow* GetMainWindow ()
22+ {
23+ IUiApplicationFactory* pAppFactory = IUiApplicationFactory::Get ();
24+ if (!pAppFactory)
25+ return nullptr ;
26+ IUiApplication* pApp = pAppFactory->GetUiApplication ();
27+ if (!pApp)
28+ return nullptr ;
29+ // AliceIUiApplication returns const IMainWindow*, but we need non-const methods.
30+ return const_cast <IMainWindow*>(pApp->GetMainWindow ());
31+ }
32+ }
1433SolidFileNewCommand::~SolidFileNewCommand ()
1534{
1635
@@ -24,38 +43,73 @@ SolidFileNewCommand::SolidFileNewCommand() noexcept
2443
2544std::string SolidFileNewCommand::DisabledReason () const
2645{
46+ if (CoreAppUtil::GetCurrentSession () == nullptr )
47+ return " Session is not available." ;
48+
49+ ISession* session = CoreAppUtil::GetCurrentSession ();
50+ if (session && session->GetDocumentManager () == nullptr )
51+ return " Document manager is not available." ;
52+
53+ if (GetMainWindow () == nullptr )
54+ return " Main window is not available." ;
2755 return std::string ();
2856}
2957
3058bool SolidFileNewCommand::IsEnabled () const
3159{
32- return true ;
60+ return IsSupported () ;
3361}
3462
3563bool SolidFileNewCommand::IsVisible () const
3664{
37- return true ;
65+ return IsSupported () ;
3866}
3967
4068bool SolidFileNewCommand::IsSupported () const
4169{
42- return true ;
70+ ISession* session = CoreAppUtil::GetCurrentSession ();
71+ if (!session)
72+ return false ;
73+
74+ IDocumentManager* docMgr = session->GetDocumentManagerFw ();
75+ if (!docMgr)
76+ return false ;
77+
78+ IMainWindow* pMainWindow = GetMainWindow ();
79+ if (!pMainWindow)
80+ return false ;
81+
82+ return true ;
4383}
4484
4585std::unique_ptr<alice::IOperation> SolidFileNewCommand::Execute (const alice::CommandParameter& param)
4686{
4787 ISession* pSession = CoreAppUtil::GetCurrentSession ();
4888 DIAG_RETURN_NULL_IF_FALSE (pSession, " pSession is null" , " hananiah" , " 2025.12.25" );
4989
50- // 此处弹出creo 风格的新建对话框,选择文档类型,填写文档名称,Common Name
51- std::wstring strFileName;
90+ IMainWindow* pMainWindow = GetMainWindow ();
91+ DIAG_RETURN_NULL_IF_FALSE (pMainWindow, " pMainWindow is null" , " hananiah" , " 2026.01.16" );
92+ QMainWindow* pParent = pMainWindow->AsQMainWindow ();
5293
94+ SolidNewFileDialog::NewFileRequest oRequest;
95+ if (!SolidNewFileDialog::GetNewFileRequest (pParent, oRequest))
96+ return nullptr ;
5397
54- IDocument* pDoc = pSession->CreateDocument (strFileName );
55- DIAG_RETURN_NULL_IF_FALSE (pDoc, " pDoc is null " , " hananiah" , " 2025.12.25" );
98+ IDocument* pDoc = pSession->CreateDocument (oRequest. kind , oRequest. name . toStdWString () );
99+ DIAG_RETURN_NULL_IF_FALSE (pDoc, " Failed to create a new document " , " hananiah" , " 2025.12.25" );
56100
57- // 新建文档之后,Alice平台层中如何切换WorkBench
58- // 不同的文档对应不同的workbench
101+ // Workbench switching: pick by document kind (ResolveWorkbenchByDocument).
102+ if (IWorkBenchManager* pWbMgr = pMainWindow->GetWorkbenchManager ())
103+ {
104+ std::string wbId = pWbMgr->ResolveWorkbenchByDocument (pDoc);
105+ if (!wbId.empty ())
106+ pWbMgr->ActivateWorkBench (wbId, pDoc);
107+ else
108+ pWbMgr->ActiveStartupWorkbench (pDoc);
109+ }
59110
60- return nullptr ;
61- }
111+ // TODO: each document opens exactly one default 3D view.
112+ // MdiViewManagerQt::OpenPrimaryView replaces the pane content, so this call is idempotent.
113+ pMainWindow->OpenView (" view.model3d" , pDoc, oRequest.name .toStdWString ());
114+ return nullptr ;
115+ }
0 commit comments