Mercurial > octave
changeset 26128:20b87596b99a
add mru-lists to the doc browser back/forward buttons (bug #54938)
* documentation.cc (documentation): initialize new class variables;
(documentation::construct_tool_bar): add two tool buttons for popup menus
for recent backward and forward pages, connect the appropriate signal for
enabling/disabling the buttons, connect signal for changed history to the
new slot for updating the mru lists, connect the actions of the new
menus with a slot for opening the url related to the action
(documentation::update_history_menus): new slot for updating the mru
lists depending on the number of history entries which has changed;
(documentation::update_history): doing the update, get the max desired
number of entries from the test browser history and put title and url
into the related menu
(documentation::open_hist_url) new slot for opening an url from the history
* documentation.h: new slots for updating history and opening an url,
new class variables for the new menus , the entry counts and the new actions
author | Torsten <mttl@mailbox.org> |
---|---|
date | Fri, 23 Nov 2018 19:46:51 +0100 |
parents | 37e3aa267374 |
children | 3c61c8137664 |
files | libgui/src/documentation.cc libgui/src/documentation.h |
diffstat | 2 files changed, 113 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/documentation.cc Thu Nov 22 22:17:28 2018 +0100 +++ b/libgui/src/documentation.cc Fri Nov 23 19:46:51 2018 +0100 @@ -43,7 +43,6 @@ #include <QLineEdit> #include <QMessageBox> #include <QTabWidget> -#include <QToolButton> #include <QVBoxLayout> #include "documentation.h" @@ -59,6 +58,10 @@ : QSplitter (Qt::Horizontal, p), m_doc_widget (p), m_tool_bar (new QToolBar (p)), + m_prev_pages_menu (new QMenu (p)), + m_next_pages_menu (new QMenu (p)), + m_prev_pages_count (0), + m_next_pages_count (0), m_findnext_shortcut (new QShortcut (p)), m_findprev_shortcut (new QShortcut (p)) { @@ -311,16 +314,57 @@ m_action_go_prev = add_action (resource_manager::icon ("go-previous"), tr ("Go back"), SLOT (backward (void)), m_doc_browser, m_tool_bar); + m_action_go_prev->setEnabled (false); + + // popdown menu with prev pages files + QToolButton *popdown_button_prev_pages = new QToolButton (); + popdown_button_prev_pages->setToolTip (tr ("Previous Pages")); + popdown_button_prev_pages->setMenu (m_prev_pages_menu); + popdown_button_prev_pages->setPopupMode (QToolButton::InstantPopup); + popdown_button_prev_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); + popdown_button_prev_pages->setCheckable (false); + popdown_button_prev_pages->setArrowType(Qt::DownArrow); + m_tool_bar->addWidget (popdown_button_prev_pages); m_action_go_next = add_action (resource_manager::icon ("go-next"), tr ("Go forward"), SLOT (forward (void)), m_doc_browser, m_tool_bar); - m_action_go_prev->setEnabled (false); m_action_go_next->setEnabled (false); + + // popdown menu with prev pages files + QToolButton *popdown_button_next_pages = new QToolButton (); + popdown_button_next_pages->setToolTip (tr ("Next Pages")); + popdown_button_next_pages->setMenu (m_next_pages_menu); + popdown_button_next_pages->setPopupMode (QToolButton::InstantPopup); + popdown_button_next_pages->setToolButtonStyle (Qt::ToolButtonTextOnly); + popdown_button_next_pages->setArrowType(Qt::DownArrow); + m_tool_bar->addWidget (popdown_button_next_pages); + connect (m_doc_browser, SIGNAL (backwardAvailable (bool)), m_action_go_prev, SLOT (setEnabled (bool))); + connect (m_doc_browser, SIGNAL (backwardAvailable (bool)), + popdown_button_prev_pages, SLOT (setEnabled (bool))); connect (m_doc_browser, SIGNAL (forwardAvailable (bool)), m_action_go_next, SLOT (setEnabled (bool))); + connect (m_doc_browser, SIGNAL (forwardAvailable (bool)), + popdown_button_next_pages, SLOT (setEnabled (bool))); + connect (m_doc_browser, SIGNAL (historyChanged (void)), + this, SLOT (update_history_menus (void))); + // Init prev/next menus + for (int i = 0; i < max_history_entries; ++i) + { + m_prev_pages_actions[i] = new QAction (this); + m_prev_pages_actions[i]->setVisible (false); + m_next_pages_actions[i] = new QAction (this); + m_next_pages_actions[i]->setVisible (false); + m_prev_pages_menu->addAction (m_prev_pages_actions[i]); + m_next_pages_menu->addAction (m_next_pages_actions[i]); + } + + connect (m_prev_pages_menu, SIGNAL (triggered (QAction *)), + this, SLOT (open_hist_url (QAction *))); + connect (m_next_pages_menu, SIGNAL (triggered (QAction *)), + this, SLOT (open_hist_url (QAction *))); // Find m_tool_bar->addSeparator (); @@ -640,6 +684,57 @@ } } + void documentation::update_history_menus (void) + { + if (m_prev_pages_count != m_doc_browser->backwardHistoryCount ()) + { + update_history (m_doc_browser->backwardHistoryCount (), + m_prev_pages_actions); + m_prev_pages_count = m_doc_browser->backwardHistoryCount (); + } + + if (m_next_pages_count != m_doc_browser->forwardHistoryCount ()) + { + update_history (m_doc_browser->forwardHistoryCount (), + m_next_pages_actions); + m_next_pages_count = m_doc_browser->forwardHistoryCount (); + } + } + + void documentation::update_history (int new_count, QAction **actions) + { + // Which menu has to be updated? + int prev_next = -1; + if (actions == m_next_pages_actions) + prev_next = 1; + + // Get maximal count limited by array size + int count = qMin (new_count, int (max_history_entries)); + + // Fill used menu entries + for (int i = 0; i < count; i++) + { + QString title = m_doc_browser->historyTitle (prev_next*(i+1)); + title.remove (QRegExp (" \\(GNU Octave \\(version [^\\)]*\\)\\)$")); + actions[i]->setText (title); + actions[i]->setData (m_doc_browser->historyUrl (prev_next*(i+1))); + actions[i]->setEnabled (true); + actions[i]->setVisible (true); + } + + // Hide unused menu entries + for (int j = count; j < max_history_entries; j++) + { + actions[j]->setEnabled (false); + actions[j]->setVisible (false); + } + } + + void documentation::open_hist_url (QAction *a) + { + m_doc_browser->setSource (a->data ().toUrl ()); + } + // The documentation browser documentation_browser::documentation_browser (QHelpEngine *he, QWidget *p)
--- a/libgui/src/documentation.h Thu Nov 22 22:17:28 2018 +0100 +++ b/libgui/src/documentation.h Fri Nov 23 19:46:51 2018 +0100 @@ -24,12 +24,14 @@ #define octave_documentation_h 1 #include <QComboBox> -#include <QWidget> +#include <QMenu> #include <QSettings> #include <QShortcut> #include <QSplitter> #include <QTextBrowser> #include <QToolBar> +#include <QToolButton> +#include <QWidget> #include <QtHelp/QHelpEngine> namespace octave @@ -119,6 +121,9 @@ void record_anchor_position (void); void handle_cursor_position_change (void); + void update_history_menus (void); + void open_hist_url (QAction *a); + signals: void show_single_result (const QUrl); @@ -129,6 +134,8 @@ QAction *add_action (const QIcon& icon, const QString& text, const char *member, QWidget *receiver = nullptr, QToolBar *tool_bar = nullptr); + void update_history (int new_count, QAction **actions); + QHelpEngine *m_help_engine; QString m_internal_search; @@ -144,6 +151,14 @@ QAction *m_action_go_home; QAction *m_action_go_prev; QAction *m_action_go_next; + QMenu *m_prev_pages_menu; + QMenu *m_next_pages_menu; + int m_prev_pages_count; + int m_next_pages_count; + + enum { max_history_entries = 10 }; + QAction *m_prev_pages_actions[max_history_entries]; + QAction *m_next_pages_actions[max_history_entries]; QAction *m_action_find; QShortcut *m_findnext_shortcut;