annotate libgui/src/m-editor/octave-qscintilla.cc @ 31649:deb553ac2c54

maint: Merge stable to default.
author John W. Eaton <jwe@octave.org>
date Tue, 06 Dec 2022 15:45:27 -0500
parents 431f80aba37a 29d734430e5f
children 1a1f47f17ed4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
1 ////////////////////////////////////////////////////////////////////////
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
2 //
30564
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 30439
diff changeset
3 // Copyright (C) 2013-2022 The Octave Project Developers
27923
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
4 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
5 // See the file COPYRIGHT.md in the top-level directory of this
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
6 // distribution or <https://octave.org/copyright/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
7 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
8 // This file is part of Octave.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
9 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
10 // Octave is free software: you can redistribute it and/or modify it
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
11 // under the terms of the GNU General Public License as published by
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
12 // the Free Software Foundation, either version 3 of the License, or
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
13 // (at your option) any later version.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
14 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
15 // Octave is distributed in the hope that it will be useful, but
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
18 // GNU General Public License for more details.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
19 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
20 // You should have received a copy of the GNU General Public License
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
21 // along with Octave; see the file COPYING. If not, see
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
22 // <https://www.gnu.org/licenses/>.
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
23 //
bd51beb6205e update formatting of copyright notices
John W. Eaton <jwe@octave.org>
parents: 27919
diff changeset
24 ////////////////////////////////////////////////////////////////////////
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
25
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
26 #if defined (HAVE_CONFIG_H)
21301
40de9f8f23a6 Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents: 21203
diff changeset
27 # 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
28 #endif
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
29
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
30 #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
31
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
32 #include <Qsci/qscilexer.h>
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
33
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
34 #include <QDir>
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
35 #include <QKeySequence>
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
36 #include <QMessageBox>
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
37 #include <QMimeData>
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
38 #include <QShortcut>
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
39 #include <QToolTip>
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
40 #include <QVBoxLayout>
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
41 #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
42 # 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
43 # 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
44 #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
45 # 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
46 # 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
47 #endif
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
48 #include <Qsci/qscicommandset.h>
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
49 #include <Qsci/qscilexerbash.h>
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
50 #include <Qsci/qscilexerbatch.h>
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
51 #include <Qsci/qscilexercpp.h>
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
52 #include <Qsci/qscilexerdiff.h>
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
53 #include <Qsci/qscilexerperl.h>
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
54
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
55 #include "file-editor-tab.h"
27560
3fcc650de22f split gui-preferences.h into one file per widget
John W. Eaton <jwe@octave.org>
parents: 27556
diff changeset
56 #include "gui-preferences-ed.h"
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
57 #include "gui-settings.h"
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
58 // FIXME: hardwired marker numbers?
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
59 #include "marker.h"
27629
8b6e928e0705 in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
60 #include "octave-qobject.h"
27412
da1f59fe04b3 try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents: 27276
diff changeset
61 #include "octave-qscintilla.h"
25443
2fa7cd178c4a new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents: 25103
diff changeset
62 #include "shortcut-manager.h"
29613
9367cba2a6d5 allow most dock widgets to be used from command line
John W. Eaton <jwe@octave.org>
parents: 29572
diff changeset
63 #include "workspace-model.h"
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
64
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
65 #include "builtin-defun-decls.h"
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
66 #include "cmd-edit.h"
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
67 #include "interpreter-private.h"
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
68 #include "interpreter.h"
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
69
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
70 // 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
71 // 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
72 // 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
73 // or the first word of the following line.
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
74
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
75 OCTAVE_BEGIN_NAMESPACE(octave)
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
76
27101
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
77 static bool
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
78 is_end (const QString& candidate, const QString& opening)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
79 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
80 bool retval = false;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
81
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
82 if (opening == "do") // The only one that can't be ended by "end"
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
83 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
84 if (candidate == "until")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
85 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
86 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
87 else
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
88 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
89 if (candidate == "end")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
90 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
91 else
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
92 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
93 if (opening == "try")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
94 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
95 if (candidate == "catch" || candidate == "end_try_catch")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
96 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
97 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
98 else if (opening == "unwind_protect")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
99 {
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
100 if (candidate == "unwind_protect_cleanup"
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
101 || candidate == "end_unwind_protect")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
102 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
103 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
104 else if (candidate == "end" + opening)
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
105 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
106 else if (opening == "if" && candidate == "else")
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
107 retval = true;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
108 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
109 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
110
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
111 return retval;
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
112 }
097774bed4ed move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 26634
diff changeset
113
27629
8b6e928e0705 in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
114 octave_qscintilla::octave_qscintilla (QWidget *p, base_qobject& oct_qobj)
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
115 : QsciScintilla (p), m_octave_qobj (oct_qobj), m_debug_mode (false),
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
116 m_word_at_cursor (), m_selection (), m_selection_replacement (),
30633
754ad6e9c0a5 do not change tool tip font when in debug mode (bug #61792)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
117 m_selection_line (-1), m_selection_col (-1), m_indicator_id (1)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
118 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
119 connect (this, SIGNAL (textChanged (void)),
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
120 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
121
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
122 connect (this, SIGNAL (cursorPositionChanged (int, int)),
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
123 this, SLOT (cursor_position_changed (int, int)));
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
124
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
125 connect (this, &octave_qscintilla::ctx_menu_run_finished_signal,
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
126 this, &octave_qscintilla::ctx_menu_run_finished,
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
127 Qt::QueuedConnection);
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
128
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
129 // clear scintilla edit shortcuts that are handled by the editor
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
130 QsciCommandSet *cmd_set = standardCommands ();
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
131
25523
5daeb4049088 gui: fix editor rendering on some displays, disable QScintilla buffered drawing
Mike Miller <mtmiller@octave.org>
parents: 25103
diff changeset
132 // Disable buffered drawing on all systems
5daeb4049088 gui: fix editor rendering on some displays, disable QScintilla buffered drawing
Mike Miller <mtmiller@octave.org>
parents: 25103
diff changeset
133 SendScintilla (SCI_SETBUFFEREDDRAW, false);
5daeb4049088 gui: fix editor rendering on some displays, disable QScintilla buffered drawing
Mike Miller <mtmiller@octave.org>
parents: 25103
diff changeset
134
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
135 #if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
136 // find () was added in QScintilla 2.6
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
137 cmd_set->find (QsciCommand::SelectionCopy)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
138 cmd_set->find (QsciCommand::SelectionCut)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
139 cmd_set->find (QsciCommand::Paste)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
140 cmd_set->find (QsciCommand::SelectAll)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
141 cmd_set->find (QsciCommand::SelectionDuplicate)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
142 cmd_set->find (QsciCommand::LineTranspose)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
143 cmd_set->find (QsciCommand::Undo)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
144 cmd_set->find (QsciCommand::Redo)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
145 cmd_set->find (QsciCommand::SelectionUpperCase)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
146 cmd_set->find (QsciCommand::SelectionLowerCase)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
147 cmd_set->find (QsciCommand::ZoomIn)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
148 cmd_set->find (QsciCommand::ZoomOut)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
149 cmd_set->find (QsciCommand::DeleteWordLeft)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
150 cmd_set->find (QsciCommand::DeleteWordRight)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
151 cmd_set->find (QsciCommand::DeleteLineLeft)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
152 cmd_set->find (QsciCommand::DeleteLineRight)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
153 cmd_set->find (QsciCommand::LineDelete)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
154 cmd_set->find (QsciCommand::LineCut)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
155 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
156 #else
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
157 // find commands via its default key (tricky way without find ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
158 QList< QsciCommand * > cmd_list = cmd_set->commands ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
159 for (int i = 0; i < cmd_list.length (); i++)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
160 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
161 int cmd_key = cmd_list.at (i)->key ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
162 switch (cmd_key)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
163 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
164 case Qt::Key_C | Qt::CTRL : // SelectionCopy
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
165 case Qt::Key_X | Qt::CTRL : // SelectionCut
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
166 case Qt::Key_V | Qt::CTRL : // Paste
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
167 case Qt::Key_A | Qt::CTRL : // SelectAll
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
168 case Qt::Key_D | Qt::CTRL : // SelectionDuplicate
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
169 case Qt::Key_T | Qt::CTRL : // LineTranspose
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
170 case Qt::Key_Z | Qt::CTRL : // Undo
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
171 case Qt::Key_Y | Qt::CTRL : // Redo
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
172 case Qt::Key_Z | Qt::CTRL | Qt::SHIFT : // Redo
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
173 case Qt::Key_U | Qt::CTRL : // SelectionLowerCase
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
174 case Qt::Key_U | Qt::CTRL | Qt::SHIFT : // SelectionUpperCase
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
175 case Qt::Key_Plus | Qt::CTRL : // ZoomIn
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
176 case Qt::Key_Minus | Qt::CTRL : // ZoomOut
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
177 case Qt::Key_Backspace | Qt::CTRL | Qt::SHIFT : // DeleteLineLeft
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
178 case Qt::Key_Delete | Qt::CTRL | Qt::SHIFT : // DeleteLineRight
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
179 case Qt::Key_K | Qt::META : // DeleteLineRight
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
180 case Qt::Key_Backspace | Qt::CTRL : // DeleteWordLeft
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
181 case Qt::Key_Delete | Qt::CTRL : // DeleteWordRight
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
182 case Qt::Key_L | Qt::CTRL | Qt::SHIFT : // LineDelete
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
183 case Qt::Key_L | Qt::CTRL : // LineCut
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
184 case Qt::Key_T | Qt::CTRL | Qt::SHIFT : // LineCopy
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
185 cmd_list.at (i)->setKey (0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
186 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
187 }
18675
c199304dfb2a handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents: 18656
diff changeset
188 #endif
18954
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 defined (Q_OS_MAC)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
191 // Octave interprets Cmd key as Meta whereas Qscintilla interprets it
27929
265b386f8b20 maint: Use two spaces between sentences in code comments.
Rik <rik@octave.org>
parents: 27923
diff changeset
192 // as Ctrl. We thus invert Meta/Ctrl in Qscintilla's shortcuts list.
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
193 QList< QsciCommand * > cmd_list_mac = cmd_set->commands ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
194 for (int i = 0; i < cmd_list_mac.length (); i++)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
195 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
196 // Primary key
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
197 int key = cmd_list_mac.at (i)->key ();
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
198
25951
7a507e71d922 style fixes
John W. Eaton <jwe@octave.org>
parents: 25796
diff changeset
199 if (static_cast<int> (key | Qt::META) == key
7a507e71d922 style fixes
John W. Eaton <jwe@octave.org>
parents: 25796
diff changeset
200 && static_cast<int> (key | Qt::CTRL) != key)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
201 key = (key ^ Qt::META) | Qt::CTRL;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
202 else if (static_cast<int> (key | Qt::CTRL) == key)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
203 key = (key ^ Qt::CTRL) | Qt::META;
27753
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
204
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
205 cmd_list_mac.at (i)->setKey (key);
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
206
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
207 // Alternate key
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
208 key = cmd_list_mac.at (i)->alternateKey ();
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
209
25951
7a507e71d922 style fixes
John W. Eaton <jwe@octave.org>
parents: 25796
diff changeset
210 if (static_cast<int> (key | Qt::META) == key
7a507e71d922 style fixes
John W. Eaton <jwe@octave.org>
parents: 25796
diff changeset
211 && static_cast<int> (key | Qt::CTRL) != key)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
212 key = (key ^ Qt::META) | Qt::CTRL;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
213 else if (static_cast<int> (key | Qt::CTRL) == key)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
214 key = (key ^ Qt::CTRL) | Qt::META;
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
215
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
216 cmd_list_mac.at (i)->setAlternateKey (key);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
217 }
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
218 #endif
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
219
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
220 // selection markers
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
221
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
222 m_indicator_id = indicatorDefine (QsciScintilla::StraightBoxIndicator);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
223 if (m_indicator_id == -1)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
224 m_indicator_id = 1;
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
225
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
226 setIndicatorDrawUnder (true, m_indicator_id);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
227
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
228 markerDefine (QsciScintilla::Minus, marker::selection);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
229
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
230 // init state of undo/redo action for this tab
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
231 emit status_update (isUndoAvailable (), isRedoAvailable ());
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
232 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
233
29716
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
234 void octave_qscintilla::setCursorPosition (int line, int col)
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
235 {
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
236 QsciScintilla::setCursorPosition (line, col);
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
237 emit update_rowcol_indicator_signal (line, col);
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
238 }
da9c55b3e9fa fix wring row/col indicator in GUI editor when auto intending (bug #60690)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29707
diff changeset
239
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
240 void octave_qscintilla::set_selection_marker_color (const QColor& c)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
241 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
242 QColor ic = c;
29498
5384bb4efc51 rearrange default lexer settings and add second color mode to gui editor
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29359
diff changeset
243 ic.setAlphaF (0.45);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
244 setIndicatorForegroundColor (ic, m_indicator_id);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
245 setIndicatorOutlineColor (ic, m_indicator_id);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
246
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
247 setMarkerForegroundColor (c, marker::selection);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
248 setMarkerBackgroundColor (c, marker::selection);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
249 }
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
250
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
251 // context menu requested
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
252 void octave_qscintilla::contextMenuEvent (QContextMenuEvent *e)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
253 {
21724
aba2e6293dd8 use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents: 21578
diff changeset
254 #if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
255 QPoint global_pos, local_pos; // the menu's position
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
256 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
257
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
258 bool in_left_margin = false;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
259
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
260 // determine position depending on mouse or keyboard event
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
261 if (e->reason () == QContextMenuEvent::Mouse)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
262 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
263 // context menu by mouse
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
264 global_pos = e->globalPos (); // global mouse position
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
265 local_pos = e->pos (); // local mouse position
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
266 if (e->x () < marginWidth (1) + marginWidth (2))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
267 in_left_margin = true;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
268 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
269 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
270 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
271 // context menu by keyboard or other: get point of text cursor
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
272 get_global_textcursor_pos (&global_pos, &local_pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
273 QRect editor_rect = geometry (); // editor rect mapped to global
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
274 editor_rect.moveTopLeft
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
275 (parentWidget ()->mapToGlobal (editor_rect.topLeft ()));
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
276 if (! editor_rect.contains (global_pos)) // is cursor outside editor?
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
277 global_pos = editor_rect.topLeft (); // yes, take top left corner
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
278 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
279
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
280 # if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
281 if (! in_left_margin)
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
282 # endif
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
283 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
284 // fill context menu with editor's standard actions
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
285 emit create_context_menu_signal (context_menu);
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
286
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
287 // additional custom entries of the context menu
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
288 context_menu->addSeparator (); // separator before custom entries
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
289
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
290 // help menu: get the position of the mouse or the text cursor
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
291 // (only for octave files)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
292 QString lexer_name = lexer ()->lexer ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
293 if (lexer_name == "octave" || lexer_name == "matlab")
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
294 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
295 m_word_at_cursor = wordAtPoint (local_pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
296 if (! m_word_at_cursor.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
297 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
298 context_menu->addAction (tr ("Help on") + ' ' + m_word_at_cursor,
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
299 this, &octave_qscintilla::contextmenu_help);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
300 context_menu->addAction (tr ("Documentation on")
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
301 + ' ' + m_word_at_cursor,
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
302 this, &octave_qscintilla::contextmenu_doc);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
303 context_menu->addAction (tr ("Edit") + ' ' + m_word_at_cursor,
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
304 this, &octave_qscintilla::contextmenu_edit);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
305 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
306 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
307 }
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
308 # if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
309 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
310 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
311 // remove all standard actions from scintilla
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
312 QList<QAction *> all_actions = context_menu->actions ();
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
313
27676
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
314 for (auto *a : all_actions)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
315 context_menu->removeAction (a);
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
316
27676
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
317 QAction *act
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
318 = context_menu->addAction (tr ("dbstop if ..."), this,
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29498
diff changeset
319 &octave_qscintilla::contextmenu_break_condition);
27676
ea7d36e9f197 use standard C++ range-based for loops instead of Qt foreach macro
John W. Eaton <jwe@octave.org>
parents: 27672
diff changeset
320 act->setData (local_pos);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
321 }
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
322 # endif
16735
cee305c91e91 show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents: 16733
diff changeset
323
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 27455
diff changeset
324 // finally show the menu
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
325 context_menu->exec (global_pos);
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
326
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
327 #else
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
328
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
329 octave_unused_parameter (e);
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
330
20277
48d9001bdee3 Avoid HAVE_ macros in header file.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
331 #endif
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
332 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
333
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
334 // common function with flag for documentation
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
335 void octave_qscintilla::contextmenu_help_doc (bool documentation)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
336 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
337 if (documentation)
29691
67eccd062618 fix calling documentations from terminal and editor
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29655
diff changeset
338 m_octave_qobj.show_documentation_window (m_word_at_cursor);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
339 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
340 emit execute_command_in_terminal_signal ("help " + m_word_at_cursor);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
341 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
342
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
343 // call edit the function related to the current word
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
344 void octave_qscintilla::context_edit (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
345 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
346 if (get_actual_word ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
347 contextmenu_edit (true);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
348 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
349
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
350 // call edit the function related to the current word
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
351 void octave_qscintilla::context_run (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
352 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
353 if (hasSelectedText ())
27753
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
354 {
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
355 contextmenu_run (true);
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
356
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
357 emit interpreter_event
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
358 ([] (interpreter&)
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
359 { command_editor::erase_empty_line (false); });
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
360 }
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
361 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
362
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
363 void octave_qscintilla::get_global_textcursor_pos (QPoint *global_pos,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
364 QPoint *local_pos)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
365 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
366 long position = SendScintilla (SCI_GETCURRENTPOS);
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
367 long point_x = SendScintilla (SCI_POINTXFROMPOSITION, 0, position);
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
368 long point_y = SendScintilla (SCI_POINTYFROMPOSITION, 0, position);
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
369 *local_pos = QPoint (point_x, point_y); // local cursor position
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
370 *global_pos = mapToGlobal (*local_pos); // global position of cursor
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
371 }
17635
7945344506ae Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents: 17628
diff changeset
372
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
373 // determine the actual word and whether we are in an octave or matlab script
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
374 bool octave_qscintilla::get_actual_word (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
375 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
376 QPoint global_pos, local_pos;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
377 get_global_textcursor_pos (&global_pos, &local_pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
378 m_word_at_cursor = wordAtPoint (local_pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
379 QString lexer_name = lexer ()->lexer ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
380 return ((lexer_name == "octave" || lexer_name == "matlab")
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
381 && ! m_word_at_cursor.isEmpty ());
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
382 }
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
383
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
384 // helper function for clearing all indicators of a specific style
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
385 void octave_qscintilla::clear_selection_markers (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
386 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
387 int end_pos = text ().length ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
388 int end_line, end_col;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
389 lineIndexFromPosition (end_pos, &end_line, &end_col);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
390 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
391
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
392 markerDeleteAll (marker::selection);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
393 }
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
394
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
395 QString octave_qscintilla::eol_string (void)
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
396 {
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
397 switch (eolMode ())
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
398 {
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
399 case QsciScintilla::EolWindows:
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
400 return ("\r\n");
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
401 case QsciScintilla::EolMac:
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
402 return ("\r");
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
403 case QsciScintilla::EolUnix:
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
404 return ("\n");
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
405 }
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
406
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
407 // Last resort, if the above goes wrong (should never happen)
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
408 return ("\r\n");
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
409 }
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
410
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
411 // Function returning the true cursor position where the tab length
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
412 // is taken into account.
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
413 void octave_qscintilla::get_current_position (int *pos, int *line, int *col)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
414 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
415 *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
416 *line = SendScintilla (QsciScintillaBase::SCI_LINEFROMPOSITION, *pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
417 *col = SendScintilla (QsciScintillaBase::SCI_GETCOLUMN, *pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
418 }
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20955
diff changeset
419
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
420 // Function returning the comment string of the current lexer
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
421 QStringList octave_qscintilla::comment_string (bool comment)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
422 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
423 int lexer = SendScintilla (SCI_GETLEXER);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
424
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
425 switch (lexer)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
426 {
24222
7d1561c9ee48 prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents: 24190
diff changeset
427 #if defined (HAVE_LEXER_OCTAVE) || defined (HAVE_LEXER_MATLAB)
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
428 #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
429 case SCLEX_OCTAVE:
24222
7d1561c9ee48 prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents: 24190
diff changeset
430 #else
7d1561c9ee48 prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents: 24190
diff changeset
431 case SCLEX_MATLAB:
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
432 #endif
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
433 {
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
434 gui_settings settings;
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
435
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
436 int comment_string;
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
437
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
438 if (comment)
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
439 {
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
440 // The commenting string is requested
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
441 if (settings.contains (ed_comment_str.key))
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
442 // new version (radio buttons)
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
443 comment_string = settings.value (ed_comment_str).toInt ();
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
444 else
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
445 // old version (combo box)
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
446 comment_string = settings.value (ed_comment_str_old.key,
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
447 ed_comment_str.def).toInt ();
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
448
25617
44d638d5eea5 reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents: 25527
diff changeset
449 return (QStringList (ed_comment_strings.at (comment_string)));
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
450 }
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
451 else
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
452 {
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
453 QStringList c_str;
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
454
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
455 // The possible uncommenting string(s) are requested
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
456 comment_string = settings.value (ed_uncomment_str).toInt ();
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
457
25617
44d638d5eea5 reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents: 25527
diff changeset
458 for (int i = 0; i < ed_comment_strings_count; i++)
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
459 {
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
460 if (1 << i & comment_string)
25617
44d638d5eea5 reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents: 25527
diff changeset
461 c_str.append (ed_comment_strings.at (i));
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
462 }
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
463
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
464 return c_str;
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
465 }
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
466
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
467 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
468 #endif
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
469
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
470 case SCLEX_PERL:
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
471 case SCLEX_BASH:
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
472 case SCLEX_DIFF:
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
473 return QStringList ("#");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
474
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
475 case SCLEX_CPP:
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
476 return QStringList ("//");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
477
23234
aaf20024db6f function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents: 23230
diff changeset
478 case SCLEX_BATCH:
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
479 return QStringList ("REM ");
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
480 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
481
24475
8cb985e362f3 Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents: 24232
diff changeset
482 return QStringList ("%"); // should never happen
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
483 }
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
484
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
485 // provide the style at a specific position
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
486 int octave_qscintilla::get_style (int pos)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
487 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
488 int position;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
489 if (pos < 0)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
490 // The positition has to be reduced by 2 for getting the real style (?)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
491 position = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS) - 2;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
492 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
493 position = pos;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
494
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
495 return SendScintilla (QsciScintillaBase::SCI_GETSTYLEAT, position);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
496 }
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
497
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
498 // Is a specific cursor position in a line or block comment?
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
499 int octave_qscintilla::is_style_comment (int pos)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
500 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
501 int lexer = SendScintilla (QsciScintillaBase::SCI_GETLEXER);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
502 int style = get_style (pos);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
503
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
504 switch (lexer)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
505 {
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
506 case SCLEX_CPP:
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27223
diff changeset
507 return (ST_LINE_COMMENT * (style == QsciLexerCPP::CommentLine
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
508 || style == QsciLexerCPP::CommentLineDoc)
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27223
diff changeset
509 + ST_BLOCK_COMMENT * (style == QsciLexerCPP::Comment
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
510 || style == QsciLexerCPP::CommentDoc
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
511 || style == QsciLexerCPP::CommentDocKeyword
27276
7455523fdf01 style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents: 27223
diff changeset
512 || style == QsciLexerCPP::CommentDocKeywordError));
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
513
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
514 #if defined (HAVE_LEXER_MATLAB)
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
515 case SCLEX_MATLAB:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
516 return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment));
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
517 #endif
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
518 #if defined (HAVE_LEXER_OCTAVE)
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
519 case SCLEX_OCTAVE:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
520 return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment));
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
521 #endif
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
522
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
523 case SCLEX_PERL:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
524 return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment));
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
525
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
526 case SCLEX_BATCH:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
527 return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment));
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
528
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
529 case SCLEX_DIFF:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
530 return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment));
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
531
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
532 case SCLEX_BASH:
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
533 return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment));
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
534
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
535 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
536
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
537 return ST_NONE;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
538 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
539
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 27455
diff changeset
540 // Do smart indentation after if, for, ...
27198
dffdabfd0213 fix cursor position for editor smart indent after keyword (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27133
diff changeset
541 void octave_qscintilla::smart_indent (bool do_smart_indent, int do_auto_close,
dffdabfd0213 fix cursor position for editor smart indent after keyword (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27133
diff changeset
542 int line, int ind_char_width)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
543 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
544 QString prevline = text (line);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
545
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
546 QRegExp bkey = QRegExp ("^[\t ]*(if|for|while|switch"
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
547 "|do|function|properties|events|classdef"
26480
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
548 "|unwind_protect|try"
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
549 "|parfor|methods)"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
550 "[\r]?[\n\t #%]");
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
551 // last word except for comments, assuming no ' or " in comment.
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
552 // rx_end = QRegExp ("(\\w+)[ \t;\r\n]*([%#][^\"']*)?$");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
553
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
554 // last word except for comments,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
555 // allowing % and # in single or double quoted strings
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
556 // FIXME: This will get confused by transpose.
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
557 QRegExp ekey = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*"
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
558 "(\\w+)[ \t;\r\n]*(?:[%#].*)?$");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
559
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
560 int bpos = bkey.indexIn (prevline, 0);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
561 int epos;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
562
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
563 if (bpos > -1)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
564 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
565 // Found keyword after that indentation should be added
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
566
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
567 // Check for existing end statement in the same line
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
568 epos = ekey.indexIn (prevline, bpos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
569 QString first_word = bkey.cap(1);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
570 bool inline_end = (epos > -1) && is_end (ekey.cap(1), first_word);
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
571
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
572 if (do_smart_indent && ! inline_end)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
573 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
574 // Do smart indent in the current line (line+1)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
575 indent (line+1);
27198
dffdabfd0213 fix cursor position for editor smart indent after keyword (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27133
diff changeset
576 setCursorPosition (line+1, indentation (line+1) / ind_char_width);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
577 }
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
578
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
579 if (do_auto_close
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
580 && ! inline_end
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
581 && ! first_word.contains (QRegExp ("(?:case|otherwise|unwind_protect_cleanup)")))
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
582 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
583 // Do auto close
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
584 auto_close (do_auto_close, line, prevline, first_word);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
585 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
586
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
587 return;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
588 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
589
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
590 QRegExp mkey = QRegExp ("^[\t ]*(?:else|elseif|catch|unwind_protect_cleanup)"
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
591 "[\r]?[\t #%\n]");
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
592 if (prevline.contains (mkey))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
593 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
594 int prev_ind = indentation (line-1);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
595 int act_ind = indentation (line);
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
596
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
597 if (prev_ind == act_ind)
23689
b729e97aa8d1 move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents: 23688
diff changeset
598 unindent (line);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
599 else if (prev_ind > act_ind)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
600 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
601 setIndentation (line+1, prev_ind);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
602 setCursorPosition (line+1, prev_ind);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
603 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
604 return;
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
605 }
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
606
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
607 QRegExp case_key = QRegExp ("^[\t ]*(?:case|otherwise)[\r]?[\t #%\n]");
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
608 if (prevline.contains (case_key) && do_smart_indent)
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
609 {
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
610 QString last_line = text (line-1);
29712
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
611 int prev_ind = indentation (line-1);
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
612 int act_ind = indentation (line);
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
613
29712
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
614 if (last_line.contains (QRegExp ("^[\t ]*switch")))
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
615 {
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
616 indent (line+1);
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
617 act_ind = indentation (line+1);
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
618 }
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
619 else
29712
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
620 {
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
621 if (prev_ind == act_ind)
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
622 unindent (line);
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
623 else if (prev_ind > act_ind)
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
624 act_ind = prev_ind;
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
625 }
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
626
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
627 setIndentation (line+1, act_ind);
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
628 setCursorPosition (line+1, act_ind);
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
629 }
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
630
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
631 ekey = QRegExp ("^[\t ]*(?:end|endif|endfor|endwhile|until|endfunction"
29712
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
632 "|endswitch|end_try_catch|end_unwind_protect)[\r]?[\t #%\n(;]");
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
633 if (prevline.contains (ekey))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
634 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
635 if (indentation (line-1) <= indentation (line))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
636 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
637 unindent (line+1);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
638 unindent (line);
29712
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
639 if (prevline.contains ("endswitch"))
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
640 {
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
641 // endswitch has to me unndented twice
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
642 unindent (line+1);
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
643 unindent (line);
0e888d2f79b7 fix auto indentation of switch-strucutre in GUI editor (bug #60649)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29654
diff changeset
644 }
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
645 setCursorPosition (line+1,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
646 indentation (line));
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
647 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
648 return;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
649 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
650 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
651
27956
2310164737b3 fix many spelling errors (bug #57613)
John W. Eaton <jwe@octave.org>
parents: 27455
diff changeset
652 // Do smart indentation of current selection or line.
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
653 void octave_qscintilla::smart_indent_line_or_selected_text (int lineFrom,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
654 int lineTo)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
655 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
656 QRegExp blank_line_regexp = QRegExp ("^[\t ]*$");
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
657
27912
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
658 // end[xxxxx] [# comment] at end of a line
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
659 QRegExp end_word_regexp
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
660 = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*"
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
661 "(?:end\\w*)[\r\n\t ;]*(?:[%#].*)?$");
27912
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
662
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
663 QRegExp begin_block_regexp
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
664 = QRegExp ("^[\t ]*(?:if|elseif|else"
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
665 "|for|while|do|parfor"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
666 "|switch|case|otherwise"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
667 "|function"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
668 "|classdef|properties|events|enumeration|methods"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
669 "|unwind_protect|unwind_protect_cleanup|try|catch)"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
670 "[\r\n\t #%]");
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
671
26480
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
672 QRegExp mid_block_regexp
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
673 = QRegExp ("^[\t ]*(?:elseif|else"
26480
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
674 "|unwind_protect_cleanup|catch)"
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
675 "[\r\n\t #%]");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
676
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
677 QRegExp end_block_regexp
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
678 = QRegExp ("^[\t ]*(?:end"
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
679 "|end(for|function|if|parfor|switch|while"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
680 "|classdef|enumeration|events|methods|properties)"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
681 "|end_(try_catch|unwind_protect)"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
682 "|until)"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
683 "[\r\n\t #%]");
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
684
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
685 QRegExp case_block_regexp
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
686 = QRegExp ("^[\t ]*(?:case|otherwise)"
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
687 "[\r\n\t #%]");
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
688
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
689 int indent_column = -1;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
690 int indent_increment = indentationWidth ();
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
691 bool in_switch = false;
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
692
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
693 for (int line = lineFrom-1; line >= 0; line--)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
694 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
695 QString line_text = text (line);
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
696
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
697 if (blank_line_regexp.indexIn (line_text) < 0)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
698 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
699 // Found first non-blank line above beginning of region or
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
700 // current line. Base indentation from this line, increasing
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
701 // indentation by indentationWidth if it looks like the
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
702 // beginning of a code block.
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
703
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
704 indent_column = indentation (line);
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
705
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
706 if (begin_block_regexp.indexIn (line_text) > -1)
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
707 {
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
708 indent_column += indent_increment;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
709 if (line_text.contains ("switch"))
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
710 in_switch = true;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
711 }
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
712
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
713 break;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
714 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
715 }
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
716
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
717 if (indent_column < 0)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
718 indent_column = indentation (lineFrom);
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24222
diff changeset
719
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
720 QString prev_line;
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
721 for (int line = lineFrom; line <= lineTo; line++)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
722 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
723 QString line_text = text (line);
23689
b729e97aa8d1 move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents: 23688
diff changeset
724
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
725 if (end_block_regexp.indexIn (line_text) > -1)
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
726 {
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
727 indent_column -= indent_increment;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
728 if (line_text.contains ("endswitch"))
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
729 {
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
730 // need a double de-indent for endswitch
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
731 if (in_switch)
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
732 indent_column -= indent_increment;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
733 in_switch = false;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
734 }
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
735 }
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
736
26480
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
737 if (mid_block_regexp.indexIn (line_text) > -1)
27935
f1844e33f621 maint: Use Octave coding conventions in libgui/ directory.
Rik <rik@octave.org>
parents: 27929
diff changeset
738 indent_column -= indent_increment;
26480
4203f6e0cd7d Allow indent of mid block keywords (#55276)
John Donoghue
parents: 26376
diff changeset
739
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
740 if (case_block_regexp.indexIn (line_text) > -1)
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
741 {
27914
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
742 if (case_block_regexp.indexIn (prev_line) < 0
a044e50c8dcb Streamline QRegExp instances in libgu.
Rik <rik@octave.org>
parents: 27912
diff changeset
743 && !prev_line.contains("switch"))
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
744 indent_column -= indent_increment;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
745 in_switch = true;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
746 }
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
747
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
748 setIndentation (line, indent_column);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
749
27912
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
750 int bpos = begin_block_regexp.indexIn (line_text);
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
751 if (bpos > -1)
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
752 {
27912
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
753 // Check for existing end statement in the same line
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
754 int epos = end_word_regexp.indexIn (line_text, bpos);
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
755 if (epos == -1)
84d6abff1006 Do not indent next line on single line constructs (Bug #57358).
John Donoghue <john.donoghue@ieee.org>
parents: 27909
diff changeset
756 indent_column += indent_increment;
26634
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
757 if (line_text.contains ("switch"))
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
758 in_switch = true;
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
759 }
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
760
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
761 if (blank_line_regexp.indexIn (line_text) < 0)
48ddf51a6ef7 Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents: 26480
diff changeset
762 prev_line = line_text;
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
763 }
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
764 }
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
765
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
766 void octave_qscintilla::set_word_selection (const QString& word)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
767 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
768 m_selection = word;
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
769
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
770 if (word.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
771 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
772 m_selection_line = -1;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
773 m_selection_col = -1;
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
774
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
775 m_selection_replacement = "";
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
776
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
777 clear_selection_markers ();
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
778
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
779 QToolTip::hideText ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
780 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
781 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
782 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
783 int pos;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
784 get_current_position (&pos, &m_selection_line, &m_selection_col);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
785 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
786 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
787
27455
e92bab9a7f26 fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26634
diff changeset
788 void octave_qscintilla::show_selection_markers (int l1, int c1, int l2, int c2)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
789 {
27455
e92bab9a7f26 fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26634
diff changeset
790 fillIndicatorRange (l1, c1, l2, c2, m_indicator_id);
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
791
27455
e92bab9a7f26 fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26634
diff changeset
792 if (l1 == l2)
e92bab9a7f26 fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26634
diff changeset
793 markerAdd (l1, marker::selection);
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
794 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
795
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
796 void octave_qscintilla::contextmenu_help (bool)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
797 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
798 contextmenu_help_doc (false);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
799 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
800
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
801 void octave_qscintilla::contextmenu_doc (bool)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
802 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
803 contextmenu_help_doc (true);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
804 }
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
805
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
806 void octave_qscintilla::context_help_doc (bool documentation)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
807 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
808 if (get_actual_word ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
809 contextmenu_help_doc (documentation);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
810 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
811
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
812 void octave_qscintilla::contextmenu_edit (bool)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
813 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
814 emit context_menu_edit_signal (m_word_at_cursor);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
815 }
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
816
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
817 void octave_qscintilla::contextmenu_run_temp_error (void)
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
818 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
819 QMessageBox::critical (this, tr ("Octave Editor"),
27935
f1844e33f621 maint: Use Octave coding conventions in libgui/ directory.
Rik <rik@octave.org>
parents: 27929
diff changeset
820 tr ("Creating temporary files failed.\n"
f1844e33f621 maint: Use Octave coding conventions in libgui/ directory.
Rik <rik@octave.org>
parents: 27929
diff changeset
821 "Make sure you have write access to temp. directory\n"
f1844e33f621 maint: Use Octave coding conventions in libgui/ directory.
Rik <rik@octave.org>
parents: 27929
diff changeset
822 "%1\n\n"
f1844e33f621 maint: Use Octave coding conventions in libgui/ directory.
Rik <rik@octave.org>
parents: 27929
diff changeset
823 "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ()));
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
824 }
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
825
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
826 void octave_qscintilla::contextmenu_run (bool)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
827 {
27629
8b6e928e0705 in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
828 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
829
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
830 // Take selected code and extend it by commands for echoing each
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
831 // evaluated line and for adding the line to the history (use script)
27678
3a85d8547584 fix executing selected code containing a clear all command (bug #57204)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27676
diff changeset
832 QString code = QString ();
28544
dc53b7b7af8b remove block begin/end comments for running selected code lines (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
833 QString hist = QString ();
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
834
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
835 // Split contents into single lines and complete commands
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
836 QStringList lines = selectedText ().split (QRegExp ("[\r\n]"),
29049
461bd8b9ce91 use Qt::SplitBehavior enum and values if available
John W. Eaton <jwe@octave.org>
parents: 28985
diff changeset
837 #if defined (HAVE_QT_SPLITBEHAVIOR_ENUM)
461bd8b9ce91 use Qt::SplitBehavior enum and values if available
John W. Eaton <jwe@octave.org>
parents: 28985
diff changeset
838 Qt::SkipEmptyParts);
461bd8b9ce91 use Qt::SplitBehavior enum and values if available
John W. Eaton <jwe@octave.org>
parents: 28985
diff changeset
839 #else
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
840 QString::SkipEmptyParts);
29049
461bd8b9ce91 use Qt::SplitBehavior enum and values if available
John W. Eaton <jwe@octave.org>
parents: 28985
diff changeset
841 #endif
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
842 for (int i = 0; i < lines.count (); i++)
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
843 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
844 QString line = lines.at (i);
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
845 if (line.trimmed ().isEmpty ())
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
846 continue;
28095
b0f949055097 Fix parse error when running code with single quotes with F9 (bug #57837).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27978
diff changeset
847 QString line_escaped = line;
b0f949055097 Fix parse error when running code with single quotes with F9 (bug #57837).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27978
diff changeset
848 line_escaped.replace (QString ("'"), QString ("''"));
27909
a29db5c46706 fix use of escape sequences when running code with F9 (bug #57469)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27893
diff changeset
849 QString line_history = line;
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
850
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
851 // Prevent output of breakpoint in temp. file for keyboard
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
852 QString next_bp_quiet;
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
853 QString next_bp_quiet_reset;
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
854 if (line.contains ("keyboard"))
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
855 {
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
856 // Define commands for not showing bp location and for resetting
28095
b0f949055097 Fix parse error when running code with single quotes with F9 (bug #57837).
Markus Mützel <markus.muetzel@gmx.de>
parents: 27978
diff changeset
857 // this in case "keyboard" was within a comment
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
858 next_bp_quiet = "__db_next_breakpoint_quiet__;\n";
29819
340d6d3dcc94 octave-qscintilla.cc (contextmenu_run): fix keyboard command handling
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29712
diff changeset
859 next_bp_quiet_reset = "\n__db_next_breakpoint_quiet__(false);";
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
860 }
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
861
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
862 // Add codeline
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
863 code += next_bp_quiet + line + next_bp_quiet_reset + "\n";
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
864 hist += line_history + "\n";
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
865 }
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
866
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
867 octave_stdout << hist.toStdString ();
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
868
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
869 // Create tmp file with the code to be executed by the interpreter
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
870 QPointer<QTemporaryFile> tmp_file
27629
8b6e928e0705 in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
871 = rmgr.create_tmp_file ("m", code);
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
872
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
873 bool tmp = (tmp_file && tmp_file->open ());
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
874 if (! tmp)
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
875 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
876 // tmp files not working: use old way to run selection
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
877 contextmenu_run_temp_error ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
878 return;
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
879 }
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
880
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
881 tmp_file->close ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
882
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
883 // Create tmp file required for adding command to history
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
884 QPointer<QTemporaryFile> tmp_hist
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
885 = rmgr.create_tmp_file ("", hist); // empty tmp file for history
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
886
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
887 tmp = (tmp_hist && tmp_hist->open ());
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
888 if (! tmp)
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
889 {
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
890 // tmp files not working: use old way to run selection
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
891 contextmenu_run_temp_error ();
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
892 return;
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
893 }
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
894
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
895 tmp_hist->close ();
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
896
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
897 // Add commands to the history
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
898 emit interpreter_event
28851
1ac5a76ae91d use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents: 28848
diff changeset
899 ([=] (interpreter& interp)
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
900 {
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
901 // INTERPRETER THREAD
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
902
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
903 std::string opt = "-r";
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
904 std::string path = tmp_hist->fileName ().toStdString ();
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
905
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
906 Fhistory (interp, ovl (opt, path));
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
907 });
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
908
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
909 // Disable opening a file at a breakpoint in case keyboard () is used
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
910 gui_settings settings;
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
911
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
912 bool show_dbg_file = settings.value (ed_show_dbg_file).toBool ();
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
913 settings.setValue (ed_show_dbg_file.key, false);
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
914
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
915 // Let the interpreter execute the tmp file
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
916 emit interpreter_event
28851
1ac5a76ae91d use [=] capture default specification where possible
John W. Eaton <jwe@octave.org>
parents: 28848
diff changeset
917 ([=] (interpreter& interp)
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
918 {
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
919 // INTERPRETER THREAD
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
920
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
921 std::string file = tmp_file->fileName ().toStdString ();
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
922
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
923 std::string pending_input = command_editor::get_current_line ();
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
924
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
925 int err_line = -1; // For storing the line of a poss. error
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
926
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
927 // Get current state of auto command repeat in debug mode
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
928 octave_value_list ovl_dbg = Fisdebugmode (interp);
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
929 bool dbg = ovl_dbg(0).bool_value ();
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
930 octave_value_list ovl_auto_repeat = ovl (true);
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
931 if (dbg)
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
932 ovl_auto_repeat = Fauto_repeat_debug_command (interp, ovl (false), 1);
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
933 bool auto_repeat = ovl_auto_repeat(0).bool_value ();
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
934
27652
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
935 try
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
936 {
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
937 // Do the job
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
938 interp.source_file (file);
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
939 }
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
940 catch (const execution_exception& ee)
27652
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
941 {
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
942 // Catch errors otherwise the rest of the interpreter
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
943 // will not be executed (cleaning up).
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
944
27696
cf231bc5876f improve error messages when executing slected code by F9 (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27687
diff changeset
945 // New error message and error stack
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
946 QString new_msg = QString::fromStdString (ee.message ());
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
947 std::list<frame_info> stack = ee.stack_info ();
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
948
27696
cf231bc5876f improve error messages when executing slected code by F9 (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27687
diff changeset
949 // Remove line and column from first line of error message only
cf231bc5876f improve error messages when executing slected code by F9 (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27687
diff changeset
950 // if it is related to the tmp itself, i.e. only if the
30878
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
951 // the error stack size is 0, 1, or, if in debug mode, 2
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
952 size_t max_stack_size = 1;
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
953 if (dbg)
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
954 max_stack_size = 2;
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
955 if (stack.size () <= max_stack_size)
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
956 {
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
957 QRegExp rx ("source: error sourcing file [^\n]*$");
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
958 if (new_msg.contains (rx))
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
959 {
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
960 // Selected code has syntax errors
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
961 new_msg.replace (rx, "error sourcing selected code");
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
962 err_line = 0; // Nothing into history?
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
963 }
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
964 else
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
965 {
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
966 // Normal error, detect line and remove file
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
967 // name from message
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
968 QStringList rx_list;
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
969 rx_list << "near line (\\d+),[^\n]*\n";
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
970 rx_list << "near line (\\d+),[^\n]*$";
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
971
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
972 QStringList replace_list;
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
973 replace_list << "\n";
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
974 replace_list << "";
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
975
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
976 for (int i = 0; i < rx_list.length (); i++)
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
977 {
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
978 int pos = 0;
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
979 rx = QRegExp (rx_list.at (i));
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
980 pos = rx.indexIn (new_msg, pos);
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
981 if (pos != -1)
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
982 {
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
983 err_line = rx.cap (1).toInt ();
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
984 new_msg = new_msg.replace (rx, replace_list.at (i));
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
985 }
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
986 }
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
987 }
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
988 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
989
30878
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
990 // Drop first stack level, which is the temporary function file,
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
991 // or, if in debug mode, drop first two stack levels
27687
2e988d51e401 fix parse error handling when executing selected code (bug #57227)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27684
diff changeset
992 if (stack.size () > 0)
2e988d51e401 fix parse error handling when executing selected code (bug #57227)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27684
diff changeset
993 stack.pop_back ();
30878
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
994 if (dbg && (stack.size () > 0))
a1c2ea6deaa4 fix err messages when running selected code while in dbg mode (bug #62105)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30633
diff changeset
995 stack.pop_back ();
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
996
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
997 // Clean up before throwing the modified error.
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
998 emit ctx_menu_run_finished_signal (show_dbg_file, err_line,
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
999 tmp_file, tmp_hist,
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1000 dbg, auto_repeat);
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
1001
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
1002 // New exception with updated message and stack
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
1003 execution_exception nee (ee.err_type (), ee.identifier (),
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
1004 new_msg.toStdString (), stack);
27684
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
1005
becd6267d6d1 hide tmp file in error and bp messages when executing selected code (bug #57205)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27678
diff changeset
1006 // Throw
29163
8f67ad8b3103 maint: Updating naming conventions for exceptions and use const where possible.
Rik <rik@octave.org>
parents: 29054
diff changeset
1007 throw (nee);
27652
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
1008 }
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
1009
f18e48749a7a fix running selected code by F9 in case of errors during execution
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27629
diff changeset
1010 // Clean up
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1011
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
1012 emit ctx_menu_run_finished_signal (show_dbg_file, err_line,
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1013 tmp_file, tmp_hist,
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1014 dbg, auto_repeat);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1015
27753
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
1016 command_editor::erase_empty_line (true);
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1017 command_editor::replace_line ("");
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1018 command_editor::set_initial_input (pending_input);
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1019 command_editor::redisplay ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1020 command_editor::interrupt_event_loop ();
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1021 command_editor::accept_line ();
27753
dcf6569cd973 prevent empty lines when using F9 for executing slected code (bug #57243)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27752
diff changeset
1022 command_editor::erase_empty_line (true);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1023
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1024 });
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1025 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1026
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
1027 void octave_qscintilla::ctx_menu_run_finished (bool show_dbg_file, int,
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1028 QTemporaryFile* tmp_file, QTemporaryFile* tmp_hist,
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1029 bool dbg, bool auto_repeat)
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1030 {
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1031 emit focus_console_after_command_signal ();
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1032
28283
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
1033 // TODO: Use line nr. (int argument) of possible error for removing
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
1034 // lines from history that were never executed. For this,
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
1035 // possible lines from commands at a debug prompt must be
777eb315b004 add selection to history before evaluation of selected code (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28281
diff changeset
1036 // taken into consideration.
27629
8b6e928e0705 in GUI objects, store reference to base_qobject instead of resource_manager
John W. Eaton <jwe@octave.org>
parents: 27620
diff changeset
1037 resource_manager& rmgr = m_octave_qobj.get_resource_manager ();
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
1038 gui_settings settings;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1039
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
1040 settings.setValue (ed_show_dbg_file.key, show_dbg_file);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1041
28281
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
1042 rmgr.remove_tmp_file (tmp_file);
12ad6f1dc3b6 run slelected editor code as block, not line by line (bug #58323)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28274
diff changeset
1043 rmgr.remove_tmp_file (tmp_hist);
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1044
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1045 emit interpreter_event
31354
38b954c0c0c1 avoid possible warning about unused lambda capture
John W. Eaton <jwe@octave.org>
parents: 30878
diff changeset
1046 ([=] (interpreter& interp)
28985
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1047 {
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1048 // INTERPRETER THREAD
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1049 if (dbg)
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1050 Fauto_repeat_debug_command (interp, ovl (auto_repeat));
47107a0979cd avoid repeating last command when using F9 in debug mode (bug #57634)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28544
diff changeset
1051 });
27556
410622ac120f improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27461
diff changeset
1052 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1053
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1054 // wrappers for dbstop related context menu items
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1055
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1056 // FIXME: Why can't the data be sent as the argument to the function???
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1057 void octave_qscintilla::contextmenu_break_condition (bool)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1058 {
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1059 #if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1060 QAction *action = qobject_cast<QAction *>(sender ());
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1061 QPoint local_pos = action->data ().value<QPoint> ();
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1062
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1063 // pick point just right of margins, so lineAt doesn't give -1
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1064 int margins = marginWidth (1) + marginWidth (2) + marginWidth (3);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1065 local_pos = QPoint (margins + 1, local_pos.y ());
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1066
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1067 emit context_menu_break_condition_signal (lineAt (local_pos));
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1068 #endif
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1069 }
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1070
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1071 void octave_qscintilla::contextmenu_break_once (const QPoint& local_pos)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1072 {
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1073 #if defined (HAVE_QSCI_VERSION_2_6_0)
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1074 emit context_menu_break_once (lineAt (local_pos));
30439
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
1075 #else
fffccc353ffc octave-qscintilla.cc: Silence compiler warning about unused parameter.
Markus Mützel <markus.muetzel@gmx.de>
parents: 30398
diff changeset
1076 octave_unused_parameter (local_pos);
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1077 #endif
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1078 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1079
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1080 void octave_qscintilla::text_changed (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1081 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1082 emit status_update (isUndoAvailable (), isRedoAvailable ());
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1083 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1084
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1085 void octave_qscintilla::cursor_position_changed (int line, int col)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1086 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1087 // Clear the selection if we move away from it. We have to check the
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1088 // position, because we allow entering text at the point of the
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1089 // selection to trigger a search and replace that does not clear the
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1090 // selection until it is complete.
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1091
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1092 if (! m_selection.isEmpty ()
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1093 && (line != m_selection_line || col != m_selection_col))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1094 set_word_selection ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1095 }
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
1096
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1097 // when edit area gets focus update information on undo/redo actions
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1098 void octave_qscintilla::focusInEvent (QFocusEvent *focusEvent)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1099 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1100 emit status_update (isUndoAvailable (), isRedoAvailable ());
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1101
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1102 QsciScintilla::focusInEvent (focusEvent);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1103 }
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1104
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1105 void octave_qscintilla::show_replace_action_tooltip (void)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1106 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1107 int pos;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1108 get_current_position (&pos, &m_selection_line, &m_selection_col);
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1109
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1110 // Offer to replace other instances.
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1111
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1112 QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return;
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1113
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1114 QString msg = (tr ("Press '%1' to replace all occurrences of '%2' with '%3'.")
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1115 . arg (keyseq.toString ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1116 . arg (m_selection)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1117 . arg (m_selection_replacement));
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1118
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1119 QPoint global_pos;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1120 QPoint local_pos;
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1121
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1122 get_global_textcursor_pos (&global_pos, &local_pos);
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1123
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1124 QFontMetrics ttfm (QToolTip::font ());
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1125
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1126 // Try to avoid overlapping with the text completion dialog
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1127 // and the text that is currently being edited.
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1128
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1129 global_pos += QPoint (2*ttfm.maxWidth (), -3*ttfm.height ());
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1130
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1131 QToolTip::showText (global_pos, msg);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1132 }
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1133
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1134 void octave_qscintilla::replace_all (const QString& o_str, const QString& n_str,
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1135 bool re, bool cs, bool wo)
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1136 {
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1137 // get the resulting cursor position
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1138 int pos, line, col, nline, ncol;
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1139 get_current_position (&pos, &line, &col);
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1140
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1141 // remember first visible line for restoring the view afterwards
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1142 int first_line = firstVisibleLine ();
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1143
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1144 // search for first occurrence of the detected word
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1145 bool find_result_available = findFirst (o_str, re, cs, wo,
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1146 false, true, 0, 0);
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1147 // replace and find more occurrences in a loop
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1148 beginUndoAction ();
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1149 while (find_result_available)
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1150 {
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1151 // findNext doesn't work properly if the length of the replacement
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1152 // text is different from the original
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1153 replace (n_str);
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1154 get_current_position (&pos, &nline, &ncol);
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1155
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1156 find_result_available = findFirst (o_str, re, cs, wo,
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1157 false, true, nline, ncol);
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1158 }
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1159 endUndoAction ();
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1160
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1161 // restore the visible area
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1162 setFirstVisibleLine (first_line);
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1163
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1164 // fix cursor column if outside of new line length
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1165 int eol_len = eol_string ().length ();
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1166 if (line == lines () - 1)
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1167 eol_len = 0;
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1168 const int col_max = text (line).length () - eol_len;
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1169 if (col_max < col)
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1170 col = col_max;
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1171
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1172 setCursorPosition (line, col);
28364
44f2d73df4b3 remove trailing spaces without replacing full editor text (bug #58417)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28283
diff changeset
1173 }
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1174
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1175 bool octave_qscintilla::event (QEvent *e)
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1176 {
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1177 if (m_debug_mode && e->type() == QEvent::ToolTip)
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1178 {
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1179 QHelpEvent *help_e = static_cast<QHelpEvent *>(e);
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1180 QString variable = wordAtPoint (help_e->pos());
28809
03c0024f95c7 avoid using bare pointers for symbol lists in editor (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28798
diff changeset
1181 QStringList symbol_names
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1182 = m_octave_qobj.get_workspace_model ()->get_symbol_names ();
28809
03c0024f95c7 avoid using bare pointers for symbol lists in editor (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28798
diff changeset
1183 int symbol_idx = symbol_names.indexOf (variable);
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1184 if (symbol_idx > -1)
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1185 {
28809
03c0024f95c7 avoid using bare pointers for symbol lists in editor (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28798
diff changeset
1186 QStringList symbol_values
30398
d4d83344d653 maint: style check C++ files in src/ and libgui/ ahead of 7.1 release.
Rik <rik@octave.org>
parents: 29821
diff changeset
1187 = m_octave_qobj.get_workspace_model ()->get_symbol_values ();
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1188 QToolTip::showText (help_e->globalPos(), variable
28809
03c0024f95c7 avoid using bare pointers for symbol lists in editor (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28798
diff changeset
1189 + " = " + symbol_values.at (symbol_idx));
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1190 }
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1191 else
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1192 {
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1193 QToolTip::hideText();
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1194 e->ignore();
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1195 }
27117
e14e48e838fa Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents: 27101
diff changeset
1196
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1197 return true;
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1198 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1199
28848
751afb1ee1d0 avoid GUI crash happening after changeset 82ccc4e69ba3 (bug #56990)
John W. Eaton <jwe@octave.org>
parents: 28809
diff changeset
1200 return QsciScintilla::event(e);
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1201 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1202
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1203 void octave_qscintilla::keyPressEvent (QKeyEvent *key_event)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1204 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1205 if (m_selection.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1206 QsciScintilla::keyPressEvent (key_event);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1207 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1208 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1209 int key = key_event->key ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1210 Qt::KeyboardModifiers modifiers = key_event->modifiers ();
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1211
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1212 if (key == Qt::Key_Return && modifiers == Qt::ShiftModifier)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1213 {
28365
2969b94cac9f simplify code for replacing all highlighted occurrences in the editor
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28364
diff changeset
1214 replace_all (m_selection, m_selection_replacement,
2969b94cac9f simplify code for replacing all highlighted occurrences in the editor
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28364
diff changeset
1215 false, true, true);
27117
e14e48e838fa Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents: 27101
diff changeset
1216
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1217 // Clear the selection.
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1218 set_word_selection ();
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1219 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1220 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1221 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1222 // The idea here is to allow backspace to remove the last
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1223 // character of the replacement text to allow minimal editing
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1224 // and to also end the selection replacement action if text is
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1225 // not valid as a word constituent (control characters,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1226 // etc.). Is there a better way than having special cases for
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1227 // DEL and ESC here?
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1228
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1229 QString text = key_event->text ();
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
1230
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1231 bool cancel_replacement = false;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1232
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1233 if (key == Qt::Key_Backspace)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1234 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1235 if (m_selection_replacement.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1236 cancel_replacement = true;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1237 else
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1238 m_selection_replacement.chop (1);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1239 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1240 else if (key == Qt::Key_Delete || key == Qt::Key_Escape)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1241 cancel_replacement = true;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1242 else if (! text.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1243 m_selection_replacement += text;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1244 else if (modifiers != Qt::ShiftModifier)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1245 cancel_replacement = true;
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1246
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1247 // Perform default action.
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1248
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1249 QsciScintilla::keyPressEvent (key_event);
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1250
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1251 if (cancel_replacement)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1252 set_word_selection ();
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
1253
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1254 if (! m_selection_replacement.isEmpty ())
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1255 show_replace_action_tooltip ();
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1256 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1257 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1258 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1259
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1260 void octave_qscintilla::auto_close (int auto_endif, int linenr,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1261 const QString& line, QString& first_word)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1262 {
27893
465ac679e976 Fix typos and grammar errors in comments in libgui (patch #9790)
Andrew Janke <andrew@apjanke.net>
parents: 27753
diff changeset
1263 // Insert an "end" for an "if" etc., if needed.
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1264 // (Use of "while" allows "return" to skip the rest.
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1265 // It may be clearer to use "if" and "goto",
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1266 // 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
1267
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1268 bool autofill_simple_end = (auto_endif == 2);
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1269
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1270 std::size_t start = line.toStdString ().find_first_not_of (" \t");
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1271
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1272 // Check if following line has the same or less indentation
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1273 // Check if the following line does not start with
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1274 // end* (until) (catch)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1275 if (linenr < lines () - 1)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1276 {
27223
1ae91e5d70cc fix auto-close feature in editor when using tabs for indentation (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27198
diff changeset
1277 int offset = 2; // linenr is the old line, thus, linnr+1 is the
1ae91e5d70cc fix auto-close feature in editor when using tabs for indentation (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27198
diff changeset
1278 // new one and can not be taken into account
29654
d13d090cb03a use std::size_t and std::ptrdiff_t in C++ code (bug #60471)
John W. Eaton <jwe@octave.org>
parents: 29358
diff changeset
1279 std::size_t next_start;
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1280 QString next_line;
27117
e14e48e838fa Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents: 27101
diff changeset
1281
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1282 do // find next non-blank line
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1283 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1284 next_line = text (linenr + offset++);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1285 next_start = next_line.toStdString ().find_first_not_of (" \t\n");
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1286 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1287 while (linenr + offset < lines ()
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1288 && next_start == std::string::npos);
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1289
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1290 if (next_start == std::string::npos)
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1291 next_start = 0;
27117
e14e48e838fa Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents: 27101
diff changeset
1292 if (start == 0 && next_start == 0)
e14e48e838fa Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents: 27101
diff changeset
1293 return; // bug #56160, don't add at 0
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1294 if (next_start > start) // more indented => don't add "end"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1295 return;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1296 if (next_start == start) // same => check if already is "end"
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1297 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1298 QRegExp rx_start = QRegExp (R"((\w+))");
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1299 int tmp = rx_start.indexIn (next_line, start);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1300 if (tmp != -1 && is_end (rx_start.cap(1), first_word))
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1301 return;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1302 }
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1303 }
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1304
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1305 // 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
1306 // 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
1307
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1308 // 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
1309 // so add a dummy line.
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1310 if (linenr + 2 == lines ())
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1311 insertAt (QString ("\n"), linenr + 2, 0);
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1312
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1313 // 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
1314 if (first_word == "try")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1315 insertAt (QString (start, ' ')
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1316 + (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
1317 linenr + 2, 0);
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1318 else if (first_word == "unwind_protect")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1319 insertAt (QString (start, ' ')
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1320 + (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
1321 linenr + 2, 0);
25796
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1322
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1323 QString next_line;
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1324 if (first_word == "do")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1325 next_line = "until\n";
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1326 else if (first_word == "try")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1327 next_line = "catch\n";
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1328 else if (first_word == "unwind_protect")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1329 next_line = "unwind_protect_cleanup\n";
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1330 else if (autofill_simple_end)
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1331 next_line = "end\n";
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1332 else
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1333 {
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1334 if (first_word == "unwind_protect")
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1335 first_word = '_' + first_word;
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1336 next_line = "end" + first_word + "\n";
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23807
diff changeset
1337 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1338
27223
1ae91e5d70cc fix auto-close feature in editor when using tabs for indentation (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27198
diff changeset
1339 //insertAt (QString (start, ' ') + next_line, linenr + 2, 0);
1ae91e5d70cc fix auto-close feature in editor when using tabs for indentation (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27198
diff changeset
1340 insertAt (next_line, linenr + 2, 0);
1ae91e5d70cc fix auto-close feature in editor when using tabs for indentation (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27198
diff changeset
1341 setIndentation (linenr + 2, indentation (linenr));
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24593
diff changeset
1342 }
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1343
25796
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1344 void octave_qscintilla::dragEnterEvent (QDragEnterEvent *e)
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1345 {
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1346 // if is not dragging a url, pass to qscintilla to handle,
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1347 // otherwise ignore it so that it will be handled by
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1348 // the parent
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1349 if (!e->mimeData ()->hasUrls ())
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1350 {
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1351 QsciScintilla::dragEnterEvent (e);
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1352 }
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1353 else
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1354 {
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1355 e->ignore();
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1356 }
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25523
diff changeset
1357 }
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1358
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1359 void octave_qscintilla::handle_enter_debug_mode (void)
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1360 {
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1361 m_debug_mode = true;
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1362 }
31648
29d734430e5f maint: Re-indent code after switch to using namespace macros.
John W. Eaton <jwe@octave.org>
parents: 31646
diff changeset
1363
28798
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1364 void octave_qscintilla::handle_exit_debug_mode (void)
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1365 {
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1366 m_debug_mode = false;
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1367 }
82ccc4e69ba3 show value in editor when hovering over variable in debug mode (bug #56990)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 28548
diff changeset
1368
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31354
diff changeset
1369 OCTAVE_END_NAMESPACE(octave)
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
1370
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
1371 #endif