From 9d26b88d754bf5e05207ee92f4ba719d58ab57b1 Mon Sep 17 00:00:00 2001 From: Marcus Tillmanns Date: Wed, 25 Sep 2024 10:25:30 +0200 Subject: [PATCH] Lua: Add Action icon option Change-Id: I18d928f490fc908b0a4f170957a7f37266509b50 Reviewed-by: hjk --- src/plugins/lua/bindings/action.cpp | 10 +++++++++- src/plugins/lua/meta/action.lua | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/plugins/lua/bindings/action.cpp b/src/plugins/lua/bindings/action.cpp index 9a5e89230b7..08c4dc3181a 100644 --- a/src/plugins/lua/bindings/action.cpp +++ b/src/plugins/lua/bindings/action.cpp @@ -3,6 +3,8 @@ #include "../luaengine.h" +#include "utils.h" + #include #include @@ -51,7 +53,11 @@ 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()]( const std::string &actionId, const sol::table &options) mutable { @@ -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()).toFSPathString())); } else throw std::runtime_error("Unknown key: " + key.toStdString()); } diff --git a/src/plugins/lua/meta/action.lua b/src/plugins/lua/meta/action.lua index 39d4cf26ab4..4789315927b 100644 --- a/src/plugins/lua/meta/action.lua +++ b/src/plugins/lua/meta/action.lua @@ -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.