[Libreoffice-commits] core.git: Branch 'feature/gsoc15-open-remote-files-dialog' - framework/inc framework/Library_fwk.mk framework/source framework/util include/sfx2 officecfg/registry sfx2/source sw/inc sw/sdi sw/source sw/uiconfig

Szymon Kłos eszkadev at gmail.com
Tue Jul 7 07:47:35 PDT 2015


 framework/Library_fwk.mk                                        |    1 
 framework/inc/classes/resource.hrc                              |    1 
 framework/source/classes/resource.src                           |    5 
 framework/source/uielement/saveasmenucontroller.cxx             |  191 ++++++++++
 framework/util/fwk.component                                    |    4 
 include/sfx2/tbxctrl.hxx                                        |   15 
 officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu |   11 
 sfx2/source/toolbox/tbxitem.cxx                                 |   50 ++
 sw/inc/cmdid.h                                                  |    1 
 sw/sdi/docsh.sdi                                                |    5 
 sw/sdi/swriter.sdi                                              |   27 +
 sw/source/uibase/app/swmodule.cxx                               |    1 
 sw/uiconfig/swriter/toolbar/standardbar.xml                     |    2 
 13 files changed, 313 insertions(+), 1 deletion(-)

New commits:
commit 9a2a0b44986efa37c738a9016e1bbefdf2996da8
Author: Szymon Kłos <eszkadev at gmail.com>
Date:   Tue Jul 7 16:44:59 2015 +0200

    'Save As' popup menu in the Writer's toolbar
    
    Change-Id: I1b1cb7fcd2ae0e0f50e4d8e3900bc416435e60bf

