forms/source/solar/control/navtoolbar.cxx     |    6 ++----
 framework/source/uielement/toolbarmanager.cxx |    9 +++------
 framework/source/uielement/toolbarmerger.cxx  |    3 +--
 include/vcl/toolbox.hxx                       |    1 +
 vcl/inc/toolbox.h                             |    1 +
 vcl/source/app/salvtables.cxx                 |    3 +--
 vcl/source/window/NotebookBarAddonsMerger.cxx |    1 -
 vcl/source/window/builder.cxx                 |    3 +--
 vcl/source/window/toolbox2.cxx                |   14 ++++++++------
 vcl/workben/vcldemo.cxx                       |    2 +-
 10 files changed, 19 insertions(+), 24 deletions(-)

New commits:
commit c76857fe4e725834e6be9bd5b3273df95bf7fafd
Author:     Maxim Monastirsky <momonas...@gmail.com>
AuthorDate: Thu Jul 21 23:56:42 2022 +0300
Commit:     Maxim Monastirsky <momonas...@gmail.com>
CommitDate: Wed Aug 10 08:28:18 2022 +0200

    Make ToolBox::InsertItem take the command name
    
    For the next patch for tdf#149956 I need the command to be
    already set when the VclEventId::ToolboxItemAdded event is emitted.
    
    Change-Id: I3d8ce44b426a3ed5704d4520d6e62bc4efbf8e44
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138038
    Tested-by: Jenkins
    Reviewed-by: Maxim Monastirsky <momonas...@gmail.com>

diff --git a/forms/source/solar/control/navtoolbar.cxx 
b/forms/source/solar/control/navtoolbar.cxx
index 217a9d55d0d3..7193ac4532c1 100644
--- a/forms/source/solar/control/navtoolbar.cxx
+++ b/forms/source/solar/control/navtoolbar.cxx
@@ -91,7 +91,6 @@ namespace frm
             if ( pAsciiCommandName != nullptr )
                 return ".uno:" + OUString::createFromAscii( pAsciiCommandName 
);
 
-            OSL_FAIL( "lcl_getCommandURL: unknown FormFeature!" );
             return OUString();
         }
     }
