diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2016-09-25 18:15:27 +0300 |
---|---|---|
committer | Maxim Monastirsky <momonasmon@gmail.com> | 2016-09-25 18:48:12 +0300 |
commit | 02ddfd10e9e46e2b121416d815303c386400ba6f (patch) | |
tree | 80e808a7592f77c7c6c7e29036b266744983268b /framework/source | |
parent | f3fd652f396219a462060342f1e135afcfad5417 (diff) |
tdf#96736 Let MenuBarManager handle the save dropdown
Instead of trying to do everything (icon theme
changes, disabling commands etc.) manually.
Change-Id: Iffd420bf09ccd566e96f39cb9684ab466a7c6555
Diffstat (limited to 'framework/source')
-rw-r--r-- | framework/source/uielement/resourcemenucontroller.cxx | 53 | ||||
-rw-r--r-- | framework/source/uielement/saveasmenucontroller.cxx | 133 |
2 files changed, 53 insertions, 133 deletions
diff --git a/framework/source/uielement/resourcemenucontroller.cxx b/framework/source/uielement/resourcemenucontroller.cxx index 33956f3fd15f..02011c72e81c 100644 --- a/framework/source/uielement/resourcemenucontroller.cxx +++ b/framework/source/uielement/resourcemenucontroller.cxx @@ -408,6 +408,51 @@ css::uno::Sequence< OUString > ResourceMenuController::getSupportedServiceNames( return { "com.sun.star.frame.PopupMenuController" }; } +class SaveAsMenuController : public ResourceMenuController +{ +public: + SaveAsMenuController( const css::uno::Reference< css::uno::XComponentContext >& rContext, + const css::uno::Sequence< css::uno::Any >& rArgs ); + + // XServiceInfo + virtual OUString SAL_CALL getImplementationName() throw ( css::uno::RuntimeException, std::exception ) override; + +private: + virtual void impl_setPopupMenu() override; +}; + +SaveAsMenuController::SaveAsMenuController( const css::uno::Reference< css::uno::XComponentContext >& rContext, + const css::uno::Sequence< css::uno::Any >& rArgs ) + : ResourceMenuController( rContext, rArgs, false ) +{ +} + +void SaveAsMenuController::impl_setPopupMenu() +{ + VCLXMenu* pPopupMenu = VCLXMenu::GetImplementation( m_xPopupMenu ); + Menu* pVCLPopupMenu = nullptr; + + SolarMutexGuard aGuard; + + if ( pPopupMenu ) + pVCLPopupMenu = pPopupMenu->GetMenu(); + + if ( !pVCLPopupMenu ) + return; + + pVCLPopupMenu->InsertItem( ".uno:SaveAs", nullptr ); + pVCLPopupMenu->InsertItem( ".uno:ExportTo", nullptr ); + pVCLPopupMenu->InsertItem( ".uno:SaveAsTemplate", nullptr ); + pVCLPopupMenu->InsertSeparator(); + pVCLPopupMenu->InsertItem( ".uno:SaveAsRemote", nullptr ); +} + +OUString SaveAsMenuController::getImplementationName() + throw ( css::uno::RuntimeException, std::exception ) +{ + return OUString( "com.sun.star.comp.framework.SaveAsMenuController" ); +} + } extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL @@ -426,4 +471,12 @@ com_sun_star_comp_framework_ToolbarAsMenuController_get_implementation( return cppu::acquire( new ResourceMenuController( context, args, true ) ); } +extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL +com_sun_star_comp_framework_SaveAsMenuController_get_implementation( + css::uno::XComponentContext* context, + css::uno::Sequence< css::uno::Any > const & args ) +{ + return cppu::acquire( new SaveAsMenuController( context, args ) ); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/uielement/saveasmenucontroller.cxx b/framework/source/uielement/saveasmenucontroller.cxx deleted file mode 100644 index 0941552678d4..000000000000 --- a/framework/source/uielement/saveasmenucontroller.cxx +++ /dev/null @@ -1,133 +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 <cppuhelper/supportsservice.hxx> -#include <svtools/popupmenucontrollerbase.hxx> -#include <vcl/menu.hxx> -#include <vcl/svapp.hxx> - -using namespace css; -using namespace com::sun::star::uno; -using namespace com::sun::star::frame; - -namespace { - -class SaveAsMenuController : public svt::PopupMenuControllerBase -{ -public: - explicit SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext ); - virtual ~SaveAsMenuController() override; - - // XServiceInfo - virtual OUString SAL_CALL getImplementationName() - throw (css::uno::RuntimeException, std::exception) override - { - return OUString("com.sun.star.comp.framework.SaveAsMenuController"); - } - - virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName) - throw (css::uno::RuntimeException, std::exception) override - { - return cppu::supportsService(this, ServiceName); - } - - virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() - throw (css::uno::RuntimeException, std::exception) override - { - css::uno::Sequence< OUString > aSeq { "com.sun.star.frame.PopupMenuController" }; - return aSeq; - } - - // XStatusListener - virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception ) override; - -private: - virtual void impl_setPopupMenu() override; - bool isCommandAvailable(const OUString & sCommand); -}; - -SaveAsMenuController::SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext ) : - svt::PopupMenuControllerBase( xContext ) -{ -} - -SaveAsMenuController::~SaveAsMenuController() -{ -} - -void SaveAsMenuController::impl_setPopupMenu() -{ - VCLXMenu* pPopupMenu = VCLXMenu::GetImplementation( m_xPopupMenu ); - Menu* pVCLPopupMenu = nullptr; - - SolarMutexGuard aSolarMutexGuard; - - if ( pPopupMenu ) - pVCLPopupMenu = pPopupMenu->GetMenu(); - - if ( !pVCLPopupMenu ) - return; - - pVCLPopupMenu->InsertItem( ".uno:SaveAs", m_xFrame ); - - OUString sExportTo(".uno:ExportTo"); - if (isCommandAvailable(sExportTo)) - pVCLPopupMenu->InsertItem( sExportTo, m_xFrame ); - - OUString sSaveAsTemplate(".uno:SaveAsTemplate"); - if (isCommandAvailable(sSaveAsTemplate)) - pVCLPopupMenu->InsertItem( sSaveAsTemplate, m_xFrame ); - - pVCLPopupMenu->InsertSeparator(); - - OUString sSaveRemote(".uno:SaveAsRemote"); - if (isCommandAvailable(sSaveRemote)) - pVCLPopupMenu->InsertItem( sSaveRemote, m_xFrame ); -} - -bool SaveAsMenuController::isCommandAvailable(const OUString & sCommand) -{ - uno::Reference<frame::XDispatchProvider> xDispatchProvider(m_xFrame, uno::UNO_QUERY); - if (!xDispatchProvider.is()) - return false; - - util::URL aTargetURL; - aTargetURL.Complete = sCommand; - m_xURLTransformer->parseStrict(aTargetURL); - - uno::Reference<frame::XDispatch> xDispatch(xDispatchProvider->queryDispatch(aTargetURL, OUString(), 0)); - return xDispatch.is(); -} - -// XStatusListener -void SAL_CALL SaveAsMenuController::statusChanged( const FeatureStateEvent& /*Event*/ ) throw ( RuntimeException, std::exception ) -{ -} - -} - -extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL -com_sun_star_comp_framework_SaveAsMenuController_get_implementation( - css::uno::XComponentContext *context, - css::uno::Sequence<css::uno::Any> const &) -{ - return cppu::acquire(new SaveAsMenuController(context)); -} - -/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |