From c0a3d654ff1b5bfadb4195015fc82a7fefe000eb Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 30 Apr 2022 14:23:54 +0200 Subject: [PATCH] Add GUI for search-ignore --- src/frontends/qt/FindAndReplace.cpp | 81 +++++++++++- src/frontends/qt/FindAndReplace.h | 7 ++ src/frontends/qt/ui/FindAndReplaceUi.ui | 157 ++++++++++++++++++++---- 3 files changed, 212 insertions(+), 33 deletions(-) diff --git a/src/frontends/qt/FindAndReplace.cpp b/src/frontends/qt/FindAndReplace.cpp index ab61e1ab73..d72fa9265a 100644 --- a/src/frontends/qt/FindAndReplace.cpp +++ b/src/frontends/qt/FindAndReplace.cpp @@ -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); diff --git a/src/frontends/qt/FindAndReplace.h b/src/frontends/qt/FindAndReplace.h index 0ffc39d458..7ea70a97ed 100644 --- a/src/frontends/qt/FindAndReplace.h +++ b/src/frontends/qt/FindAndReplace.h @@ -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 @@ -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(); }; diff --git a/src/frontends/qt/ui/FindAndReplaceUi.ui b/src/frontends/qt/ui/FindAndReplaceUi.ui index 58a16eb245..6713723e9e 100644 --- a/src/frontends/qt/ui/FindAndReplaceUi.ui +++ b/src/frontends/qt/ui/FindAndReplaceUi.ui @@ -7,7 +7,7 @@ 0 0 374 - 380 + 664 @@ -263,7 +263,7 @@ Settin&gs - + @@ -365,42 +365,26 @@ QLayout::SetMinimumSize - - - Restrict search to math environments only - - - Search on&ly in maths - - - - - + - true - - - If unchecked, the search will be limited to occurrences of the selected text and paragraph style + false - I&gnore format - - - true + E&xpand macros - - - - false + + + + Restrict search to math environments only - E&xpand macros + Search on&ly in maths - + Keep the case of the replacement's first letter as in each matching text first letter @@ -423,8 +407,127 @@ + + + + Do not search in content that is not output (e.g., notes) + + + Ignore &non-output content + + + + + + + If the search string is formatted in a non-default way, only find strings formatted like the search string in the checked respects + + + Ad&here to search string formatting of + + + true + + + false + + + + + + Strike-through + + + + + + + Font series + + + + + + + Font color + + + + + + + Emph/noun + + + + + + + Deselect all + + + + + + + Font family + + + + + + + Language + + + + + + + Sectioning markup + + + + + + + Deletion (change) + + + + + + + Underlining + + + + + + + Font shape + + + + + + + Select all + + + + + + + Font size + + + + + + -- 2.39.2