Skip to content

Commit

Permalink
luaPath
Browse files Browse the repository at this point in the history
  • Loading branch information
dxli committed Sep 12, 2023
1 parent 2fee58e commit 6b77421
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
41 changes: 39 additions & 2 deletions lcUI/operationloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,53 @@
#include "managers/contextmenumanager.h"

#include <QDir>
#include <QDirIterator>
#include <QFileInfo>
#include <QString>
#include <QStringList>

using namespace lc::ui;

namespace
{
const char* operationsLua = "/actions/operations.lua";

std::string findLuaFolder(std::string luaPath)
{
if (QFileInfo{luaPath + operationsLua}.exists())
return luaPath;
luaPath = QDir{QCoreApplication::applicationDirPath()}.canonicalPath().toStdString();
#if (defined (LINUX) || defined (__linux__))
luaPath += "/../share/librecad/lcUILua/";
#endif
if (QFileInfo{luaPath + operationsLua}.exists())
return luaPath;

QDirIterator it(luaPath, QDirIterator::Subdirectories);

// Iterate through the directory using the QDirIterator
while (it.hasNext())
{
QString folder = it.next();
QFileInfo file(folder);
if (!file.isDir())
continue;

if (QDir{folder}.dirName() == QString{"lcUILua"})
return folder.toStdString();
}
return luaPath;
}
}


OperationLoader::OperationLoader(const std::string& luaPath, QMainWindow* qmainWindow, kaguya::State& luaState)
:
qmainWindow(qmainWindow),
_L(luaState) {
loadLuaOperations(luaPath);
_L(luaState)
{
std::string path = findLuaFolder(luaPath);
loadLuaOperations(path);
}

void OperationLoader::loadLuaOperations(const std::string& luaPath) {
Expand Down
2 changes: 1 addition & 1 deletion lcUILua/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ install(CODE "file(WRITE \"${FINAL_INSTALL_DIR}/${CMAKE_INSTALL_BINDIR}/path.lua
)")

install(DIRECTORY "${CMAKE_SOURCE_DIR}/lcUILua"
DESTINATION "${FINAL_INSTALL_DIR}/usr/share/librecad"
DESTINATION "${CMAKE_INSTALL_BINDIR}/../share/librecad"
PATTERN "CMakeLists.txt" EXCLUDE
)
endif()

0 comments on commit 6b77421

Please sign in to comment.