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 <aha_1980@gmx.de>
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
Reviewed-by: Yuchen Deng <loaden@gmail.com>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@nokia.com>
This commit is contained in:
Francois Ferrand
2010-06-24 17:51:39 +02:00
committed by Eike Ziller
parent d1eefacd55
commit 3f4a9548be
4 changed files with 49 additions and 8 deletions

View File

@@ -417,6 +417,12 @@
\row \row
\o Find previous \o Find previous
\o Shift+F3 \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 \row
\o Replace next \o Replace next
\o Ctrl+= \o Ctrl+=

View File

@@ -183,6 +183,18 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious())); connect(m_findPreviousAction, SIGNAL(triggered()), this, SLOT(invokeFindPrevious()));
m_ui.findPreviousButton->setDefaultAction(cmd->action()); 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); m_replaceAction = new QAction(tr("Replace"), this);
cmd = am->registerAction(m_replaceAction, Constants::REPLACE, globalcontext); cmd = am->registerAction(m_replaceAction, Constants::REPLACE, globalcontext);
cmd->setDefaultKeySequence(QKeySequence()); cmd->setDefaultKeySequence(QKeySequence());
@@ -327,7 +339,10 @@ void FindToolBar::adaptToCandidate()
void FindToolBar::updateFindAction() 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() void FindToolBar::updateToolBar()
@@ -605,13 +620,13 @@ Core::FindToolBarPlaceHolder *FindToolBar::findToolBarPlaceHolder() const
return 0; return 0;
} }
void FindToolBar::openFind() void FindToolBar::openFind(bool focus)
{ {
setBackward(false); setBackward(false);
openFindToolBar(); openFindToolBar(focus);
} }
void FindToolBar::openFindToolBar() void FindToolBar::openFindToolBar(bool focus)
{ {
installEventFilters(); installEventFilters();
if (!m_currentDocumentFind->candidateIsEnabled()) if (!m_currentDocumentFind->candidateIsEnabled())
@@ -627,13 +642,27 @@ void FindToolBar::openFindToolBar()
holder->setWidget(this); holder->setWidget(this);
holder->setVisible(true); holder->setVisible(true);
setVisible(true); setVisible(true);
setFocus(); if (focus)
setFocus();
QString text = m_currentDocumentFind->currentFindString(); QString text = m_currentDocumentFind->currentFindString();
if (!text.isEmpty()) if (!text.isEmpty())
setFindText(text); setFindText(text);
m_currentDocumentFind->defineFindScope(); m_currentDocumentFind->defineFindScope();
m_currentDocumentFind->highlightAll(getFindText(), effectiveFindFlags()); 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) bool FindToolBar::focusNextPrevChild(bool next)

View File

@@ -60,7 +60,7 @@ public:
void readSettings(); void readSettings();
void writeSettings(); void writeSettings();
void openFindToolBar(); void openFindToolBar(bool focus = true);
void setUseFakeVim(bool on); void setUseFakeVim(bool on);
public slots: public slots:
@@ -84,7 +84,9 @@ private slots:
void updateFromFindClipboard(); void updateFromFindClipboard();
void hideAndResetFocus(); void hideAndResetFocus();
void openFind(); void openFind(bool focus = true);
void findNextSelected();
void findPreviousSelected();
void updateFindAction(); void updateFindAction();
void updateToolBar(); void updateToolBar();
void findFlagsChanged(); void findFlagsChanged();
@@ -121,6 +123,8 @@ private:
QCompleter *m_findCompleter; QCompleter *m_findCompleter;
QCompleter *m_replaceCompleter; QCompleter *m_replaceCompleter;
QAction *m_findInDocumentAction; QAction *m_findInDocumentAction;
QAction *m_findNextSelectedAction;
QAction *m_findPreviousSelectedAction;
QAction *m_enterFindStringAction; QAction *m_enterFindStringAction;
QAction *m_findNextAction; QAction *m_findNextAction;
QAction *m_findPreviousAction; QAction *m_findPreviousAction;

View File

@@ -51,6 +51,8 @@ const char G_FIND_ACTIONS[] = "Find.FindMenu.Actions";
const char ADVANCED_FIND[] = "Find.Dialog"; const char ADVANCED_FIND[] = "Find.Dialog";
const char FIND_IN_DOCUMENT[] = "Find.FindInCurrentDocument"; 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_NEXT[] = "Find.FindNext";
const char FIND_PREVIOUS[] = "Find.FindPrevious"; const char FIND_PREVIOUS[] = "Find.FindPrevious";
const char REPLACE[] = "Find.Replace"; const char REPLACE[] = "Find.Replace";