1 #include "CopyUndoAction.h"
2 
3 #include "control/Control.h"
4 #include "gui/XournalppCursor.h"
5 #include "model/PageRef.h"
6 
7 #include "i18n.h"
8 
CopyUndoAction(const PageRef & pageref,int pageNr)9 CopyUndoAction::CopyUndoAction(const PageRef& pageref, int pageNr): UndoAction("CopyUndoAction") {
10     this->page = pageref;
11     this->pageNr = pageNr;
12 }
13 
~CopyUndoAction()14 CopyUndoAction::~CopyUndoAction() { this->page = nullptr; }
15 
undo(Control * control)16 auto CopyUndoAction::undo(Control* control) -> bool {
17     Document* doc = control->getDocument();
18 
19     // in order to fix the hang, we need to get out
20     // of text mode
21     // ***This might kill whatever we've got selected
22     control->clearSelectionEndText();
23 
24     // first send event, then delete page...
25     // we need to unlock the document from UndoRedoHandler
26     // because firePageDeleted is threadsafe.
27     doc->unlock();
28     control->firePageDeleted(pageNr);
29     doc->lock();
30     doc->deletePage(pageNr);
31 
32     control->updateDeletePageButton();
33 
34     return true;
35 }
36 
redo(Control * control)37 auto CopyUndoAction::redo(Control* control) -> bool {
38     Document* doc = control->getDocument();
39 
40     // just in case there would be a hang here,
41     // we'll clear the selection in redo as well
42     control->clearSelectionEndText();
43 
44     // see deletePage for why this is done
45     // doc->lock();
46     doc->insertPage(this->page, this->pageNr);
47     doc->unlock();
48 
49     // these are all threadsafe (I think...)
50     control->firePageInserted(this->pageNr);
51     control->getCursor()->updateCursor();
52     control->getScrollHandler()->scrollToPage(this->pageNr);
53     control->updateDeletePageButton();
54 
55     // this prevents the double unlock
56     doc->lock();
57     return true;
58 }
59 
getText()60 auto CopyUndoAction::getText() -> string { return _("Copy page"); }
61