From: Tommaso Cucinotta Date: Fri, 23 Aug 2013 19:36:50 +0000 (+0100) Subject: Added restrict-search-to-maths-only checkbox to advanced pane of Advanced F&R. X-Git-Tag: 2.1.0beta2~22 X-Git-Url: https://git.lyx.org/gitweb/?a=commitdiff_plain;h=b93f2c20d34b713e0b47cd573f2699e50e797d83;p=features.git Added restrict-search-to-maths-only checkbox to advanced pane of Advanced F&R. --- diff --git a/src/frontends/qt4/FindAndReplace.cpp b/src/frontends/qt4/FindAndReplace.cpp index 1a390ec4b2..ce32a8eb98 100644 --- a/src/frontends/qt4/FindAndReplace.cpp +++ b/src/frontends/qt4/FindAndReplace.cpp @@ -439,6 +439,12 @@ bool FindAndReplaceWidget::findAndReplace( scope = FindAndReplaceOptions::S_ALL_MANUALS; else LATTEST(false); + + FindAndReplaceOptions::SearchRestriction restr = + OnlyMaths->isChecked() + ? FindAndReplaceOptions::R_ONLY_MATHS + : FindAndReplaceOptions::R_EVERYTHING; + LYXERR(Debug::FIND, "FindAndReplaceOptions: " << "find_buf_name=" << find_buf_name << ", casesensitiv=" << casesensitive @@ -448,10 +454,12 @@ bool FindAndReplaceWidget::findAndReplace( << ", ignoreformat=" << ignoreformat << ", repl_buf_name" << repl_buf_name << ", keep_case=" << keep_case - << ", scope=" << scope); + << ", scope=" << scope + << ", restr=" << restr); + FindAndReplaceOptions opt(find_buf_name, casesensitive, matchword, !backwards, expandmacros, ignoreformat, - repl_buf_name, keep_case, scope); + repl_buf_name, keep_case, scope, restr); return findAndReplaceScope(opt, replace_all); } diff --git a/src/frontends/qt4/ui/FindAndReplaceUi.ui b/src/frontends/qt4/ui/FindAndReplaceUi.ui index ecca12f7d2..b73db8a88c 100644 --- a/src/frontends/qt4/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt4/ui/FindAndReplaceUi.ui @@ -7,7 +7,7 @@ 0 0 276 - 291 + 421 @@ -264,19 +264,6 @@ - - - - Qt::Vertical - - - - 20 - 40 - - - - @@ -311,7 +298,7 @@ - + false @@ -321,21 +308,28 @@ - - - - Qt::Vertical - - - - 20 - 40 - + + + + Search only in mat&hs - + + + + + Qt::Vertical + + + + 20 + 40 + + + + diff --git a/src/lyxfind.cpp b/src/lyxfind.cpp index 59dcb8ff48..99e361ea47 100644 --- a/src/lyxfind.cpp +++ b/src/lyxfind.cpp @@ -904,6 +904,9 @@ MatchStringAdv::MatchStringAdv(lyx::Buffer & buf, FindAndReplaceOptions const & int MatchStringAdv::findAux(DocIterator const & cur, int len, bool at_begin) const { + if (at_begin && + (opt.restr == FindAndReplaceOptions::R_ONLY_MATHS && !cur.inMathed()) ) + return 0; docstring docstr = stringifyFromForSearch(opt, cur, len); LYXERR(Debug::FIND, "Matching against '" << lyx::to_utf8(docstr) << "'"); string str = normalize(docstr, true); @@ -1296,10 +1299,10 @@ FindAndReplaceOptions::FindAndReplaceOptions( docstring const & find_buf_name, bool casesensitive, bool matchword, bool forward, bool expandmacros, bool ignoreformat, docstring const & repl_buf_name, bool keep_case, - SearchScope scope) + SearchScope scope, SearchRestriction restr) : find_buf_name(find_buf_name), casesensitive(casesensitive), matchword(matchword), forward(forward), expandmacros(expandmacros), ignoreformat(ignoreformat), - repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope) + repl_buf_name(repl_buf_name), keep_case(keep_case), scope(scope), restr(restr) { } @@ -1492,7 +1495,8 @@ ostringstream & operator<<(ostringstream & os, FindAndReplaceOptions const & opt << opt.ignoreformat << ' ' << to_utf8(opt.repl_buf_name) << "\nEOSS\n" << opt.keep_case << ' ' - << int(opt.scope); + << int(opt.scope) << ' ' + << int(opt.restr); LYXERR(Debug::FIND, "built: " << os.str()); @@ -1534,8 +1538,12 @@ istringstream & operator>>(istringstream & is, FindAndReplaceOptions & opt) int i; is >> i; opt.scope = FindAndReplaceOptions::SearchScope(i); + is >> i; + opt.restr = FindAndReplaceOptions::SearchRestriction(i); + LYXERR(Debug::FIND, "parsed: " << opt.casesensitive << ' ' << opt.matchword << ' ' << opt.forward << ' ' - << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case); + << opt.expandmacros << ' ' << opt.ignoreformat << ' ' << opt.keep_case << ' ' + << opt.scope << ' ' << opt.restr); return is; } diff --git a/src/lyxfind.h b/src/lyxfind.h index 9adcae968d..6b53da5474 100644 --- a/src/lyxfind.h +++ b/src/lyxfind.h @@ -80,6 +80,10 @@ public: S_OPEN_BUFFERS, S_ALL_MANUALS } SearchScope; + typedef enum { + R_EVERYTHING, + R_ONLY_MATHS + } SearchRestriction; FindAndReplaceOptions( docstring const & find_buf_name, bool casesensitive, @@ -89,7 +93,8 @@ public: bool ignoreformat, docstring const & repl_buf_name, bool keep_case, - SearchScope scope = S_BUFFER + SearchScope scope = S_BUFFER, + SearchRestriction restr = R_EVERYTHING ); FindAndReplaceOptions() { } docstring find_buf_name; @@ -102,6 +107,7 @@ public: docstring repl_buf_name; bool keep_case; SearchScope scope; + SearchRestriction restr; }; /// Write a FindAdvOptions instance to a stringstream