[Libreoffice-commits] core.git: 5 commits - sd/inc sd/source

Caolán McNamara caolanm at redhat.com
Wed May 18 11:55:02 UTC 2016


 sd/inc/drawdoc.hxx                                           |    1 
 sd/source/core/drawdoc2.cxx                                  |   10 +
 sd/source/ui/inc/SlideSorterViewShell.hxx                    |    7 
 sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx |   15 -
 sd/source/ui/slidesorter/controller/SlsSlotManager.cxx       |    8 
 sd/source/ui/slidesorter/model/SlideSorterModel.cxx          |    6 
 sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx      |  104 +++++------
 sd/source/ui/view/viewshel.cxx                               |   39 ++++
 8 files changed, 118 insertions(+), 72 deletions(-)

New commits:
commit cc03133e1b719ad6ae3885f2eca519196843f2c4
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed May 18 12:23:34 2016 +0100

    refactor this repeated code into a single method
    
    no logic change
    
    Change-Id: I362d888323bb22ded7812147811efbebce933564

diff --git a/sd/source/ui/inc/SlideSorterViewShell.hxx b/sd/source/ui/inc/SlideSorterViewShell.hxx
index f191e73..8e66752 100644
--- a/sd/source/ui/inc/SlideSorterViewShell.hxx
+++ b/sd/source/ui/inc/SlideSorterViewShell.hxx
@@ -222,6 +222,13 @@ private:
     void PostMoveSlidesActions(const std::shared_ptr<SlideSorterViewShell::PageSelection> &rpSelection);
 
     void MainViewEndEditAndUnmarkAll();
+
+    /** Select the same pages in the document as are selected in the
+        SlideSorterViewShell
+
+        return the page numbers of the first and last selected pages
+    */
+    std::pair<sal_uInt16, sal_uInt16> SyncPageSelectionToDocument(const std::shared_ptr<SlideSorterViewShell::PageSelection> &rpSelection);
 };
 
 typedef std::shared_ptr<SlideSorterViewShell::PageSelection> SharedPageSelection;
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
index 24fab76..8fd5503 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
@@ -712,22 +712,40 @@ void SlideSorterViewShell::MainViewEndEditAndUnmarkAll()
     }
 }
 
-void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& /*rReq*/)
+std::pair<sal_uInt16, sal_uInt16> SlideSorterViewShell::SyncPageSelectionToDocument(const std::shared_ptr<SlideSorterViewShell::PageSelection> &rpSelection)
 {
-    MainViewEndEditAndUnmarkAll();
+    sal_uInt16 firstSelectedPageNo = SAL_MAX_UINT16;
+    sal_uInt16 lastSelectedPageNo = 0;
 
-    // SdDrawDocument MovePages is based on SdPage IsSelected, so
-    // transfer the SlideSorter selection to SdPages (*it)
     GetDoc()->UnselectAllPages();
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
+    for (auto it = rpSelection->begin(); it != rpSelection->end(); ++it)
+    {
+        // Check page number
+        sal_uInt16 pageNo = (*it)->GetPageNum();
+        if (pageNo > lastSelectedPageNo)
+            lastSelectedPageNo = pageNo;
+        if (pageNo < firstSelectedPageNo)
+            firstSelectedPageNo = pageNo;
         GetDoc()->SetSelected(*it, true);
     }
 
+    return std::make_pair(firstSelectedPageNo, lastSelectedPageNo);
+}
+
+void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& /*rReq*/)
+{
+    MainViewEndEditAndUnmarkAll();
+
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
+
+    // SdDrawDocument MovePages is based on SdPage IsSelected, so
+    // transfer the SlideSorter selection to SdPages
+    SyncPageSelectionToDocument(xSelection);
+
     // Moves selected pages after page -1
     GetDoc()->MovePages( (sal_uInt16) -1 );
 
-    PostMoveSlidesActions(pSelection);
+    PostMoveSlidesActions(xSelection);
 }
 
 void SlideSorterViewShell::GetStateMovePageFirst (SfxItemSet& rSet)
