# HG changeset patch # User Torsten Lilge # Date 1654373878 -7200 # Node ID 0b402f523f0945612c3f03b8523344e2630ab17a # Parent 5261a81765b049fa9e9fa66e12a5fbc1ffdd8650 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 diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/command-widget.cc --- a/libgui/src/command-widget.cc Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/command-widget.cc Sat Jun 04 22:17:58 2022 +0200 @@ -184,7 +184,7 @@ } // Prepare a new command line with the current prompt - void console::new_command_line () + void console::new_command_line (const QString& command) { QTextCursor cursor (m_document->lastBlock ()); @@ -194,7 +194,7 @@ cursor.insertBlock (); } - cursor.insertText (m_command_widget->prompt ()); + cursor.insertText (m_command_widget->prompt () + command); setTextCursor (cursor); } @@ -225,6 +225,16 @@ setTextCursor (cursor); } + // Execute a command + void console::execute_command (const QString& command) + { + if (command.trimmed ().isEmpty ()) + return; + + new_command_line (command); + accept_command_line (); + } + // Re-implement key event void console::keyPressEvent (QKeyEvent *e) { diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/command-widget.h --- a/libgui/src/command-widget.h Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/command-widget.h Sat Jun 04 22:17:58 2022 +0200 @@ -52,7 +52,9 @@ public slots: - void new_command_line (void); + void new_command_line (const QString& command = QString ()); + + void execute_command (const QString& command); protected: @@ -78,6 +80,8 @@ command_widget (base_qobject& oct_qobj, QWidget *p); + console * get_console ( ) { return m_console; }; + void init_command_prompt (); QString prompt (void); @@ -93,7 +97,7 @@ void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); - void new_command_line_signal (void); + void new_command_line_signal (const QString& command = QString ()); public slots: diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/main-window.cc --- a/libgui/src/main-window.cc Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/main-window.cc Sat Jun 04 22:17:58 2022 +0200 @@ -282,6 +282,11 @@ connect (cmd_widget, &QTerminal::clear_command_window_request, this, &main_window::handle_clear_command_window_request); } + else + { + connect (this, &main_window::execute_command_signal, + m_command_window, &terminal_dock_widget::execute_command_signal); + } } void main_window::adopt_documentation_widget (void) @@ -1141,19 +1146,26 @@ void main_window::execute_command_in_terminal (const QString& command) { - emit interpreter_event - ([=] (void) - { - // INTERPRETER THREAD - - std::string pending_input = command_editor::get_current_line (); - - command_editor::set_initial_input (pending_input); - command_editor::replace_line (command.toStdString ()); - command_editor::redisplay (); - command_editor::interrupt_event_loop (); - command_editor::accept_line (); - }); + if (m_octave_qobj.experimental_terminal_widget ()) + { + emit execute_command_signal (command); + } + else + { + emit interpreter_event + ([=] (void) + { + // INTERPRETER THREAD + + std::string pending_input = command_editor::get_current_line (); + + command_editor::set_initial_input (pending_input); + command_editor::replace_line (command.toStdString ()); + command_editor::redisplay (); + command_editor::interrupt_event_loop (); + command_editor::accept_line (); + }); + } focus_console_after_command (); } diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/main-window.h --- a/libgui/src/main-window.h Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/main-window.h Sat Jun 04 22:17:58 2022 +0200 @@ -129,6 +129,8 @@ void interpreter_event (const fcn_callback& fcn); void interpreter_event (const meth_callback& meth); + void execute_command_signal (const QString& command); + public slots: void focus_changed (QWidget *w_old, QWidget *w_new); diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/terminal-dock-widget.cc --- a/libgui/src/terminal-dock-widget.cc Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/terminal-dock-widget.cc Sat Jun 04 22:17:58 2022 +0200 @@ -53,6 +53,7 @@ if (m_experimental_terminal_widget) { command_widget *widget = new command_widget (oct_qobj, this); + console *con = widget->get_console (); connect (this, &terminal_dock_widget::settings_changed, widget, &command_widget::notice_settings); @@ -63,6 +64,9 @@ connect (this, &terminal_dock_widget::interpreter_output_signal, widget, &command_widget::insert_interpreter_output); + connect (this, &terminal_dock_widget::execute_command_signal, + con, &console::execute_command); + m_terminal = widget; } else diff -r 5261a81765b0 -r 0b402f523f09 libgui/src/terminal-dock-widget.h --- a/libgui/src/terminal-dock-widget.h Sat Jun 04 21:52:20 2022 +0200 +++ b/libgui/src/terminal-dock-widget.h Sat Jun 04 22:17:58 2022 +0200 @@ -72,6 +72,8 @@ void interpreter_output_signal (const QString&); + void execute_command_signal (const QString&); + public slots: void notice_settings (const gui_settings *settings);