Mercurial > octave
annotate libgui/src/m-editor/octave-qscintilla.cc @ 24187:ff9bd559799b
pop up tooltip message for changing selected words in editor
* octave-qscintilla.h, octave-qscintilla.cc
(octave_qscintilla::m_selection_replacement): New data member.
(octave_qscintilla::set_word_selection): Also initialize
m_selection_replacement and hide tooltip when clearing word selection.
(octave_qscintilla::keyPressEvent): New function. Handle replacement
of selected word.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 24 Oct 2017 17:13:51 -0400 |
parents | 90903d915625 |
children | 90fe16a3a5a1 |
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 | 23 // Author: Torsten <ttl@justmail.de> |
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 |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
31 #include <Qsci/qscilexer.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
32 |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
33 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
34 # define HAVE_LEXER_OCTAVE 1 |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
35 # include <Qsci/qscilexeroctave.h> |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
36 #elif defined (HAVE_QSCI_QSCILEXERMATLAB_H) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
37 # define HAVE_LEXER_MATLAB 1 |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
38 # include <Qsci/qscilexermatlab.h> |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
39 #endif |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
40 #include <Qsci/qscilexercpp.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
41 #include <Qsci/qscilexerbash.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
42 #include <Qsci/qscilexerperl.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
43 #include <Qsci/qscilexerbatch.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
44 #include <Qsci/qscilexerdiff.h> |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
45 |
18656
1b289f45187f
add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents:
18560
diff
changeset
|
46 #include <Qsci/qscicommandset.h> |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
47 |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
48 #include <QKeySequence> |
18560
26d15a57f45b
add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents:
18460
diff
changeset
|
49 #include <QShortcut> |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
50 #include <QToolTip> |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
51 #include <QVBoxLayout> |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
52 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
53 // FIXME: hardwired marker numbers? |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
54 #include "marker.h" |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
55 |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
56 #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
|
57 #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
|
58 #include "shortcut-manager.h" |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
59 #include "resource-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
|
60 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
61 // Return true if CANDIDATE is a "closing" that matches OPENING, |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
62 // such as "end" or "endif" for "if", or "catch" for "try". |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
63 // Used for testing the last word of an "if" etc. line, |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
64 // or the first word of the following line. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
65 static bool |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
66 is_end (const QString& candidate, const QString& opening) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
67 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
68 bool retval = false; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
69 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
70 if (opening == "do") // The only one that can't be ended by "end" |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
71 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
72 if (candidate == "until") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
73 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
74 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
75 else |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
76 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
77 if (candidate == "end") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
78 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
79 else |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
80 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
81 if (opening == "try") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
82 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
83 if (candidate == "catch" || candidate == "end_try_catch") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
84 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
85 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
86 else if (opening == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
87 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
88 if (candidate == "unwind_protect_cleanup" |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
89 || candidate == "end_unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
90 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
91 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
92 else if (candidate == "end" + opening) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
93 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
94 else if (opening == "if" && candidate == "else") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
95 retval = true; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
96 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
97 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
98 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
99 return retval; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
100 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
101 |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
102 octave_qscintilla::octave_qscintilla (QWidget *p) |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
103 : QsciScintilla (p), m_word_at_cursor (), m_selection (), |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
104 m_selection_replacement (), m_selection_line (-1), |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
105 m_selection_col (-1), m_indicator_id (1) |
18560
26d15a57f45b
add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents:
18460
diff
changeset
|
106 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
107 connect (this, SIGNAL (textChanged (void)), this, SLOT (text_changed (void))); |
18689
fac35875f6eb
update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents:
18687
diff
changeset
|
108 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
109 connect (this, SIGNAL (cursorPositionChanged (int, int)), |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
110 this, SLOT (cursor_position_changed (int, int))); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
111 |
18656
1b289f45187f
add some qscintilla actions to the menu and to the shortcut manager
Torsten <ttl@justmail.de>
parents:
18560
diff
changeset
|
112 // 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
|
113 QsciCommandSet *cmd_set = standardCommands (); |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
114 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
115 #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
|
116 // 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
|
117 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
|
118 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
|
119 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
|
120 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
|
121 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
|
122 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
|
123 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
|
124 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
|
125 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
|
126 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
|
127 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
|
128 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
|
129 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
|
130 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
|
131 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
|
132 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
|
133 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
|
134 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
|
135 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
|
136 #else |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
137 // 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
|
138 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
|
139 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
|
140 { |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
141 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
|
142 switch (cmd_key) |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
143 { |
22411
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
144 case Qt::Key_C | Qt::CTRL : // SelectionCopy |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
145 case Qt::Key_X | Qt::CTRL : // SelectionCut |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
146 case Qt::Key_V | Qt::CTRL : // Paste |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
147 case Qt::Key_A | Qt::CTRL : // SelectAll |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
148 case Qt::Key_D | Qt::CTRL : // SelectionDuplicate |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
149 case Qt::Key_T | Qt::CTRL : // LineTranspose |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
150 case Qt::Key_Z | Qt::CTRL : // Undo |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
151 case Qt::Key_Y | Qt::CTRL : // Redo |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
152 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
|
153 case Qt::Key_U | Qt::CTRL : // SelectionLowerCase |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
154 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
|
155 case Qt::Key_Plus | Qt::CTRL : // ZoomIn |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
156 case Qt::Key_Minus | Qt::CTRL : // ZoomOut |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
157 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
|
158 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
|
159 case Qt::Key_K | Qt::META : // DeleteLineRight |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
160 case Qt::Key_Backspace | Qt::CTRL : // DeleteWordLeft |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
161 case Qt::Key_Delete | Qt::CTRL : // DeleteWordRight |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
162 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
|
163 case Qt::Key_L | Qt::CTRL : // LineCut |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
164 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
|
165 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
|
166 } |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
167 } |
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
168 #endif |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
169 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
170 #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
|
171 // 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
|
172 // 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
|
173 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
|
174 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
|
175 { |
19595
be7ac98fab43
strip trailing whitespace from most source files
John W. Eaton <jwe@octave.org>
parents:
19426
diff
changeset
|
176 // 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
|
177 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
|
178 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
185 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
|
186 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
187 // Alternate key |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
188 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
|
189 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
190 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
|
191 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
|
192 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
|
193 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
|
194 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
|
195 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
196 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
|
197 } |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
198 #endif |
20986
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
199 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
200 // selection markers |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
201 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
202 m_indicator_id = indicatorDefine (QsciScintilla::StraightBoxIndicator); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
203 if (m_indicator_id == -1) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
204 m_indicator_id = 1; |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
205 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
206 setIndicatorDrawUnder (true, m_indicator_id); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
207 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
208 markerDefine (QsciScintilla::Minus, marker::selection); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
209 |
20986
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
210 // 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
|
211 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
|
212 } |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
213 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
214 void |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
215 octave_qscintilla::set_selection_marker_color (const QColor& c) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
216 { |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
217 QColor ic = c; |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
218 ic.setAlphaF (0.25); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
219 setIndicatorForegroundColor (ic, m_indicator_id); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
220 setIndicatorOutlineColor (ic, m_indicator_id); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
221 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
222 setMarkerForegroundColor (c, marker::selection); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
223 setMarkerBackgroundColor (c, marker::selection); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
224 } |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
225 |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
226 // 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
|
227 void |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
228 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
|
229 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
230 #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
|
231 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
|
232 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
|
233 |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
234 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
|
235 |
18687
99e26cb0f87f
use the actions from the editor for the context menu
Torsten <ttl@justmail.de>
parents:
18684
diff
changeset
|
236 // 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
|
237 if (e->reason () == QContextMenuEvent::Mouse) |
17790
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17669
diff
changeset
|
238 { |
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17669
diff
changeset
|
239 // 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
|
240 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
|
241 local_pos = e->pos (); // local mouse position |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
242 if (e->x () < marginWidth (1) + marginWidth (2)) |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
243 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
|
244 } |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
245 else |
17790
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17669
diff
changeset
|
246 { |
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17669
diff
changeset
|
247 // 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
|
248 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
|
249 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
|
250 editor_rect.moveTopLeft |
17790
86c6ae5f969e
Use GNU style coding conventions for code in libgui/
Rik <rik@octave.org>
parents:
17669
diff
changeset
|
251 (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
|
252 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
|
253 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
|
254 } |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
255 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
256 #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
|
257 if (! in_left_margin) |
21371
dc3252099232
Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
258 #endif |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
259 { |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
260 // fill context menu with editor's standard actions |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
261 emit create_context_menu_signal (context_menu); |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
262 |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
263 // additional custom entries of the context menu |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
264 context_menu->addSeparator (); // separator before custom entries |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
265 |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
266 // 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
|
267 // (only for octave files) |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
268 QString lexer_name = lexer ()->lexer (); |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
269 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
|
270 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
271 m_word_at_cursor = wordAtPoint (local_pos); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
272 if (! m_word_at_cursor.isEmpty ()) |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
273 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
274 context_menu->addAction (tr ("Help on") + ' ' + m_word_at_cursor, |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
275 this, SLOT (contextmenu_help (bool))); |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
276 context_menu->addAction (tr ("Documentation on") |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
277 + ' ' + m_word_at_cursor, |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
278 this, SLOT (contextmenu_doc (bool))); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
279 context_menu->addAction (tr ("Edit") + ' ' + m_word_at_cursor, |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
280 this, SLOT (contextmenu_edit (bool))); |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
281 } |
17635
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
282 } |
22411
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
283 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
284 #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
|
285 else |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
286 { |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
287 // remove all standard actions from scintilla |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
288 QList<QAction *> all_actions = context_menu->actions (); |
23449
c763214a8260
maint: Use convention 'int *x' for naming pointers.
Rik <rik@octave.org>
parents:
23236
diff
changeset
|
289 QAction *a; |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
290 |
22411
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
291 foreach (a, all_actions) |
23223
4b642b593ec2
maint: Indent foreach blocks in Qt GUI code for readability.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
292 context_menu->removeAction (a); |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
293 |
22411
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
294 a = context_menu->addAction (tr ("dbstop if ..."), this, |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
295 SLOT (contextmenu_break_condition (bool))); |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
296 a->setData (local_pos); |
c69805d1fa64
maint: Style check C++ code in libgui/
Rik <rik@octave.org>
parents:
22323
diff
changeset
|
297 } |
21371
dc3252099232
Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
298 #endif |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
299 |
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
300 // 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
|
301 context_menu->exec (global_pos); |
20277
48d9001bdee3
Avoid HAVE_ macros in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
302 #endif |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
303 } |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
304 |
17627
811019b9ef57
Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents:
16768
diff
changeset
|
305 // 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
|
306 void |
811019b9ef57
Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents:
16768
diff
changeset
|
307 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
|
308 { |
811019b9ef57
Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents:
16768
diff
changeset
|
309 if (documentation) |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
310 emit show_doc_signal (m_word_at_cursor); |
17627
811019b9ef57
Add help and documentation on actual keyword to the editor menu
Torsten <ttl@justmail.de>
parents:
16768
diff
changeset
|
311 else |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
312 emit execute_command_in_terminal_signal ("help " + m_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
|
313 } |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
314 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
315 // call edit the function related to the current word |
17628
99ffa521ecec
Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents:
17627
diff
changeset
|
316 void |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
317 octave_qscintilla::context_edit (void) |
17628
99ffa521ecec
Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents:
17627
diff
changeset
|
318 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
319 if (get_actual_word ()) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
320 contextmenu_edit (true); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
321 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
322 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
323 // call edit the function related to the current word |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
324 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
325 octave_qscintilla::context_run (void) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
326 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
327 if (hasSelectedText ()) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
328 contextmenu_run (true); |
17628
99ffa521ecec
Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents:
17627
diff
changeset
|
329 } |
99ffa521ecec
Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents:
17627
diff
changeset
|
330 |
17635
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
331 void |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
332 octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos, |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
333 QPoint *local_pos) |
17635
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
334 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
335 long position = SendScintilla (SCI_GETCURRENTPOS); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
336 long point_x = SendScintilla |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
337 (SCI_POINTXFROMPOSITION,0,position); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
338 long point_y = SendScintilla |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
339 (SCI_POINTYFROMPOSITION,0,position); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
340 *local_pos = QPoint (point_x,point_y); // local cursor position |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
341 *global_pos = mapToGlobal (*local_pos); // global position of cursor |
17635
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
342 } |
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
343 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
344 // determine the actual word and whether we are in an octave or matlab script |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
345 bool |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
346 octave_qscintilla::get_actual_word (void) |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
347 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
348 QPoint global_pos, local_pos; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
349 get_global_textcursor_pos (&global_pos, &local_pos); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
350 m_word_at_cursor = wordAtPoint (local_pos); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
351 QString lexer_name = lexer ()->lexer (); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
352 return ((lexer_name == "octave" || lexer_name == "matlab") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
353 && ! m_word_at_cursor.isEmpty ()); |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
354 } |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
355 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
356 // helper function for clearing all indicators of a specific style |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
357 void |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
358 octave_qscintilla::clear_selection_markers (void) |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
359 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
360 int end_pos = text ().length (); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
361 int end_line, end_col; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
362 lineIndexFromPosition (end_pos, &end_line, &end_col); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
363 clearIndicatorRange (0, 0, end_line, end_col, m_indicator_id); |
24171
1680d425bb38
also place marker in editor margin for lines matching selected word
John W. Eaton <jwe@octave.org>
parents:
24166
diff
changeset
|
364 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
365 markerDeleteAll (marker::selection); |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
366 } |
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
367 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
368 // Function returning the true cursor position where the tab length |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
369 // is taken into account. |
18684
86eca5d178a6
disable some global shortcuts when editor gets focus to prevent conflicts
Torsten <ttl@justmail.de>
parents:
18675
diff
changeset
|
370 void |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
371 octave_qscintilla::get_current_position (int *pos, int *line, int *col) |
18689
fac35875f6eb
update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents:
18687
diff
changeset
|
372 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
373 *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
374 *line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
375 *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos); |
20986
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
376 } |
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
377 |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
378 // Function returning the comment string of the current lexer |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
379 QString |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
380 octave_qscintilla::comment_string (void) |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
381 { |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
382 int lexer = SendScintilla (SCI_GETLEXER); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
383 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
384 switch (lexer) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
385 { |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
386 #if defined (HAVE_LEXER_MATLAB) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
387 case SCLEX_MATLAB: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
388 #if defined (HAVE_LEXER_OCTAVE) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
389 case SCLEX_OCTAVE: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
390 #endif |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
391 { |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
392 QSettings *settings = resource_manager::get_settings (); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
393 int comment_index |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
394 = settings->value ("editor/octave_comment_string", 0).toInt (); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
395 if (comment_index == 1) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
396 return QString ("#"); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
397 else if (comment_index == 2) |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
398 return QString ("%"); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
399 else |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
400 return QString ("##"); // default and for index 0 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
401 } |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
402 #endif |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
403 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
404 case SCLEX_PERL: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
405 case SCLEX_BASH: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
406 case SCLEX_DIFF: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
407 return QString ("#"); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
408 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
409 case SCLEX_CPP: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
410 return QString ("//"); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
411 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
412 case SCLEX_BATCH: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
413 return QString ("REM "); |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
414 } |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
415 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
416 return QString ("%"); // should never happen |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
417 } |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
418 |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
419 // provide the style at a specific position |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
420 int |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
421 octave_qscintilla::get_style (int pos) |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
422 { |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
423 int position; |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
424 if (pos < 0) |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
425 // The positition has to be reduced by 2 for getting the real style (?) |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
426 position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2; |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
427 else |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
428 position = pos; |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
429 |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
430 return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position); |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
431 } |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
432 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
433 // Is a specific cursor position in a line or block comment? |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
434 int |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
435 octave_qscintilla::is_style_comment (int pos) |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
436 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
437 int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
438 int style = get_style (pos); |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
439 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
440 switch (lexer) |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
441 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
442 case SCLEX_CPP: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
443 return (ST_LINE_COMMENT * ( |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
444 style == QsciLexerCPP::CommentLine |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
445 || style == QsciLexerCPP::CommentLineDoc) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
446 + ST_BLOCK_COMMENT * ( |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
447 style == QsciLexerCPP::Comment |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
448 || style == QsciLexerCPP::CommentDoc |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
449 || style == QsciLexerCPP::CommentDocKeyword |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
450 || style == QsciLexerCPP::CommentDocKeywordError) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
451 ); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
452 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
453 #if defined (HAVE_LEXER_MATLAB) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
454 case SCLEX_MATLAB: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
455 return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
456 #endif |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
457 #if defined (HAVE_LEXER_OCTAVE) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
458 case SCLEX_OCTAVE: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
459 return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
460 #endif |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
461 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
462 case SCLEX_PERL: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
463 return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
464 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
465 case SCLEX_BATCH: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
466 return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
467 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
468 case SCLEX_DIFF: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
469 return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
470 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
471 case SCLEX_BASH: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
472 return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
473 |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
474 } |
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
475 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
476 return ST_NONE; |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
477 } |
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
478 |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
479 // Do smart indendation after if, for, ... |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
480 void |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
481 octave_qscintilla::smart_indent (bool do_smart_indent, |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
482 int do_auto_close, int line) |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
483 { |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
484 QString prevline = text (line); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
485 |
24160
d0cee5e09879
fix auto close for case in editor (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24020
diff
changeset
|
486 QRegExp bkey = QRegExp ("^[\t ]*(if|for|while|switch|case|otherwise" |
d0cee5e09879
fix auto close for case in editor (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24020
diff
changeset
|
487 "|do|function|properties|events|classdef" |
24166
37190507b5d7
fix issues in editor auto closing feature (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24160
diff
changeset
|
488 "|unwind_protect|unwind_protect_cleanup|try" |
37190507b5d7
fix issues in editor auto closing feature (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24160
diff
changeset
|
489 "|parfor|methods)" |
23735
6798f5e5c58e
Add possible '\r' to smartindent regex exprepression (Bug #51279)
John D
parents:
23698
diff
changeset
|
490 "[\r]?[\n\t #%]"); |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
491 // last word except for comments, assuming no ' or " in comment. |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
492 // rx_end = QRegExp ("(\\w+)[ \t;\r\n]*([%#][^\"']*)?$"); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
493 |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
494 // last word except for comments, |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
495 // allowing % and # in single or double quoted strings |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
496 // FIXME This will get confused by transpose. |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
497 QRegExp ekey = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
498 "(\\w+)[ \t;\r\n]*([%#].*)?$"); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
499 |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
500 int bpos = bkey.indexIn (prevline, 0); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
501 int epos; |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
502 |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
503 if (bpos > -1) |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
504 { |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
505 // Found keyword after that indentation should be added |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
506 |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
507 // Check for existing end statement in the same line |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
508 epos = ekey.indexIn (prevline, bpos); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
509 QString first_word = bkey.cap(1); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
510 bool inline_end = (epos > -1) && is_end (ekey.cap(1), first_word); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
511 |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
512 if (do_smart_indent && ! inline_end) |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
513 { |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
514 // Do smart indent in the current line (line+1) |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
515 indent (line+1); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
516 setCursorPosition (line+1, indentation (line) + indentationWidth ()); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
517 } |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
518 |
24160
d0cee5e09879
fix auto close for case in editor (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24020
diff
changeset
|
519 if (do_auto_close |
d0cee5e09879
fix auto close for case in editor (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24020
diff
changeset
|
520 && ! inline_end |
24166
37190507b5d7
fix issues in editor auto closing feature (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24160
diff
changeset
|
521 && ! first_word.contains ( |
37190507b5d7
fix issues in editor auto closing feature (bug #52235)
Torsten <mttl@mailbox.org>
parents:
24160
diff
changeset
|
522 QRegExp ("(case|otherwise|unwind_protect_cleanup)"))) |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
523 { |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
524 // Do auto close |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
525 auto_close (do_auto_close, line, prevline, first_word); |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
526 } |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
527 |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
528 return; |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
529 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
530 |
23735
6798f5e5c58e
Add possible '\r' to smartindent regex exprepression (Bug #51279)
John D
parents:
23698
diff
changeset
|
531 QRegExp mkey = QRegExp ("^[\t ]*(else|elseif|catch)[\r]?[\t #%\n]"); |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
532 if (prevline.contains (mkey)) |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
533 { |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
534 int prev_ind = indentation (line-1); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
535 int act_ind = indentation (line); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
536 |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
537 if (prev_ind == act_ind) |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
538 unindent (line); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
539 else if (prev_ind > act_ind) |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
540 { |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
541 setIndentation (line+1, prev_ind); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
542 setCursorPosition (line+1, prev_ind); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
543 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
544 return; |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
545 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
546 |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
547 ekey = QRegExp ("^[\t ]*(end|endif|endfor|endwhile|until|endfunction" |
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
548 "|end_try_catch|end_unwind_protext)[\r]?[\t #%\n(;]"); |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
549 if (prevline.contains (ekey)) |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
550 { |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
551 if (indentation (line-1) <= indentation (line)) |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
552 { |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
553 unindent (line+1); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
554 unindent (line); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
555 setCursorPosition (line+1, |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
556 indentation (line)); |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
557 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
558 return; |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
559 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
560 |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
561 } |
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
562 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
563 void |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
564 octave_qscintilla::set_word_selection (const QString& word) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
565 { |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
566 m_selection = word; |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
567 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
568 if (word.isEmpty ()) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
569 { |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
570 m_selection_line = -1; |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
571 m_selection_col = -1; |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
572 |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
573 m_selection_replacement = ""; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
574 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
575 clear_selection_markers (); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
576 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
577 QToolTip::hideText (); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
578 } |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
579 else |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
580 getCursorPosition (&m_selection_line, &m_selection_col); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
581 } |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
582 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
583 void |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
584 octave_qscintilla::show_selection_markers (int line, int col, int len) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
585 { |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
586 fillIndicatorRange (line, col - len, line, col, m_indicator_id); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
587 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
588 markerAdd (line, marker::selection); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
589 } |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
590 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
591 void |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
592 octave_qscintilla::contextmenu_help (bool) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
593 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
594 contextmenu_help_doc (false); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
595 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
596 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
597 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
598 octave_qscintilla::contextmenu_doc (bool) |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
599 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
600 contextmenu_help_doc (true); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
601 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
602 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
603 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
604 octave_qscintilla::context_help_doc (bool documentation) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
605 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
606 if (get_actual_word ()) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
607 contextmenu_help_doc (documentation); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
608 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
609 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
610 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
611 octave_qscintilla::contextmenu_edit (bool) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
612 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
613 emit context_menu_edit_signal (m_word_at_cursor); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
614 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
615 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
616 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
617 octave_qscintilla::contextmenu_run (bool) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
618 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
619 QStringList commands = selectedText ().split (QRegExp ("[\r\n]"), |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
620 QString::SkipEmptyParts); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
621 for (int i = 0; i < commands.size (); i++) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
622 emit execute_command_in_terminal_signal (commands.at (i)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
623 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
624 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
625 // wrappers for dbstop related context menu items |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
626 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
627 // FIXME: Why can't the data be sent as the argument to the function??? |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
628 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
629 octave_qscintilla::contextmenu_break_condition (bool) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
630 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
631 #if defined (HAVE_QSCI_VERSION_2_6_0) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
632 QAction *action = qobject_cast<QAction *>(sender ()); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
633 QPoint local_pos = action->data ().value<QPoint> (); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
634 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
635 // pick point just right of margins, so lineAt doesn't give -1 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
636 int margins = marginWidth (1) + marginWidth (2) + marginWidth (3); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
637 local_pos = QPoint (margins + 1, local_pos.y ()); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
638 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
639 emit context_menu_break_condition_signal (lineAt (local_pos)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
640 #endif |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
641 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
642 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
643 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
644 octave_qscintilla::contextmenu_break_once (const QPoint& local_pos) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
645 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
646 #if defined (HAVE_QSCI_VERSION_2_6_0) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
647 emit context_menu_break_once (lineAt (local_pos)); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
648 #endif |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
649 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
650 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
651 void |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
652 octave_qscintilla::text_changed (void) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
653 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
654 emit status_update (isUndoAvailable (), isRedoAvailable ()); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
655 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
656 |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
657 void |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
658 octave_qscintilla::cursor_position_changed (int line, int col) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
659 { |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
660 // Clear the selection if we move away from it. We have to check the |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
661 // position, because we allow entering text at the point of the |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
662 // selection to trigger a search and replace that does not clear the |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
663 // selection until it is complete. |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
664 |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
665 if (! m_selection.isEmpty () |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
666 && (line != m_selection_line || col != m_selection_col)) |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
667 set_word_selection (); |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
668 } |
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
669 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
670 // when edit area gets focus update information on undo/redo actions |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
671 void octave_qscintilla::focusInEvent (QFocusEvent *focusEvent) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
672 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
673 emit status_update (isUndoAvailable (), isRedoAvailable ()); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
674 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
675 QsciScintilla::focusInEvent (focusEvent); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
676 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
677 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
678 void |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
679 octave_qscintilla::keyPressEvent (QKeyEvent *key_event) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
680 { |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
681 if (m_selection.isEmpty ()) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
682 QsciScintilla::keyPressEvent (key_event); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
683 else |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
684 { |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
685 if (key_event->key () == Qt::Key_Return |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
686 && key_event->modifiers () == Qt::ShiftModifier) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
687 { |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
688 // get the resulting cursor position |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
689 // (required if click was beyond a line ending) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
690 int line, col; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
691 getCursorPosition (&line, &col); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
692 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
693 // remember first visible line for restoring the view afterwards |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
694 int first_line = firstVisibleLine (); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
695 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
696 // search for first occurrence of the detected word |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
697 bool find_result_available |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
698 = findFirst (m_selection, |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
699 false, // no regexp |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
700 true, // case sensitive |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
701 true, // whole words only |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
702 false, // do not wrap |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
703 true, // forward |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
704 0, 0, // from the beginning |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
705 false |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
706 #if defined (HAVE_QSCI_VERSION_2_6_0) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
707 , true |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
708 #endif |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
709 ); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
710 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
711 while (find_result_available) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
712 { |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
713 replace (m_selection_replacement); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
714 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
715 // FIXME: is this the right thing to do? findNext doesn't |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
716 // work properly if the length of the replacement text is |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
717 // different from the original. |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
718 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
719 int new_line, new_col; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
720 getCursorPosition (&new_line, &new_col); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
721 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
722 find_result_available |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
723 = findFirst (m_selection, |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
724 false, // no regexp |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
725 true, // case sensitive |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
726 true, // whole words only |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
727 false, // do not wrap |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
728 true, // forward |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
729 new_line, new_col, // from new pos |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
730 false |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
731 #if defined (HAVE_QSCI_VERSION_2_6_0) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
732 , true |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
733 #endif |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
734 ); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
735 } |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
736 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
737 // restore the visible area of the file, the cursor position, |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
738 // and the selection |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
739 setFirstVisibleLine (first_line); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
740 setCursorPosition (line, col); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
741 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
742 // Clear the selection. |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
743 set_word_selection (); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
744 } |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
745 else |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
746 { |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
747 // FIXME: End selection replacement if text is not valid as |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
748 // a word constituent (control characters, etc.). |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
749 // FIXME: Should backspace and delete remove the last |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
750 // character entered or end selection replacement? |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
751 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
752 m_selection_replacement += key_event->text (); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
753 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
754 // Perform default action. |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
755 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
756 QsciScintilla::keyPressEvent (key_event); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
757 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
758 getCursorPosition (&m_selection_line, &m_selection_col); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
759 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
760 // Offer to replace other instances. |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
761 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
762 QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
763 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
764 QString msg = (tr ("Press '%1' to replace all occurrences of '%2' with '%3'.") |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
765 . arg (keyseq.toString ()) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
766 . arg (m_selection) |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
767 . arg (m_selection_replacement)); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
768 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
769 QPoint global_pos; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
770 QPoint local_pos; |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
771 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
772 get_global_textcursor_pos (&global_pos, &local_pos); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
773 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
774 QFontMetrics ttfm (QToolTip::font ()); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
775 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
776 // Try to avoid overlapping with the text completion dialog |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
777 // and the text that is currently being edited. |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
778 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
779 global_pos += QPoint (2*ttfm.maxWidth (), -3*ttfm.height ()); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
780 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
781 QToolTip::showText (global_pos, msg); |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
782 } |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
783 } |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
784 } |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
785 |
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
786 void |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
787 octave_qscintilla::auto_close (int auto_endif, int linenr, |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
788 const QString& line, QString& first_word) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
789 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
790 // Insert and "end" for an "if" etc., if needed. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
791 // (Use of "while" allows "return" to skip the rest. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
792 // It may be clearer to use "if" and "goto", |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
793 // but that violates the coding standards.) |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
794 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
795 bool autofill_simple_end = (auto_endif == 2); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
796 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
797 size_t start = line.toStdString ().find_first_not_of (" \t"); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
798 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
799 // Check if following line has the same or less indentation |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
800 // Check if the following line does not start with |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
801 // end* (until) (catch) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
802 if (linenr < lines () - 1) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
803 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
804 int offset = 1; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
805 size_t next_start; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
806 QString next_line; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
807 do // find next non-blank line |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
808 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
809 next_line = text (linenr + offset++); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
810 next_start = next_line.toStdString ().find_first_not_of (" \t\n"); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
811 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
812 while (linenr + offset < lines () |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
813 && next_start == std::string::npos); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
814 if (next_start == std::string::npos) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
815 next_start = 0; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
816 if (next_start > start) // more indented => don't add "end" |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
817 return; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
818 if (next_start == start) // same => check if already is "end" |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
819 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
820 QRegExp rx_start = QRegExp (R"((\w+))"); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
821 int tmp = rx_start.indexIn (next_line, start); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
822 if (tmp != -1 && is_end (rx_start.cap(1), first_word)) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
823 return; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
824 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
825 } |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
826 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
827 // If all of the above, insert a new line, with matching indent |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
828 // and either 'end' or 'end...', depending on a flag. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
829 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
830 // If we insert directly after the last line, the "end" is autoindented, |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
831 // so add a dummy line. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
832 if (linenr + 2 == lines ()) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
833 insertAt (QString ("\n"), linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
834 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
835 // For try/catch/end, fill "end" first, so "catch" is top of undo stack |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
836 if (first_word == "try") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
837 insertAt (QString (start, ' ') |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
838 + (autofill_simple_end ? "end\n" : "end_try_catch\n"), |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
839 linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
840 else if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
841 insertAt (QString (start, ' ') |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
842 + (autofill_simple_end ? "end\n" : "end_unwind_protect\n"), |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
843 linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
844 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
845 QString next_line; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
846 if (first_word == "do") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
847 next_line = "until\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
848 else if (first_word == "try") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
849 next_line = "catch\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
850 else if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
851 next_line = "unwind_protect_cleanup\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
852 else if (autofill_simple_end) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
853 next_line = "end\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
854 else |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
855 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
856 if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
857 first_word = '_' + first_word; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
858 next_line = "end" + first_word + "\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
859 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
860 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
861 insertAt (QString (start, ' ') + next_line, linenr + 2, 0); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
862 } |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
863 |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
864 #endif |