[LyX/master] GuiSearch: separate findClicked() slot from more general function

Juergen Spitzmueller spitz at lyx.org
Wed Feb 17 13:45:46 UTC 2021


commit ca160da07dfd048fe1bb203375a47237ac1ea372
Author: Juergen Spitzmueller <spitz at lyx.org>
Date:   Wed Feb 17 14:48:31 2021 +0100

    GuiSearch: separate findClicked() slot from more general function
    
    the latter one is also accessed by different paths than clicking
---
 src/frontends/qt/GuiSearch.cpp |   60 ++++++++++++++++++++++++---------------
 src/frontends/qt/GuiSearch.h   |   10 ++++--
 2 files changed, 44 insertions(+), 26 deletions(-)

diff --git a/src/frontends/qt/GuiSearch.cpp b/src/frontends/qt/GuiSearch.cpp
index fcb8c85..a9b93d8 100644
--- a/src/frontends/qt/GuiSearch.cpp
+++ b/src/frontends/qt/GuiSearch.cpp
@@ -106,7 +106,7 @@ void GuiSearchWidget::keyPressEvent(QKeyEvent * ev)
 
 	// catch Return and Shift-Return
 	if (ev->key() == Qt::Key_Return || ev->key() == Qt::Key_Enter) {
-		findClicked(ev->modifiers() == Qt::ShiftModifier);
+		doFind(ev->modifiers() == Qt::ShiftModifier);
 		return;
 	}
 	if (ev->key() == Qt::Key_Escape) {
@@ -119,12 +119,13 @@ void GuiSearchWidget::keyPressEvent(QKeyEvent * ev)
 		KeyModifier mod = lyx::q_key_state(ev->modifiers());
 		KeySequence keyseq(&theTopLevelKeymap(), &theTopLevelKeymap());
 		FuncRequest fr = keyseq.addkey(sym, mod);
-		if (fr == FuncRequest(LFUN_WORD_FIND_FORWARD) || fr == FuncRequest(LFUN_WORD_FIND)) {
-			findClicked();
+		if (fr == FuncRequest(LFUN_WORD_FIND_FORWARD)
+		    || fr == FuncRequest(LFUN_WORD_FIND)) {
+			doFind();
 			return;
 		}
 		if (fr == FuncRequest(LFUN_WORD_FIND_BACKWARD)) {
-			findClicked(true);
+			doFind(true);
 			return;
 		}
 		if (fr == FuncRequest(LFUN_DIALOG_TOGGLE, "findreplace")) {
@@ -193,41 +194,31 @@ void GuiSearchWidget::findChanged()
 	replacePrevPB->setEnabled(replace);
 	replaceallPB->setEnabled(replace);
 	if (instantSearchCB->isChecked() && !emptytext)
-		findClicked(false, true);
+		doFind(false, true);
 }
 
 
-void GuiSearchWidget::findClicked(bool const backwards, bool const instant)
+void GuiSearchWidget::findClicked()
 {
-	docstring const needle = qstring_to_ucs4(findCO->currentText());
-	find(needle, caseCB->isChecked(), wordsCB->isChecked(), !backwards,
-	     instant, wrapCB->isChecked(), selectionCB->isChecked());
-	uniqueInsert(findCO, findCO->currentText());
-	if (!instant)
-		findCO->lineEdit()->selectAll();
+	doFind();
 }
 
 
 void GuiSearchWidget::findPrevClicked()
 {
-	findClicked(true);
+	doFind(true);
 }
 
 
-void GuiSearchWidget::replaceClicked(bool const backwards)
+void GuiSearchWidget::replaceClicked()
 {
-	docstring const needle = qstring_to_ucs4(findCO->currentText());
-	docstring const repl = qstring_to_ucs4(replaceCO->currentText());
-	replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
-		!backwards, false, wrapCB->isChecked(), selectionCB->isChecked());
-	uniqueInsert(findCO, findCO->currentText());
-	uniqueInsert(replaceCO, replaceCO->currentText());
+	doReplace();
 }
 
 
 void GuiSearchWidget::replacePrevClicked()
 {
-	replaceClicked(true);
+	doReplace(true);
 }
 
 
@@ -242,9 +233,20 @@ void GuiSearchWidget::replaceallClicked()
 }
 
 
+void GuiSearchWidget::doFind(bool const backwards, bool const instant)
+{
+	docstring const needle = qstring_to_ucs4(findCO->currentText());
+	find(needle, caseCB->isChecked(), wordsCB->isChecked(), !backwards,
+	     instant, wrapCB->isChecked(), selectionCB->isChecked());
+	uniqueInsert(findCO, findCO->currentText());
+	if (!instant)
+		findCO->lineEdit()->selectAll();
+}
+
+
 void GuiSearchWidget::find(docstring const & search, bool casesensitive,
-			 bool matchword, bool forward, bool instant,
-			 bool wrap, bool onlysel)
+			   bool matchword, bool forward, bool instant,
+			   bool wrap, bool onlysel)
 {
 	docstring const sdata =
 		find2string(search, casesensitive, matchword,
@@ -254,6 +256,17 @@ void GuiSearchWidget::find(docstring const & search, bool casesensitive,
 }
 
 
+void GuiSearchWidget::doReplace(bool const backwards)
+{
+	docstring const needle = qstring_to_ucs4(findCO->currentText());
+	docstring const repl = qstring_to_ucs4(replaceCO->currentText());
+	replace(needle, repl, caseCB->isChecked(), wordsCB->isChecked(),
+		!backwards, false, wrapCB->isChecked(), selectionCB->isChecked());
+	uniqueInsert(findCO, findCO->currentText());
+	uniqueInsert(replaceCO, replaceCO->currentText());
+}
+
+
 void GuiSearchWidget::replace(docstring const & search, docstring const & replace,
 			    bool casesensitive, bool matchword,
 			    bool forward, bool all, bool wrap, bool onlysel)
@@ -261,6 +274,7 @@ void GuiSearchWidget::replace(docstring const & search, docstring const & replac
 	docstring const sdata =
 		replace2string(replace, search, casesensitive,
 			       matchword, all, forward, true, wrap, onlysel);
+
 	dispatch(FuncRequest(LFUN_WORD_REPLACE, sdata));
 }
 
diff --git a/src/frontends/qt/GuiSearch.h b/src/frontends/qt/GuiSearch.h
index 6e05f49..440e277 100644
--- a/src/frontends/qt/GuiSearch.h
+++ b/src/frontends/qt/GuiSearch.h
@@ -45,10 +45,9 @@ public:
 private Q_SLOTS:
 	void findChanged();
 	void findBufferChanged();
-	void findClicked(bool const backwards = false,
-			 bool const instant = false);
+	void findClicked();
 	void findPrevClicked();
-	void replaceClicked(bool const backwards = false);
+	void replaceClicked();
 	void replacePrevClicked();
 	void replaceallClicked();
 	void minimizeClicked(bool const toggle = true);
@@ -61,6 +60,11 @@ private:
 	void keyPressEvent(QKeyEvent * e) override;
 	///
 	void showEvent(QShowEvent * e) override;
+	///
+	void doFind(bool const backwards = false,
+		    bool const instant = false);
+	///
+	void doReplace(bool const backwards = false);
 	/// Searches occurrence of string
 	void find(docstring const & search,
 		  bool casesensitive, bool matchword,


More information about the lyx-cvs mailing list