summaryrefslogtreecommitdiff
path: root/framework
diff options
context:
space:
mode:
authorMaxim Monastirsky <momonasmon@gmail.com>2016-10-18 23:56:57 +0300
committerMaxim Monastirsky <momonasmon@gmail.com>2016-10-27 11:05:38 +0300
commite59013d6e95846fbc8066bdd8ef3b4b132043e45 (patch)
tree8c00a538aa014d42229bf1eb3f41a0df2028e194 /framework
parent853c9efd00f38fd9f2da0fe50a866bf1592e3451 (diff)
GenericPopupToolbarController: Support replacing the main command
If a second arg is passed in the "Value" property, it will be treated as boolean. If true - the button will be ToolBoxItemBits::DROPDOWN, and will keep replacing the main command with the last selected one from the dropdown. It will also respond to status updates of that command, currently for enabled/disabled and boolean (true treated as pressed) states. Change-Id: I09a5c20e6d2a010867037754f036096246749ec4
Diffstat (limited to 'framework')
-rw-r--r--framework/source/uielement/popuptoolbarcontroller.cxx40
1 files changed, 35 insertions, 5 deletions
diff --git a/framework/source/uielement/popuptoolbarcontroller.cxx b/framework/source/uielement/popuptoolbarcontroller.cxx
index ee8c0d3ba6de..acf28d161583 100644
--- a/framework/source/uielement/popuptoolbarcontroller.cxx
+++ b/framework/source/uielement/popuptoolbarcontroller.cxx
@@ -272,7 +272,8 @@ public:
virtual css::uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (css::uno::RuntimeException) override;
private:
- bool m_bSplitButton;
+ bool m_bSplitButton, m_bReplaceWithLast;
+ void functionExecuted(const OUString &rCommand) override;
ToolBoxItemBits getDropDownStyle() const override;
};
@@ -280,19 +281,21 @@ GenericPopupToolbarController::GenericPopupToolbarController(
const css::uno::Reference< css::uno::XComponentContext >& xContext,
const css::uno::Sequence< css::uno::Any >& rxArgs )
: PopupMenuToolbarController( xContext )
- , m_bSplitButton( false )
+ , m_bReplaceWithLast( false )
{
css::beans::PropertyValue aPropValue;
for ( const auto& arg: rxArgs )
{
if ( ( arg >>= aPropValue ) && aPropValue.Name == "Value" )
{
- aPropValue.Value >>= m_aPopupCommand;
+ OUString aValue;
+ aPropValue.Value >>= aValue;
+ m_aPopupCommand = aValue.getToken(0, ';');
+ m_bReplaceWithLast = aValue.getToken(1, ';').toBoolean();
break;
}
}
- if ( !m_aPopupCommand.isEmpty() )
- m_bSplitButton = true;
+ m_bSplitButton = m_bReplaceWithLast || !m_aPopupCommand.isEmpty();
}
OUString GenericPopupToolbarController::getImplementationName()
@@ -313,6 +316,33 @@ css::uno::Sequence<OUString> GenericPopupToolbarController::getSupportedServiceN
return {"com.sun.star.frame.ToolbarController"};
}
+void GenericPopupToolbarController::functionExecuted( const OUString& rCommand )
+{
+ if ( m_bReplaceWithLast )
+ {
+ removeStatusListener( m_aCommandURL );
+
+ OUString aRealCommand( vcl::CommandInfoProvider::Instance().GetRealCommandForCommand( rCommand, m_xFrame ) );
+ m_aCommandURL = aRealCommand.isEmpty() ? rCommand : aRealCommand;
+ addStatusListener( m_aCommandURL );
+
+ ToolBox* pToolBox = nullptr;
+ sal_uInt16 nId = 0;
+ if ( getToolboxId( nId, &pToolBox ) )
+ {
+ pToolBox->SetItemCommand( nId, rCommand );
+ pToolBox->SetHelpText( nId, OUString() ); // Will retrieve the new one from help.
+ pToolBox->SetItemText( nId, vcl::CommandInfoProvider::Instance().GetLabelForCommand( rCommand, m_xFrame ) );
+ pToolBox->SetQuickHelpText( nId, vcl::CommandInfoProvider::Instance().GetTooltipForCommand( rCommand, m_xFrame ) );
+ Image aImage = vcl::CommandInfoProvider::Instance().GetImageForCommand( rCommand,
+ pToolBox->GetToolboxButtonSize() == ToolBoxButtonSize::Large,
+ m_xFrame );
+ if ( !!aImage )
+ pToolBox->SetItemImage( nId, aImage );
+ }
+ }
+}
+
ToolBoxItemBits GenericPopupToolbarController::getDropDownStyle() const
{
return m_bSplitButton ? ToolBoxItemBits::DROPDOWN : ToolBoxItemBits::DROPDOWNONLY;