Fix escape handling in find tool bar.

It was explicitly handling the escape key for "return to current
document find", which is wrong since the shortcut for "return to editor"
(which it replaces) can be changed.
The correct thing is to register an own action for "return to editor"
for the find tool bar, overriding the default behavior.

Change-Id: I77c690fa5921ce4022b8d2b38383668efd717875
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Eike Ziller <eike.ziller@digia.com>
This commit is contained in:
Eike Ziller
2014-03-03 11:55:50 +01:00
parent 23e6a0ac09
commit 9ac55e5b2c
4 changed files with 19 additions and 26 deletions

View File

@@ -129,6 +129,11 @@ void FindPlugin::initialize(const QStringList &, QString *)
d->m_currentDocumentFind = new Internal::CurrentDocumentFind;
d->m_findToolBar = new Internal::FindToolBar(this, d->m_currentDocumentFind);
auto *findToolBarContext = new IContext(this);
findToolBarContext->setWidget(d->m_findToolBar);
findToolBarContext->setContext(Context(Constants::C_FINDTOOLBAR));
ICore::addContextObject(findToolBarContext);
d->m_findDialog = new Internal::FindToolWindow(this);
d->m_searchResultWindow = new SearchResultWindow(d->m_findDialog);
ExtensionSystem::PluginManager::addObject(d->m_searchResultWindow);

View File

@@ -149,6 +149,11 @@ FindToolBar::FindToolBar(FindPlugin *plugin, CurrentDocumentFind *currentDocumen
m_ui.advancedButton->setDefaultAction(Core::ActionManager::command(Constants::ADVANCED_FIND)->action());
m_goToCurrentFindAction = new QAction(tr("Go to Current Document Find"), this);
cmd = Core::ActionManager::registerAction(m_goToCurrentFindAction, Constants::S_RETURNTOEDITOR,
Context(Constants::C_FINDTOOLBAR));
connect(m_goToCurrentFindAction, SIGNAL(triggered()), this, SLOT(setFocusToCurrentFindSupport()));
QIcon icon = QIcon::fromTheme(QLatin1String("edit-find-replace"));
m_findInDocumentAction = new QAction(icon, tr("Find/Replace"), this);
cmd = Core::ActionManager::registerAction(m_findInDocumentAction, Constants::FIND_IN_DOCUMENT, globalcontext);
@@ -277,14 +282,6 @@ void FindToolBar::installEventFilters()
}
}
bool FindToolBar::shouldSetFocusOnKeyEvent(QKeyEvent *event)
{
return event->key() == Qt::Key_Escape && !event->modifiers()
&& !m_findCompleter->popup()->isVisible()
&& !m_replaceCompleter->popup()->isVisible()
&& m_currentDocumentFind->isEnabled();
}
bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
{
if (event->type() == QEvent::KeyPress) {
@@ -315,10 +312,7 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
}
} else if (obj == this && event->type() == QEvent::ShortcutOverride) {
QKeyEvent *ke = static_cast<QKeyEvent *>(event);
if (shouldSetFocusOnKeyEvent(ke)) {
event->accept();
return true;
} else if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
if (ke->key() == Qt::Key_Space && (ke->modifiers() & Utils::HostOsInfo::controlModifier())) {
event->accept();
return true;
}
@@ -330,16 +324,6 @@ bool FindToolBar::eventFilter(QObject *obj, QEvent *event)
return Utils::StyledBar::eventFilter(obj, event);
}
void FindToolBar::keyPressEvent(QKeyEvent *event)
{
if (shouldSetFocusOnKeyEvent(event)) {
if (setFocusToCurrentFindSupport())
event->accept();
return;
}
return Utils::StyledBar::keyPressEvent(event);
}
void FindToolBar::adaptToCandidate()
{
updateFindAction();
@@ -359,6 +343,9 @@ void FindToolBar::updateToolBar()
{
bool enabled = m_currentDocumentFind->isEnabled();
bool replaceEnabled = enabled && m_currentDocumentFind->supportsReplace();
m_goToCurrentFindAction->setEnabled(enabled);
m_findNextAction->setEnabled(enabled);
m_findPreviousAction->setEnabled(enabled);

View File

@@ -119,14 +119,14 @@ private slots:
void adaptToCandidate();
bool setFocusToCurrentFindSupport();
protected:
bool focusNextPrevChild(bool next);
void keyPressEvent(QKeyEvent *event);
private:
void installEventFilters();
void invokeClearResults();
bool setFocusToCurrentFindSupport();
void setFindFlag(FindFlag flag, bool enabled);
bool hasFindFlag(FindFlag flag);
FindFlags effectiveFindFlags();
@@ -140,13 +140,12 @@ private:
void updateIcons();
void updateFlagMenus();
bool shouldSetFocusOnKeyEvent(QKeyEvent *event);
FindPlugin *m_plugin;
CurrentDocumentFind *m_currentDocumentFind;
Ui::FindWidget m_ui;
QCompleter *m_findCompleter;
QCompleter *m_replaceCompleter;
QAction *m_goToCurrentFindAction;
QAction *m_findInDocumentAction;
QAction *m_findNextSelectedAction;
QAction *m_findPreviousSelectedAction;

View File

@@ -39,6 +39,8 @@
namespace Core {
namespace Constants {
const char C_FINDTOOLBAR[] = "Find.ToolBar";
const char M_FIND[] = "Find.FindMenu";
const char M_FIND_ADVANCED[] = "Find.FindAdvancedMenu";
const char G_FIND_CURRENTDOCUMENT[] = "Find.FindMenu.CurrentDocument";