Mercurial > octave
annotate libgui/src/command-widget.h @ 31068:0b402f523f09
allow executing a command in the new terminal widget
* command-widget.cc (console::new_command_line): Allow a new command
line with preset text;
(console::execute_command): Slot for executing a command
* command-widget.h, class console: new_command_line with optional
string argument, new functions execute_command and get_console
* main-window.cc (adopt_terminal_widget): connect execute command
signal with related signal in terminal widget;
(execute_command_in_terminal): in case of exp. terminal widget,
emit new signal execute_command_signal
* main-window.h: new signal execute_command_signal
* terminal-dock-widget.cc (terminal_dock_widget): connect own
execute signal to the slot in the console
* terminal-dock-widget.h: new signal execute_command_signal
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sat, 04 Jun 2022 22:17:58 +0200 |
parents | 5261a81765b0 |
children | 56ee6a223c51 |
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 (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> |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
30 #include <QTextEdit> |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
31 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
32 #include "octave-qobject.h" |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
33 #include "gui-settings.h" |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
34 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
35 class QLabel; |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
36 class QLineEdit; |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
37 class QStrung; |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
38 class QTextEdit; |
29503
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 namespace octave |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
41 { |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
42 class base_qobject; |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
43 class command_widget; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
44 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
45 class console : public QTextEdit |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
46 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
47 Q_OBJECT |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
48 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
49 public: |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
50 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
51 console (command_widget *p); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
52 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
53 public slots: |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
54 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
55 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:
31067
diff
changeset
|
56 |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
57 void execute_command (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
|
58 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
59 protected: |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
60 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
61 void 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
|
62 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
63 private: |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
64 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
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:
30564
diff
changeset
|
66 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
67 void append_block (void); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
68 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
69 int m_command_block_number; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
70 command_widget *m_command_widget; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
71 QTextDocument *m_document; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
72 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
73 }; |
29503
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 class command_widget : public QWidget |
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 Q_OBJECT |
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 public: |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
80 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
81 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
|
82 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
83 console * get_console ( ) { return m_console; }; |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
84 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
85 void 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
|
86 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
87 QString prompt (void); |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
88 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
89 signals: |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
90 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
91 void clear_line_edit (void); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
92 |
29786
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29525
diff
changeset
|
93 void interpreter_pause (void); |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29525
diff
changeset
|
94 void interpreter_resume (void); |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29525
diff
changeset
|
95 void interpreter_stop (void); |
63c515ff762f
eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents:
29525
diff
changeset
|
96 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
97 void interpreter_event (const fcn_callback& fcn); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
98 void interpreter_event (const meth_callback& meth); |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
99 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
100 void new_command_line_signal (const QString& command = QString ()); |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
101 |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
102 public slots: |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
103 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
104 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:
30564
diff
changeset
|
105 |
29787
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
106 void 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
|
107 |
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
108 void insert_interpreter_output (const QString& msg); |
b4d2fa28d1d4
allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents:
29786
diff
changeset
|
109 |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
110 void 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
|
111 |
29503
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
112 private: |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
113 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
114 bool m_incomplete_parse; |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
115 QString m_prompt; |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
116 console *m_console; |
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 |
3bfec185c9e2
experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff
changeset
|
120 #endif |