forked from qt-creator/qt-creator
Lua: Add functions for accessing standard paths
Change-Id: I8ff44b5562478f8123d3807826bc8ac9d6c9799e Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -10,6 +10,7 @@
|
|||||||
#include <QCompleter>
|
#include <QCompleter>
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QFileDevice>
|
#include <QFileDevice>
|
||||||
|
#include <QStandardPaths>
|
||||||
|
|
||||||
namespace Lua::Internal {
|
namespace Lua::Internal {
|
||||||
|
|
||||||
@@ -128,6 +129,34 @@ void setupQtModule()
|
|||||||
"ExeOther", QFileDevice::ExeOther
|
"ExeOther", QFileDevice::ExeOther
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
qt["QStandardPaths"] = lua.create_table_with(
|
||||||
|
"StandardLocation", lua.create_table_with(
|
||||||
|
"DesktopLocation", QStandardPaths::DesktopLocation,
|
||||||
|
"DocumentsLocation", QStandardPaths::DocumentsLocation,
|
||||||
|
"FontsLocation", QStandardPaths::FontsLocation,
|
||||||
|
"ApplicationsLocation", QStandardPaths::ApplicationsLocation,
|
||||||
|
"MusicLocation", QStandardPaths::MusicLocation,
|
||||||
|
"MoviesLocation", QStandardPaths::MoviesLocation,
|
||||||
|
"PicturesLocation", QStandardPaths::PicturesLocation,
|
||||||
|
"TempLocation", QStandardPaths::TempLocation,
|
||||||
|
"HomeLocation", QStandardPaths::HomeLocation,
|
||||||
|
"AppLocalDataLocation", QStandardPaths::AppLocalDataLocation,
|
||||||
|
"CacheLocation", QStandardPaths::CacheLocation,
|
||||||
|
"GenericDataLocation", QStandardPaths::GenericDataLocation,
|
||||||
|
"RuntimeLocation", QStandardPaths::RuntimeLocation,
|
||||||
|
"ConfigLocation", QStandardPaths::ConfigLocation,
|
||||||
|
"DownloadLocation", QStandardPaths::DownloadLocation,
|
||||||
|
"GenericCacheLocation", QStandardPaths::GenericCacheLocation,
|
||||||
|
"GenericConfigLocation", QStandardPaths::GenericConfigLocation,
|
||||||
|
"AppDataLocation", QStandardPaths::AppDataLocation,
|
||||||
|
"AppConfigLocation", QStandardPaths::AppConfigLocation,
|
||||||
|
"PublicShareLocation", QStandardPaths::PublicShareLocation,
|
||||||
|
"TemplatesLocation", QStandardPaths::TemplatesLocation,
|
||||||
|
"StateLocation", QStandardPaths::StateLocation,
|
||||||
|
"GenericStateLocation", QStandardPaths::GenericStateLocation
|
||||||
|
)
|
||||||
|
);
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
return qt;
|
return qt;
|
||||||
|
@@ -182,6 +182,34 @@ void setupUtilsModule()
|
|||||||
utils["FilePath"]["searchInPath_cb"] = utils["__searchInPath_cb__"];
|
utils["FilePath"]["searchInPath_cb"] = utils["__searchInPath_cb__"];
|
||||||
utils["FilePath"]["searchInPath"] = wrap(utils["__searchInPath_cb__"]);
|
utils["FilePath"]["searchInPath"] = wrap(utils["__searchInPath_cb__"]);
|
||||||
|
|
||||||
|
utils["standardLocations"] = [](QStandardPaths::StandardLocation location) {
|
||||||
|
const auto locationsStrings = QStandardPaths::standardLocations(
|
||||||
|
static_cast<QStandardPaths::StandardLocation>(location));
|
||||||
|
|
||||||
|
QList<FilePath> locationsPaths;
|
||||||
|
std::transform(locationsStrings.constBegin(), locationsStrings.constEnd(),
|
||||||
|
std::back_inserter(locationsPaths), &FilePath::fromString);
|
||||||
|
return locationsPaths;
|
||||||
|
};
|
||||||
|
utils["standardLocation"] =
|
||||||
|
[](QStandardPaths::StandardLocation location) -> sol::optional<FilePath> {
|
||||||
|
const auto paths = QStandardPaths::standardLocations(
|
||||||
|
static_cast<QStandardPaths::StandardLocation>(location));
|
||||||
|
if (paths.isEmpty())
|
||||||
|
return sol::nullopt;
|
||||||
|
|
||||||
|
return FilePath::fromString(paths.first());
|
||||||
|
};
|
||||||
|
utils["writableLocation"] =
|
||||||
|
[](QStandardPaths::StandardLocation location) -> sol::optional<FilePath> {
|
||||||
|
const auto path = QStandardPaths::writableLocation(
|
||||||
|
static_cast<QStandardPaths::StandardLocation>(location));
|
||||||
|
if (path.isEmpty())
|
||||||
|
return sol::nullopt;
|
||||||
|
|
||||||
|
return FilePath::fromString(path);
|
||||||
|
};
|
||||||
|
|
||||||
utils.new_usertype<CommandLine>(
|
utils.new_usertype<CommandLine>(
|
||||||
"CommandLine",
|
"CommandLine",
|
||||||
sol::call_constructor,
|
sol::call_constructor,
|
||||||
|
@@ -110,4 +110,33 @@ qt.QFileDevice = {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qt.QStandardPaths = {
|
||||||
|
---@enum StandardLocation
|
||||||
|
StandardLocation = {
|
||||||
|
DesktopLocation = 0,
|
||||||
|
DocumentsLocation = 0,
|
||||||
|
FontsLocation = 0,
|
||||||
|
ApplicationsLocation = 0,
|
||||||
|
MusicLocation = 0,
|
||||||
|
MoviesLocation = 0,
|
||||||
|
PicturesLocation = 0,
|
||||||
|
TempLocation = 0,
|
||||||
|
HomeLocation = 0,
|
||||||
|
AppLocalDataLocation = 0,
|
||||||
|
CacheLocation = 0,
|
||||||
|
GenericDataLocation = 0,
|
||||||
|
RuntimeLocation = 0,
|
||||||
|
ConfigLocation = 0,
|
||||||
|
DownloadLocation = 0,
|
||||||
|
GenericCacheLocation = 0,
|
||||||
|
GenericConfigLocation = 0,
|
||||||
|
AppDataLocation = 0,
|
||||||
|
AppConfigLocation = 0,
|
||||||
|
PublicShareLocation = 0,
|
||||||
|
TemplatesLocation = 0,
|
||||||
|
StateLocation = 0,
|
||||||
|
GenericStateLocation = 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return qt
|
return qt
|
||||||
|
@@ -100,6 +100,21 @@ function utils.FilePath:permissions() end
|
|||||||
---@param permissions Permission The complete OR-ed together combination of permissions for the file.
|
---@param permissions Permission The complete OR-ed together combination of permissions for the file.
|
||||||
function utils.FilePath:setPermissions() end
|
function utils.FilePath:setPermissions() end
|
||||||
|
|
||||||
|
---Returns the list of paths for the given standard location.
|
||||||
|
---@param location StandardLocation The standard location to get paths for.
|
||||||
|
---@return [FilePath] The list of paths for the given standard location.
|
||||||
|
function utils.standardLocations(location) end
|
||||||
|
|
||||||
|
---Returns the first available paths for the given standard location.
|
||||||
|
---@param location StandardLocation The standard location to get the path for.
|
||||||
|
---@return FilePath|nil The first available paths for the given standard location or nil if no location is available.
|
||||||
|
function utils.standardLocation(location) end
|
||||||
|
|
||||||
|
---Returns the writable paths for the given standard location.
|
||||||
|
---@param location StandardLocation The standard location to get path for.
|
||||||
|
---@return FilePath|nil The writable paths for the given standard location or nil if no writable location is available.
|
||||||
|
function utils.writableLocation(location) end
|
||||||
|
|
||||||
---@class CommandLine
|
---@class CommandLine
|
||||||
---@field command FilePath The command to execute.
|
---@field command FilePath The command to execute.
|
||||||
---@field arguments string[] The arguments to pass to the command.
|
---@field arguments string[] The arguments to pass to the command.
|
||||||
|
Reference in New Issue
Block a user