diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-11-13 17:00:03 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2015-11-16 08:08:09 +0100 |
commit | 099f1016fa507809e24f0874848f6107a08a4fb0 (patch) | |
tree | 09e6d1bf78cc27e4ac9e0deced6b9b69c9f6f800 /sfx2 | |
parent | 773a07a94ebc9f578b5bb6a90ddd1974d1577351 (diff) |
Cleanup: Consolidate the different ways to get command labels/tooltips
Change-Id: Ieab809a3122c9d592894b84ec2e68195a4e02dde
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/Library_sfx.mk | 1 | ||||
-rw-r--r-- | sfx2/source/sidebar/CommandInfoProvider.cxx | 302 | ||||
-rw-r--r-- | sfx2/source/sidebar/ControllerFactory.cxx | 8 | ||||
-rw-r--r-- | sfx2/source/sidebar/ControllerItem.cxx | 11 |
4 files changed, 6 insertions, 316 deletions
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 <sfx2/sidebar/CommandInfoProvider.hxx> - -#include <comphelper/processfactory.hxx> -#include <svtools/acceleratorexecute.hxx> -#include <cppuhelper/compbase.hxx> -#include <cppuhelper/basemutex.hxx> - -#include <com/sun/star/frame/ModuleManager.hpp> -#include <com/sun/star/frame/theUICommandDescription.hpp> -#include <com/sun/star/ui/GlobalAcceleratorConfiguration.hpp> -#include <com/sun/star/ui/XUIConfigurationManagerSupplier.hpp> -#include <com/sun/star/ui/theModuleUIConfigurationManagerSupplier.hpp> - -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<frame::XFrame>& 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<frame::XFrame> 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<frame::XFrame>& 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<frame::XFrame>& 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<ui::XAcceleratorConfiguration> CommandInfoProvider::GetDocumentAcceleratorConfiguration() -{ - if ( ! mxCachedDocumentAcceleratorConfiguration.is()) - { - // Get the accelerator configuration for the document. - if (mxCachedDataFrame.is()) - { - Reference<frame::XController> xController = mxCachedDataFrame->getController(); - if (xController.is()) - { - Reference<frame::XModel> xModel (xController->getModel()); - if (xModel.is()) - { - Reference<ui::XUIConfigurationManagerSupplier> xSupplier (xModel, UNO_QUERY); - if (xSupplier.is()) - { - Reference<ui::XUIConfigurationManager> xConfigurationManager( - xSupplier->getUIConfigurationManager(), - UNO_QUERY); - if (xConfigurationManager.is()) - { - mxCachedDocumentAcceleratorConfiguration = xConfigurationManager->getShortCutManager(); - } - } - } - } - } - } - return mxCachedDocumentAcceleratorConfiguration; -} - -Reference<ui::XAcceleratorConfiguration> CommandInfoProvider::GetModuleAcceleratorConfiguration() -{ - if ( ! mxCachedModuleAcceleratorConfiguration.is()) - { - try - { - Reference<ui::XModuleUIConfigurationManagerSupplier> xSupplier = ui::theModuleUIConfigurationManagerSupplier::get(mxContext); - Reference<ui::XUIConfigurationManager> xManager ( - xSupplier->getUIConfigurationManager(GetModuleIdentifier())); - if (xManager.is()) - { - mxCachedModuleAcceleratorConfiguration = xManager->getShortCutManager(); - } - } - catch (Exception&) - { - } - } - return mxCachedModuleAcceleratorConfiguration; -} - -Reference<ui::XAcceleratorConfiguration> 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<frame::XModuleManager2> 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<ui::XAcceleratorConfiguration>& rxConfiguration, - const OUString& rsCommandName) -{ - if (rxConfiguration.is()) - { - try - { - Sequence<OUString> aCommands { rsCommandName }; - - Sequence<Any> 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<beans::PropertyValue> CommandInfoProvider::GetCommandProperties (const OUString& rsCommandName) -{ - Sequence<beans::PropertyValue> aProperties; - - try - { - const OUString sModuleIdentifier (GetModuleIdentifier()); - if (sModuleIdentifier.getLength() > 0) - { - Reference<container::XNameAccess> xNameAccess = frame::theUICommandDescription::get(mxContext); - Reference<container::XNameAccess> xUICommandLabels; - if (xNameAccess->getByName(sModuleIdentifier) >>= xUICommandLabels) - xUICommandLabels->getByName(rsCommandName) >>= aProperties; - } - } - catch (Exception&) - { - } - - return aProperties; -} - -OUString CommandInfoProvider::GetCommandLabel (const OUString& rsCommandName) -{ - const Sequence<beans::PropertyValue> aProperties (GetCommandProperties(rsCommandName)); - for (sal_Int32 nIndex=0; nIndex<aProperties.getLength(); ++nIndex) - { - if (aProperties[nIndex].Name == "Name") - { - OUString sLabel; - aProperties[nIndex].Value >>= 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 <sfx2/sidebar/ControllerFactory.hxx> -#include <sfx2/sidebar/CommandInfoProvider.hxx> #include <sfx2/sidebar/Tools.hxx> #include <com/sun/star/frame/XToolbarController.hpp> @@ -28,6 +27,7 @@ #include <framework/sfxhelperfunctions.hxx> #include <svtools/generictoolboxcontroller.hxx> +#include <svtools/commandinfoprovider.hxx> #include <comphelper/processfactory.hxx> #include <toolkit/helper/vclunohelper.hxx> @@ -120,13 +120,13 @@ Reference<frame::XToolbarController> 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 <sfx2/imagemgr.hxx> #include <sfx2/bindings.hxx> #include <unotools/cmdoptions.hxx> -#include <sfx2/sidebar/CommandInfoProvider.hxx> +#include <svtools/commandinfoprovider.hxx> #include <vcl/svapp.hxx> #include <vcl/toolbox.hxx> #include <vcl/help.hxx> @@ -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()); } |