changeset 25371:41bbdf17f51a

make shortcuts for searching within the documentation configurable * documentation.cc: include shortcut-manager.h, (documentation): use class variables for the shortcuts; (notice_settings): get the configured shortcuts via shortcut manager; * documentation.h: include QShortcut, new class variables for the used shortcuts * shortcut-manager.cc (do_shortcut): new method for reading a shortcut from the settings file; (do_fill_treewidget): create a new section for shortcuts for searching in dock widgets, put editor find shortcuts into this new section; * shortcut-manager.h (shortcut): new static method, calling new method do_shortcut
author Torsten <mttl@mailbox.org>
date Sun, 13 May 2018 10:07:54 +0200
parents 9cc1ca6538e3
children f9ed57ecd3b4
files libgui/src/documentation.cc libgui/src/documentation.h libgui/src/shortcut-manager.cc libgui/src/shortcut-manager.h
diffstat 4 files changed, 58 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/documentation.cc	Thu May 10 21:05:55 2018 +0200
+++ b/libgui/src/documentation.cc	Sun May 13 10:07:54 2018 +0200
@@ -41,20 +41,23 @@
 #include <QLabel>
 #include <QLineEdit>
 #include <QMessageBox>
-#include <QShortcut>
 #include <QTabWidget>
 #include <QToolButton>
 #include <QVBoxLayout>
 
 #include "documentation.h"
 #include "resource-manager.h"
