From f5006e8a2f34afa390f0bbcf0f6af15218cf4105 Mon Sep 17 00:00:00 2001 From: thickbrick Date: Sat, 25 Sep 2010 12:58:56 +0200 Subject: LLLineEditor context translator: - Added a xui attribute "allow_translate", default to off (not enabled in any xml file yet.) - Only show translate menu if clicked on a word, or something is selected. --- linden/indra/llui/lllineeditor.cpp | 35 ++++++++++++++++------------------- linden/indra/llui/lllineeditor.h | 2 ++ 2 files changed, 18 insertions(+), 19 deletions(-) (limited to 'linden/indra/llui') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 503a1bd..05966d6 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -175,7 +175,8 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), mSpellCheckable( FALSE ), - mShowMisspellings(FALSE) + mShowMisspellings(FALSE), + mAllowTranslate(FALSE) { llassert( max_length_bytes > 0 ); @@ -762,7 +763,8 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //setCursorAtLocalPos( x); S32 wordStart = 0; - S32 wordEnd = calculateCursorFromMouse(x); + S32 wordEnd = 0; + S32 pos = calculateCursorFromMouse(x); LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get(); if (menu) @@ -785,29 +787,19 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - menu->setItemVisible("Translate To", !mReadOnly); - menu->setItemVisible("Transep", !mReadOnly); + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); + // allow_translate="true" in xui + bool can_translate = mAllowTranslate && !mReadOnly && (is_word_part || hasSelection()); + menu->setItemVisible("Translate To", can_translate); + menu->setItemVisible("Transep", can_translate); // spell_check="true" in xui if (!mReadOnly && mSpellCheckable) { - const LLWString& text = mText.getWString(); - // search for word matches - if (LLTextEditor::isPartOfWord(text[wordEnd])) + if (is_word_part) { - // Select word the cursor is over - while ((wordEnd > 0) && LLTextEditor::isPartOfWord(text[wordEnd-1])) - { - wordEnd--; - } - wordStart = wordEnd; - //startSelection(); - - while ((wordEnd < (S32)text.length()) && LLTextEditor::isPartOfWord( text[wordEnd] ) ) - { - wordEnd++; - } + const LLWString& text = mText.getWString(); std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart)); if (!glggHunSpell->isSpelledRight(selectedWord)) @@ -2893,6 +2885,11 @@ LLView* LLLineEditor::fromXML(LLXMLNodePtr node, LLView *parent, LLUICtrlFactory { line_editor->setSpellCheckable(spell_checking); } + BOOL allow_translate = FALSE; + if (node->getAttributeBOOL("allow_translate", allow_translate)) + { + line_editor->setAllowTranslate(allow_translate); + } line_editor->setColorParameters(node); diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index af37f62..0ad415a 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -200,6 +200,7 @@ public: void setReadOnlyBgColor( const LLColor4& c ) { mReadOnlyBgColor = c; } void setFocusBgColor(const LLColor4& c) { mFocusBgColor = c; } void setSpellCheckable(BOOL b) { mSpellCheckable = b; } + void setAllowTranslate(BOOL b) { mAllowTranslate = b; } const LLColor4& getFgColor() const { return mFgColor; } const LLColor4& getReadOnlyFgColor() const { return mReadOnlyFgColor; } @@ -301,6 +302,7 @@ protected: //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; S32 mLastContextMenuX; + BOOL mAllowTranslate; // set in xui as "allow_translate". // line history support: BOOL mHaveHistory; // flag for enabled line history -- cgit v1.1