Mercurial > octave
changeset 27288:0a2e5c808709
allow editing and showing help on selected text in console (bug #41276)
* QTerminal.cc (handleCustomContextMenuRequested): make new context menu
action visible depending on selected text and on the occurrance of a word
within the selection, set menu text and action data accordingly;
(edit_selected): new slot for editing a selected function;
(help_on_expression): new slot for showing help on selected expressions;
(doc_on_expression): new slot for showing documentation on selected expr.
* QTerminal.h: new signal show_doc_signal, new slots edit_selected,
help_on_expression, doc_on_expression and new actions m_edit_selected_action,
m_help_selected_action, and m_doc_selected_action;
(ctor): add new actions on editing or showing help/doc on selected
expressions, connect new signal show_doc_signal to the already
existing slot in main_window
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Wed, 24 Jul 2019 07:47:33 +0200 |
parents | 871313d4b948 |
children | 9dcbc0a449af |
files | libgui/qterminal/libqterminal/QTerminal.cc libgui/qterminal/libqterminal/QTerminal.h |
diffstat | 2 files changed, 77 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/qterminal/libqterminal/QTerminal.cc Tue Jul 23 17:00:06 2019 -0400 +++ b/libgui/qterminal/libqterminal/QTerminal.cc Wed Jul 24 07:47:33 2019 +0200 @@ -100,6 +100,9 @@ bool has_selected_text = ! selected_text.isEmpty (); _edit_action->setVisible (false); + m_edit_selected_action->setVisible (false); + m_help_selected_action->setVisible (false); + m_doc_selected_action->setVisible (false); #if defined (Q_OS_WIN32) // include this when in windows because there is no filter for @@ -126,9 +129,34 @@ } #endif + if (has_selected_text) + { + QRegExp expr (".*\b*(\\w+)\b*.*"); + + int pos = expr.indexIn (selected_text); + + if (pos > -1) + { + QString expr_found = expr.cap (1); + + m_edit_selected_action->setVisible (true); + m_edit_selected_action->setText (tr ("Edit %1").arg (expr_found)); + m_edit_selected_action->setData (expr_found); + + m_help_selected_action->setVisible (true); + m_help_selected_action->setText (tr ("Help on %1").arg (expr_found)); + m_help_selected_action->setData (expr_found); + + m_doc_selected_action->setVisible (true); + m_doc_selected_action->setText (tr ("Documentation on %1") + .arg (expr_found)); + m_doc_selected_action->setData (expr_found); + } + } + _paste_action->setEnabled (cb->text().length() > 0); _copy_action->setEnabled (has_selected_text); - _run_selection_action->setEnabled (has_selected_text); + _run_selection_action->setVisible (has_selected_text); // Get the actions of any hotspots the filters may have found QList<QAction*> actions = get_hotspot_actions (at); @@ -166,6 +194,30 @@ emit edit_mfile_request (file,line); } +// slot for edit selected function names +void QTerminal::edit_selected () +{ + QString file = m_edit_selected_action->data ().toString (); + + emit edit_mfile_request (file,0); +} + +// slot for showing help on selected epxression +void QTerminal::help_on_expression () +{ + QString expr = m_help_selected_action->data ().toString (); + + emit execute_command_in_terminal_signal ("help " + expr); +} + +// slot for showing documentation on selected epxression +void QTerminal::doc_on_expression () +{ + QString expr = m_doc_selected_action->data ().toString (); + + emit show_doc_signal (expr); +} + void QTerminal::notice_settings (const QSettings *settings) {
--- a/libgui/qterminal/libqterminal/QTerminal.h Tue Jul 23 17:00:06 2019 -0400 +++ b/libgui/qterminal/libqterminal/QTerminal.h Wed Jul 24 07:47:33 2019 +0200 @@ -99,6 +99,8 @@ void edit_mfile_request (const QString&, int); + void show_doc_signal (const QString&); + void execute_command_in_terminal_signal (const QString&); public slots: @@ -123,6 +125,12 @@ void edit_file (void); + void edit_selected (void); + + void help_on_expression (void); + + void doc_on_expression (void); + virtual void handle_visibility_changed (bool) { }; protected: @@ -151,6 +159,16 @@ = _contextMenu->addAction (tr ("Run Selection"), this, SLOT (run_selection ())); + m_edit_selected_action + = _contextMenu->addAction (tr ("Edit selection"), this, + SLOT (edit_selected ())); + m_help_selected_action + = _contextMenu->addAction (tr ("Help on selection"), this, + SLOT (help_on_expression ())); + m_doc_selected_action + = _contextMenu->addAction (tr ("Documentation on selection"), this, + SLOT (doc_on_expression ())); + _edit_action = _contextMenu->addAction (tr (""), this, SLOT (edit_file ())); _contextMenu->addSeparator (); @@ -164,6 +182,9 @@ connect (this, SIGNAL (report_status_message (const QString&)), xparent, SLOT (report_status_message (const QString&))); + connect (this, SIGNAL (show_doc_signal (const QString&)), + xparent, SLOT (handle_show_doc (const QString&))); + connect (this, SIGNAL (edit_mfile_request (const QString&, int)), xparent, SLOT (edit_mfile (const QString&, int))); @@ -210,6 +231,9 @@ QAction * _selectall_action; QAction * _edit_action; QAction * _run_selection_action; + QAction * m_edit_selected_action; + QAction * m_help_selected_action; + QAction * m_doc_selected_action; QAction *_interrupt_action; QAction *_nop_action;