@@ -744,14 +762,11 @@ void SlideSorterViewShell::GetStateMovePageFirst (SfxItemSet& rSet)
         }
     }
 
-    sal_uInt16 firstSelectedPageNo = SAL_MAX_UINT16;
-    sal_uInt16 pageNo;
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
-        // Check page number
-        pageNo = (*it)->GetPageNum();
-        if (pageNo < firstSelectedPageNo) firstSelectedPageNo = pageNo;
-    }
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
+
+    // SdDrawDocument MovePages is based on SdPage IsSelected, so
+    // transfer the SlideSorter selection to SdPages
+    sal_uInt16 firstSelectedPageNo = SyncPageSelectionToDocument(xSelection).first;
     // Now compute human page number from internal page number
     firstSelectedPageNo = (firstSelectedPageNo - 1) / 2;
 
@@ -766,19 +781,11 @@ void SlideSorterViewShell::ExecMovePageUp (SfxRequest& /*rReq*/)
 {
     MainViewEndEditAndUnmarkAll();
 
-    sal_uInt16 firstSelectedPageNo = SAL_MAX_UINT16;
-    sal_uInt16 pageNo;
-    // SdDrawDocument MovePages is based on SdPage IsSelected, so
-    // transfer the SlideSorter selection to SdPages (*it)
-    GetDoc()->UnselectAllPages();
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
-        // Check page number
-        pageNo = (*it)->GetPageNum();
-        if (pageNo < firstSelectedPageNo) firstSelectedPageNo = pageNo;
-        GetDoc()->SetSelected(*it, true);
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
 
-    }
+    // SdDrawDocument MovePages is based on SdPage IsSelected, so
+    // transfer the SlideSorter selection to SdPages
+    sal_uInt16 firstSelectedPageNo = SyncPageSelectionToDocument(xSelection).first;
     // Now compute human page number from internal page number
     firstSelectedPageNo = (firstSelectedPageNo - 1) / 2;
 
@@ -789,7 +796,7 @@ void SlideSorterViewShell::ExecMovePageUp (SfxRequest& /*rReq*/)
     // remembering that -1 means at first, which is good.
     GetDoc()->MovePages( firstSelectedPageNo - 2 );
 
-    PostMoveSlidesActions(pSelection);
+    PostMoveSlidesActions(xSelection);
 }
 
 void SlideSorterViewShell::GetStateMovePageUp (SfxItemSet& rSet)
@@ -801,19 +808,11 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& /*rReq*/)
 {
     MainViewEndEditAndUnmarkAll();
 
-    sal_uInt16 lastSelectedPageNo = 0;
-    sal_uInt16 pageNo;
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
+
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
-    // transfer the SlideSorter selection to SdPages (*it)
-    GetDoc()->UnselectAllPages();
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it )
-    {
-        // Check page number
-        pageNo = (*it)->GetPageNum();
-        if (pageNo > lastSelectedPageNo) lastSelectedPageNo = pageNo;
-        GetDoc()->SetSelected(*it, true);
-    }
+    // transfer the SlideSorter selection to SdPages
+    sal_uInt16 lastSelectedPageNo = SyncPageSelectionToDocument(xSelection).second;
 
     // Get page number of the last page
     sal_uInt16 nNoOfPages = GetDoc()->GetSdPageCount(PK_STANDARD);
@@ -826,7 +825,7 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& /*rReq*/)
     // Move to position after lastSelectedPageNo
     GetDoc()->MovePages( lastSelectedPageNo + 1 );
 
-    PostMoveSlidesActions(pSelection);
+    PostMoveSlidesActions(xSelection);
 }
 
 void SlideSorterViewShell::GetStateMovePageDown (SfxItemSet& rSet)
@@ -838,13 +837,11 @@ void SlideSorterViewShell::ExecMovePageLast (SfxRequest& /*rReq*/)
 {
     MainViewEndEditAndUnmarkAll();
 
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
+
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
-    // transfer the SlideSorter selection to SdPages (*it)
-    GetDoc()->UnselectAllPages();
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
-        GetDoc()->SetSelected(*it, true);
-    }
+    // transfer the SlideSorter selection to SdPages
+    SyncPageSelectionToDocument(xSelection);
 
     // Get page number of the last page
     sal_uInt16 nNoOfPages = GetDoc()->GetSdPageCount(PK_STANDARD);
