diff options
author | Thomas Lange <tl@openoffice.org> | 2009-11-25 16:52:25 +0000 |
---|---|---|
committer | Thomas Lange <tl@openoffice.org> | 2009-11-25 16:52:25 +0000 |
commit | 2523b874cd4bad0618a1b20d41fa3fdff3a3f4f4 (patch) | |
tree | 62209ce27daa94ce0fdc18d8ebc1e52304bff2ae /sw/source/ui/shells | |
parent | 388486a510c8f5b04132a614fa5f2c330d229248 (diff) |
#i51258# thesaurus for right click context menu
Diffstat (limited to 'sw/source/ui/shells')
-rwxr-xr-x | sw/source/ui/shells/annotsh.cxx | 42 | ||||
-rw-r--r-- | sw/source/ui/shells/drwtxtex.cxx | 168 | ||||
-rw-r--r-- | sw/source/ui/shells/drwtxtsh.cxx | 2 | ||||
-rw-r--r-- | sw/source/ui/shells/textsh1.cxx | 52 |
4 files changed, 185 insertions, 79 deletions
diff --git a/sw/source/ui/shells/annotsh.cxx b/sw/source/ui/shells/annotsh.cxx index 38d3ca021a72..6e8bc651c1ff 100755 --- a/sw/source/ui/shells/annotsh.cxx +++ b/sw/source/ui/shells/annotsh.cxx @@ -30,14 +30,17 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" + #include <hintids.hxx> -#include <tools/shl.hxx> #include <com/sun/star/i18n/TransliterationModules.hpp> #include <com/sun/star/i18n/TransliterationModulesExtra.hpp> #include <com/sun/star/i18n/TextConversionOption.hpp> #include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> #include <com/sun/star/lang/XInitialization.hpp> + +#include <tools/shl.hxx> +#include <i18npool/mslangid.hxx> #include <sfx2/objface.hxx> #include <sfx2/viewfrm.hxx> #include <sfx2/bindings.hxx> @@ -121,8 +124,8 @@ #include <docsh.hxx> #include <svtools/undo.hxx> -#include "swabstdlg.hxx" //CHINA001 -#include "chrdlg.hrc" //CHINA001 +#include "swabstdlg.hxx" +#include "chrdlg.hrc" #include "misc.hrc" #include <app.hrc> @@ -1132,7 +1135,17 @@ void SwAnnotationShell::ExecLingu(SfxRequest &rReq) bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,rView,rSh); break; } - case FN_THESAURUS_DLG: + case SID_THES: + { + String aReplaceText; + SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False ); + if (pItem2) + aReplaceText = pItem2->GetValue(); + if (aReplaceText.Len() > 0) + ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText ); + break; + } + case SID_THESAURUS: { pOLV->StartThesaurus(); break; @@ -1240,8 +1253,25 @@ void SwAnnotationShell::GetLinguState(SfxItemSet &rSet) SwLangHelper::GetLanguageStatus(pOLV,rSet); break; } + + case SID_THES: + { + String aStatusVal; + LanguageType nLang = LANGUAGE_NONE; + bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() ); + rSet.Put( SfxStringItem( SID_THES, aStatusVal ) ); + + // disable "Thesaurus" context menu entry if there is nothing to look up + uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); + lang::Locale aLocale( SvxCreateLocale( nLang ) ); + if (!bIsLookUpWord || + !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale )) + rSet.DisableItem( SID_THES ); + break; + } + // disable "Thesaurus" if the language is not supported - case FN_THESAURUS_DLG: + case SID_THESAURUS: { const SfxPoolItem &rItem = rView.GetWrtShell().GetDoc()->GetDefault( GetWhichOfScript( RES_CHRATR_LANGUAGE, @@ -1251,7 +1281,7 @@ void SwAnnotationShell::GetLinguState(SfxItemSet &rSet) uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); if (!xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( SvxCreateLocale( nLang ) )) - rSet.DisableItem( FN_THESAURUS_DLG ); + rSet.DisableItem( SID_THESAURUS ); } break; case SID_HANGUL_HANJA_CONVERSION: diff --git a/sw/source/ui/shells/drwtxtex.cxx b/sw/source/ui/shells/drwtxtex.cxx index 11874ca5b151..6e7d31297e8e 100644 --- a/sw/source/ui/shells/drwtxtex.cxx +++ b/sw/source/ui/shells/drwtxtex.cxx @@ -30,90 +30,84 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" -#include <hintids.hxx> -#include <tools/shl.hxx> -#include <svx/svdview.hxx> -#include <svx/spltitem.hxx> -#include <svx/orphitem.hxx> -#include <svx/brkitem.hxx> -#include <svx/widwitem.hxx> -#include <svx/kernitem.hxx> -#include <svx/escpitem.hxx> -#ifndef _SVX_PARAITEM_HXX //autogen -#include <svx/lspcitem.hxx> -#endif -#include <svx/adjitem.hxx> -#include <svx/crsditem.hxx> -#include <svx/shdditem.hxx> -#include <svx/hyznitem.hxx> -#include <svx/udlnitem.hxx> -#include <svx/fontitem.hxx> -#include <svx/fhgtitem.hxx> -#include <svx/colritem.hxx> -#include <svx/wghtitem.hxx> -#ifndef _SVX_CNTRITEM_HXX //autogen -#include <svx/cntritem.hxx> -#endif -#include <svx/postitem.hxx> -#include <svx/frmdiritem.hxx> -#include <svx/svdoutl.hxx> -#include <sfx2/viewfrm.hxx> -#include <svtools/whiter.hxx> -#include <svtools/cjkoptions.hxx> -#include <svtools/ctloptions.hxx> +#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> + +#include <comphelper/processfactory.hxx> +#include <i18npool/mslangid.hxx> #include <sfx2/bindings.hxx> -#include <vcl/msgbox.hxx> #include <sfx2/dispatch.hxx> #include <sfx2/request.hxx> -#include <svx/flditem.hxx> +#include <sfx2/viewfrm.hxx> +#include <svtools/cjkoptions.hxx> +#include <svtools/ctloptions.hxx> +#include <svtools/langtab.hxx> +#include <svtools/languageoptions.hxx> +#include <svtools/slstitm.hxx> +#include <svtools/whiter.hxx> +#include <svx/adjitem.hxx> +#include <svx/brkitem.hxx> +#include <svx/cntritem.hxx> +#include <svx/colritem.hxx> +#include <svx/crsditem.hxx> +#include <svx/editdata.hxx> +#include <svx/editeng.hxx> #include <svx/editstat.hxx> +#include <svx/editview.hxx> +#include <svx/eeitem.hxx> +#include <svx/escpitem.hxx> +#include <svx/fhgtitem.hxx> +#include <svx/flditem.hxx> +#include <svx/fontitem.hxx> +#include <svx/frmdiritem.hxx> #include <svx/hlnkitem.hxx> #include <svx/htmlmode.hxx> +#include <svx/hyznitem.hxx> +#include <svx/kernitem.hxx> #include <svx/langitem.hxx> -#include <svx/unolingu.hxx> +#include <svx/lspcitem.hxx> +#include <svx/orphitem.hxx> +#include <svx/outliner.hxx> +#include <svx/postitem.hxx> #include <svx/scripttypeitem.hxx> +#include <svx/shdditem.hxx> +#include <svx/spltitem.hxx> +#include <svx/svdoutl.hxx> +#include <svx/svdview.hxx> +#include <svx/udlnitem.hxx> +#include <svx/unolingu.hxx> +#include <svx/wghtitem.hxx> +#include <svx/widwitem.hxx> #include <svx/writingmodeitem.hxx> +#include <tools/shl.hxx> +#include <vcl/msgbox.hxx> +#include <vcl/outdev.hxx> +#include <vcl/window.hxx> + +#include <cmdid.h> #include <doc.hxx> -#include <wview.hxx> -#include <viewopt.hxx> -#include <wrtsh.hxx> -#include <uitool.hxx> +#include <docstat.hxx> +#include <drwtxtsh.hxx> +#include <edtwin.hxx> +#include <globals.hrc> +#include <hintids.hxx> +#include <initui.hxx> // fuer SpellPointer +#include <langhelper.hxx> #include <pardlg.hxx> +#include <shells.hrc> +#include <string.h> #include <swdtflvr.hxx> -#include <drwtxtsh.hxx> #include <swmodule.hxx> -#include <initui.hxx> // fuer SpellPointer -#include <edtwin.hxx> #include <swwait.hxx> -#include <docstat.hxx> - -#include <comphelper/processfactory.hxx> -#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> +#include <uitool.hxx> +#include <viewopt.hxx> +#include <wrtsh.hxx> +#include <wview.hxx> -#include <cmdid.h> -#include <globals.hrc> -#include <shells.hrc> #include "swabstdlg.hxx" #include "chrdlg.hrc" #include "misc.hrc" -//modified on Jul. 30th -#include <svtools/languageoptions.hxx> -#include <svx/langitem.hxx> -#include <svtools/langtab.hxx> -#include <svtools/slstitm.hxx> -#include <string.h> - -#include <svx/eeitem.hxx> -#include <svx/editeng.hxx> -#include <svx/editdata.hxx> -#include <svx/outliner.hxx> -#include <vcl/window.hxx> -#include <svx/editview.hxx> -#include <vcl/outdev.hxx> - -#include <langhelper.hxx> using namespace ::com::sun::star; @@ -151,6 +145,18 @@ void SwDrawTextShell::Execute( SfxRequest &rReq ) bRestoreSelection = SwLangHelper::SetLanguageStatus(pOLV,rReq,GetView(),rSh); break; } + + case SID_THES: + { + String aReplaceText; + SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES, sal_False ); + if (pItem2) + aReplaceText = pItem2->GetValue(); + if (aReplaceText.Len() > 0) + ReplaceTextWithSynonym( pOLV->GetEditView(), aReplaceText ); + break; + } + case SID_ATTR_CHAR_FONT: case SID_ATTR_CHAR_FONTHEIGHT: case SID_ATTR_CHAR_WEIGHT: @@ -572,7 +578,27 @@ void SwDrawTextShell::GetState(SfxItemSet& rSet) nSlotId = SwLangHelper::GetLanguageStatus(pOLV,rSet);; break; } - case SID_ATTR_PARA_ADJUST_LEFT: eAdjust = SVX_ADJUST_LEFT; goto ASK_ADJUST; + + case SID_THES: + { + String aStatusVal; + LanguageType nLang = LANGUAGE_NONE; + bool bIsLookUpWord = GetStatusValueForThesaurusFromContext( aStatusVal, nLang, pOLV->GetEditView() ); + rSet.Put( SfxStringItem( SID_THES, aStatusVal ) ); + + // disable "Thesaurus" context menu entry if there is nothing to look up + uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); + lang::Locale aLocale( SvxCreateLocale( nLang ) ); + if (!bIsLookUpWord || + !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale )) + rSet.DisableItem( SID_THES ); + + //! avoid puting the same item as SfxBoolItem at the end of this function
+ nSlotId = 0;
+ break; + } + + case SID_ATTR_PARA_ADJUST_LEFT: eAdjust = SVX_ADJUST_LEFT; goto ASK_ADJUST; case SID_ATTR_PARA_ADJUST_RIGHT: eAdjust = SVX_ADJUST_RIGHT; goto ASK_ADJUST; case SID_ATTR_PARA_ADJUST_CENTER: eAdjust = SVX_ADJUST_CENTER; goto ASK_ADJUST; case SID_ATTR_PARA_ADJUST_BLOCK: eAdjust = SVX_ADJUST_BLOCK; goto ASK_ADJUST; @@ -623,19 +649,17 @@ ASK_ESCAPE: } break; - case FN_THESAURUS_DLG: + case SID_THESAURUS: { // disable "Thesaurus" if the language is not supported const SfxPoolItem &rItem = GetShell().GetDoc()->GetDefault( GetWhichOfScript( RES_CHRATR_LANGUAGE, GetI18NScriptTypeOfLanguage( (USHORT)GetAppLanguage())) ); - LanguageType nLang = ((const SvxLanguageItem &) - rItem).GetLanguage(); - // + LanguageType nLang = ((const SvxLanguageItem &) rItem).GetLanguage(); + uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); - if (!xThes.is() || nLang == LANGUAGE_NONE || - !xThes->hasLocale( SvxCreateLocale( nLang ) )) - rSet.DisableItem( FN_THESAURUS_DLG ); + if (!xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( SvxCreateLocale( nLang ) )) + rSet.DisableItem( SID_THESAURUS ); nSlotId = 0; } break; diff --git a/sw/source/ui/shells/drwtxtsh.cxx b/sw/source/ui/shells/drwtxtsh.cxx index 40909287d8d6..9a40834daf55 100644 --- a/sw/source/ui/shells/drwtxtsh.cxx +++ b/sw/source/ui/shells/drwtxtsh.cxx @@ -400,7 +400,7 @@ void SwDrawTextShell::ExecDrawLingu(SfxRequest &rReq) { switch(rReq.GetSlot()) { - case FN_THESAURUS_DLG: + case SID_THESAURUS: pOLV->StartThesaurus(); break; diff --git a/sw/source/ui/shells/textsh1.cxx b/sw/source/ui/shells/textsh1.cxx index 736221981631..6fa27d002415 100644 --- a/sw/source/ui/shells/textsh1.cxx +++ b/sw/source/ui/shells/textsh1.cxx @@ -30,7 +30,10 @@ // MARKER(update_precomp.py): autogen include statement, do not remove #include "precompiled_sw.hxx" + +#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/ui/dialogs/XExecutableDialog.hpp> + #include <comphelper/processfactory.hxx> #include <svx/dialogs.hrc> #include <hintids.hxx> @@ -402,6 +405,23 @@ void SwTextShell::Execute(SfxRequest &rReq) break; } + case SID_THES: + { + // replace word/selection with text from selected sub menu entry + String aReplaceText; + SFX_REQUEST_ARG( rReq, pItem2, SfxStringItem, SID_THES , sal_False ); + if (pItem2) + aReplaceText = pItem2->GetValue(); + if (aReplaceText.Len() > 0) + { + SwView &rView = rWrtSh.GetView(); + const bool bSelection = rWrtSh.HasSelection();
+ const String aLookUpText = rView.GetThesaurusLookUpText( bSelection );
+ rView.InsertThesaurusSynonym( aReplaceText, aLookUpText, bSelection );
+ } + } + break; + case SID_CHARMAP: { InsertSymbol( rReq ); @@ -1380,6 +1400,38 @@ void SwTextShell::GetState( SfxItemSet &rSet ) } break; + case SID_THES: + { + // is there a valid selection to get text from?
+ String aText; + sal_Bool bValid = !rSh.HasSelection() ||
+ (rSh.IsSelOnePara() && !rSh.IsMultiSelection());
+ // prevent context menu from showing when cursor is not in or at the end of a word
+ // (GetCurWord will return the next word if there is none at the current position...)
+ const sal_Int16 nWordType = ::i18n::WordType::DICTIONARY_WORD;
+ bool bWord = rSh.IsInWord( nWordType ) || rSh.IsStartWord( nWordType ) || rSh.IsEndWord( nWordType );
+ if (bValid && bWord) + aText = rSh.HasSelection()? rSh.GetSelTxt() : rSh.GetCurWord();
+ + LanguageType nLang = rSh.GetCurLang(); + lang::Locale aLocale = SvxCreateLocale( nLang ); + String aLangText( MsLangId::convertLanguageToIsoString( nLang ) ); + + // set word and locale to look up as status value
+ String aStatusVal( aText );
+ aStatusVal.AppendAscii( "#" );
+ aStatusVal += aLangText;
+
+ rSet.Put( SfxStringItem( SID_THES, aStatusVal ) );
+ + // disable "Thesaurus" context menu entry if there is nothing to look up + uno::Reference< linguistic2::XThesaurus > xThes( ::GetThesaurus() ); + if (aText.Len() == 0 || + !xThes.is() || nLang == LANGUAGE_NONE || !xThes->hasLocale( aLocale )) + rSet.DisableItem( SID_THES ); + } + break; + case FN_NUMBER_NEWSTART : if(!rSh.GetCurNumRule()) rSet.DisableItem(nWhich); |