changeset 29084:2a70a068c4ab

add option for using alt-modifer in command windows readline (bug #59478) * gui-preferences-sc.h: key and default value for new pref for disabling menu accelerators when command window has focus * main-window.cc (main_window): initial new boolean class variable storing the pref for disabling the menu accelerators; (focus_changed): check for editor and command window getting or losing focus and en-/disable menu accelerators accordingly; (notice_settings): get new preference, disable menu accelerators if desired and if command window has focus (construct): remove connection of editor focus changed signal with the slot in main window since the related slot is now directly called from focus_changed if required * main-window.h: new class variable m_prevent_readline_conflicts_menu * settings-dialog.cc (settings_dialog) read new pref and initialize the related check box; (write_changed_settings): store state of the check box in pref file * settings-dialog.ui: added check box for new preference
author Torsten Lilge <ttl-octave@mailbox.org>
date Fri, 20 Nov 2020 20:02:29 +0100
parents 95ec5841c9d6
children 3b29d72645a9
files libgui/src/gui-preferences-sc.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/settings-dialog.cc libgui/src/settings-dialog.ui
diffstat 5 files changed, 72 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences-sc.h	Fri Nov 20 18:22:56 2020 +0100
+++ b/libgui/src/gui-preferences-sc.h	Fri Nov 20 20:02:29 2020 +0100
@@ -264,5 +264,7 @@
 
 const gui_pref
 sc_prevent_rl_conflicts ("shortcuts/prevent_readline_conflicts", QVariant (true));
+const gui_pref
+sc_prevent_rl_conflicts_menu ("shortcuts/prevent_readline_conflicts_menu", QVariant (false));
 
 #endif
--- a/libgui/src/main-window.cc	Fri Nov 20 18:22:56 2020 +0100
+++ b/libgui/src/main-window.cc	Fri Nov 20 20:02:29 2020 +0100
@@ -119,7 +119,9 @@
       m_find_files_dlg (nullptr), m_set_path_dlg (nullptr),
       m_release_notes_window (nullptr), m_community_news_window (nullptr),
       m_clipboard (QApplication::clipboard ()),
-      m_prevent_readline_conflicts (true), m_suppress_dbg_location (true),
+      m_prevent_readline_conflicts (true),
+      m_prevent_readline_conflicts_menu (false),
+      m_suppress_dbg_location (true),
       m_closing (false), m_file_encoding (QString ())
   {
     resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
@@ -352,9 +354,12 @@
         count++;  // Limited number of trials
       }
 
-    // editor needs extra handling
+    // editor and terminal needs extra handling
     octave_dock_widget *edit_dock_widget
       = static_cast<octave_dock_widget *> (m_editor_window);
+    octave_dock_widget *cmd_dock_widget
+      = static_cast<octave_dock_widget *> (m_command_window);
+
     // if new dock has focus, emit signal and store active focus
     // except editor changes to a dialog (dock=0)
     if ((dock || m_active_dock != edit_dock_widget) && (dock != m_active_dock))
@@ -369,10 +374,37 @@
               dock->set_predecessor_widget (m_active_dock);
           }
 
+        int editor = 0;
         if (edit_dock_widget == dock)
-          emit editor_focus_changed (true);
+          {
+            emit editor_focus_changed (true);
+            editor = 1;
+          }
         else if (edit_dock_widget == m_active_dock)
-          emit editor_focus_changed (false);
+          {
+            emit editor_focus_changed (false);
+            editor = -1;
+          }
+
+        int command = 0;
+        if (m_prevent_readline_conflicts_menu)
+          {
+            if (cmd_dock_widget == dock)
+              command = 1;
+            else if (cmd_dock_widget == m_active_dock)
+              command = -1;
+          }
+
+        // If editor or command gets/looses focus, disable/enable
+        // main menu accelerators
+        if (editor || command)
+          {
+            int sum = editor + command;
+            if (sum > 0)
+              disable_menu_shortcuts (true);
+            else if (sum < 0)
+              disable_menu_shortcuts (false);
+          }
 
         if (m_active_dock)
           m_previous_dock = m_active_dock;
@@ -916,6 +948,10 @@
       = settings->value (sc_prevent_rl_conflicts.key,
                          sc_prevent_rl_conflicts.def).toBool ();
 
+    m_prevent_readline_conflicts_menu
+      = settings->value (sc_prevent_rl_conflicts_menu.key,
+                         sc_prevent_rl_conflicts_menu.def).toBool ();
+
     m_suppress_dbg_location
       = ! settings->value (cs_dbg_location).toBool ();
 
