From 51809d12a76784c379ada51bf812ac901952a730 Mon Sep 17 00:00:00 2001 From: con <qtc-committer@nokia.com> Date: Mon, 23 Nov 2009 12:40:08 +0100 Subject: [PATCH] Fix the document history popup for cocoa. Get rid of the hide timer and check modifier keys directly before showing the open documents popup at all. Task-number: QTCREATORBUG-258 --- .../editormanager/editormanager.cpp | 18 +++++++------ .../coreplugin/editormanager/editormanager.h | 2 +- .../editormanager/openeditorswindow.cpp | 25 ++++++------------- .../editormanager/openeditorswindow.h | 6 ++--- 4 files changed, 23 insertions(+), 28 deletions(-) diff --git a/src/plugins/coreplugin/editormanager/editormanager.cpp b/src/plugins/coreplugin/editormanager/editormanager.cpp index 7f4db0b13a7..de6dde03251 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.cpp +++ b/src/plugins/coreplugin/editormanager/editormanager.cpp @@ -1419,7 +1419,7 @@ void EditorManager::gotoNextDocHistory() EditorView *view = currentEditorView(); dialog->setEditors(m_d->m_view, view, m_d->m_editorModel); dialog->selectNextEditor(); - showWindowPopup(); + showPopupOrSelectDocument(); } } @@ -1432,7 +1432,7 @@ void EditorManager::gotoPreviousDocHistory() EditorView *view = currentEditorView(); dialog->setEditors(m_d->m_view, view, m_d->m_editorModel); dialog->selectPreviousEditor(); - showWindowPopup(); + showPopupOrSelectDocument(); } } @@ -1535,12 +1535,16 @@ OpenEditorsWindow *EditorManager::windowPopup() const return m_d->m_windowPopup; } -void EditorManager::showWindowPopup() const +void EditorManager::showPopupOrSelectDocument() const { - const QPoint p(mapToGlobal(QPoint(0, 0))); - m_d->m_windowPopup->move((width()-m_d->m_windowPopup->width())/2 + p.x(), - (height()-m_d->m_windowPopup->height())/2 + p.y()); - m_d->m_windowPopup->setVisible(true); + if (QApplication::keyboardModifiers() == Qt::NoModifier) { + windowPopup()->selectAndHide(); + } else { + const QPoint p(mapToGlobal(QPoint(0, 0))); + windowPopup()->move((width()-m_d->m_windowPopup->width())/2 + p.x(), + (height()-m_d->m_windowPopup->height())/2 + p.y()); + windowPopup()->setVisible(true); + } } QByteArray EditorManager::saveState() const diff --git a/src/plugins/coreplugin/editormanager/editormanager.h b/src/plugins/coreplugin/editormanager/editormanager.h index 06e88b8bf91..44febeba42b 100644 --- a/src/plugins/coreplugin/editormanager/editormanager.h +++ b/src/plugins/coreplugin/editormanager/editormanager.h @@ -159,7 +159,7 @@ public: void readSettings(); Internal::OpenEditorsWindow *windowPopup() const; - void showWindowPopup() const; + void showPopupOrSelectDocument() const; void showEditorInfoBar(const QString &kind, const QString &infoText, diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp index 6079ee7e60c..8a428d87bf0 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.cpp @@ -63,9 +63,6 @@ OpenEditorsWindow::OpenEditorsWindow(QWidget *parent) : connect(m_editorList, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(editorClicked(QTreeWidgetItem*))); - - m_autoHide.setSingleShot(true); - connect(&m_autoHide, SIGNAL(timeout()), this, SLOT(selectAndHide())); } void OpenEditorsWindow::selectAndHide() @@ -78,7 +75,6 @@ void OpenEditorsWindow::setVisible(bool visible) { QWidget::setVisible(visible); if (visible) { - m_autoHide.start(600); setFocus(); } } @@ -96,19 +92,6 @@ bool OpenEditorsWindow::isCentering() } -bool OpenEditorsWindow::event(QEvent *e) { - if (e->type() == QEvent::KeyRelease) { - QKeyEvent *ke = static_cast<QKeyEvent*>(e); - m_autoHide.stop(); - if (ke->modifiers() == 0 - /*HACK this is to overcome some event inconsistencies between platforms*/ - || (ke->modifiers() == Qt::AltModifier && (ke->key() == Qt::Key_Alt || ke->key() == -1))) { - selectAndHide(); - } - } - return QWidget::event(e); -} - bool OpenEditorsWindow::eventFilter(QObject *obj, QEvent *e) { if (obj == m_editorList) { @@ -122,6 +105,14 @@ bool OpenEditorsWindow::eventFilter(QObject *obj, QEvent *e) selectEditor(m_editorList->currentItem()); return true; } + } else if (e->type() == QEvent::KeyRelease) { + QKeyEvent *ke = static_cast<QKeyEvent*>(e); + if (ke->modifiers() == 0 + /*HACK this is to overcome some event inconsistencies between platforms*/ + || (ke->modifiers() == Qt::AltModifier + && (ke->key() == Qt::Key_Alt || ke->key() == -1))) { + selectAndHide(); + } } } return QWidget::eventFilter(obj, e); diff --git a/src/plugins/coreplugin/editormanager/openeditorswindow.h b/src/plugins/coreplugin/editormanager/openeditorswindow.h index 12175d66b0a..b883170f06d 100644 --- a/src/plugins/coreplugin/editormanager/openeditorswindow.h +++ b/src/plugins/coreplugin/editormanager/openeditorswindow.h @@ -59,17 +59,18 @@ public: void setEditors(EditorView *mainView, EditorView *view, OpenEditorsModel *model); - bool event(QEvent *e); bool eventFilter(QObject *src, QEvent *e); void focusInEvent(QFocusEvent *); void setVisible(bool visible); void selectNextEditor(); void selectPreviousEditor(); +public slots: + void selectAndHide(); + private slots: void editorClicked(QTreeWidgetItem *item); void selectEditor(QTreeWidgetItem *item); - void selectAndHide(); private: static const int WIDTH; @@ -85,7 +86,6 @@ private: bool isSameFile(IEditor *editorA, IEditor *editorB) const; QTreeWidget *m_editorList; - QTimer m_autoHide; }; } // namespace Internal -- GitLab