[Libreoffice-commits] core.git: framework/source

Maxim Monastirsky momonasmon at gmail.com
Sun Dec 6 11:39:05 PST 2015


 framework/source/uielement/thesaurusmenucontroller.cxx |   59 ++---------------
 1 file changed, 8 insertions(+), 51 deletions(-)

New commits:
commit 4d3d266e8a47715268cbec1b5e5b8d9fecc54cf6
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Sun Dec 6 21:31:56 2015 +0200

    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

diff --git a/framework/source/uielement/thesaurusmenucontroller.cxx b/framework/source/uielement/thesaurusmenucontroller.cxx
index 8c1111b..41601e3 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 );
     }
 }
 


More information about the Libreoffice-commits mailing list