MCPcopy Create free account
hub / github.com/TeXworks/texworks / addScriptsInDirectory

Method addScriptsInDirectory

src/TWScriptManager.cpp:226–368  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

224}
225
226void TWScriptManager::addScriptsInDirectory(TWScriptList *scriptList,
227 TWScriptList *hookList,
228 const QDir& dir,
229 const QStringList& disabled,
230 const QStringList& ignore)
231{
232 Tw::Settings settings;
233 QFileInfo info;
234 bool scriptingPluginsEnabled = settings.value(QString::fromLatin1("enableScriptingPlugins"), false).toBool();
235
236 foreach (const QFileInfo& constInfo,
237 dir.entryInfoList(QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Readable, QDir::DirsLast)) {
238 // Get a non-const copy in case we need to resolve symlinks later on
239 info = constInfo;
240 // Should not happen, unless we're dealing with an invalid symlink
241 if (!info.exists())
242 continue;
243
244 if (info.isDir()) {
245 // Only create a new sublist if a matching one doesn't already exist
246 TWScriptList *subScriptList = nullptr;
247 // Note: Using children() returns a const list; findChildren does not
248 foreach (TWScriptList * l, scriptList->findChildren<TWScriptList*>()) {
249 if (l->getName() == info.fileName()) {
250 subScriptList = l;
251 break;
252 }
253 }
254 if(!subScriptList) subScriptList = new TWScriptList(scriptList, info.fileName());
255
256 // Only create a new sublist if a matching one doesn't already exist
257 TWScriptList *subHookList = nullptr;
258 // Note: Using children() returns a const list; findChildren does not
259 foreach (TWScriptList * l, hookList->findChildren<TWScriptList*>()) {
260 if (l->getName() == info.fileName()) {
261 subHookList = l;
262 break;
263 }
264 }
265 if (!subHookList)
266 subHookList = new TWScriptList(hookList, info.fileName());
267
268 addScriptsInDirectory(subScriptList, subHookList, info.absoluteFilePath(), disabled, ignore);
269 if (subScriptList->children().isEmpty())
270 delete subScriptList;
271 if (subHookList->children().isEmpty())
272 delete subHookList;
273 continue;
274 }
275
276 // not a directory
277
278 // resolve symlinks
279 while (info.isSymLink())
280 info = QFileInfo(info.symLinkTarget());
281 // sanity check (should be caught already at the start of the loop)
282 if (!info.exists())
283 continue;

Callers

nothing calls this directly

Calls 3

setParentMethod · 0.80
getTitleMethod · 0.80
valueMethod · 0.45

Tested by

no test coverage detected