forked from qt-creator/qt-creator
Lua: Create simple ExtensionOptionsPage
Allows Simple extensions to easily piggy-back off of the Extension Manager settings category. Change-Id: I955120fe54d42ac93a74e2d306fc580956d53e35 Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -288,12 +288,15 @@ sol::usertype<T> addTypedAspect(sol::table &lua, const QString &name)
|
|||||||
|
|
||||||
void setupSettingsModule()
|
void setupSettingsModule()
|
||||||
{
|
{
|
||||||
registerProvider("Settings", [](sol::state_view l) -> sol::object {
|
registerProvider("Settings", [](sol::state_view lua) -> sol::object {
|
||||||
sol::table settings = l.create_table();
|
const ScriptPluginSpec *pluginSpec = lua.get<ScriptPluginSpec *>("PluginSpec");
|
||||||
|
|
||||||
|
sol::table settings = lua.create_table();
|
||||||
|
|
||||||
settings.new_usertype<BaseAspect>("Aspect", "apply", &BaseAspect::apply);
|
settings.new_usertype<BaseAspect>("Aspect", "apply", &BaseAspect::apply);
|
||||||
|
|
||||||
settings.new_usertype<LuaAspectContainer>("AspectContainer",
|
settings.new_usertype<LuaAspectContainer>(
|
||||||
|
"AspectContainer",
|
||||||
"create",
|
"create",
|
||||||
&aspectContainerCreate,
|
&aspectContainerCreate,
|
||||||
"apply",
|
"apply",
|
||||||
@@ -515,10 +518,9 @@ void setupSettingsModule()
|
|||||||
options,
|
options,
|
||||||
[](AspectList *aspect, const std::string &key, const sol::object &value) {
|
[](AspectList *aspect, const std::string &key, const sol::object &value) {
|
||||||
if (key == "createItemFunction") {
|
if (key == "createItemFunction") {
|
||||||
aspect->setCreateItemFunction([func = value.as<sol::function>()]()
|
aspect->setCreateItemFunction(
|
||||||
-> std::shared_ptr<BaseAspect> {
|
[func = value.as<sol::function>()]() -> std::shared_ptr<BaseAspect> {
|
||||||
auto res = safe_call<std::shared_ptr<BaseAspect>>(
|
auto res = safe_call<std::shared_ptr<BaseAspect>>(func);
|
||||||
func);
|
|
||||||
QTC_ASSERT_EXPECTED(res, return nullptr);
|
QTC_ASSERT_EXPECTED(res, return nullptr);
|
||||||
return *res;
|
return *res;
|
||||||
});
|
});
|
||||||
@@ -558,19 +560,42 @@ void setupSettingsModule()
|
|||||||
sol::base_classes,
|
sol::base_classes,
|
||||||
sol::bases<BaseAspect>());
|
sol::bases<BaseAspect>());
|
||||||
|
|
||||||
|
class ExtensionOptionsPage : public Core::IOptionsPage
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ExtensionOptionsPage(const ScriptPluginSpec *spec, AspectContainer *container)
|
||||||
|
{
|
||||||
|
setId(Id::fromString(QString("Extension.%2").arg(spec->id)));
|
||||||
|
setCategory(Id("ExtensionManager"));
|
||||||
|
|
||||||
|
setDisplayName(spec->name);
|
||||||
|
|
||||||
|
if (container->isAutoApply())
|
||||||
|
throw sol::error("AspectContainer must have autoApply set to false");
|
||||||
|
|
||||||
|
setSettingsProvider([container]() { return container; });
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
class OptionsPage : public Core::IOptionsPage
|
class OptionsPage : public Core::IOptionsPage
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
OptionsPage(const sol::table &options)
|
OptionsPage(const ScriptPluginSpec *spec, const sol::table &options)
|
||||||
{
|
{
|
||||||
setId(Id::fromString(options.get<QString>("id")));
|
setId(
|
||||||
|
Id::fromString(QString("%1.%2").arg(spec->id).arg(options.get<QString>("id"))));
|
||||||
|
setCategory(Id::fromString(
|
||||||
|
QString("%1.%2").arg(spec->id).arg(options.get<QString>("categoryId"))));
|
||||||
|
|
||||||
setDisplayName(options.get<QString>("displayName"));
|
setDisplayName(options.get<QString>("displayName"));
|
||||||
setCategory(Id::fromString(options.get<QString>("categoryId")));
|
|
||||||
setDisplayCategory(options.get<QString>("displayCategory"));
|
setDisplayCategory(options.get<QString>("displayCategory"));
|
||||||
|
|
||||||
const FilePath catIcon = options.get<std::optional<FilePath>>("categoryIconPath")
|
const FilePath catIcon = options.get<std::optional<FilePath>>("categoryIconPath")
|
||||||
.value_or(FilePath::fromUserInput(
|
.value_or(FilePath::fromUserInput(
|
||||||
options.get_or<QString>("categoryIconPath", {})));
|
options.get_or<QString>("categoryIconPath", {})));
|
||||||
|
|
||||||
setCategoryIconPath(catIcon);
|
setCategoryIconPath(catIcon);
|
||||||
|
|
||||||
AspectContainer *container = options.get<AspectContainer *>("aspectContainer");
|
AspectContainer *container = options.get<AspectContainer *>("aspectContainer");
|
||||||
if (container->isAutoApply())
|
if (container->isAutoApply())
|
||||||
throw sol::error("AspectContainer must have autoApply set to false");
|
throw sol::error("AspectContainer must have autoApply set to false");
|
||||||
@@ -582,28 +607,39 @@ void setupSettingsModule()
|
|||||||
settings.new_usertype<OptionsPage>(
|
settings.new_usertype<OptionsPage>(
|
||||||
"OptionsPage",
|
"OptionsPage",
|
||||||
"create",
|
"create",
|
||||||
[](const sol::table &options) { return std::make_unique<OptionsPage>(options); },
|
[pluginSpec](const sol::table &options) {
|
||||||
|
return std::make_unique<OptionsPage>(pluginSpec, options);
|
||||||
|
},
|
||||||
"show",
|
"show",
|
||||||
[](OptionsPage *page) { Core::ICore::showOptionsDialog(page->id()); });
|
[](OptionsPage *page) { Core::ICore::showOptionsDialog(page->id()); });
|
||||||
|
|
||||||
|
settings.new_usertype<ExtensionOptionsPage>(
|
||||||
|
"ExtensionOptionsPage",
|
||||||
|
"create",
|
||||||
|
[pluginSpec](AspectContainer *container) {
|
||||||
|
return std::make_unique<ExtensionOptionsPage>(pluginSpec, container);
|
||||||
|
},
|
||||||
|
"show",
|
||||||
|
[](ExtensionOptionsPage *page) { Core::ICore::showOptionsDialog(page->id()); });
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
settings["StringDisplayStyle"] = l.create_table_with(
|
settings["StringDisplayStyle"] = lua.create_table_with(
|
||||||
"Label", StringAspect::DisplayStyle::LabelDisplay,
|
"Label", StringAspect::DisplayStyle::LabelDisplay,
|
||||||
"LineEdit", StringAspect::DisplayStyle::LineEditDisplay,
|
"LineEdit", StringAspect::DisplayStyle::LineEditDisplay,
|
||||||
"TextEdit", StringAspect::DisplayStyle::TextEditDisplay,
|
"TextEdit", StringAspect::DisplayStyle::TextEditDisplay,
|
||||||
"PasswordLineEdit", StringAspect::DisplayStyle::PasswordLineEditDisplay
|
"PasswordLineEdit", StringAspect::DisplayStyle::PasswordLineEditDisplay
|
||||||
);
|
);
|
||||||
|
|
||||||
settings["SelectionDisplayStyle"] = l.create_table_with(
|
settings["SelectionDisplayStyle"] = lua.create_table_with(
|
||||||
"RadioButtons", SelectionAspect::DisplayStyle::RadioButtons,
|
"RadioButtons", SelectionAspect::DisplayStyle::RadioButtons,
|
||||||
"ComboBox", SelectionAspect::DisplayStyle::ComboBox
|
"ComboBox", SelectionAspect::DisplayStyle::ComboBox
|
||||||
);
|
);
|
||||||
|
|
||||||
settings["CheckBoxPlacement"] = l.create_table_with(
|
settings["CheckBoxPlacement"] = lua.create_table_with(
|
||||||
"Top", CheckBoxPlacement::Top,
|
"Top", CheckBoxPlacement::Top,
|
||||||
"Right", CheckBoxPlacement::Right
|
"Right", CheckBoxPlacement::Right
|
||||||
);
|
);
|
||||||
settings["Kind"] = l.create_table_with(
|
settings["Kind"] = lua.create_table_with(
|
||||||
"ExistingDirectory", PathChooser::Kind::ExistingDirectory,
|
"ExistingDirectory", PathChooser::Kind::ExistingDirectory,
|
||||||
"Directory", PathChooser::Kind::Directory,
|
"Directory", PathChooser::Kind::Directory,
|
||||||
"File", PathChooser::Kind::File,
|
"File", PathChooser::Kind::File,
|
||||||
@@ -612,7 +648,7 @@ void setupSettingsModule()
|
|||||||
"Command", PathChooser::Kind::Command,
|
"Command", PathChooser::Kind::Command,
|
||||||
"Any", PathChooser::Kind::Any
|
"Any", PathChooser::Kind::Any
|
||||||
);
|
);
|
||||||
settings["LabelPlacement"] = l.create_table_with(
|
settings["LabelPlacement"] = lua.create_table_with(
|
||||||
"AtCheckBox", BoolAspect::LabelPlacement::AtCheckBox,
|
"AtCheckBox", BoolAspect::LabelPlacement::AtCheckBox,
|
||||||
"Compact", BoolAspect::LabelPlacement::Compact,
|
"Compact", BoolAspect::LabelPlacement::Compact,
|
||||||
"InExtraLabel", BoolAspect::LabelPlacement::InExtraLabel
|
"InExtraLabel", BoolAspect::LabelPlacement::InExtraLabel
|
||||||
|
@@ -218,4 +218,14 @@ function settings.OptionsPage.create(options) end
|
|||||||
---Shows options page.
|
---Shows options page.
|
||||||
function settings.OptionsPage:show() end
|
function settings.OptionsPage:show() end
|
||||||
|
|
||||||
|
---@class ExtensionOptionsPage
|
||||||
|
settings.extensionOptionsPage = {}
|
||||||
|
|
||||||
|
---Create an ExtensionOptionsPage.
|
||||||
|
---@param aspectContainer AspectContainer
|
||||||
|
---@return ExtensionOptionsPage
|
||||||
|
function settings.extensionOptionsPage.create(aspectContainer) end
|
||||||
|
|
||||||
|
---Show the options page.
|
||||||
|
function settings.extensionOptionsPage:show() end
|
||||||
return settings
|
return settings
|
||||||
|
Reference in New Issue
Block a user