]> git.lyx.org Git - features.git/commitdiff
Added restrict-search-to-maths-only checkbox to advanced pane of Advanced F&R.
authorTommaso Cucinotta <tommaso@lyx.org>
Fri, 23 Aug 2013 19:36:50 +0000 (20:36 +0100)
committerTommaso Cucinotta <tommaso@lyx.org>
Sat, 12 Oct 2013 23:59:46 +0000 (00:59 +0100)
src/frontends/qt4/FindAndReplace.cpp
src/frontends/qt4/ui/FindAndReplaceUi.ui
src/lyxfind.cpp
src/lyxfind.h

index 1a390ec4b27cc0c31a6260edf545ff5a18b434b7..ce32a8eb98be927c7056d1c9ea5c0eb98b0255f6 100644 (file)
@@ -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);
 }
 
index ecca12f7d27effa51021ee16aa3dcc6107378431..b73db8a88cfffd745ff6677cda474ed31130fe1a 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>276</width>
-    <height>291</height>
+    <height>421</height>
    </rect>
   </property>
   <property name="sizePolicy">
          </property>
         </widget>
        </item>
-       <item>
-        <spacer name="verticalSpacer">
-         <property name="orientation">
-          <enum>Qt::Vertical</enum>
-         </property>
-         <property name="sizeHint" stdset="0">
-          <size>
-           <width>20</width>
-           <height>40</height>
-          </size>
-         </property>
-        </spacer>
-       </item>
       </layout>
      </widget>
     </item>
         </property>
        </widget>
       </item>
-      <item row="3" column="0">
+      <item row="4" column="0">
        <widget class="QCheckBox" name="expandMacrosCB">
         <property name="enabled">
          <bool>false</bool>
         </property>
        </widget>
       </item>
-      <item row="4" column="0">
-       <spacer name="verticalSpacer_2">
-        <property name="orientation">
-         <enum>Qt::Vertical</enum>
-        </property>
-        <property name="sizeHint" stdset="0">
-         <size>
-          <width>20</width>
-          <height>40</height>
-         </size>
+      <item row="3" column="0">
+       <widget class="QCheckBox" name="OnlyMaths">
+        <property name="text">
+         <string>Search only in mat&amp;hs</string>
         </property>
-       </spacer>
+       </widget>
       </item>
      </layout>
     </item>
+    <item>
+     <spacer name="verticalSpacer_2">
+      <property name="orientation">
+       <enum>Qt::Vertical</enum>
+      </property>
+      <property name="sizeHint" stdset="0">
+       <size>
+        <width>20</width>
+        <height>40</height>
+       </size>
+      </property>
+     </spacer>
+    </item>
    </layout>
   </widget>
  </widget>
index 59dcb8ff48287a26fb4720b2fe67d9a562e550ec..99e361ea47c6b7fb59d37441ddcd484fcd0a3f16 100644 (file)
@@ -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;
 }
 
index 9adcae968d9c0faf26f729df98b67a7c28f1836a..6b53da5474829d2a8be41b042b058d84df32aff4 100644 (file)
@@ -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