From d0d41147a74119fd17574156379559589c926417 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Wed, 15 Jul 2009 10:08:56 +0000 Subject: [PATCH] branch: Fix bug #2213: GuiChanges? lacks "Previous Change" button. see r29108, r29109, r29110, r29111, and r29115. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/branches/BRANCH_1_6_X@30597 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/BufferView.cpp | 9 ++++- src/Cursor.cpp | 6 ++++ src/Cursor.h | 2 ++ src/FuncCode.h | 4 +-- src/LyXAction.cpp | 9 +++++ src/frontends/qt4/GuiChanges.cpp | 7 ++++ src/frontends/qt4/GuiChanges.h | 2 ++ src/frontends/qt4/ui/ChangesUi.ui | 13 +++++++ src/lyxfind.cpp | 59 ++++++++++++++++++++++++++----- src/lyxfind.h | 8 +++++ status.16x | 6 ++-- 11 files changed, 111 insertions(+), 14 deletions(-) diff --git a/src/BufferView.cpp b/src/BufferView.cpp index fd3928f390..d01a6e41ab 100644 --- a/src/BufferView.cpp +++ b/src/BufferView.cpp @@ -964,6 +964,7 @@ FuncStatus BufferView::getStatus(FuncRequest const & cmd) case LFUN_CHANGES_MERGE: case LFUN_CHANGE_NEXT: + case LFUN_CHANGE_PREVIOUS: case LFUN_ALL_CHANGES_ACCEPT: case LFUN_ALL_CHANGES_REJECT: // TODO: context-sensitive enabling of LFUNs @@ -1210,9 +1211,15 @@ bool BufferView::dispatch(FuncRequest const & cmd) // FIXME: Move this LFUN to Buffer so that we don't have to do this: processUpdateFlags(Update::Force | Update::FitCursor); break; + + case LFUN_CHANGE_PREVIOUS: + findPreviousChange(this); + // FIXME: Move this LFUN to Buffer so that we don't have to do this: + processUpdateFlags(Update::Force | Update::FitCursor); + break; case LFUN_CHANGES_MERGE: - if (findNextChange(this)) { + if (findNextChange(this) || findPreviousChange(this)) { processUpdateFlags(Update::Force | Update::FitCursor); showDialog("changes"); } diff --git a/src/Cursor.cpp b/src/Cursor.cpp index b427f8cbed..ec2781a5de 100644 --- a/src/Cursor.cpp +++ b/src/Cursor.cpp @@ -446,6 +446,12 @@ void Cursor::resetAnchor() } +void Cursor::setCursorToAnchor() +{ + if (selection()) + setCursor(anchor_); +} + bool Cursor::posBackward() { diff --git a/src/Cursor.h b/src/Cursor.h index 16cbf4d632..6baef62de5 100644 --- a/src/Cursor.h +++ b/src/Cursor.h @@ -63,6 +63,8 @@ public: void leaveInset(Inset const & inset); /// sets cursor part void setCursor(DocIterator const & it); + /// sets the cursor to the anchor + void setCursorToAnchor(); /// void setCurrentFont(); diff --git a/src/FuncCode.h b/src/FuncCode.h index d37f86f174..0fca191cf2 100644 --- a/src/FuncCode.h +++ b/src/FuncCode.h @@ -349,10 +349,10 @@ enum FuncCode LFUN_PARAGRAPH_MOVE_UP, // 265 LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427 - LFUN_MATH_BIGDELIM, LFUN_CLIPBOARD_PASTE, LFUN_INSET_DISSOLVE, // jspitzm 20060807 LFUN_CHANGE_NEXT, + LFUN_CHANGE_PREVIOUS, // vfr 20090404 // 270 LFUN_WINDOW_NEW, // Abdel 20061021 LFUN_WINDOW_CLOSE, // Abdel 20061023 @@ -424,7 +424,7 @@ enum FuncCode LFUN_INSET_BEGIN_SELECT, // JMarc, 20090316 LFUN_INSET_END_SELECT, // JMarc, 20090316 LFUN_VC_LOCKING_TOGGLE, - + LFUN_MATH_BIGDELIM, LFUN_LASTACTION // end of the table }; diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp index 9555eae379..5d32833229 100644 --- a/src/LyXAction.cpp +++ b/src/LyXAction.cpp @@ -2089,6 +2089,15 @@ void LyXAction::init() * \endvar */ { LFUN_CHANGE_NEXT, "change-next", ReadOnly, Edit }, +/*! + * \var lyx::FuncCode lyx::LFUN_CHANGE_PREVIOUS + * \li Action: Moves the cursor to the position of the previous change + of the change tracking records. + * \li Syntax: change-previous + * \li Origin: vfr, 4 Apr 2009 + * \endvar + */ + { LFUN_CHANGE_PREVIOUS, "change-previous", ReadOnly, Edit }, /*! * \var lyx::FuncCode lyx::LFUN_CHANGES_MERGE * \li Action: Open change tracking dialog for merging and moves the cursor diff --git a/src/frontends/qt4/GuiChanges.cpp b/src/frontends/qt4/GuiChanges.cpp index 5405e5d603..faf02741eb 100644 --- a/src/frontends/qt4/GuiChanges.cpp +++ b/src/frontends/qt4/GuiChanges.cpp @@ -43,6 +43,7 @@ GuiChanges::GuiChanges(GuiView & lv) connect(closePB, SIGNAL(clicked()), this, SLOT(slotClose())); connect(nextPB, SIGNAL(clicked()), this, SLOT(nextChange())); + connect(previousPB, SIGNAL(clicked()), this, SLOT(previousChange())); connect(rejectPB, SIGNAL(clicked()), this, SLOT(rejectChange())); connect(acceptPB, SIGNAL(clicked()), this, SLOT(acceptChange())); @@ -74,6 +75,12 @@ void GuiChanges::nextChange() } +void GuiChanges::previousChange() +{ + dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS)); +} + + docstring GuiChanges::changeDate() const { Change const & c = bufferview()->getCurrentChange(); diff --git a/src/frontends/qt4/GuiChanges.h b/src/frontends/qt4/GuiChanges.h index 2579145ba1..344f5e5607 100644 --- a/src/frontends/qt4/GuiChanges.h +++ b/src/frontends/qt4/GuiChanges.h @@ -35,6 +35,8 @@ protected Q_SLOTS: void rejectChange(); /// find the next change and highlight it void nextChange(); + /// find the previous change and highlight it + void previousChange(); private: /// diff --git a/src/frontends/qt4/ui/ChangesUi.ui b/src/frontends/qt4/ui/ChangesUi.ui index e6a979a29b..0a31087d96 100644 --- a/src/frontends/qt4/ui/ChangesUi.ui +++ b/src/frontends/qt4/ui/ChangesUi.ui @@ -43,6 +43,19 @@ 6 + + + + Go to previous change + + + &Previous change + + + false + + + diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index bc1f037e7a..7b54163e7b 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -100,11 +100,19 @@ bool findBackwards(DocIterator & cur, MatchString const & match, } -bool findChange(DocIterator & cur) +bool findChange(DocIterator & cur, bool next) { - for (; cur; cur.forwardPos()) - if (cur.inTexted() && !cur.paragraph().isUnchanged(cur.pos())) + if (!next) + cur.backwardPos(); + for (; cur; next ? cur.forwardPos() : cur.backwardPos()) + if (cur.inTexted() && !cur.paragraph().isUnchanged(cur.pos())) { + if (!next) + // if we search backwards, take a step forward + // to correctly set the anchor + cur.forwardPos(); return true; + } + return false; } @@ -317,21 +325,54 @@ void replace(BufferView * bv, FuncRequest const & ev, bool has_deleted) bool findNextChange(BufferView * bv) { - DocIterator cur = bv->cursor(); + return findChange(bv, true); +} - if (!findChange(cur)) + +bool findPreviousChange(BufferView * bv) +{ + return findChange(bv, false); +} + + +bool findChange(BufferView * bv, bool next) +{ + if (bv->cursor().selection()) { + // set the cursor at the beginning or at the end of the selection + // before searching. Otherwise, the current change will be found. + if (next != bv->cursor().top() > bv->cursor().anchor()) + bv->cursor().setCursorToAnchor(); + } + + DocIterator cur = bv->cursor(); + if (!findChange(cur, next)) return false; bv->cursor().setCursor(cur); bv->cursor().resetAnchor(); + if (!next) + // take a step into the change + cur.backwardPos(); + Change orig_change = cur.paragraph().lookupChange(cur.pos()); CursorSlice & tip = cur.top(); - for (; !tip.at_end(); tip.forwardPos()) { - Change change = tip.paragraph().lookupChange(tip.pos()); - if (change != orig_change) - break; + if (next) { + for (; !tip.at_end(); tip.forwardPos()) { + Change change = tip.paragraph().lookupChange(tip.pos()); + if (change != orig_change) + break; + } + } else { + for (; !tip.at_begin(); tip.backwardPos()) { + Change change = tip.paragraph().lookupChange(tip.pos()); + if (change != orig_change) { + // take a step forward to correctly set the selection + tip.forwardPos(); + break; + } + } } // Now put cursor to end of selection: diff --git a/src/lyxfind.h b/src/lyxfind.h index 6301ab5b74..09a6984fef 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -58,6 +58,14 @@ void replace(BufferView * bv, FuncRequest const &, bool has_deleted = false); /// find the next change in the buffer bool findNextChange(BufferView * bv); +/// find the previous change in the buffer +bool findPreviousChange(BufferView * bv); + +/// find the change in the buffer +/// \param next true to find the next change, otherwise the previous +bool findChange(BufferView * bv, bool next); + + } // namespace lyx #endif // LYXFIND_H diff --git a/status.16x b/status.16x index ff4e701f4e..7b6faccf07 100644 --- a/status.16x +++ b/status.16x @@ -70,6 +70,7 @@ What's new - Make it possible to copy from a deleted section (bug 5390). +- Reverse searching added to the merge changes dialog (bug 2213). * DOCUMENTATION AND LOCALIZATION @@ -223,8 +224,9 @@ What's new - Fix selection of math insets on some archs. -- Fix unitialized variable in Math, Dialog and inset painting code - (bugs 6082, 6081, 6077). +- Fix of painter glitches caused by unitialized variables (bug 6077). + +- Fix unitialized variable in Dialog code (bug 6081). * DOCUMENTATION AND LOCALIZATION