annotate libgui/src/command-widget.h @ 31085:56ee6a223c51

use QScintilla instead of QTextEdit for new terminal widget * command-widget.cc (ctor): pass qobj to console; (insert_interpreter_output): just append output message to console text; (console::console): initialize QScintilla, remove obsolete document; (console::new_command_line): append new line, add prompt, remember current cursor pos for later use, append possibly given command string; (console::accept_command_line): just get last line, and append a new line; (console::append_block): removed; (console::append_string): new function appending a string and moving cursor to the end; (console::keyPressEvent): process QsciScintilla::keyPressEvent * command-widget.h: include Qsci/qsciscintilla.h, console inherits from QsciScintilla and gets oct_qobj for later use, new function append_string, new class variable m_command_position for storing the begin of the active command line
author Torsten Lilge <ttl-octave@mailbox.org>
date Tue, 07 Jun 2022 23:03:11 +0200
parents 0b402f523f09
children b818d4ec035e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29508
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 //
30569
796f54d4ddbf update Octave Project Developers copyright for the new year
John W. Eaton <jwe@octave.org>
parents: 29792
diff changeset
3 // Copyright (C) 2021-2022 The Octave Project Developers
29508
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 (octave_command_widget_h)
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
27 #define octave_command_widget_h 1
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
28
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
29 #include <QWidget>
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
30
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
31 #include <Qsci/qsciscintilla.h>
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
33 #include "octave-qobject.h"
29530
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29508
diff changeset
34 #include "gui-settings.h"
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
35
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
36 class QsciScintilla;
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
37
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38 namespace octave
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
39 {
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40 class base_qobject;
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
41 class command_widget;
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
42
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
43 class console : public QsciScintilla
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
44 {
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
45 Q_OBJECT
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
46
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
47 public:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
48
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
49 console (command_widget *p, base_qobject& oct_qobj);
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
50
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
51 public slots:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
52
31073
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
53 void new_command_line (const QString& command = QString ());
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
54
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
55 void execute_command (const QString& command);
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
56
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
57 protected:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
58
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
59 void keyPressEvent (QKeyEvent *e);
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
60
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
61 private:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
62
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
63 void append_string (const QString& string);
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
64
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
65 void accept_command_line (void);
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
66
31085
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31073
diff changeset
67 int m_command_position;
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
68 command_widget *m_command_widget;
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
69 QTextDocument *m_document;
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
70
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
71 };
29508
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 class command_widget : public QWidget
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
74 {
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
75 Q_OBJECT
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
76
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
77 public:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
78
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
79 command_widget (base_qobject& oct_qobj, QWidget *p);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
80
31073
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
81 console * get_console ( ) { return m_console; };
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
82
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
83 void init_command_prompt ();
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
84
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
85 QString prompt (void);
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
86
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
87 signals:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
88
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
89 void clear_line_edit (void);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
90
29791
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29530
diff changeset
91 void interpreter_pause (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29530
diff changeset
92 void interpreter_resume (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29530
diff changeset
93 void interpreter_stop (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29530
diff changeset
94
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 void interpreter_event (const fcn_callback& fcn);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
96 void interpreter_event (const meth_callback& meth);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
97
31073
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31072
diff changeset
98 void new_command_line_signal (const QString& command = QString ());
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
99
29530
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29508
diff changeset
100 public slots:
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29508
diff changeset
101
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
102 void process_input_line (const QString& input_line);
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
103
29792
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29791
diff changeset
104 void update_prompt (const QString& prompt);
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29791
diff changeset
105
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29791
diff changeset
106 void insert_interpreter_output (const QString& msg);
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29791
diff changeset
107
29530
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29508
diff changeset
108 void notice_settings (const gui_settings *settings);
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29508
diff changeset
109
29508
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
110 private:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
111
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
112 bool m_incomplete_parse;
31072
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
113 QString m_prompt;
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30569
diff changeset
114 console *m_console;
29508
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
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
118 #endif