diff --git a/framework/Library_fwk.mk b/framework/Library_fwk.mk
index 74e72a9..b47d2ad 100644
--- a/framework/Library_fwk.mk
+++ b/framework/Library_fwk.mk
@@ -144,6 +144,7 @@ $(eval $(call gb_Library_add_exception_objects,fwk,\
     framework/source/uielement/popuptoolbarcontroller \
     framework/source/uielement/progressbarwrapper \
     framework/source/uielement/recentfilesmenucontroller \
+    framework/source/uielement/saveasmenucontroller \
     framework/source/uielement/spinfieldtoolbarcontroller \
     framework/source/uielement/statusbar \
     framework/source/uielement/statusbaritem \
diff --git a/framework/inc/classes/resource.hrc b/framework/inc/classes/resource.hrc
index 6620c99..2b1ea1c 100644
--- a/framework/inc/classes/resource.hrc
+++ b/framework/inc/classes/resource.hrc
@@ -51,6 +51,7 @@
 #define STR_CLEAR_RECENT_FILES_HELP             (RID_STR_START+24)
 #define STR_LANGSTATUS_HINT                     (RID_STR_START+25)
 #define STR_OPEN_REMOTE                         (RID_STR_START+26)
+#define STR_REMOTE_FILE                         (RID_STR_START+27)
 
 #define POPUPMENU_TOOLBAR_QUICKCUSTOMIZATION    (RID_MENU_START+0)
 
diff --git a/framework/source/classes/resource.src b/framework/source/classes/resource.src
index 0ef53ae..4f8ce0e 100644
--- a/framework/source/classes/resource.src
+++ b/framework/source/classes/resource.src
@@ -119,6 +119,11 @@ String STR_OPEN_REMOTE
     Text [ en-US ] = "Open remote file";
 };
 
+String STR_REMOTE_FILE
+{
+    Text [ en-US ] = "Remote file";
+};
+
 String STR_TOOLBAR_TITLE_ADDON
 {
     Text [ en-US ] = "Add-On %num%";
diff --git a/framework/source/uielement/saveasmenucontroller.cxx b/framework/source/uielement/saveasmenucontroller.cxx
new file mode 100644
index 0000000..7e4fd92
--- /dev/null
+++ b/framework/source/uielement/saveasmenucontroller.cxx
@@ -0,0 +1,191 @@
+/* -*- 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 <classes/resource.hrc>
+#include <classes/fwkresid.hxx>
+
+#include <cppuhelper/implbase1.hxx>
+#include <cppuhelper/supportsservice.hxx>
+#include <osl/file.hxx>
+#include <osl/mutex.hxx>
+#include <rtl/ref.hxx>
+#include <svtools/popupmenucontrollerbase.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/historyoptions.hxx>
+#include <vcl/menu.hxx>
+#include <vcl/svapp.hxx>
+
+using namespace css;
+using namespace com::sun::star::uno;
+using namespace com::sun::star::lang;
+using namespace com::sun::star::frame;
+using namespace com::sun::star::beans;
+using namespace com::sun::star::util;
+using namespace framework;
+
+namespace {
+
+static const char CMD_SAVE_REMOTE[]  = ".uno:OpenRemote"; // TODO
+
+class SaveAsMenuController :  public svt::PopupMenuControllerBase
+{
+    using svt::PopupMenuControllerBase::disposing;
+
+public:
+    SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext );
+    virtual ~SaveAsMenuController();
+
+    // XServiceInfo
+    virtual OUString SAL_CALL getImplementationName()
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+    {
+        return OUString("com.sun.star.comp.framework.SaveAsMenuController");
+    }
+
+    virtual sal_Bool SAL_CALL supportsService(OUString const & ServiceName)
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+    {
+        return cppu::supportsService(this, ServiceName);
+    }
+
+    virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames()
+        throw (css::uno::RuntimeException, std::exception) SAL_OVERRIDE
+    {
+        css::uno::Sequence< OUString > aSeq(1);
+        aSeq[0] = "com.sun.star.frame.PopupMenuController";
+        return aSeq;
+    }
+
+    // XStatusListener
+    virtual void SAL_CALL statusChanged( const frame::FeatureStateEvent& Event ) throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
+
+    // XMenuListener
+    virtual void SAL_CALL itemSelected( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
+    virtual void SAL_CALL itemActivated( const awt::MenuEvent& rEvent ) throw (uno::RuntimeException, std::exception) SAL_OVERRIDE;
+
+    // XEventListener
+    virtual void SAL_CALL disposing( const com::sun::star::lang::EventObject& Source ) throw ( uno::RuntimeException, std::exception ) SAL_OVERRIDE;
+
+private:
+    virtual void impl_setPopupMenu() SAL_OVERRIDE;
+
+    void fillPopupMenu( com::sun::star::uno::Reference< com::sun::star::awt::XPopupMenu >& rPopupMenu );
+
+    bool                  m_bDisabled : 1;
+};
+
+SaveAsMenuController::SaveAsMenuController( const uno::Reference< uno::XComponentContext >& xContext ) :
+    svt::PopupMenuControllerBase( xContext ),
+    m_bDisabled( false )
+{
+}
+
+SaveAsMenuController::~SaveAsMenuController()
+{
+}
+
+// private function
+void SaveAsMenuController::fillPopupMenu( Reference< css::awt::XPopupMenu >& rPopupMenu )
+{
+    VCLXPopupMenu* pPopupMenu    = static_cast<VCLXPopupMenu *>(VCLXMenu::GetImplementation( rPopupMenu ));
+    PopupMenu*     pVCLPopupMenu = 0;
+
+    SolarMutexGuard aSolarMutexGuard;
+
+    resetPopupMenu( rPopupMenu );
+    if ( pPopupMenu )
+        pVCLPopupMenu = static_cast<PopupMenu *>(pPopupMenu->GetMenu());
+
+    if ( pVCLPopupMenu )
+    {
+        // Open remote menu entry
+        pVCLPopupMenu->InsertItem( sal_uInt16( 0 ),
+                                   FWK_RESSTR( STR_REMOTE_FILE ) );
+        pVCLPopupMenu->SetItemCommand( sal_uInt16( 0 ),
+                                       OUString( CMD_SAVE_REMOTE ) );
+    }
+}
+
+// XEventListener
+void SAL_CALL SaveAsMenuController::disposing( const EventObject& ) throw ( RuntimeException, std::exception )
+{
+    Reference< css::awt::XMenuListener > xHolder(( OWeakObject *)this, UNO_QUERY );
+
+    osl::MutexGuard aLock( m_aMutex );
+    m_xFrame.clear();
+    m_xDispatch.clear();
+
+    if ( m_xPopupMenu.is() )
+        m_xPopupMenu->removeMenuListener( Reference< css::awt::XMenuListener >(( OWeakObject *)this, UNO_QUERY ));
+    m_xPopupMenu.clear();
+}
+
+// XStatusListener
+void SAL_CALL SaveAsMenuController::statusChanged( const FeatureStateEvent& Event ) throw ( RuntimeException, std::exception )
+{
+    osl::MutexGuard aLock( m_aMutex );
+    m_bDisabled = !Event.IsEnabled;
+}
+
+void SAL_CALL SaveAsMenuController::itemSelected( const css::awt::MenuEvent& rEvent ) throw (RuntimeException, std::exception)
+{
+    Reference< css::awt::XPopupMenu > xPopupMenu;
+
+    osl::ClearableMutexGuard aLock( m_aMutex );
+    xPopupMenu = m_xPopupMenu;
+    aLock.clear();
+
+    if ( xPopupMenu.is() )
+    {
+        const OUString aCommand( xPopupMenu->getCommand( rEvent.MenuId ) );
+        OSL_TRACE( "SaveAsMenuController::itemSelected() - Command : %s",
+                   OUStringToOString( aCommand, RTL_TEXTENCODING_UTF8 ).getStr() );
+
+        if ( aCommand == CMD_SAVE_REMOTE )
+        {
+            Sequence< PropertyValue > aArgsList( 0 );
+            dispatchCommand( CMD_SAVE_REMOTE, aArgsList );
+        }
+    }
+}
+
+void SAL_CALL SaveAsMenuController::itemActivated( const css::awt::MenuEvent& ) throw (RuntimeException, std::exception)
+{
+    osl::MutexGuard aLock( m_aMutex );
+    impl_setPopupMenu();
+}
+
+// XPopupMenuController
+void SaveAsMenuController::impl_setPopupMenu()
+{
+    if ( m_xPopupMenu.is() )
+        fillPopupMenu( m_xPopupMenu );
+}
+
+}
+
+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/framework/util/fwk.component b/framework/util/fwk.component
index 6541f14..1eaf2d0 100644
--- a/framework/util/fwk.component
+++ b/framework/util/fwk.component
@@ -117,6 +117,10 @@
       constructor="com_sun_star_comp_framework_RecentFilesMenuController_get_implementation">
     <service name="com.sun.star.frame.PopupMenuController"/>
   </implementation>
+  <implementation name="com.sun.star.comp.framework.SaveAsMenuController"
+      constructor="com_sun_star_comp_framework_SaveAsMenuController_get_implementation">
+    <service name="com.sun.star.frame.PopupMenuController"/>
+  </implementation>
   <implementation name="com.sun.star.comp.framework.StatusBarControllerFactory"
       constructor="com_sun_star_comp_framework_StatusBarControllerFactory_get_implementation">
     <service name="com.sun.star.frame.StatusbarControllerFactory"/>
diff --git a/include/sfx2/tbxctrl.hxx b/include/sfx2/tbxctrl.hxx
index 11da16c..57ab404 100644
--- a/include/sfx2/tbxctrl.hxx
+++ b/include/sfx2/tbxctrl.hxx
@@ -329,6 +329,21 @@ protected:
     virtual VclPtr<SfxPopupWindow> CreatePopupWindow() SAL_OVERRIDE;
 };
 
+class SfxSaveAsToolBoxControl : public SfxToolBoxControl
+{
+public:
+    // We don't use SFX_DECL_TOOLBOX_CONTROL() here as we need to have this
+    // RegisterControl() marked as SFX2_DLLPUBLIC
+    static SfxToolBoxControl* CreateImpl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox &rTbx );
+    static void SFX2_DLLPUBLIC RegisterControl(sal_uInt16 nSlotId = 0, SfxModule *pMod=NULL);
+
+    SfxSaveAsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox );
+    virtual ~SfxSaveAsToolBoxControl();
+
+protected:
+    virtual VclPtr<SfxPopupWindow> CreatePopupWindow() SAL_OVERRIDE;
+};
+
 class SfxReloadToolBoxControl_Impl : public SfxToolBoxControl
 {
     protected:
diff --git a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
index 74acecb..4fb73a7 100644
--- a/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
+++ b/officecfg/registry/data/org/openoffice/Office/UI/Controller.xcu
@@ -174,6 +174,17 @@
           <value>com.sun.star.comp.framework.LanguageSelectionMenuController</value>
         </prop>
       </node>
+      <node oor:name="c16" oor:op="replace">
+        <prop oor:name="Command">
+          <value>.uno:SaveAsMenu</value>
+        </prop>
+        <prop oor:name="Module">
+          <value/>
+        </prop>
+        <prop oor:name="Controller">
+          <value>com.sun.star.comp.framework.SaveAsMenuController</value>
+        </prop>
+      </node>
     </node>
     <node oor:name="ToolBar">
       <node oor:name="c1" oor:op="replace">
diff --git a/sfx2/source/toolbox/tbxitem.cxx b/sfx2/source/toolbox/tbxitem.cxx
index 5119f608..d299109 100644
--- a/sfx2/source/toolbox/tbxitem.cxx
+++ b/sfx2/source/toolbox/tbxitem.cxx
@@ -107,6 +107,7 @@ using namespace ::com::sun::star::ui;
 
 SFX_IMPL_TOOLBOX_CONTROL_ARG(SfxToolBoxControl, SfxStringItem, true);
 SFX_IMPL_TOOLBOX_CONTROL(SfxRecentFilesToolBoxControl, SfxStringItem);
+SFX_IMPL_TOOLBOX_CONTROL(SfxSaveAsToolBoxControl, SfxStringItem);
 
 static vcl::Window* GetTopMostParentSystemWindow( vcl::Window* pWindow )
 {
@@ -1429,4 +1430,53 @@ VclPtr<SfxPopupWindow> SfxRecentFilesToolBoxControl::CreatePopupWindow()
     return 0;
 }
 
+SfxSaveAsToolBoxControl::SfxSaveAsToolBoxControl( sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rBox )
+    : SfxToolBoxControl( nSlotId, nId, rBox )
+{
+    rBox.SetItemBits( nId, rBox.GetItemBits( nId ) | ToolBoxItemBits::DROPDOWN);
+}
+
+SfxSaveAsToolBoxControl::~SfxSaveAsToolBoxControl()
+{
+}
+
+VclPtr<SfxPopupWindow> SfxSaveAsToolBoxControl::CreatePopupWindow()
+{
+    ToolBox& rBox = GetToolBox();
+    sal_uInt16 nItemId = GetId();
+    ::Rectangle aRect( rBox.GetItemRect( nItemId ) );
+
+    Sequence< Any > aArgs( 2 );
+    PropertyValue aPropValue;
+
+    aPropValue.Name = "CommandURL";
+    aPropValue.Value <<= OUString( ".uno:SaveAsMenu" );
+    aArgs[0] <<= aPropValue;
+
+    aPropValue.Name = "Frame";
+    aPropValue.Value <<= m_xFrame;
+    aArgs[1] <<= aPropValue;
+
+    uno::Reference< frame::XPopupMenuController > xPopupController( m_xContext->getServiceManager()->createInstanceWithArgumentsAndContext(
+                "com.sun.star.comp.framework.SaveAsMenuController", aArgs, m_xContext ), UNO_QUERY );
+
+    uno::Reference< awt::XPopupMenu > xPopupMenu( m_xContext->getServiceManager()->createInstanceWithContext(
+                "com.sun.star.awt.PopupMenu", m_xContext ), uno::UNO_QUERY );
+
+    if ( xPopupController.is() && xPopupMenu.is() )
+    {
+        xPopupController->setPopupMenu( xPopupMenu );
+
+        rBox.SetItemDown( nItemId, true );
+        Reference< awt::XWindowPeer > xPeer( getParent(), uno::UNO_QUERY );
+
+        if ( xPeer.is() )
+            xPopupMenu->execute( xPeer, VCLUnoHelper::ConvertToAWTRect( aRect ), 0 );
+
+        rBox.SetItemDown( nItemId, false );
+    }
+
+    return 0;
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/cmdid.h b/sw/inc/cmdid.h
index dda4a38..913f81a 100644
--- a/sw/inc/cmdid.h
+++ b/sw/inc/cmdid.h
@@ -62,6 +62,7 @@
 
 // Region: File
 #define FN_NEW_GLOBAL_DOC       (FN_FILE + 4 )    /* Create Global Document */
+#define FN_SAVE_FILE_AS         (FN_FILE + 5 )    /* Save As */
 #define FN_OPEN_FILE            (FN_FILE + 7 )    /* Open */
 
 #define FN_OUTLINE_TO_IMPRESS   (FN_FILE + 36)  /* Send outline to impress */
diff --git a/sw/sdi/docsh.sdi b/sw/sdi/docsh.sdi
index 9085bdf..5e9fe78 100644
--- a/sw/sdi/docsh.sdi
+++ b/sw/sdi/docsh.sdi
@@ -59,6 +59,11 @@ interface TextDocument : BaseTextDocument
         ExecMethod = Execute;
         StateMethod = GetState;
     ]
+    FN_SAVE_FILE_AS
+    [
+        ExecMethod = Execute;
+        StateMethod = GetState;
+    ]
 }
 
 shell SwDocShell
