summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2015-12-06 21:31:56 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2015-12-06 21:37:32 +0200
commit4d3d266e8a47715268cbec1b5e5b8d9fecc54cf6 (patch)
tree3ed7765d752bd2c90dbef5b6d3a4d863ed3fc2f1 /framework
parent0daed9b52fb74b090295a8e079664956785e02c2 (diff)
ThesaurusMenuController improvements
- The method to fill the menu shouldn't override impl_setPopupMenu from the base class, because we can't fill the menu before getting some data through status updates. - Use vcl::CommandInfoProvider to get menu labels. Change-Id: Ieeeafb81921bc4786256aae4e26d87c6106e63da
Diffstat (limited to 'framework')
-rw-r--r--framework/source/uielement/thesaurusmenucontroller.cxx59
1 files changed, 8 insertions, 51 deletions
diff --git a/framework/source/uielement/thesaurusmenucontroller.cxx b/framework/source/uielement/thesaurusmenucontroller.cxx
index 8c1111b94869..41601e3ee7d1 100644
--- a/framework/source/uielement/thesaurusmenucontroller.cxx
+++ b/framework/source/uielement/thesaurusmenucontroller.cxx
@@ -17,14 +17,13 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
-#include <comphelper/processfactory.hxx>
#include <svl/lngmisc.hxx>
#include <svtools/popupmenucontrollerbase.hxx>
#include <unotools/lingucfg.hxx>
+#include <vcl/commandinfoprovider.hxx>
#include <vcl/image.hxx>
#include <vcl/menu.hxx>
-#include <com/sun/star/frame/theUICommandDescription.hpp>
#include <com/sun/star/linguistic2/LinguServiceManager.hpp>
class ThesaurusMenuController : public svt::PopupMenuControllerBase
@@ -41,7 +40,7 @@ public:
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( css::uno::RuntimeException, std::exception ) override;
private:
- virtual void impl_setPopupMenu() override;
+ void fillPopupMenu();
void getMeanings( std::vector< OUString >& rSynonyms, const OUString& rWord, const css::lang::Locale& rLocale, size_t nMaxSynonms );
OUString getThesImplName( const css::lang::Locale& rLocale ) const;
css::uno::Reference< css::linguistic2::XLinguServiceManager2 > m_xLinguServiceManager;
@@ -49,49 +48,6 @@ private:
OUString m_aLastWord;
};
-namespace {
-
-OUString RetrieveLabelFromCommand( const OUString& rCmdURL, const OUString& rModuleName )
-{
- if ( rCmdURL.isEmpty() || rModuleName.isEmpty() )
- return OUString();
-
- css::uno::Any a;
- css::uno::Sequence< css::beans::PropertyValue > aPropSeq;
- try
- {
- css::uno::Reference< css::container::XNameAccess > const xNameAccess(
- css::frame::theUICommandDescription::get( comphelper::getProcessComponentContext() ), css::uno::UNO_QUERY_THROW );
- a = xNameAccess->getByName( rModuleName );
- css::uno::Reference< css::container::XNameAccess > xUICommandLabels;
- a >>= xUICommandLabels;
- a = xUICommandLabels->getByName( rCmdURL );
- a >>= aPropSeq;
- }
- catch ( const css::uno::Exception& )
- {
- SAL_WARN( "fwk.uielement", "Failed to get label for command " << rCmdURL );
- }
-
- OUString aLabel;
- for ( const auto& aProp : aPropSeq )
- {
- if ( aProp.Name == "Label" )
- {
- aProp.Value >>= aLabel;
- }
- else if ( aProp.Name == "PopupLabel" )
- {
- OUString aStr;
- if ( ( aProp.Value >>= aStr ) && !aStr.isEmpty() )
- return aStr;
- }
- }
- return aLabel;
-}
-
-}
-
ThesaurusMenuController::ThesaurusMenuController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) :
svt::PopupMenuControllerBase( rxContext ),
m_xLinguServiceManager( css::linguistic2::LinguServiceManager::create( rxContext ) ),
@@ -109,10 +65,10 @@ void ThesaurusMenuController::statusChanged( const css::frame::FeatureStateEvent
rEvent.State >>= m_aLastWord;
m_xPopupMenu->clear();
if ( rEvent.IsEnabled )
- impl_setPopupMenu();
+ fillPopupMenu();
}
-void ThesaurusMenuController::impl_setPopupMenu()
+void ThesaurusMenuController::fillPopupMenu()
{
OUString aText = m_aLastWord.getToken(0, '#');
OUString aIsoLang = m_aLastWord.getToken(1, '#');
@@ -135,21 +91,22 @@ void ThesaurusMenuController::impl_setPopupMenu()
if ( !aThesImplName.isEmpty() && !aSynonymsImageUrl.isEmpty() )
aImage = Image( aSynonymsImageUrl );
+ sal_uInt16 nId = 1;
for ( const auto& aSynonym : aSynonyms )
{
- const sal_uInt16 nId = pVCLMenu->GetItemCount() + 1;
OUString aItemText( linguistic::GetThesaurusReplaceText( aSynonym ) );
pVCLMenu->InsertItem( nId, aItemText );
pVCLMenu->SetItemCommand( nId, ".uno:ThesaurusFromContext?WordReplace:string=" + aItemText );
if ( !aSynonymsImageUrl.isEmpty() )
pVCLMenu->SetItemImage( nId, aImage );
+ nId++;
}
pVCLMenu->InsertSeparator();
OUString aThesaurusDialogCmd( ".uno:ThesaurusDialog" );
- pVCLMenu->InsertItem( 100, RetrieveLabelFromCommand( aThesaurusDialogCmd, m_aModuleName ) );
- pVCLMenu->SetItemCommand( 100, aThesaurusDialogCmd );
+ pVCLMenu->InsertItem( nId, vcl::CommandInfoProvider::Instance().GetPopupLabelForCommand( aThesaurusDialogCmd, m_xFrame ) );
+ pVCLMenu->SetItemCommand( nId, aThesaurusDialogCmd );
}
}