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

Maxim Monastirsky momonasmon at gmail.com
Sun Sep 25 15:51:42 UTC 2016


 framework/Library_fwk.mk                              |    1 
 framework/source/uielement/resourcemenucontroller.cxx |   53 +++++++
 framework/source/uielement/saveasmenucontroller.cxx   |  133 ------------------
 vcl/source/window/menu.cxx                            |   18 +-
 4 files changed, 65 insertions(+), 140 deletions(-)

New commits:
commit 02ddfd10e9e46e2b121416d815303c386400ba6f
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Sun Sep 25 18:15:27 2016 +0300

    tdf#96736 Let MenuBarManager handle the save dropdown
    
    Instead of trying to do everything (icon theme
    changes, disabling commands etc.) manually.
    
    Change-Id: Iffd420bf09ccd566e96f39cb9684ab466a7c6555

diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index ab6518a..e6d0ae2 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -141,7 +141,6 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
     framework/source/uielement/progressbarwrapper \
     framework/source/uielement/recentfilesmenucontroller \
     framework/source/uielement/resourcemenucontroller \
-    framework/source/uielement/saveasmenucontroller \
     framework/source/uielement/spinfieldtoolbarcontroller \
     framework/source/uielement/statusbar \
     framework/source/uielement/statusbaritem \
diff --git a/framework/source/uielement/resourcemenucontroller.cxx b/framework/source/uielement/resourcemenucontroller.cxx
index 33956f3..02011c7 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 0941552..0000000
--- 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: */
diff --git a/vcl/source/window/menu.cxx b/vcl/source/window/menu.cxx
index 579e993..a93811d 100644
--- a/vcl/source/window/menu.cxx
+++ b/vcl/source/window/menu.cxx
@@ -515,15 +515,21 @@ void Menu::InsertItem( const ResId& rResId )
 
 void Menu::InsertItem(const OUString& rCommand, const css::uno::Reference<css::frame::XFrame>& rFrame)
 {
-    OUString aLabel(CommandInfoProvider::Instance().GetPopupLabelForCommand(rCommand, rFrame));
-    OUString aTooltip(CommandInfoProvider::Instance().GetTooltipForCommand(rCommand, rFrame));
-    Image aImage(CommandInfoProvider::Instance().GetImageForCommand(rCommand, /*bLarge=*/ false, rFrame));
-
     sal_uInt16 nItemId = GetItemCount() + 1;
 
-    InsertItem(nItemId, aLabel, aImage);
+    if (rFrame.is())
+    {
+        OUString aLabel(CommandInfoProvider::Instance().GetPopupLabelForCommand(rCommand, rFrame));
+        OUString aTooltip(CommandInfoProvider::Instance().GetTooltipForCommand(rCommand, rFrame));
+        Image aImage(CommandInfoProvider::Instance().GetImageForCommand(rCommand, /*bLarge=*/ false, rFrame));
+
+        InsertItem(nItemId, aLabel, aImage);
+        SetHelpText(nItemId, aTooltip);
+    }
+    else
+        InsertItem(nItemId, OUString());
+
     SetItemCommand(nItemId, rCommand);
-    SetHelpText(nItemId, aTooltip);
 }
 
 


More information about the Libreoffice-commits mailing list