diff options
| author | Francois Ferrand <[email protected]> | 2010-06-24 17:51:39 +0200 |
|---|---|---|
| committer | Eike Ziller <[email protected]> | 2012-04-23 10:26:55 +0200 |
| commit | 3f4a9548be70906b2cc0acf71e9d5eadf78f7a8b (patch) | |
| tree | cd528defb56f25515a0861818ad49c7f24b9fd35 | |
| parent | d1eefacd5556b256503cae1eec14b313925f3970 (diff) | |
Editor: implement find next/previous selected text.
Add actions to search next/previous occurence of the selected text/text
under the cursor, like in Visual Studio (ctrl+F3 and ctrl+shift+F3).
Task-number: QTCREATORBUG-464
Change-Id: I0bf44e386b91fce4b26c6e3864e6df484f2e3556
Reviewed-by: Andre Hartmann <[email protected]>
Reviewed-by: Leandro Melo <[email protected]>
Reviewed-by: Yuchen Deng <[email protected]>
Reviewed-by: Orgad Shaneh <[email protected]>
Reviewed-by: Eike Ziller <[email protected]>
| -rw-r--r-- | doc/src/howto/creator-keyboard-shortcuts.qdoc | 6 | ||||
| -rw-r--r-- | src/plugins/find/findtoolbar.cpp | 41 | ||||
| -rw-r--r-- | src/plugins/find/findtoolbar.h | 8 | ||||
| -rw-r--r-- | src/plugins/find/textfindconstants.h | 2 |
4 files changed, 49 insertions, 8 deletions
diff --git a/doc/src/howto/creator-keyboard-shortcuts.qdoc b/doc/src/howto/creator-keyboard-shortcuts.qdoc index d2ca4715a74..08d133f2657 100644 --- a/doc/src/howto/creator-keyboard-shortcuts.qdoc +++ b/doc/src/howto/creator-keyboard-shortcuts.qdoc @@ -418,6 +418,12 @@ \o Find previous \o Shift+F3 \row + \o Find next occurence of selected text + \o Ctrl+F3 + \row + \o Find previous occurence of selected text + \o Ctrl+Shift+F3 + \row \o Replace next \o Ctrl+= \row diff --git a/src/plugins/find/findtoolbar.cpp b/src/plugins/find/findtoolbar.cpp index 1a7f8eefeb5..9b1017f1f3e 100644 --- a/src/plugins/find/findtoolbar.cpp +++ b/src/plugins/find/findtoolbar.cpp @@ -183,6 +183,18 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); m_ui.findPreviousButton->setDefaultAction(cmd->action()); + m_findNextSelectedAction = new QAction(tr("Find Next (Selected)"), this); + cmd = am->registerAction(m_findNextSelectedAction, Constants::FIND_NEXT_SELECTED, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+F3"))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findNextSelectedAction, SIGNAL(triggered()), this, SLOT(findNextSelected())); + + m_findPreviousSelectedAction = new QAction(tr("Find Previous (Selected)"), this); + cmd = am->registerAction(m_findPreviousSelectedAction, Constants::FIND_PREV_SELECTED, globalcontext); + cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+F3"))); + mfind->addAction(cmd, Constants::G_FIND_ACTIONS); + connect(m_findPreviousSelectedAction, SIGNAL(triggered()), this, SLOT(findPreviousSelected())); + m_replaceAction = new QAction(tr("Replace"), this); cmd = am->registerAction(m_replaceAction, Constants::REPLACE, globalcontext); cmd->setDefaultKeySequence(QKeySequence()); @@ -327,7 +339,10 @@ void FindToolBar::adaptToCandidate() void FindToolBar::updateFindAction() { - m_findInDocumentAction->setEnabled(m_currentDocumentFind->candidateIsEnabled()); + bool enabled = m_currentDocumentFind->candidateIsEnabled(); + m_findInDocumentAction->setEnabled(enabled); + m_findNextSelectedAction->setEnabled(enabled); + m_findPreviousSelectedAction->setEnabled(enabled); } void FindToolBar::updateToolBar() @@ -605,13 +620,13 @@ Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const return 0; } -void FindToolBar::openFind() +void FindToolBar::openFind(bool focus) { setBackward(false); - openFindToolBar(); + openFindToolBar(focus); } -void FindToolBar::openFindToolBar() +void FindToolBar::openFindToolBar(bool focus) { installEventFilters(); if (!m_currentDocumentFind->candidateIsEnabled()) @@ -627,13 +642,27 @@ void FindToolBar::openFindToolBar() holder->setWidget(this); holder->setVisible(true); setVisible(true); - setFocus(); + if (focus) + setFocus(); QString text = m_currentDocumentFind->currentFindString(); if (!text.isEmpty()) setFindText(text); m_currentDocumentFind->defineFindScope(); m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); - selectFindText(); + if (focus) + selectFindText(); +} + +void FindToolBar::findNextSelected() +{ + openFind(false); + invokeFindNext(); +} + +void FindToolBar::findPreviousSelected() +{ + openFind(false); + invokeFindPrevious(); } bool FindToolBar::focusNextPrevChild(bool next) diff --git a/src/plugins/find/findtoolbar.h b/src/plugins/find/findtoolbar.h index aa4f07e5b68..0fa68aea0b9 100644 --- a/src/plugins/find/findtoolbar.h +++ b/src/plugins/find/findtoolbar.h @@ -60,7 +60,7 @@ public: void readSettings(); void writeSettings(); - void openFindToolBar(); + void openFindToolBar(bool focus = true); void setUseFakeVim(bool on); public slots: @@ -84,7 +84,9 @@ private slots: void updateFromFindClipboard(); void hideAndResetFocus(); - void openFind(); + void openFind(bool focus = true); + void findNextSelected(); + void findPreviousSelected(); void updateFindAction(); void updateToolBar(); void findFlagsChanged(); @@ -121,6 +123,8 @@ private: QCompleter *m_findCompleter; QCompleter *m_replaceCompleter; QAction *m_findInDocumentAction; + QAction *m_findNextSelectedAction; + QAction *m_findPreviousSelectedAction; QAction *m_enterFindStringAction; QAction *m_findNextAction; QAction *m_findPreviousAction; diff --git a/src/plugins/find/textfindconstants.h b/src/plugins/find/textfindconstants.h index ab9f0bc92df..d470e111723 100644 --- a/src/plugins/find/textfindconstants.h +++ b/src/plugins/find/textfindconstants.h @@ -51,6 +51,8 @@ const char G_FIND_ACTIONS[] = "Find.FindMenu.Actions"; const char ADVANCED_FIND[] = "Find.Dialog"; const char FIND_IN_DOCUMENT[] = "Find.FindInCurrentDocument"; +const char FIND_NEXT_SELECTED[]= "Find.FindNextSelected"; +const char FIND_PREV_SELECTED[]= "Find.FindPreviousSelected"; const char FIND_NEXT[] = "Find.FindNext"; const char FIND_PREVIOUS[] = "Find.FindPrevious"; const char REPLACE[] = "Find.Replace"; |
