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 <raykowj@gmail.com>
This commit is contained in:
Jim Raykowski
2022-05-28 23:13:28 -08:00
parent 74918534ee
commit c4fa91bf5b
5 changed files with 60 additions and 5 deletions

View File

@ -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);

View File

@ -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<weld::TreeIter> xEntry(m_xTreeView->make_iterator());
if (m_xTreeView->get_iter_first(*xEntry))
{
do
{
if (weld::fromId<SdrObject*>(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)

View File

@ -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());

View File

@ -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
{

View File

@ -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<SdNavigatorFloat*>( 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,