Add GUI for search-ignore

This commit is contained in:
Juergen Spitzmueller 2022-04-30 14:23:54 +02:00
parent cbe2f61396
commit c0a3d654ff
3 changed files with 213 additions and 34 deletions

View 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);

View 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();
};

View 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">
@ -263,7 +263,7 @@
<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">
@ -365,32 +365,6 @@
<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">
<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>
</property>
<property name="text">
<string>I&amp;gnore format</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QCheckBox" name="expandMacrosCB">
<property name="enabled">
<bool>false</bool>
@ -401,6 +375,16 @@
</widget>
</item>
<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>Search on&amp;ly in maths</string>
</property>
</widget>
</item>
<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>
@ -423,8 +407,127 @@
</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">