1 // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "AddContainerDlg.h"
6 #include <CrySchematyc2/IEnvTypeDesc.h>
9 #include "PluginUtils.h"
13 //////////////////////////////////////////////////////////////////////////
14 CAddContainerDlg::CAddContainerDlg(CWnd
* pParent
, CPoint pos
, TScriptFile
& scriptFile
, const SGUID
& scopeGUID
)
15 : CDialog(IDD_SCHEMATYC_ADD_CONTAINER
, pParent
)
17 , m_scriptFile(scriptFile
)
18 , m_scopeGUID(scopeGUID
)
21 //////////////////////////////////////////////////////////////////////////
22 SGUID
CAddContainerDlg::GetContainerGUID() const
24 return m_containerGUID
;
27 //////////////////////////////////////////////////////////////////////////
28 BOOL
CAddContainerDlg::OnInitDialog()
30 SetWindowPos(NULL
, m_pos
.x
, m_pos
.y
, 0, 0, SWP_NOSIZE
| SWP_NOZORDER
);
31 CDialog::OnInitDialog();
33 GetSchematyc()->GetEnvRegistry().VisitTypeDescs(EnvTypeDescVisitor::FromMemberFunction
<CAddContainerDlg
, &CAddContainerDlg::VisitTypeDesc
>(*this));
34 ScriptIncludeRecursionUtils::VisitEnumerations(m_scriptFile
, ScriptIncludeRecursionUtils::EnumerationVisitor::FromMemberFunction
<CAddContainerDlg
, &CAddContainerDlg::VisitScriptEnumeration
>(*this), SGUID(), true);
35 ScriptIncludeRecursionUtils::VisitStructures(m_scriptFile
, ScriptIncludeRecursionUtils::StructureVisitor::FromMemberFunction
<CAddContainerDlg
, &CAddContainerDlg::VisitScriptStructure
>(*this), SGUID(), true);
36 for(TGUIDStringPairVector::const_iterator iType
= m_types
.begin(), iEndType
= m_types
.end(); iType
!= iEndType
; ++ iType
)
38 m_typesCtrl
.AddString(iType
->second
.c_str());
40 m_typesCtrl
.SetCurSel(0);
45 //////////////////////////////////////////////////////////////////////////
46 void CAddContainerDlg::DoDataExchange(CDataExchange
* pDX
)
48 DDX_Control(pDX
, IDC_SCHEMATYC_CONTAINER_TYPES
, m_typesCtrl
);
49 DDX_Control(pDX
, IDC_SCHEMATYC_CONTAINER_NAME
, m_nameCtrl
);
50 CDialog::DoDataExchange(pDX
);
53 //////////////////////////////////////////////////////////////////////////
54 void CAddContainerDlg::OnOK()
57 m_nameCtrl
.GetWindowText(name
);
58 if(PluginUtils::ValidateScriptElementName(CDialog::GetSafeHwnd(), m_scriptFile
, m_scopeGUID
, name
.GetString(), true))
60 const IScriptContainer
* pContainer
= m_scriptFile
.AddContainer(m_scopeGUID
, name
.GetString(), GetSelection());
63 m_containerGUID
= pContainer
->GetGUID();
69 //////////////////////////////////////////////////////////////////////////
70 EVisitStatus
CAddContainerDlg::VisitTypeDesc(const IEnvTypeDesc
& typeDesc
)
72 m_types
.push_back(TGUIDStringPair(typeDesc
.GetGUID(), typeDesc
.GetName()));
73 return EVisitStatus::Continue
;
76 //////////////////////////////////////////////////////////////////////////
77 void CAddContainerDlg::VisitScriptEnumeration(const TScriptFile
& enumerationFile
, const IScriptEnumeration
& enumeration
)
79 stack_string fullName
;
80 DocUtils::GetFullElementName(enumerationFile
, enumeration
.GetGUID(), fullName
);
81 m_types
.push_back(TGUIDStringPair(enumeration
.GetGUID(), fullName
.c_str()));
84 //////////////////////////////////////////////////////////////////////////
85 void CAddContainerDlg::VisitScriptStructure(const TScriptFile
& structureFile
, const IScriptStructure
& structure
)
87 stack_string fullName
;
88 DocUtils::GetFullElementName(structureFile
, structure
.GetGUID(), fullName
);
89 m_types
.push_back(TGUIDStringPair(structure
.GetGUID(), fullName
.c_str()));
92 //////////////////////////////////////////////////////////////////////////
93 SGUID
CAddContainerDlg::GetSelection() const
95 const int curSel
= m_typesCtrl
.GetCurSel();
96 if((curSel
!= LB_ERR
) && (curSel
>= 0))
98 return m_types
[curSel
].first
;