From 099f1016fa507809e24f0874848f6107a08a4fb0 Mon Sep 17 00:00:00 2001 From: Samuel Mehrbrodt Date: Fri, 13 Nov 2015 17:00:03 +0100 Subject: Cleanup: Consolidate the different ways to get command labels/tooltips Change-Id: Ieab809a3122c9d592894b84ec2e68195a4e02dde --- compilerplugins/clang/store/deletedspecial.cxx | 2 +- framework/source/uielement/toolbarmanager.cxx | 125 +-------- include/sfx2/sidebar/CommandInfoProvider.hxx | 94 ------- include/sfx2/sidebar/ControllerItem.hxx | 5 - include/svtools/commandinfoprovider.hxx | 112 ++++++++ sfx2/Library_sfx.mk | 1 - sfx2/source/sidebar/CommandInfoProvider.cxx | 302 --------------------- sfx2/source/sidebar/ControllerFactory.cxx | 8 +- sfx2/source/sidebar/ControllerItem.cxx | 11 +- svtools/Library_svt.mk | 1 + svtools/source/misc/commandinfoprovider.cxx | 317 ++++++++++++++++++++++ svx/source/sidebar/insert/InsertPropertyPanel.cxx | 1 - 12 files changed, 442 insertions(+), 537 deletions(-) delete mode 100644 include/sfx2/sidebar/CommandInfoProvider.hxx create mode 100644 include/svtools/commandinfoprovider.hxx delete mode 100644 sfx2/source/sidebar/CommandInfoProvider.cxx create mode 100644 svtools/source/misc/commandinfoprovider.cxx diff --git a/compilerplugins/clang/store/deletedspecial.cxx b/compilerplugins/clang/store/deletedspecial.cxx index b1329229e2fc..ff82f7eefedb 100644 --- a/compilerplugins/clang/store/deletedspecial.cxx +++ b/compilerplugins/clang/store/deletedspecial.cxx @@ -118,7 +118,7 @@ bool DeletedSpecial::VisitCXXMethodDecl(CXXMethodDecl const * decl) { || whitelist(decl, "sd::IconCache", "sd/source/ui/inc/tools/IconCache.hxx") || whitelist(decl, "sd::RemoteServer", "sd/source/ui/inc/RemoteServer.hxx") || whitelist(decl, "sd::slidesorter::cache::PageCacheManager", "sd/source/ui/slidesorter/inc/cache/SlsPageCacheManager.hxx") - || whitelist(decl, "sfx2::sidebar::CommandInfoProvider", "include/sfx2/sidebar/CommandInfoProvider.hxx") + || whitelist(decl, "svt::CommandInfoProvider", "include/svt/commandinfoprovider.hxx") || whitelist(decl, "vcl::SettingsConfigItem", "include/vcl/configsettings.hxx") || whitelist(decl, "writerfilter::ooxml::OOXMLFactory", "writerfilter/source/ooxml/OOXMLFactory.hxx")) { diff --git a/framework/source/uielement/toolbarmanager.cxx b/framework/source/uielement/toolbarmanager.cxx index a60589b9561d..ee792f73b567 100644 --- a/framework/source/uielement/toolbarmanager.cxx +++ b/framework/source/uielement/toolbarmanager.cxx @@ -69,9 +69,9 @@ #include #include +#include #include #include -#include // namespaces @@ -1272,8 +1272,8 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine if (( nType == css::ui::ItemType::DEFAULT ) && !aCommandURL.isEmpty() ) { - OUString aString( RetrieveFromCommand( "Name", aCommandURL )); - OUString aTooltipFromCommand( RetrieveFromCommand( "TooltipLabel", aCommandURL )); + OUString aString(svt::CommandInfoProvider::Instance().GetLabelForCommand(aCommandURL, m_xFrame)); + OUString aTooltipFromCommand(svt::CommandInfoProvider::Instance().GetTooltipForCommand(aCommandURL, m_xFrame, false)); ToolBoxItemBits nItemBits = ConvertStyleToToolboxItemBits( nStyle ); if ( aMenuDesc.is() ) @@ -1289,8 +1289,8 @@ void ToolBarManager::FillToolbar( const Reference< XIndexAccess >& rItemContaine sQuickHelp = aTooltip; else if ( !aTooltipFromCommand.isEmpty() ) // Tooltip from uno command (TooltipLabel) sQuickHelp = aTooltipFromCommand; - OUString sShortCut; - if( RetrieveShortcut( aCommandURL, sShortCut ) ) + OUString sShortCut = svt::CommandInfoProvider::Instance().GetCommandShortcut(aCommandURL, m_xFrame); + if( !sShortCut.isEmpty() ) { sQuickHelp += " ("; sQuickHelp += sShortCut; @@ -2167,121 +2167,6 @@ Image ToolBarManager::QueryAddonsImage( const OUString& aCommandURL, bool bBigIm Image aImage = framework::AddonsOptions().GetImageFromURL( aCommandURL, bBigImages ); return aImage; } - -bool ToolBarManager::impl_RetrieveShortcutsFromConfiguration( - const Reference< XAcceleratorConfiguration >& rAccelCfg, - const OUString& rCommand, - OUString& rShortCut ) -{ - if ( rAccelCfg.is() ) - { - try - { - css::awt::KeyEvent aKeyEvent; - Sequence< OUString > aCommands { rCommand }; - - Sequence< Any > aSeqKeyCode( rAccelCfg->getPreferredKeyEventsForCommandList( aCommands ) ); - if( aSeqKeyCode.getLength() == 1 ) - { - if ( aSeqKeyCode[0] >>= aKeyEvent ) - { - rShortCut = svt::AcceleratorExecute::st_AWTKey2VCLKey( aKeyEvent ).GetName(); - return true; - } - } - } - catch (const IllegalArgumentException&) - { - } - } - - return false; -} - -bool ToolBarManager::RetrieveShortcut( const OUString& rCommandURL, OUString& rShortCut ) -{ - if ( m_bModuleIdentified ) - { - Reference< XAcceleratorConfiguration > xDocAccelCfg( m_xDocAcceleratorManager ); - Reference< XAcceleratorConfiguration > xModuleAccelCfg( m_xModuleAcceleratorManager ); - Reference< XAcceleratorConfiguration > xGlobalAccelCfg( m_xGlobalAcceleratorManager ); - - if ( !m_bAcceleratorCfg ) - { - // Retrieve references on demand - m_bAcceleratorCfg = true; - if ( !xDocAccelCfg.is() ) - { - Reference< XController > xController = m_xFrame->getController(); - Reference< XModel > xModel; - if ( xController.is() ) - { - xModel = xController->getModel(); - if ( xModel.is() ) - { - Reference< XUIConfigurationManagerSupplier > xSupplier( xModel, UNO_QUERY ); - if ( xSupplier.is() ) - { - Reference< XUIConfigurationManager > xDocUICfgMgr( xSupplier->getUIConfigurationManager(), UNO_QUERY ); - if ( xDocUICfgMgr.is() ) - { - xDocAccelCfg = xDocUICfgMgr->getShortCutManager(); - m_xDocAcceleratorManager = xDocAccelCfg; - } - } - } - } - } - - if ( !xModuleAccelCfg.is() ) - { - Reference< XModuleUIConfigurationManagerSupplier > xModuleCfgMgrSupplier = - theModuleUIConfigurationManagerSupplier::get( m_xContext ); - try - { - Reference< XUIConfigurationManager > xUICfgMgr = xModuleCfgMgrSupplier->getUIConfigurationManager( m_aModuleIdentifier ); - if ( xUICfgMgr.is() ) - { - xModuleAccelCfg = xUICfgMgr->getShortCutManager(); - m_xModuleAcceleratorManager = xModuleAccelCfg; - } - } - catch (const RuntimeException&) - { - throw; - } - catch (const Exception&) - { - } - } - - if ( !xGlobalAccelCfg.is() ) try - { - xGlobalAccelCfg = GlobalAcceleratorConfiguration::create( m_xContext ); - m_xGlobalAcceleratorManager = xGlobalAccelCfg; - } - catch ( const css::uno::DeploymentException& ) - { - SAL_WARN("fwk.uielement", "GlobalAcceleratorConfiguration" - " not available. This should happen only on mobile platforms."); - } - } - - bool bFound = false; - - if ( m_xGlobalAcceleratorManager.is() ) - bFound = impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); - if ( !bFound && m_xModuleAcceleratorManager.is() ) - bFound = impl_RetrieveShortcutsFromConfiguration( xModuleAccelCfg, rCommandURL, rShortCut ); - if ( !bFound && m_xDocAcceleratorManager.is() ) - impl_RetrieveShortcutsFromConfiguration( xGlobalAccelCfg, rCommandURL, rShortCut ); - - if( bFound ) - return true; - } - return false; -} - } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/sidebar/CommandInfoProvider.hxx b/include/sfx2/sidebar/CommandInfoProvider.hxx deleted file mode 100644 index 9161b126816a..000000000000 --- a/include/sfx2/sidebar/CommandInfoProvider.hxx +++ /dev/null @@ -1,94 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ -#ifndef INCLUDED_SFX2_SIDEBAR_COMMANDINFOPROVIDER_HXX -#define INCLUDED_SFX2_SIDEBAR_COMMANDINFOPROVIDER_HXX - -#include - -#include -#include -#include - - -namespace sfx2 { namespace sidebar { - -/** Provide information about UNO commands like tooltip text with - keyboard accelerator. -*/ -class SFX2_DLLPUBLIC CommandInfoProvider -{ -public: - /** Return the singleton instance. - - It caches some objects for the last XFrame object given to - GetLabelForCommand. These objects are release and created new - when that method is called with a different XFrame from the - last call. - - Lifetime control should work but could be more elegant. - */ - static CommandInfoProvider& Instance(); - - /** Return a label for the given command. - @param rsCommandName - The command name is expected to start with .uno: - @param rxFrame - The frame is used to identify the module and document. - @return - The returned label contains the keyboard accelerator, if - one is defined. - */ - ::rtl::OUString GetLabelForCommand ( - const ::rtl::OUString& rsCommandName, - const css::uno::Reference& rxFrame); - - /** Do not call. Should be part of a local and hidden interface. - */ - void SetFrame (const css::uno::Reference& rxFrame); - - private: - css::uno::Reference mxContext; - css::uno::Reference mxCachedDataFrame; - css::uno::Reference mxCachedDocumentAcceleratorConfiguration; - css::uno::Reference mxCachedModuleAcceleratorConfiguration; - css::uno::Reference mxCachedGlobalAcceleratorConfiguration; - ::rtl::OUString msCachedModuleIdentifier; - css::uno::Reference mxFrameListener; - - CommandInfoProvider(); - ~CommandInfoProvider(); - - css::uno::Reference GetDocumentAcceleratorConfiguration(); - css::uno::Reference GetModuleAcceleratorConfiguration(); - css::uno::Reference GetGlobalAcceleratorConfiguration(); - ::rtl::OUString GetModuleIdentifier(); - ::rtl::OUString GetCommandShortcut (const ::rtl::OUString& rCommandName); - css::uno::Sequence GetCommandProperties ( - const ::rtl::OUString& rsCommandName); - ::rtl::OUString GetCommandLabel (const ::rtl::OUString& rsCommandName); - static rtl::OUString RetrieveShortcutsFromConfiguration( - const css::uno::Reference& rxConfiguration, - const rtl::OUString& rsCommandName); -}; - -} } // end of namespace sfx2/framework - -#endif - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/include/sfx2/sidebar/ControllerItem.hxx b/include/sfx2/sidebar/ControllerItem.hxx index 94e22e0c2d6b..2c31f8be3481 100644 --- a/include/sfx2/sidebar/ControllerItem.hxx +++ b/include/sfx2/sidebar/ControllerItem.hxx @@ -94,11 +94,6 @@ public: */ void RequestUpdate(); - /** Return the label for the command. It contains the keyboard - accelerator when one exists. - */ - ::rtl::OUString GetLabel() const; - /** Return the extended help text for the command. Returns an empty string when the UNO command name is not available. */ diff --git a/include/svtools/commandinfoprovider.hxx b/include/svtools/commandinfoprovider.hxx new file mode 100644 index 000000000000..6c0431bf7d7c --- /dev/null +++ b/include/svtools/commandinfoprovider.hxx @@ -0,0 +1,112 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ +#ifndef INCLUDED_COMPHELPER_COMMANDINFOPROVIDER_HXX +#define INCLUDED_COMPHELPER_COMMANDINFOPROVIDER_HXX + +#include + +#include +#include +#include + + +namespace svt { + +/** Provide information about UNO commands like tooltip text with + keyboard accelerator. +*/ +class SVT_DLLPUBLIC CommandInfoProvider +{ +public: + /** Return the singleton instance. + + It caches some objects for the last XFrame object given to + GetLabelForCommand. These objects are release and created new + when that method is called with a different XFrame from the + last call. + + Lifetime control should work but could be more elegant. + */ + static CommandInfoProvider& Instance(); + + /** Return a label for the given command. + @param rsCommandName + The command name is expected to start with .uno: + @param rxFrame + The frame is used to identify the module and document. + @return + The command labe. + */ + OUString GetLabelForCommand ( + const OUString& rsCommandName, + const css::uno::Reference& rxFrame); + + /** Return a tooltip for the given command. Falls back to label if command has no tooltip. + @param rsCommandName + The command name is expected to start with .uno: + @param rxFrame + The frame is used to identify the module and document. + @param bIncludeShortcut + Whether the shortcut should be appended in brackets + @return + The returned label contains the keyboard accelerator, if + one is defined and bIncludeShortcut is true. + */ + OUString GetTooltipForCommand ( + const OUString& rsCommandName, + const css::uno::Reference& rxFrame, + bool bIncludeShortcut = true); + + /** Returns the shortcut for a command in human-readable form */ + OUString GetCommandShortcut (const OUString& rCommandName, + const css::uno::Reference& rxFrame); + + /** Do not call. Should be part of a local and hidden interface. + */ + void SetFrame (const css::uno::Reference& rxFrame); + + private: + css::uno::Reference mxContext; + css::uno::Reference mxCachedDataFrame; + css::uno::Reference mxCachedDocumentAcceleratorConfiguration; + css::uno::Reference mxCachedModuleAcceleratorConfiguration; + css::uno::Reference mxCachedGlobalAcceleratorConfiguration; + OUString msCachedModuleIdentifier; + css::uno::Reference mxFrameListener; + + CommandInfoProvider(); + ~CommandInfoProvider(); + + css::uno::Reference GetDocumentAcceleratorConfiguration(); + css::uno::Reference GetModuleAcceleratorConfiguration(); + css::uno::Reference GetGlobalAcceleratorConfiguration(); + OUString GetModuleIdentifier(); + css::uno::Sequence GetCommandProperties ( + const OUString& rsCommandName); + OUString GetCommandProperty(const OUString& rsProperty, const OUString& rsCommandName); + static OUString RetrieveShortcutsFromConfiguration( + const css::uno::Reference& rxConfiguration, + const OUString& rsCommandName); +}; + +} // end of namespace svt + +#endif // INCLUDED_COMPHELPER_COMMANDINFOPROVIDER_HXX + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 9f0bb3dad062..420a3c7cb104 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -257,7 +257,6 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/sidebar/Accessible \ sfx2/source/sidebar/AccessibleTitleBar \ sfx2/source/sidebar/AsynchronousCall \ - sfx2/source/sidebar/CommandInfoProvider \ sfx2/source/sidebar/Context \ sfx2/source/sidebar/ContextChangeBroadcaster \ sfx2/source/sidebar/ContextList \ diff --git a/sfx2/source/sidebar/CommandInfoProvider.cxx b/sfx2/source/sidebar/CommandInfoProvider.cxx deleted file mode 100644 index 1abaed1ea7fc..000000000000 --- a/sfx2/source/sidebar/CommandInfoProvider.cxx +++ /dev/null @@ -1,302 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ -/* - * This file is part of the LibreOffice project. - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * This file incorporates work covered by the following license notice: - * - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed - * with this work for additional information regarding copyright - * ownership. The ASF licenses this file to you under the Apache - * License, Version 2.0 (the "License"); you may not use this file - * except in compliance with the License. You may obtain a copy of - * the License at http://www.apache.org/licenses/LICENSE-2.0 . - */ - -#include - -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -using namespace css; -using namespace css::uno; -using ::rtl::OUString; - - -namespace -{ - typedef ::cppu::WeakComponentImplHelper < - css::lang::XEventListener - > FrameListenerInterfaceBase; - class FrameListener - : public ::cppu::BaseMutex, - public FrameListenerInterfaceBase - { - public: - FrameListener (sfx2::sidebar::CommandInfoProvider& rInfoProvider, const Reference& rxFrame) - : FrameListenerInterfaceBase(m_aMutex), - mrInfoProvider(rInfoProvider), - mxFrame(rxFrame) - { - if (mxFrame.is()) - mxFrame->addEventListener(this); - } - virtual ~FrameListener() - { - } - virtual void SAL_CALL disposing() override - { - if (mxFrame.is()) - mxFrame->removeEventListener(this); - } - virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) - throw (css::uno::RuntimeException, std::exception) override - { - (void)rEvent; - mrInfoProvider.SetFrame(nullptr); - mxFrame = nullptr; - } - - private: - sfx2::sidebar::CommandInfoProvider& mrInfoProvider; - Reference mxFrame; - }; -} - -namespace sfx2 { namespace sidebar { - -CommandInfoProvider& CommandInfoProvider::Instance() -{ - static CommandInfoProvider aProvider; - return aProvider; -} - -CommandInfoProvider::CommandInfoProvider() - : mxContext(comphelper::getProcessComponentContext()), - mxCachedDataFrame(), - mxCachedDocumentAcceleratorConfiguration(), - mxCachedModuleAcceleratorConfiguration(), - mxCachedGlobalAcceleratorConfiguration(), - msCachedModuleIdentifier(), - mxFrameListener() -{ -} - -CommandInfoProvider::~CommandInfoProvider() -{ - if (mxFrameListener.is()) - { - mxFrameListener->dispose(); - mxFrameListener = nullptr; - } -} - - -OUString CommandInfoProvider::GetLabelForCommand ( - const OUString& rsCommandName, - const Reference& rxFrame) -{ - SetFrame(rxFrame); - - const OUString sLabel (GetCommandLabel(rsCommandName)); - const OUString sShortCut (GetCommandShortcut(rsCommandName)); - if (sShortCut.getLength() > 0) - return sLabel + " (" + sShortCut + ")"; - else - return sLabel; -} - -void CommandInfoProvider::SetFrame (const Reference& rxFrame) -{ - if (rxFrame != mxCachedDataFrame) - { - // Detach from the old frame. - if (mxFrameListener.is()) - { - mxFrameListener->dispose(); - mxFrameListener = nullptr; - } - - // Release objects that are tied to the old frame. - mxCachedDocumentAcceleratorConfiguration = nullptr; - mxCachedModuleAcceleratorConfiguration = nullptr; - msCachedModuleIdentifier.clear(); - mxCachedDataFrame = rxFrame; - - // Connect to the new frame. - if (rxFrame.is()) - mxFrameListener = new FrameListener(*this, rxFrame); - } -} - -Reference CommandInfoProvider::GetDocumentAcceleratorConfiguration() -{ - if ( ! mxCachedDocumentAcceleratorConfiguration.is()) - { - // Get the accelerator configuration for the document. - if (mxCachedDataFrame.is()) - { - Reference xController = mxCachedDataFrame->getController(); - if (xController.is()) - { - Reference xModel (xController->getModel()); - if (xModel.is()) - { - Reference xSupplier (xModel, UNO_QUERY); - if (xSupplier.is()) - { - Reference xConfigurationManager( - xSupplier->getUIConfigurationManager(), - UNO_QUERY); - if (xConfigurationManager.is()) - { - mxCachedDocumentAcceleratorConfiguration = xConfigurationManager->getShortCutManager(); - } - } - } - } - } - } - return mxCachedDocumentAcceleratorConfiguration; -} - -Reference CommandInfoProvider::GetModuleAcceleratorConfiguration() -{ - if ( ! mxCachedModuleAcceleratorConfiguration.is()) - { - try - { - Reference xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(mxContext); - Reference xManager ( - xSupplier->getUIConfigurationManager(GetModuleIdentifier())); - if (xManager.is()) - { - mxCachedModuleAcceleratorConfiguration = xManager->getShortCutManager(); - } - } - catch (Exception&) - { - } - } - return mxCachedModuleAcceleratorConfiguration; -} - -Reference CommandInfoProvider::GetGlobalAcceleratorConfiguration() -{ - // Get the global accelerator configuration. - if ( ! mxCachedGlobalAcceleratorConfiguration.is()) - { - mxCachedGlobalAcceleratorConfiguration = ui::GlobalAcceleratorConfiguration::create(mxContext); - } - - return mxCachedGlobalAcceleratorConfiguration; -} - -OUString CommandInfoProvider::GetModuleIdentifier() -{ - if (msCachedModuleIdentifier.getLength() == 0) - { - Reference xModuleManager = frame::ModuleManager::create(mxContext); - msCachedModuleIdentifier = xModuleManager->identify(mxCachedDataFrame); - } - return msCachedModuleIdentifier; -} - -OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName) -{ - OUString sShortcut; - - sShortcut = RetrieveShortcutsFromConfiguration(GetDocumentAcceleratorConfiguration(), rsCommandName); - if (sShortcut.getLength() > 0) - return sShortcut; - - sShortcut = RetrieveShortcutsFromConfiguration(GetModuleAcceleratorConfiguration(), rsCommandName); - if (sShortcut.getLength() > 0) - return sShortcut; - - sShortcut = RetrieveShortcutsFromConfiguration(GetGlobalAcceleratorConfiguration(), rsCommandName); - if (sShortcut.getLength() > 0) - return sShortcut; - - return OUString(); -} - -OUString CommandInfoProvider::RetrieveShortcutsFromConfiguration( - const Reference& rxConfiguration, - const OUString& rsCommandName) -{ - if (rxConfiguration.is()) - { - try - { - Sequence aCommands { rsCommandName }; - - Sequence aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands)); - if (aCommands.getLength() == 1) - { - css::awt::KeyEvent aKeyEvent; - if (aKeyCodes[0] >>= aKeyEvent) - { - return svt::AcceleratorExecute::st_AWTKey2VCLKey(aKeyEvent).GetName(); - } - } - } - catch (lang::IllegalArgumentException&) - { - } - } - return OUString(); -} - -Sequence CommandInfoProvider::GetCommandProperties (const OUString& rsCommandName) -{ - Sequence aProperties; - - try - { - const OUString sModuleIdentifier (GetModuleIdentifier()); - if (sModuleIdentifier.getLength() > 0) - { - Reference xNameAccess = frame::theUICommandDescription::get(mxContext); - Reference xUICommandLabels; - if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) - xUICommandLabels->getByName(rsCommandName) >>= aProperties; - } - } - catch (Exception&) - { - } - - return aProperties; -} - -OUString CommandInfoProvider::GetCommandLabel (const OUString& rsCommandName) -{ - const Sequence aProperties (GetCommandProperties(rsCommandName)); - for (sal_Int32 nIndex=0; nIndex>= sLabel; - return sLabel; - } - } - return OUString(); -} - -} } // end of namespace sfx2/framework - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/sidebar/ControllerFactory.cxx b/sfx2/source/sidebar/ControllerFactory.cxx index 17980cdff0c9..65590377019a 100644 --- a/sfx2/source/sidebar/ControllerFactory.cxx +++ b/sfx2/source/sidebar/ControllerFactory.cxx @@ -18,7 +18,6 @@ */ #include -#include #include #include @@ -28,6 +27,7 @@ #include #include +#include #include #include @@ -120,13 +120,13 @@ Reference ControllerFactory::CreateToolBoxController( if (xUpdatable.is()) xUpdatable->update(); - // Add label. + // Add tooltip. if (xController.is()) { - const OUString sLabel (sfx2::sidebar::CommandInfoProvider::Instance().GetLabelForCommand( + const OUString sTooltip (svt::CommandInfoProvider::Instance().GetTooltipForCommand( rsCommandName, rxFrame)); - pToolBox->SetQuickHelpText(nItemId, sLabel); + pToolBox->SetQuickHelpText(nItemId, sTooltip); pToolBox->EnableItem(nItemId); } } diff --git a/sfx2/source/sidebar/ControllerItem.cxx b/sfx2/source/sidebar/ControllerItem.cxx index 4fca46b3cd49..cf24c3441c73 100644 --- a/sfx2/source/sidebar/ControllerItem.cxx +++ b/sfx2/source/sidebar/ControllerItem.cxx @@ -23,7 +23,7 @@ #include #include #include -#include +#include #include #include #include @@ -179,13 +179,6 @@ void ControllerItem::ResetFrame() mxFrame = nullptr; } -::rtl::OUString ControllerItem::GetLabel() const -{ - return CommandInfoProvider::Instance().GetLabelForCommand( - ".uno:" + msCommandName, - mxFrame); -} - ::rtl::OUString ControllerItem::GetHelpText() const { Help* pHelp = Application::GetHelp(); @@ -211,7 +204,7 @@ ControllerItem::ItemUpdateReceiverInterface::~ItemUpdateReceiverInterface() void ControllerItem::SetupToolBoxItem (ToolBox& rToolBox, const sal_uInt16 nIndex) { - rToolBox.SetQuickHelpText(nIndex, GetLabel()); + rToolBox.SetQuickHelpText(nIndex,svt::CommandInfoProvider::Instance().GetTooltipForCommand(".uno:" + msCommandName, mxFrame)); rToolBox.SetHelpText(nIndex, GetHelpText()); rToolBox.SetItemImage(nIndex, GetIcon()); } diff --git a/svtools/Library_svt.mk b/svtools/Library_svt.mk index 9e30e77037a6..19779cb24d76 100644 --- a/svtools/Library_svt.mk +++ b/svtools/Library_svt.mk @@ -172,6 +172,7 @@ $(eval $(call gb_Library_add_exception_objects,svt,\ svtools/source/misc/acceleratorexecute \ svtools/source/misc/bindablecontrolhelper \ svtools/source/misc/cliplistener \ + svtools/source/misc/commandinfoprovider \ svtools/source/misc/dialogclosedlistener \ svtools/source/misc/dialogcontrolling \ svtools/source/misc/ehdl \ diff --git a/svtools/source/misc/commandinfoprovider.cxx b/svtools/source/misc/commandinfoprovider.cxx new file mode 100644 index 000000000000..3536ba47e794 --- /dev/null +++ b/svtools/source/misc/commandinfoprovider.cxx @@ -0,0 +1,317 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +using namespace css; +using namespace css::uno; + + +namespace +{ + typedef ::cppu::WeakComponentImplHelper < + css::lang::XEventListener + > FrameListenerInterfaceBase; + class FrameListener + : public ::cppu::BaseMutex, + public FrameListenerInterfaceBase + { + public: + FrameListener (svt::CommandInfoProvider& rInfoProvider, const Reference& rxFrame) + : FrameListenerInterfaceBase(m_aMutex), + mrInfoProvider(rInfoProvider), + mxFrame(rxFrame) + { + if (mxFrame.is()) + mxFrame->addEventListener(this); + } + virtual ~FrameListener() + { + } + virtual void SAL_CALL disposing() override + { + if (mxFrame.is()) + mxFrame->removeEventListener(this); + } + virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) + throw (css::uno::RuntimeException, std::exception) override + { + (void)rEvent; + mrInfoProvider.SetFrame(nullptr); + mxFrame = nullptr; + } + + private: + svt::CommandInfoProvider& mrInfoProvider; + Reference mxFrame; + }; +} + +namespace svt { + +CommandInfoProvider& CommandInfoProvider::Instance() +{ + static CommandInfoProvider aProvider; + return aProvider; +} + +CommandInfoProvider::CommandInfoProvider() + : mxContext(comphelper::getProcessComponentContext()), + mxCachedDataFrame(), + mxCachedDocumentAcceleratorConfiguration(), + mxCachedModuleAcceleratorConfiguration(), + mxCachedGlobalAcceleratorConfiguration(), + msCachedModuleIdentifier(), + mxFrameListener() +{ +} + +CommandInfoProvider::~CommandInfoProvider() +{ + if (mxFrameListener.is()) + { + mxFrameListener->dispose(); + mxFrameListener = nullptr; + } +} + + +OUString CommandInfoProvider::GetLabelForCommand ( + const OUString& rsCommandName, + const Reference& rxFrame) +{ + SetFrame(rxFrame); + + return GetCommandProperty("Name", rsCommandName); +} + +OUString CommandInfoProvider::GetTooltipForCommand ( + const OUString& rsCommandName, + const Reference& rxFrame, + bool bIncludeShortcut) +{ + SetFrame(rxFrame); + + OUString sLabel (GetCommandProperty("TooltipLabel", rsCommandName)); + if (sLabel.isEmpty()) + sLabel = GetLabelForCommand(rsCommandName, rxFrame); + + if (bIncludeShortcut) { + const OUString sShortCut(GetCommandShortcut(rsCommandName, rxFrame)); + if (!sShortCut.isEmpty()) + return sLabel + " (" + sShortCut + ")"; + } + return sLabel; +} + +OUString CommandInfoProvider::GetCommandShortcut (const OUString& rsCommandName, + const Reference& rxFrame) +{ + SetFrame(rxFrame); + + OUString sShortcut; + + sShortcut = RetrieveShortcutsFromConfiguration(GetDocumentAcceleratorConfiguration(), rsCommandName); + if (sShortcut.getLength() > 0) + return sShortcut; + + sShortcut = RetrieveShortcutsFromConfiguration(GetModuleAcceleratorConfiguration(), rsCommandName); + if (sShortcut.getLength() > 0) + return sShortcut; + + sShortcut = RetrieveShortcutsFromConfiguration(GetGlobalAcceleratorConfiguration(), rsCommandName); + if (sShortcut.getLength() > 0) + return sShortcut; + + return OUString(); +} + +void CommandInfoProvider::SetFrame (const Reference& rxFrame) +{ + if (rxFrame != mxCachedDataFrame) + { + // Detach from the old frame. + if (mxFrameListener.is()) + { + mxFrameListener->dispose(); + mxFrameListener = nullptr; + } + + // Release objects that are tied to the old frame. + mxCachedDocumentAcceleratorConfiguration = nullptr; + mxCachedModuleAcceleratorConfiguration = nullptr; + msCachedModuleIdentifier.clear(); + mxCachedDataFrame = rxFrame; + + // Connect to the new frame. + if (rxFrame.is()) + mxFrameListener = new FrameListener(*this, rxFrame); + } +} + +Reference CommandInfoProvider::GetDocumentAcceleratorConfiguration() +{ + if ( ! mxCachedDocumentAcceleratorConfiguration.is()) + { + // Get the accelerator configuration for the document. + if (mxCachedDataFrame.is()) + { + Reference xController = mxCachedDataFrame->getController(); + if (xController.is()) + { + Reference xModel (xController->getModel()); + if (xModel.is()) + { + Reference xSupplier (xModel, UNO_QUERY); + if (xSupplier.is()) + { + Reference xConfigurationManager( + xSupplier->getUIConfigurationManager(), + UNO_QUERY); + if (xConfigurationManager.is()) + { + mxCachedDocumentAcceleratorConfiguration = xConfigurationManager->getShortCutManager(); + } + } + } + } + } + } + return mxCachedDocumentAcceleratorConfiguration; +} + +Reference CommandInfoProvider::GetModuleAcceleratorConfiguration() +{ + if ( ! mxCachedModuleAcceleratorConfiguration.is()) + { + try + { + Reference xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(mxContext); + Reference xManager ( + xSupplier->getUIConfigurationManager(GetModuleIdentifier())); + if (xManager.is()) + { + mxCachedModuleAcceleratorConfiguration = xManager->getShortCutManager(); + } + } + catch (Exception&) + { + } + } + return mxCachedModuleAcceleratorConfiguration; +} + +Reference CommandInfoProvider::GetGlobalAcceleratorConfiguration() +{ + // Get the global accelerator configuration. + if ( ! mxCachedGlobalAcceleratorConfiguration.is()) + { + mxCachedGlobalAcceleratorConfiguration = ui::GlobalAcceleratorConfiguration::create(mxContext); + } + + return mxCachedGlobalAcceleratorConfiguration; +} + +OUString CommandInfoProvider::GetModuleIdentifier() +{ + if (msCachedModuleIdentifier.getLength() == 0) + { + Reference xModuleManager = frame::ModuleManager::create(mxContext); + msCachedModuleIdentifier = xModuleManager->identify(mxCachedDataFrame); + } + return msCachedModuleIdentifier; +} + +OUString CommandInfoProvider::RetrieveShortcutsFromConfiguration( + const Reference& rxConfiguration, + const OUString& rsCommandName) +{ + if (rxConfiguration.is()) + { + try + { + Sequence aCommands { rsCommandName }; + + Sequence aKeyCodes (rxConfiguration->getPreferredKeyEventsForCommandList(aCommands)); + if (aCommands.getLength() == 1) + { + css::awt::KeyEvent aKeyEvent; + if (aKeyCodes[0] >>= aKeyEvent) + { + return svt::AcceleratorExecute::st_AWTKey2VCLKey(aKeyEvent).GetName(); + } + } + } + catch (lang::IllegalArgumentException&) + { + } + } + return OUString(); +} + +Sequence CommandInfoProvider::GetCommandProperties(const OUString& rsCommandName) +{ + Sequence aProperties; + + try + { + const OUString sModuleIdentifier (GetModuleIdentifier()); + if (sModuleIdentifier.getLength() > 0) + { + Reference xNameAccess = frame::theUICommandDescription::get(mxContext); + Reference xUICommandLabels; + if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) + xUICommandLabels->getByName(rsCommandName) >>= aProperties; + } + } + catch (Exception&) + { + } + + return aProperties; +} + +OUString CommandInfoProvider::GetCommandProperty(const OUString& rsProperty, const OUString& rsCommandName) +{ + const Sequence aProperties (GetCommandProperties(rsCommandName)); + for (sal_Int32 nIndex=0; nIndex>= sLabel; + return sLabel; + } + } + return OUString(); +} + +} // end of namespace svt + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svx/source/sidebar/insert/InsertPropertyPanel.cxx b/svx/source/sidebar/insert/InsertPropertyPanel.cxx index b27c520cf294..131e98959c9c 100644 --- a/svx/source/sidebar/insert/InsertPropertyPanel.cxx +++ b/svx/source/sidebar/insert/InsertPropertyPanel.cxx @@ -17,7 +17,6 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ #include "InsertPropertyPanel.hxx" -#include "sfx2/sidebar/CommandInfoProvider.hxx" #include #include -- cgit