@@ -926,7 +962,13 @@
 
     configure_shortcuts ();
     set_global_shortcuts (m_active_dock == m_command_window);
-    disable_menu_shortcuts (m_active_dock == m_editor_window);
+
+    bool do_disable_main_menu_shortcuts
+      = (m_active_dock == m_editor_window)
+        || (m_prevent_readline_conflicts_menu
+            && (m_active_dock == m_command_window));
+
+    disable_menu_shortcuts (do_disable_main_menu_shortcuts);
 
     // Check whether some octave internal preferences have to be updated
     QString new_default_encoding
@@ -2103,9 +2145,6 @@
              this, SLOT (notice_settings (const gui_settings *)));
 
     connect (this, SIGNAL (editor_focus_changed (bool)),
-             this, SLOT (disable_menu_shortcuts (bool)));
-
-    connect (this, SIGNAL (editor_focus_changed (bool)),
              m_editor_window, SLOT (enable_menu_shortcuts (bool)));
 
     connect (this, SIGNAL (step_into_file_signal (void)),
--- a/libgui/src/main-window.h	Fri Nov 20 18:22:56 2020 +0100
+++ b/libgui/src/main-window.h	Fri Nov 20 20:02:29 2020 +0100
@@ -434,6 +434,7 @@
     //! Some class global flags.
     //!@{
     bool m_prevent_readline_conflicts;
+    bool m_prevent_readline_conflicts_menu;
     bool m_suppress_dbg_location;
     bool m_editor_has_tabs;
 
--- a/libgui/src/settings-dialog.cc	Fri Nov 20 18:22:56 2020 +0100
+++ b/libgui/src/settings-dialog.cc	Fri Nov 20 20:02:29 2020 +0100
@@ -458,6 +458,9 @@
     cb_prevent_readline_conflicts->setChecked (
           settings->value (sc_prevent_rl_conflicts.key,
                            sc_prevent_rl_conflicts.def).toBool ());
+    cb_prevent_readline_conflicts_menu->setChecked (
+          settings->value (sc_prevent_rl_conflicts_menu.key,
+                           sc_prevent_rl_conflicts_menu.def).toBool ());
 
     // initialize the tree view with all shortcut data
     scmgr.fill_treewidget (shortcuts_treewidget);
@@ -1072,6 +1075,7 @@
     // shortcuts
 
     settings->setValue (sc_prevent_rl_conflicts.key, cb_prevent_readline_conflicts->isChecked ());
+    settings->setValue (sc_prevent_rl_conflicts_menu.key, cb_prevent_readline_conflicts_menu->isChecked ());
     shortcut_manager& scmgr = m_octave_qobj.get_shortcut_manager ();
     scmgr.write_shortcuts (settings, closing);
 
--- a/libgui/src/settings-dialog.ui	Fri Nov 20 18:22:56 2020 +0100
+++ b/libgui/src/settings-dialog.ui	Fri Nov 20 20:02:29 2020 +0100
@@ -32,7 +32,7 @@
       </size>
      </property>
      <property name="currentIndex">
-      <number>7</number>
+      <number>6</number>
      </property>
      <widget class="QWidget" name="tab_general">
       <property name="enabled">
@@ -51,7 +51,7 @@
           <property name="geometry">
            <rect>
             <x>0</x>
-            <y>0</y>
+            <y>-38</y>
             <width>1021</width>
             <height>607</height>
            </rect>
@@ -2638,8 +2638,15 @@
               <number>0</number>
              </property>
              <item>
-              <layout class="QHBoxLayout" name="horizontalLayout_15">
-               <item>
+              <layout class="QVBoxLayout" name="verticalLayout_36">
+               <property name="topMargin">
+                <number>6</number>
+               </property>
+              </layout>
+             </item>
+             <item>
+              <layout class="QGridLayout" name="gridLayout_6">
+               <item row="0" column="0">
                 <widget class="QCheckBox" name="cb_prevent_readline_conflicts">
                  <property name="toolTip">
                   <string>Select this option to prevent conflicts with readline shortcuts</string>
@@ -2652,6 +2659,13 @@
                  </property>
                 </widget>
                </item>
+               <item row="1" column="0">
+                <widget class="QCheckBox" name="cb_prevent_readline_conflicts_menu">
+                 <property name="text">
+                  <string>Disable menu accelerators of main window menus when Commmand Window has focus</string>
+                 </property>
+                </widget>
+               </item>
               </layout>
              </item>
              <item>