From adb6c935d27cbbb91d0e38782ed63d3defcaf49a Mon Sep 17 00:00:00 2001 From: Ansariel Date: Fri, 10 Jul 2015 14:47:01 +0200 Subject: [PATCH] Add linefeed input support to chat textboxes via Ctrl-Shift-Enter --- indra/llui/lllineeditor.h | 14 ++++++++--- indra/llui/lltextbase.h | 2 ++ indra/llui/lltexteditor.cpp | 12 +++++++++ indra/llui/lltexteditor.h | 2 ++ indra/newview/fsfloaterim.cpp | 36 +++++++++++++++++++++++++++ indra/newview/fsfloaterim.h | 2 ++ indra/newview/fsfloaternearbychat.cpp | 29 ++++++++++++++++++++- indra/newview/fsnearbychatcontrol.cpp | 8 +++--- 8 files changed, 96 insertions(+), 9 deletions(-) diff --git a/indra/llui/lllineeditor.h b/indra/llui/lllineeditor.h index 9dcbc44f5c..e549302bb9 100755 --- a/indra/llui/lllineeditor.h +++ b/indra/llui/lllineeditor.h @@ -280,15 +280,21 @@ public: void setContextMenu(LLContextMenu* new_context_menu); + // Make these protected + void removeChar(); + void removeWord(bool prev); + void addChar(const llwchar c); + // + private: // private helper methods void pasteHelper(bool is_primary); - void removeChar(); - // Ctrl-Backspace remove word - void removeWord(bool prev); - void addChar(const llwchar c); + // Make these protected + //void removeChar(); + //void addChar(const llwchar c); + // void setCursorAtLocalPos(S32 local_mouse_x); S32 findPixelNearestPos(S32 cursor_offset = 0) const; S32 calcCursorPos(S32 mouse_x); diff --git a/indra/llui/lltextbase.h b/indra/llui/lltextbase.h index 29d2179724..dd1dd03819 100755 --- a/indra/llui/lltextbase.h +++ b/indra/llui/lltextbase.h @@ -413,6 +413,8 @@ public: virtual void setText(const LLStringExplicit &utf8str , const LLStyle::Params& input_params = LLStyle::Params()); // uses default style virtual std::string getText() const; void setMaxTextLength(S32 length) { mMaxTextByteLength = length; } + // Getter for mMaxTextByteLength + S32 getMaxTextLength() const { return mMaxTextByteLength; } // wide-char versions void setWText(const LLWString& text); diff --git a/indra/llui/lltexteditor.cpp b/indra/llui/lltexteditor.cpp index d80ec7f47a..b587344b14 100755 --- a/indra/llui/lltexteditor.cpp +++ b/indra/llui/lltexteditor.cpp @@ -2450,6 +2450,18 @@ void LLTextEditor::insertText(LLWString &new_text) setEnabled( enabled ); } +// Allow inserting a linefeed +void LLTextEditor::insertLinefeed() +{ + BOOL enabled = getEnabled(); + setEnabled( TRUE ); + + addLineBreakChar(FALSE); + + setEnabled( enabled ); +} +// + void LLTextEditor::appendWidget(const LLInlineViewSegment::Params& params, const std::string& text, bool allow_undo) { // Save old state diff --git a/indra/llui/lltexteditor.h b/indra/llui/lltexteditor.h index 391348cb5c..9279be88de 100755 --- a/indra/llui/lltexteditor.h +++ b/indra/llui/lltexteditor.h @@ -177,6 +177,8 @@ public: // inserts text at cursor void insertText(const std::string &text); void insertText(LLWString &text); + // Allow inserting a linefeed + void insertLinefeed(); void appendWidget(const LLInlineViewSegment::Params& params, const std::string& text, bool allow_undo); // Non-undoable diff --git a/indra/newview/fsfloaterim.cpp b/indra/newview/fsfloaterim.cpp index 85f5ab65cf..038cdb1f2c 100644 --- a/indra/newview/fsfloaterim.cpp +++ b/indra/newview/fsfloaterim.cpp @@ -1761,6 +1761,42 @@ bool FSFloaterIM::dropPerson(LLUUID* person_id, bool drop) return res; } +// virtual +BOOL FSFloaterIM::handleKeyHere( KEY key, MASK mask ) +{ + BOOL handled = FALSE; + + if (key == KEY_RETURN && mask == (MASK_SHIFT | MASK_CONTROL)) + { + if (!gSavedSettings.getBOOL("FSUseSingleLineChatEntry")) + { + if ((wstring_utf8_length(mInputEditor->getWText()) + wchar_utf8_length('\n')) > mInputEditor->getMaxTextLength()) + { + LLUI::reportBadKeystroke(); + } + else + { + mInputEditor->insertLinefeed(); + } + } + else + { + if ((wstring_utf8_length(mInputEditor->getWText()) + wchar_utf8_length(llwchar(182))) > mInputEditor->getMaxTextLength()) + { + LLUI::reportBadKeystroke(); + } + else + { + mInputEditor->insertText(LLWString(1, 182)); + } + } + + handled = TRUE; + } + + return handled; +} + BOOL FSFloaterIM::isInviteAllowed() const { return ( (IM_SESSION_CONFERENCE_START == mDialog) diff --git a/indra/newview/fsfloaterim.h b/indra/newview/fsfloaterim.h index eba991978d..548081b505 100644 --- a/indra/newview/fsfloaterim.h +++ b/indra/newview/fsfloaterim.h @@ -122,6 +122,8 @@ public: void *cargo_data, EAcceptance *accept, std::string& tooltip_msg); + virtual BOOL handleKeyHere( KEY key, MASK mask ); + /** * Returns true if chat is displayed in multi tabbed floater * false if chat is displayed in multiple windows diff --git a/indra/newview/fsfloaternearbychat.cpp b/indra/newview/fsfloaternearbychat.cpp index 4175440cc7..22a1456cb6 100644 --- a/indra/newview/fsfloaternearbychat.cpp +++ b/indra/newview/fsfloaternearbychat.cpp @@ -708,8 +708,35 @@ BOOL FSFloaterNearbyChat::handleKeyHere( KEY key, MASK mask ) sendChat(CHAT_TYPE_OOC); handled = TRUE; } + else if (mask == (MASK_SHIFT | MASK_CONTROL)) + { + if (!gSavedSettings.getBOOL("FSUseSingleLineChatEntry")) + { + if ((wstring_utf8_length(mInputEditor->getWText()) + wchar_utf8_length('\n')) > mInputEditor->getMaxTextLength()) + { + LLUI::reportBadKeystroke(); + } + else + { + mInputEditor->insertLinefeed(); + } + } + else + { + if ((wstring_utf8_length(mInputEditor->getWText()) + wchar_utf8_length(llwchar(182))) > mInputEditor->getMaxTextLength()) + { + LLUI::reportBadKeystroke(); + } + else + { + mInputEditor->insertText(LLWString(1, 182)); + } + } + + handled = TRUE; + } } - + return handled; } diff --git a/indra/newview/fsnearbychatcontrol.cpp b/indra/newview/fsnearbychatcontrol.cpp index 86e5db169e..f22e8d7d2a 100644 --- a/indra/newview/fsnearbychatcontrol.cpp +++ b/indra/newview/fsnearbychatcontrol.cpp @@ -370,11 +370,11 @@ BOOL FSNearbyChatControl::handleKeyHere(KEY key, MASK mask ) type = CHAT_TYPE_OOC; handled = TRUE; } - else if (mask == MASK_NONE) + else if (mask == (MASK_SHIFT | MASK_CONTROL)) { - // say - type = CHAT_TYPE_NORMAL; - handled = TRUE; + addChar(llwchar(182)); + + return TRUE; } else {