From 33e123a5cd7fadd3e507d165867b5e52132f72eb Mon Sep 17 00:00:00 2001 From: Tommaso Cucinotta Date: Sat, 9 Jan 2010 22:49:35 +0000 Subject: [PATCH] Added ALL_MANUALS scope to Advanced Find & Replace. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@32925 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/frontends/qt4/FindAndReplace.cpp | 61 ++++++++++++++++++++++++ src/frontends/qt4/GuiWorkArea.cpp | 3 ++ src/frontends/qt4/ui/FindAndReplaceUi.ui | 2 +- src/lyxfind.h | 2 +- 4 files changed, 66 insertions(+), 2 deletions(-) diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index 2eadfcd2d3..53a19b56b0 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -32,6 +32,7 @@ #include "support/FileName.h" #include "support/gettext.h" #include "support/lassert.h" +#include "support/filetools.h" #include #include @@ -125,6 +126,23 @@ static docstring buffer_to_latex(Buffer & buffer) { } +static vector const & allManualsFiles() { + static vector v; + static const char * files[] = { + "Intro", "UserGuide", "Tutorial", "Additional", "EmbeddedObjects", + "Math", "Customization", "Shortcuts", "LFUNs", "LaTeXConfig" + }; + if (v.empty()) { + FileName fname; + for (size_t i = 0; i < sizeof(files) / sizeof(files[0]); ++i) { + fname = i18nLibFileSearch("doc", files[i], "lyx"); + v.push_back(fname.absFilename()); + } + } + return v; +} + + /** Switch p_buf to point to next document buffer. ** ** Return true if restarted from master-document buffer. @@ -220,6 +238,29 @@ static bool next_prev_buffer(Buffer * & buf, FindAndReplaceOptions const & opt) restarted = buf == *(theBufferList().end() - 1); } break; + case FindAndReplaceOptions::S_ALL_MANUALS: + vector const & v = allManualsFiles(); + vector::const_iterator it = find(v.begin(), v.end(), buf->absFileName()); + if (it == v.end()) { + it = v.begin(); + } else if (opt.forward) { + ++it; + if (it == v.end()) { + it = v.begin(); + restarted = true; + } + } else { + if (it == v.begin()) { + it = v.end(); + restarted = true; + } + --it; + } + FileName const & fname = FileName(*it); + if (!theBufferList().exists(fname)) + guiApp->currentView()->loadDocument(fname, false); + buf = theBufferList().getBuffer(fname); + break; } return restarted; } @@ -241,6 +282,9 @@ docstring question_string(FindAndReplaceOptions const & opt) case FindAndReplaceOptions::S_OPEN_BUFFERS: scope = _("open files"); break; + case FindAndReplaceOptions::S_ALL_MANUALS: + scope = _("manuals"); + break; } docstring dir = opt.forward ? _("forward") : _("backwards"); return cur_pos + _(" of ") + scope @@ -261,6 +305,21 @@ void FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt) { Buffer * buf_orig = &bv->buffer(); Cursor cur_orig(bv->cursor()); + if (opt.scope == FindAndReplaceOptions::S_ALL_MANUALS) { + vector const & v = allManualsFiles(); + if (std::find(v.begin(), v.end(), buf->absFileName()) == v.end()) { + FileName const & fname = FileName(*v.begin()); + if (!theBufferList().exists(fname)) + guiApp->currentView()->loadDocument(fname, false); + buf = theBufferList().getBuffer(fname); + lyx::dispatch(FuncRequest(LFUN_BUFFER_SWITCH, + buf->absFileName())); + bv = view_.documentBufferView(); + bv->cursor().clear(); + bv->cursor().push_back(CursorSlice(buf->inset())); + } + } + do { LYXERR(Debug::FIND, "Dispatching LFUN_WORD_FINDADV"); dispatch(cmd); @@ -346,6 +405,8 @@ void FindAndReplaceWidget::findAndReplace( scope = FindAndReplaceOptions::S_DOCUMENT; else if (OpenDocuments->isChecked()) scope = FindAndReplaceOptions::S_OPEN_BUFFERS; + else if (AllManualsRB->isChecked()) + scope = FindAndReplaceOptions::S_ALL_MANUALS; else LASSERT(false, /**/); LYXERR(Debug::FIND, "FindAndReplaceOptions: " diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 08b935d9da..fce8cf87e3 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -1277,6 +1277,9 @@ void EmbeddedWorkArea::disable() stopBlinkingCursor(); if (view().currentWorkArea() != this) return; + // No problem if currentMainWorkArea() is 0 (setCurrentWorkArea() + // tolerates it and shows the background logo), what happens if + // an EmbeddedWorkArea is closed after closing all document WAs view().setCurrentWorkArea(view().currentMainWorkArea()); } diff --git a/src/frontends/qt4/ui/FindAndReplaceUi.ui b/src/frontends/qt4/ui/FindAndReplaceUi.ui index 9fd9bed0cc..cb84079ad8 100644 --- a/src/frontends/qt4/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt4/ui/FindAndReplaceUi.ui @@ -697,7 +697,7 @@ - false + true diff --git a/src/lyxfind.h b/src/lyxfind.h index 7d660eed11..711bf8ee25 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -82,7 +82,7 @@ public: S_BUFFER, S_DOCUMENT, S_OPEN_BUFFERS, - /*S_ALL_MANUALS*/ + S_ALL_MANUALS } SearchScope; FindAndReplaceOptions( docstring const & search,