@@ -852,7 +849,7 @@ void SlideSorterViewShell::ExecMovePageLast (SfxRequest& /*rReq*/)
     // Move to position after last page No (=Number of pages - 1)
     GetDoc()->MovePages( nNoOfPages - 1 );
 
-    PostMoveSlidesActions(pSelection);
+    PostMoveSlidesActions(xSelection);
 }
 
 void SlideSorterViewShell::GetStateMovePageLast (SfxItemSet& rSet)
@@ -866,19 +863,11 @@ void SlideSorterViewShell::GetStateMovePageLast (SfxItemSet& rSet)
         return;
     }
 
-    sal_uInt16 lastSelectedPageNo = 0;
-    sal_uInt16 pageNo;
+    std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection());
+
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
-    // transfer the SlideSorter selection to SdPages (*it)
-    GetDoc()->UnselectAllPages();
-    std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
-    for (auto it = pSelection->begin(); it != pSelection->end() ; ++it )
-    {
-        // Check page number
-        pageNo = (*it)->GetPageNum();
-        if (pageNo > lastSelectedPageNo) lastSelectedPageNo = pageNo;
-        GetDoc()->SetSelected(*it, true);
-    }
+    // transfer the SlideSorter selection to SdPages
+    sal_uInt16 lastSelectedPageNo = SyncPageSelectionToDocument(xSelection).second;
 
     // Get page number of the last page
     sal_uInt16 nNoOfPages = GetDoc()->GetSdPageCount(PK_STANDARD);
commit db00223e6d3132eac9603e5dabd20cd03f599cb3
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Wed May 18 12:10:26 2016 +0100

    Related: tdf#99523 select only the desired slides
    
    when selecting the same slides in the document as are
    selected in the slide pane, don't forget to unselect
    any slides already selected in the document.
    
    impress is nuts in carrying around two selection
    mechanisms.
    
    Change-Id: I97d744c1c57b68dc312a17a5cd5290e1b6ccf083

diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx
index bf5e0db..476be4d 100644
--- a/sd/inc/drawdoc.hxx
+++ b/sd/inc/drawdoc.hxx
@@ -363,6 +363,7 @@ public:
     sal_uInt16 GetSdPageCount(PageKind ePgKind) const;
 
     SAL_DLLPRIVATE void                SetSelected(SdPage* pPage, bool bSelect);
+    SAL_DLLPRIVATE void                UnselectAllPages();
     SAL_DLLPRIVATE bool                MovePages(sal_uInt16 nTargetPage);
 
     SdPage*GetMasterSdPage(sal_uInt16 nPgNum, PageKind ePgKind);
diff --git a/sd/source/core/drawdoc2.cxx b/sd/source/core/drawdoc2.cxx
index 68f3b91..200f613 100644
--- a/sd/source/core/drawdoc2.cxx
+++ b/sd/source/core/drawdoc2.cxx
@@ -696,6 +696,16 @@ bool SdDrawDocument::CreateMissingNotesAndHandoutPages()
     return bOK;
 }
 
+void SdDrawDocument::UnselectAllPages()
+{
+    sal_uInt16 nNoOfPages = GetSdPageCount(PK_STANDARD);
+    for (sal_uInt16 nPage = 0; nPage < nNoOfPages; ++nPage)
+    {
+        SdPage* pPage = GetSdPage(nPage, PK_STANDARD);
+        pPage->SetSelected(false);
+    }
+}
+
 // + Move selected pages after said page
 //   (nTargetPage = (sal_uInt16)-1  --> move before first page)
 // + Returns sal_True when the page has been moved
diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
index dbc53f2..24fab76 100644
--- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
+++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx
@@ -718,6 +718,7 @@ void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& /*rReq*/)
 
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
     // transfer the SlideSorter selection to SdPages (*it)
+    GetDoc()->UnselectAllPages();
     std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
     for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
         GetDoc()->SetSelected(*it, true);
