From 41e14d35ae2dfa644716cb195545d59c468538c5 Mon Sep 17 00:00:00 2001 From: Mnikolenko Productengine Date: Mon, 25 Mar 2024 15:06:11 +0200 Subject: Add keystroke event support and allow adding text lines to the line editor --- indra/llui/llluafloater.cpp | 40 +++++++++++++++++++++++++++++++++------- 1 file changed, 33 insertions(+), 7 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index afc287a864..8f624788c2 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; -- cgit v1.2.3 From 7f39a5bb109338b201c9cd0d3a40baac2b2e4fc1 Mon Sep 17 00:00:00 2001 From: Maxim Nikolenko Date: Mon, 25 Mar 2024 17:10:46 +0200 Subject: mac build fix --- indra/llui/llluafloater.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'indra/llui') diff --git a/indra/llui/llluafloater.cpp b/indra/llui/llluafloater.cpp index 8f624788c2..268075b05d 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 -- cgit v1.2.3