Mercurial > octave
annotate libgui/src/command-widget.cc @ 31649:deb553ac2c54
maint: Merge stable to default.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 15:45:27 -0500 |
parents | 431f80aba37a 29d734430e5f |
children | dd904ce6f53f |
rev | line source |
---|---|
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
1 //////////////////////////////////////////////////////////////////////// |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
2 // |
30564
796f54d4ddbf
update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents:
29787
diff
changeset
|
3 // Copyright (C) 2021-2022 The Octave Project Developers |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
4 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
5 // See the file COPYRIGHT.md in the top-level directory of this |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
6 // distribution or <https://octave.org/copyright/>. |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
7 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
8 // This file is part of Octave. |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
9 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
10 // Octave is free software: you can redistribute it and/or modify it |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
11 // under the terms of the GNU General Public License as published by |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
12 // the Free Software Foundation, either version 3 of the License, or |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
13 // (at your option) any later version. |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
14 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
15 // Octave is distributed in the hope that it will be useful, but |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
16 // WITHOUT ANY WARRANTY; without even the implied warranty of |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
18 // GNU General Public License for more details. |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
19 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
20 // You should have received a copy of the GNU General Public License |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
21 // along with Octave; see the file COPYING. If not, see |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
22 // <https://www.gnu.org/licenses/>. |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
23 // |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
24 //////////////////////////////////////////////////////////////////////// |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
25 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
26 #if defined (HAVE_CONFIG_H) |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
27 # include "config.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
28 #endif |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
29 |
31222
1a0756f7c90a
disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31086
diff
changeset
|
30 #if defined (HAVE_QSCINTILLA) |
1a0756f7c90a
disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31086
diff
changeset
|
31 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <QGroupBox> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include <QHBoxLayout> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #include <QLabel> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 #include <QLineEdit> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 #include <QPushButton> |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
37 #include <QTextEdit> |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
38 #include <QTextBlock> |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include <QVBoxLayout> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
40 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 #include "command-widget.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
43 #include "cmd-edit.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
44 #include "event-manager.h" |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
45 #include "gui-preferences-cs.h" |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
46 #include "gui-preferences-global.h" |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
47 #include "gui-settings.h" |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
48 #include "gui-utils.h" |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 #include "input.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 #include "interpreter.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
51 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
52 OCTAVE_BEGIN_NAMESPACE(octave) |
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
53 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
54 command_widget::command_widget (base_qobject& oct_qobj, QWidget *p) |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
55 : QWidget (p), m_incomplete_parse (false), |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
56 m_prompt (QString ()), |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
57 m_console (new console (this, oct_qobj)) |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
58 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
59 QPushButton *pause_button = new QPushButton (tr("Pause"), this); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
60 QPushButton *stop_button = new QPushButton (tr("Stop"), this); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 QPushButton *resume_button = new QPushButton (tr("Continue"), this); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
63 QGroupBox *input_group_box = new QGroupBox (); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 QHBoxLayout *input_layout = new QHBoxLayout; |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 input_layout->addWidget (pause_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 input_layout->addWidget (stop_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 input_layout->addWidget (resume_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
68 input_group_box->setLayout (input_layout); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 QVBoxLayout *main_layout = new QVBoxLayout (); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
71 main_layout->addWidget (m_console); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 main_layout->addWidget (input_group_box); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
73 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 setLayout (main_layout); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
75 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
76 setFocusProxy (m_console); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
77 |
29542
3d34b70b5a49
connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents:
29531
diff
changeset
|
78 connect (pause_button, &QPushButton::clicked, |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
79 this, &command_widget::interpreter_pause); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
81 connect (resume_button, &QPushButton::clicked, |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
82 this, &command_widget::interpreter_resume); |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
83 |
29542
3d34b70b5a49
connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents:
29531
diff
changeset
|
84 connect (stop_button, &QPushButton::clicked, |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
85 this, &command_widget::interpreter_stop); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
86 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
87 connect (this, &command_widget::new_command_line_signal, |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
88 m_console, &console::new_command_line); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
89 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
90 insert_interpreter_output ("\n\n Welcome to Octave\n\n"); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
91 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
92 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
93 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
94 void command_widget::init_command_prompt () |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
95 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
96 emit interpreter_event |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
97 ([=] (interpreter& interp) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
98 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
99 // INTERPRETER THREAD |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
100 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
101 event_manager& evmgr = interp.get_event_manager (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
102 input_system& input_sys = interp.get_input_system (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
103 std::string prompt = input_sys.PS1 (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
104 evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
105 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
106 emit new_command_line_signal (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
107 }); |
29787
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
108 } |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
109 |
29787
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
110 void command_widget::update_prompt (const QString& prompt) |
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
111 { |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
112 m_prompt = prompt; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
113 } |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
115 QString command_widget::prompt () |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
116 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
117 return m_prompt; |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
118 } |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
119 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 void command_widget::insert_interpreter_output (const QString& msg) |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
122 m_console->append (msg); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
123 } |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
125 void command_widget::process_input_line (const QString& input_line) |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
126 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
127 emit interpreter_event |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 ([=] (interpreter& interp) |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
129 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
130 // INTERPRETER THREAD |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
29531
41d53e20389e
fix newline issues in new command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29525
diff
changeset
|
132 interp.parse_and_execute (input_line.toStdString (), |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 m_incomplete_parse); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
134 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 event_manager& evmgr = interp.get_event_manager (); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 input_system& input_sys = interp.get_input_system (); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
137 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 std::string prompt |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
139 = m_incomplete_parse ? input_sys.PS2 () : input_sys.PS1 (); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
140 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 evmgr.update_prompt (command_editor::decode_prompt_string (prompt)); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
142 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
143 emit new_command_line_signal (); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
144 }); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
145 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
146 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
147 |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
148 void command_widget::notice_settings (void) |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
149 { |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
150 gui_settings settings; |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
151 |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
152 // Set terminal font: |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
153 QFont term_font = QFont (); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
154 term_font.setStyleHint (QFont::TypeWriter); |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
155 QString default_font = settings.value (global_mono_font).toString (); |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
156 term_font.setFamily |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
157 (settings.value (cs_font.key, default_font).toString ()); |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
158 term_font.setPointSize |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
159 (settings.value (cs_font_size).toInt ()); |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
160 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
161 m_console->setFont (term_font); |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
162 |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
163 // Colors |
31619
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
164 int mode = settings.value (cs_color_mode).toInt (); |
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
165 QColor fgc = settings.color_value (cs_colors[0], mode); |
ad014fc78bd6
use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
166 QColor bgc = settings.color_value (cs_colors[1], mode); |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
167 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
168 m_console->setStyleSheet (QString ("color: %1; background-color:%2;") |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
169 .arg (fgc.name ()).arg (bgc.name ())); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
170 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
171 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
172 // The console itself using QScintilla. |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
173 // This implementation is partly based on the basic concept of |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
174 // "qpconsole" as proposed by user "DerManu" in the Qt-forum thread |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
175 // https://forum.qt.io/topic/28765/command-terminal-using-qtextedit |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
176 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
177 console::console (command_widget *p, base_qobject&) |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
178 : QsciScintilla (p), |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
179 m_command_position (-1), |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
180 m_cursor_position (0), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
181 m_text_changed (false), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
182 m_command_widget (p), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
183 m_last_key_string (QString ()) |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
184 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
185 setMargins (0); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
186 setWrapMode (QsciScintilla::WrapWord); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
187 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
188 connect (this, SIGNAL (cursorPositionChanged (int, int)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
189 this, SLOT (cursor_position_changed (int, int))); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
190 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
191 connect (this, SIGNAL (textChanged (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
192 this, SLOT (text_changed (void))); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
193 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
194 connect (this, SIGNAL (modificationAttempted (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
195 this, SLOT (move_cursor_to_end (void))); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
196 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
197 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
198 // Prepare a new command line with the current prompt |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
199 void console::new_command_line (const QString& command) |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
200 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
201 if (! text (lines () -1).isEmpty ()) |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
202 append ("\n"); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
203 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
204 append_string (m_command_widget->prompt ()); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
205 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
206 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
207 getCursorPosition (&line,&index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
208 m_command_position = positionFromLineIndex (line, index); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
209 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
210 append_string (command); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
211 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
212 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
213 // Accept the current command line (or block) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
214 void console::accept_command_line () |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
215 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
216 QString input_line = text (lines () - 1); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
217 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
218 if (input_line.startsWith (m_command_widget->prompt ())) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
219 input_line.remove(0, m_command_widget->prompt ().length ()); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
220 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
221 input_line = input_line.trimmed (); |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
222 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
223 append_string ("\n"); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
224 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
225 if (input_line.isEmpty ()) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
226 new_command_line (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
227 else |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
228 m_command_widget->process_input_line (input_line); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
229 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
230 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
231 // Execute a command |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
232 void console::execute_command (const QString& command) |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
233 { |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
234 if (command.trimmed ().isEmpty ()) |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
235 return; |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
236 |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
237 new_command_line (command); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
238 accept_command_line (); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
239 } |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
240 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
241 // Append a string and update the curdor püosition |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
242 void console::append_string (const QString& string) |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
243 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
244 setReadOnly (false); |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
245 append (string); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
246 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
247 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
248 lineIndexFromPosition (text ().length (), &line, &index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
249 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
250 setCursorPosition (line, index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
251 } |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
252 |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
253 // Cursor position changed: Are we in the command line or not? |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
254 void console::cursor_position_changed (int line, int col) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
255 { |
31086
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
256 m_cursor_position = positionFromLineIndex (line, col); |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
257 if (m_cursor_position < m_command_position) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
258 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
259 // We are in the read only area |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
260 if (m_text_changed && (m_cursor_position == m_command_position - 1)) |
31086
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
261 { |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
262 setReadOnly (false); |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
263 insert (m_command_widget->prompt ().right (1)); // And here we have tried to remove the prompt by Backspace |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
264 setCursorPosition (line+1, col); |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
265 } |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
266 setReadOnly (true); |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
267 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
268 else |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
269 setReadOnly (false); // Writable area |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
270 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
271 m_text_changed = false; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
272 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
273 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
274 // User attempted to type on read only mode: move cursor at end and allow |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
275 // editing |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
276 void console::move_cursor_to_end (void) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
277 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
278 if ((! m_last_key_string.isEmpty ()) && (m_last_key_string.at (0).isPrint ())) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
279 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
280 append_string (m_last_key_string); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
281 setReadOnly (true); // Avoid that changing read only text is done afterwards |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
282 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
283 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
284 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
285 // Text has changed: is cursor still in "writable" area? |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
286 // This signal seems to be emitted before cursor position changed. |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
287 void console::text_changed (void) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
288 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
289 m_text_changed = true; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
290 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
291 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
292 // Re-implement key event |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
293 void console::keyPressEvent (QKeyEvent *e) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
294 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
295 if (e->key () == Qt::Key_Return) |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
296 // On "return", accept the current command line |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
297 accept_command_line (); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
298 else |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
299 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
300 // Otherwise, store text process the expected event |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
301 m_last_key_string = e->text (); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
302 QsciScintilla::keyPressEvent(e); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
303 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
304 } |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
305 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
306 OCTAVE_END_NAMESPACE(octave) |
31222
1a0756f7c90a
disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31086
diff
changeset
|
307 |
31549
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
31222
diff
changeset
|
308 #endif |