Mercurial > octave
annotate libgui/src/command-widget.cc @ 31086:d5696a4efa84
exp cmd widget: fix preventing prompt deletion
* command-widget.cc (cursor_position_changed): store current position in
correct variable, add last char of prompt if deleted this by backspace
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Fri, 10 Jun 2022 18:02:21 +0200 |
parents | b818d4ec035e |
children | 1a0756f7c90a |
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 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
30 #include <QGroupBox> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 #include <QHBoxLayout> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include <QLabel> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
33 #include <QLineEdit> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 #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
|
35 #include <QTextEdit> |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
36 #include <QTextBlock> |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 #include <QVBoxLayout> |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
38 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
39 #include "command-widget.h" |
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 "cmd-edit.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 #include "event-manager.h" |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
43 #include "gui-preferences-cs.h" |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
44 #include "gui-preferences-global.h" |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
45 #include "gui-utils.h" |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
46 #include "input.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
47 #include "interpreter.h" |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
48 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
49 namespace octave |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
50 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
51 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
|
52 : 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
|
53 m_prompt (QString ()), |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
54 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
|
55 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
56 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
|
57 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
|
58 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
|
59 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
60 QGroupBox *input_group_box = new QGroupBox (); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
61 QHBoxLayout *input_layout = new QHBoxLayout; |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
62 input_layout->addWidget (pause_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
63 input_layout->addWidget (stop_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
64 input_layout->addWidget (resume_button); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
65 input_group_box->setLayout (input_layout); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
66 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
67 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
|
68 main_layout->addWidget (m_console); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
69 main_layout->addWidget (input_group_box); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
70 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
71 setLayout (main_layout); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
72 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
73 setFocusProxy (m_console); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
74 |
29542
3d34b70b5a49
connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents:
29531
diff
changeset
|
75 connect (pause_button, &QPushButton::clicked, |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
76 this, &command_widget::interpreter_pause); |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
77 |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
78 connect (resume_button, &QPushButton::clicked, |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
79 this, &command_widget::interpreter_resume); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
29542
3d34b70b5a49
connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents:
29531
diff
changeset
|
81 connect (stop_button, &QPushButton::clicked, |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29542
diff
changeset
|
82 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
|
83 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
84 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
|
85 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
|
86 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
87 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
|
88 |
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 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
91 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
|
92 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
93 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
|
94 ([=] (interpreter& interp) |
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 // INTERPRETER THREAD |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
97 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
98 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
|
99 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
|
100 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
|
101 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
|
102 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
103 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
|
104 }); |
29787
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
105 } |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
106 |
29787
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
107 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
|
108 { |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
109 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
|
110 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
111 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
112 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
|
113 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
114 return m_prompt; |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
115 } |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
116 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
117 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
|
118 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
119 m_console->append (msg); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 } |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
121 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
122 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
|
123 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
124 emit interpreter_event |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
125 ([=] (interpreter& interp) |
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 // INTERPRETER THREAD |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
128 |
29531
41d53e20389e
fix newline issues in new command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29525
diff
changeset
|
129 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
|
130 m_incomplete_parse); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
131 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
132 event_manager& evmgr = interp.get_event_manager (); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
133 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
|
134 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
135 std::string prompt |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
136 = 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
|
137 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
138 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
|
139 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
140 emit new_command_line_signal (); |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
141 }); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
142 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
143 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
144 |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
145 void command_widget::notice_settings (const gui_settings *settings) |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
146 { |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
147 // Set terminal font: |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
148 QFont term_font = QFont (); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
149 term_font.setStyleHint (QFont::TypeWriter); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
150 QString default_font = settings->value (global_mono_font).toString (); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
151 term_font.setFamily |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
152 (settings->value (cs_font.key, default_font).toString ()); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
153 term_font.setPointSize |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
154 (settings->value (cs_font_size).toInt ()); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
155 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
156 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
|
157 |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
158 // Colors |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
159 int mode = settings->value (cs_color_mode).toInt (); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
160 QColor fgc = settings->color_value (cs_colors[0], mode); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
161 QColor bgc = settings->color_value (cs_colors[1], mode); |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
162 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
163 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
|
164 .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
|
165 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
166 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
167 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
168 // 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
|
169 // 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
|
170 // "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
|
171 // 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
|
172 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
173 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
|
174 : QsciScintilla (p), |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
175 m_command_position (-1), |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
176 m_cursor_position (0), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
177 m_text_changed (false), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
178 m_command_widget (p), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
179 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
|
180 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
181 setMargins (0); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
182 setWrapMode (QsciScintilla::WrapWord); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
183 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
184 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
|
185 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
|
186 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
187 connect (this, SIGNAL (textChanged (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
188 this, SLOT (text_changed (void))); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
189 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
190 connect (this, SIGNAL (modificationAttempted (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
191 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
|
192 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
193 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
194 // 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
|
195 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
|
196 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
197 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
|
198 append ("\n"); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
199 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
200 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
|
201 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
202 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
203 getCursorPosition (&line,&index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
204 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
|
205 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
206 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
|
207 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
208 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
209 // 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
|
210 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
|
211 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
212 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
|
213 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
214 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
|
215 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
|
216 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
217 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
|
218 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
219 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
|
220 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
221 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
|
222 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
|
223 else |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
224 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
|
225 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
226 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
227 // Execute a command |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
228 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
|
229 { |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
230 if (command.trimmed ().isEmpty ()) |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
231 return; |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
232 |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
233 new_command_line (command); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
234 accept_command_line (); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
235 } |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
236 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
237 // 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
|
238 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
|
239 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
240 setReadOnly (false); |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
241 append (string); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
242 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
243 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
244 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
|
245 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
246 setCursorPosition (line, index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
247 } |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
248 |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
249 // 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
|
250 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
|
251 { |
31086
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
252 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
|
253 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
|
254 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
255 // 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
|
256 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
|
257 { |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
258 setReadOnly (false); |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
259 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
|
260 setCursorPosition (line+1, col); |
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 (true); |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
263 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
264 else |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
265 setReadOnly (false); // Writable area |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
266 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
267 m_text_changed = false; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
268 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
269 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
270 // 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
|
271 // editing |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
272 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
|
273 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
274 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
|
275 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
276 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
|
277 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
|
278 } |
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 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
281 // 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
|
282 // 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
|
283 void console::text_changed (void) |
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 m_text_changed = true; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
286 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
287 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
288 // 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
|
289 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
|
290 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
291 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
|
292 // 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
|
293 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
|
294 else |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
295 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
296 // 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
|
297 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
|
298 QsciScintilla::keyPressEvent(e); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
299 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
300 } |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
301 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
302 } |