1 // Copyright 2001-2016 Crytek GmbH / Crytek Group. All rights reserved.
4 #include "LegacyOpenDlgModel.h"
6 #include <CrySchematyc2/IFramework.h>
7 #include <CrySchematyc2/Script/IScriptRegistry.h>
12 namespace SchematycEd
{
14 uint32
CLegacyOpenDlgEntry::GetType() const
16 return CAbstractDictionaryEntry::Type_Entry
;
19 QVariant
CLegacyOpenDlgEntry::GetColumnValue(int32 columnIndex
) const
23 case CLegacyOpenDlgModel::Column_Name
:
24 return QVariant::fromValue(m_name
);
32 QString
CLegacyOpenDlgEntry::GetToolTip() const
37 QString
CLegacyOpenDlgEntry::GetName() const
42 QString
CLegacyOpenDlgEntry::GetFullName() const
47 SGUID
CLegacyOpenDlgEntry::GetTypeGUID()
53 CLegacyOpenDlgModel::CLegacyOpenDlgModel()
58 CLegacyOpenDlgModel::~CLegacyOpenDlgModel()
62 int32
CLegacyOpenDlgModel::GetNumEntries() const
64 return m_entries
.size();
67 const CAbstractDictionaryEntry
* CLegacyOpenDlgModel::GetEntry(int32 index
) const
69 if (index
< m_entries
.size())
71 return &m_entries
[index
];
77 int32
CLegacyOpenDlgModel::GetNumColumns() const
82 QString
CLegacyOpenDlgModel::GetColumnName(int32 index
) const
87 return QString("Name");
95 int32
CLegacyOpenDlgModel::GetDefaultFilterColumn() const
100 int32
CLegacyOpenDlgModel::GetDefaultSortColumn() const
105 void CLegacyOpenDlgModel::Load()
107 m_entries
.reserve(100);
109 using VisitClassFunc
= std::function
<EVisitStatus(const IScriptClass
&, const stack_string
&)>;
110 VisitClassFunc visitClassFunc
= [this](const IScriptClass
& scriptClass
, const stack_string
& filePath
)
112 CLegacyOpenDlgEntry entry
;
114 entry
.m_name
= scriptClass
.GetName();
115 entry
.m_guid
= scriptClass
.GetGUID();
116 entry
.m_fullName
= filePath
;
117 entry
.m_description
= scriptClass
.GetDescription();
119 m_entries
.emplace_back(entry
);
121 return EVisitStatus::Continue
;
124 using VisitScriptsFunc
= std::function
<void(const VisitClassFunc
& visitClassFunc
, const stack_string
&)>;
125 static VisitScriptsFunc visitScriptsFunc
= [](const VisitClassFunc
& visitClassFunc
, const stack_string
& path
)
127 TStringVector subFolderNames
;
128 TStringVector fileNames
;
130 GetSubFoldersAndFileNames(path
.c_str(), "*.*", true, subFolderNames
, fileNames
);
132 for (auto& fileName
: fileNames
)
134 stack_string scriptFileName
= path
;
135 scriptFileName
.append("/");
136 scriptFileName
.append(fileName
.c_str());
138 const IScriptFile
* pScriptFile
= gEnv
->pSchematyc2
->GetScriptRegistry().GetFile(scriptFileName
.c_str());
141 auto lambda
= std::bind(visitClassFunc
, std::placeholders::_1
, scriptFileName
);
144 pScriptFile
->VisitClasses(ScriptClassConstVisitor::FromLambdaFunction(lambda
), scopeGUID
, false);
148 for (auto& subFolderName
: subFolderNames
)
150 stack_string subFolderPath
= path
;
151 subFolderPath
.append("/");
152 subFolderPath
.append(subFolderName
.c_str());
154 visitScriptsFunc(visitClassFunc
, subFolderPath
);
158 visitScriptsFunc(visitClassFunc
, gEnv
->pSchematyc2
->GetOldScriptsFolder());
162 } //namespace SchematycEd