annotate libgui/src/m-editor/octave-qscintilla.cc @ 23230:f7fdc9ef3971

improve line breaking in the editor * file-editor-tab.cc (handle_cursor_moved): use real cursor position taking the tab length into account and do not leave blanks at the end of the line * octave-qscintilla..h / octave-qscintilla.cc (get_current_position): new function calculating the real column taking the tab length into account
author Torsten <mttl@mailbox.org>
date Fri, 24 Feb 2017 21:37:11 +0100
parents 4b642b593ec2
children aaf20024db6f
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
23219
3ac9f9ecfae5 maint: Update copyright dates.
John W. Eaton <jwe@octave.org>
parents: 23083
diff changeset
3 Copyright (C) 2013-2017 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
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
8 under the terms of the GNU General Public License as published by
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
9 the Free Software Foundation; either version 3 of the License, or
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
10 (at your option) any later version.
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
11
22755
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
12 Octave is distributed in the hope that it will be useful, but
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
13 WITHOUT ANY WARRANTY; without even the implied warranty of
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3a2b891d0b33 maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents: 22411
diff changeset
15 GNU General Public License for more details.
16731
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
25 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
26 # include "config.h"
16731
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
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
29 #if defined (HAVE_QSCINTILLA)
16731
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>
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
32 #include <Qsci/qscicommandset.h>
18560
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>
19002
00b1d60500bd improved finding a function file for editing in gui (case 1 in bug #41509)
Torsten <ttl@justmail.de>
parents: 18954
diff changeset
34 #include <QMessageBox>
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
35
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
36 #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
37 #include "file-editor-tab.h"
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
38 #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
39
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
40 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
41 : QsciScintilla (p)
18560
26d15a57f45b add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
42 {
18689
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
43 connect (this, SIGNAL (textChanged ()), this, SLOT (text_changed ()));
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
44
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
45 // clear scintilla edit shortcuts that are handled by the editor
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
46 QsciCommandSet *cmd_set = standardCommands ();
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
47
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
48 #if defined (HAVE_QSCI_VERSION_2_6_0)
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
49 // find () was added in QScintilla 2.6
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
50 cmd_set->find (QsciCommand::SelectionCopy)->setKey (0);
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
51 cmd_set->find (QsciCommand::SelectionCut)->setKey (0);
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
52 cmd_set->find (QsciCommand::Paste)->setKey (0);
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
53 cmd_set->find (QsciCommand::SelectAll)->setKey (0);
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
54 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: 18560
diff changeset
55 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: 18560
diff changeset
56 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: 18560
diff changeset
57 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: 18560
diff changeset
58 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: 18560
diff changeset
59 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: 18560
diff changeset
60 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: 18560
diff changeset
61 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: 18560
diff changeset
62 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: 18560
diff changeset
63 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: 18560
diff changeset
64 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: 18560
diff changeset
65 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: 18560
diff changeset
66 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: 18560
diff changeset
67 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: 18560
diff changeset
68 cmd_set->find (QsciCommand::LineCopy)->setKey (0);
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
69 #else
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
70 // find commands via its default key (tricky way without find ())
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
71 QList< QsciCommand * > cmd_list = cmd_set->commands ();
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
72 for (int i = 0; i < cmd_list.length (); i++)
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
73 {
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
74 int cmd_key = cmd_list.at (i)->key ();
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
75 switch (cmd_key)
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
76 {
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
77 case Qt::Key_C | Qt::CTRL : // SelectionCopy
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
78 case Qt::Key_X | Qt::CTRL : // SelectionCut
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
79 case Qt::Key_V | Qt::CTRL : // Paste
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
80 case Qt::Key_A | Qt::CTRL : // SelectAll
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
81 case Qt::Key_D | Qt::CTRL : // SelectionDuplicate
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
82 case Qt::Key_T | Qt::CTRL : // LineTranspose
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
83 case Qt::Key_Z | Qt::CTRL : // Undo
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
84 case Qt::Key_Y | Qt::CTRL : // Redo
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
85 case Qt::Key_Z | Qt::CTRL | Qt::SHIFT : // Redo
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
86 case Qt::Key_U | Qt::CTRL : // SelectionLowerCase
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
87 case Qt::Key_U | Qt::CTRL | Qt::SHIFT : // SelectionUpperCase
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
88 case Qt::Key_Plus | Qt::CTRL : // ZoomIn
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
89 case Qt::Key_Minus | Qt::CTRL : // ZoomOut
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
90 case Qt::Key_Backspace | Qt::CTRL | Qt::SHIFT : // DeleteLineLeft
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
91 case Qt::Key_Delete | Qt::CTRL | Qt::SHIFT : // DeleteLineRight
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
92 case Qt::Key_K | Qt::META : // DeleteLineRight
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
93 case Qt::Key_Backspace | Qt::CTRL : // DeleteWordLeft
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
94 case Qt::Key_Delete | Qt::CTRL : // DeleteWordRight
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
95 case Qt::Key_L | Qt::CTRL | Qt::SHIFT : // LineDelete
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
96 case Qt::Key_L | Qt::CTRL : // LineCut
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
97 case Qt::Key_T | Qt::CTRL | Qt::SHIFT : // LineCopy
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
98 cmd_list.at (i)->setKey (0);
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
99 }
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
100 }
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
101 #endif
18954
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
102
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
103 #if defined (Q_OS_MAC)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
104 // Octave interprets Cmd key as Meta whereas Qscintilla interprets it
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
105 // as Ctrl. We thus invert Meta/Ctrl in Qscintilla's shortcuts list.
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
106 QList< QsciCommand * > cmd_list_mac = cmd_set->commands ();
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
107 for (int i = 0; i < cmd_list_mac.length (); i++)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
108 {
19595
be7ac98fab43 strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents: 19426
diff changeset
109 // Primary key
18954
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
110 int key = cmd_list_mac.at (i)->key ();
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
111
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
112 if (static_cast<int> (key | Qt::META) == key &&
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
113 static_cast<int> (key | Qt::CTRL) != key)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
114 key = (key ^ Qt::META) | Qt::CTRL;
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
115 else if (static_cast<int> (key | Qt::CTRL) == key)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
116 key = (key ^ Qt::CTRL) | Qt::META;
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
117
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
118 cmd_list_mac.at (i)->setKey (key);
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
119
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
120 // Alternate key
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
121 key = cmd_list_mac.at (i)->alternateKey ();
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
122
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
123 if (static_cast<int> (key | Qt::META) == key &&
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
124 static_cast<int> (key | Qt::CTRL) != key)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
125 key = (key ^ Qt::META) | Qt::CTRL;
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
126 else if (static_cast<int> (key | Qt::CTRL) == key)
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
127 key = (key ^ Qt::CTRL) | Qt::META;
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
128
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
129 cmd_list_mac.at (i)->setAlternateKey (key);
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
130 }
c6b89c4a9e63 Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents: 18767
diff changeset
131 #endif
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
132
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
133 // init state of undo/redo action for this tab
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
134 emit status_update (isUndoAvailable (), isRedoAvailable ());
18560
26d15a57f45b add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
135 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
136
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
137 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
138 { }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
139
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
140 void
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
141 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
142 QPoint *local_pos)
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
143 {
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
144 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
145 long point_x = SendScintilla
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
146 (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
147 long point_y = SendScintilla
18656
1b289f45187f add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents: 18560
diff changeset
148 (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
149 *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
150 *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
151 }
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
152
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
153 // 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
154 bool
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
155 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
156 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
157 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
158 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
159 _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
160 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
161 return ((lexer_name == "octave" || lexer_name == "matlab")
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20277
diff changeset
162 && ! _word_at_cursor.isEmpty ());
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
163 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
164
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
165 // 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
166 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
167 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
168 {
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
169 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
170 contextmenu_help_doc (documentation);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
171 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
172
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
173 // 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
174 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
175 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
176 {
17655
b4783277bd11 *octave-qscintilla.cc: fix edit function at cursor by shortcut Ctrl-E
Torsten <ttl@justmail.de>
parents: 17635
diff changeset
177 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
178 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
179 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
180
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
181 // 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
182 void
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
183 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
184 {
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
185 if (hasSelectedText ())
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
186 contextmenu_run (true);
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
187 }
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
188
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
189 // 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
190 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
191 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
192 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
193 #if defined (HAVE_QSCI_VERSION_2_6_0)
18687
99e26cb0f87f use the actions from the editor for the context menu
Torsten <ttl@justmail.de>
parents: 18684
diff changeset
194 QPoint global_pos, local_pos; // the menu's position
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18656
diff changeset
195 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
196
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
197 bool in_left_margin = false;
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
198
18687
99e26cb0f87f use the actions from the editor for the context menu
Torsten <ttl@justmail.de>
parents: 18684
diff changeset
199 // determine position depending on mouse or keyboard event
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
200 if (e->reason () == QContextMenuEvent::Mouse)
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
201 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
202 // 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
203 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
204 local_pos = e->pos (); // local mouse position
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
205 if (e->x () < marginWidth (1) + marginWidth (2))
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
206 in_left_margin = true;
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
207 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
208 else
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
209 {
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
210 // 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
211 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
212 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
213 editor_rect.moveTopLeft
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
214 (parentWidget ()->mapToGlobal (editor_rect.topLeft ()));
20955
77f5591878bf maint: Use '! expr' rather than '!expr' to conform to coding guidelines.
Rik <rik@octave.org>
parents: 20277
diff changeset
215 if (! editor_rect.contains (global_pos)) // is cursor outside editor?
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
216 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
217 }
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
218
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
219 #if defined (HAVE_QSCI_VERSION_2_6_0)
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
220 if (! in_left_margin)
21371
dc3252099232 Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21301
diff changeset
221 #endif
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
222 {
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
223 // fill context menu with editor's standard actions
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
224 emit create_context_menu_signal (context_menu);
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
225
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
226 // additional custom entries of the context menu
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
227 context_menu->addSeparator (); // separator before custom entries
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
228
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
229 // help menu: get the position of the mouse or the text cursor
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
230 // (only for octave files)
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
231 QString lexer_name = lexer ()->lexer ();
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
232 if (lexer_name == "octave" || lexer_name == "matlab")
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
233 {
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
234 _word_at_cursor = wordAtPoint (local_pos);
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
235 if (! _word_at_cursor.isEmpty ())
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
236 {
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
237 context_menu->addAction (tr ("Help on") + " " + _word_at_cursor,
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
238 this, SLOT (contextmenu_help (bool)));
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
239 context_menu->addAction (tr ("Documentation on")
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
240 + " " + _word_at_cursor,
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
241 this, SLOT (contextmenu_doc (bool)));
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
242 context_menu->addAction (tr ("Edit") + " " + _word_at_cursor,
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
243 this, SLOT (contextmenu_edit (bool)));
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
244 }
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
245 }
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
246 }
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
247 #if defined (HAVE_QSCI_VERSION_2_6_0)
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
248 else
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
249 {
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
250 // remove all standard actions from scintilla
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
251 QList<QAction *> all_actions = context_menu->actions ();
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
252 QAction* a;
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
253
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
254 foreach (a, all_actions)
23223
4b642b593ec2 maint: Indent foreach blocks in Qt GUI code for readability.
Rik <rik@octave.org>
parents: 23220
diff changeset
255 context_menu->removeAction (a);
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
256
22411
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
257 a = context_menu->addAction (tr ("dbstop if ..."), this,
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
258 SLOT (contextmenu_break_condition (bool)));
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
259 a->setData (local_pos);
c69805d1fa64 maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents: 22323
diff changeset
260 }
21371
dc3252099232 Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21301
diff changeset
261 #endif
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
262
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
263 // 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
264 context_menu->exec (global_pos);
20277
48d9001bdee3 Avoid HAVE_ macros in header file.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
265 #endif
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
266 }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
267
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
268 // 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
269 void
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
270 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
271 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
272 contextmenu_help_doc (true);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
273 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
274 void
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
275 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
276 {
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
277 contextmenu_help_doc (false);
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
278 }
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
279
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
280 // 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
281 void
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
282 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
283 {
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
284 if (documentation)
19606
3156773fcc80 open a doc page from editor directly without command window
Torsten <ttl@justmail.de>
parents: 19595
diff changeset
285 emit show_doc_signal (_word_at_cursor);
17627
811019b9ef57 Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents: 16768
diff changeset
286 else
19606
3156773fcc80 open a doc page from editor directly without command window
Torsten <ttl@justmail.de>
parents: 19595
diff changeset
287 emit execute_command_in_terminal_signal ("help " + _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
288 }
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
289
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
290 void
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
291 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
292 {
19004
e87e65bc71ae improved finding a function file for editing in gui (bug #41509)
Torsten <ttl@justmail.de>
parents: 19002
diff changeset
293 emit context_menu_edit_signal (_word_at_cursor);
17628
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
294 }
99ffa521ecec Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents: 17627
diff changeset
295
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
296 void
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
297 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
298 {
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
299 QStringList commands = selectedText ().split (QRegExp ("[\r\n]"),
17790
86c6ae5f969e Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents: 17669
diff changeset
300 QString::SkipEmptyParts);
18678
6113e0c6920b maint: Clean up extra spaces before/after parentheses.
Rik <rik@octave.org>
parents: 18656
diff changeset
301 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
302 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
303 }
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
304
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
305 // wrappers for dbstop related context menu items
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
306
21578
683a1beee538 maint: Use "FIXME:" for all code blocks needing further attention.
Rik <rik@octave.org>
parents: 21371
diff changeset
307 // FIXME: Why can't the data be sent as the argument to the function???
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
308 void
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
309 octave_qscintilla::contextmenu_break_condition (bool)
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
310 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
311 #if defined (HAVE_QSCI_VERSION_2_6_0)
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
312 QAction *action = qobject_cast<QAction *>(sender ());
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
313 QPoint local_pos = action->data ().value<QPoint> ();
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
314
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
315 // pick point just right of margins, so lineAt doesn't give -1
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
316 int margins = marginWidth (1) + marginWidth (2) + marginWidth (3);
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
317 local_pos = QPoint (margins + 1, local_pos.y ());
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
318
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
319 emit context_menu_break_condition_signal (lineAt (local_pos));
21371
dc3252099232 Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21301
diff changeset
320 #endif
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
321 }
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
322
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
323 void
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
324 octave_qscintilla::contextmenu_break_once (const QPoint& local_pos)
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
325 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
326 #if defined (HAVE_QSCI_VERSION_2_6_0)
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
327 emit context_menu_break_once (lineAt (local_pos));
21371
dc3252099232 Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents: 21301
diff changeset
328 #endif
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
329 }
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
330
18684
86eca5d178a6 disable some global shortcuts when editor gets focus to prevent conflicts
Torsten <ttl@justmail.de>
parents: 18675
diff changeset
331 void
18689
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
332 octave_qscintilla::text_changed ()
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
333 {
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
334 emit status_update (isUndoAvailable (), isRedoAvailable ());
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
335 }
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
336
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
337 // when edit area gets focus update information on undo/redo actions
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
338 void octave_qscintilla::focusInEvent (QFocusEvent *focusEvent)
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
339 {
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
340 emit status_update (isUndoAvailable (), isRedoAvailable ());
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
341
23070
bef714f45999 maint: Use space after function name/before parenthesis in libgui.
Rik <rik@octave.org>
parents: 22755
diff changeset
342 QsciScintilla::focusInEvent (focusEvent);
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
343 }
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
344
23190
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
345 // helper function for clearing all indicators of a specific style
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
346 void
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
347 octave_qscintilla::clear_indicator (int indicator_style)
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
348 {
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
349 int end_pos = text ().length ();
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
350 int end_line, end_col;
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
351 lineIndexFromPosition (end_pos, &end_line, &end_col);
4a2c42792d6c highlight all occurrences of a selected word in the editor (bug #41470)
Torsten <mttl@mailbox.org>
parents: 23084
diff changeset
352 clearIndicatorRange (0, 0, end_line, end_col, indicator_style);
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
353 }
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
354
23230
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
355 // Function returning the true cursor position where the tab length
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
356 // is taken into account.
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
357 void
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
358 octave_qscintilla::get_current_position (int *pos, int *line, int *col)
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
359 {
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
360 *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS);
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
361 *line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos);
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
362 *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos);
f7fdc9ef3971 improve line breaking in the editor
Torsten <mttl@mailbox.org>
parents: 23223
diff changeset
363 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
364 #endif