Lua: Add Action icon option

Change-Id: I18d928f490fc908b0a4f170957a7f37266509b50
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2024-09-25 10:25:30 +02:00
parent 547ecd4b89
commit 9d26b88d75
2 changed files with 10 additions and 1 deletions

View File

@@ -3,6 +3,8 @@
#include "../luaengine.h"
#include "utils.h"
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/modemanager.h>
@@ -51,6 +53,10 @@ void setupActionModule()
[](ScriptCommand *cmd) { return cmd->m_contextAction->text(); },
[](ScriptCommand *cmd, const QString &text) {
cmd->m_contextAction->setText(text);
}),
"icon",
sol::property([](ScriptCommand *cmd, const FilePathOrString &&icon) {
cmd->m_contextAction->setIcon(QIcon(toFilePath(icon).toFSPathString()));
}));
result["create"] = [parent = std::make_unique<QObject>()](
@@ -93,6 +99,8 @@ void setupActionModule()
throw std::runtime_error(
"asMode needs an integer argument for the priority");
}
} else if (key == "icon") {
b.setIcon(QIcon(toFilePath(v.as<FilePathOrString>()).toFSPathString()));
} else
throw std::runtime_error("Unknown key: " + key.toStdString());
}

View File

@@ -17,6 +17,7 @@ action.CommandAttribute = {
---@class ActionOptions
---@field context? string The context in which the action is available.
---@field text? string The text to display for the action.
---@field icon? FilePath|string The icon to display for the action.
---@field iconText? string The icon text to display for the action.
---@field toolTip? string The tooltip to display for the action.
---@field onTrigger? function The callback to call when the action is triggered.