]> git.lyx.org Git - lyx.git/commitdiff
Add GUI for search-ignore
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Apr 2022 12:23:54 +0000 (14:23 +0200)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 30 Apr 2022 12:23:54 +0000 (14:23 +0200)
src/frontends/qt/FindAndReplace.cpp
src/frontends/qt/FindAndReplace.h
src/frontends/qt/ui/FindAndReplaceUi.ui

index ab61e1ab7347c325b1f0cc2e2cd853b1d2c80698..d72fa9265a4d1c7032a785acbbb8877df91bba24 100644 (file)
@@ -421,7 +421,7 @@ bool FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt, bool
 /// Return true if a match was found
 bool FindAndReplaceWidget::findAndReplace(
        bool casesensitive, bool matchword, bool backwards,
-       bool expandmacros, bool ignoreformat, bool replace,
+       bool expandmacros, bool adhereformat, bool replace,
        bool keep_case, bool replace_all)
 {
        Buffer & find_buf = find_work_area_->bufferView().buffer();
@@ -460,19 +460,59 @@ bool FindAndReplaceWidget::findAndReplace(
               << ", matchword=" << matchword
               << ", backwards=" << backwards
               << ", expandmacros=" << expandmacros
-              << ", ignoreformat=" << ignoreformat
+              << ", adhereformat=" << adhereformat
               << ", repl_buf_name" << repl_buf_name
               << ", keep_case=" << keep_case
               << ", scope=" << scope
               << ", restr=" << restr);
 
        FindAndReplaceOptions opt(find_buf_name, casesensitive, matchword,
-                                 !backwards, expandmacros, ignoreformat,
+                                 !backwards, expandmacros, !adhereformat,
                                  repl_buf_name, keep_case, scope, restr);
+       
+       if (adhereformat) {
+               // Formats to adhere
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("language",
+                                         !adhereLanguageCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("color",
+                                         !adhereColorCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("family",
+                                         !adhereFFamilyCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("series",
+                                         !adhereFSeriesCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("shape",
+                                         !adhereFShapeCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("size",
+                                         !adhereFSizeCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("markup",
+                                         !adhereMarkupCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("underline",
+                                         !adhereUnderlineCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("strike",
+                                         !adhereStrikeCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("deleted",
+                                         !adhereDeletedCB->isChecked())));
+               lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("sectioning",
+                                         !adhereSectioningCB->isChecked())));
+       }
+       lyx::dispatch(FuncRequest(LFUN_SEARCH_IGNORE, checkState("non-output-content",
+                                 ignoreNonOutputCB->isChecked())));
+       
        return findAndReplaceScope(opt, replace_all);
 }
 
 
+docstring const FindAndReplaceWidget::checkState(string const s, bool const b)
+{
+       docstring res = from_ascii(s) + from_ascii(" ");
+       if (b)
+               res += from_ascii("true");
+       else
+               res += from_ascii("false");
+       return res;
+}
+
+
 bool FindAndReplaceWidget::findAndReplace(bool backwards, bool replace, bool replace_all)
 {
        if (! view_.currentMainWorkArea()) {
@@ -492,7 +532,7 @@ bool FindAndReplaceWidget::findAndReplace(bool backwards, bool replace, bool rep
                wordsCB->isChecked(),
                backwards,
                expandMacrosCB->isChecked(),
-               ignoreFormatCB->isChecked(),
+               adhereFormatGB->isChecked(),
                replace,
                keepCaseCB->isChecked(),
                replace_all);
@@ -532,6 +572,34 @@ void FindAndReplaceWidget::on_searchbackCB_clicked()
 }
 
 
+void FindAndReplaceWidget::setFormatIgnores(bool const b)
+{
+       adhereLanguageCB->setChecked(b);
+       adhereColorCB->setChecked(b);
+       adhereFFamilyCB->setChecked(b);
+       adhereFSeriesCB->setChecked(b);
+       adhereFShapeCB->setChecked(b);
+       adhereFSizeCB->setChecked(b);
+       adhereMarkupCB->setChecked(b);
+       adhereUnderlineCB->setChecked(b);
+       adhereStrikeCB->setChecked(b);
+       adhereDeletedCB->setChecked(b);
+       adhereSectioningCB->setChecked(b);
+}
+
+
+void FindAndReplaceWidget::on_selectAllPB_clicked()
+{
+       setFormatIgnores(true);
+}
+
+
+void FindAndReplaceWidget::on_deselectAllPB_clicked()
+{
+       setFormatIgnores(false);
+}
+
+
 // Copy selected elements from bv's BufferParams to the dest_bv's
 static void copy_params(BufferView const & bv, BufferView & dest_bv) {
        Buffer const & doc_buf = bv.buffer();
@@ -584,8 +652,9 @@ void FindAndReplace::updateView()
 
 
 FindAndReplace::FindAndReplace(GuiView & parent,
-               Qt::DockWidgetArea area, Qt::WindowFlags flags)
-       : DockView(parent, "findreplaceadv", qt_("Advanced Find and Replace"),
+                              Qt::DockWidgetArea area,
+                              Qt::WindowFlags flags)
+    : DockView(parent, "findreplaceadv", qt_("Advanced Find and Replace"),
                   area, flags)
 {
        widget_ = new FindAndReplaceWidget(parent);
index 0ffc39d45810712dad78fd72cd76794e41d153a4..7ea70a97ed80ea97a9059a443b8be67d6a6f8b8d 100644 (file)
@@ -16,6 +16,7 @@
 // This is needed so that ui_FindAndReplaceUi.h can find qt_()
 #include "qt_helpers.h"
 #include "ui_FindAndReplaceUi.h"
+#include "support/docstring.h"
 
 #include <string>
 
@@ -65,12 +66,18 @@ private:
        void virtual hideEvent(QHideEvent *ev) override;
 
        void hideDialog();
+       
+       void setFormatIgnores(bool const b);
+       
+       docstring const checkState(std::string const s, bool const b);
 
 protected Q_SLOTS:
        void on_findNextPB_clicked();
        void on_replacePB_clicked();
        void on_replaceallPB_clicked();
        void on_searchbackCB_clicked();
+       void on_selectAllPB_clicked();
+       void on_deselectAllPB_clicked();
 };
 
 
index 58a16eb24525bcd67a8bbdbe9cbb1c10b044b62c..6713723e9ec05aa9773a19cc6c6ea294fb74edd3 100644 (file)
@@ -7,7 +7,7 @@
     <x>0</x>
     <y>0</y>
     <width>374</width>
-    <height>380</height>
+    <height>664</height>
    </rect>
   </property>
   <property name="windowTitle">
    <attribute name="title">
     <string>Settin&amp;gs</string>
    </attribute>
-   <layout class="QVBoxLayout" name="dynamicLayoutAdvanced_" stretch="0,0,1">
+   <layout class="QVBoxLayout" name="dynamicLayoutAdvanced_" stretch="0,0,0,1">
     <item>
      <widget class="QGroupBox" name="groupBox_2">
       <property name="enabled">
        <enum>QLayout::SetMinimumSize</enum>
       </property>
       <item row="3" column="0">
-       <widget class="QCheckBox" name="OnlyMaths">
-        <property name="toolTip">
-         <string>Restrict search to math environments only</string>
-        </property>
-        <property name="text">
-         <string>Search on&amp;ly in maths</string>
-        </property>
-       </widget>
-      </item>
-      <item row="1" column="0">
-       <widget class="QCheckBox" name="ignoreFormatCB">
+       <widget class="QCheckBox" name="expandMacrosCB">
         <property name="enabled">
-         <bool>true</bool>
-        </property>
-        <property name="toolTip">
-         <string>If unchecked, the search will be limited to occurrences of the selected text and paragraph style</string>
+         <bool>false</bool>
         </property>
         <property name="text">
-         <string>I&amp;gnore format</string>
-        </property>
-        <property name="checked">
-         <bool>true</bool>
+         <string>E&amp;xpand macros</string>
         </property>
        </widget>
       </item>
-      <item row="4" column="0">
-       <widget class="QCheckBox" name="expandMacrosCB">
-        <property name="enabled">
-         <bool>false</bool>
+      <item row="2" column="0">
+       <widget class="QCheckBox" name="OnlyMaths">
+        <property name="toolTip">
+         <string>Restrict search to math environments only</string>
         </property>
         <property name="text">
-         <string>E&amp;xpand macros</string>
+         <string>Search on&amp;ly in maths</string>
         </property>
        </widget>
       </item>
-      <item row="2" column="0">
+      <item row="1" column="0">
        <widget class="QCheckBox" name="keepCaseCB">
         <property name="toolTip">
          <string>Keep the case of the replacement's first letter as in each matching text first letter</string>
         </property>
        </spacer>
       </item>
+      <item row="4" column="0">
+       <widget class="QCheckBox" name="ignoreNonOutputCB">
+        <property name="toolTip">
+         <string>Do not search in content that is not output (e.g., notes)</string>
+        </property>
+        <property name="text">
+         <string>Ignore &amp;non-output content</string>
+        </property>
+       </widget>
+      </item>
      </layout>
     </item>
+    <item>
+     <widget class="QGroupBox" name="adhereFormatGB">
+      <property name="toolTip">
+       <string>If the search string is formatted in a non-default way, only find strings formatted like the search string in the checked respects</string>
+      </property>
+      <property name="title">
+       <string>Ad&amp;here to search string formatting of</string>
+      </property>
+      <property name="checkable">
+       <bool>true</bool>
+      </property>
+      <property name="checked">
+       <bool>false</bool>
+      </property>
+      <layout class="QGridLayout" name="gridLayout_4">
+       <item row="2" column="1">
+        <widget class="QCheckBox" name="adhereStrikeCB">
+         <property name="text">
+          <string>Strike-through</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="0">
+        <widget class="QCheckBox" name="adhereFSeriesCB">
+         <property name="text">
+          <string>Font series</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="0">
+        <widget class="QCheckBox" name="adhereColorCB">
+         <property name="text">
+          <string>Font color</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="1">
+        <widget class="QCheckBox" name="adhereMarkupCB">
+         <property name="text">
+          <string>Emph/noun</string>
+         </property>
+        </widget>
+       </item>
+       <item row="6" column="1">
+        <widget class="QPushButton" name="deselectAllPB">
+         <property name="text">
+          <string>Deselect all</string>
+         </property>
+        </widget>
+       </item>
+       <item row="2" column="0">
+        <widget class="QCheckBox" name="adhereFFamilyCB">
+         <property name="text">
+          <string>Font family</string>
+         </property>
+        </widget>
+       </item>
+       <item row="0" column="0">
+        <widget class="QCheckBox" name="adhereLanguageCB">
+         <property name="text">
+          <string>Language</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="1">
+        <widget class="QCheckBox" name="adhereSectioningCB">
+         <property name="text">
+          <string>Sectioning markup</string>
+         </property>
+        </widget>
+       </item>
+       <item row="3" column="1">
+        <widget class="QCheckBox" name="adhereDeletedCB">
+         <property name="text">
+          <string>Deletion (change)</string>
+         </property>
+        </widget>
+       </item>
+       <item row="1" column="1">
+        <widget class="QCheckBox" name="adhereUnderlineCB">
+         <property name="text">
+          <string>Underlining</string>
+         </property>
+        </widget>
+       </item>
+       <item row="4" column="0">
+        <widget class="QCheckBox" name="adhereFShapeCB">
+         <property name="text">
+          <string>Font shape</string>
+         </property>
+        </widget>
+       </item>
+       <item row="6" column="0">
+        <widget class="QPushButton" name="selectAllPB">
+         <property name="text">
+          <string>Select all</string>
+         </property>
+        </widget>
+       </item>
+       <item row="5" column="0">
+        <widget class="QCheckBox" name="adhereFSizeCB">
+         <property name="text">
+          <string>Font size</string>
+         </property>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </item>
     <item>
      <spacer name="verticalSpacer_2">
       <property name="orientation">