# HG changeset patch # User Torsten # Date 1370707201 -7200 # Node ID cee305c91e91bc2f4746c6fa3a4a7ee8410382f2 # Parent 67b67fc0969aec937f93eb87d169193c836219b3 show help menu in editors context menu only for octave files * octave-qscintilla.cc(contextMenuEvent): show the help entry in the context menu of the editor only for octave files diff -r 67b67fc0969a -r cee305c91e91 libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Sat Jun 08 16:06:55 2013 +0100 +++ b/libgui/src/m-editor/octave-qscintilla.cc Sat Jun 08 18:00:01 2013 +0200 @@ -26,6 +26,8 @@ #ifdef HAVE_QSCINTILLA +#include + #include "octave-qscintilla.h" #include "file-editor-tab.h" @@ -44,14 +46,14 @@ { QMenu *context_menu = createStandardContextMenu ( ); // standard menu - context_menu->addSeparator (); // separator before custom entries + // the menu's position + QPoint global_pos, local_pos; - // help menu: get the position of the mouse or the text cursor - _word_at_cursor = ""; - QPoint global_pos = e->globalPos (); // global mouse position - - if (e->reason () == QContextMenuEvent::Mouse) // context menu by mouse - _word_at_cursor = wordAtPoint (e->pos ()); + if (e->reason () == QContextMenuEvent::Mouse) + { // context menu by mouse + global_pos = e->globalPos (); // global mouse position + local_pos = e->pos (); // local mouse position + } else { // context menu by keyboard or other: get point of text cursor long position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); @@ -59,20 +61,30 @@ (QsciScintillaBase::SCI_POINTXFROMPOSITION,0,position); long point_y = SendScintilla (QsciScintillaBase::SCI_POINTYFROMPOSITION,0,position); - QPoint local_pos = QPoint (point_x,point_y); // local position of cursor + local_pos = QPoint (point_x,point_y); // local cursor position global_pos = mapToGlobal (local_pos); // global position of cursor - QRect editor_rect = geometry (); // get editor rect and map to global - editor_rect.moveTopLeft(parentWidget()->mapToGlobal(editor_rect.topLeft())); - if (editor_rect.contains (global_pos)) // is cursor within editor? - _word_at_cursor = wordAtPoint (local_pos); - else - global_pos = editor_rect.topLeft (); + QRect editor_rect = geometry (); // editor rect mapped to global + editor_rect.moveTopLeft + (parentWidget ()->mapToGlobal (editor_rect.topLeft ())); + if (!editor_rect.contains (global_pos)) // is cursor outside editor? + global_pos = editor_rect.topLeft (); // yes, take top left corner } - // finally create the menu entry if a word at cursor was found - if (!_word_at_cursor.isEmpty ()) - context_menu->addAction (tr ("help") + " " + _word_at_cursor, - this, SLOT (contextmenu_help (bool))); + + // additional custom entries of the context menu + context_menu->addSeparator (); // separator before custom entries + // help menu: get the position of the mouse or the text cursor + // (only for octave files) + QString lexer_name = lexer ()->lexer (); + if (lexer_name == "octave" || lexer_name == "matlab") + { + _word_at_cursor = wordAtPoint (local_pos); + if (!_word_at_cursor.isEmpty ()) + context_menu->addAction (tr ("help") + " " + _word_at_cursor, + this, SLOT (contextmenu_help (bool))); + } + + // finaly show the menu context_menu->exec (global_pos); } #endif