summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2016-05-18 12:23:34 +0100
committerCaolán McNamara <caolanm@redhat.com>2016-05-18 12:54:38 +0100
commitcc03133e1b719ad6ae3885f2eca519196843f2c4 (patch)
tree2247cb5f5da5e50992277d5d2bc7d045ee07d02c /sd
parentdb00223e6d3132eac9603e5dabd20cd03f599cb3 (diff)
refactor this repeated code into a single method
no logic change Change-Id: I362d888323bb22ded7812147811efbebce933564
Diffstat (limited to 'sd')
-rw-r--r--sd/source/ui/inc/SlideSorterViewShell.hxx7
-rw-r--r--sd/source/ui/slidesorter/shell/SlideSorterViewShell.cxx109
2 files changed, 56 insertions, 60 deletions
diff --git a/sd/source/ui/inc/SlideSorterViewShell.hxx b/sd/source/ui/inc/SlideSorterViewShell.hxx
index f191e73419f0..8e667521c7bf 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 24fab760d082..8fd55037d9e6 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);