From c4fa91bf5b64e052d22d910097f2aca270fb86dc Mon Sep 17 00:00:00 2001 From: Jim Raykowski Date: Sat, 28 May 2022 23:13:28 -0800 Subject: [PATCH] tdf#138868 SdNavigator: track object selected on canvas Change-Id: Ie28d0ee9482d0bcb4a0a8803e499af3bc0e816d6 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135084 Tested-by: Jenkins Reviewed-by: Jim Raykowski --- sd/source/ui/dlg/navigatr.cxx | 27 ++++++++++++++++++++++++--- sd/source/ui/dlg/sdtreelb.cxx | 25 +++++++++++++++++++++++++ sd/source/ui/docshell/docshel4.cxx | 4 +++- sd/source/ui/inc/sdtreelb.hxx | 1 + sd/source/ui/view/drviews4.cxx | 8 +++++++- 5 files changed, 60 insertions(+), 5 deletions(-) diff --git a/sd/source/ui/dlg/navigatr.cxx b/sd/source/ui/dlg/navigatr.cxx index 78525efe54f2..4cec75753505 100644 --- a/sd/source/ui/dlg/navigatr.cxx +++ b/sd/source/ui/dlg/navigatr.cxx @@ -125,6 +125,19 @@ SdNavigatorWin::~SdNavigatorWin() mxLbDocs.reset(); } +static void lcl_select_marked_object(const sd::ViewShell* pViewShell, SdPageObjsTLV* pTlbObjects) +{ + 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]); + else + pTlbObjects->SelectEntry(nullptr); + } +} + //when object is marked , fresh the corresponding entry tree . void SdNavigatorWin::FreshTree( const SdDrawDocument* pDoc ) { @@ -132,9 +145,14 @@ void SdNavigatorWin::FreshTree( const SdDrawDocument* pDoc ) sd::DrawDocShell* pDocShell = pNonConstDoc->GetDocSh(); const OUString& aDocShName( pDocShell->GetName() ); OUString aDocName = pDocShell->GetMedium()->GetName(); - mxTlbObjects->Fill( pDoc, false, aDocName ); // Only normal pages - RefreshDocumentLB(); - mxLbDocs->set_active_text(aDocShName); + if (!mxTlbObjects->IsEqualToDoc(pDoc)) + { + mxTlbObjects->Fill( pDoc, false, aDocName ); // Only normal pages + RefreshDocumentLB(); + mxLbDocs->set_active_text(aDocShName); + } + if (const sd::ViewShell* pViewShell = pDocShell->GetViewShell()) + lcl_select_marked_object(pViewShell, mxTlbObjects.get()); } void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc ) @@ -182,6 +200,9 @@ void SdNavigatorWin::InitTreeLB( const SdDrawDocument* pDoc ) } } + if (pViewShell) + lcl_select_marked_object(pViewShell, mxTlbObjects.get()); + SfxViewFrame* pViewFrame = ( ( pViewShell && pViewShell->GetViewFrame() ) ? pViewShell->GetViewFrame() : SfxViewFrame::Current() ); if( pViewFrame ) pViewFrame->GetBindings().Invalidate(SID_NAVIGATOR_PAGENAME, true, true); diff --git a/sd/source/ui/dlg/sdtreelb.cxx b/sd/source/ui/dlg/sdtreelb.cxx index c15a2ea09be7..1b49eccb6cc3 100644 --- a/sd/source/ui/dlg/sdtreelb.cxx +++ b/sd/source/ui/dlg/sdtreelb.cxx @@ -1186,6 +1186,31 @@ bool SdPageObjsTLV::SelectEntry( std::u16string_view rName ) return bFound; } +bool SdPageObjsTLV::SelectEntry(const SdrObject *pObj) +{ + bool bFound = false; + if (pObj) + { + std::unique_ptr xEntry(m_xTreeView->make_iterator()); + if (m_xTreeView->get_iter_first(*xEntry)) + { + do + { + if (weld::fromId(m_xTreeView->get_id(*xEntry)) == pObj) + { + m_xTreeView->set_cursor(*xEntry); + bFound = true; + break; + } + } + while (m_xTreeView->iter_next(*xEntry)); + } + } + if (!bFound) + m_xTreeView->set_cursor(-1); + return bFound; +} + SdPageObjsTLV::~SdPageObjsTLV() { if (m_nSelectEventId) diff --git a/sd/source/ui/docshell/docshel4.cxx b/sd/source/ui/docshell/docshel4.cxx index efc3d1bd97cd..13b08deafa1a 100644 --- a/sd/source/ui/docshell/docshel4.cxx +++ b/sd/source/ui/docshell/docshel4.cxx @@ -836,12 +836,14 @@ void DrawDocShell::GotoBookmark(std::u16string_view rBookmark) pDrawViewShell->SwitchPage(nSdPgNum); } + // Do UnmarkAll here to stop the Navigator from reselecting the previously marked + // entry when a slide entry is selected. + pDrawViewShell->GetView()->UnmarkAll(); if (pObj != nullptr) { // show and select object if (vcl::Window* pWindow = pDrawViewShell->GetActiveWindow()) pDrawViewShell->MakeVisible(pObj->GetSnapRect(), *pWindow); - pDrawViewShell->GetView()->UnmarkAll(); pDrawViewShell->GetView()->MarkObj( pObj, pDrawViewShell->GetView()->GetSdrPageView()); diff --git a/sd/source/ui/inc/sdtreelb.hxx b/sd/source/ui/inc/sdtreelb.hxx index ea59ed0b58d8..c59e2897ab08 100644 --- a/sd/source/ui/inc/sdtreelb.hxx +++ b/sd/source/ui/inc/sdtreelb.hxx @@ -218,6 +218,7 @@ public: bool HasSelectedChildren(std::u16string_view rName); bool SelectEntry(std::u16string_view rName); + bool SelectEntry(const SdrObject* pObj); OUString get_selected_text() const { diff --git a/sd/source/ui/view/drviews4.cxx b/sd/source/ui/view/drviews4.cxx index b07279844265..31636aa13b57 100644 --- a/sd/source/ui/view/drviews4.cxx +++ b/sd/source/ui/view/drviews4.cxx @@ -300,13 +300,19 @@ void DrawViewShell::StartRulerDrag ( void DrawViewShell::FreshNavigatrTree() { - SfxChildWindow* pWindow = GetViewFrame()->GetChildWindow( SID_NAVIGATOR ); + SfxViewFrame *pViewFrame = GetViewFrame(); + if (!pViewFrame) + return; + SfxChildWindow* pWindow = pViewFrame->GetChildWindow( SID_NAVIGATOR ); if( pWindow ) { SdNavigatorFloat* pNavWin = static_cast( pWindow->GetWindow() ); if( pNavWin ) pNavWin->FreshTree( GetDoc() ); } + // sidebar version + SfxBindings& rBindings = pViewFrame->GetBindings(); + rBindings.Invalidate(SID_NAVIGATOR_STATE, true); } void DrawViewShell::MouseButtonDown(const MouseEvent& rMEvt,