annotate libgui/src/command-widget.h @ 31697:dd904ce6f53f

use interpreter event to display documentation in terminal and editor widgets * QTerminal.h, QTerminal.cc (QTerminal::doc_on_expression): Use interpreter_event to display doc browser instead of calling base_qobject::show_documentation_window. (QTerminal::interpreter_event): New signals. * command-widget.h, command-widget.cc (console::interpreter_event): New signals. (command_widget::command_widget): Forward console interpreter_event signals to command_widget interpreter_event signals. * octave-qscintilla.cc (octave_qscintilla::contextmenu_help_doc): Use interpreter_event to display doc browser instead of calling base_qobject::show_documentation_window. * octave-qobject.cc (base_qobject::terminal_widget): Also call connect_interpreter_events for QTerminal. * terminal-dock-widget.h, terminal-dock-widget.cc (terminal_dock_widget::interpreter_event): New signals. (terminal_dock_widget::terminal_dock_widget): Forward QTerminal interpreter_event signals to terminal_dock_widget interpreter_event signals.
author John W. Eaton <jwe@octave.org>
date Fri, 30 Dec 2022 23:13:00 -0500
parents deb553ac2c54
children 276a992d0c08
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 (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>
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
30
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
31 #include <Qsci/qsciscintilla.h>
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
32
31639
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 31619
diff changeset
33 // FIXME: We need the following header for the fcn_callback and
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 31619
diff changeset
34 // meth_callback typedefs. Maybe it would be better to declare those in
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 31619
diff changeset
35 // a separate file because inclding "event-manager.h" pulls in a lot of
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 31619
diff changeset
36 // other unnecessary declarations.
ca7d58406f82 eliminate unnecessary uses of octave_qobject in GUI classes
John W. Eaton <jwe@octave.org>
parents: 31619
diff changeset
37 #include "event-manager.h"
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
38
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
39 class QsciScintilla;
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
40
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31081
diff changeset
41 OCTAVE_BEGIN_NAMESPACE(octave)
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31081
diff changeset
42
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
43 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
44 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
45
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
46 class console : public QsciScintilla
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
47 {
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
48 Q_OBJECT
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
49
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
50 public:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
51
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
52 console (command_widget *p, base_qobject& oct_qobj);
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
53
31697
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
54 signals:
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
55
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
56 void interpreter_event (const fcn_callback& fcn);
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
57 void interpreter_event (const meth_callback& meth);
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
58
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
59 public slots:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
60
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
61 void 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
62
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
63 void text_changed (void);
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
64
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
65 void move_cursor_to_end (void);
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
66
31068
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
67 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
68
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
69 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
70
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
71 protected:
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 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
74
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
75 private:
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
76
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
77 void 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
78
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
79 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
80
31080
56ee6a223c51 use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31068
diff changeset
81 int m_command_position;
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
82 int m_cursor_position;
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
83 bool m_text_changed;
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
84 command_widget *m_command_widget;
31081
b818d4ec035e exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31080
diff changeset
85 QString m_last_key_string;
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
86
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
87 };
29503
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 class command_widget : public QWidget
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 Q_OBJECT
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
92
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
93 public:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
94
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
95 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
96
31068
0b402f523f09 allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 31067
diff changeset
97 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
98
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
99 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
100
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
101 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
102
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
103 signals:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
104
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
105 void clear_line_edit (void);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
106
29786
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29525
diff changeset
107 void interpreter_pause (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29525
diff changeset
108 void interpreter_resume (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29525
diff changeset
109 void interpreter_stop (void);
63c515ff762f eliminate more signal connections to parent objects
John W. Eaton <jwe@octave.org>
parents: 29525
diff changeset
110
31697
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
111 void new_command_line_signal (const QString& command = QString ());
dd904ce6f53f use interpreter event to display documentation in terminal and editor widgets
John W. Eaton <jwe@octave.org>
parents: 31649
diff changeset
112
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
113 void interpreter_event (const fcn_callback& fcn);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
114 void interpreter_event (const meth_callback& meth);
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
115
29525
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
116 public slots:
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
117
31067
5261a81765b0 merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 30564
diff changeset
118 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
119
29787
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29786
diff changeset
120 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
121
b4d2fa28d1d4 allow terminal window to be opened from command line
John W. Eaton <jwe@octave.org>
parents: 29786
diff changeset
122 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
123
31619
ad014fc78bd6 use individual local gui_settings objects
John W. Eaton <jwe@octave.org>
parents: 31081
diff changeset
124 void notice_settings (void);
29525
d6b2d9f9e1e0 use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents: 29503
diff changeset
125
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
126 private:
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
127
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
128 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
129 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
130 console *m_console;
29503
3bfec185c9e2 experimental command window widget with server loop
John W. Eaton <jwe@octave.org>
parents:
diff changeset
131 };
31646
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31081
diff changeset
132
c6d54dd31a7e maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents: 31081
diff changeset
133 OCTAVE_END_NAMESPACE(octave)
29503
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 #endif