# HG changeset patch # User Torsten # Date 1381493557 -7200 # Node ID 99ffa521ecec47c07f9d2f091c19c9ba797ceea5 # Parent 811019b9ef578f8684a5b4cae3d6447773fa31bd Add possibility to edit the function related to the actual keyword in editor * octave-qscintilla.cc(get_actual_word): new internal function; (context_help_doc): uses new function get_actual_word; (contextMenuEvent): new context menu for editing function of actual keyword (context_edit): function for edit action in editor file menu; (contextmenu_edit): new slot for context menu; * octave-qscintilla.h: new functions context_edit, contextmenu_edit, get_actual_word * file-editor-tab.cc(context_edit): new slot for editor menu action * file-editor-tab.h: new slot context_edit * file-editor.cc(request_context_edit): new slot for file menu entry; (construct): new entry in file menu for editing function of actual keyword; (add_file_editor_tab): connect new signal fetab_context_edit to the new slot context_edit in file_editor_tab; (set_shortcuts): enable/disable new shortcut when editor focus changes (check_actions): enable/disable new action depending on existing tabs * file-editor.h: new signal fetab_context_edit, new slot request_context_edit, new edit function action diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri Oct 11 14:12:37 2013 +0200 @@ -418,6 +418,15 @@ } void +file_editor_tab::context_edit (const QWidget *ID) +{ + if (ID != this) + return; + + _edit_area->context_edit (); +} + +void file_editor_tab::save_file (const QWidget *ID) { if (ID != this) diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Fri Oct 11 14:12:37 2013 +0200 @@ -71,6 +71,7 @@ void cut (const QWidget *ID); void paste (const QWidget *ID); void context_help (const QWidget *ID, bool); + void context_edit (const QWidget *ID); void save_file (const QWidget *ID); void save_file (const QWidget *ID, const QString& fileName, bool remove_on_success); diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/file-editor.cc Fri Oct 11 14:12:37 2013 +0200 @@ -478,6 +478,12 @@ } void +file_editor::request_context_edit (bool) +{ + emit fetab_context_edit (_tab_widget->currentWidget ()); +} + +void file_editor::request_save_file (void) { emit fetab_save_file (_tab_widget->currentWidget ()); @@ -877,7 +883,10 @@ fileMenu->addAction (new_action); fileMenu->addAction (open_action); fileMenu->addMenu (_mru_file_menu); - + fileMenu->addSeparator (); + _context_edit_action = + fileMenu->addAction (QIcon (), tr ("&Edit Function"), + this, SLOT (request_context_edit (bool))); fileMenu->addSeparator (); fileMenu->addAction (_save_action); fileMenu->addAction (_save_as_action); @@ -1130,6 +1139,9 @@ connect (this, SIGNAL (fetab_context_help (const QWidget*, bool)), f, SLOT (context_help (const QWidget*, bool))); + connect (this, SIGNAL (fetab_context_edit (const QWidget*)), + f, SLOT (context_edit (const QWidget*))); + connect (this, SIGNAL (fetab_save_file (const QWidget*)), f, SLOT (save_file (const QWidget*))); @@ -1241,6 +1253,7 @@ _print_action->setShortcut (QKeySequence::Print); _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R); + _context_edit_action->setShortcut (Qt::ControlModifier + Qt::Key_E); _save_action->setShortcut (QKeySequence::Save); _save_as_action->setShortcut (QKeySequence::SaveAs); _close_action->setShortcut (QKeySequence::Close); @@ -1270,6 +1283,7 @@ _print_action->setShortcut (no_key); _run_action->setShortcut (no_key); + _context_edit_action->setShortcut (no_key); _save_action->setShortcut (no_key); _save_as_action->setShortcut (no_key); _close_action->setShortcut (no_key); @@ -1303,6 +1317,7 @@ _print_action->setEnabled (have_tabs); _run_action->setEnabled (have_tabs); + _context_edit_action->setEnabled (have_tabs); _save_action->setEnabled (have_tabs); _save_as_action->setEnabled (have_tabs); _close_action->setEnabled (have_tabs); diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/file-editor.h Fri Oct 11 14:12:37 2013 +0200 @@ -75,6 +75,7 @@ void fetab_cut (const QWidget* ID); void fetab_paste (const QWidget* ID); void fetab_context_help (const QWidget* ID, bool); + void fetab_context_edit (const QWidget* ID); void fetab_save_file (const QWidget* ID); void fetab_save_file_as (const QWidget* ID); void fetab_print_file (const QWidget* ID); @@ -117,6 +118,7 @@ void request_paste (void); void request_context_help (bool); void request_context_doc (bool); + void request_context_edit (bool); void request_save_file (void); void request_save_file_as (void); void request_run_file (void); @@ -207,6 +209,7 @@ QAction *_print_action; QAction *_run_action; + QAction *_context_edit_action; QAction *_save_action; QAction *_save_as_action; QAction *_close_action; diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.cc Fri Oct 11 14:12:37 2013 +0200 @@ -52,19 +52,34 @@ *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) +// determine the actual word and whether we are in an octave or matlab script +bool +octave_qscintilla::get_actual_word () { 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 ()) + return ((lexer_name == "octave" || lexer_name == "matlab") + && !_word_at_cursor.isEmpty ()); +} + +// call documentation or help on the current word +void +octave_qscintilla::context_help_doc (bool documentation) +{ + if (get_actual_word ()) contextmenu_help_doc (documentation); } +// call edit the function related to the current word +void +octave_qscintilla::context_edit () +{ + if (get_actual_word ()) + contextmenu_edit (true); +} + #ifdef HAVE_QSCI_VERSION_2_6_0 // context menu requested void @@ -104,6 +119,8 @@ this, SLOT (contextmenu_help (bool))); context_menu->addAction (tr ("Documentation on") + " " + _word_at_cursor, this, SLOT (contextmenu_doc (bool))); + context_menu->addAction (tr ("Edit") + " " + _word_at_cursor, + this, SLOT (contextmenu_edit (bool))); } // finaly show the menu @@ -136,4 +153,10 @@ emit execute_command_in_terminal_signal (command + _word_at_cursor); } +void +octave_qscintilla::contextmenu_edit (bool) +{ + emit execute_command_in_terminal_signal (QString("edit ") + _word_at_cursor); +} + #endif diff -r 811019b9ef57 -r 99ffa521ecec libgui/src/m-editor/octave-qscintilla.h --- a/libgui/src/m-editor/octave-qscintilla.h Fri Oct 11 13:05:06 2013 +0200 +++ b/libgui/src/m-editor/octave-qscintilla.h Fri Oct 11 14:12:37 2013 +0200 @@ -42,6 +42,9 @@ virtual void contextMenuEvent (QContextMenuEvent *e); #endif void context_help_doc (bool); + void context_edit (); + void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); + bool get_actual_word (); signals: @@ -52,7 +55,7 @@ void contextmenu_help (bool); void contextmenu_doc (bool); void contextmenu_help_doc (bool); - void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos); + void contextmenu_edit (bool); private: