Mercurial > octave
annotate libgui/src/command-widget.cc @ 31646:c6d54dd31a7e stable
maint: Use macros to begin/end C++ namespaces.
* BaseControl.cc, BaseControl.h, ButtonControl.cc, ButtonControl.h,
ButtonGroup.cc, ButtonGroup.h, Canvas.cc, Canvas.h,
CheckBoxControl.cc, CheckBoxControl.h, Container.cc, Container.h,
ContextMenu.cc, ContextMenu.h, EditControl.cc, EditControl.h,
Figure.cc, Figure.h, FigureWindow.cc, FigureWindow.h, GLCanvas.cc,
GLCanvas.h, GenericEventNotify.h, KeyMap.cc, KeyMap.h,
ListBoxControl.cc, ListBoxControl.h, Logger.cc, Logger.h, Menu.cc,
Menu.h, MenuContainer.h, Object.cc, Object.h, ObjectProxy.cc,
ObjectProxy.h, Panel.cc, Panel.h, PopupMenuControl.cc,
PopupMenuControl.h, PushButtonControl.cc, PushButtonControl.h,
PushTool.cc, PushTool.h, QtHandlesUtils.cc, QtHandlesUtils.h,
RadioButtonControl.cc, RadioButtonControl.h, SliderControl.cc,
SliderControl.h, Table.cc, Table.h, TextControl.cc, TextControl.h,
TextEdit.cc, TextEdit.h, ToggleButtonControl.cc,
ToggleButtonControl.h, ToggleTool.cc, ToggleTool.h, ToolBar.cc,
ToolBar.h, ToolBarButton.cc, ToolBarButton.h, annotation-dialog.cc,
annotation-dialog.h, gl-select.cc, gl-select.h, qopengl-functions.h,
qt-graphics-toolkit.cc, qt-graphics-toolkit.h, QTerminal.h,
color-picker.cc, color-picker.h, command-widget.cc, command-widget.h,
community-news.cc, community-news.h, dialog.cc, dialog.h,
documentation-bookmarks.cc, documentation-bookmarks.h,
documentation-dock-widget.cc, documentation-dock-widget.h,
documentation.cc, documentation.h, dw-main-window.cc,
dw-main-window.h, external-editor-interface.cc,
external-editor-interface.h, files-dock-widget.cc,
files-dock-widget.h, find-files-dialog.cc, find-files-dialog.h,
find-files-model.cc, find-files-model.h, graphics-init.cc,
graphics-init.h, gui-settings.cc, gui-settings.h, gui-utils.cc,
gui-utils.h, history-dock-widget.cc, history-dock-widget.h,
interpreter-qobject.cc, interpreter-qobject.h, led-indicator.cc,
led-indicator.h, file-editor-interface.h, file-editor-tab.cc,
file-editor-tab.h, file-editor.cc, file-editor.h, find-dialog.cc,
find-dialog.h, marker.cc, marker.h, octave-qscintilla.cc,
octave-qscintilla.h, octave-txt-lexer.cc, octave-txt-lexer.h,
main-window.cc, main-window.h, news-reader.cc, news-reader.h,
octave-dock-widget.cc, octave-dock-widget.h, octave-qobject.cc,
octave-qobject.h, qt-application.cc, qt-application.h,
qt-interpreter-events.cc, qt-interpreter-events.h, qt-utils.h,
release-notes.cc, release-notes.h, resource-manager.cc,
resource-manager.h, set-path-dialog.cc, set-path-dialog.h,
set-path-model.cc, set-path-model.h, settings-dialog.cc,
settings-dialog.h, shortcut-manager.cc, shortcut-manager.h,
tab-bar.cc, tab-bar.h, terminal-dock-widget.cc,
terminal-dock-widget.h, variable-editor-model.cc,
variable-editor-model.h, variable-editor.cc, variable-editor.h,
welcome-wizard.cc, welcome-wizard.h, workspace-model.cc,
workspace-model.h, workspace-view.cc, workspace-view.h:
Use new macros to begin/end C++ namespaces.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 06 Dec 2022 14:37:51 -0500 |
parents | ed7b17c7ddf3 |
children | 431f80aba37a 29d734430e5f |
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 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
51 OCTAVE_BEGIN_NAMESPACE(octave) |
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
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 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
169 // 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
|
170 // 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
|
171 // "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
|
172 // 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
|
173 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
174 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
|
175 : QsciScintilla (p), |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
176 m_command_position (-1), |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
177 m_cursor_position (0), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
178 m_text_changed (false), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
179 m_command_widget (p), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
180 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
|
181 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
182 setMargins (0); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
183 setWrapMode (QsciScintilla::WrapWord); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
184 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
185 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
|
186 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
|
187 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
188 connect (this, SIGNAL (textChanged (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
189 this, SLOT (text_changed (void))); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
190 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
191 connect (this, SIGNAL (modificationAttempted (void)), |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
192 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
|
193 } |
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 // 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
|
196 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
|
197 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
198 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
|
199 append ("\n"); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
200 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
201 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
|
202 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
203 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
204 getCursorPosition (&line,&index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
205 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
|
206 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
207 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
|
208 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
209 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
210 // 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
|
211 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
|
212 { |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
213 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
|
214 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
215 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
|
216 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
|
217 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
218 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
|
219 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
220 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
|
221 |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
222 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
|
223 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
|
224 else |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
225 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
|
226 } |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
227 |
31068
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
228 // Execute a command |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
229 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
|
230 { |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
231 if (command.trimmed ().isEmpty ()) |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
232 return; |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
233 |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
234 new_command_line (command); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
235 accept_command_line (); |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
236 } |
0b402f523f09
allow executing a command in the new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31067
diff
changeset
|
237 |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
238 // 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
|
239 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
|
240 { |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
241 setReadOnly (false); |
31080
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
242 append (string); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
243 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
244 int line, index; |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
245 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
|
246 |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
247 setCursorPosition (line, index); |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
248 } |
56ee6a223c51
use QScintilla instead of QTextEdit for new terminal widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31068
diff
changeset
|
249 |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
250 // 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
|
251 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
|
252 { |
31086
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
253 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
|
254 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
|
255 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
256 // 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
|
257 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
|
258 { |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
259 setReadOnly (false); |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
260 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
|
261 setCursorPosition (line+1, col); |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
262 } |
d5696a4efa84
exp cmd widget: fix preventing prompt deletion
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31081
diff
changeset
|
263 setReadOnly (true); |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
264 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
265 else |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
266 setReadOnly (false); // Writable area |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
267 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
268 m_text_changed = false; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
269 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
270 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
271 // 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
|
272 // editing |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
273 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
|
274 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
275 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
|
276 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
277 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
|
278 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
|
279 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
280 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
281 |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
282 // 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
|
283 // 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
|
284 void console::text_changed (void) |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
285 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
286 m_text_changed = true; |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
287 } |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
288 |
31067
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
289 // 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
|
290 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
|
291 { |
5261a81765b0
merge input and output of exp. terminal widget into one widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
30564
diff
changeset
|
292 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
|
293 // 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
|
294 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
|
295 else |
31081
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
296 { |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
297 // 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
|
298 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
|
299 QsciScintilla::keyPressEvent(e); |
b818d4ec035e
exp cmd widget: prevent wirting in previous ouputs
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31080
diff
changeset
|
300 } |
29525
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
301 } |
d6b2d9f9e1e0
use terminal settings for the experimental command widget
Torsten Lilge <ttl-octave@mailbox.org>
parents:
29503
diff
changeset
|
302 |
31646
c6d54dd31a7e
maint: Use macros to begin/end C++ namespaces.
John W. Eaton <jwe@octave.org>
parents:
31549
diff
changeset
|
303 OCTAVE_END_NAMESPACE(octave) |
31222
1a0756f7c90a
disable experimental terminal widget when building without qscintilla
Torsten Lilge <ttl-octave@mailbox.org>
parents:
31086
diff
changeset
|
304 |
31549
ed7b17c7ddf3
maint: Strip trailing spaces and add missing EOL to all files.
Rik <rik@octave.org>
parents:
31222
diff
changeset
|
305 #endif |