diff options
author | Eike Ziller <eike.ziller@nokia.com> | 2011-08-03 15:11:31 +0200 |
---|---|---|
committer | Bill King <bill.king@nokia.com> | 2011-08-05 09:11:06 +0200 |
commit | 55f0f64a5dbba40442efc34a1868d428a66298ff (patch) | |
tree | e2b8cda202fe66e8ee71dc7f003a8db60e751fca /src/plugins/locator/locatorwidget.cpp | |
parent | 30076b1c97b8246a106f98b2a57a2f3fc3326110 (diff) |
Wait with activating/opening a Locator entry until update has finished
So, if you pressed the enter key faster than the list updated, it will
wait for the list to update and then select an entry, which is much
saner behavior.
Task-number: QTCREATORBUG-5710
Change-Id: Ic98d48122c9db1aad903f9b76040ae5c14a8c44e
Reviewed-on: http://codereview.qt.nokia.com/2667
Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com>
Reviewed-by: Bill King <bill.king@nokia.com>
Diffstat (limited to 'src/plugins/locator/locatorwidget.cpp')
-rw-r--r-- | src/plugins/locator/locatorwidget.cpp | 42 |
1 files changed, 32 insertions, 10 deletions
diff --git a/src/plugins/locator/locatorwidget.cpp b/src/plugins/locator/locatorwidget.cpp index 5e9024c48b..935df4127d 100644 --- a/src/plugins/locator/locatorwidget.cpp +++ b/src/plugins/locator/locatorwidget.cpp @@ -278,13 +278,15 @@ void CompletionList::updatePreferredSize() // =========== LocatorWidget =========== LocatorWidget::LocatorWidget(LocatorPlugin *qop) : - m_locatorPlugin(qop), - m_locatorModel(new LocatorModel(this)), - m_completionList(new CompletionList(this)), - m_filterMenu(new QMenu(this)), - m_refreshAction(new QAction(tr("Refresh"), this)), - m_configureAction(new QAction(tr("Configure..."), this)), - m_fileLineEdit(new Utils::FilterLineEdit) + m_locatorPlugin(qop), + m_locatorModel(new LocatorModel(this)), + m_completionList(new CompletionList(this)), + m_filterMenu(new QMenu(this)), + m_refreshAction(new QAction(tr("Refresh"), this)), + m_configureAction(new QAction(tr("Configure..."), this)), + m_fileLineEdit(new Utils::FilterLineEdit), + m_updateRequested(false), + m_acceptRequested(false) { // Explicitly hide the completion list popup. m_completionList->hide(); @@ -331,7 +333,7 @@ LocatorWidget::LocatorWidget(LocatorPlugin *qop) : connect(m_fileLineEdit, SIGNAL(textChanged(const QString&)), this, SLOT(showPopup())); connect(m_completionList, SIGNAL(activated(QModelIndex)), - this, SLOT(acceptCurrentEntry())); + this, SLOT(scheduleAcceptCurrentEntry())); m_entriesWatcher = new QFutureWatcher<FilterEntry>(this); connect(m_entriesWatcher, SIGNAL(finished()), SLOT(updateEntries())); @@ -404,7 +406,7 @@ bool LocatorWidget::eventFilter(QObject *obj, QEvent *event) return true; case Qt::Key_Enter: case Qt::Key_Return: - acceptCurrentEntry(); + scheduleAcceptCurrentEntry(); return true; case Qt::Key_Escape: m_completionList->hide(); @@ -449,6 +451,7 @@ void LocatorWidget::showCompletionList() void LocatorWidget::showPopup() { + m_updateRequested = true; m_showPopupTimer->start(); } @@ -506,6 +509,7 @@ static void filter_helper(QFutureInterface<Locator::FilterEntry> &entries, QList void LocatorWidget::updateCompletionList(const QString &text) { + m_updateRequested = true; QString searchText; const QList<ILocatorFilter*> filters = filtersFor(text, searchText); @@ -519,8 +523,12 @@ void LocatorWidget::updateCompletionList(const QString &text) void LocatorWidget::updateEntries() { - if (m_entriesWatcher->future().isCanceled()) + m_updateRequested = false; + if (m_entriesWatcher->future().isCanceled()) { + // reset to usable state + m_acceptRequested = false; return; + } const QList<FilterEntry> entries = m_entriesWatcher->future().results(); m_locatorModel->setEntries(entries); @@ -530,10 +538,24 @@ void LocatorWidget::updateEntries() #if 0 m_completionList->updatePreferredSize(); #endif + if (m_acceptRequested) + acceptCurrentEntry(); +} + +void LocatorWidget::scheduleAcceptCurrentEntry() +{ + if (m_updateRequested) { + // don't just accept the selected entry, since the list is not up to date + // accept will be called after the update finished + m_acceptRequested = true; + } else { + acceptCurrentEntry(); + } } void LocatorWidget::acceptCurrentEntry() { + m_acceptRequested = false; if (!m_completionList->isVisible()) return; const QModelIndex index = m_completionList->currentIndex(); |