@@ -769,6 +770,7 @@ void SlideSorterViewShell::ExecMovePageUp (SfxRequest& /*rReq*/)
     sal_uInt16 pageNo;
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
     // transfer the SlideSorter selection to SdPages (*it)
+    GetDoc()->UnselectAllPages();
     std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
     for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
         // Check page number
@@ -803,6 +805,7 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& /*rReq*/)
     sal_uInt16 pageNo;
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
     // transfer the SlideSorter selection to SdPages (*it)
+    GetDoc()->UnselectAllPages();
     std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
     for (auto it = pSelection->begin(); it != pSelection->end() ; ++it )
     {
@@ -837,6 +840,7 @@ void SlideSorterViewShell::ExecMovePageLast (SfxRequest& /*rReq*/)
 
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
     // transfer the SlideSorter selection to SdPages (*it)
+    GetDoc()->UnselectAllPages();
     std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
     for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) {
         GetDoc()->SetSelected(*it, true);
@@ -866,6 +870,7 @@ void SlideSorterViewShell::GetStateMovePageLast (SfxItemSet& rSet)
     sal_uInt16 pageNo;
     // SdDrawDocument MovePages is based on SdPage IsSelected, so
     // transfer the SlideSorter selection to SdPages (*it)
+    GetDoc()->UnselectAllPages();
     std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() );
     for (auto it = pSelection->begin(); it != pSelection->end() ; ++it )
     {
commit bb3671180eb7327be9ac178e0d8341322f63d72a
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue May 17 20:38:37 2016 +0100

    Related: tdf#99523 NotifyPageEvent ultimately comes from HINT_PAGEORDERCHG...
    
    which is called for removepage, insertpage *and* change page number. e.g.
    ctrl+shift+end and similar *move* the page, in those cases not removing before
    adding results in duplicate pages/slides in the list, causing inconsistencies
    on what gets selected on undo
    
    Change-Id: I7e0a0231e90a77adea03619a0dd92ddbbcbba442

diff --git a/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx b/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx
index 18b77b6..cf1ed11 100644
--- a/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx
@@ -75,15 +75,16 @@ void SelectionObserver::NotifyPageEvent (const SdrPage* pSdrPage)
     if (pPage == nullptr)
         return;
 
+    //NotifyPageEvent is called for add, remove, *and* change position so for
+    //the change position case we must ensure we don't end up with the slide
+    //duplicated in our list
+    std::vector<const SdPage*>::iterator iPage(
+        std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
+    if (iPage != maInsertedPages.end())
+        maInsertedPages.erase(iPage);
+
     if (pPage->IsInserted())
         maInsertedPages.push_back(pPage);
-    else
-    {
-        ::std::vector<const SdPage*>::iterator iPage(
-            ::std::find(maInsertedPages.begin(), maInsertedPages.end(), pPage));
-        if (iPage != maInsertedPages.end())
-            maInsertedPages.erase(iPage);
-    }
 }
 
 void SelectionObserver::StartObservation()
diff --git a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
index 68fc9a0..dae17c5 100644
--- a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
+++ b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
@@ -533,10 +533,12 @@ bool SlideSorterModel::NotifyPageEvent (const SdrPage* pSdrPage)
     if (pPage->IsMasterPage() != (meEditMode==EM_MASTERPAGE))
         return false;
 
+    //NotifyPageEvent is called for add, remove, *and* change position so for
+    //the change position case we must ensure we don't end up with the slide
+    //duplicated in our list
+    DeleteSlide(pPage);
     if (pPage->IsInserted())
         InsertSlide(pPage);
-    else
-        DeleteSlide(pPage);
     CheckModel(*this);
 
     return true;
commit a0de7474400ae0a84daf688de12c9344d028df93
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue May 17 20:34:31 2016 +0100

    move the KeepSlideSorterInSyncWithPageChanges to a level lower
    
    so that is a SlideSorter is present it is kept in sync on
    undo/redo. regardless of whether focus is in the SlideSorter
    or in the main shell.
    
    Change-Id: I11b3333b4447a6020862092e89e9a89de1768f87

diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
index 05fd566..1f54ce0 100644
--- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
@@ -334,23 +334,6 @@ void SlotManager::FuPermanent (SfxRequest& rRequest)
     //  Invalidate( SID_OBJECT_SELECT );
 }
 
-class KeepSlideSorterInSyncWithPageChanges
-{
-    view::SlideSorterView::DrawLock m_aDrawLock;
-    SlideSorterController::ModelChangeLock m_aModelLock;
-    PageSelector::UpdateLock m_aUpdateLock;
-    SelectionObserver::Context m_aContext;
-
-public:
-    KeepSlideSorterInSyncWithPageChanges(SlideSorter& rSlideSorter)
-        : m_aDrawLock(rSlideSorter)
-        , m_aModelLock(rSlideSorter.GetController())
-        , m_aUpdateLock(rSlideSorter)
-        , m_aContext(rSlideSorter)
-    {
-    }
-};
-
 void SlotManager::FuSupport (SfxRequest& rRequest)
 {
     switch (rRequest.GetSlot())
@@ -423,7 +406,6 @@ void SlotManager::FuSupport (SfxRequest& rRequest)
                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
             if (pViewShell != nullptr)
             {
-                KeepSlideSorterInSyncWithPageChanges aWatcher(mrSlideSorter);
                 pViewShell->ImpSidUndo (false, rRequest);
             }
             break;
@@ -435,7 +417,6 @@ void SlotManager::FuSupport (SfxRequest& rRequest)
                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
             if (pViewShell != nullptr)
             {
-                KeepSlideSorterInSyncWithPageChanges aWatcher(mrSlideSorter);
                 pViewShell->ImpSidRedo (false, rRequest);
             }
             break;
diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx
index fa9d189..c46b9ef 100644
--- a/sd/source/ui/view/viewshel.cxx
+++ b/sd/source/ui/view/viewshel.cxx
@@ -58,6 +58,8 @@
 #include "TextObjectBar.hxx"
 #include "GraphicObjectBar.hxx"
 #include "MediaObjectBar.hxx"
+#include "SlideSorter.hxx"
+#include "SlideSorterViewShell.hxx"
 #include "ViewShellManager.hxx"
 #include "FormShellManager.hxx"
 #include <svx/dialogs.hrc>
@@ -70,6 +72,10 @@
 #include <svl/slstitm.hxx>
 #include <sfx2/request.hxx>
 #include "SpellDialogChildWindow.hxx"
+#include "controller/SlideSorterController.hxx"
+#include "controller/SlsPageSelector.hxx"
+#include "controller/SlsSelectionObserver.hxx"
+#include "view/SlideSorterView.hxx"
 
 #include <basegfx/tools/zoomtools.hxx>
 
@@ -1226,8 +1232,33 @@ void ViewShell::ImpGetRedoStrings(SfxItemSet &rSet) const
     }
 }
 
