sd/source/ui/dlg/navigatr.cxx | 24 +++++++++++++++++++----- sd/source/ui/dlg/sdtreelb.cxx | 15 +++++---------- sd/source/ui/inc/sdtreelb.hxx | 2 +- 3 files changed, 25 insertions(+), 16 deletions(-)
New commits: commit 158014e9aecbec6afb0ebf3aceb8b09e4a64b8e0 Author: Jim Raykowski <rayk...@gmail.com> AuthorDate: Sat Oct 15 16:22:30 2022 -0800 Commit: Jim Raykowski <rayk...@gmail.com> CommitDate: Sun Oct 23 09:45:51 2022 +0200 tdf#138868 SdNavigator: Select in the objects tree all marked objects in the draw view This patch makes all marked objects on a Draw/Impress page be selected in the Navigator. Previous to this patch, only the first marked object is selected in the Navigator. Change-Id: I430d0aa83297d0bf89cc90d341267b5d70dac534 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/141426 Tested-by: Jenkins Reviewed-by: Jim Raykowski <rayk...@gmail.com> diff --git a/sd/source/ui/dlg/navigatr.cxx b/sd/source/ui/dlg/navigatr.cxx index ea9e74c687cc..7724643b1e8a 100644 --- a/sd/source/ui/dlg/navigatr.cxx +++ b/sd/source/ui/dlg/navigatr.cxx @@ -66,7 +66,7 @@ SdNavigatorWin::SdNavigatorWin(weld::Widget* pParent, SfxBindings* pInBindings, mxTlbObjects->SetViewFrame( mpBindings->GetDispatcher()->GetFrame() ); mxTlbObjects->connect_row_activated(LINK(this, SdNavigatorWin, ClickObjectHdl)); - mxTlbObjects->set_selection_mode(SelectionMode::Single); + mxTlbObjects->set_selection_mode(SelectionMode::Multiple); mxToolbox->connect_clicked(LINK(this, SdNavigatorWin, SelectToolboxHdl)); mxToolbox->connect_menu_toggled(LINK(this, SdNavigatorWin, DropdownClickToolBoxHdl)); @@ -131,11 +131,14 @@ static void lcl_select_marked_object(const sd::ViewShell* pViewShell, SdPageObjs if (const SdrView* pView = pViewShell->GetDrawView()) { auto vMarkedObjects = pView->GetMarkedObjects(); - // tree is only single selection so select first in vMarkedObjects if there is one if (vMarkedObjects.size()) - pTlbObjects->SelectEntry(vMarkedObjects[0]); + { + pTlbObjects->unselect_all(); + for (auto rMarkedObject: vMarkedObjects) + pTlbObjects->SelectEntry(rMarkedObject); + } else - pTlbObjects->SelectEntry(nullptr); + pTlbObjects->SelectEntry(pViewShell->GetName()); } } @@ -740,10 +743,21 @@ void SdPageNameControllerItem::StateChangedAtToolBoxControl( sal_uInt16 nSId, if( !(pInfo && pInfo->IsActive()) ) return; + // Without a test for marked objects the page name entry is not selected when there are no + // marked objects. The HasSelectedChildren test is required when in 'Named Shapes' mode in + // order to select the page name when none of the marked objects have a name. + bool bDrawViewHasMarkedObjects = false; + if (pInfo->GetDrawDocShell() && pInfo->GetDrawDocShell()->GetViewShell()) + { + const SdrView* pDrawView = pInfo->GetDrawDocShell()->GetViewShell()->GetDrawView(); + if (pDrawView && pDrawView->GetMarkedObjectCount()) + bDrawViewHasMarkedObjects = true; + } + const SfxStringItem& rStateItem = dynamic_cast<const SfxStringItem&>(*pItem); const OUString& aPageName = rStateItem.GetValue(); - if( !pNavigatorWin->mxTlbObjects->HasSelectedChildren( aPageName ) ) + if (!bDrawViewHasMarkedObjects || !pNavigatorWin->mxTlbObjects->HasSelectedChildren(aPageName)) { if (pNavigatorWin->mxTlbObjects->get_selection_mode() == SelectionMode::Multiple) { diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx index 72b3b93215dd..3e86c4bc2376 100644 --- a/sd/source/ui/dlg/sdtreelb.cxx +++ b/sd/source/ui/dlg/sdtreelb.cxx @@ -1187,9 +1187,8 @@ bool SdPageObjsTLV::SelectEntry( std::u16string_view rName ) return bFound; } -bool SdPageObjsTLV::SelectEntry(const SdrObject *pObj) +void SdPageObjsTLV::SelectEntry(const SdrObject *pObj) { - bool bFound = false; if (pObj) { std::unique_ptr<weld::TreeIter> xEntry(m_xTreeView->make_iterator()); @@ -1199,20 +1198,16 @@ bool SdPageObjsTLV::SelectEntry(const SdrObject *pObj) { if (weld::fromId<SdrObject*>(m_xTreeView->get_id(*xEntry)) == pObj) { - m_xTreeView->set_cursor(*xEntry); - bFound = true; + // only scroll to row of the first selected + if (m_xTreeView->get_selected_rows().empty()) + m_xTreeView->scroll_to_row(*xEntry); + m_xTreeView->select(*xEntry); break; } } while (m_xTreeView->iter_next(*xEntry)); } } - if (!bFound) - { - m_xTreeView->unselect_all(); - m_xTreeView->set_cursor(-1); - } - return bFound; } SdPageObjsTLV::~SdPageObjsTLV() diff --git a/sd/source/ui/inc/sdtreelb.hxx b/sd/source/ui/inc/sdtreelb.hxx index e2e23618b7bd..84432f180834 100644 --- a/sd/source/ui/inc/sdtreelb.hxx +++ b/sd/source/ui/inc/sdtreelb.hxx @@ -218,7 +218,7 @@ public: bool HasSelectedChildren(std::u16string_view rName); bool SelectEntry(std::u16string_view rName); - bool SelectEntry(const SdrObject* pObj); + void SelectEntry(const SdrObject* pObj); OUString get_selected_text() const {