annotate libgui/src/command-widget.cc @ 31222:1a0756f7c90a

disable experimental terminal widget when building without qscintilla * command-widget.cc: inlcude into #if defined (HAVE_QSCINTILLA) * main-window.cc: include command-widget.h only if HAVE_QSCINTILLA * module.mk: only build moc-command-widget.cc if HAVE_QSCINTILLA * octave-qobject.cc: include command-widget.h only if HAVE_QSCINTILLA, (base_qobject::terminal_widget): use conditional compilation where referring to new terminal widget * terminal-dock-widget.cc: include command-widget.h only if HAVE_QSCINTILLA, (terminal_dock_widget, init_command_prompt): use conditional compilation where referring to new terminal widget * terminal-dock-widget.h: use conditional compilation where referring to new terminal widget Thu Sep 01 02:34:37 2022 +0200 * octave.cc (cmdline_options): only return true on experimental terminal widget option if built with scintilla
author Torsten Lilge <ttl-octave@mailbox.org>
date Sat, 03 Sep 2022 00:18:49 +0200
parents d5696a4efa84
children ed7b17c7ddf3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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"
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
47 #include "gui-utils.h"
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
48 #include "input.h"
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
49 #include "interpreter.h"
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
50
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
51 namespace octave
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
52 {
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
53 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
54 : 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
55 m_prompt (QString ()),
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
56 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
57 {
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
58 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
59 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
60 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
61
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
62 QGroupBox *input_group_box = new QGroupBox ();
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
63 QHBoxLayout *input_layout = new QHBoxLayout;
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
64 input_layout->addWidget (pause_button);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
65 input_layout->addWidget (stop_button);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
66 input_layout->addWidget (resume_button);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
67 input_group_box->setLayout (input_layout);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
68
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
69 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
70 main_layout->addWidget (m_console);
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
71 main_layout->addWidget (input_group_box);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
72
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
73 setLayout (main_layout);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
75 setFocusProxy (m_console);
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29531
diff changeset
77 connect (pause_button, &QPushButton::clicked,
29786
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29542
diff changeset
78 this, &command_widget::interpreter_pause);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29542
diff changeset
79
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29542
diff changeset
80 connect (resume_button, &QPushButton::clicked,
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29542
diff changeset
81 this, &command_widget::interpreter_resume);
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
82
29542
3d34b70b5a49 connect many Qt signals and slots without SIGNAL and SLOT macros
John W. Eaton <jwe@octave.org>
parents: 29531
diff changeset
83 connect (stop_button, &QPushButton::clicked,
29786
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29542
diff changeset
84 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
85
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
86 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
87 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
88
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
89 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
90
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 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
94 {
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
95 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
96 ([=] (interpreter& interp)
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 // INTERPRETER THREAD
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
99
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
100 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
101 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
102 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
103 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
104
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
105 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
106 });
29787
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29786
diff changeset
107 }
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
108
29787
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29786
diff changeset
109 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
110 {
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
111 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
112 }
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 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
115 {
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
116 return m_prompt;
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
117 }
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
119 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
120 {
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
121 m_console->append (msg);
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
122 }
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
123
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
124 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
125 {
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 emit interpreter_event
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127 ([=] (interpreter& interp)
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 {
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
129 // INTERPRETER THREAD
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
130
29531
41d53e20389e fix newline issues in new command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29525
diff changeset
131 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
132 m_incomplete_parse);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
133
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
134 event_manager& evmgr = interp.get_event_manager ();
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
135 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
136
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
137 std::string prompt
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
138 = 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
139
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
140 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
141
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
142 emit new_command_line_signal ();
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
143 });
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 }
29525
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 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
148 {
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
149 // Set terminal font:
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
150 QFont term_font = QFont ();
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
151 term_font.setStyleHint (QFont::TypeWriter);
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
152 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
153 term_font.setFamily
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
154 (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
155 term_font.setPointSize
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
156 (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
157
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
158 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
159
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
160 // Colors
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
161 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
162 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
163 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
164
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
165 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
166 .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
167 }
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
168
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
169
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
170 // 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
171 // 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
172 // "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
173 // 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
174
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
175 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
176 : QsciScintilla (p),
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
177 m_command_position (-1),
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
178 m_cursor_position (0),
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
179 m_text_changed (false),
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
180 m_command_widget (p),
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
181 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
182 {
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
183 setMargins (0);
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
184 setWrapMode (QsciScintilla::WrapWord);
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
185
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
186 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
187 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
188
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
189 connect (this, SIGNAL (textChanged (void)),
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
190 this, SLOT (text_changed (void)));
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
191
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
192 connect (this, SIGNAL (modificationAttempted (void)),
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
193 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
194 }
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
195
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
196 // 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
197 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
198 {
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
199 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
200 append ("\n");
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
201
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
202 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
203
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
204 int line, index;
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
205 getCursorPosition (&line,&index);
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
206 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
207
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
208 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
209 }
29525
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
210
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
211 // 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
212 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
213 {
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
214 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
215
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
216 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
217 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
218
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 = input_line.trimmed ();
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
220
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
221 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
222
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
223 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
224 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
225 else
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
226 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
227 }
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
228
31068
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
229 // Execute a command
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
230 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
231 {
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
232 if (command.trimmed ().isEmpty ())
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
233 return;
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
234
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
235 new_command_line (command);
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
236 accept_command_line ();
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
237 }
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
238
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
239 // 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
240 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
241 {
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
242 setReadOnly (false);
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
243 append (string);
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
244
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
245 int line, index;
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
246 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
247
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
248 setCursorPosition (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
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
251 // 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
252 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
253 {
31086
d5696a4efa84 exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31081
diff changeset
254 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
255 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
256 {
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
257 // 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
258 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
259 {
d5696a4efa84 exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31081
diff changeset
260 setReadOnly (false);
d5696a4efa84 exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31081
diff changeset
261 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
262 setCursorPosition (line+1, col);
d5696a4efa84 exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31081
diff changeset
263 }
d5696a4efa84 exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31081
diff changeset
264 setReadOnly (true);
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
265 }
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
266 else
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
267 setReadOnly (false); // Writable area
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 m_text_changed = false;
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
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
272 // 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
273 // editing
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
274 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
275 {
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
276 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
277 {
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
278 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
279 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
280 }
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
281 }
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 // 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
284 // 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
285 void console::text_changed (void)
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 m_text_changed = true;
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
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
290 // 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
291 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
292 {
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
293 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
294 // 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
295 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
296 else
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
297 {
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
298 // 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
299 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
300 QsciScintilla::keyPressEvent(e);
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
301 }
29525
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
302 }
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
303
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
304 }
31222
1a0756f7c90a disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31086
diff changeset
305
1a0756f7c90a disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31086
diff changeset
306 #endif