From 255e7d1d75cfe7cdae188a0da594df8753031933 Mon Sep 17 00:00:00 2001
From: mae <qt-info@nokia.com>
Date: Mon, 14 Dec 2009 14:24:47 +0100
Subject: [PATCH] Fixed disabled action shortcuts

The patch introduces a dummy action which eats the respective
shortcuts when the real action is disabled.
This works around an issue on X11, where some Ctrl-shortcuts do
insert printable text, for example Ctrl+. for the next bookmark.
Without the patch, Ctrl+. would insert an unexpected '.' into
the text when there are no bookmarks.

Reviewed-by: con
---
 src/plugins/coreplugin/actionmanager/command.cpp | 11 ++++++++++-
 src/plugins/coreplugin/actionmanager/command_p.h |  1 +
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/plugins/coreplugin/actionmanager/command.cpp b/src/plugins/coreplugin/actionmanager/command.cpp
index 653009203b7..4c7b2c3f303 100644
--- a/src/plugins/coreplugin/actionmanager/command.cpp
+++ b/src/plugins/coreplugin/actionmanager/command.cpp
@@ -37,6 +37,7 @@
 
 #include <QtGui/QAction>
 #include <QtGui/QShortcut>
+#include <QtGui/QMainWindow>
 
 /*!
     \class Core::Command
@@ -424,8 +425,11 @@ QKeySequence Action::keySequence() const
 
 OverrideableAction::OverrideableAction(int id)
     : Action(id), m_currentAction(0), m_active(false),
-    m_contextInitialized(false)
+    m_contextInitialized(false),
+    m_dummyShortcutEater(this)
 {
+    Core::ICore::instance()->mainWindow()->addAction(&m_dummyShortcutEater);
+    m_dummyShortcutEater.setEnabled(false);
 }
 
 void OverrideableAction::setAction(QAction *action)
@@ -465,9 +469,11 @@ bool OverrideableAction::setCurrentContext(const QList<int> &context)
         m_active = true;
         return true;
     }
+    // no active/delegate action, "visible" action is not enabled/visible
     if (hasAttribute(CA_Hide))
         m_action->setVisible(false);
     m_action->setEnabled(false);
+    m_dummyShortcutEater.setEnabled(false);
     m_active = false;
     return false;
 }
@@ -521,6 +527,9 @@ void OverrideableAction::actionChanged()
 
     m_action->setEnabled(m_currentAction->isEnabled());
     m_action->setVisible(m_currentAction->isVisible());
+
+    m_dummyShortcutEater.setShortcuts(m_action->shortcuts());
+    m_dummyShortcutEater.setEnabled(!m_action->isEnabled());
 }
 
 bool OverrideableAction::isActive() const
diff --git a/src/plugins/coreplugin/actionmanager/command_p.h b/src/plugins/coreplugin/actionmanager/command_p.h
index 176866dfeeb..1c89fd7b7fb 100644
--- a/src/plugins/coreplugin/actionmanager/command_p.h
+++ b/src/plugins/coreplugin/actionmanager/command_p.h
@@ -153,6 +153,7 @@ private:
     QMap<int, QPointer<QAction> > m_contextActionMap;
     bool m_active;
     bool m_contextInitialized;
+    QAction m_dummyShortcutEater;
 };
 
 } // namespace Internal
-- 
GitLab