annotate libgui/src/m-editor/octave-qscintilla.h @ 27198:dffdabfd0213

fix cursor position for editor smart indent after keyword (bug #56533) * file-editor-tab.cc (notice_settings): initialize new class variable holding the width of the character used for indentation; (handle_cursor_moved): pass new class variable to smart_indent * file-editor-tab.h: new class variable for indentation character width * octave-qscintilla.cc (smart_indent): length of indentation character is a new parameter which is used for setting the cursor position at the end of the indentation of a new line * octave-qscintilla.cc (smart_indent): new parameter
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 25 Jun 2019 22:10:14 +0200
parents fbe46901ae62
children da1f59fe04b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
1 /*
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
2
26376
00f796120a6d maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents: 25796
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
16768
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16733
diff changeset
23 // Author: Torsten <ttl@justmail.de>
e2de3c8882be copyright notice fixes
John W. Eaton <jwe@octave.org>
parents: 16733
diff changeset
24
20791
f7084eae3318 maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents: 20277
diff changeset
25 #if ! defined (octave_octave_qscintilla_h)
17822
ebb3ef964372 maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents: 17635
diff changeset
26 #define octave_octave_qscintilla_h 1
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
27
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
28 #include <Qsci/qsciscintilla.h>
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
29
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
30 #include <QContextMenuEvent>
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
31 #include <QKeyEvent>
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
32 #include <QLabel>
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
33 #include <QMenu>
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
34
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
35 namespace octave
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
36 {
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
37 class octave_qscintilla : public QsciScintilla
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
38 {
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
39 Q_OBJECT
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
40
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
41 public:
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
42
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
43 octave_qscintilla (QWidget *p);
24020
387be1a6c3dc style fixes for GUI editor
John W. Eaton <jwe@octave.org>
parents: 23771
diff changeset
44
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
45 ~octave_qscintilla (void) = default;
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
46
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
47 enum
25103
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
48 {
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
49 ST_NONE = 0,
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
50 ST_LINE_COMMENT,
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
51 ST_BLOCK_COMMENT
078b795c5219 maint: style check C++ ahead of 4.4 release.
Rik <rik@octave.org>
parents: 25054
diff changeset
52 };
23236
4cd5f975d26c automatically add a comment string when line breaking in line comments
Torsten <mttl@mailbox.org>
parents: 23234
diff changeset
53
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
54 virtual void contextMenuEvent (QContextMenuEvent *e);
20277
48d9001bdee3 Avoid HAVE_ macros in header file.
John W. Eaton <jwe@octave.org>
parents: 19697
diff changeset
55
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
56 void context_help_doc (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
57 void context_edit (void);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
58 void context_run (void);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
59 void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
60 bool get_actual_word (void);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
61 void clear_selection_markers (void);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
62 void 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: 24534
diff changeset
63 QStringList comment_string (bool comment = true);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
64 int get_style (int pos = -1);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
65 int is_style_comment (int pos = -1);
27198
dffdabfd0213 fix cursor position for editor smart indent after keyword (bug #56533)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 27133
diff changeset
66 void 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
67 int line, int ind_char_width);
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
68
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
69 void smart_indent_line_or_selected_text (int lineFrom, int lineTo);
24232
e0bcd17ac070 smart indentation for selections or current line in code editor
John W. Eaton <jwe@octave.org>
parents: 24190
diff changeset
70
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
71 void set_word_selection (const QString& word = QString ());
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
72
27133
fbe46901ae62 fix editors search and replace in selection (bug #56405)
Torsten Lilge <ttl-octave@mailbox.org>
parents: 26376
diff changeset
73 void show_selection_markers (int l1, int c1, int l2, int c2);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
74
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
75 void set_selection_marker_color (const QColor& c);
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
76
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
77 signals:
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
78
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
79 void execute_command_in_terminal_signal (const QString&);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
80 void create_context_menu_signal (QMenu*);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
81 void context_menu_edit_signal (const QString&);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
82 void qsci_has_focus_signal (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
83 void status_update (bool, bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
84 void show_doc_signal (const QString&);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
85 void context_menu_break_condition_signal (int);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
86 void context_menu_break_once (int);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
87
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
88 private slots:
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
89
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
90 void contextmenu_help (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
91 void contextmenu_doc (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
92 void contextmenu_help_doc (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
93 void contextmenu_edit (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
94 void contextmenu_run (bool);
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
95
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
96 void contextmenu_break_condition (bool);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
97 void contextmenu_break_once (const QPoint&);
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
98
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
99 void text_changed (void);
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
100 void cursor_position_changed (int, int);
21158
65827e9cccb8 Gui support for enhancement of dbstop.
Lachlan Andrew <lachlanbis@gmail.com>
parents: 20986
diff changeset
101
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
102 protected:
18689
fac35875f6eb update enabled status of undo/redo actions in the editor
Torsten <ttl@justmail.de>
parents: 18687
diff changeset
103
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
104 void focusInEvent (QFocusEvent *focusEvent);
18684
86eca5d178a6 disable some global shortcuts when editor gets focus to prevent conflicts
Torsten <ttl@justmail.de>
parents: 18460
diff changeset
105
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
106 void show_replace_action_tooltip (void);
20986
00835323fb44 prevent shortcut ambiguity between main and editor window
Torsten <ttl@justmail.de>
parents: 20791
diff changeset
107
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
108 void keyPressEvent (QKeyEvent *e);
24190
90fe16a3a5a1 improve selection replacement in editor
John W. Eaton <jwe@octave.org>
parents: 24187
diff changeset
109
25796
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25103
diff changeset
110 void dragEnterEvent (QDragEnterEvent *e);
052a0d5dfd2c Reenable drag and drop of editor text (Bug #54495)
John Donoghue
parents: 25103
diff changeset
111
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
112 private:
24187
ff9bd559799b pop up tooltip message for changing selected words in editor
John W. Eaton <jwe@octave.org>
parents: 24172
diff changeset
113
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
114 void auto_close (int auto_endif, int l,
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
115 const QString& line, QString& first_word);
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
116
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
117 QString m_word_at_cursor;
24172
90903d915625 improve handling of selection markers in editor
John W. Eaton <jwe@octave.org>
parents: 24171
diff changeset
118
24716
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
119 QString m_selection;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
120 QString m_selection_replacement;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
121 int m_selection_line;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
122 int m_selection_col;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
123 int m_indicator_id;
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
124 };
2b3e0b570e77 move GUI file editor classes inside octave namespace
John W. Eaton <jwe@octave.org>
parents: 24534
diff changeset
125 }
16731
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
126
01d523d5f796 add help for word at mouse or text cursor to the editors context menu
Torsten <ttl@justmail.de>
parents:
diff changeset
127 #endif