@@ -279,13 +278,12 @@ namespace frm
             {   // it's _not_ a separator
 
                 // insert the entry
-                m_pToolbar->InsertItem( 
ToolBoxItemId(pSupportedFeatures->nId), OUString(), pSupportedFeatures->bRepeat 
? ToolBoxItemBits::REPEAT : ToolBoxItemBits::NONE );
+                OUString sCommandURL( lcl_getCommandURL( 
pSupportedFeatures->nId ) );
+                m_pToolbar->InsertItem( 
ToolBoxItemId(pSupportedFeatures->nId), OUString(), sCommandURL, 
pSupportedFeatures->bRepeat ? ToolBoxItemBits::REPEAT : ToolBoxItemBits::NONE );
                 m_pToolbar->SetQuickHelpText( 
ToolBoxItemId(pSupportedFeatures->nId), OUString() );  // TODO
 
                 if ( !isArtificialItem( pSupportedFeatures->nId ) )
                 {
-                    OUString sCommandURL( lcl_getCommandURL( 
pSupportedFeatures->nId ) );
-                    m_pToolbar->SetItemCommand( 
ToolBoxItemId(pSupportedFeatures->nId), sCommandURL );
                     auto aProperties = 
vcl::CommandInfoProvider::GetCommandProperties(sCommandURL, m_sModuleId);
                     
m_pToolbar->SetQuickHelpText(ToolBoxItemId(pSupportedFeatures->nId),
                             
vcl::CommandInfoProvider::GetLabelForCommand(aProperties));
diff --git a/framework/source/uielement/toolbarmanager.cxx 
b/framework/source/uielement/toolbarmanager.cxx
index 7dbee84c1072..ef3470a28fb3 100644
--- a/framework/source/uielement/toolbarmanager.cxx
+++ b/framework/source/uielement/toolbarmanager.cxx
@@ -221,8 +221,7 @@ public:
                             const OUString& rLabel,
                             ToolBoxItemBits nItemBits) override
     {
-        m_pToolBar->InsertItem( nId, rLabel, nItemBits );
-        m_pToolBar->SetItemCommand( nId, rCommandURL );
+        m_pToolBar->InsertItem( nId, rLabel, rCommandURL, nItemBits );
         m_pToolBar->SetQuickHelpText(nId, rTooltip);
         m_pToolBar->EnableItem( nId );
         m_pToolBar->SetItemState( nId, TRISTATE_FALSE );
@@ -1525,7 +1524,7 @@ void ToolBarManager::FillAddonToolbar( const Sequence< 
Sequence< PropertyValue >
             }
             else
             {
-                m_pToolBar->InsertItem( nId, aTitle );
+                m_pToolBar->InsertItem( nId, aTitle, aURL );
 
                 OUString 
aShortcut(vcl::CommandInfoProvider::GetCommandShortcut(aURL, m_xFrame));
                 if (!aShortcut.isEmpty())
@@ -1536,7 +1535,6 @@ void ToolBarManager::FillAddonToolbar( const Sequence< 
Sequence< PropertyValue >
                 pRuntimeItemData->aControlType = aControlType;
                 pRuntimeItemData->nWidth = nWidth;
                 m_pToolBar->SetItemData( nId, pRuntimeItemData );
-                m_pToolBar->SetItemCommand( nId, aURL );
 
                 // Fill command map. It stores all our commands and from what
                 // image manager we got our image. So we can decide if we have 
to use an
@@ -1583,8 +1581,7 @@ void ToolBarManager::FillOverflowToolbar( ToolBox const * 
pParent )
             }
 
             const OUString aCommandURL( pParent->GetItemCommand( nId ) );
-            m_pToolBar->InsertItem( nId, pParent->GetItemText( nId ) );
-            m_pToolBar->SetItemCommand( nId, aCommandURL );
+            m_pToolBar->InsertItem( nId, pParent->GetItemText( nId ), 
aCommandURL );
             m_pToolBar->SetQuickHelpText( nId, pParent->GetQuickHelpText( nId 
) );
 
             // Handle possible add-on controls.
diff --git a/framework/source/uielement/toolbarmerger.cxx 
b/framework/source/uielement/toolbarmerger.cxx
index db9416af66bc..5588ff0522d3 100644
--- a/framework/source/uielement/toolbarmerger.cxx
+++ b/framework/source/uielement/toolbarmerger.cxx
@@ -630,8 +630,7 @@ void ToolBarMerger::CreateToolbarItem( ToolBox* pToolbar, 
ToolBox::ImplToolItems
 {
     assert(pToolbar->GetItemData(nItemId) == nullptr); // that future would 
contain a double free
 
-    pToolbar->InsertItem( nItemId, rItem.aLabel, ToolBoxItemBits::NONE, nPos );
-    pToolbar->SetItemCommand( nItemId, rItem.aCommandURL );
+    pToolbar->InsertItem( nItemId, rItem.aLabel, rItem.aCommandURL, 
ToolBoxItemBits::NONE, nPos );
     pToolbar->SetQuickHelpText( nItemId, rItem.aLabel );
     pToolbar->SetItemText( nItemId, rItem.aLabel );
     pToolbar->EnableItem( nItemId );
diff --git a/include/vcl/toolbox.hxx b/include/vcl/toolbox.hxx
index e0f6f085fa66..f89cb335b541 100644
--- a/include/vcl/toolbox.hxx
+++ b/include/vcl/toolbox.hxx
@@ -313,6 +313,7 @@ public:
                                     ToolBoxItemBits nBits = 
ToolBoxItemBits::NONE,
                                     ImplToolItems::size_type nPos = APPEND );
     void                InsertItem( ToolBoxItemId nItemId, const OUString& 
rText,
+                                    const OUString& rCommand,
                                     ToolBoxItemBits nBits = 
ToolBoxItemBits::NONE,
                                     ImplToolItems::size_type nPos = APPEND );
     void                InsertWindow( ToolBoxItemId nItemId, vcl::Window* 
pWindow,
diff --git a/vcl/inc/toolbox.h b/vcl/inc/toolbox.h
index 387a0ba0037e..3dd481de6f01 100644
--- a/vcl/inc/toolbox.h
+++ b/vcl/inc/toolbox.h
@@ -71,6 +71,7 @@ struct ImplToolItem
                         ImplToolItem( ToolBoxItemId nItemId, Image aImage,
                                       ToolBoxItemBits nItemBits );
                         ImplToolItem( ToolBoxItemId nItemId, OUString aTxt,
+                                      OUString aCommand,
                                       ToolBoxItemBits nItemBits );
                         ImplToolItem( ToolBoxItemId nItemId, Image aImage,
                                       OUString aTxt,
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 673c2ea4dbec..39713700bd20 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -1111,8 +1111,7 @@ void SalInstanceToolbar::set_item_menu(const OString& 
rIdent, weld::Menu* pMenu)
 void SalInstanceToolbar::insert_item(int pos, const OUString& rId)
 {
     ToolBoxItemId nId(pos);
-    m_xToolBox->InsertItem(nId, rId, ToolBoxItemBits::ICON_ONLY);
-    m_xToolBox->SetItemCommand(nId, rId);
+    m_xToolBox->InsertItem(nId, OUString(), rId, ToolBoxItemBits::ICON_ONLY);
 }
 
 void SalInstanceToolbar::insert_separator(int pos, const OUString& /*rId*/)
diff --git a/vcl/source/window/NotebookBarAddonsMerger.cxx 
b/vcl/source/window/NotebookBarAddonsMerger.cxx
index 274b455bdb8f..3a96f2a380e9 100644
--- a/vcl/source/window/NotebookBarAddonsMerger.cxx
+++ b/vcl/source/window/NotebookBarAddonsMerger.cxx
@@ -78,7 +78,6 @@ static void CreateNotebookBarToolBox(vcl::Window* 
pNotebookbarToolBox,
     Image sImage;
     pToolbox->InsertItem(aAddonNotebookBarItem.sCommandURL, m_xFrame, 
ToolBoxItemBits::NONE, aSize);
     nItemId = pToolbox->GetItemId(aAddonNotebookBarItem.sCommandURL);
-    pToolbox->SetItemCommand(nItemId, aAddonNotebookBarItem.sCommandURL);
     pToolbox->SetQuickHelpText(nItemId, aAddonNotebookBarItem.sLabel);
 
     if (nIter < aImageVec.size())
diff --git a/vcl/source/window/builder.cxx b/vcl/source/window/builder.cxx
index f26d14462171..6b1b9632a40f 100644
--- a/vcl/source/window/builder.cxx
+++ b/vcl/source/window/builder.cxx
@@ -2093,10 +2093,9 @@ VclPtr<vcl::Window> VclBuilder::makeObject(vcl::Window 
*pParent, const OString &
             {
                 nItemId = ToolBoxItemId(pToolBox->GetItemCount() + 1);
                     //TODO: ImplToolItems::size_type -> sal_uInt16!
-                pToolBox->InsertItem(nItemId, extractLabel(rMap), nBits);
                 if (aCommand.isEmpty() && !m_bLegacy)
                     aCommand = OUString::fromUtf8(id);
-                pToolBox->SetItemCommand(nItemId, aCommand);
+                pToolBox->InsertItem(nItemId, extractLabel(rMap), aCommand, 
nBits);
             }
 
             pToolBox->SetHelpId(nItemId, m_sHelpRoot + id);
diff --git a/vcl/source/window/toolbox2.cxx b/vcl/source/window/toolbox2.cxx
index 3913b5ee6321..223938660c03 100644
--- a/vcl/source/window/toolbox2.cxx
+++ b/vcl/source/window/toolbox2.cxx
@@ -119,8 +119,9 @@ ImplToolItem::ImplToolItem( ToolBoxItemId nItemId, Image 
aImage,
 }
 
 ImplToolItem::ImplToolItem( ToolBoxItemId nItemId, OUString aText,
-                            ToolBoxItemBits nItemBits ) :
-    maText(std::move( aText ))
+                            OUString aCommand, ToolBoxItemBits nItemBits ) :
+    maText(std::move( aText )),
+    maCommandStr(std::move( aCommand ))
 {
     init(nItemId, nItemBits, false);
 }
@@ -417,7 +418,8 @@ void ToolBox::InsertItem( ToolBoxItemId nItemId, const 
Image& rImage, const OUSt
     CallEventListeners( VclEventId::ToolboxItemAdded, reinterpret_cast< void* 
>( nNewPos ) );
 }
 
-void ToolBox::InsertItem( ToolBoxItemId nItemId, const OUString& rText, 
ToolBoxItemBits nBits, ImplToolItems::size_type nPos )
+void ToolBox::InsertItem( ToolBoxItemId nItemId, const OUString& rText, const 
OUString& rCommand, ToolBoxItemBits nBits,
+                          ImplToolItems::size_type nPos )
 {
     SAL_WARN_IF( !nItemId, "vcl", "ToolBox::InsertItem(): ItemId == 0" );
     SAL_WARN_IF( GetItemPos( nItemId ) != ITEM_NOTFOUND, "vcl",
@@ -425,7 +427,7 @@ void ToolBox::InsertItem( ToolBoxItemId nItemId, const 
OUString& rText, ToolBoxI
 
     // create item and add to list
     mpData->m_aItems.insert( (nPos < mpData->m_aItems.size()) ? 
mpData->m_aItems.begin()+nPos : mpData->m_aItems.end(),
-                             ImplToolItem( nItemId, 
MnemonicGenerator::EraseAllMnemonicChars(rText), nBits ) );
+                             ImplToolItem( nItemId, 
MnemonicGenerator::EraseAllMnemonicChars(rText), rCommand, nBits ) );
     mpData->ImplClearLayoutData();
 
     ImplInvalidate( true );
@@ -446,8 +448,8 @@ void ToolBox::InsertItem(const OUString& rCommand, const 
css::uno::Reference<css
 
     ToolBoxItemId nItemId(GetItemCount() + 1);
         //TODO: ImplToolItems::size_type -> sal_uInt16!
-    InsertItem(nItemId, aImage, aLabel, nBits, nPos);
-    SetItemCommand(nItemId, rCommand);
+    InsertItem(nItemId, aLabel, rCommand, nBits, nPos);
+    SetItemImage(nItemId, aImage);
     SetQuickHelpText(nItemId, aTooltip);
 
     // set the minimal size
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 379901c01398..5cdfbcf8abd5 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -1922,7 +1922,7 @@ public:
 
         Help::EnableBalloonHelp();
         mpToolbox->SetHelpText("Help text");
-        mpToolbox->InsertItem(ToolBoxItemId(0), "Toolbar item");
+        mpToolbox->InsertItem(ToolBoxItemId(0), "Toolbar item", OUString());
         mpToolbox->SetQuickHelpText(ToolBoxItemId(0), "This is a tooltip 
popup");
         mpToolbox->InsertSeparator();
         mpToolbox->Show();

Reply via email to