work save: find next & find previous done

This commit is contained in:
royqh1979@gmail.com 2021-08-04 00:17:38 +08:00
parent f93b23f451
commit 590c7adc6e
4 changed files with 69 additions and 6 deletions

View File

@ -1531,10 +1531,24 @@ void MainWindow::on_actionReplace_triggered()
void MainWindow::on_actionFind_Next_triggered()
{
Editor *e = mEditorList->getEditor();
if (e==nullptr)
return;
if (mSearchDialog==nullptr)
return;
mSearchDialog->findNext();
}
void MainWindow::on_actionFind_Previous_triggered()
{
Editor *e = mEditorList->getEditor();
if (e==nullptr)
return;
if (mSearchDialog==nullptr)
return;
mSearchDialog->findPrevious();
}

View File

@ -1287,11 +1287,17 @@
<property name="text">
<string>Find Next</string>
</property>
<property name="shortcut">
<string>F3</string>
</property>
</action>
<action name="actionFind_Previous">
<property name="text">
<string>Find Previous</string>
</property>
<property name="shortcut">
<string>Ctrl+F3</string>
</property>
</action>
</widget>
<customwidgets>

View File

@ -40,6 +40,20 @@ void SearchDialog::find(const QString &text)
show();
}
void SearchDialog::findNext()
{
if (mTabBar->currentIndex()==0) { // it's a find action
// Disable entire scope searching
ui->rbEntireScope->setChecked(false);
// Always search forwards
ui->rbForward->setChecked(true);
ui->btnExecute->click();
}
}
void SearchDialog::findInFiles(const QString &text)
{
mTabBar->setCurrentIndex(1);
@ -74,9 +88,15 @@ void SearchDialog::onTabChanged()
ui->cbReplace->setVisible(isreplace || isreplacefiles);
ui->grpOrigin->setVisible(isfind || isreplace);
ui->grpOrigin->setEnabled(isfind || isreplace);
ui->grpScope->setVisible(isfind || isreplace);
ui->grpScope->setEnabled(isreplace);
ui->grpWhere->setVisible(isfindfiles || isreplacefiles);
ui->grpWhere->setEnabled(isfindfiles || isreplacefiles);
ui->grpDirection->setVisible(isfind || isreplace);
ui->grpDirection->setEnabled(isfind || isreplace);
// grpOption is always visible
// Disable project search option when none is open
@ -144,22 +164,22 @@ void SearchDialog::on_btnExecute_clicked()
mSearchOptions.setFlag(ssoPrompt);
}
// Apply scope, when visible
if (ui->grpScope->isVisible()) {
// Apply scope, when enabled
if (ui->grpScope->isEnabled()) {
if (ui->rbSelection->isChecked()) {
mSearchOptions.setFlag(ssoSelectedOnly);
}
}
// Apply direction, when visible
if (ui->grpDirection->isVisible()) {
// Apply direction, when enabled
if (ui->grpDirection->isEnabled()) {
if (ui->rbBackward->isChecked()) {
mSearchOptions.setFlag(ssoBackwards);
}
}
// Apply origin, when visible
if (ui->grpOrigin->isVisible()) {
// Apply origin, when enabled
if (ui->grpOrigin->isEnabled()) {
if (ui->rbEntireScope->isChecked()) {
mSearchOptions.setFlag(ssoEntireScope);
}
@ -389,7 +409,26 @@ int SearchDialog::execute(Editor *editor, SearchDialog::SearchAction actionType)
// editor.SearchEngine := enginebackup;
}
QTabBar *SearchDialog::tabBar() const
{
return mTabBar;
}
PSynSearchBase SearchDialog::searchEngine() const
{
return mSearchEngine;
}
void SearchDialog::findPrevious()
{
if (mTabBar->currentIndex()==0) { // it's a find action
// Disable entire scope searching
ui->rbEntireScope->setChecked(false);
// Always search backward
ui->rbBackward->setChecked(true);
ui->btnExecute->click();
}
}

View File

@ -25,11 +25,15 @@ public:
explicit SearchDialog(QWidget *parent = nullptr);
~SearchDialog();
void find(const QString& text);
void findNext();
void findPrevious();
void findInFiles(const QString& text);
void replace(const QString& sFind, const QString& sReplace);
void replaceInFiles(const QString& sFind, const QString& sReplace);
PSynSearchBase searchEngine() const;
QTabBar *tabBar() const;
private slots:
void onTabChanged();
void on_cbFind_currentTextChanged(const QString &arg1);