+#include "shortcut-manager.h"
 
 namespace octave
 {
   // The documentation splitter, which is the main widget
   // of the doc dock widget
   documentation::documentation (QWidget *p)
-    : QSplitter (Qt::Horizontal, p)
+    : QSplitter (Qt::Horizontal, p),
+      m_show_shortcut (new QShortcut (p)),
+      m_findnext_shortcut (new QShortcut (p)),
+      m_findprev_shortcut (new QShortcut (p))
   {
     // Get original collection
     QString collection = getenv ("OCTAVE_QTHELP_COLLECTION");
@@ -133,28 +136,30 @@
     v_box_browser_find->addWidget (find_footer);
     browser_find->setLayout (v_box_browser_find);
 
-    QShortcut *show_shortcut = new QShortcut (QKeySequence (QKeySequence::Find), p);
-    show_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
-    connect (show_shortcut, SIGNAL (activated (void)),
+    notice_settings (resource_manager::get_settings ());
+
+    m_show_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_show_shortcut, SIGNAL (activated (void)),
              m_find_line_edit->parentWidget (), SLOT (show (void)));
-    connect (show_shortcut, SIGNAL (activated (void)),
+    connect (m_show_shortcut, SIGNAL (activated (void)),
              m_find_line_edit, SLOT (selectAll (void)));
-    connect (show_shortcut, SIGNAL (activated (void)),
+    connect (m_show_shortcut, SIGNAL (activated (void)),
              m_find_line_edit, SLOT (setFocus (void)));
     QShortcut *hide_shortcut = new QShortcut (Qt::Key_Escape, p);
+
     hide_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
     connect (hide_shortcut, SIGNAL (activated (void)),
              m_find_line_edit->parentWidget (), SLOT(hide (void)));
     connect (hide_shortcut, SIGNAL (activated (void)),
              m_doc_browser, SLOT (setFocus (void)));
-    QShortcut *findnext_shortcut = new QShortcut (QKeySequence (QKeySequence::FindNext), p);
-    findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
-    connect (findnext_shortcut, SIGNAL (activated (void)),
+
+    m_findnext_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_findnext_shortcut, SIGNAL (activated (void)),
              this, SLOT(find_forward (void)));
-    QShortcut *findprev_shortcut = new QShortcut (QKeySequence (QKeySequence::FindPrevious), p);
-    findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
-    connect (findprev_shortcut, SIGNAL (activated (void)),
+    m_findprev_shortcut->setContext (Qt::WidgetWithChildrenShortcut);
+    connect (m_findprev_shortcut, SIGNAL (activated (void)),
              this, SLOT(find_backward (void)));
+
     find_footer->hide ();
     m_search_anchor_position = 0;
 
@@ -295,7 +300,12 @@
     qApp->restoreOverrideCursor();
   }
 
-  void documentation::notice_settings (const QSettings *) { }
+  void documentation::notice_settings (const QSettings *)
+  {
+    shortcut_manager::shortcut (m_show_shortcut, "editor_edit:find_replace");
+    shortcut_manager::shortcut (m_findnext_shortcut, "editor_edit:find_next");
+    shortcut_manager::shortcut (m_findprev_shortcut, "editor_edit:find_previous");
+  }
 
   void documentation::copyClipboard (void) { }
 
--- a/libgui/src/documentation.h	Thu May 10 21:05:55 2018 +0200
+++ b/libgui/src/documentation.h	Sun May 13 10:07:54 2018 +0200
@@ -26,6 +26,7 @@
 #include <QComboBox>
 #include <QWidget>
 #include <QSettings>
+#include <QShortcut>
 #include <QSplitter>
 #include <QTextBrowser>
 #include <QtHelp/QHelpEngine>
@@ -101,6 +102,9 @@
     QComboBox *m_filter;
     QString m_collection;
 
+    QShortcut *m_show_shortcut;
+    QShortcut *m_findnext_shortcut;
+    QShortcut *m_findprev_shortcut;
   };
 
 }
--- a/libgui/src/shortcut-manager.cc	Thu May 10 21:05:55 2018 +0200
+++ b/libgui/src/shortcut-manager.cc	Sun May 13 10:07:54 2018 +0200
@@ -509,6 +509,19 @@
       qDebug () << "Key: " << key << " not found in m_action_hash";
   }
 
+  void shortcut_manager::do_shortcut (QShortcut *sc, const QString& key)
+  {
+    int index;
+
+    index = m_action_hash[key] - 1;
+
+    if (index > -1 && index < m_sc.count ())
+      sc->setKey (QKeySequence (m_settings->value ("shortcuts/" + key,
+                                m_sc.at (index).m_default_sc).toString ()));
+    else
+      qDebug () << "Key: " << key << " not found in m_action_hash";
+  }
+
   void shortcut_manager::do_fill_treewidget (QTreeWidget *tree_view)
   {
     m_dialog = nullptr;
@@ -537,6 +550,8 @@
     main_news->setText (0, tr ("News Menu"));
     QTreeWidgetItem *main_tabs = new QTreeWidgetItem (main);
     main_tabs->setText (0, tr ("Tab Handling in Dock Widgets"));
+    QTreeWidgetItem *main_find = new QTreeWidgetItem (main);
+    main_find->setText (0, tr ("Find & Replace in Dock Widgets"));
 
     m_level_hash["main_file"]   = main_file;
     m_level_hash["main_edit"]   = main_edit;
@@ -546,6 +561,7 @@
     m_level_hash["main_news"]   = main_news;
     m_level_hash["main_tabs"]   = main_tabs;
     m_level_hash["editor_tabs"]   = main_tabs;
+    m_level_hash["editor_find"]   = main_find;
 
     QTreeWidgetItem *editor = new QTreeWidgetItem (tree_view);
     editor->setText (0, tr ("Editor"));
@@ -587,6 +603,12 @@
             if (sc.m_settings_key.contains ("editor_file:close"))
               section = main_tabs;
           }
+        if (section == editor_edit)
+          {
+            // Find & replace now in global file & replace handling section
+            if (sc.m_settings_key.contains ("editor_edit:find"))
+              section = main_find;
+          }
 
         QTreeWidgetItem *tree_item = new QTreeWidgetItem (section);
 
--- a/libgui/src/shortcut-manager.h	Thu May 10 21:05:55 2018 +0200
+++ b/libgui/src/shortcut-manager.h	Sun May 13 10:07:54 2018 +0200
@@ -29,6 +29,7 @@
 #include <QKeyEvent>
 #include <QLabel>
 #include <QSettings>
+#include <QShortcut>
 
 namespace octave
 {
@@ -95,6 +96,12 @@
         instance->do_set_shortcut (action, key);
     }
 
+    static void shortcut (QShortcut *sc, const QString& key)
+    {
+      if (instance_ok () && sc)
+        instance->do_shortcut (sc, key);
+    }
+
     static void fill_treewidget (QTreeWidget *tree_view)
     {
       if (instance_ok ())
@@ -127,6 +134,7 @@
     void do_init_data ();
     void do_write_shortcuts (QSettings *settings, bool closing);
     void do_set_shortcut (QAction *action, const QString& key);
+    void do_shortcut (QShortcut *sc, const QString& key);
     void do_fill_treewidget (QTreeWidget *tree_view);
     bool do_import_export (int action);
     void shortcut_dialog (int);