diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-11-25 14:25:28 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-11-28 13:53:03 +0100 |
commit | 7f1a82783ce1bfad08fcf39025c985c56fc3d90f (patch) | |
tree | 944afd23ab387f2141e4c2fa0fa960f243d1084d /cui | |
parent | 663ed9e55691bad2dda5da01d6760b2a85a0730b (diff) |
tdf#126043 use another bulk_insert_for_each
Change-Id: I05c3fc6e708d000ba955981dbd8d11371ea99da2
Reviewed-on: https://gerrit.libreoffice.org/83686
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 05734503ed36cff64cfaac8afb7c6df5eced8873)
Reviewed-on: https://gerrit.libreoffice.org/83983
Diffstat (limited to 'cui')
-rw-r--r-- | cui/source/customize/SvxMenuConfigPage.cxx | 29 | ||||
-rw-r--r-- | cui/source/customize/SvxToolbarConfigPage.cxx | 12 | ||||
-rw-r--r-- | cui/source/customize/cfg.cxx | 57 | ||||
-rw-r--r-- | cui/source/inc/cfg.hxx | 9 |
4 files changed, 65 insertions, 42 deletions
diff --git a/cui/source/customize/SvxMenuConfigPage.cxx b/cui/source/customize/SvxMenuConfigPage.cxx index 218d087349ad..7289b3506a7c 100644 --- a/cui/source/customize/SvxMenuConfigPage.cxx +++ b/cui/source/customize/SvxMenuConfigPage.cxx @@ -263,22 +263,21 @@ short SvxMenuConfigPage::QueryReset() void SvxMenuConfigPage::SelectElement() { - m_xContentsListBox->clear(); + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); SvxConfigEntry* pMenuData = GetTopLevelSelection(); - - if ( pMenuData ) + if (!pMenuData) + rTreeView.clear(); + else { SvxEntries* pEntries = pMenuData->GetEntries(); - int i = 0; - for (auto const& entry : *pEntries) - { + rTreeView.bulk_insert_for_each(pEntries->size(), [this, &rTreeView, pEntries](weld::TreeIter& rIter, int nIdx) { + auto const& entry = (*pEntries)[nIdx]; OUString sId(OUString::number(reinterpret_cast<sal_Int64>(entry))); - m_xContentsListBox->insert(i, sId); - InsertEntryIntoUI(entry, i, 0); - ++i; - } + rTreeView.set_id(rIter, sId); + InsertEntryIntoUI(entry, rTreeView, rIter, 0); + }); } UpdateButtonStates(); @@ -364,9 +363,10 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, AddCommandHdl, weld::Button&, void ) int nPos = AddFunction(-1, /*bAllowDuplicates*/false); if (nPos == -1) return; + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); SvxConfigEntry* pEntry = - reinterpret_cast<SvxConfigEntry*>(m_xContentsListBox->get_id(nPos).toInt64()); - InsertEntryIntoUI(pEntry, nPos, 0); + reinterpret_cast<SvxConfigEntry*>(rTreeView.get_id(nPos).toInt64()); + InsertEntryIntoUI(pEntry, rTreeView, nPos, 0); } IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void ) @@ -380,12 +380,13 @@ IMPL_LINK_NOARG( SvxMenuConfigPage, RemoveCommandHdl, weld::Button&, void ) IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OString&, rIdent, void) { + weld::TreeView& rTreeView = m_xContentsListBox->get_widget(); if (rIdent == "insertseparator") { SvxConfigEntry* pNewEntryData = new SvxConfigEntry; pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 0); + InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, 0); } else if (rIdent == "insertsubmenu") { @@ -406,7 +407,7 @@ IMPL_LINK(SvxMenuConfigPage, InsertHdl, const OString&, rIdent, void) pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 0); + InsertEntryIntoUI(pNewEntryData, rTreeView, nPos, 0); ReloadTopLevelListBox(); diff --git a/cui/source/customize/SvxToolbarConfigPage.cxx b/cui/source/customize/SvxToolbarConfigPage.cxx index b8058df387f5..b30302d52ed3 100644 --- a/cui/source/customize/SvxToolbarConfigPage.cxx +++ b/cui/source/customize/SvxToolbarConfigPage.cxx @@ -463,7 +463,7 @@ IMPL_LINK(SvxToolbarConfigPage, InsertHdl, const OString&, rIdent, void) pNewEntryData->SetUserDefined(); int nPos = AppendEntry(pNewEntryData, -1); - InsertEntryIntoUI(pNewEntryData, nPos, 1); + InsertEntryIntoUI(pNewEntryData, m_xContentsListBox->get_widget(), nPos, 1); static_cast<ToolbarSaveInData*>( GetSaveInData())->ApplyToolbar( pToolbar ); @@ -561,7 +561,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -601,7 +601,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pEntry))); m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -658,7 +658,7 @@ IMPL_LINK(SvxToolbarConfigPage, ModifyItemHdl, const OString&, rIdent, void) m_xContentsListBox->insert(nActEntry, sId); m_xContentsListBox->set_toggle(nActEntry, pEntry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(pEntry, nActEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nActEntry, 1); m_xContentsListBox->select(nActEntry); m_xContentsListBox->scroll_to_row(nActEntry); @@ -790,7 +790,7 @@ void SvxToolbarConfigPage::SelectElement() m_xContentsListBox->insert(i, sId); if (entry->IsBinding() && !entry->IsSeparator()) m_xContentsListBox->set_toggle(i, entry->IsVisible() ? TRISTATE_TRUE : TRISTATE_FALSE, 0); - InsertEntryIntoUI(entry, i, 1); + InsertEntryIntoUI(entry, m_xContentsListBox->get_widget(), i, 1); ++i; } @@ -819,7 +819,7 @@ void SvxToolbarConfigPage::AddFunction(int nTarget) m_xContentsListBox->set_toggle(nNewLBEntry, TRISTATE_TRUE, 0); } - InsertEntryIntoUI(pEntry, nNewLBEntry, 1); + InsertEntryIntoUI(pEntry, m_xContentsListBox->get_widget(), nNewLBEntry, 1); // Changes are not visible on the toolbar until this point // TODO: Figure out a way to show the changes on the toolbar, but revert if diff --git a/cui/source/customize/cfg.cxx b/cui/source/customize/cfg.cxx index 1cb922bc51c6..8daf8409ed68 100644 --- a/cui/source/customize/cfg.cxx +++ b/cui/source/customize/cfg.cxx @@ -1506,34 +1506,49 @@ int SvxConfigPage::AppendEntry( return nNewEntry; } -void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, int nPos, int nStartCol) +namespace { - OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData))); - - m_xContentsListBox->set_id(nPos, sId); - - if (pNewEntryData->IsSeparator()) - { - m_xContentsListBox->set_text(nPos, "----------------------------------", nStartCol + 1); - } - else + template<typename itertype> void TmplInsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, itertype& rIter, int nStartCol, SaveInData* pSaveInData, VirtualDevice& rDropDown) { - auto xImage = GetSaveInData()->GetImage(pNewEntryData->GetCommand()); - if (xImage.is()) - m_xContentsListBox->set_image(nPos, xImage, nStartCol); - OUString aName = SvxConfigPageHelper::stripHotKey( pNewEntryData->GetName() ); - m_xContentsListBox->set_text(nPos, aName, nStartCol + 1); - } + OUString sId(OUString::number(reinterpret_cast<sal_Int64>(pNewEntryData))); - if (nStartCol == 0) // menus - { - if (pNewEntryData->IsPopup() || pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN) - m_xContentsListBox->set_dropdown(nPos, nStartCol + 2); + rTreeView.set_id(rIter, sId); + + if (pNewEntryData->IsSeparator()) + { + rTreeView.set_text(rIter, "----------------------------------", nStartCol + 1); + } else - m_xContentsListBox->set_image(nPos, nullptr, nStartCol + 2); + { + auto xImage = pSaveInData->GetImage(pNewEntryData->GetCommand()); + if (xImage.is()) + rTreeView.set_image(rIter, xImage, nStartCol); + OUString aName = SvxConfigPageHelper::stripHotKey( pNewEntryData->GetName() ); + rTreeView.set_text(rIter, aName, nStartCol + 1); + } + + if (nStartCol == 0) // menus + { + if (pNewEntryData->IsPopup() || pNewEntryData->GetStyle() & css::ui::ItemStyle::DROP_DOWN) + rTreeView.set_image(rIter, rDropDown, nStartCol + 2); + else + rTreeView.set_image(rIter, css::uno::Reference<css::graphic::XGraphic>(), nStartCol + 2); + } } } +void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, int nPos, int nStartCol) +{ + TmplInsertEntryIntoUI<int>(pNewEntryData, rTreeView, nPos, nStartCol, + GetSaveInData(), m_xContentsListBox->get_dropdown_image()); +} + +void SvxConfigPage::InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, weld::TreeView& rTreeView, weld::TreeIter& rIter, int nStartCol) +{ + TmplInsertEntryIntoUI<weld::TreeIter>(pNewEntryData, rTreeView, rIter, nStartCol, + GetSaveInData(), m_xContentsListBox->get_dropdown_image()); +} + IMPL_LINK(SvxConfigPage, MoveHdl, weld::Button&, rButton, void) { MoveEntry(&rButton == m_xMoveUpButton.get()); diff --git a/cui/source/inc/cfg.hxx b/cui/source/inc/cfg.hxx index d5410a6ce667..fa825b92f207 100644 --- a/cui/source/inc/cfg.hxx +++ b/cui/source/inc/cfg.hxx @@ -325,6 +325,8 @@ public: SvxMenuEntriesListBox(std::unique_ptr<weld::TreeView> xControl, SvxConfigPage* pPage); virtual ~SvxMenuEntriesListBox(); + VirtualDevice& get_dropdown_image() const { return *m_xDropDown; } + int get_selected_index() const { return m_xControl->get_selected_index(); } OUString get_id(int nPos) const { return m_xControl->get_id(nPos); } void remove(int nPos) { m_xControl->remove(nPos); } @@ -451,7 +453,12 @@ protected: SvxConfigEntry const * pParentData ); void InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, - int nPos, int nStartCol); + weld::TreeView& rTreeView, int nPos, + int nStartCol); + void InsertEntryIntoUI(SvxConfigEntry* pNewEntryData, + weld::TreeView& rTreeView, weld::TreeIter& rIter, + int nStartCol); + void InsertEntryIntoNotebookbarTabUI(const OUString& sClassId, const OUString& sUIItemId, const OUString& sUIItemCommand, weld::TreeView& rTreeView, weld::TreeIter& rIter, |