Mercurial > hg > octave-nkf
changeset 17627:811019b9ef57
Add help and documentation on actual keyword to the editor menu
* octave-qscintilla.cc(context_help_doc): new function for editor menu action;
(get_global_textcursor_pos): new function for calculationg the cursor pos;
(contextMenuEvent): uses get_global_textcursor_pos now, added context menu
entry for documentation;
(contextmenu_help,contextmenu_doc): slots for context menu;
(contextmenu_help_doc): new common function used from context_help_doc and the
context menu slots
* octave-qscintilla.h: new functions context_help_doc, contextmenu_doc,
contextmenu_help_doc, get_global_textcursor_pos
* file-editor-tab.cc(context_help): new slot for editor menu action
* file-editor-tab.h: new slot context_help
* file-editor.cc(request_context_help,request_context_doc): new slots for
help menu entries;
(construct): new help menu with keyword help and documentation;
(add_file_editor_tab): connect new signal fetab_context_help to the new
slot context_help in file_editor_tab;
(set_shortcuts): enable/disable new shortcuts when editor focus changes
(check_actions): enable/disable new actions depending on existing tabs
* file-editor.h: new signal fetab_context_help, new slots request_context_help
and request_contest_doc, new help and doc actions
author | Torsten <ttl@justmail.de> |
---|---|
date | Fri, 11 Oct 2013 13:05:06 +0200 |
parents | 82b1778798d3 |
children | 99ffa521ecec |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/m-editor/octave-qscintilla.cc libgui/src/m-editor/octave-qscintilla.h |
diffstat | 6 files changed, 94 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -409,6 +409,15 @@ } void +file_editor_tab::context_help (const QWidget *ID, bool doc) +{ + if (ID != this) + return; + + _edit_area->context_help_doc (doc); +} + +void file_editor_tab::save_file (const QWidget *ID) { if (ID != this)
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -70,6 +70,7 @@ void copy (const QWidget *ID); void cut (const QWidget *ID); void paste (const QWidget *ID); + void context_help (const QWidget *ID, bool); void save_file (const QWidget *ID); void save_file (const QWidget *ID, const QString& fileName, bool remove_on_success);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -467,6 +467,17 @@ } void +file_editor::request_context_help (bool) +{ + emit fetab_context_help (_tab_widget->currentWidget (), false); +} +void +file_editor::request_context_doc (bool) +{ + emit fetab_context_help (_tab_widget->currentWidget (), true); +} + +void file_editor::request_save_file (void) { emit fetab_save_file (_tab_widget->currentWidget ()); @@ -927,6 +938,15 @@ _run_menu->addAction (_run_action); _menu_bar->addMenu (_run_menu); + QMenu *_help_menu = new QMenu (tr ("&Help"), _menu_bar); + _context_help_action = + _help_menu->addAction (QIcon (), tr ("&Help on Keyword"), + this, SLOT (request_context_help (bool))); + _context_doc_action = + _help_menu->addAction (QIcon (), tr ("&Documentation on Keyword"), + this, SLOT (request_context_doc (bool))); + _menu_bar->addMenu (_help_menu); + // shortcuts set_shortcuts (true); @@ -1107,6 +1127,9 @@ connect (this, SIGNAL (fetab_paste (const QWidget*)), f, SLOT (paste (const QWidget*))); + connect (this, SIGNAL (fetab_context_help (const QWidget*, bool)), + f, SLOT (context_help (const QWidget*, bool))); + connect (this, SIGNAL (fetab_save_file (const QWidget*)), f, SLOT (save_file (const QWidget*))); @@ -1205,6 +1228,8 @@ _copy_action->setShortcut (QKeySequence::Copy); _cut_action->setShortcut (QKeySequence::Cut); _paste_action->setShortcut (QKeySequence::Paste); + _context_help_action->setShortcut (QKeySequence::HelpContents); + _context_doc_action->setShortcut (Qt::SHIFT + Qt::Key_F1); _find_action->setShortcut (QKeySequence::Find); _goto_line_action->setShortcut (Qt::ControlModifier+ Qt::Key_G); @@ -1233,6 +1258,7 @@ _copy_action->setShortcut (no_key); _cut_action->setShortcut (no_key); _paste_action->setShortcut (no_key); + _context_help_action->setShortcut (no_key); _find_action->setShortcut (no_key); _goto_line_action->setShortcut (no_key); @@ -1264,6 +1290,8 @@ _copy_action->setEnabled (have_tabs); _cut_action->setEnabled (have_tabs); _paste_action->setEnabled (have_tabs); + _context_help_action->setEnabled (have_tabs); + _context_doc_action->setEnabled (have_tabs); _find_action->setEnabled (have_tabs); _goto_line_action->setEnabled (have_tabs);
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -74,6 +74,7 @@ void fetab_copy (const QWidget* ID); void fetab_cut (const QWidget* ID); void fetab_paste (const QWidget* ID); + void fetab_context_help (const QWidget* ID, bool); void fetab_save_file (const QWidget* ID); void fetab_save_file_as (const QWidget* ID); void fetab_print_file (const QWidget* ID); @@ -114,6 +115,8 @@ void request_copy (void); void request_cut (void); void request_paste (void); + void request_context_help (bool); + void request_context_doc (bool); void request_save_file (void); void request_save_file_as (void); void request_run_file (void); @@ -190,6 +193,8 @@ QAction *_copy_action; QAction *_cut_action; QAction *_paste_action; + QAction *_context_help_action; + QAction *_context_doc_action; QAction *_find_action; QAction *_goto_line_action;
--- a/libgui/src/m-editor/octave-qscintilla.cc +++ b/libgui/src/m-editor/octave-qscintilla.cc @@ -40,6 +40,30 @@ octave_qscintilla::~octave_qscintilla () { } +void +octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos) +{ + long position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); + long point_x = SendScintilla + (QsciScintillaBase::SCI_POINTXFROMPOSITION,0,position); + long point_y = SendScintilla + (QsciScintillaBase::SCI_POINTYFROMPOSITION,0,position); + *local_pos = QPoint (point_x,point_y); // local cursor position + *global_pos = mapToGlobal (*local_pos); // global position of cursor +} + +// call documentation or help on the current word +void +octave_qscintilla::context_help_doc (bool documentation) +{ + QPoint global_pos, local_pos; + get_global_textcursor_pos (&global_pos, &local_pos); + _word_at_cursor = wordAtPoint (local_pos); + QString lexer_name = lexer ()->lexer (); + if ((lexer_name == "octave" || lexer_name == "matlab") + && !_word_at_cursor.isEmpty ()) + contextmenu_help_doc (documentation); +} #ifdef HAVE_QSCI_VERSION_2_6_0 // context menu requested @@ -58,13 +82,7 @@ } else { // context menu by keyboard or other: get point of text cursor - long position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); - long point_x = SendScintilla - (QsciScintillaBase::SCI_POINTXFROMPOSITION,0,position); - long point_y = SendScintilla - (QsciScintillaBase::SCI_POINTYFROMPOSITION,0,position); - local_pos = QPoint (point_x,point_y); // local cursor position - global_pos = mapToGlobal (local_pos); // global position of cursor + get_global_textcursor_pos (&global_pos, &local_pos); QRect editor_rect = geometry (); // editor rect mapped to global editor_rect.moveTopLeft (parentWidget ()->mapToGlobal (editor_rect.topLeft ())); @@ -82,8 +100,10 @@ { _word_at_cursor = wordAtPoint (local_pos); if (!_word_at_cursor.isEmpty ()) - context_menu->addAction (tr ("help") + " " + _word_at_cursor, + context_menu->addAction (tr ("Help on") + " " + _word_at_cursor, this, SLOT (contextmenu_help (bool))); + context_menu->addAction (tr ("Documentation on") + " " + _word_at_cursor, + this, SLOT (contextmenu_doc (bool))); } // finaly show the menu @@ -92,12 +112,28 @@ #endif -// handle the menu entry for calling help +// handle the menu entry for calling help or doc +void +octave_qscintilla::contextmenu_doc (bool) +{ + contextmenu_help_doc (true); +} void octave_qscintilla::contextmenu_help (bool) { - QString command = "help " + _word_at_cursor; - emit execute_command_in_terminal_signal (command); + contextmenu_help_doc (false); +} + +// common function with flag for documentation +void +octave_qscintilla::contextmenu_help_doc (bool documentation) +{ + QString command; + if (documentation) + command = "doc "; + else + command = "help "; + emit execute_command_in_terminal_signal (command + _word_at_cursor); } #endif
--- a/libgui/src/m-editor/octave-qscintilla.h +++ b/libgui/src/m-editor/octave-qscintilla.h @@ -41,6 +41,7 @@ #ifdef HAVE_QSCI_VERSION_2_6_0 virtual void contextMenuEvent (QContextMenuEvent *e); #endif + void context_help_doc (bool); signals: @@ -49,6 +50,9 @@ private slots: void contextmenu_help (bool); + void contextmenu_doc (bool); + void contextmenu_help_doc (bool); + void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); private: