annotate libgui/src/m-editor/octave-qscintilla.cc @ 18712:6113e0c6920b

maint: Clean up extra spaces before/after parentheses.
author Rik <rik@octave.org>
date Fri, 25 Apr 2014 13:25:25 -0700
parents 1b289f45187f
children 7c78430535db
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
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16735
diff changeset
3 Copyright (C) 2013 Torsten
16731
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
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16735
diff changeset
23 // Author: Torsten <ttl@justmail.de>
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16735
diff changeset
24
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
25 #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
26 #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
27 #endif
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
28
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
29 #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
30
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
31 #include <Qsci/qscilexer.h>
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
32 #include <Qsci/qscicommandset.h>
18573
26d15a57f45b add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
33 #include <QShortcut>
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
34
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
35 #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
36 #include "file-editor-tab.h"
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
37 #include "shortcut-manager.h"
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
38
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
39 octave_qscintilla::octave_qscintilla (QWidget *p)
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
40 : QsciScintilla (p)
18573
26d15a57f45b add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
41 {
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
42 // clear scintilla edit shortcuts that are handled by the editor
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
43 QsciCommandSet *cmd_set = standardCommands ();
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
44 cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
45 cmd_set->find (QsciCommand::LineTranspose)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
46 cmd_set->find (QsciCommand::Undo)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
47 cmd_set->find (QsciCommand::Redo)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
48 cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
49 cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
50 cmd_set->find (QsciCommand::ZoomIn)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
51 cmd_set->find (QsciCommand::ZoomOut)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
52 cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
53 cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
54 cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
55 cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
56 cmd_set->find (QsciCommand::LineDelete)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
57 cmd_set->find (QsciCommand::LineCut)->setKey (0);
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
58 cmd_set->find (QsciCommand::LineCopy)->setKey (0);
18573
26d15a57f45b add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
59 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
60
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
61 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
62 { }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
63
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
64 void
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
65 octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos,
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
66 QPoint *local_pos)
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
67 {
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
68 long position = SendScintilla (SCI_GETCURRENTPOS);
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
69 long point_x = SendScintilla
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
70 (SCI_POINTXFROMPOSITION,0,position);
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
71 long point_y = SendScintilla
18690
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18573
diff changeset
72 (SCI_POINTYFROMPOSITION,0,position);
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
73 *local_pos = QPoint (point_x,point_y); // local cursor position
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
74 *global_pos = mapToGlobal (*local_pos); // global position of cursor
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
75 }
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
76
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
77 // determine the actual word and whether we are in an octave or matlab script
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
78 bool
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
79 octave_qscintilla::get_actual_word ()
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
80 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
81 QPoint global_pos, local_pos;
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
82 get_global_textcursor_pos (&global_pos, &local_pos);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
83 _word_at_cursor = wordAtPoint (local_pos);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
84 QString lexer_name = lexer ()->lexer ();
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
85 return ((lexer_name == "octave" || lexer_name == "matlab")
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
86 && !_word_at_cursor.isEmpty ());
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
87 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
88
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
89 // call documentation or help on the current word
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
90 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
91 octave_qscintilla::context_help_doc (bool documentation)
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
92 {
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
93 if (get_actual_word ())
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
94 contextmenu_help_doc (documentation);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
95 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
96
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
97 // call edit the function related to the current word
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
98 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
99 octave_qscintilla::context_edit ()
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
100 {
17655
b4783277bd11 *octave-qscintilla.cc: fix edit function at cursor by shortcut Ctrl-E
Torsten <ttl@justmail.de>
parents: 17635
diff changeset
101 if (get_actual_word ())
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
102 contextmenu_edit (true);
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
103 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
104
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
105 // call edit the function related to the current word
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
106 void
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
107 octave_qscintilla::context_run ()
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
108 {
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
109 if (hasSelectedText ())
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
110 contextmenu_run (true);
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
111 }
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
112
16733
2723d1144f11 added test for qscintilla version 2.6.0
Torsten <ttl@justmail.de>
parents: 16731
diff changeset
113 #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
114 // 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
115 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
116 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
117 {
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18690
diff changeset
118 QMenu *context_menu = createStandardContextMenu (); // standard menu
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
119
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
120 // the menu's position
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
121 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
122
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
123 if (e->reason () == QContextMenuEvent::Mouse)
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
124 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
125 // context menu by mouse
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
126 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
127 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
128 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
129 else
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
130 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
131 // context menu by keyboard or other: get point of text cursor
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
132 get_global_textcursor_pos (&global_pos, &local_pos);
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
133 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
134 editor_rect.moveTopLeft
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
135 (parentWidget ()->mapToGlobal (editor_rect.topLeft ()));
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
136 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
137 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
138 }
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
139
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
140 // 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
141 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
142
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
143 // 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
144 // (only for octave files)
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
145 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
146 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
147 {
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
148 _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
149 if (!_word_at_cursor.isEmpty ())
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
150 {
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
151 context_menu->addAction (tr ("Help on") + " " + _word_at_cursor,
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
152 this, SLOT (contextmenu_help (bool)));
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
153 context_menu->addAction (tr ("Documentation on")
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
154 + " " + _word_at_cursor,
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
155 this, SLOT (contextmenu_doc (bool)));
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
156 context_menu->addAction (tr ("Edit") + " " + _word_at_cursor,
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
157 this, SLOT (contextmenu_edit (bool)));
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
158 }
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
159 context_menu->addSeparator (); // separator before custom entries
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
160 if (hasSelectedText ())
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
161 context_menu->addAction (tr ("&Run Selection"),
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
162 this, SLOT (contextmenu_run (bool)));
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
163 }
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
164
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
165 // 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
166 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
167 }
16733
2723d1144f11 added test for qscintilla version 2.6.0
Torsten <ttl@justmail.de>
parents: 16731
diff changeset
168 #endif
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
169
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
170
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
171 // handle the menu entry for calling help or doc
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
172 void
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
173 octave_qscintilla::contextmenu_doc (bool)
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
174 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
175 contextmenu_help_doc (true);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
176 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
177 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
178 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
179 {
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
180 contextmenu_help_doc (false);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
181 }
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
182
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
183 // common function with flag for documentation
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
184 void
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
185 octave_qscintilla::contextmenu_help_doc (bool documentation)
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
186 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
187 QString command;
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
188 if (documentation)
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
189 command = "doc ";
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
190 else
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
191 command = "help ";
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
192 emit execute_command_in_terminal_signal (command + _word_at_cursor);
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
193 }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
194
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
195 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
196 octave_qscintilla::contextmenu_edit (bool)
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
197 {
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
198 emit execute_command_in_terminal_signal (QString("edit ") + _word_at_cursor);
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
199 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
200
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
201 void
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
202 octave_qscintilla::contextmenu_run (bool)
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
203 {
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
204 QStringList commands = selectedText ().split (QRegExp("[\r\n]"),
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
205 QString::SkipEmptyParts);
18712
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18690
diff changeset
206 for (int i = 0; i < commands.size (); i++)
17669
b7670c05731b *octave-qscintilla.cc(contextmenu_run): split selection into single commands
Torsten <ttl@justmail.de>
parents: 17655
diff changeset
207 emit execute_command_in_terminal_signal (commands.at (i));
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
208 }
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
209
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
210 #endif