This patch adds reverse change searching to the GuiChanges dialog.
Ok ? Vincent
Index: src/LyXAction.cpp =================================================================== --- src/LyXAction.cpp (revision 29065) +++ src/LyXAction.cpp (working copy) @@ -2109,6 +2109,15 @@ */ { 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 to the position of the next change. Index: src/BufferView.cpp =================================================================== --- src/BufferView.cpp (revision 29066) +++ src/BufferView.cpp (working copy) @@ -983,6 +983,7 @@ 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 @@ -1228,6 +1229,12 @@ 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)) { processUpdateFlags(Update::Force | Update::FitCursor); Index: src/lyxfind.cpp =================================================================== --- src/lyxfind.cpp (revision 29065) +++ src/lyxfind.cpp (working copy) @@ -115,11 +115,19 @@ } -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; } @@ -332,23 +340,50 @@ bool findNextChange(BufferView * bv) { + return findChange(bv, true); +} + + +bool findPreviousChange(BufferView * bv) +{ + return findChange(bv, false); +} + + +bool findChange(BufferView * bv, bool next) +{ DocIterator cur = bv->cursor(); - if (!findChange(cur)) + 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: bv->cursor().setCursor(cur); bv->cursor().setSelection(); Index: src/frontends/qt4/GuiChanges.cpp =================================================================== --- src/frontends/qt4/GuiChanges.cpp (revision 29065) +++ src/frontends/qt4/GuiChanges.cpp (working copy) @@ -42,6 +42,7 @@ 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())); @@ -73,6 +74,12 @@ } +void GuiChanges::previousChange() +{ + dispatch(FuncRequest(LFUN_CHANGE_PREVIOUS)); +} + + docstring GuiChanges::changeDate() const { Change const & c = bufferview()->getCurrentChange(); Index: src/frontends/qt4/ui/ChangesUi.ui =================================================================== --- src/frontends/qt4/ui/ChangesUi.ui (revision 29065) +++ src/frontends/qt4/ui/ChangesUi.ui (working copy) @@ -44,6 +44,19 @@ <number>6</number> </property> <item> + <widget class="QPushButton" name="previousPB" > + <property name="toolTip" > + <string>Go to previous change</string> + </property> + <property name="text" > + <string>&Previous change</string> + </property> + <property name="default" > + <bool>false</bool> + </property> + </widget> + </item> + <item> <widget class="QPushButton" name="nextPB" > <property name="toolTip" > <string>Go to next change</string> Index: src/frontends/qt4/GuiChanges.h =================================================================== --- src/frontends/qt4/GuiChanges.h (revision 29065) +++ src/frontends/qt4/GuiChanges.h (working copy) @@ -35,6 +35,8 @@ void rejectChange(); /// find the next change and highlight it void nextChange(); + /// find the previous change and highlight it + void previousChange(); private: /// Index: src/lyxfind.h =================================================================== --- src/lyxfind.h (revision 29065) +++ src/lyxfind.h (working copy) @@ -66,6 +66,13 @@ /// 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); + // Hopefully, nobody will ever replace with something like this #define LYX_FR_NULL_STRING "__LYX__F&R__NULL__STRING__" Index: src/FuncCode.h =================================================================== --- src/FuncCode.h (revision 29065) +++ src/FuncCode.h (working copy) @@ -348,10 +348,10 @@ LFUN_PARAGRAPH_MOVE_UP, LFUN_BUFFER_TOGGLE_COMPRESSION, // bpeng 20060427 // 265 - LFUN_MATH_BIGDELIM, LFUN_CLIPBOARD_PASTE, LFUN_INSET_DISSOLVE, // jspitzm 20060807 LFUN_CHANGE_NEXT, + LFUN_CHANGE_PREVIOUS, // vfr 20090404 LFUN_WINDOW_NEW, // Abdel 20061021 // 270 LFUN_WINDOW_CLOSE, // Abdel 20061023 @@ -423,6 +423,7 @@ LFUN_INSET_BEGIN_SELECT, // JMarc, 20090316 LFUN_INSET_END_SELECT, // JMarc, 20090316 LFUN_SCREEN_SHOW_CURSOR, // vfr, 20090325 + LFUN_MATH_BIGDELIM, LFUN_LASTACTION // end of the table