forked from qt-creator/qt-creator
Lua: Add first plugin
Change-Id: I207b986e7ce17aad544f1bdaba29fd4930ad679c Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
@@ -1119,3 +1119,28 @@ function(qtc_add_public_header header)
|
||||
COMPONENT Devel EXCLUDE_FROM_ALL
|
||||
)
|
||||
endfunction()
|
||||
|
||||
function (add_qtc_lua_plugin name)
|
||||
cmake_parse_arguments(_arg "EXCLUDE_FROM_INSTALL;" "" "SOURCES;" ${ARGN})
|
||||
|
||||
add_custom_target(${name} ALL SOURCES ${_arg_SOURCES})
|
||||
|
||||
foreach(SOURCE ${_arg_SOURCES})
|
||||
add_custom_command(TARGET ${name} POST_BUILD
|
||||
COMMAND
|
||||
${CMAKE_COMMAND} -E copy
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}
|
||||
${CMAKE_BINARY_DIR}/${IDE_PLUGIN_PATH}/lua-plugins/${SOURCE}
|
||||
COMMENT "Copying ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE} to ${CMAKE_BINARY_DIR}/${IDE_PLUGIN_PATH}/lua-plugins/${SOURCE}"
|
||||
)
|
||||
|
||||
if (NOT _arg_EXCLUDE_FROM_INSTALL)
|
||||
cmake_path(GET SOURCE PARENT_PATH SOURCE_DIR)
|
||||
|
||||
install(FILES
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE}
|
||||
DESTINATION ${IDE_PLUGIN_PATH}/lua-plugins/${SOURCE_DIR}
|
||||
)
|
||||
endif()
|
||||
endforeach()
|
||||
endfunction()
|
||||
|
||||
@@ -118,3 +118,4 @@ endif()
|
||||
add_subdirectory(qnx)
|
||||
add_subdirectory(mcusupport)
|
||||
add_subdirectory(qtapplicationmanager)
|
||||
add_subdirectory(tellajoke)
|
||||
|
||||
1
src/plugins/tellajoke/CMakeLists.txt
Normal file
1
src/plugins/tellajoke/CMakeLists.txt
Normal file
@@ -0,0 +1 @@
|
||||
add_qtc_lua_plugin(tellajoke SOURCES tellajoke/tellajoke.lua)
|
||||
56
src/plugins/tellajoke/tellajoke/tellajoke.lua
Normal file
56
src/plugins/tellajoke/tellajoke/tellajoke.lua
Normal file
@@ -0,0 +1,56 @@
|
||||
--- Copyright (C) 2024 The Qt Company Ltd.
|
||||
--- SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
local function fetchJoke()
|
||||
print("Fetching ...")
|
||||
|
||||
local a = require("async")
|
||||
local fetch = require("Fetch").fetch
|
||||
local utils = require("Utils")
|
||||
local mm = require("MessageManager")
|
||||
|
||||
local r = a.wait(fetch({ url = "https://official-joke-api.appspot.com/random_joke", convertToTable = true }))
|
||||
if (type(r) == "table") then
|
||||
mm.writeDisrupting(r.setup)
|
||||
a.wait(utils.waitms(1000))
|
||||
mm.writeSilently(".")
|
||||
a.wait(utils.waitms(1000))
|
||||
mm.writeSilently(".")
|
||||
a.wait(utils.waitms(1000))
|
||||
mm.writeSilently(".")
|
||||
a.wait(utils.waitms(1000))
|
||||
mm.writeDisrupting(r.punchline)
|
||||
else
|
||||
print("echo Error fetching: " .. r)
|
||||
end
|
||||
end
|
||||
|
||||
local function fetchJokeSafe()
|
||||
local ok, err = pcall(fetchJoke)
|
||||
if not ok then
|
||||
print("echo Error fetching: " .. err)
|
||||
end
|
||||
end
|
||||
|
||||
local function setup()
|
||||
local a = require("async")
|
||||
Action = require("Action")
|
||||
Action.create("Simple.joke", {
|
||||
text = "Tell a joke",
|
||||
onTrigger = function() a.sync(fetchJokeSafe)() end,
|
||||
defaultKeySequences = { "Meta+Ctrl+Shift+J", "Ctrl+Shift+Alt+J" },
|
||||
})
|
||||
end
|
||||
|
||||
return {
|
||||
Name = "Tell A Joke",
|
||||
Version = "1.0.0",
|
||||
CompatVersion = "1.0.0",
|
||||
Vendor = "The Qt Company",
|
||||
Category = "Fun",
|
||||
Description = "This plugin adds an action that tells a joke.",
|
||||
Dependencies = {
|
||||
{ Name = "Lua", Version = "13.0.82", Required = true },
|
||||
},
|
||||
setup = setup,
|
||||
} --[[@as QtcPlugin]]
|
||||
Reference in New Issue
Block a user