diff --git a/sw/sdi/swriter.sdi b/sw/sdi/swriter.sdi
index deea1c0..364ece7 100644
--- a/sw/sdi/swriter.sdi
+++ b/sw/sdi/swriter.sdi
@@ -10026,6 +10026,33 @@ SfxVoidItem OpenFromWriter FN_OPEN_FILE
     GroupId = GID_APPLICATION;
 ]
 
+SfxVoidItem SaveAs FN_SAVE_FILE_AS
+()
+[
+    /* flags: */
+    AutoUpdate = FALSE,
+    Cachable = Cachable,
+    FastCall = FALSE,
+    HasCoreId = FALSE,
+    HasDialog = FALSE,
+    ReadOnlyDoc = TRUE,
+    Toggle = FALSE,
+    Container = FALSE,
+    RecordAbsolute = FALSE,
+    RecordPerSet;
+    Synchron;
+
+    /* status: */
+    SlotType = SfxStringItem
+
+    /* config: */
+    AccelConfig = TRUE,
+    MenuConfig = TRUE,
+    StatusBarConfig = FALSE,
+    ToolBoxConfig = TRUE,
+    GroupId = GID_APPLICATION;
+]
+
 SfxInt16Item PageColumnType SID_ATTR_PAGE_COLUMN
 
 [
diff --git a/sw/source/uibase/app/swmodule.cxx b/sw/source/uibase/app/swmodule.cxx
index a9af46e..2bd0ebc 100644
--- a/sw/source/uibase/app/swmodule.cxx
+++ b/sw/source/uibase/app/swmodule.cxx
@@ -307,6 +307,7 @@ void SwDLL::RegisterControls()
     SvxColorToolBoxControl::RegisterControl( SID_EXTRUSION_3D_COLOR, pMod );
     svx::FontWorkShapeTypeControl::RegisterControl( SID_FONTWORK_SHAPE_TYPE, pMod );
 
+    SfxSaveAsToolBoxControl::RegisterControl(FN_SAVE_FILE_AS, pMod );
     SvxClipBoardControl::RegisterControl(SID_PASTE, pMod );
     SvxUndoRedoControl::RegisterControl(SID_UNDO, pMod );
     SvxUndoRedoControl::RegisterControl(SID_REDO, pMod );
diff --git a/sw/uiconfig/swriter/toolbar/standardbar.xml b/sw/uiconfig/swriter/toolbar/standardbar.xml
index d94a44b..6963143 100644
--- a/sw/uiconfig/swriter/toolbar/standardbar.xml
+++ b/sw/uiconfig/swriter/toolbar/standardbar.xml
@@ -24,7 +24,7 @@
  <toolbar:toolbaritem xlink:href=".uno:OpenFromWriter" toolbar:style="dropdown"/>
  <toolbar:toolbaritem xlink:href=".uno:OpenRemote"/>
  <toolbar:toolbaritem xlink:href=".uno:Save" toolbar:helpid="5505"/>
- <toolbar:toolbaritem xlink:href=".uno:SaveAs" toolbar:helpid="5502"/>
+ <toolbar:toolbaritem xlink:href=".uno:SaveAs" toolbar:style="dropdown" toolbar:helpid="5502"/>
  <toolbar:toolbaritem xlink:href=".uno:SendMail" toolbar:visible="false" toolbar:helpid="5331"/>
  <toolbar:toolbarseparator/>
  <toolbar:toolbaritem xlink:href=".uno:EditDoc" toolbar:helpid="6312" toolbar:visible="false"/>


More information about the Libreoffice-commits mailing list