From 3bba7671eb11c05625445f70729f65796160dd8e Mon Sep 17 00:00:00 2001 From: Neremyn <252772838+primgineer@users.noreply.github.com> Date: Tue, 5 May 2026 20:36:17 +0300 Subject: [PATCH 01/23] Add byte counter to notecard preview --- indra/newview/llpreviewnotecard.cpp | 48 ++++++++++++++++++- indra/newview/llpreviewnotecard.h | 10 +++- .../xui/en/floater_preview_notecard.xml | 10 ++++ .../xui/ja/floater_preview_notecard.xml | 4 ++ .../xui/ru/floater_preview_notecard.xml | 4 ++ .../xui/zh/floater_preview_notecard.xml | 4 ++ 6 files changed, 77 insertions(+), 3 deletions(-) diff --git a/indra/newview/llpreviewnotecard.cpp b/indra/newview/llpreviewnotecard.cpp index c525d06674..97671103ea 100644 --- a/indra/newview/llpreviewnotecard.cpp +++ b/indra/newview/llpreviewnotecard.cpp @@ -27,6 +27,7 @@ #include "llviewerprecompiledheaders.h" #include "llpreviewnotecard.h" +#include "llnotecard.h" #include "llinventory.h" @@ -60,6 +61,7 @@ #include "lllineeditor.h" #include "lluictrlfactory.h" #include "llviewerassetupload.h" +#include "lluistring.h" // [SL:KB] - Patch: UI-FloaterSearchReplace | Checked: 2010-11-05 (Catznip-2.3.0a) | Added: Catznip-2.3.0a #include "llfloatersearchreplace.h" @@ -125,6 +127,14 @@ bool LLPreviewNotecard::postBuild() mEditBtn = getChild("Edit"); mEditBtn->setCommitCallback(boost::bind(&LLPreviewNotecard::openInExternalEditor, this)); + + // Byte counter + mByteCounter = getChild("byte_counter"); + if (mByteCounter) + { + mByteCounterTemplate = mByteCounter->getText(); + } + mEditor->setKeystrokeCallback([this](LLTextEditor*) { mByteCounterDirty = true; }); // FIRE-13969: Search button getChild("Search")->setClickedCallback(boost::bind(&LLPreviewNotecard::onSearchButtonClicked, this)); @@ -156,6 +166,36 @@ bool LLPreviewNotecard::saveItem() return saveIfNeeded(item); } +// Byte counter +// - Neremyn +void LLPreviewNotecard::updateByteCounter() +{ + if (!mEditor || !mByteCounter) return; + + std::string text = mEditor->getText(); + size_t bytes = text.size(); // Assumes UTF-8 encoding where size() == bytes + + const size_t MAX_BYTES = LLNotecard::MAX_SIZE; + + auto getColorForByteCount = [MAX_BYTES, bytes]() -> LLColor4 + { + if (bytes >= MAX_BYTES) + return LLColor4::red; + + if (bytes > (MAX_BYTES * 8 / 10)) + return LLColor4::yellow; + + return LLColor4::white; + }; + mByteCounter->setColor(getColorForByteCount()); + + LLUIString ui_text(mByteCounterTemplate); + ui_text.setArg("[BYTES]", std::to_string(bytes)); + ui_text.setArg("[MAX]", std::to_string(MAX_BYTES)); + + mByteCounter->setText(ui_text.getString()); +} + void LLPreviewNotecard::setEnabled(bool enabled) { if (mEditor) @@ -182,7 +222,11 @@ void LLPreviewNotecard::draw() bool changed = !mEditor->isPristine(); mSaveBtn->setEnabled(changed && getEnabled()); - + if (mByteCounterDirty) // Byte counter + { + updateByteCounter(); + mByteCounterDirty = false; + } LLPreview::draw(); } @@ -969,4 +1013,4 @@ void LLPreviewNotecard::onFontChanged() } // -// EOF +// EOF \ No newline at end of file diff --git a/indra/newview/llpreviewnotecard.h b/indra/newview/llpreviewnotecard.h index 3f010dec8b..0107350709 100644 --- a/indra/newview/llpreviewnotecard.h +++ b/indra/newview/llpreviewnotecard.h @@ -99,6 +99,9 @@ protected: void updateTitleButtons() override; void loadAsset() override; bool saveIfNeeded(LLInventoryItem* copyitem = NULL, bool sync = true); + + // Byte counter + void updateByteCounter(); void deleteNotecard(); @@ -138,6 +141,11 @@ protected: LLButton* mDeleteBtn = nullptr; LLUICtrl* mLockBtn = nullptr; + // Byte counter + LLTextBox* mByteCounter = nullptr; + std::string mByteCounterTemplate; + bool mByteCounterDirty = true; + LLUUID mAssetID; LLUUID mObjectID; @@ -150,4 +158,4 @@ protected: }; -#endif // LL_LLPREVIEWNOTECARD_H +#endif // LL_LLPREVIEWNOTECARD_H \ No newline at end of file diff --git a/indra/newview/skins/default/xui/en/floater_preview_notecard.xml b/indra/newview/skins/default/xui/en/floater_preview_notecard.xml index eac2fbc2fd..d93af2907f 100644 --- a/indra/newview/skins/default/xui/en/floater_preview_notecard.xml +++ b/indra/newview/skins/default/xui/en/floater_preview_notecard.xml @@ -106,6 +106,16 @@ name="Edit" top="332" width="100" /> +