Mercurial > octave
annotate libgui/src/m-editor/octave-qscintilla.cc @ 27556:410622ac120f
improve run selection from editor (bug #42705)
* file-editor-tab.cc (file_editor_tab): relay interpreter event signals
to the ones of the editor widget
* file-editor.cc (make_file_editor_tab): connect signal of edit area for
giving focus to console window to the new slot in main_window
* octave-qscintilla.cc: include headers required for interpreter threads
and for additionally used Qt libs;
(octave_qscintilla): connect new signals for finished run selection
action to the new related slot;
(contextmenu_run_temp_error): new method displaying a message box on
error handling temp. files;
(contextmenu_run): create a temp. file with all selected lines extended
by commands for displaying each line and add it to the command history,
disable opening a file at breakpoints, run this temp. file by the
interpreter and emit new signal when running this file is finished;
(ctx_menu_run_finished): slot when running the temp. file is finished,
removing temp. files and reset modified editor preferences;
* octave-qscintilla.h: include QSettings and interpreter-events,
interpreter signal, signal for focusing console window and signal when
running temp file is finished, new slot for the latter
* main-window.cc (focus_console_after_command): do not return the related
setting, but actually give console window the focus if desired,
(run_file_in_terminal, execute_command_in_terminal): use this new form
* main-window.h: change focus_console_method from private method into
public slot
* resource-manager.cc (resource_manager): initialize new list of created
temp. files;
(~resource_manager): remove any temp. files that are still existing;
(do_create_tmp_file): create a new temp. file with the given contents
and store its smart pointer into a list for removing the file later;
(do_remove_tmp_file): remove given temp. file and remove it from the list;
* resource-manager.h: include QPointer and QTemporaryFile,
(create_tmp_file): new static method calling internal do_create_tmp_file;
(remove_tmp_file): new static method calling internal do_create_tmp_file;
new internal methods do_create_tmp_file and do_remove_tmp_file,
new list for storing temp. file pointers
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 25 Oct 2019 07:36:37 +0200 |
parents | 15752c577f6d |
children | 3fcc650de22f |
rev | line source |
---|---|
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
1 /* |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
2 |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25952
diff
changeset
|
3 Copyright (C) 2013-2019 Torsten |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
4 |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
5 This file is part of Octave. |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
6 |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24475
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24475
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
10 (at your option) any later version. |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22411
diff
changeset
|
15 GNU General Public License for more details. |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
16 |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
17 You should have received a copy of the GNU General Public License |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
24475
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
20 |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
21 */ |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
22 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
23 // Author: Torsten Lilge <ttl-octave@mailbox.org> |
16768 | 24 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
25 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21203
diff
changeset
|
26 # include "config.h" |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
27 #endif |
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
28 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
29 #if defined (HAVE_QSCINTILLA) |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
30 |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
31 #include <Qsci/qscilexer.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
32 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
33 #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
|
34 #include <QKeySequence> |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
35 #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
|
36 #include <QMimeData> |
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
37 #include <QShortcut> |
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
38 #include <QToolTip> |
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
39 #include <QVBoxLayout> |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
40 #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
|
41 # 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
|
42 # 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
|
43 #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
|
44 # 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
|
45 # 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
|
46 #endif |
27412
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
47 #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
|
48 #include <Qsci/qscilexerbash.h> |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
49 #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
|
50 #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
|
51 #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
|
52 #include <Qsci/qscilexerperl.h> |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
53 |
27412
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
54 #include "file-editor-tab.h" |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
55 #include "gui-preferences.h" |
27412
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
56 // 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
|
57 #include "marker.h" |
da1f59fe04b3
try to use consitent ordering for include files in libgui sources
John W. Eaton <jwe@octave.org>
parents:
27276
diff
changeset
|
58 #include "octave-qscintilla.h" |
25443
2fa7cd178c4a
new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
59 #include "resource-manager.h" |
2fa7cd178c4a
new class for miscellaneous interpreter settings
John W. Eaton <jwe@octave.org>
parents:
25103
diff
changeset
|
60 #include "shortcut-manager.h" |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
61 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
62 #include "builtin-defun-decls.h" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
63 #include "cmd-edit.h" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
64 #include "interpreter-private.h" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
65 #include "interpreter.h" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
66 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
67 // 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
|
68 // 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
|
69 // 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
|
70 // 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
|
71 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
72 namespace octave |
18560
26d15a57f45b
add menu entries and shortcuts for zoom functions in the editor (bug #41516)
Torsten <ttl@justmail.de>
parents:
18460
diff
changeset
|
73 { |
27101
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
74 static bool |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
75 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
|
76 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
77 bool retval = false; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
78 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
79 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
|
80 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
81 if (candidate == "until") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
82 retval = true; |
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 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
85 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
86 if (candidate == "end") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
87 retval = true; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
88 else |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
89 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
90 if (opening == "try") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
91 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
92 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
|
93 retval = true; |
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 else if (opening == "unwind_protect") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
96 { |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
97 if (candidate == "unwind_protect_cleanup" |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
98 || candidate == "end_unwind_protect") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
99 retval = true; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
100 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
101 else if (candidate == "end" + opening) |
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 else if (opening == "if" && candidate == "else") |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
104 retval = true; |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
105 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
106 } |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
107 |
097774bed4ed
move some static functions inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
26634
diff
changeset
|
108 return retval; |
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 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
111 octave_qscintilla::octave_qscintilla (QWidget *p) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
112 : QsciScintilla (p), m_word_at_cursor (), m_selection (), |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
113 m_selection_replacement (), m_selection_line (-1), |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
114 m_selection_col (-1), m_indicator_id (1) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
115 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
116 connect (this, SIGNAL (textChanged (void)), |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
117 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
|
118 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
119 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
|
120 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
|
121 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
122 connect (this, SIGNAL (ctx_menu_run_finished_signal (bool, QTemporaryFile*, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
123 QTemporaryFile*, QTemporaryFile*)), |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
124 this, SLOT (ctx_menu_run_finished (bool, QTemporaryFile*, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
125 QTemporaryFile*, QTemporaryFile*)), |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
126 Qt::QueuedConnection); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
127 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
128 // 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
|
129 QsciCommandSet *cmd_set = standardCommands (); |
18675
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
130 |
25523
5daeb4049088
gui: fix editor rendering on some displays, disable QScintilla buffered drawing
Mike Miller <mtmiller@octave.org>
parents:
25103
diff
changeset
|
131 // 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
|
132 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
|
133 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
134 #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
|
135 // 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
|
136 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
|
137 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
|
138 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
|
139 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
|
140 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
|
141 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
|
142 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
|
143 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
|
144 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
|
145 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
|
146 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
|
147 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
|
148 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
|
149 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
|
150 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
|
151 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
|
152 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
|
153 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
|
154 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
|
155 #else |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
156 // 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
|
157 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
|
158 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
|
159 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
160 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
|
161 switch (cmd_key) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
162 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
163 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
|
164 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
|
165 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
|
166 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
|
167 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
|
168 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
|
169 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
|
170 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
|
171 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
|
172 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
|
173 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
|
174 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
|
175 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
|
176 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
|
177 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
|
178 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
|
179 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
|
180 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
|
181 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
|
182 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
|
183 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
|
184 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
|
185 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
186 } |
18675
c199304dfb2a
handling qscintilla internal shortcuts and commands depending on qsci version
Torsten <ttl@justmail.de>
parents:
18656
diff
changeset
|
187 #endif |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
188 |
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
189 #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
|
190 // Octave interprets Cmd key as Meta whereas Qscintilla interprets it |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
191 // as Ctrl. We thus invert Meta/Ctrl in Qscintilla's shortcuts list. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
192 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
|
193 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
|
194 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
195 // Primary key |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
196 int key = cmd_list_mac.at (i)->key (); |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
197 |
25951 | 198 if (static_cast<int> (key | Qt::META) == key |
199 && 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
|
200 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
|
201 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
|
202 key = (key ^ Qt::CTRL) | Qt::META; |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
203 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
204 cmd_list_mac.at (i)->setKey (key); |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
205 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
206 // Alternate key |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
207 key = cmd_list_mac.at (i)->alternateKey (); |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
208 |
25951 | 209 if (static_cast<int> (key | Qt::META) == key |
210 && 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
|
211 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
|
212 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
|
213 key = (key ^ Qt::CTRL) | Qt::META; |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
214 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
215 cmd_list_mac.at (i)->setAlternateKey (key); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
216 } |
18954
c6b89c4a9e63
Swap Ctrl and Meta in Qscintilla shortcut list for mac (bug #41217)
pantxo <pantxo.diribarne@gmail.com>
parents:
18767
diff
changeset
|
217 #endif |
20986
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
218 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
219 // selection markers |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
220 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
221 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
|
222 if (m_indicator_id == -1) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
223 m_indicator_id = 1; |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
224 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
225 setIndicatorDrawUnder (true, m_indicator_id); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
226 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
227 markerDefine (QsciScintilla::Minus, marker::selection); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
228 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
229 // 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
|
230 emit status_update (isUndoAvailable (), isRedoAvailable ()); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
231 } |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
232 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
233 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
|
234 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
235 QColor ic = c; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
236 ic.setAlphaF (0.25); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
237 setIndicatorForegroundColor (ic, m_indicator_id); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
238 setIndicatorOutlineColor (ic, m_indicator_id); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
239 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
240 setMarkerForegroundColor (c, marker::selection); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
241 setMarkerBackgroundColor (c, marker::selection); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
242 } |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
243 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
244 // context menu requested |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
245 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
|
246 { |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
247 #if defined (HAVE_QSCI_VERSION_2_6_0) |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
248 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
|
249 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
|
250 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
251 bool in_left_margin = false; |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
252 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
253 // 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
|
254 if (e->reason () == QContextMenuEvent::Mouse) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
255 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
256 // context menu by mouse |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
257 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
|
258 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
|
259 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
|
260 in_left_margin = true; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
261 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
262 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
263 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
264 // 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
|
265 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
|
266 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
|
267 editor_rect.moveTopLeft |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
268 (parentWidget ()->mapToGlobal (editor_rect.topLeft ())); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
269 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
|
270 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
|
271 } |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
272 |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
273 #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
|
274 if (! in_left_margin) |
21371
dc3252099232
Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
275 #endif |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
276 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
277 // 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
|
278 emit create_context_menu_signal (context_menu); |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
279 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
280 // 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
|
281 context_menu->addSeparator (); // separator before custom entries |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
282 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
283 // 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
|
284 // (only for octave files) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
285 QString lexer_name = lexer ()->lexer (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
286 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
|
287 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
288 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
|
289 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
|
290 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
291 context_menu->addAction (tr ("Help on") + ' ' + m_word_at_cursor, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
292 this, SLOT (contextmenu_help (bool))); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
293 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
|
294 + ' ' + m_word_at_cursor, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
295 this, SLOT (contextmenu_doc (bool))); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
296 context_menu->addAction (tr ("Edit") + ' ' + m_word_at_cursor, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
297 this, SLOT (contextmenu_edit (bool))); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
298 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
299 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
300 } |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21578
diff
changeset
|
301 #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
|
302 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
303 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
304 // 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
|
305 QList<QAction *> all_actions = context_menu->actions (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
306 QAction *a; |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
307 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
308 foreach (a, all_actions) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
309 context_menu->removeAction (a); |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
310 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
311 a = context_menu->addAction (tr ("dbstop if ..."), this, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
312 SLOT (contextmenu_break_condition (bool))); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
313 a->setData (local_pos); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
314 } |
21371
dc3252099232
Allow GUI build with QScintilla 2.4 (bug #47226).
Lachlan Andrew <lachlanbis@gmail.com>
parents:
21301
diff
changeset
|
315 #endif |
16735
cee305c91e91
show help menu in editors context menu only for octave files
Torsten <ttl@justmail.de>
parents:
16733
diff
changeset
|
316 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
317 // finaly show the menu |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
318 context_menu->exec (global_pos); |
20277
48d9001bdee3
Avoid HAVE_ macros in header file.
John W. Eaton <jwe@octave.org>
parents:
19697
diff
changeset
|
319 #endif |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
320 } |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
321 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
322 // 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
|
323 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
|
324 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
325 if (documentation) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
326 emit show_doc_signal (m_word_at_cursor); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
327 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
328 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
|
329 } |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
330 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
331 // 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
|
332 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
|
333 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
334 if (get_actual_word ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
335 contextmenu_edit (true); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
336 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
337 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
338 // 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
|
339 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
|
340 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
341 if (hasSelectedText ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
342 contextmenu_run (true); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
343 } |
17628
99ffa521ecec
Add possibility to edit the function related to the actual keyword in editor
Torsten <ttl@justmail.de>
parents:
17627
diff
changeset
|
344 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
345 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
|
346 QPoint *local_pos) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
347 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
348 long position = SendScintilla (SCI_GETCURRENTPOS); |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
349 long point_x = SendScintilla (SCI_POINTXFROMPOSITION,0,position); |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
350 long point_y = SendScintilla (SCI_POINTYFROMPOSITION,0,position); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
351 *local_pos = QPoint (point_x,point_y); // local cursor position |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
352 *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
|
353 } |
17635
7945344506ae
Add possibility to run selected text of the editor in the terminal
Torsten <ttl@justmail.de>
parents:
17628
diff
changeset
|
354 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
355 // 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
|
356 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
|
357 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
358 QPoint global_pos, local_pos; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
359 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
|
360 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
|
361 QString lexer_name = lexer ()->lexer (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
362 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
|
363 && ! m_word_at_cursor.isEmpty ()); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
364 } |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
365 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
366 // 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
|
367 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
|
368 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
369 int end_pos = text ().length (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
370 int end_line, end_col; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
371 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
|
372 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
|
373 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
374 markerDeleteAll (marker::selection); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
375 } |
21158
65827e9cccb8
Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20986
diff
changeset
|
376 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
377 // 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
|
378 // is taken into account. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
379 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
|
380 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
381 *pos = SendScintilla (QsciScintillaBase::SCI_GETCURRENTPOS); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
382 *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
|
383 *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
|
384 } |
20986
00835323fb44
prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents:
20955
diff
changeset
|
385 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
386 // 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
|
387 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
|
388 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
389 int lexer = SendScintilla (SCI_GETLEXER); |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
390 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
391 switch (lexer) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
392 { |
24222
7d1561c9ee48
prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents:
24190
diff
changeset
|
393 #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
|
394 #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
|
395 case SCLEX_OCTAVE: |
24222
7d1561c9ee48
prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents:
24190
diff
changeset
|
396 #else |
7d1561c9ee48
prevent ignoring octave lexer when determining comment string (bug #52364)
Torsten <mttl@mailbox.org>
parents:
24190
diff
changeset
|
397 case SCLEX_MATLAB: |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
398 #endif |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
399 { |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
400 QSettings *settings = resource_manager::get_settings (); |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
401 int comment_string; |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
402 |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
403 if (comment) |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
404 { |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
405 // The commenting string is requested |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
406 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
|
407 // new version (radio buttons) |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
408 comment_string = settings->value (ed_comment_str.key, |
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
409 ed_comment_str.def).toInt (); |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
410 else |
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
411 // old version (combo box) |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
412 comment_string = settings->value (ed_comment_str_old.key, |
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
413 ed_comment_str.def).toInt (); |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
414 |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
415 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
|
416 } |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
417 else |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
418 { |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
419 QStringList c_str; |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
420 |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
421 // The possible uncommenting string(s) are requested |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
422 comment_string = settings->value (ed_uncomment_str.key, |
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
423 ed_uncomment_str.def).toInt (); |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
424 |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
425 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
|
426 { |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
427 if (1 << i & comment_string) |
25617
44d638d5eea5
reorganize constants for preferences keys and default values
Torsten <mttl@mailbox.org>
parents:
25527
diff
changeset
|
428 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
|
429 } |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
430 |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
431 return c_str; |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
432 } |
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
433 |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
434 } |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
435 #endif |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
436 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
437 case SCLEX_PERL: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
438 case SCLEX_BASH: |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
439 case SCLEX_DIFF: |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
440 return QStringList ("#"); |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
441 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
442 case SCLEX_CPP: |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
443 return QStringList ("//"); |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
444 |
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
445 case SCLEX_BATCH: |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
446 return QStringList ("REM "); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
447 } |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
448 |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
449 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
|
450 } |
23234
aaf20024db6f
function providing comment strings uses lexer number and not lexer names
Torsten <mttl@mailbox.org>
parents:
23230
diff
changeset
|
451 |
24475
8cb985e362f3
Allow uncommenting with any kind of comment (bug #52695):
Torsten <mttl@mailbox.org>
parents:
24232
diff
changeset
|
452 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
453 // 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
|
454 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
|
455 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
456 int position; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
457 if (pos < 0) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
458 // 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
|
459 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
|
460 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
461 position = pos; |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
462 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
463 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
|
464 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
465 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
466 // 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
|
467 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
|
468 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
469 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
|
470 int style = get_style (pos); |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
471 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
472 switch (lexer) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
473 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
474 case SCLEX_CPP: |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
27223
diff
changeset
|
475 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
|
476 || style == QsciLexerCPP::CommentLineDoc) |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
27223
diff
changeset
|
477 + 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
|
478 || style == QsciLexerCPP::CommentDoc |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
479 || style == QsciLexerCPP::CommentDocKeyword |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
27223
diff
changeset
|
480 || style == QsciLexerCPP::CommentDocKeywordError)); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
481 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
482 #if defined (HAVE_LEXER_MATLAB) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
483 case SCLEX_MATLAB: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
484 return (ST_LINE_COMMENT * (style == QsciLexerMatlab::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
485 #endif |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
486 #if defined (HAVE_LEXER_OCTAVE) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
487 case SCLEX_OCTAVE: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
488 return (ST_LINE_COMMENT * (style == QsciLexerOctave::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
489 #endif |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
490 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
491 case SCLEX_PERL: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
492 return (ST_LINE_COMMENT * (style == QsciLexerPerl::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
493 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
494 case SCLEX_BATCH: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
495 return (ST_LINE_COMMENT * (style == QsciLexerBatch::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
496 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
497 case SCLEX_DIFF: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
498 return (ST_LINE_COMMENT * (style == QsciLexerDiff::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
499 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
500 case SCLEX_BASH: |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
501 return (ST_LINE_COMMENT * (style == QsciLexerBash::Comment)); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
502 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
503 } |
23688
cb36684b7a33
In the GUI editor, automatically add "endif" for "if" etc.
Lachlan Andrew <lachlanbis@gmail.com>
parents:
23449
diff
changeset
|
504 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
505 return ST_NONE; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
506 } |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
507 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
508 // Do smart indendation 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
|
509 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
|
510 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
|
511 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
512 QString prevline = text (line); |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
513 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
514 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
|
515 "|do|function|properties|events|classdef" |
26480
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
516 "|unwind_protect|try" |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
517 "|parfor|methods)" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
518 "[\r]?[\n\t #%]"); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
519 // 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
|
520 // rx_end = QRegExp ("(\\w+)[ \t;\r\n]*([%#][^\"']*)?$"); |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
521 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
522 // last word except for comments, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
523 // allowing % and # in single or double quoted strings |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
524 // FIXME This will get confused by transpose. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
525 QRegExp ekey = QRegExp ("(?:(?:['\"][^'\"]*['\"])?[^%#]*)*" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
526 "(\\w+)[ \t;\r\n]*([%#].*)?$"); |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
527 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
528 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
|
529 int epos; |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
530 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
531 if (bpos > -1) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
532 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
533 // Found keyword after that indentation should be added |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
534 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
535 // 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
|
536 epos = ekey.indexIn (prevline, bpos); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
537 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
|
538 bool inline_end = (epos > -1) && is_end (ekey.cap(1), first_word); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
539 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
540 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
|
541 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
542 // 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
|
543 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
|
544 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
|
545 } |
23771
ed492a5a47fd
eliminate duplicate code in editor smart indentation and auto close
Torsten <mttl@mailbox.org>
parents:
23735
diff
changeset
|
546 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
547 if (do_auto_close |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
548 && ! inline_end |
27276
7455523fdf01
style fixes: avoid breaking lines immediately after '('
John W. Eaton <jwe@octave.org>
parents:
27223
diff
changeset
|
549 && ! 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
|
550 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
551 // Do auto close |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
552 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
|
553 } |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
554 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
555 return; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
556 } |
23689
b729e97aa8d1
move smart indendation from file_editor_tab to octave_qscintilla
Torsten <mttl@mailbox.org>
parents:
23688
diff
changeset
|
557 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
558 QRegExp mkey = QRegExp ("^[\t ]*(else|elseif|catch|unwind_protect_cleanup)" |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
559 "[\r]?[\t #%\n]"); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
560 if (prevline.contains (mkey)) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
561 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
562 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
|
563 int act_ind = indentation (line); |
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 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
|
566 unindent (line); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
567 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
|
568 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
569 setIndentation (line+1, prev_ind); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
570 setCursorPosition (line+1, prev_ind); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
571 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
572 return; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
573 } |
24232
e0bcd17ac070
smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents:
24222
diff
changeset
|
574 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
575 QRegExp case_key = QRegExp ("^[\t ]*(case|otherwise)[\r]?[\t #%\n]"); |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
576 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
|
577 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
578 QString last_line = text (line-1); |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
579 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
|
580 |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
581 if (last_line.contains ("switch")) |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
582 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
583 indent (line+1); |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
584 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
|
585 } |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
586 else |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
587 unindent (line); |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
588 |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
589 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
|
590 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
|
591 } |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
592 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
593 ekey = QRegExp ("^[\t ]*(end|endif|endfor|endwhile|until|endfunction" |
26480
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
594 "|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
|
595 if (prevline.contains (ekey)) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
596 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
597 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
|
598 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
599 unindent (line+1); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
600 unindent (line); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
601 setCursorPosition (line+1, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
602 indentation (line)); |
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; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
605 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
606 } |
24232
e0bcd17ac070
smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents:
24222
diff
changeset
|
607 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
608 // Do smart indendation of current selection or line. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
609 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
|
610 int lineTo) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
611 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
612 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
|
613 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
614 QRegExp begin_block_regexp |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
615 = QRegExp ("^([\t ]*)(if|elseif|else" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
616 "|for|while|do|parfor" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
617 "|switch|case|otherwise" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
618 "|function" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
619 "|classdef|properties|events|enumeration|methods" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
620 "|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
|
621 "[\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
|
622 |
26480
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
623 QRegExp mid_block_regexp |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
624 = QRegExp ("^([\t ]*)(elseif|else" |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
625 "|otherwise" |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
626 "|unwind_protect_cleanup|catch)" |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
627 "[\r\n\t #%]"); |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
628 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
629 QRegExp end_block_regexp |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
630 = QRegExp ("^([\t ]*)(end" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
631 "|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
|
632 "|classdef|enumeration|events|methods|properties)" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
633 "|end_(try_catch|unwind_protect)" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
634 "|until)" |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
635 "[\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
|
636 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
637 QRegExp case_block_regexp |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
638 = QRegExp ("^([\t ]*)(case|otherwise)" |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
639 "[\r\n\t #%]"); |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
640 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
641 int indent_column = -1; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
642 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
|
643 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
|
644 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
645 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
|
646 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
647 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
|
648 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
649 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
|
650 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
651 // 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
|
652 // 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
|
653 // 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
|
654 // 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
|
655 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
656 indent_column = indentation (line); |
24232
e0bcd17ac070
smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents:
24222
diff
changeset
|
657 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
658 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
|
659 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
660 indent_column += indent_increment; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
661 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
|
662 in_switch = true; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
663 } |
24232
e0bcd17ac070
smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents:
24222
diff
changeset
|
664 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
665 break; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
666 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
667 } |
24232
e0bcd17ac070
smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents:
24222
diff
changeset
|
668 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
669 if (indent_column < 0) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
670 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
|
671 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
672 QString prev_line; |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
673 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
|
674 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
675 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
|
676 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
677 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
|
678 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
679 indent_column -= indent_increment; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
680 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
|
681 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
682 // 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
|
683 if (in_switch) |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
684 indent_column -= indent_increment; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
685 in_switch = false; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
686 } |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
687 } |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
688 |
26480
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
689 if (mid_block_regexp.indexIn (line_text) > -1) |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
690 indent_column -= indent_increment; |
4203f6e0cd7d
Allow indent of mid block keywords (#55276)
John Donoghue
parents:
26376
diff
changeset
|
691 |
26634
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
692 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
|
693 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
694 if (case_block_regexp.indexIn (prev_line) < 0 && !prev_line.contains("switch")) |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
695 indent_column -= indent_increment; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
696 in_switch = true; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
697 } |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
698 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
699 setIndentation (line, indent_column); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
700 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
701 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
|
702 { |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
703 indent_column += indent_increment; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
704 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
|
705 in_switch = true; |
48ddf51a6ef7
Update smart indent code for case/otherwise (Bug #55276)
John Donoghue <john.donoghue@ieee.org>
parents:
26480
diff
changeset
|
706 } |
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 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
|
709 prev_line = line_text; |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
710 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
711 } |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
712 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
713 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
|
714 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
715 m_selection = word; |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
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 (word.isEmpty ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
718 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
719 m_selection_line = -1; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
720 m_selection_col = -1; |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
721 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
722 m_selection_replacement = ""; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
723 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
724 clear_selection_markers (); |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
725 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
726 QToolTip::hideText (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
727 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
728 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
729 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
730 int pos; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
731 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
|
732 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
733 } |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
734 |
27455
e92bab9a7f26
fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
26634
diff
changeset
|
735 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
|
736 { |
27455
e92bab9a7f26
fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
26634
diff
changeset
|
737 fillIndicatorRange (l1, c1, l2, c2, m_indicator_id); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
738 |
27455
e92bab9a7f26
fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
26634
diff
changeset
|
739 if (l1 == l2) |
e92bab9a7f26
fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
26634
diff
changeset
|
740 markerAdd (l1, marker::selection); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
741 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
742 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
743 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
|
744 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
745 contextmenu_help_doc (false); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
746 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
747 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
748 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
|
749 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
750 contextmenu_help_doc (true); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
751 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
752 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
753 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
|
754 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
755 if (get_actual_word ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
756 contextmenu_help_doc (documentation); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
757 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
758 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
759 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
|
760 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
761 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
|
762 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
763 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
764 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
|
765 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
766 QMessageBox::critical (this, tr ("Octave Editor"), |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
767 tr ("Creating temporary files failed.\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
768 "Make sure you have write access to temp. directory\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
769 "%1\n\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
770 "\"Run Selection\" requires temporary files.").arg (QDir::tempPath ())); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
771 } |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
772 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
773 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
|
774 { |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
775 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
776 // Create tmp file required for adding command to history |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
777 QPointer<QTemporaryFile> tmp_hist |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
778 = resource_manager::create_tmp_file (); // empty tmp file for history |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
779 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
780 // Create tmp file required for the script echoing and adding cmd to hist |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
781 QPointer<QTemporaryFile> tmp_script |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
782 = resource_manager::create_tmp_file ("m"); // tmp script file |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
783 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
784 bool tmp = (tmp_hist && tmp_hist->open () && |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
785 tmp_script && tmp_script->open()); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
786 if (! tmp) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
787 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
788 // 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
|
789 contextmenu_run_temp_error (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
790 return; |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
791 } |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
792 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
793 tmp_hist->close (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
794 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
795 QString tmp_hist_name = QFileInfo (tmp_hist->fileName ()).baseName (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
796 QString tmp_script_name = QFileInfo (tmp_script->fileName ()).baseName (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
797 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
798 // Create tmp file with script for echoing a command and adding |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
799 // the the history |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
800 QString echo_hist = QString ( |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
801 "function cnt = %2 (oldcnt, i, command, line)\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
802 " cnt = oldcnt;\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
803 " if cnt < i\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
804 " cnt = i;\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
805 " disp ([PS1, command]);\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
806 " if (history_save ())\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
807 " fid = fopen ('%1','w');\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
808 " if (fid != -1)\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
809 " fprintf (fid, [line,'\\n']);\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
810 " fclose (fid);\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
811 " end;\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
812 " history -r '%1'\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
813 " end\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
814 " end\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
815 " end\n").arg (tmp_hist->fileName ()).arg (tmp_script_name); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
816 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
817 tmp_script->write (echo_hist.toUtf8 ()); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
818 tmp_script->close (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
819 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
820 // 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
|
821 // evaluated line and for adding the line to the history (use script) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
822 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
823 QString tmp_dir = QFileInfo (tmp_script->fileName ()).absolutePath (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
824 QString code = QString ("%1 = -1;\n\n").arg (tmp_hist_name); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
825 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
826 // 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
|
827 QStringList lines = selectedText ().split (QRegExp ("[\r\n]"), |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
828 QString::SkipEmptyParts); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
829 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
830 for (int i = 0; i < lines.count (); i++) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
831 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
832 QString line = lines.at (i); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
833 line = line.replace (QString ("%"), QString ("%%")); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
834 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
835 code += QString ("%1 = %2 (%1, %3, '%4', '%5');\n" |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
836 "%4\n\n") |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
837 .arg (tmp_hist_name) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
838 .arg (tmp_script_name) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
839 .arg (i) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
840 .arg (lines.at (i)) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
841 .arg (line); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
842 } |
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 code += QString ("clear %1 %2_fcn;\n") |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
845 .arg (tmp_hist_name).arg (tmp_script_name); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
846 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
847 // 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
|
848 QPointer<QTemporaryFile> tmp_file |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
849 = resource_manager::create_tmp_file ("m", code); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
850 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
851 tmp = (tmp_file && tmp_file->open ()); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
852 if (! tmp) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
853 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
854 // 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
|
855 contextmenu_run_temp_error (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
856 return; |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
857 } |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
858 tmp_file->close (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
859 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
860 // Disable opening a file at a breakpoint in case keyboard () is used |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
861 QSettings* settings = resource_manager::get_settings (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
862 bool show_dbg_file = settings->value (ed_show_dbg_file.key, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
863 ed_show_dbg_file.def).toBool (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
864 settings->setValue (ed_show_dbg_file.key, false); |
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 emit focus_console_after_command_signal (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
867 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
868 // 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
|
869 emit interpreter_event |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
870 ([this, tmp_file, tmp_hist, tmp_script, show_dbg_file] (interpreter& interp) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
871 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
872 // INTERPRETER THREAD |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
873 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
874 std::string file = tmp_file->fileName ().toStdString (); |
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 std::string pending_input = command_editor::get_current_line (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
877 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
878 // Add tmp dir to the path for echo/hist script |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
879 octave_value_list path = |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
880 ovl (QFileInfo (tmp_script->fileName ()).absolutePath ().toStdString ()); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
881 Faddpath (interp, path); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
882 interp.source_file (file); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
883 Frmpath (interp, path); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
884 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
885 command_editor::replace_line (""); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
886 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
|
887 command_editor::redisplay (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
888 command_editor::interrupt_event_loop (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
889 command_editor::accept_line (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
890 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
891 // Done, restore settings and remove tmp files |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
892 emit ctx_menu_run_finished_signal (show_dbg_file, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
893 tmp_file, tmp_hist, tmp_script); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
894 }); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
895 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
896 |
27556
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
897 void octave_qscintilla::ctx_menu_run_finished (bool show_dbg_file, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
898 QTemporaryFile* tmp_file, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
899 QTemporaryFile* tmp_hist, |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
900 QTemporaryFile* tmp_script) |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
901 { |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
902 QSettings *settings = resource_manager::get_settings (); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
903 settings->setValue (ed_show_dbg_file.key, show_dbg_file); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
904 resource_manager::remove_tmp_file (tmp_file); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
905 resource_manager::remove_tmp_file (tmp_hist); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
906 resource_manager::remove_tmp_file (tmp_script); |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
907 } |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
908 |
410622ac120f
improve run selection from editor (bug #42705)
Torsten Lilge <ttl-octave@mailbox.org>
parents:
27461
diff
changeset
|
909 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
910 // wrappers for dbstop related context menu items |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
911 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
912 // 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
|
913 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
|
914 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
915 #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
|
916 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
|
917 QPoint local_pos = action->data ().value<QPoint> (); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
918 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
919 // 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
|
920 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
|
921 local_pos = QPoint (margins + 1, local_pos.y ()); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
922 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
923 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
|
924 #endif |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
925 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
926 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
927 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
|
928 { |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
929 #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
|
930 emit context_menu_break_once (lineAt (local_pos)); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
931 #endif |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
932 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
933 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
934 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
|
935 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
936 emit status_update (isUndoAvailable (), isRedoAvailable ()); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
937 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
938 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
939 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
|
940 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
941 // 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
|
942 // 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
|
943 // 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
|
944 // selection until it is complete. |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
945 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
946 if (! m_selection.isEmpty () |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
947 && (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
|
948 set_word_selection (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
949 } |
24172
90903d915625
improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents:
24171
diff
changeset
|
950 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
951 // 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
|
952 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
|
953 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
954 emit status_update (isUndoAvailable (), isRedoAvailable ()); |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
955 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
956 QsciScintilla::focusInEvent (focusEvent); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
957 } |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
958 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
959 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
|
960 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
961 int pos; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
962 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
|
963 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
964 // Offer to replace other instances. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
965 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
966 QKeySequence keyseq = Qt::SHIFT + Qt::Key_Return; |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
967 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
968 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
|
969 . arg (keyseq.toString ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
970 . arg (m_selection) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
971 . arg (m_selection_replacement)); |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
972 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
973 QPoint global_pos; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
974 QPoint local_pos; |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
975 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
976 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
|
977 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
978 QFontMetrics ttfm (QToolTip::font ()); |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
979 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
980 // 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
|
981 // and the text that is currently being edited. |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
982 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
983 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
|
984 |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
985 QToolTip::showText (global_pos, msg); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
986 } |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
987 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
988 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
|
989 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
990 if (m_selection.isEmpty ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
991 QsciScintilla::keyPressEvent (key_event); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
992 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
993 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
994 int key = key_event->key (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
995 Qt::KeyboardModifiers modifiers = key_event->modifiers (); |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
996 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
997 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
|
998 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
999 // get the resulting cursor position |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1000 // (required if click was beyond a line ending) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1001 int pos, line, col; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1002 get_current_position (&pos, &line, &col); |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
1003 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1004 // remember first visible line for restoring the view afterwards |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1005 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
|
1006 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1007 // search for first occurrence of the detected word |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1008 bool find_result_available |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1009 = findFirst (m_selection, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1010 false, // no regexp |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1011 true, // case sensitive |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1012 true, // whole words only |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1013 false, // do not wrap |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1014 true, // forward |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1015 0, 0, // from the beginning |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1016 false |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1017 #if defined (HAVE_QSCI_VERSION_2_6_0) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1018 , true |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1019 #endif |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1020 ); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1021 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1022 while (find_result_available) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1023 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1024 replace (m_selection_replacement); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1025 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1026 // FIXME: is this the right thing to do? findNext doesn't |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1027 // work properly if the length of the replacement text is |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1028 // different from the original. |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1029 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1030 int new_line, new_col; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1031 get_current_position (&pos, &new_line, &new_col); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1032 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1033 find_result_available |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1034 = findFirst (m_selection, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1035 false, // no regexp |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1036 true, // case sensitive |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1037 true, // whole words only |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1038 false, // do not wrap |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1039 true, // forward |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1040 new_line, new_col, // from new pos |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1041 false |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1042 #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
|
1043 , true |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1044 #endif |
25103
078b795c5219
maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents:
25054
diff
changeset
|
1045 ); |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1046 } |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1047 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1048 // restore the visible area of the file, the cursor position, |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1049 // and the selection |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1050 setFirstVisibleLine (first_line); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1051 setCursorPosition (line, col); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1052 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1053 // Clear the selection. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1054 set_word_selection (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1055 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1056 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1057 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1058 // 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
|
1059 // 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
|
1060 // 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
|
1061 // 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
|
1062 // 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
|
1063 // DEL and ESC here? |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
1064 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1065 QString text = key_event->text (); |
24190
90fe16a3a5a1
improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents:
24187
diff
changeset
|
1066 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1067 bool cancel_replacement = false; |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1068 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1069 if (key == Qt::Key_Backspace) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1070 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1071 if (m_selection_replacement.isEmpty ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1072 cancel_replacement = true; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1073 else |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1074 m_selection_replacement.chop (1); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1075 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1076 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
|
1077 cancel_replacement = true; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1078 else if (! text.isEmpty ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1079 m_selection_replacement += text; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1080 else if (modifiers != Qt::ShiftModifier) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1081 cancel_replacement = true; |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1082 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1083 // Perform default action. |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1084 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1085 QsciScintilla::keyPressEvent (key_event); |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1086 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1087 if (cancel_replacement) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1088 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
|
1089 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1090 if (! m_selection_replacement.isEmpty ()) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1091 show_replace_action_tooltip (); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1092 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1093 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1094 } |
24187
ff9bd559799b
pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents:
24172
diff
changeset
|
1095 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1096 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
|
1097 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
|
1098 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1099 // Insert and "end" for an "if" etc., if needed. |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1100 // (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
|
1101 // 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
|
1102 // 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
|
1103 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1104 bool autofill_simple_end = (auto_endif == 2); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
1105 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1106 size_t start = line.toStdString ().find_first_not_of (" \t"); |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
1107 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1108 // 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
|
1109 // 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
|
1110 // end* (until) (catch) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1111 if (linenr < lines () - 1) |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1112 { |
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
|
1113 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
|
1114 // new one and can not be taken into account |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1115 size_t next_start; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1116 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
|
1117 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1118 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
|
1119 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1120 next_line = text (linenr + offset++); |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1121 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
|
1122 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1123 while (linenr + offset < lines () |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1124 && next_start == std::string::npos); |
27117
e14e48e838fa
Don't add extra closing endXXX keywords in GUI Editor (bug #56160).
Rik <rik@octave.org>
parents:
27101
diff
changeset
|
1125 |
24716
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1126 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
|
1127 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
|
1128 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
|
1129 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
|
1130 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
|
1131 return; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1132 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
|
1133 { |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1134 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
|
1135 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
|
1136 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
|
1137 return; |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1138 } |
2b3e0b570e77
move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents:
24593
diff
changeset
|
1139 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
1140 |
24020
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1141 // 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
|
1142 // 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
|
1143 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1144 // 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
|
1145 // so add a dummy line. |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1146 if (linenr + 2 == lines ()) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1147 insertAt (QString ("\n"), linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1148 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1149 // 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
|
1150 if (first_word == "try") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1151 insertAt (QString (start, ' ') |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1152 + (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
|
1153 linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1154 else if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1155 insertAt (QString (start, ' ') |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1156 + (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
|
1157 linenr + 2, 0); |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1158 |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1159 QString next_line; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1160 if (first_word == "do") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1161 next_line = "until\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1162 else if (first_word == "try") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1163 next_line = "catch\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1164 else if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1165 next_line = "unwind_protect_cleanup\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1166 else if (autofill_simple_end) |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1167 next_line = "end\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1168 else |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1169 { |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1170 if (first_word == "unwind_protect") |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1171 first_word = '_' + first_word; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1172 next_line = "end" + first_word + "\n"; |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1173 } |
387be1a6c3dc
style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents:
23807
diff
changeset
|
1174 |
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
|
1175 //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
|
1176 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
|
1177 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
|
1178 } |
25796
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1179 |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1180 void octave_qscintilla::dragEnterEvent (QDragEnterEvent *e) |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1181 { |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1182 // 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
|
1183 // 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
|
1184 // the parent |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1185 if (!e->mimeData ()->hasUrls ()) |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1186 { |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1187 QsciScintilla::dragEnterEvent (e); |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1188 } |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1189 else |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1190 { |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1191 e->ignore(); |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1192 } |
052a0d5dfd2c
Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents:
25523
diff
changeset
|
1193 } |
23236
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
1194 } |
4cd5f975d26c
automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents:
23234
diff
changeset
|
1195 |
16731
01d523d5f796
add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff
changeset
|
1196 #endif |