[Libreoffice-commits] core.git: Branch 'libreoffice-5-2' - framework/source

Maxim Monastirsky momonasmon at gmail.com
Fri Jun 17 13:39:32 UTC 2016


 framework/source/uielement/popuptoolbarcontroller.cxx |   48 ++++++++++--------
 1 file changed, 27 insertions(+), 21 deletions(-)

New commits:
commit 003431294d7c02d1acc24a822f7550e45db2dbb1
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Thu Jun 16 20:11:14 2016 +0300

    SaveToolbarController: back to using XStorable
    
    See 747a0fdda2a7723c2f8a8a022b468bcf29c700e3
    ("SaveToolbarController: Better support of readonly docs")
    for the background. However this doesn't work, because
    the save slot is disabled in other cases too, not just for
    r/o docs (e.g. locked UI during file save, or when cond.
    formatting window open in Calc).
    
    Until a better solution is found, at least make sure that
    the button is disabled, instead of going into the normal
    save mode, which doesn't work.
    
    Change-Id: If6e1b91b7c780fffac22cdb25c82bbd0a8520dc4
    (cherry picked from commit 011128aa9493a680c3e9da6d074f125a90ec455c)
    Reviewed-on: https://gerrit.libreoffice.org/26417
    Reviewed-by: Maxim Monastirsky <momonasmon at gmail.com>
    Tested-by: Maxim Monastirsky <momonasmon at gmail.com>

diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx
index 2bdce6a..5d7b6d8 100644
--- a/framework/source/uielement/popuptoolbarcontroller.cxx
+++ b/framework/source/uielement/popuptoolbarcontroller.cxx
@@ -43,6 +43,7 @@
 #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/lang/XServiceInfo.hpp>
@@ -356,16 +357,15 @@ public:
     virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() throw ( css::uno::RuntimeException ) override;
 
 private:
-    bool m_bSaveAsModeAllowed;
-    bool m_bSaveAsModeActive;
+    bool m_bReadOnly;
     bool m_bModified;
+    css::uno::Reference< css::frame::XStorable > m_xStorable;
     css::uno::Reference< css::util::XModifiable > m_xModifiable;
 };
 
 SaveToolbarController::SaveToolbarController( const css::uno::Reference< css::uno::XComponentContext >& rxContext )
     : ImplInheritanceHelper( rxContext, ".uno:SaveAsMenu" )
-    , m_bSaveAsModeAllowed( true )
-    , m_bSaveAsModeActive( false )
+    , m_bReadOnly( false )
     , m_bModified( false )
 {
 }
@@ -377,22 +377,22 @@ void SaveToolbarController::initialize( const css::uno::Sequence< css::uno::Any
 
     ToolBox* pToolBox = nullptr;
     sal_uInt16 nId = 0;
-    if ( getToolboxId( nId, &pToolBox ) && pToolBox->GetItemCommand( nId ) != m_aCommandURL )
-    {
-        m_bSaveAsModeAllowed = false;
-        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~ ToolBoxItemBits::DROPDOWN );
-    }
+    if ( !getToolboxId( nId, &pToolBox ) )
+        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() )
-    {
+    if ( m_xModifiable.is() && pToolBox->GetItemCommand( nId ) == m_aCommandURL )
+        // Will also enable the save as only mode.
+        m_xStorable.set( m_xModifiable, css::uno::UNO_QUERY );
+    else if ( !m_xModifiable.is() )
         // Can be in table/query design.
-        m_bSaveAsModeAllowed = false;
         m_xModifiable.set( xController, css::uno::UNO_QUERY );
-    }
+    else
+        // Simple save button, without the dropdown.
+        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~ ToolBoxItemBits::DROPDOWN );
 }
 
 void SaveToolbarController::update()
@@ -436,7 +436,7 @@ void SaveToolbarController::updateImage()
     bool bLargeIcons = pToolBox->GetToolboxButtonSize() == TOOLBOX_BUTTONSIZE_LARGE;
     Image aImage;
 
-    if ( m_bSaveAsModeActive )
+    if ( m_bReadOnly )
     {
         aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( ".uno:SaveAs", bLargeIcons, m_xFrame );
     }
@@ -461,17 +461,19 @@ void SaveToolbarController::statusChanged( const css::frame::FeatureStateEvent&
     if ( !getToolboxId( nId, &pToolBox ) )
         return;
 
-    if ( !m_bSaveAsModeAllowed )
-        pToolBox->EnableItem( nId, rEvent.IsEnabled );
-    else if ( m_bSaveAsModeActive == bool( rEvent.IsEnabled ) )
+    bool bLastReadOnly = m_bReadOnly;
+    m_bReadOnly = m_xStorable.is() && m_xStorable->isReadonly();
+    if ( bLastReadOnly != m_bReadOnly )
     {
-        m_bSaveAsModeActive = !m_bSaveAsModeActive;
         pToolBox->SetQuickHelpText( nId,
-            vcl::CommandInfoProvider::Instance().GetTooltipForCommand( rEvent.IsEnabled ? m_aCommandURL : OUString( ".uno:SaveAs" ), m_xFrame ) );
-        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) );
-        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) |  ( rEvent.IsEnabled ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
+            vcl::CommandInfoProvider::Instance().GetTooltipForCommand( m_bReadOnly ? OUString( ".uno:SaveAs" ) : m_aCommandURL, m_xFrame ) );
+        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) & ~( m_bReadOnly ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY ) );
+        pToolBox->SetItemBits( nId, pToolBox->GetItemBits( nId ) |  ( m_bReadOnly ? ToolBoxItemBits::DROPDOWNONLY : ToolBoxItemBits::DROPDOWN ) );
         updateImage();
     }
+
+    if ( !m_bReadOnly )
+        pToolBox->EnableItem( nId, rEvent.IsEnabled );
 }
 
 void SaveToolbarController::modified( const css::lang::EventObject& /*rEvent*/ )
@@ -487,7 +489,10 @@ void SaveToolbarController::disposing( const css::lang::EventObject& rEvent )
     throw ( css::uno::RuntimeException, std::exception )
 {
     if ( rEvent.Source == m_xModifiable )
+    {
         m_xModifiable.clear();
+        m_xStorable.clear();
+    }
     else
         PopupMenuToolbarController::disposing( rEvent );
 }
@@ -501,6 +506,7 @@ void SaveToolbarController::dispose()
         m_xModifiable->removeModifyListener( this );
         m_xModifiable.clear();
     }
+    m_xStorable.clear();
 }
 
 OUString SaveToolbarController::getImplementationName()


More information about the Libreoffice-commits mailing list