From 262dcc6643225d413490fbf03a1b1471b380518d Mon Sep 17 00:00:00 2001 From: David Schulz Date: Thu, 29 Feb 2024 13:17:33 +0100 Subject: [PATCH] Core: do not activate open documents entry on right click If we activate an entry before we handle the context menu event we might switch into another mode. For example when right clicking on a ui File. Fixes: QTCREATORBUG-30357 Change-Id: I8de78c3a6bbd9d62e2766ccd2059ee3ee4ef0870 Reviewed-by: Eike Ziller --- src/libs/utils/itemviews.h | 16 ++++++++++++++++ .../coreplugin/editormanager/openeditorsview.cpp | 9 +++++++++ src/plugins/projectexplorer/projectwindow.cpp | 14 +------------- 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/src/libs/utils/itemviews.h b/src/libs/utils/itemviews.h index 50e8a4af01e..ff1f5328b15 100644 --- a/src/libs/utils/itemviews.h +++ b/src/libs/utils/itemviews.h @@ -59,6 +59,22 @@ public: BaseT::keyPressEvent(event); } + virtual bool userWantsContextMenu(const QMouseEvent *) const + { + return false; + } + + void mousePressEvent(QMouseEvent *e) override + { + if (!userWantsContextMenu(e)) + BaseT::mousePressEvent(e); + } + + void mouseReleaseEvent(QMouseEvent *e) override + { + if (!userWantsContextMenu(e)) + BaseT::mouseReleaseEvent(e); + } }; class QTCREATOR_UTILS_EXPORT TreeView : public View diff --git a/src/plugins/coreplugin/editormanager/openeditorsview.cpp b/src/plugins/coreplugin/editormanager/openeditorsview.cpp index 350cdac142b..cc7451b9395 100644 --- a/src/plugins/coreplugin/editormanager/openeditorsview.cpp +++ b/src/plugins/coreplugin/editormanager/openeditorsview.cpp @@ -66,6 +66,8 @@ private: void activateEditor(const QModelIndex &index); void closeDocument(const QModelIndex &index); + bool userWantsContextMenu(const QMouseEvent *) const final; + ProxyModel *m_model; }; @@ -138,6 +140,13 @@ void OpenEditorsWidget::closeDocument(const QModelIndex &index) updateCurrentItem(EditorManager::currentEditor()); } +bool OpenEditorsWidget::userWantsContextMenu(const QMouseEvent *e) const +{ + // block activating on entry on right click otherwise we might switch into another mode + // see QTCREATORBUG-30357 + return e->button() == Qt::RightButton; +} + void OpenEditorsWidget::contextMenuRequested(QPoint pos) { QMenu contextMenu; diff --git a/src/plugins/projectexplorer/projectwindow.cpp b/src/plugins/projectexplorer/projectwindow.cpp index 66dca5ecd56..1c2f04a04c5 100644 --- a/src/plugins/projectexplorer/projectwindow.cpp +++ b/src/plugins/projectexplorer/projectwindow.cpp @@ -648,24 +648,12 @@ private: return; } - bool userWantsContextMenu(const QMouseEvent *e) const + bool userWantsContextMenu(const QMouseEvent *e) const final { // On Windows, we get additional mouse events for the item view when right-clicking, // causing unwanted kit activation (QTCREATORBUG-24156). Let's suppress these. return HostOsInfo::isWindowsHost() && e->button() == Qt::RightButton; } - - void mousePressEvent(QMouseEvent *e) final - { - if (!userWantsContextMenu(e)) - BaseTreeView::mousePressEvent(e); - } - - void mouseReleaseEvent(QMouseEvent *e) final - { - if (!userWantsContextMenu(e)) - BaseTreeView::mouseReleaseEvent(e); - } }; class ComboBoxItem : public TreeItem