Kaydet (Commit) ce722af0 authored tarafından Szymon Kłos's avatar Szymon Kłos

'Save As' popup menu in the Writer's toolbar

Change-Id: I1b1cb7fcd2ae0e0f50e4d8e3900bc416435e60bf
üst 1ceb7bc5
......@@ -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 \
......
......@@ -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)
......
......@@ -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%";
......
/* -*- 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: */
......@@ -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"/>
......
......@@ -315,6 +315,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:
......
......@@ -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="GraphicFilterControl" oor:op="replace">
......
......@@ -106,6 +106,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 )
{
......@@ -1403,4 +1404,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: */
......@@ -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 */
......
......@@ -59,6 +59,11 @@ interface TextDocument : BaseTextDocument
ExecMethod = Execute;
StateMethod = GetState;
]
FN_SAVE_FILE_AS
[
ExecMethod = Execute;
StateMethod = GetState;
]
}
shell SwDocShell
......
......@@ -10124,6 +10124,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
[
......
......@@ -296,6 +296,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 );
......
......@@ -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"/>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment