sd/inc/drawdoc.hxx | 1 sd/source/core/drawdoc2.cxx | 10 sd/source/ui/inc/SlideSorterViewShell.hxx | 9 sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx | 23 - sd/source/ui/slidesorter/controller/SlsSlotManager.cxx | 8 sd/source/ui/slidesorter/inc/controller/SlsSelectionObserver.hxx | 1 sd/source/ui/slidesorter/model/SlideSorterModel.cxx | 6 sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx | 124 +++++----- sd/source/ui/view/viewshel.cxx | 39 +++ 9 files changed, 141 insertions(+), 80 deletions(-)
New commits: commit 83c3c4d46d7185856041be3d9da660aaceff8799 Author: Caolán McNamara <caol...@redhat.com> Date: Mon May 16 13:18:06 2016 +0100 Resolves: tdf#99523 exit text edit and unmark objects before moving slide otherwise correct undo isn't recorded for moving the slides Change-Id: I08338a413f10242c4bdf92a73d504f125bc26631 (cherry picked from commit 4e41e784b97a5b6f5e0cc1f5b24b816ef887b310) 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. Change-Id: I97d744c1c57b68dc312a17a5cd5290e1b6ccf083 (cherry picked from commit db00223e6d3132eac9603e5dabd20cd03f599cb3) 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 (cherry picked from commit e226c19e9136dda366c1485a9d53a0c5d433387c) 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 (cherry picked from commit a0de7474400ae0a84daf688de12c9344d028df93) maDeletedPages member of slidesorter is only written to, never read Change-Id: I5eb58462306f3d8cab54eb00f4ff492c80585dbb (cherry picked from commit 9288886b01907545e22b98dca1dc666a11d71e55) 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 (cherry picked from commit bb3671180eb7327be9ac178e0d8341322f63d72a) refactor this repeated code into a single method no logic change Change-Id: I362d888323bb22ded7812147811efbebce933564 (cherry picked from commit cc03133e1b719ad6ae3885f2eca519196843f2c4) Reviewed-on: https://gerrit.libreoffice.org/25107 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Miklos Vajna <vmik...@collabora.co.uk> diff --git a/sd/inc/drawdoc.hxx b/sd/inc/drawdoc.hxx index ee8a876..ea112a2 100644 --- a/sd/inc/drawdoc.hxx +++ b/sd/inc/drawdoc.hxx @@ -364,6 +364,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 a5406d2..00006cf 100644 --- a/sd/source/core/drawdoc2.cxx +++ b/sd/source/core/drawdoc2.cxx @@ -682,6 +682,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/inc/SlideSorterViewShell.hxx b/sd/source/ui/inc/SlideSorterViewShell.hxx index 8338211..50bdc36 100644 --- a/sd/source/ui/inc/SlideSorterViewShell.hxx +++ b/sd/source/ui/inc/SlideSorterViewShell.hxx @@ -220,6 +220,15 @@ private: virtual void UpdateScrollBars() override; 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/controller/SlsSelectionObserver.cxx b/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx index c90b104..cf1ed11 100644 --- a/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx +++ b/sd/source/ui/slidesorter/controller/SlsSelectionObserver.cxx @@ -58,8 +58,7 @@ void SelectionObserver::Context::Abort() SelectionObserver::SelectionObserver (SlideSorter& rSlideSorter) : mrSlideSorter(rSlideSorter), mbIsOvservationActive(false), - maInsertedPages(), - maDeletedPages() + maInsertedPages() { } @@ -76,24 +75,22 @@ 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); - - maDeletedPages.push_back(pPage->GetPageNum()); - } } void SelectionObserver::StartObservation() { OSL_ASSERT(!mbIsOvservationActive); maInsertedPages.clear(); - maDeletedPages.clear(); mbIsOvservationActive = true; } @@ -102,7 +99,6 @@ void SelectionObserver::AbortObservation() OSL_ASSERT(mbIsOvservationActive); mbIsOvservationActive = false; maInsertedPages.clear(); - maDeletedPages.clear(); } void SelectionObserver::EndObservation() @@ -126,7 +122,6 @@ void SelectionObserver::EndObservation() } maInsertedPages.clear(); } - maDeletedPages.clear(); aUpdateLock.Release(); mrSlideSorter.GetController().GetFocusManager().SetFocusedPageToCurrentPage(); diff --git a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx index b03821c..f40e9c6 100644 --- a/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx +++ b/sd/source/ui/slidesorter/controller/SlsSlotManager.cxx @@ -409,10 +409,6 @@ 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); pViewShell->ImpSidUndo (false, rRequest); } break; @@ -424,10 +420,6 @@ 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); pViewShell->ImpSidRedo (false, rRequest); } break; diff --git a/sd/source/ui/slidesorter/inc/controller/SlsSelectionObserver.hxx b/sd/source/ui/slidesorter/inc/controller/SlsSelectionObserver.hxx index 4bdfc15..c88b032 100644 --- a/sd/source/ui/slidesorter/inc/controller/SlsSelectionObserver.hxx +++ b/sd/source/ui/slidesorter/inc/controller/SlsSelectionObserver.hxx @@ -68,7 +68,6 @@ private: bool mbIsOvservationActive; ::std::vector<const SdPage*> maInsertedPages; - ::std::vector<sal_Int32> maDeletedPages; }; } } } // end of namespace ::sd::slidesorter::controller diff --git a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx index 4d9ddfa..444ee3a 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; diff --git a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx index a77a630..cd51323 100644 --- a/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx +++ b/sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx @@ -701,19 +701,52 @@ void SlideSorterViewShell::RemoveSelectionChangeListener ( mpSlideSorter->GetController().GetSelectionManager()->RemoveSelectionChangeListener(rCallback); } -void SlideSorterViewShell::ExecMovePageFirst (SfxRequest& /*rReq*/) +void SlideSorterViewShell::MainViewEndEditAndUnmarkAll() { - // SdDrawDocument MovePages is based on SdPage IsSelected, so - // transfer the SlideSorter selection to SdPages (*it) - std::shared_ptr<SlideSorterViewShell::PageSelection> pSelection ( GetPageSelection() ); - for (auto it = pSelection->begin(); it != pSelection->end() ; ++it ) { + std::shared_ptr<ViewShell> pMainViewShell = GetViewShellBase().GetMainViewShell(); + DrawViewShell* pDrawViewShell = dynamic_cast<DrawViewShell*>(pMainViewShell.get()); + SdrView* pView = pDrawViewShell ? pDrawViewShell->GetDrawView() : nullptr; + if (pView) + { + pView->SdrEndTextEdit(); + pView->UnmarkAll(); + } +} + +std::pair<sal_uInt16, sal_uInt16> SlideSorterViewShell::SyncPageSelectionToDocument(const std::shared_ptr<SlideSorterViewShell::PageSelection> &rpSelection) +{ + sal_uInt16 firstSelectedPageNo = SAL_MAX_UINT16; + sal_uInt16 lastSelectedPageNo = 0; + + GetDoc()->UnselectAllPages(); + 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) @@ -733,14 +766,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; @@ -753,18 +783,13 @@ void SlideSorterViewShell::GetStateMovePageFirst (SfxItemSet& rSet) void SlideSorterViewShell::ExecMovePageUp (SfxRequest& /*rReq*/) { - sal_uInt16 firstSelectedPageNo = SAL_MAX_UINT16; - sal_uInt16 pageNo; - // SdDrawDocument MovePages is based on SdPage IsSelected, so - // transfer the SlideSorter selection to SdPages (*it) - 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); + MainViewEndEditAndUnmarkAll(); - } + 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; @@ -775,7 +800,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) @@ -785,18 +810,13 @@ void SlideSorterViewShell::GetStateMovePageUp (SfxItemSet& rSet) void SlideSorterViewShell::ExecMovePageDown (SfxRequest& /*rReq*/) { - sal_uInt16 lastSelectedPageNo = 0; - sal_uInt16 pageNo; + MainViewEndEditAndUnmarkAll(); + + std::shared_ptr<SlideSorterViewShell::PageSelection> xSelection(GetPageSelection()); + // SdDrawDocument MovePages is based on SdPage IsSelected, so - // transfer the SlideSorter selection to SdPages (*it) - 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); @@ -809,7 +829,7 @@ void SlideSorterViewShell::ExecMovePageDown (SfxRequest& /*rReq*/) // Move to position after lastSelectedPageNo GetDoc()->MovePages( lastSelectedPageNo + 1 ); - PostMoveSlidesActions(pSelection); + PostMoveSlidesActions(xSelection); } void SlideSorterViewShell::GetStateMovePageDown (SfxItemSet& rSet) @@ -819,12 +839,13 @@ void SlideSorterViewShell::GetStateMovePageDown (SfxItemSet& rSet) 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) - 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); @@ -832,7 +853,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) @@ -849,18 +870,11 @@ void SlideSorterViewShell::GetStateMovePageLast (SfxItemSet& rSet) } } - 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) - 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); diff --git a/sd/source/ui/view/viewshel.cxx b/sd/source/ui/view/viewshel.cxx index a3e92b0..3d4ea73 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> @@ -69,6 +71,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();
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits