Kaydet (Commit) 747a0fdd authored tarafından Maxim Monastirsky's avatar Maxim Monastirsky

SaveToolbarController: Better support of readonly docs

The sfx2 impl. of XStorable::isReadonly isn't really helpful
for files w/o write permissions that were switched to edit
mode, as it returns the state of the UI. So instead let's just
rely on the state of the .uno:Save slot.

Change-Id: I3b033be3c9424a4479e9224f02d186960b540d21
üst cb6d938a
...@@ -43,7 +43,6 @@ ...@@ -43,7 +43,6 @@
#include <com/sun/star/frame/thePopupMenuControllerFactory.hpp> #include <com/sun/star/frame/thePopupMenuControllerFactory.hpp>
#include <com/sun/star/frame/XDispatchProvider.hpp> #include <com/sun/star/frame/XDispatchProvider.hpp>
#include <com/sun/star/frame/XPopupMenuController.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/XSubToolbarController.hpp>
#include <com/sun/star/frame/XUIControllerFactory.hpp> #include <com/sun/star/frame/XUIControllerFactory.hpp>
#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/lang/XServiceInfo.hpp>
...@@ -355,14 +354,14 @@ public: ...@@ -355,14 +354,14 @@ public:
private: private:
bool m_bSplitButton; bool m_bSplitButton;
bool m_bModified; TriState m_eModified;
css::uno::Reference< css::util::XModifiable > m_xModifiable; css::uno::Reference< css::util::XModifiable > m_xModifiable;
}; };
SaveToolbarController::SaveToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext ) SaveToolbarController::SaveToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
: ImplInheritanceHelper( rxContext, ".uno:SaveAsMenu" ) : ImplInheritanceHelper( rxContext, ".uno:SaveAsMenu" )
, m_bSplitButton( true ) , m_bSplitButton( true )
, m_bModified( false ) , m_eModified( TRISTATE_FALSE )
{ {
} }
...@@ -378,20 +377,6 @@ void SaveToolbarController::initialize( const css::uno::Sequence< css::uno::Any ...@@ -378,20 +377,6 @@ void SaveToolbarController::initialize( const css::uno::Sequence< css::uno::Any
m_bSplitButton = false; m_bSplitButton = false;
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~ ToolBoxItemBits::DROPDOWN ); pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~ ToolBoxItemBits::DROPDOWN );
} }
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 );
m_bModified = m_xModifiable->isModified();
}
} }
sal_Bool SaveToolbarController::opensSubToolbar() sal_Bool SaveToolbarController::opensSubToolbar()
...@@ -421,14 +406,13 @@ void SaveToolbarController::updateImage() ...@@ -421,14 +406,13 @@ void SaveToolbarController::updateImage()
return; return;
bool bLargeIcons = pToolBox->GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE; bool bLargeIcons = pToolBox->GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE;
css::uno::Reference< css::frame::XStorable > xStorable( m_xModifiable, css::uno::UNO_QUERY );
Image aImage; Image aImage;
if ( m_bSplitButton && xStorable.is() && xStorable->isReadonly() ) if ( m_bSplitButton && m_eModified == TRISTATE_INDET )
{ {
aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( ".uno:SaveAs", bLargeIcons, m_xFrame ); aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( ".uno:SaveAs", bLargeIcons, m_xFrame );
} }
else if ( m_bModified ) else if ( m_eModified == TRISTATE_TRUE )
{ {
Image aResImage( bLargeIcons ? FwkResId( IMG_SAVEMODIFIED_LARGE ) : FwkResId( IMG_SAVEMODIFIED_SMALL ) ); Image aResImage( bLargeIcons ? FwkResId( IMG_SAVEMODIFIED_LARGE ) : FwkResId( IMG_SAVEMODIFIED_SMALL ) );
aImage = aResImage; aImage = aResImage;
...@@ -444,36 +428,55 @@ void SaveToolbarController::updateImage() ...@@ -444,36 +428,55 @@ void SaveToolbarController::updateImage()
void SaveToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent ) void SaveToolbarController::statusChanged( const css::frame::FeatureStateEvent& rEvent )
throw ( css::uno::RuntimeException, std::exception ) throw ( css::uno::RuntimeException, std::exception )
{ {
css::uno::Reference< css::frame::XStorable > xStorable( m_xModifiable, css::uno::UNO_QUERY ); ToolBox* pToolBox = nullptr;
sal_uInt16 nId = 0;
if ( !getToolboxId( nId, &pToolBox ) )
return;
css::uno::Reference< css::frame::XModel > xModel;
css::uno::Reference< css::frame::XController > xController( m_xFrame->getController(), css::uno::UNO_QUERY );
if ( xController.is() )
xModel.set( xController->getModel(), 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 if ( !m_xModifiable.is() )
// 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 ( m_bSplitButton && xStorable.is() )
{ {
ToolBox* pToolBox = nullptr; m_xModifiable.set( xModel, css::uno::UNO_QUERY );
sal_uInt16 nId = 0;
if ( !getToolboxId( nId, &pToolBox ) ) if ( !m_xModifiable.is() )
return; // Can be in table/query design.
m_xModifiable.set( xController, css::uno::UNO_QUERY );
bool bReadOnly = xStorable->isReadonly(); if ( m_xModifiable.is() )
m_xModifiable->addModifyListener( this );
}
m_eModified = m_xModifiable.is() && m_xModifiable->isModified() ? TRISTATE_TRUE : TRISTATE_FALSE;
// xModel is nullptr in table/query design, so use that to exclude them from
// the save as only mode, as they disable also the save as command when not in
// edit mode, or with empty table/query.
if ( m_bSplitButton && xModel.is() )
{
pToolBox->SetQuickHelpText( nId, pToolBox->SetQuickHelpText( nId,
vcl::CommandInfoProvider::Instance().GetTooltipForCommand( bReadOnly ? OUString( ".uno:SaveAs" ) : m_aCommandURL, m_xFrame ) ); vcl::CommandInfoProvider::Instance().GetTooltipForCommand( rEvent.IsEnabled ? m_aCommandURL : OUString( ".uno:SaveAs" ), m_xFrame ) );
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( bReadOnly ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) ); pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) );
pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( bReadOnly ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) ); pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) | ( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
updateImage(); if ( !rEvent.IsEnabled )
m_eModified = TRISTATE_INDET;
} }
else else
PopupMenuToolbarController::statusChanged( rEvent ); pToolBox->EnableItem( nId, rEvent.IsEnabled );
updateImage();
} }
void SaveToolbarController::modified( const css::lang::EventObject& /*rEvent*/ ) void SaveToolbarController::modified( const css::lang::EventObject& /*rEvent*/ )
throw ( css::uno::RuntimeException, std::exception ) throw ( css::uno::RuntimeException, std::exception )
{ {
bool bModified = m_xModifiable->isModified(); TriState eModified = m_xModifiable->isModified() ? TRISTATE_TRUE : TRISTATE_FALSE;
if ( bModified != m_bModified ) if ( eModified != m_eModified && TRISTATE_INDET != m_eModified )
{ {
m_bModified = bModified; m_eModified = eModified;
updateImage(); updateImage();
} }
} }
......
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