annotate libgui/src/m-editor/octave-qscintilla.cc @ 16735:cee305c91e91

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
author Torsten <ttl@justmail.de>
date Sat, 08 Jun 2013 18:00:01 +0200
parents 2723d1144f11
children e2de3c8882be
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
1 /*
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
2
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
3 Copyright (C) 2013 Torsten <ttl@justmail.de>
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
4
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
5 This file is part of Octave.
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
6
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
10 option) any later version.
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
11
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
15 for more details.
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
16
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, see
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
19 <http://www.gnu.org/licenses/>.
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
20
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
21 */
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
22
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
23 #ifdef HAVE_CONFIG_H
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
24 #include <config.h>
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
25 #endif
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
26
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
27 #ifdef HAVE_QSCINTILLA
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
28
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
29 #include <Qsci/qscilexer.h>
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
30
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
31 #include "octave-qscintilla.h"
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
32 #include "file-editor-tab.h"
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
33
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
34 octave_qscintilla::octave_qscintilla (QWidget *p)
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
35 : QsciScintilla (p)
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
36 { }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
37
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
38 octave_qscintilla::~octave_qscintilla ()
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
39 { }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
40
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
41
16733
2723d1144f11 added test for qscintilla version 2.6.0
Torsten <ttl@justmail.de>
parents: 16731
diff changeset
42 #ifdef HAVE_QSCI_VERSION_2_6_0
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
43 // context menu requested
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
44 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
45 octave_qscintilla::contextMenuEvent (QContextMenuEvent *e)
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
46 {
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
47 QMenu *context_menu = createStandardContextMenu ( ); // standard menu
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
48
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
49 // the menu's position
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
50 QPoint global_pos, local_pos;
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
51
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
52 if (e->reason () == QContextMenuEvent::Mouse)
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
53 { // context menu by mouse
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
54 global_pos = e->globalPos (); // global mouse position
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
55 local_pos = e->pos (); // local mouse position
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
56 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
57 else
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
58 { // context menu by keyboard or other: get point of text cursor
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
59 long position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS);
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
60 long point_x = SendScintilla
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
61 (QsciScintillaBase::SCI_POINTXFROMPOSITION,0,position);
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
62 long point_y = SendScintilla
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
63 (QsciScintillaBase::SCI_POINTYFROMPOSITION,0,position);
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
64 local_pos = QPoint (point_x,point_y); // local cursor position
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
65 global_pos = mapToGlobal (local_pos); // global position of cursor
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
66 QRect editor_rect = geometry (); // editor rect mapped to global
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
67 editor_rect.moveTopLeft
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
68 (parentWidget ()->mapToGlobal (editor_rect.topLeft ()));
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
69 if (!editor_rect.contains (global_pos)) // is cursor outside editor?
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
70 global_pos = editor_rect.topLeft (); // yes, take top left corner
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
71 }
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
72
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
73 // additional custom entries of the context menu
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
74 context_menu->addSeparator (); // separator before custom entries
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
75
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
76 // help menu: get the position of the mouse or the text cursor
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
77 // (only for octave files)
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
78 QString lexer_name = lexer ()->lexer ();
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
79 if (lexer_name == "octave" || lexer_name == "matlab")
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
80 {
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
81 _word_at_cursor = wordAtPoint (local_pos);
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
82 if (!_word_at_cursor.isEmpty ())
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
83 context_menu->addAction (tr ("help") + " " + _word_at_cursor,
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
84 this, SLOT (contextmenu_help (bool)));
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
85 }
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
86
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
87 // finaly show the menu
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
88 context_menu->exec (global_pos);
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
89 }
16733
2723d1144f11 added test for qscintilla version 2.6.0
Torsten <ttl@justmail.de>
parents: 16731
diff changeset
90 #endif
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
91
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
92
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
93 // handle the menu entry for calling help
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
94 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
95 octave_qscintilla::contextmenu_help (bool)
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
96 {
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
97 QString command = "help " + _word_at_cursor;
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
98 emit execute_command_in_terminal_signal (command);
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
99 }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
100
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
101 #endif