From 41e14d35ae2dfa644716cb195545d59c468538c5 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 25 Mar 2024 15:06:11 +0200 Subject: [PATCH 1/4] Add keystroke event support and allow adding text lines to the line editor --- indra/llui/llluafloater.cpp | 40 +++++++++++++++---- indra/newview/scripts/lua/luafloater_demo.xml | 13 +++++- .../scripts/lua/test_luafloater_demo.lua | 4 +- .../lua/test_luafloater_gesture_list.lua | 3 +- indra/newview/scripts/lua/util.lua | 10 ----- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index afc287a8644..8f624788c25 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -32,6 +32,7 @@ #include "llcheckboxctrl.h" #include "llcombobox.h" #include "llscrolllistctrl.h" +#include "lltexteditor.h" const std::string LISTENER_NAME("LLLuaFloater"); @@ -45,7 +46,8 @@ std::set EVENT_LIST = { "right_mouse_down", "right_mouse_up", "post_build", - "floater_close" + "floater_close", + "keystroke" }; LLLuaFloater::LLLuaFloater(const LLSD &key) : @@ -99,6 +101,16 @@ LLLuaFloater::LLLuaFloater(const LLSD &key) : } }, requiredParams); + mDispatchListener.add("add_text", "", [this](const LLSD &event) + { + LLTextEditor *editor = getChild(event["ctrl_name"].asString()); + if (editor) + { + editor->pasteTextWithLinebreaks(stringize(event["value"])); + editor->addLineBreakChar(true); + } + }, requiredParams); + mDispatchListener.add("set_title", "", [this](const LLSD &event) { setTitle(event["value"].asString()); @@ -182,6 +194,12 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str post(event.with("x", x).with("y", y)); }; + auto post_with_value = [this, data](LLSD& value) + { + LLSD event(data); + post(event.with("value", value)); + }; + if (event_is(event, "mouse_enter")) { ctrl->setMouseEnterCallback(mouse_event_cb); @@ -211,18 +229,26 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str LLScrollListCtrl *list = dynamic_cast(ctrl); if (list) { - list->setDoubleClickCallback( - [this, data, list]() - { - LLSD event(data); - post(event.with("value", list->getCurrentID())); - }); + list->setDoubleClickCallback( [this, post_with_value, list](){ post_with_value(LLSD(list->getCurrentID())); }); } else { ctrl->setDoubleClickCallback(mouse_event_coords_cb); } } + else if (event_is(event, "keystroke")) + { + LLTextEditor* text_editor = dynamic_cast(ctrl); + if (text_editor) + { + text_editor->setKeystrokeCallback([this, post_with_value](LLTextEditor *editor) { post_with_value(editor->getValue()); }); + } + LLLineEditor* line_editor = dynamic_cast(ctrl); + if (line_editor) + { + line_editor->setKeystrokeCallback([this, post_with_value](LLLineEditor *editor, void* userdata) { post_with_value(editor->getValue()); }, NULL); + } + } else { LL_WARNS("LuaFloater") << "Can't register callback for unknown event: " << event << " , control: " << ctrl_name << LL_ENDL; diff --git a/indra/newview/scripts/lua/luafloater_demo.xml b/indra/newview/scripts/lua/luafloater_demo.xml index 069f2291283..b2273d77184 100644 --- a/indra/newview/scripts/lua/luafloater_demo.xml +++ b/indra/newview/scripts/lua/luafloater_demo.xml @@ -1,7 +1,7 @@ + diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index b81259c0608..22ed7d7b3a3 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -2,7 +2,6 @@ XML_FILE_PATH = "luafloater_demo.xml" leap = require 'leap' coro = require 'coro' -util = require 'util' --event pump for sending actions to the floater COMMAND_PUMP_NAME = "" @@ -15,7 +14,7 @@ end) leap.process() local function _event(event_name) - if not util.contains(event_list, event_name) then + if not table.find(event_list, event_name) then print_warning("Incorrect event name: " .. event_name) end return event_name @@ -31,6 +30,7 @@ function getCurrentTime() end function handleEvents(event_data) + post({action="add_text", ctrl_name="events_editor", value = event_data}) if event_data.event == _event("commit") then if event_data.ctrl_name == "disable_ctrl" then post({action="set_enabled", ctrl_name="open_btn", value = (1 - event_data.value)}) diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index b46e36b4d91..b1ff129d855 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -2,7 +2,6 @@ XML_FILE_PATH = "luafloater_gesture_list.xml" leap = require 'leap' coro = require 'coro' -util = require 'util' LLGesture = require 'LLGesture' --event pump for sending actions to the floater @@ -16,7 +15,7 @@ end) leap.process() local function _event(event_name) - if not util.contains(event_list, event_name) then + if not table.find(event_list, event_name) then print_warning("Incorrect event name: " .. event_name) end return event_name diff --git a/indra/newview/scripts/lua/util.lua b/indra/newview/scripts/lua/util.lua index 5d6042dfe5e..e3af633ea77 100644 --- a/indra/newview/scripts/lua/util.lua +++ b/indra/newview/scripts/lua/util.lua @@ -36,14 +36,4 @@ function util.equal(t1, t2) return util.empty(temp) end --- check if array-like table contains certain value -function util.contains(t, v) - for _, value in ipairs(t) do - if value == v then - return true - end - end - return false -end - return util From 7f39a5bb109338b201c9cd0d3a40baac2b2e4fc1 Mon Sep 17 00:00:00 2001 From: Maxim Nikolenko Date: Mon, 25 Mar 2024 17:10:46 +0200 Subject: [PATCH 2/4] mac build fix --- indra/llui/llluafloater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 8f624788c25..268075b05de 100644 --- a/indra/llui/llluafloater.cpp +++ b/indra/llui/llluafloater.cpp @@ -194,7 +194,7 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str post(event.with("x", x).with("y", y)); }; - auto post_with_value = [this, data](LLSD& value) + auto post_with_value = [this, data](LLSD value) { LLSD event(data); post(event.with("value", value)); @@ -229,7 +229,7 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str LLScrollListCtrl *list = dynamic_cast(ctrl); if (list) { - list->setDoubleClickCallback( [this, post_with_value, list](){ post_with_value(LLSD(list->getCurrentID())); }); + list->setDoubleClickCallback( [post_with_value, list](){ post_with_value(LLSD(list->getCurrentID())); }); } else { @@ -241,12 +241,12 @@ void LLLuaFloater::registerCallback(const std::string &ctrl_name, const std::str LLTextEditor* text_editor = dynamic_cast(ctrl); if (text_editor) { - text_editor->setKeystrokeCallback([this, post_with_value](LLTextEditor *editor) { post_with_value(editor->getValue()); }); + text_editor->setKeystrokeCallback([post_with_value](LLTextEditor *editor) { post_with_value(editor->getValue()); }); } LLLineEditor* line_editor = dynamic_cast(ctrl); if (line_editor) { - line_editor->setKeystrokeCallback([this, post_with_value](LLLineEditor *editor, void* userdata) { post_with_value(editor->getValue()); }, NULL); + line_editor->setKeystrokeCallback([post_with_value](LLLineEditor *editor, void* userdata) { post_with_value(editor->getValue()); }, NULL); } } else From 6cedaecad9c4830aa29068b90611b8b9da301ac9 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 25 Mar 2024 20:41:33 +0200 Subject: [PATCH 3/4] Update test scripts to call leap.request() from main thread --- .../newview/scripts/lua/test_luafloater_demo.lua | 16 ++-------------- .../scripts/lua/test_luafloater_gesture_list.lua | 14 ++------------ 2 files changed, 4 insertions(+), 26 deletions(-) diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index 22ed7d7b3a3..f2cf34206e7 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -6,12 +6,7 @@ coro = require 'coro' --event pump for sending actions to the floater COMMAND_PUMP_NAME = "" --table of floater UI events -event_list={} -coro.launch(function () - event_list = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] - leap.done() -end) -leap.process() +event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events local function _event(event_name) if not table.find(event_list, event_name) then @@ -53,12 +48,7 @@ end local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --sign for additional events for defined control {= {action1, action2, ...}} key.extra_events={show_time_lbl = {_event("right_mouse_down"), _event("double_click")}} -coro.launch(function () - --script received event pump name, after floater was built - COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key)["command_name"] - leap.done() -end) -leap.process() +COMMAND_PUMP_NAME = leap.request("LLFloaterReg", key).command_name catch_events = leap.WaitFor:new(-1, "all_events") function catch_events:filter(pump, data) @@ -74,5 +64,3 @@ function process_events(waitfor) end coro.launch(process_events, catch_events) -leap.process() -print_warning("End of the script") diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index b1ff129d855..049ba757d36 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -7,12 +7,7 @@ LLGesture = require 'LLGesture' --event pump for sending actions to the floater COMMAND_PUMP_NAME = "" --table of floater UI events -event_list={} -coro.launch(function () - event_list = leap.request("LLFloaterReg", {op="getFloaterEvents"})["events"] - leap.done() -end) -leap.process() +event_list=leap.request("LLFloaterReg", {op="getFloaterEvents"}).events local function _event(event_name) if not table.find(event_list, event_name) then @@ -50,11 +45,7 @@ end local key = {xml_path = XML_FILE_PATH, op = "showLuaFloater"} --receive additional events for defined control {= {action1, action2, ...}} key.extra_events={gesture_list = {_event("double_click")}} -coro.launch(function () - handleEvents(leap.request("LLFloaterReg", key)) - leap.done() -end) -leap.process() +handleEvents(leap.request("LLFloaterReg", key)) catch_events = leap.WaitFor:new(-1, "all_events") function catch_events:filter(pump, data) @@ -70,4 +61,3 @@ function process_events(waitfor) end coro.launch(process_events, catch_events) -leap.process() From 24a7842b9b08dc5cfb89fe36e5ebcd9c2598fa44 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Tue, 26 Mar 2024 19:12:13 +0200 Subject: [PATCH 4/4] update scripts to use fiber.launch() --- indra/newview/scripts/lua/test_luafloater_demo.lua | 3 ++- indra/newview/scripts/lua/test_luafloater_gesture_list.lua | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/indra/newview/scripts/lua/test_luafloater_demo.lua b/indra/newview/scripts/lua/test_luafloater_demo.lua index f2cf34206e7..be189bc146e 100644 --- a/indra/newview/scripts/lua/test_luafloater_demo.lua +++ b/indra/newview/scripts/lua/test_luafloater_demo.lua @@ -2,6 +2,7 @@ XML_FILE_PATH = "luafloater_demo.xml" leap = require 'leap' coro = require 'coro' +fiber = require 'fiber' --event pump for sending actions to the floater COMMAND_PUMP_NAME = "" @@ -63,4 +64,4 @@ function process_events(waitfor) end end -coro.launch(process_events, catch_events) +fiber.launch("catch_events", process_events, catch_events) diff --git a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua index 049ba757d36..7e2139468fc 100644 --- a/indra/newview/scripts/lua/test_luafloater_gesture_list.lua +++ b/indra/newview/scripts/lua/test_luafloater_gesture_list.lua @@ -2,6 +2,7 @@ XML_FILE_PATH = "luafloater_gesture_list.xml" leap = require 'leap' coro = require 'coro' +fiber = require 'fiber' LLGesture = require 'LLGesture' --event pump for sending actions to the floater @@ -60,4 +61,4 @@ function process_events(waitfor) end end -coro.launch(process_events, catch_events) +fiber.launch("catch_events", process_events, catch_events)