+class KeepSlideSorterInSyncWithPageChanges
+{
+    sd::slidesorter::view::SlideSorterView::DrawLock m_aDrawLock;
+    sd::slidesorter::controller::SlideSorterController::ModelChangeLock m_aModelLock;
+    sd::slidesorter::controller::PageSelector::UpdateLock m_aUpdateLock;
+    sd::slidesorter::controller::SelectionObserver::Context m_aContext;
+
+public:
+    KeepSlideSorterInSyncWithPageChanges(sd::slidesorter::SlideSorter& rSlideSorter)
+        : m_aDrawLock(rSlideSorter)
+        , m_aModelLock(rSlideSorter.GetController())
+        , m_aUpdateLock(rSlideSorter)
+        , m_aContext(rSlideSorter)
+    {
+    }
+};
+
 void ViewShell::ImpSidUndo(bool, SfxRequest& rReq)
 {
+    //The xWatcher keeps the SlideSorter selection in sync
+    //with the page insertions/deletions that Undo may introduce
+    std::unique_ptr<KeepSlideSorterInSyncWithPageChanges> xWatcher;
+    slidesorter::SlideSorterViewShell* pSlideSorterViewShell
+        = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
+    if (pSlideSorterViewShell)
+        xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
+
     ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
     sal_uInt16 nNumber(1);
     const SfxItemSet* pReqArgs = rReq.GetArgs();
@@ -1271,6 +1302,14 @@ void ViewShell::ImpSidUndo(bool, SfxRequest& rReq)
 
 void ViewShell::ImpSidRedo(bool, SfxRequest& rReq)
 {
+    //The xWatcher keeps the SlideSorter selection in sync
+    //with the page insertions/deletions that Undo may introduce
+    std::unique_ptr<KeepSlideSorterInSyncWithPageChanges> xWatcher;
+    slidesorter::SlideSorterViewShell* pSlideSorterViewShell
+        = slidesorter::SlideSorterViewShell::GetSlideSorter(GetViewShellBase());
+    if (pSlideSorterViewShell)
+        xWatcher.reset(new KeepSlideSorterInSyncWithPageChanges(pSlideSorterViewShell->GetSlideSorter()));
+
     ::svl::IUndoManager* pUndoManager = ImpGetUndoManager();
     sal_uInt16 nNumber(1);
     const SfxItemSet* pReqArgs = rReq.GetArgs();
commit e226c19e9136dda366c1485a9d53a0c5d433387c
Author: Caolán McNamara <caolanm at redhat.com>
Date:   Tue May 17 16:25:17 2016 +0100

    give this tremendously useful snippet a descriptive name and de-duplicate it
    
    This is the magic smoke which sets the right selection on an undo of move
    slides when the slidesorter has the focus. If the main shell has the focus
    then the undo doesn't reselect the original slides like it does when this
    artifact is in the mix.
    
    Change-Id: I5ebe0195225136bfaf81e28ad4ba8e9ec431cc22

diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
index 56e7e4b..05fd566 100644
--- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx
@@ -334,6 +334,23 @@ void SlotManager::FuPermanent (SfxRequest& rRequest)
     //  Invalidate( SID_OBJECT_SELECT );
 }
 
+class KeepSlideSorterInSyncWithPageChanges
+{
+    view::SlideSorterView::DrawLock m_aDrawLock;
+    SlideSorterController::ModelChangeLock m_aModelLock;
+    PageSelector::UpdateLock m_aUpdateLock;
+    SelectionObserver::Context m_aContext;
+
+public:
+    KeepSlideSorterInSyncWithPageChanges(SlideSorter& rSlideSorter)
+        : m_aDrawLock(rSlideSorter)
+        , m_aModelLock(rSlideSorter.GetController())
+        , m_aUpdateLock(rSlideSorter)
+        , m_aContext(rSlideSorter)
+    {
+    }
+};
+
 void SlotManager::FuSupport (SfxRequest& rRequest)
 {
     switch (rRequest.GetSlot())
@@ -406,10 +423,7 @@ void SlotManager::FuSupport (SfxRequest& rRequest)
                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
             if (pViewShell != nullptr)
             {
-                view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
-                SlideSorterController::ModelChangeLock aModelLock (mrSlideSorter.GetController());
-                PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
-                SelectionObserver::Context aContext (mrSlideSorter);
+                KeepSlideSorterInSyncWithPageChanges aWatcher(mrSlideSorter);
                 pViewShell->ImpSidUndo (false, rRequest);
             }
             break;
@@ -421,10 +435,7 @@ void SlotManager::FuSupport (SfxRequest& rRequest)
                 = dynamic_cast<SlideSorterViewShell*>(mrSlideSorter.GetViewShell());
             if (pViewShell != nullptr)
             {
-                view::SlideSorterView::DrawLock aDrawLock (mrSlideSorter);
-                SlideSorterController::ModelChangeLock aModelLock (mrSlideSorter.GetController());
-                PageSelector::UpdateLock aUpdateLock (mrSlideSorter);
-                SelectionObserver::Context aContext (mrSlideSorter);
+                KeepSlideSorterInSyncWithPageChanges aWatcher(mrSlideSorter);
                 pViewShell->ImpSidRedo (false, rRequest);
             }
             break;


More information about the Libreoffice-commits mailing list