From 81a3df503aece6b46e1efbdb7e274253cb898660 Mon Sep 17 00:00:00 2001
From: thickbrick
Date: Sat, 25 Sep 2010 15:00:50 +0200
Subject: LLTextEditor 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/lltexteditor.cpp | 34 +++++++++++++++-------------------
 linden/indra/llui/lltexteditor.h   |  1 +
 2 files changed, 16 insertions(+), 19 deletions(-)

(limited to 'linden/indra/llui')

diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp
index 4bae155..adf0260 100644
--- a/linden/indra/llui/lltexteditor.cpp
+++ b/linden/indra/llui/lltexteditor.cpp
@@ -330,7 +330,8 @@ LLTextEditor::LLTextEditor(
 	mReflowNeeded(FALSE),
 	mScrollNeeded(FALSE),
 	mSpellCheckable(FALSE),
-	mShowMisspellings(FALSE)
+	mShowMisspellings(FALSE),
+	mAllowTranslate(FALSE)
 {
 	mSourceID.generate();
 
@@ -1484,7 +1485,8 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask )
 
 	//setCursorAtLocalPos( x, y, TRUE );
 	S32 wordStart = 0;
-	S32 wordEnd = getCursorPosFromLocalCoord(x,y,TRUE);
+	S32 wordEnd = 0;
+	S32 pos = getCursorPosFromLocalCoord(x,y,TRUE);
 
 	LLMenuGL* menu = (LLMenuGL*)mPopupMenuHandle.get();
 	if (menu)
@@ -1503,29 +1505,21 @@ BOOL LLTextEditor::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 = mWText;
-			
-			if (isPartOfWord(text[wordEnd]) && !mReadOnly)
+			if (is_word_part)
 			{
-				// Select word the cursor is over
-				while ((wordEnd > 0) && isPartOfWord(text[wordEnd-1]))
-				{
-					wordEnd--;
-				}
-				wordStart = wordEnd;
-				//startSelection();
-
-				while ((wordEnd < (S32)text.length()) && isPartOfWord( text[wordEnd] ) )
-				{
-					wordEnd++;
-				}		
+				const LLWString &text = mWText;
 				std::string selectedWord(std::string(text.begin(), text.end()).substr(wordStart,wordEnd-wordStart));
+
 				if (!glggHunSpell->isSpelledRight(selectedWord))
 				{
 					//misspelled word here, and you have just right clicked on it!
@@ -4964,6 +4958,8 @@ void LLTextEditor::setTextEditorParameters(LLXMLNodePtr node)
 
 	node->getAttributeBOOL("spell_check", mSpellCheckable);
 
+	node->getAttributeBOOL("allow_translate", mAllowTranslate);
+
 	LLColor4 color;
 	if (LLUICtrlFactory::getAttributeColor(node,"cursor_color", color)) 
 	{
diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h
index f6669c4..3269e17 100644
--- a/linden/indra/llui/lltexteditor.h
+++ b/linden/indra/llui/lltexteditor.h
@@ -530,6 +530,7 @@ private:
 	std::vector<S32> misspellLocations;     // where all the mispelled words are
 	BOOL			mSpellCheckable;			// set in xui as "spell_check". Default value for a field
 	BOOL			mShowMisspellings;		// show misspellings as highlighted (initialized in the ctor)
+	BOOL			mAllowTranslate;		// set in xui as "allow_translate".
 	
 	S32				mMaxTextByteLength;		// Maximum length mText is allowed to be in bytes
 
-- 
cgit v1.1