[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [konsole/konsole-settings] src: Enable or disable menu accelerators at realtime
From:       Jekyll Wu <adaptee () gmail ! com>
Date:       2012-01-15 6:49:47
Message-ID: 20120115064947.B2924A60A6 () git ! kde ! org
[Download RAW message or body]

Git commit a29aeac9e85a39168073757fb079c52e05cd2ab2 by Jekyll Wu.
Committed on 15/01/2012 at 05:41.
Pushed by jekyllwu into branch 'konsole-settings'.

Enable or disable menu accelerators at realtime

M  +26   -1    src/MainWindow.cpp
M  +2    -0    src/MainWindow.h
M  +13   -0    src/settings/GeneralSettings.ui

http://commits.kde.org/konsole/a29aeac9e85a39168073757fb079c52e05cd2ab2

diff --git a/src/MainWindow.cpp b/src/MainWindow.cpp
index cd5bfa3..9ace8f1 100644
--- a/src/MainWindow.cpp
+++ b/src/MainWindow.cpp
@@ -114,6 +114,9 @@ MainWindow::MainWindow()
 
     // create menus
     createGUI();
+
+    rememberMenuAccelerators();
+
     // remove accelerators for standard menu items (eg. &File, &View, &Edit)
     // etc. which are defined in kdelibs/kdeui/xmlgui/ui_standards.rc, again,
     // to avoid conflicting with Alt+[Letter] terminal shortcuts
@@ -123,6 +126,7 @@ MainWindow::MainWindow()
     // XMLGUI file (konsoleui.rc in this case) - the text for standard items
     // can then be redefined there to exclude the standard accelerators
     //removeMenuAccelerators();
+
     // replace standard shortcuts which cannot be used in a terminal
     // (as they are reserved for use by terminal programs)
     correctShortcuts();
@@ -134,6 +138,15 @@ MainWindow::MainWindow()
     applyAppSettings();
     connect(AppSettings::self(), SIGNAL(configChanged()), this, SLOT(applyAppSettings()));
 }
+
+void MainWindow::rememberMenuAccelerators()
+{
+    foreach(QAction * menuItem, menuBar()->actions()) {
+        QString itemText = menuItem->text();
+        menuItem->setData(itemText);
+    }
+}
+
 void MainWindow::removeMenuAccelerators()
 {
     foreach(QAction * menuItem, menuBar()->actions()) {
@@ -143,6 +156,14 @@ void MainWindow::removeMenuAccelerators()
     }
 }
 
+void MainWindow::recoverMenuAccelerators()
+{
+    foreach(QAction * menuItem, menuBar()->actions()) {
+        QString itemText = menuItem->data().toString();
+        menuItem->setText(itemText);
+    }
+}
+
 void MainWindow::setSaveGeometryOnExit(bool save)
 {
     setAutoSaveSettings("MainWindow", save);
@@ -517,9 +538,13 @@ void MainWindow::showSettingsDialog()
 void MainWindow::applyAppSettings()
 {
     kDebug() << "object:" << AppSettings::self();
-    if ( !AppSettings::allowMenuAccelerators() ) {
+    if ( AppSettings::allowMenuAccelerators() ) {
+        recoverMenuAccelerators();
+    }
+    else {
         removeMenuAccelerators();
     }
+
     //kDebug() << "showTerminalSizeHint:" << AppSettings::showTerminalSizeHint();
     // setAutoSaveSettings("MainWindow", AppSettings::saveGeometryOnExit());
 }
diff --git a/src/MainWindow.h b/src/MainWindow.h
index 50a85d4..e4fd310 100644
--- a/src/MainWindow.h
+++ b/src/MainWindow.h
@@ -183,7 +183,9 @@ private slots:
 
 private:
     void correctShortcuts();
+    void rememberMenuAccelerators();
     void removeMenuAccelerators();
+    void recoverMenuAccelerators();
     void setupActions();
     void setupWidgets();
     QString activeSessionDir() const;
diff --git a/src/settings/GeneralSettings.ui b/src/settings/GeneralSettings.ui
index 74a7d3f..28614f1 100644
--- a/src/settings/GeneralSettings.ui
+++ b/src/settings/GeneralSettings.ui
@@ -70,6 +70,19 @@
           </property>
          </widget>
         </item>
+        <item row="3" column="0">
+         <widget class="QCheckBox" name="kcfg_AllowMenuAccelerators">
+          <property name="sizePolicy">
+           <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
+            <horstretch>0</horstretch>
+            <verstretch>0</verstretch>
+           </sizepolicy>
+          </property>
+          <property name="text">
+           <string>Enable menu accelerators</string>
+          </property>
+         </widget>
+        </item>
        </layout>
       </widget>
      </item>
[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic