summaryrefslogtreecommitdiff
path: root/framework/source/uielement
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2015-12-22 13:12:23 +0200
committerMaxim Monastirsky <momonasmon@gmail.com>2015-12-23 09:38:25 +0000
commit22328a224df4619218b88205838307f70612207e (patch)
tree251c9aaf8ab1b1db5cf80af9c8644d6cacd6d897 /framework/source/uielement
parent2351fd5d489fde281e8d1ef97af747149a29c247 (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. TODO: - Icons for the document modified state are still missing. I added some fake links to Tango's links.txt in order to test the new behavior. These links shouldn't stay as-is in a production version! Change-Id: I56c169bf48b78faaf53c2989ce8624f8297ffb6e Reviewed-on: https://gerrit.libreoffice.org/20839 Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com> Tested-by: Maxim Monastirsky <momonasmon@gmail.com>
Diffstat (limited to 'framework/source/uielement')
-rw-r--r--framework/source/uielement/popuptoolbarcontroller.cxx159
1 files changed, 153 insertions, 6 deletions
diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx
index cd5931c24144..43b68821cd15 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:
explicit 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();
}
}