diff options
author | Eike Ziller <eike.ziller@qt.io> | 2022-09-02 15:31:21 +0200 |
---|---|---|
committer | Eike Ziller <eike.ziller@qt.io> | 2022-09-07 06:40:08 +0000 |
commit | a6176e293b1c267f21d8a5f4f256b9180d3530a6 (patch) | |
tree | b46d6da83308f5089400b91a45184eb34dfeac93 | |
parent | dbfdd334b55bc6e9d754ae070bc5005268409ad5 (diff) | |
download | qt-creator-a6176e293b1c267f21d8a5f4f256b9180d3530a6.tar.gz |
Find: Copy search string from find tool bar to advanced search
Always when pressing the "Advanced..." button it makes sense to copy the search
term to the advanced search dialog.
Otherwise if advanced search is triggered while the focus is in the find tool bar.
Fixes: QTCREATORBUG-17964
Change-Id: I96106e769238a689ed6c55fae6de451d250aa44d
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
-rw-r--r-- | src/plugins/coreplugin/find/findplugin.cpp | 17 | ||||
-rw-r--r-- | src/plugins/coreplugin/find/findplugin.h | 2 | ||||
-rw-r--r-- | src/plugins/coreplugin/find/findtoolbar.cpp | 10 | ||||
-rw-r--r-- | src/plugins/coreplugin/find/findtoolbar.h | 3 |
4 files changed, 25 insertions, 7 deletions
diff --git a/src/plugins/coreplugin/find/findplugin.cpp b/src/plugins/coreplugin/find/findplugin.cpp index 19a5a0d2df..254c879dad 100644 --- a/src/plugins/coreplugin/find/findplugin.cpp +++ b/src/plugins/coreplugin/find/findplugin.cpp @@ -239,12 +239,21 @@ bool FindPrivate::isAnyFilterEnabled() const return Utils::anyOf(m_findDialog->findFilters(), &IFindFilter::isEnabled); } -void Find::openFindDialog(IFindFilter *filter) +void Find::openFindDialog(IFindFilter *filter, const QString &findString) { d->m_currentDocumentFind->acceptCandidate(); - const QString currentFindString = - d->m_currentDocumentFind->isEnabled() ? - d->m_currentDocumentFind->currentFindString() : QString(); + const QString currentFindString = [findString] { + if (!findString.isEmpty()) + return findString; + if (d->m_findToolBar->isVisible() + && QApplication::focusWidget() == d->m_findToolBar->focusWidget() + && !d->m_findToolBar->getFindText().isEmpty()) { + return d->m_findToolBar->getFindText(); + } + if (d->m_currentDocumentFind->isEnabled()) + return d->m_currentDocumentFind->currentFindString(); + return QString(); + }(); if (!currentFindString.isEmpty()) d->m_findDialog->setFindText(currentFindString); d->m_findDialog->setCurrentFilter(filter); diff --git a/src/plugins/coreplugin/find/findplugin.h b/src/plugins/coreplugin/find/findplugin.h index 72d5a76d75..a7efc60aa6 100644 --- a/src/plugins/coreplugin/find/findplugin.h +++ b/src/plugins/coreplugin/find/findplugin.h @@ -38,7 +38,7 @@ public: static QStringListModel *replaceCompletionModel(); static void setUseFakeVim(bool on); static void openFindToolBar(FindDirection direction); - static void openFindDialog(IFindFilter *filter); + static void openFindDialog(IFindFilter *filter, const QString &findString = {}); static void setCaseSensitive(bool sensitive); static void setWholeWord(bool wholeOnly); diff --git a/src/plugins/coreplugin/find/findtoolbar.cpp b/src/plugins/coreplugin/find/findtoolbar.cpp index 0c59847ea1..4a093bc8d4 100644 --- a/src/plugins/coreplugin/find/findtoolbar.cpp +++ b/src/plugins/coreplugin/find/findtoolbar.cpp @@ -132,7 +132,15 @@ FindToolBar::FindToolBar(CurrentDocumentFind *currentDocumentFind) ActionContainer *mfind = ActionManager::actionContainer(Constants::M_FIND); Command *cmd; - m_ui.advancedButton->setDefaultAction(ActionManager::command(Constants::ADVANCED_FIND)->action()); + auto advancedAction = new QAction(Find::tr("Open Advanced Find..."), this); + advancedAction->setIconText(Find::tr("Advanced...")); + Command *advancedCmd = ActionManager::command(Constants::ADVANCED_FIND); + if (advancedCmd) + advancedCmd->augmentActionWithShortcutToolTip(advancedAction); + m_ui.advancedButton->setDefaultAction(advancedAction); + connect(advancedAction, &QAction::triggered, this, [this] { + Find::openFindDialog(nullptr, m_ui.findEdit->text()); + }); m_goToCurrentFindAction = new QAction(this); ActionManager::registerAction(m_goToCurrentFindAction, Constants::S_RETURNTOEDITOR, diff --git a/src/plugins/coreplugin/find/findtoolbar.h b/src/plugins/coreplugin/find/findtoolbar.h index 28fbba15c6..ac75d30b2e 100644 --- a/src/plugins/coreplugin/find/findtoolbar.h +++ b/src/plugins/coreplugin/find/findtoolbar.h @@ -42,6 +42,8 @@ public: void setLightColoredIcon(bool lightColored); + QString getFindText(); + public slots: void setBackward(bool backward); @@ -112,7 +114,6 @@ private: bool eventFilter(QObject *obj, QEvent *event) override; void setFindText(const QString &text); - QString getFindText(); QString getReplaceText(); void selectFindText(); void updateIcons(); |