From 24e2c495fe9836603ccf59f402f9499476975898 Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Wed, 30 Dec 2009 21:50:55 +0000 Subject: [PATCH] Implemented S_OPEN_BUFFERS scope in Advanced Find feature (keep searching and find all occurrences within all open buffers). git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32680 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/FindAndReplace.cpp | 2 + src/frontends/qt4/ui/FindAndReplaceUi.ui | 129 +++++++---------------- src/lyxfind.cpp | 42 ++++++++ 3 files changed, 81 insertions(+), 92 deletions(-) diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index ca5e23f27d..a3c6f833ab 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -167,6 +167,8 @@ void FindAndReplaceWidget::findAndReplace( scope = FindAndReplaceOptions::S_BUFFER; else if (MasterDocument->isChecked()) scope = FindAndReplaceOptions::S_DOCUMENT; + else if (OpenDocuments->isChecked()) + scope = FindAndReplaceOptions::S_OPEN_BUFFERS; else LASSERT(false, /**/); LYXERR(Debug::FIND, "FindAndReplaceOptions: " diff --git a/src/frontends/qt4/ui/FindAndReplaceUi.ui b/src/frontends/qt4/ui/FindAndReplaceUi.ui index fa19147d9d..3a2cf46da9 100644 --- a/src/frontends/qt4/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt4/ui/FindAndReplaceUi.ui @@ -1,3 +1,4 @@ + FindAndReplaceUi @@ -5,14 +6,12 @@ 0 0 - 325 + 327 523 - - 1 - 7 + 0 0 @@ -52,17 +51,15 @@ 0 0 - 303 - 501 + 307 + 503 - - 7 - 7 + 0 0 @@ -81,9 +78,7 @@ - - 5 - 7 + 0 0 @@ -101,9 +96,7 @@ - - 7 - 7 + 0 0 @@ -127,9 +120,7 @@ - - 7 - 7 + 0 0 @@ -181,14 +172,12 @@ 0 0 - 237 - 84 + 239 + 79 - - 7 - 7 + 0 0 @@ -202,9 +191,7 @@ true - - 7 - 1 + 1 0 @@ -223,9 +210,7 @@ true - - 7 - 1 + 1 0 @@ -244,9 +229,7 @@ false - - 7 - 1 + 0 0 @@ -259,9 +242,7 @@ - - 7 - 1 + 1 0 @@ -277,9 +258,7 @@ - - 7 - 1 + 1 0 @@ -301,9 +280,7 @@ - - 7 - 7 + 0 0 @@ -321,9 +298,7 @@ - - 7 - 7 + 0 0 @@ -381,14 +356,12 @@ 0 0 - 237 - 85 + 239 + 80 - - 7 - 7 + 0 0 @@ -399,9 +372,7 @@ - - 7 - 1 + 0 0 @@ -420,9 +391,7 @@ true - - 7 - 1 + 0 0 @@ -468,9 +437,7 @@ true - - 7 - 1 + 0 0 @@ -492,9 +459,7 @@ true - - 7 - 1 + 0 0 @@ -516,9 +481,7 @@ false - - 7 - 1 + 0 0 @@ -541,9 +504,7 @@ - - 7 - 7 + 0 0 @@ -569,9 +530,7 @@ true - - 7 - 1 + 0 0 @@ -607,9 +566,7 @@ false - - 1 - 1 + 0 0 @@ -631,9 +588,7 @@ true - - 1 - 1 + 0 0 @@ -655,9 +610,7 @@ true - - 1 - 1 + 0 0 @@ -673,12 +626,10 @@ - false + true - - 1 - 1 + 0 0 @@ -697,9 +648,7 @@ false - - 1 - 1 + 0 0 @@ -718,9 +667,7 @@ false - - 7 - 1 + 0 0 @@ -736,9 +683,7 @@ true - - 7 - 1 + 0 0 diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index e5bf8b609b..bb4518031a 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -17,6 +17,7 @@ #include "lyxfind.h" #include "Buffer.h" +#include "BufferList.h" #include "buffer_funcs.h" #include "BufferParams.h" #include "BufferView.h" @@ -1005,6 +1006,42 @@ bool prev_document_buffer(Buffer * & p_buf) { } +/** Switch p_buf to point to next open buffer. + ** + ** Return true if restarted from first open buffer. + **/ +bool next_open_buffer(Buffer * & p_buf) { + BufferList::const_iterator it = find(theBufferList().begin(), theBufferList().end(), p_buf); + LASSERT(it != theBufferList().end(), /**/) + ++it; + if (it == theBufferList().end()) { + p_buf = *theBufferList().begin(); + return true; + } + p_buf = *it; + return false; +} + + +/** Switch p_buf to point to previous open buffer. + ** + ** Return true if restarted from last open buffer. + **/ +bool prev_open_buffer(Buffer * & p_buf) { + BufferList::const_iterator it = find(theBufferList().begin(), theBufferList().end(), p_buf); + LASSERT(it != theBufferList().end(), /**/) + if (it == theBufferList().begin()) { + it = theBufferList().end(); + --it; + p_buf = *it; + return true; + } + --it; + p_buf = *it; + return false; +} + + /// Finds forward int findForwardAdv(DocIterator & cur, MatchStringAdv & match) { @@ -1029,6 +1066,8 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) prompt = true; } else if (match.opt.scope == FindAndReplaceOptions::S_DOCUMENT) { prompt = next_document_buffer(match.p_buf); + } else if (match.opt.scope == FindAndReplaceOptions::S_OPEN_BUFFERS) { + prompt = next_open_buffer(match.p_buf); } else { /* Unimplemented scope */ LASSERT(false, /**/); @@ -1049,6 +1088,7 @@ int findForwardAdv(DocIterator & cur, MatchStringAdv & match) return 0; } + /// Find the most backward consecutive match within same paragraph while searching backwards. void findMostBackwards(DocIterator & cur, MatchStringAdv const & match, int & len) { DocIterator cur_begin = doc_iterator_begin(cur.buffer()); @@ -1141,6 +1181,8 @@ int findBackwardsAdv(DocIterator & cur, MatchStringAdv & match) { prompt = true; } else if (match.opt.scope == FindAndReplaceOptions::S_DOCUMENT) { prompt = prev_document_buffer(match.p_buf); + } else if (match.opt.scope == FindAndReplaceOptions::S_OPEN_BUFFERS) { + prompt = prev_open_buffer(match.p_buf); } else { /* Unimplemented scope */ LASSERT(false, /**/);