From 13b1fd24af265af8eb14585121958bf1e4bc89fd Mon Sep 17 00:00:00 2001 From: thickbrick Date: Tue, 28 Sep 2010 18:06:43 +0200 Subject: Context menu translator: - Don't hide the translate menu, instead only enable the options that make sense in the context (translate languages, copy/paste/etc.) - Made highlighting misspellings a global option, with immediate effect. - Convert newview/lgghunspell_wrapper.cpp to UTF-8. --- linden/indra/llui/lllineeditor.cpp | 127 +++++++++++++++++---------- linden/indra/llui/lllineeditor.h | 19 ++-- linden/indra/llui/lltexteditor.cpp | 125 ++++++++++++++++---------- linden/indra/llui/lltexteditor.h | 12 ++- linden/indra/newview/lgghunspell_wrapper.cpp | 18 ++-- linden/indra/newview/lgghunspell_wrapper.h | 4 +- 6 files changed, 189 insertions(+), 116 deletions(-) (limited to 'linden') diff --git a/linden/indra/llui/lllineeditor.cpp b/linden/indra/llui/lllineeditor.cpp index 8d88ce9..49fe3be 100644 --- a/linden/indra/llui/lllineeditor.cpp +++ b/linden/indra/llui/lllineeditor.cpp @@ -175,7 +175,6 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, mImage( sImage ), mReplaceNewlinesWithSpaces( TRUE ), mSpellCheckable( FALSE ), - mShowMisspellings(FALSE), mAllowTranslate(TRUE) { llassert( max_length_bytes > 0 ); @@ -215,12 +214,6 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, } mImage = sImage; - // in other words, highlighting requires a restart - if (glggHunSpell->getSpellCheckHighlight()) - { - mShowMisspellings = TRUE; - } - // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -228,46 +221,49 @@ LLLineEditor::LLLineEditor(const std::string& name, const LLRect& rect, { menu = new LLMenuGL(LLStringUtil::null); }*/ - menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + + menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); + menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); + menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); //menu->setBackgroundColor(gColors.getColor("MenuPopupBgColor")); @@ -443,7 +439,7 @@ void LLLineEditor::setText(const LLStringExplicit &new_text) // Picks a new cursor position based on the actual screen size of text being drawn. -S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) +S32 LLLineEditor::calculateCursorFromMouse( S32 local_mouse_x ) const { const llwchar* wtext = mText.getWString().c_str(); LLWString asterix_text; @@ -521,17 +517,30 @@ void LLLineEditor::deselect() mIsSelecting = FALSE; } +BOOL LLLineEditor::context_enable_cut(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canCut()); +} void LLLineEditor::context_cut(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->cut(); } + +BOOL LLLineEditor::context_enable_copy(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line &&line->canCopy()); +} + void LLLineEditor::context_copy(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->copy(); } + void LLLineEditor::spell_correct(void* data) { SpellMenuBind* tempBind = (SpellMenuBind*)data; @@ -544,7 +553,13 @@ void LLLineEditor::spell_correct(void* data) } } -void LLLineEditor::translateText(void * data) +BOOL LLLineEditor::context_enable_translate(void* data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + return (t && t->origin && t->origin->canTranslate()); +} + +void LLLineEditor::context_translate(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLLineEditor* line = t->origin; @@ -579,16 +594,10 @@ void LLLineEditor::spell_show(void * data) SpellMenuBind* tempBind = (SpellMenuBind*)data; LLLineEditor* line = tempBind->origin; - if( tempBind && line) + if (tempBind && line) { - if (tempBind->word == "Show Misspellings") - { - line->mShowMisspellings = TRUE; - } - else - { - line->mShowMisspellings = FALSE; - } + BOOL show = (tempBind->word == "Show Misspellings"); + glggHunSpell->setSpellCheckHighlight(show); } } @@ -648,18 +657,36 @@ void LLLineEditor::spell_add(void* data) } } +BOOL LLLineEditor::context_enable_paste(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canPaste()); +} + void LLLineEditor::context_paste(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->paste(); } +BOOL LLLineEditor::context_enable_delete(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canDoDelete()); +} + void LLLineEditor::context_delete(void* data) { LLLineEditor* line = (LLLineEditor*)data; if(line)line->doDelete(); } +BOOL LLLineEditor::context_enable_selectall(void* data) +{ + LLLineEditor* line = (LLLineEditor*)data; + return (line && line->canSelectAll()); +} + void LLLineEditor::context_selectall(void* data) { LLLineEditor* line = (LLLineEditor*)data; @@ -787,16 +814,12 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - 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 + menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { // search for word matches + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); if (is_word_part) { const LLWString& text = mText.getWString(); @@ -806,7 +829,6 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) { //misspelled word here, and you have just right clicked on it! std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); - //menu->setItemVisible("Transep",(suggs.size()>0)); for (int i = 0; i<(int)suggs.size() ;i++) { @@ -837,7 +859,7 @@ BOOL LLLineEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -1370,6 +1392,15 @@ void LLLineEditor::translationReplace(const std::string &translation, const S32 setCursor(pos + text_wlen); } +BOOL LLLineEditor::canTranslate() const +{ + // if allow_translate="true" in xui, and if other factors permit, we allow it + S32 pos = calculateCursorFromMouse(mLastContextMenuX); + const LLWString& wtext = getWText(); + bool is_word_part = (pos > -1) && LLTextEditor::isPartOfWord(wtext[pos]); + return (mAllowTranslate && !mReadOnly && (is_word_part || hasSelection())); +} + void LLLineEditor::insert(std::string what, S32 wher) { LLLineEditorRollback rollback(this); @@ -1980,7 +2011,7 @@ void LLLineEditor::drawMisspelled(LLRect background) } } - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i =0; i<(int)misspellLocations.size(); i++) { diff --git a/linden/indra/llui/lllineeditor.h b/linden/indra/llui/lllineeditor.h index 0ad415a..f9e0621 100644 --- a/linden/indra/llui/lllineeditor.h +++ b/linden/indra/llui/lllineeditor.h @@ -108,6 +108,7 @@ public: virtual void spellReplace(SpellMenuBind* spellData); virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); + virtual BOOL canTranslate() const; virtual void insert(std::string what,S32 wher); // LLEditMenuHandler overrides @@ -134,15 +135,22 @@ public: virtual void deselect(); virtual BOOL canDeselect() const; + static BOOL context_enable_cut(void* data); static void context_cut(void* data); + static BOOL context_enable_copy(void* data); static void context_copy(void* data); - static void spell_correct(void* data); - static void spell_show(void* data); - static void translateText(void * data); - static void spell_add(void* data); + static BOOL context_enable_paste(void* data); static void context_paste(void* data); + static BOOL context_enable_delete(void* data); static void context_delete(void* data); + static BOOL context_enable_selectall(void* data); static void context_selectall(void* data); + static BOOL context_enable_translate(void * data); + static void context_translate(void * data); + static void spell_correct(void* data); + static void spell_show(void* data); + static void spell_add(void* data); + std::vector getMisspelledWordsPositions(); // view overrides virtual void draw(); @@ -264,7 +272,7 @@ private: void removeChar(); void addChar(const llwchar c); void setCursorAtLocalPos(S32 local_mouse_x); - S32 calculateCursorFromMouse(S32 local_mouse_x); + S32 calculateCursorFromMouse(S32 local_mouse_x) const; S32 findPixelNearestPos(S32 cursor_offset = 0) const; void reportBadKeystroke(); BOOL handleSpecialKey(KEY key, MASK mask); @@ -297,7 +305,6 @@ protected: S32 mStartSpellHere; // the position of the first char on the screen, stored so we know when to update S32 mEndSpellHere; // the location of the last char on the screen BOOL mSpellCheckable; // set in xui as "spell_check". Default value for a field - BOOL mShowMisspellings; // show misspellings as highlighted (initialized in the ctor) LLFrameTimer mSpellTimer; //to keep track of what we have to remove before showing menu std::vector suggestionMenuItems; diff --git a/linden/indra/llui/lltexteditor.cpp b/linden/indra/llui/lltexteditor.cpp index e2335c9..8dcb014 100644 --- a/linden/indra/llui/lltexteditor.cpp +++ b/linden/indra/llui/lltexteditor.cpp @@ -330,7 +330,6 @@ LLTextEditor::LLTextEditor( mReflowNeeded(FALSE), mScrollNeeded(FALSE), mSpellCheckable(FALSE), - mShowMisspellings(FALSE), mAllowTranslate(TRUE) { mSourceID.generate(); @@ -384,12 +383,6 @@ LLTextEditor::LLTextEditor( mParseHTML=FALSE; mHTML.clear(); - // in other words, highlighting requires a restart - if (glggHunSpell->getSpellCheckHighlight()) - { - mShowMisspellings = TRUE; - } - // make the popup menu available //LLMenuGL* menu = LLUICtrlFactory::getInstance()->buildMenu("menu_texteditor.xml", parent_view); LLMenuGL* menu = new LLMenuGL("wot"); @@ -397,46 +390,46 @@ LLTextEditor::LLTextEditor( { menu = new LLMenuGL(LLStringUtil::null); }*/ - menu->append(new LLMenuItemCallGL("Cut", context_cut, NULL, this)); - menu->append(new LLMenuItemCallGL("Copy", context_copy, NULL, this)); - menu->append(new LLMenuItemCallGL("Paste", context_paste, NULL, this)); - menu->append(new LLMenuItemCallGL("Delete", context_delete, NULL, this)); - menu->append(new LLMenuItemCallGL("Select All", context_selectall, NULL, this)); + menu->append(new LLMenuItemCallGL("Cut", context_cut, context_enable_cut, this)); + menu->append(new LLMenuItemCallGL("Copy", context_copy, context_enable_copy, this)); + menu->append(new LLMenuItemCallGL("Paste", context_paste, context_enable_paste, this)); + menu->append(new LLMenuItemCallGL("Delete", context_delete, context_enable_delete, this)); + menu->append(new LLMenuItemCallGL("Select All", context_selectall, context_enable_selectall, this)); menu->appendSeparator("Transep"); LLMenuGL* translatemenu = new LLMenuGL("Translate To"); translatemenu->setCanTearOff(FALSE); SpellMenuBind* t=new SpellMenuBind;t->origin=this;t->word="en"; - translatemenu->append(new LLMenuItemCallGL("English",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("English", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="da"; - translatemenu->append(new LLMenuItemCallGL("Danish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Danish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="de"; - translatemenu->append(new LLMenuItemCallGL("Deutsch(German)",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Deutsch(German)", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="es"; - translatemenu->append(new LLMenuItemCallGL("Spanish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Spanish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="fr"; - translatemenu->append(new LLMenuItemCallGL("French",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("French", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="it"; - translatemenu->append(new LLMenuItemCallGL("Italian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Italian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="hu"; - translatemenu->append(new LLMenuItemCallGL("Hungarian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Hungarian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="nl"; - translatemenu->append(new LLMenuItemCallGL("Dutch",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Dutch", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pl"; - translatemenu->append(new LLMenuItemCallGL("Polish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Polish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="pt"; - translatemenu->append(new LLMenuItemCallGL("Portugese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Portugese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ru"; - translatemenu->append(new LLMenuItemCallGL("Russian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Russian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="tr"; - translatemenu->append(new LLMenuItemCallGL("Turkish",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Turkish", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="uk"; - translatemenu->append(new LLMenuItemCallGL("Ukrainian",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Ukrainian", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="zh"; - translatemenu->append(new LLMenuItemCallGL("Chinese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Chinese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ja"; - translatemenu->append(new LLMenuItemCallGL("Japanese",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Japanese", context_translate, context_enable_translate, t)); t=new SpellMenuBind;t->origin=this;t->word="ko"; - translatemenu->append(new LLMenuItemCallGL("Korean",translateText, NULL, t)); + translatemenu->append(new LLMenuItemCallGL("Korean", context_translate, context_enable_translate, t)); menu->appendMenu(translatemenu); menu->appendSeparator("Spelsep"); @@ -446,7 +439,6 @@ LLTextEditor::LLTextEditor( mPopupMenuHandle = menu->getHandle(); } - LLTextEditor::~LLTextEditor() { gFocusMgr.releaseFocusIfNeeded( this ); // calls onCommit() @@ -464,18 +456,38 @@ LLTextEditor::~LLTextEditor() std::for_each(mUndoStack.begin(), mUndoStack.end(), DeletePointer()); LLView::deleteViewByHandle(mPopupMenuHandle); } + +BOOL LLTextEditor::context_enable_cut(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canCut()); +} + void LLTextEditor::context_cut(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->cut(); } + +BOOL LLTextEditor::context_enable_copy(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canCopy()); +} + void LLTextEditor::context_copy(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->copy(); } -void LLTextEditor::translateText(void * data) +BOOL LLTextEditor::context_enable_translate(void * data) +{ + SpellMenuBind* t = (SpellMenuBind*)data; + return (t && t->origin && t->origin->canTranslate()); +} + +void LLTextEditor::context_translate(void * data) { SpellMenuBind* t = (SpellMenuBind*)data; LLTextEditor* line = t->origin; @@ -523,14 +535,8 @@ void LLTextEditor::spell_show(void * data) if (tempBind && line) { - if (tempBind->word == "Show Misspellings") - { - glggHunSpell->setSpellCheckHighlight(TRUE); - } - else - { - glggHunSpell->setSpellCheckHighlight(FALSE); - } + BOOL show = (tempBind->word == "Show Misspellings"); + glggHunSpell->setSpellCheckHighlight(show); } } @@ -582,16 +588,37 @@ void LLTextEditor::spell_add(void* data) tempBind->origin->mPrevSpelledText.erase();//make it update } } + +BOOL LLTextEditor::context_enable_paste(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return(line && line->canPaste()); +} + void LLTextEditor::context_paste(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->paste(); } + +BOOL LLTextEditor::context_enable_delete(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canDoDelete()); +} + void LLTextEditor::context_delete(void* data) { LLTextEditor* line = (LLTextEditor*)data; if(line)line->doDelete(); } + +BOOL LLTextEditor::context_enable_selectall(void* data) +{ + LLTextEditor* line = (LLTextEditor*)data; + return (line && line->canSelectAll()); +} + void LLTextEditor::context_selectall(void* data) { LLTextEditor* line = (LLTextEditor*)data; @@ -1506,16 +1533,11 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) } suggestionMenuItems.clear(); - 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 + menu->setItemVisible("Spelsep", !mReadOnly && mSpellCheckable); if (!mReadOnly && mSpellCheckable) { + bool is_word_part = getWordBoundriesAt(pos, &wordStart, &wordEnd); if (is_word_part) { const LLWString &text = mWText; @@ -1526,7 +1548,6 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) //misspelled word here, and you have just right clicked on it! std::vector suggs = glggHunSpell->getSuggestionList(selectedWord); - //menu->setItemVisible("Transep",(suggs.size()>0)); for (int i = 0; i<(int)suggs.size(); i++) { SpellMenuBind * tempStruct = new SpellMenuBind; @@ -1557,7 +1578,7 @@ BOOL LLTextEditor::handleRightMouseDown( S32 x, S32 y, MASK mask ) SpellMenuBind * tempStruct = new SpellMenuBind; tempStruct->origin = this; - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { tempStruct->word = "Hide Misspellings"; } @@ -2301,6 +2322,14 @@ void LLTextEditor::translationReplace(const std::string &translation, const S32 needsReflow(); } +BOOL LLTextEditor::canTranslate() const +{ + // if allow_translate="true" in xui, and if other factors permit, we allow it + S32 pos = getCursorPosFromLocalCoord(mLastContextMenuX, mLastContextMenuY, TRUE); + bool is_word_part = (pos > -1) && isPartOfWord(mWText[pos]); + return (mAllowTranslate && !mReadOnly && (is_word_part || hasSelection())); +} + // paste from clipboard void LLTextEditor::paste() { @@ -3225,7 +3254,7 @@ void LLTextEditor::drawMisspelled() } } //draw - if (mShowMisspellings) + if (glggHunSpell->getSpellCheckHighlight()) { for (int i = 0; i<(int)misspellLocations.size() ;i++) { diff --git a/linden/indra/llui/lltexteditor.h b/linden/indra/llui/lltexteditor.h index 3269e17..f2a831b 100644 --- a/linden/indra/llui/lltexteditor.h +++ b/linden/indra/llui/lltexteditor.h @@ -137,6 +137,7 @@ public: virtual void spellReplace(SpellMenuBind* spellData); virtual void translationReplace(const std::string &translation, const S32 orig_start, const S32 orig_length); + virtual BOOL canTranslate() const; virtual void updatePrimary(); virtual void copyPrimary(); @@ -149,13 +150,19 @@ public: virtual BOOL canSelectAll() const; virtual void deselect(); virtual BOOL canDeselect() const; - static void context_cut(void* data); + static BOOL context_enable_cut(void* data); + static void context_cut(void* data); + static BOOL context_enable_copy(void* data); static void context_copy(void* data); + static BOOL context_enable_paste(void* data); static void context_paste(void* data); + static BOOL context_enable_delete(void* data); static void context_delete(void* data); + static BOOL context_enable_selectall(void* data); static void context_selectall(void* data); - static void translateText(void * data); + static BOOL context_enable_translate(void * data); + static void context_translate(void * data); static void spell_correct(void* data); static void spell_add(void* data); static void spell_show(void* data); @@ -529,7 +536,6 @@ private: S32 spellEnd; std::vector 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 diff --git a/linden/indra/newview/lgghunspell_wrapper.cpp b/linden/indra/newview/lgghunspell_wrapper.cpp index f800043..aa4507c 100644 --- a/linden/indra/newview/lgghunspell_wrapper.cpp +++ b/linden/indra/newview/lgghunspell_wrapper.cpp @@ -72,7 +72,7 @@ static char * countryCodesraw[] = { (char*)"CF",(char*)"Central African Republic", (char*)"CG",(char*)"Congo", (char*)"CH",(char*)"Switzerland", - (char*)"CI",(char*)"Côte D'ivoire (Ivory Coast)", + (char*)"CI",(char*)"Côte D'ivoire (Ivory Coast)", (char*)"CK",(char*)"Cook Iislands", (char*)"CL",(char*)"Chile", (char*)"CM",(char*)"Cameroon", @@ -212,7 +212,7 @@ static char * countryCodesraw[] = { (char*)"PW",(char*)"Palau", (char*)"PY",(char*)"Paraguay", (char*)"QA",(char*)"Qatar", - (char*)"RE",(char*)"Réunion", + (char*)"RE",(char*)"Réunion", (char*)"RO",(char*)"Romania", (char*)"RU",(char*)"Russian Federation", (char*)"RW",(char*)"Rwanda", @@ -333,7 +333,7 @@ static char * languageCodesraw[]={ (char*)"ga",(char*)"Irish", (char*)"gd",(char*)"Gaelic", (char*)"gl",(char*)"Galician", - (char*)"gn",(char*)"Guaraní", + (char*)"gn",(char*)"Guaraní", (char*)"gu",(char*)"Gujarati", (char*)"gv",(char*)"Manx", (char*)"ha",(char*)"Hausa", @@ -456,7 +456,7 @@ static char * languageCodesraw[]={ (char*)"uz",(char*)"Uzbek", (char*)"ve",(char*)"Venda", (char*)"vi",(char*)"Vietnamese", - (char*)"vo",(char*)"Volapük", + (char*)"vo",(char*)"Volapük", (char*)"wa",(char*)"Walloon", (char*)"wo",(char*)"Wolof", (char*)"xh",(char*)"Xhosa", @@ -470,10 +470,9 @@ static char * languageCodesraw[]={ #define LANGUAGE_CODES_RAW_SIZE 368 lggHunSpell_Wrapper::lggHunSpell_Wrapper() - : - mSpellCheckHighlight(false) { //languageCodes(begin(languageCodesraw), end(languageCodesraw)); + mSpellCheckHighlight = rebind_llcontrol("EmeraldSpellDisplay", &gSavedSettings, false); } lggHunSpell_Wrapper::~lggHunSpell_Wrapper() @@ -638,8 +637,6 @@ void lggHunSpell_Wrapper::processSettings() //expects everything to already be in saved settings //this will also reload and read the installed dicts setNewDictionary(gSavedSettings.getString("EmeraldSpellBase")); - mSpellCheckHighlight = gSavedSettings.getBOOL("EmeraldSpellDisplay"); - } void lggHunSpell_Wrapper::addDictionary(std::string additionalDictionary) @@ -966,5 +963,8 @@ void lggHunSpell_Wrapper::editCustomButton() void lggHunSpell_Wrapper::setSpellCheckHighlight(BOOL highlight) { - mSpellCheckHighlight = highlight; + if (mSpellCheckHighlight) + { + *mSpellCheckHighlight = highlight; + } } diff --git a/linden/indra/newview/lgghunspell_wrapper.h b/linden/indra/newview/lgghunspell_wrapper.h index b5f3ddb..71b2f14 100644 --- a/linden/indra/newview/lgghunspell_wrapper.h +++ b/linden/indra/newview/lgghunspell_wrapper.h @@ -55,7 +55,7 @@ public: std::string VEC2CSV(std::vector vec); void setSpellCheckHighlight(BOOL highlight); - BOOL getSpellCheckHighlight() { return mSpellCheckHighlight; } + BOOL getSpellCheckHighlight() { return mSpellCheckHighlight && *mSpellCheckHighlight; } private: void createCustomDic(); @@ -67,7 +67,7 @@ private: std::string currentBaseDic; //std::vector languageCodes; //std::vector countryCodes; - BOOL mSpellCheckHighlight; + BOOL* mSpellCheckHighlight; }; extern lggHunSpell_Wrapper* glggHunSpell; // the singleton hunspell wrapper -- cgit v1.1