]> git.lyx.org Git - lyx.git/blobdiff - src/frontends/qt/FindAndReplace.cpp
Add GUI for search-ignore
[lyx.git] / src / frontends / qt / FindAndReplace.cpp
index 300c291da37c6fdcbab66565c79ad814d0965828..d72fa9265a4d1c7032a785acbbb8877df91bba24 100644 (file)
@@ -115,9 +115,9 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
        case Qt::Key_Tab:
                if (e->modifiers() == Qt::NoModifier) {
                        if (obj == find_work_area_){
-                               LYXERR(Debug::FIND, "Focusing replace WA");
+                               LYXERR(Debug::FINDVERBOSE, "Focusing replace WA");
                                replace_work_area_->setFocus();
-                               LYXERR(Debug::FIND, "Selecting entire replace buffer");
+                               LYXERR(Debug::FINDVERBOSE, "Selecting entire replace buffer");
                                dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
                                dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
                                return true;
@@ -127,9 +127,9 @@ bool FindAndReplaceWidget::eventFilter(QObject * obj, QEvent * event)
 
        case Qt::Key_Backtab:
                if (obj == replace_work_area_) {
-                       LYXERR(Debug::FIND, "Focusing find WA");
+                       LYXERR(Debug::FINDVERBOSE, "Focusing find WA");
                        find_work_area_->setFocus();
-                       LYXERR(Debug::FIND, "Selecting entire find buffer");
+                       LYXERR(Debug::FINDVERBOSE, "Selecting entire find buffer");
                        dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
                        dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
                        return true;
@@ -172,7 +172,7 @@ static vector<string> const & allManualsFiles()
 static bool nextDocumentBuffer(Buffer * & buf)
 {
        ListOfBuffers const children = buf->allRelatives();
-       LYXERR(Debug::FIND, "children.size()=" << children.size());
+       LYXERR(Debug::FINDVERBOSE, "children.size()=" << children.size());
        ListOfBuffers::const_iterator it =
                find(children.begin(), children.end(), buf);
        LASSERT(it != children.end(), return false);
@@ -193,7 +193,7 @@ static bool nextDocumentBuffer(Buffer * & buf)
 static bool prevDocumentBuffer(Buffer * & buf)
 {
        ListOfBuffers const children = buf->allRelatives();
-       LYXERR(Debug::FIND, "children.size()=" << children.size());
+       LYXERR(Debug::FINDVERBOSE, "children.size()=" << children.size());
        ListOfBuffers::const_iterator it =
                find(children.begin(), children.end(), buf);
        LASSERT(it != children.end(), return false)
@@ -344,9 +344,9 @@ bool FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt, bool
        UndoGroupHelper helper(buf);
 
        do {
-               LYXERR(Debug::FIND, "Dispatching LFUN_WORD_FINDADV");
+               LYXERR(Debug::FINDVERBOSE, "Dispatching LFUN_WORD_FINDADV");
                dispatch(cmd);
-               LYXERR(Debug::FIND, "dispatched");
+               LYXERR(Debug::FINDVERBOSE, "dispatched");
                if (bv->cursor().result().dispatched()) {
                        // New match found and selected (old selection replaced if needed)
                        if (replace_all)
@@ -398,7 +398,7 @@ bool FindAndReplaceWidget::findAndReplaceScope(FindAndReplaceOptions & opt, bool
                        //lyx::dispatch(FuncRequest(LFUN_BUFFER_END));
                        bv->cursor().setCursor(doc_iterator_end(buf));
                        bv->cursor().backwardPos();
-                       LYXERR(Debug::FIND, "findBackAdv5: cur: "
+                       LYXERR(Debug::FINDVERBOSE, "findBackAdv5: cur: "
                                << bv->cursor());
                }
                bv->clearSelection();
@@ -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();
@@ -454,25 +454,65 @@ bool FindAndReplaceWidget::findAndReplace(
                        ? FindAndReplaceOptions::R_ONLY_MATHS
                        : FindAndReplaceOptions::R_EVERYTHING;
 
-       LYXERR(Debug::FIND, "FindAndReplaceOptions: "
+       LYXERR(Debug::FINDVERBOSE, "FindAndReplaceOptions: "
               << "find_buf_name=" << find_buf_name
               << ", casesensitiv=" << casesensitive
               << ", 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();
@@ -556,7 +624,7 @@ void FindAndReplaceWidget::showEvent(QShowEvent * /* ev */)
        replace_work_area_->installEventFilter(this);
 
        view_.setCurrentWorkArea(find_work_area_);
-       LYXERR(Debug::FIND, "Selecting entire find buffer");
+       LYXERR(Debug::FINDVERBOSE, "Selecting entire find buffer");
        dispatch(FuncRequest(LFUN_BUFFER_BEGIN));
        dispatch(FuncRequest(LFUN_BUFFER_END_SELECT));
 }
@@ -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);