diff options
author | Maxim Monastirsky <momonasmon@gmail.com> | 2015-12-22 13:12:23 +0200 |
---|---|---|
committer | Adolfo Jayme Barrientos <fitojb@ubuntu.com> | 2016-01-12 12:46:31 -0600 |
commit | 677197b3459df2c89be32595e0cb1b8b3e144c69 (patch) | |
tree | 370561ff6bb70aa54052d1cf95081792f894de19 /framework | |
parent | feebc5953fb416c5dc8cdf8c7e924a9ff9c70f17 (diff) |
New saving behavior
Changes in this commit:
- AlwaysAllowSave config is gone. Saving is always permitted, unless in
a read only document. Also changed the behavior in dbaccess to match
sfx2.
- The toolbar save button is always enabled, to always give access to
the dropdown. That's the case even in a read only document, except
that it changes to DROPDOWNONLY, and the save as command icon+tooltip.
In table/query designers we still disable the button in read only state.
- When the document is modified, the toolbar button gets a special icon
to indicate that.
Reviewed-on: https://gerrit.libreoffice.org/20839
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
Tested-by: Maxim Monastirsky <momonasmon@gmail.com>
(cherry picked from commit 22328a224df4619218b88205838307f70612207e)
loplugin:unreffun
(cherry picked from commit ea708936c4684668f9aefc3ce9ec2001dbd4bdf2)
Change-Id: I56c169bf48b78faaf53c2989ce8624f8297ffb6e
Tango: Update Save icons and support “savemodified” status
Change-Id: I03589895437907b9048542f07128801577fe62dc
(cherry picked from commit a7198d38f0294ab5db04a7f4457565ea8b2c32f1)
Reviewed-on: https://gerrit.libreoffice.org/21260
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Reviewed-by: Adolfo Jayme Barrientos <fitojb@ubuntu.com>
Tested-by: Jenkins <ci@libreoffice.org>
Tested-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'framework')
-rw-r--r-- | framework/source/uielement/popuptoolbarcontroller.cxx | 159 |
1 files changed, 153 insertions, 6 deletions
diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx index 4055cbcd8944..111491b89fd8 100644 --- a/framework/source/uielement/popuptoolbarcontroller.cxx +++ b/framework/source/uielement/popuptoolbarcontroller.cxx @@ -21,6 +21,7 @@ #include <cppuhelper/supportsservice.hxx> #include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/propertysequence.hxx> #include <framework/menuconfiguration.hxx> #include <rtl/ref.hxx> #include <svtools/imagemgr.hxx> @@ -30,6 +31,7 @@ #include <toolkit/helper/vclunohelper.hxx> #include <tools/urlobj.hxx> #include <unotools/moduleoptions.hxx> +#include <vcl/commandinfoprovider.hxx> #include <vcl/svapp.hxx> #include <vcl/toolbox.hxx> @@ -38,10 +40,14 @@ #include <com/sun/star/frame/thePopupMenuControllerFactory.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/frame/XPopupMenuController.hpp> +#include <com/sun/star/frame/XStorable.hpp> +#include <com/sun/star/frame/XSubToolbarController.hpp> #include <com/sun/star/frame/XUIControllerFactory.hpp> +#include <com/sun/star/graphic/GraphicProvider.hpp> #include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/ucb/CommandFailedException.hpp> #include <com/sun/star/ucb/ContentCreationException.hpp> +#include <com/sun/star/util/XModifiable.hpp> using namespace framework; @@ -302,34 +308,175 @@ ToolBoxItemBits GenericPopupToolbarController::getDropDownStyle() const return m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY; } -class SaveToolbarController : public PopupMenuToolbarController +class SaveToolbarController : public cppu::ImplInheritanceHelper< PopupMenuToolbarController, + css::frame::XSubToolbarController, + css::util::XModifyListener > { public: SaveToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); + // XInitialization + virtual void SAL_CALL initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) throw ( css::uno::Exception, css::uno::RuntimeException, std::exception ) override; + + // XSubToolbarController + // Ugly HACK to cause ToolBarManager ask our controller for updated image, in case of icon theme change. + virtual sal_Bool SAL_CALL opensSubToolbar() throw ( css::uno::RuntimeException, std::exception ) override; + virtual OUString SAL_CALL getSubToolbarName() throw ( css::uno::RuntimeException, std::exception ) override; + virtual void SAL_CALL functionSelected( const OUString& aCommand ) throw ( css::uno::RuntimeException, std::exception ) override; + virtual void SAL_CALL updateImage() throw ( css::uno::RuntimeException, std::exception ) override; + // XStatusListener virtual void SAL_CALL statusChanged( const css::frame::FeatureStateEvent& rEvent ) throw ( css::uno::RuntimeException, std::exception ) override; + // XModifyListener + virtual void SAL_CALL modified( const css::lang::EventObject& rEvent ) throw ( css::uno::RuntimeException, std::exception ) override; + + // XEventListener + virtual void SAL_CALL disposing( const css::lang::EventObject& rEvent ) throw ( css::uno::RuntimeException, std::exception ) override; + + // XComponent + virtual void SAL_CALL dispose() throw ( css::uno::RuntimeException, std::exception ) override; + // XServiceInfo virtual OUString SAL_CALL getImplementationName() throw ( css::uno::RuntimeException ) override; virtual sal_Bool SAL_CALL supportsService( OUString const & rServiceName ) throw ( css::uno::RuntimeException ) override; virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( css::uno::RuntimeException ) override; + +private: + css::uno::Reference< css::util::XModifiable > m_xModifiable; }; SaveToolbarController::SaveToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) - : PopupMenuToolbarController( rxContext, ".uno:SaveAsMenu" ) + : ImplInheritanceHelper( rxContext, ".uno:SaveAsMenu" ) { } -void SaveToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) +void SaveToolbarController::initialize( const css::uno::Sequence< css::uno::Any >& aArguments ) + throw ( css::uno::Exception, css::uno::RuntimeException, std::exception ) +{ + PopupMenuToolbarController::initialize( aArguments ); + + if ( m_sModuleName.endsWith( "RelationDesign" ) ) + { + // Should not have the dropdown. + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if ( getToolboxId( nId, &pToolBox ) ) + pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~ ToolBoxItemBits::DROPDOWN ); + return; + } + + css::uno::Reference< css::frame::XController > xController( m_xFrame->getController(), css::uno::UNO_QUERY ); + if ( xController.is() ) + m_xModifiable.set( xController->getModel(), css::uno::UNO_QUERY ); + + if ( !m_xModifiable.is() ) + // Can be in table/query design. + m_xModifiable.set( xController, css::uno::UNO_QUERY ); + + if ( m_xModifiable.is() ) + m_xModifiable->addModifyListener( this ); +} + +sal_Bool SaveToolbarController::opensSubToolbar() + throw ( css::uno::RuntimeException, std::exception ) +{ + return sal_True; +} + +OUString SaveToolbarController::getSubToolbarName() + throw ( css::uno::RuntimeException, std::exception ) +{ + return OUString(); +} + +void SaveToolbarController::functionSelected( const OUString& /*aCommand*/ ) + throw ( css::uno::RuntimeException, std::exception ) +{ +} + +void SaveToolbarController::updateImage() throw ( css::uno::RuntimeException, std::exception ) { ToolBox* pToolBox = nullptr; sal_uInt16 nId = 0; - if ( getToolboxId( nId, &pToolBox ) ) + if ( !getToolboxId( nId, &pToolBox ) ) + return; + + bool bLargeIcons = pToolBox->GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE; + css::uno::Reference< css::frame::XStorable > xStorable( m_xModifiable, css::uno::UNO_QUERY ); + Image aImage; + + if ( xStorable.is() && xStorable->isReadonly() ) + { + aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( ".uno:SaveAs", bLargeIcons, m_xFrame ); + } + else if ( m_xModifiable.is() && m_xModifiable->isModified() ) + { + const OUString aImageURL( "private:graphicrepository/res/savemodified_" + ( bLargeIcons ? OUString( "large.png" ) : OUString( "small.png" ) ) ); + const css::uno::Reference< css::graphic::XGraphicProvider > xGraphicProvider( css::graphic::GraphicProvider::create( m_xContext ) ); + const css::uno::Reference< css::graphic::XGraphic > xGraphic( + xGraphicProvider->queryGraphic( comphelper::InitPropertySequence( { { "URL", css::uno::makeAny( aImageURL ) } } ) ), css::uno::UNO_QUERY ); + if ( xGraphic.is() ) + aImage = Image( xGraphic ); + } + + if ( !aImage ) + aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( m_aCommandURL, bLargeIcons, m_xFrame ); + + if ( !!aImage ) + pToolBox->SetItemImage( nId, aImage ); +} + +void SaveToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) + throw ( css::uno::RuntimeException, std::exception ) +{ + css::uno::Reference< css::frame::XStorable > xStorable( m_xModifiable, css::uno::UNO_QUERY ); + + // If the model is able to tell us whether we're in read only mode, change the button to save as only mode + // based on that. Otherwise just dumbly disable the button (because there could be other reasons why the + // save slot is disabled, where save as isn't possible as well). + if ( xStorable.is() ) + { + ToolBox* pToolBox = nullptr; + sal_uInt16 nId = 0; + if ( !getToolboxId( nId, &pToolBox ) ) + return; + + bool bReadOnly = xStorable->isReadonly(); + pToolBox->SetQuickHelpText( nId, + vcl::CommandInfoProvider::Instance().GetTooltipForCommand( bReadOnly ? OUString( ".uno:SaveAs" ) : m_aCommandURL, m_xFrame ) ); + pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( bReadOnly ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) ); + pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( bReadOnly ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) ); + updateImage(); + } + else + PopupMenuToolbarController::statusChanged( rEvent ); +} + +void SaveToolbarController::modified( const css::lang::EventObject& /*rEvent*/ ) + throw ( css::uno::RuntimeException, std::exception ) +{ + updateImage(); +} + +void SaveToolbarController::disposing( const css::lang::EventObject& rEvent ) + throw ( css::uno::RuntimeException, std::exception ) +{ + if ( rEvent.Source == m_xModifiable ) + m_xModifiable.clear(); + else + PopupMenuToolbarController::disposing( rEvent ); +} + +void SaveToolbarController::dispose() + throw ( css::uno::RuntimeException, std::exception ) +{ + PopupMenuToolbarController::dispose(); + if ( m_xModifiable.is() ) { - pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) ); - pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) ); + m_xModifiable->removeModifyListener( this ); + m_xModifiable.clear(); } } |