From d8bd69e7d60d39ad472c508a3ab184ee9c56bd58 Mon Sep 17 00:00:00 2001 From: andreasb123 Date: Thu, 19 May 2011 08:06:27 +0000 Subject: [PATCH] Undo Redo Fix: Double Lock... git-svn-id: https://xournal.svn.sourceforge.net/svnroot/xournal/trunk/xournalpp@150 9fe2bcd3-a095-4d8b-a836-9b85dc8d7627 --- src/model/Document.cpp | 17 ++-- src/undo/PageBackgroundChangedUndoAction.cpp | 100 +++++++++---------- 2 files changed, 57 insertions(+), 60 deletions(-) diff --git a/src/model/Document.cpp b/src/model/Document.cpp index c03511ab..f28c6a0d 100644 --- a/src/model/Document.cpp +++ b/src/model/Document.cpp @@ -41,17 +41,22 @@ void Document::lock() { g_mutex_lock(this->documentLock); - // if(tryLock()) { - // Stacktrace::printStracktrace(); - // fprintf(stderr, "\n\n\n\n"); - // } else { - // g_mutex_lock(this->documentLock); - // } +// if(tryLock()) { +// fprintf(stderr, "Locked by\n"); +// Stacktrace::printStracktrace(); +// fprintf(stderr, "\n\n\n\n"); +// } else { +// g_mutex_lock(this->documentLock); +// } } void Document::unlock() { XOJ_CHECK_TYPE(Document); g_mutex_unlock(this->documentLock); + +// fprintf(stderr, "Unlocked by\n"); +// Stacktrace::printStracktrace(); +// fprintf(stderr, "\n\n\n\n"); } bool Document::tryLock() { diff --git a/src/undo/PageBackgroundChangedUndoAction.cpp b/src/undo/PageBackgroundChangedUndoAction.cpp index 5a84cb4a..5d6c0d3a 100644 --- a/src/undo/PageBackgroundChangedUndoAction.cpp +++ b/src/undo/PageBackgroundChangedUndoAction.cpp @@ -21,37 +21,31 @@ PageBackgroundChangedUndoAction::~PageBackgroundChangedUndoAction() { bool PageBackgroundChangedUndoAction::undo(Control * control) { XOJ_CHECK_TYPE(PageBackgroundChangedUndoAction); - // TODO: CRASH!! - -// this->newType = this->page.getBackgroundType(); -// this->newPdfPage = this->page.getPdfPageNr(); -// this->newBackgroundImage = this->page.getBackgroundImage(); -// this->newW = this->page.getWidth(); -// this->newH = this->page.getHeight(); -// -// Document * doc = control->getDocument(); -// doc->lock(); -// -// int pageNr = doc->indexOf(this->page); -// if (pageNr == -1) { -// doc->unlock(); -// return false; -// } -// -// if (this->newW != this->origW || this->newH != this->origH) { -// this->page.setSize(this->origW, this->origH); -// control->firePageSizeChanged(pageNr); -// } -// -// this->page.setBackgroundType(this->origType); -// if (this->origType == BACKGROUND_TYPE_PDF) { -// this->page.setBackgroundPdfPageNr(this->origPdfPage); -// } else if (this->origType == BACKGROUND_TYPE_IMAGE) { -// this->page.setBackgroundImage(this->origBackgroundImage); -// } -// -// doc->unlock(); -// control->firePageChanged(pageNr); + this->newType = this->page.getBackgroundType(); + this->newPdfPage = this->page.getPdfPageNr(); + this->newBackgroundImage = this->page.getBackgroundImage(); + this->newW = this->page.getWidth(); + this->newH = this->page.getHeight(); + + Document * doc = control->getDocument(); + int pageNr = doc->indexOf(this->page); + if (pageNr == -1) { + return false; + } + + if (this->newW != this->origW || this->newH != this->origH) { + this->page.setSize(this->origW, this->origH); + control->firePageSizeChanged(pageNr); + } + + this->page.setBackgroundType(this->origType); + if (this->origType == BACKGROUND_TYPE_PDF) { + this->page.setBackgroundPdfPageNr(this->origPdfPage); + } else if (this->origType == BACKGROUND_TYPE_IMAGE) { + this->page.setBackgroundImage(this->origBackgroundImage); + } + + control->firePageChanged(pageNr); return true; } @@ -59,29 +53,27 @@ bool PageBackgroundChangedUndoAction::undo(Control * control) { bool PageBackgroundChangedUndoAction::redo(Control * control) { XOJ_CHECK_TYPE(PageBackgroundChangedUndoAction); -// Document * doc = control->getDocument(); -// -// doc->lock(); -// int pageNr = doc->indexOf(this->page); -// doc->unlock(); -// -// if (pageNr == -1) { -// return false; -// } -// -// if (this->newW != this->origW || this->newH != this->origH) { -// this->page.setSize(this->newW, this->newH); -// control->firePageSizeChanged(pageNr); -// } -// -// this->page.setBackgroundType(this->newType); -// if (this->newType == BACKGROUND_TYPE_PDF) { -// this->page.setBackgroundPdfPageNr(this->newPdfPage); -// } else if (this->newType == BACKGROUND_TYPE_IMAGE) { -// this->page.setBackgroundImage(this->newBackgroundImage); -// } -// -// control->firePageChanged(pageNr); + Document * doc = control->getDocument(); + + int pageNr = doc->indexOf(this->page); + + if (pageNr == -1) { + return false; + } + + if (this->newW != this->origW || this->newH != this->origH) { + this->page.setSize(this->newW, this->newH); + control->firePageSizeChanged(pageNr); + } + + this->page.setBackgroundType(this->newType); + if (this->newType == BACKGROUND_TYPE_PDF) { + this->page.setBackgroundPdfPageNr(this->newPdfPage); + } else if (this->newType == BACKGROUND_TYPE_IMAGE) { + this->page.setBackgroundImage(this->newBackgroundImage); + } + + control->firePageChanged(pageNr); return true;