Mercurial > octave
changeset 27263:99aa1bcb8848
rename octave_link and octave_link_events classes, move inside octave namespace
* event-manager.h, event-manager.cc: Rename from octave-link.h and
octave-link.cc.
(class event_manager): Rename from octave_link. Move inside octave
namespace. Change all uses.
(class interpreter_events): Rename from octave_link_events. Move
inside octave namespace. Change all uses.
* libinterp/corefcn/module.mk: Update.
* qt-interpreter-events.h, qt-interpreter-events.cc: Rename from
octave-qt-link.h and octave-qt-link.cc.
(class qt_interpreter_events): Rename from octave_qt_link_events
Change all uses.
* libgui/src/module.mk: Update.
Change all interpreter functions that uses octave_link in their names
to use event_manager instead.
line wrap: on
line diff
--- a/libgui/graphics/Canvas.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/graphics/Canvas.cc Thu Jul 18 11:23:22 2019 -0400 @@ -44,7 +44,7 @@ #include "interpreter-private.h" #include "interpreter.h" #include "oct-opengl.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "resource-manager.h" #include "builtin-defun-decls.h" @@ -875,10 +875,10 @@ props = anno_dlg.get_properties (); props.prepend (figObj.get_handle ().as_octave_value ()); - octave_link& olnk - = octave::__get_octave_link__ ("Canvas::canvasMouseReleaseEvent"); + octave::event_manager& evmgr + = octave::__get_event_manager__ ("Canvas::canvasMouseReleaseEvent"); - olnk.post_event + evmgr.post_event ([this, props] (void) { octave::interpreter& interp
--- a/libgui/graphics/Figure.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/graphics/Figure.cc Thu Jul 18 11:23:22 2019 -0400 @@ -56,7 +56,7 @@ #include "utils.h" #include "version.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "builtin-defun-decls.h"
--- a/libgui/graphics/GLCanvas.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/graphics/GLCanvas.cc Thu Jul 18 11:23:22 2019 -0400 @@ -24,11 +24,11 @@ # include "config.h" #endif +#include "event-manager.h" #include "gl-render.h" #include "gl2ps-print.h" #include "graphics.h" #include "interpreter-private.h" -#include "octave-link.h" #include "GLCanvas.h" #include "gl-select.h" @@ -174,10 +174,10 @@ } catch (octave::execution_exception& e) { - octave_link& olnk - = octave::__get_octave_link__ ("GLCanvas::do_print"); + octave::event_manager& evmgr + = octave::__get_event_manager__ ("GLCanvas::do_print"); - olnk.post_exception (std::current_exception ()); + evmgr.post_exception (std::current_exception ()); } end_rendering ();
--- a/libgui/graphics/__init_qt__.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/graphics/__init_qt__.cc Thu Jul 18 11:23:22 2019 -0400 @@ -41,7 +41,7 @@ #include "QtHandlesUtils.h" #include "__init_qt__.h" -// PKG_ADD: if (__have_feature__ ("QT") && __have_feature__ ("OPENGL") && have_window_system () && __octave_link_enabled__ ()) register_graphics_toolkit ("qt"); endif +// PKG_ADD: if (__have_feature__ ("QT") && __have_feature__ ("OPENGL") && have_window_system () && __event_manager_enabled__ ()) register_graphics_toolkit ("qt"); endif namespace QtHandles {
--- a/libgui/src/interpreter-qobject.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/interpreter-qobject.cc Thu Jul 18 11:23:22 2019 -0400 @@ -27,7 +27,7 @@ #include "interpreter-qobject.h" #include "octave-qobject.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "qt-application.h" #include "input.h" @@ -37,7 +37,7 @@ { interpreter_qobject::interpreter_qobject (base_qobject *oct_qobj) : QObject (), m_octave_qobject (oct_qobj), - m_qt_link (new octave_qt_link_events ()) + m_qt_link (new qt_interpreter_events ()) { } void interpreter_qobject::execute (void) @@ -48,10 +48,10 @@ interpreter& interp = app_context.create_interpreter (); - octave_link& olnk = interp.get_octave_link (); + event_manager& evmgr = interp.get_event_manager (); - olnk.connect_link (m_qt_link); - olnk.enable (); + evmgr.connect_link (m_qt_link); + evmgr.enable (); connect (qt_link (), SIGNAL (confirm_shutdown_signal (void)), m_octave_qobject, SLOT (confirm_shutdown_octave (void)));
--- a/libgui/src/interpreter-qobject.h Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/interpreter-qobject.h Thu Jul 18 11:23:22 2019 -0400 @@ -31,7 +31,7 @@ namespace octave { class base_qobject; - class octave_qt_link_events; + class qt_interpreter_events; class interpreter_qobject : public QObject { @@ -43,7 +43,7 @@ ~interpreter_qobject (void) = default; - octave_qt_link_events * qt_link (void) { return m_qt_link.get (); } + qt_interpreter_events * qt_link (void) { return m_qt_link.get (); } void confirm_shutdown (bool closenow); @@ -62,7 +62,7 @@ base_qobject *m_octave_qobject; - std::shared_ptr<octave_qt_link_events> m_qt_link; + std::shared_ptr<qt_interpreter_events> m_qt_link; }; }
--- a/libgui/src/m-editor/file-editor-tab.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Thu Jul 18 11:23:22 2019 -0400 @@ -75,7 +75,7 @@ #include "interpreter-private.h" #include "interpreter.h" #include "oct-map.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "ov-usr-fcn.h" #include "symtab.h" #include "unwind-prot.h" @@ -1107,16 +1107,16 @@ { bp_info info (_file_name, line); - octave_link& olnk - = __get_octave_link__ ("file_editor_tab::handle_request_remove_breakpoint"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("file_editor_tab::handle_request_remove_breakpoint"); + + evmgr.post_event ([info] (void) { bp_table::intmap line_info; line_info[0] = info.line; - if (octave_qt_link_events::file_in_path (info.file, info.dir)) + if (qt_interpreter_events::file_in_path (info.file, info.dir)) { bp_table& bptab = __get_bp_table__ ("file_editor_tab::handle_request_remove_breakpoint"); @@ -1193,13 +1193,13 @@ bp_info info (_file_name); - octave_link& olnk - = __get_octave_link__ ("file_editor_tab::remove_all_breakpoints"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("file_editor_tab::remove_all_breakpoints"); + + evmgr.post_event ([info] (void) { - if (octave_qt_link_events::file_in_path (info.file, info.dir)) + if (qt_interpreter_events::file_in_path (info.file, info.dir)) { bp_table& bptab = __get_bp_table__ ("file_editor_tab::remove_all_breakpoints"); @@ -1325,16 +1325,16 @@ void file_editor_tab::add_breakpoint_event (const bp_info& info) { - octave_link& olnk - = __get_octave_link__ ("file_editor_tab::add_breakpoint_event"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("file_editor_tab::add_breakpoint_event"); + + evmgr.post_event ([this, info] (void) { bp_table::intmap line_info; line_info[0] = info.line; - if (octave_qt_link_events::file_in_path (info.file, info.dir)) + if (qt_interpreter_events::file_in_path (info.file, info.dir)) { bp_table& bptab = __get_bp_table__ ("file_editor_tab::add_breakpoint_event"); @@ -1917,10 +1917,10 @@ // commands processed in the background. /* - connect (octave_link, SIGNAL (fileSelected (QObject *, const QString&, const octave_value_list&)), + connect (event_manager, SIGNAL (fileSelected (QObject *, const QString&, const octave_value_list&)), this, SLOT (handle_feval_result (QObject *, const QString&, const octave_value_list&))); connect (this, SIGNAL (evaluate_octave_command (const QString&)), - octave_link, SLOT (queue_octave_command (const QString&))); + event_manager, SLOT (queue_octave_command (const QString&))); emit evaluate_octave_command ("dbstatus"); */ @@ -2055,10 +2055,10 @@ // Create and queue the command object. - octave_link& olnk - = __get_octave_link__ ("file_editor_tab::update_breakpoints"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("file_editor_tab::update_breakpoints"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD
--- a/libgui/src/m-editor/file-editor.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/m-editor/file-editor.cc Thu Jul 18 11:23:22 2019 -0400 @@ -44,12 +44,13 @@ #include <QVBoxLayout> #include <Qsci/qscicommandset.h> +#include "event-manager.h" +#include "oct-env.h" +#include "oct-map.h" +#include "utils.h" + #include "main-window.h" #include "gui-preferences.h" -#include "oct-env.h" -#include "oct-map.h" -#include "octave-link.h" -#include "utils.h" namespace octave {
--- a/libgui/src/main-window.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/main-window.cc Thu Jul 18 11:23:22 2019 -0400 @@ -336,10 +336,10 @@ if (! file.isEmpty ()) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_save_workspace_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_save_workspace_request"); + + evmgr.post_event ([file] (void) { // INTERPRETER THREAD @@ -368,10 +368,10 @@ if (! file.isEmpty ()) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_load_workspace_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_load_workspace_request"); + + evmgr.post_event ([file] (void) { // INTERPRETER THREAD @@ -383,9 +383,9 @@ tree_evaluator& tw = interp.get_evaluator (); - octave_link& xolnk = interp.get_octave_link (); - - xolnk.set_workspace (true, tw.get_symbol_info ()); + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info ()); }); } } @@ -396,10 +396,10 @@ { std::string file = file_arg.toStdString (); - octave_link& olnk - = __get_octave_link__ ("main_window::handle_open_any_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_open_any_request"); + + evmgr.post_event ([file] (void) { // INTERPRETER THREAD @@ -413,19 +413,19 @@ // variables. tree_evaluator& tw = interp.get_evaluator (); - octave_link& xolnk = interp.get_octave_link (); - - xolnk.set_workspace (true, tw.get_symbol_info ()); + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info ()); }); } } void main_window::handle_clear_workspace_request (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_clear_workspace_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_clear_workspace_request"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -439,10 +439,10 @@ void main_window::handle_clear_command_window_request (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_clear_command_window_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_clear_command_window_request"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -454,10 +454,10 @@ void main_window::handle_clear_history_request (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_clear_history_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_clear_history_request"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -473,10 +473,10 @@ { if (command_window_has_focus ()) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_undo_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_undo_request"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -496,10 +496,10 @@ std::string old_name = old_name_arg.toStdString (); std::string new_name = new_name_arg.toStdString (); - octave_link& olnk - = __get_octave_link__ ("main_window::handle_rename_variable_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_rename_variable_request"); + + evmgr.post_event ([old_name, new_name] (void) { // INTERPRETER THREAD @@ -515,9 +515,9 @@ tree_evaluator& tw = interp.get_evaluator (); - octave_link& xolnk = interp.get_octave_link (); - - xolnk.set_workspace (true, tw.get_symbol_info ()); + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info ()); } // FIXME: if this action fails, do we need a way to display that info @@ -547,7 +547,7 @@ { interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - octave_qt_link_events *qt_link = interp_qobj->qt_link (); + qt_interpreter_events *qt_link = interp_qobj->qt_link (); // Wait for worker to suspend qt_link->lock (); @@ -886,10 +886,10 @@ { m_default_encoding = new_default_encoding; - octave_link& olnk - = __get_octave_link__ ("main_window::notice_settings"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::notice_settings"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1010,10 +1010,10 @@ if (fileInfo.exists () && fileInfo.isDir ()) { - octave_link& olnk - = __get_octave_link__ ("main_window::set_current_working_directory"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::set_current_working_directory"); + + evmgr.post_event ([xdir] (void) { // INTERPRETER THREAD @@ -1048,10 +1048,10 @@ void main_window::execute_command_in_terminal (const QString& command) { - octave_link& olnk - = __get_octave_link__ ("main_window::execute_command_in_terminal"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::execute_command_in_terminal"); + + evmgr.post_event ([command] (void) { // INTERPRETER THREAD @@ -1070,10 +1070,10 @@ void main_window::run_file_in_terminal (const QFileInfo& info) { - octave_link& olnk - = __get_octave_link__ ("main_window::run_file_in_terminal"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::run_file_in_terminal"); + + evmgr.post_event ([info] (void) { // INTERPRETER THREAD @@ -1091,7 +1091,7 @@ std::string path = info.absolutePath ().toStdString (); - if (octave_qt_link_events::file_in_path (file_path, path)) + if (qt_interpreter_events::file_in_path (file_path, path)) command_editor::replace_line (function_name.toStdString ()); } else @@ -1119,10 +1119,10 @@ void main_window::handle_new_figure_request (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::handle_new_figure_request"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_new_figure_request"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -1167,10 +1167,10 @@ void main_window::debug_continue (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::debug_continue"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::debug_continue"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1187,10 +1187,10 @@ void main_window::debug_step_into (void) { - octave_link& olnk - = __get_octave_link__ ("main_window::debug_step_into"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::debug_step_into"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1211,10 +1211,10 @@ { // We are in debug mode, just call dbstep. - octave_link& olnk - = __get_octave_link__ ("main_window::debug_step_over"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::debug_step_over"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1237,9 +1237,9 @@ void main_window::debug_step_out (void) { - octave_link& olnk = __get_octave_link__ ("main_window::debug_step_out"); - - olnk.post_event + event_manager& evmgr = __get_event_manager__ ("main_window::debug_step_out"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1256,9 +1256,9 @@ void main_window::debug_quit (void) { - octave_link& olnk = __get_octave_link__ ("main_window::debug_quit"); - - olnk.post_event + event_manager& evmgr = __get_event_manager__ ("main_window::debug_quit"); + + evmgr.post_event ([this] (void) { // INTERPRETER THREAD @@ -1805,9 +1805,9 @@ void main_window::set_screen_size (int ht, int wd) { - octave_link& olnk = __get_octave_link__ ("main_window::set_screen_size"); - - olnk.post_event + event_manager& evmgr = __get_event_manager__ ("main_window::set_screen_size"); + + evmgr.post_event ([ht, wd] (void) { // INTERPRETER THREAD @@ -1893,10 +1893,10 @@ // interpreter. That will eventually cause the workspace view in the // GUI to be updated. - octave_link& olnk - = __get_octave_link__ ("main_window::handle_variable_editor_update"); - - olnk.post_event + event_manager& evmgr + = __get_event_manager__ ("main_window::handle_variable_editor_update"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -1906,9 +1906,9 @@ tree_evaluator& tw = interp.get_evaluator (); - octave_link& xolnk = interp.get_octave_link (); - - xolnk.set_workspace (true, tw.get_symbol_info (), false); + event_manager& xevmgr = interp.get_event_manager (); + + xevmgr.set_workspace (true, tw.get_symbol_info (), false); }); } @@ -1916,9 +1916,9 @@ { e->ignore (); - octave_link& olnk = __get_octave_link__ ("main_window::closeEvent"); - - olnk.post_event + event_manager& evmgr = __get_event_manager__ ("main_window::closeEvent"); + + evmgr.post_event ([] (void) { // INTERPRETER THREAD @@ -1956,7 +1956,7 @@ interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - octave_qt_link_events *qt_link = interp_qobj->qt_link (); + qt_interpreter_events *qt_link = interp_qobj->qt_link (); connect (qt_link, SIGNAL (edit_variable_signal (const QString&, @@ -2135,7 +2135,7 @@ { interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - octave_qt_link_events *qt_link = interp_qobj->qt_link (); + qt_interpreter_events *qt_link = interp_qobj->qt_link (); connect (qt_link, SIGNAL (set_workspace_signal (bool, bool, const symbol_info_list&)), @@ -2740,7 +2740,7 @@ interpreter_qobject *interp_qobj = m_octave_qobj.interpreter_qobj (); - octave_qt_link_events *qt_link = interp_qobj->qt_link (); + qt_interpreter_events *qt_link = interp_qobj->qt_link (); // Wait for worker to suspend qt_link->lock ();
--- a/libgui/src/main-window.h Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/main-window.h Thu Jul 18 11:23:22 2019 -0400 @@ -51,7 +51,7 @@ #include "find-files-dialog.h" #include "history-dock-widget.h" #include "octave-dock-widget.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "resource-manager.h" #include "terminal-dock-widget.h" #include "variable-editor.h"
--- a/libgui/src/module.mk Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/module.mk Thu Jul 18 11:23:22 2019 -0400 @@ -142,11 +142,11 @@ %reldir%/moc-main-window.cc \ %reldir%/moc-news-reader.cc \ %reldir%/moc-octave-qobject.cc \ - %reldir%/moc-octave-qt-link.cc \ %reldir%/moc-settings-dialog.cc \ %reldir%/moc-terminal-dock-widget.cc \ %reldir%/moc-color-picker.cc \ %reldir%/moc-tab-bar.cc \ + %reldir%/moc-qt-interpreter-events.cc \ %reldir%/moc-resource-manager.cc \ %reldir%/moc-shortcut-manager.cc \ %reldir%/moc-welcome-wizard.cc \ @@ -200,8 +200,8 @@ %reldir%/main-window.h \ %reldir%/news-reader.h \ %reldir%/octave-qobject.h \ - %reldir%/octave-qt-link.h \ %reldir%/qt-application.h \ + %reldir%/qt-interpreter-events.h \ %reldir%/resource-manager.h \ %reldir%/settings-dialog.h \ %reldir%/shortcut-manager.h \ @@ -235,7 +235,7 @@ %reldir%/news-reader.cc \ %reldir%/octave-dock-widget.cc \ %reldir%/octave-qobject.cc \ - %reldir%/octave-qt-link.cc \ + %reldir%/qt-interpreter-events.cc \ %reldir%/qt-application.cc \ %reldir%/resource-manager.cc \ %reldir%/settings-dialog.cc \
--- a/libgui/src/octave-qobject.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/octave-qobject.cc Thu Jul 18 11:23:22 2019 -0400 @@ -38,7 +38,7 @@ #include "interpreter-qobject.h" #include "main-window.h" #include "octave-qobject.h" -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "qt-application.h" #include "resource-manager.h" @@ -70,9 +70,9 @@ } catch (execution_exception&) { - octave_link& olnk = __get_octave_link__ ("octave_qapplication::notify"); + event_manager& evmgr = __get_event_manager__ ("octave_qapplication::notify"); - olnk.post_exception (std::current_exception ()); + evmgr.post_exception (std::current_exception ()); } return false;
--- a/libgui/src/octave-qt-link.cc Thu Jul 18 09:58:41 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,651 +0,0 @@ -/* - -Copyright (C) 2013-2019 John W. Eaton -Copyright (C) 2011-2019 Jacob Dawid -Copyright (C) 2011-2019 John P. Swensen - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include <QDialog> -#include <QDir> -#include <QMetaType> -#include <QPushButton> -#include <QStringList> - -#include "oct-env.h" -#include "str-vec.h" - -#include "builtin-defun-decls.h" -#include "dialog.h" -#include "error.h" -#include "interpreter-private.h" -#include "load-path.h" -#include "ov.h" -#include "octave.h" -#include "oct-map.h" -#include "syminfo.h" -#include "utils.h" - -#include "octave-qt-link.h" -#include "resource-manager.h" - -Q_DECLARE_METATYPE (octave_value) -Q_DECLARE_METATYPE (octave::symbol_info_list) - -namespace octave -{ - octave_qt_link_events::octave_qt_link_events (void) - : octave_link_events (), m_shutdown_confirm_result (false) - { - qRegisterMetaType<octave_value> ("octave_value"); - qRegisterMetaType<symbol_info_list> ("symbol_info_list"); - } - - bool octave_qt_link_events::do_confirm_shutdown (void) - { - // Lock the mutex before emitting signal. - lock (); - - emit confirm_shutdown_signal (); - - // Wait while the GUI shuts down. - wait (); - - // The GUI has sent a signal and the thread has been awakened. - - unlock (); - - return m_shutdown_confirm_result; - } - - bool octave_qt_link_events::do_copy_image_to_clipboard (const std::string& file) - { - emit copy_image_to_clipboard_signal (QString::fromStdString (file), true); - - return true; - } - - bool octave_qt_link_events::do_edit_file (const std::string& file) - { - emit edit_file_signal (QString::fromStdString (file)); - - return true; - } - - bool octave_qt_link_events::do_prompt_new_edit_file (const std::string& file) - { - QSettings *settings = resource_manager::get_settings (); - - if (! settings || settings->value ("editor/create_new_file",false).toBool ()) - return true; - - std::string abs_fname = sys::env::make_absolute (file); - - QStringList btn; - QStringList role; - role << "YesRole" << "RejectRole"; - btn << tr ("Create") << tr ("Cancel"); - - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_dialog ( - tr ("File\n%1\ndoes not exist. Do you want to create it?"). - arg (QString::fromStdString (abs_fname)), - tr ("Octave Editor"), "quest", btn, tr ("Create"), role); - - // Wait while the user is responding to message box. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - QString answer = uiwidget_creator.get_dialog_button (); - - uiwidget_creator.unlock (); - - return (answer == tr ("Create")); - } - - uint8NDArray octave_qt_link_events::do_get_named_icon (const std::string& icon_name) - { - uint8NDArray retval; - QIcon icon = resource_manager::icon (QString::fromStdString (icon_name)); - if (! icon.isNull ()) - { - QImage img = icon.pixmap (QSize (32, 32)).toImage (); - - if (img.format () == QImage::Format_ARGB32_Premultiplied) - { - retval.resize (dim_vector (img.height (), img.width (), 4), 0); - uint8_t* bits = img.bits (); - for (int i = 0; i < img.height (); i++) - for (int j = 0; j < img.width (); j++) - { - retval(i,j,2) = bits[0]; - retval(i,j,1) = bits[1]; - retval(i,j,0) = bits[2]; - retval(i,j,3) = bits[3]; - bits += 4; - } - } - } - return retval; - } - - std::string octave_qt_link_events::do_question_dialog (const std::string& msg, - const std::string& title, - const std::string& btn1, - const std::string& btn2, - const std::string& btn3, - const std::string& btndef) - { - QStringList btn; - QStringList role; - // Must use ResetRole which is left-aligned for all OS and WM. - role << "ResetRole" << "ResetRole" << "ResetRole"; - btn << QString::fromStdString (btn1); - if (btn2 == "") - role.removeAt (0); - else - btn << QString::fromStdString (btn2); - btn << QString::fromStdString (btn3); - - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_dialog (QString::fromStdString (msg), - QString::fromStdString (title), - "quest", - btn, - QString::fromStdString (btndef), - role); - - // Wait while the user is responding to message box. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - std::string answer = uiwidget_creator.get_dialog_button ().toStdString (); - - uiwidget_creator.unlock (); - - return answer; - } - - static QStringList - make_qstring_list (const std::list<std::string>& lst) - { - QStringList retval; - - for (auto it = lst.begin (); it != lst.end (); it++) - retval.append (QString::fromStdString (*it)); - - return retval; - } - - static QStringList - make_filter_list (const octave_link::filter_list& lst) - { - QStringList retval; - - // We have pairs of data, first being the list of extensions - // exta;exb;extc etc second the name to use as filter name - // (optional). Qt wants a list of filters in the format of - // 'FilterName (space separated exts)'. - - for (auto it = lst.begin (); it != lst.end (); it++) - { - QString ext = QString::fromStdString (it->first); - QString name = QString::fromStdString (it->second); - - // Strip out extensions from name and replace ';' with spaces in - // list. - - name.replace (QRegExp ("\\(.*\\)"), ""); - ext.replace (";", " "); - - if (name.isEmpty ()) - { - // No name field. Build one from the extensions. - name = ext.toUpper () + " Files"; - } - - retval.append (name + " (" + ext + ')'); - } - - return retval; - } - - std::pair<std::list<int>, int> - octave_qt_link_events::do_list_dialog (const std::list<std::string>& list, - const std::string& mode, - int width, int height, - const std::list<int>& initial, - const std::string& name, - const std::list<std::string>& prompt, - const std::string& ok_string, - const std::string& cancel_string) - { - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_listview (make_qstring_list (list), - QString::fromStdString (mode), - width, height, - QList<int>::fromStdList (initial), - QString::fromStdString (name), - make_qstring_list (prompt), - QString::fromStdString (ok_string), - QString::fromStdString (cancel_string)); - - // Wait while the user is responding to message box. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - const QIntList *selected = uiwidget_creator.get_list_index (); - int ok = uiwidget_creator.get_dialog_result (); - - uiwidget_creator.unlock (); - - return std::pair<std::list<int>, int> (selected->toStdList (), ok); - } - - std::list<std::string> - octave_qt_link_events::do_input_dialog (const std::list<std::string>& prompt, - const std::string& title, - const std::list<float>& nr, - const std::list<float>& nc, - const std::list<std::string>& defaults) - { - std::list<std::string> retval; - - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_inputlayout (make_qstring_list (prompt), - QString::fromStdString (title), - QFloatList::fromStdList (nr), - QFloatList::fromStdList (nc), - make_qstring_list (defaults)); - - // Wait while the user is responding to message box. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - const QStringList *inputLine = uiwidget_creator.get_string_list (); - - uiwidget_creator.unlock (); - - for (auto it = inputLine->begin (); it != inputLine->end (); it++) - retval.push_back (it->toStdString ()); - - return retval; - } - - std::list<std::string> - octave_qt_link_events::do_file_dialog (const filter_list& filter, - const std::string& title, - const std::string& filename, - const std::string& dirname, - const std::string& multimode) - { - std::list<std::string> retval; - - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_filedialog (make_filter_list (filter), - QString::fromStdString (title), - QString::fromStdString (filename), - QString::fromStdString (dirname), - QString::fromStdString (multimode)); - - // Wait while the user is responding to dialog. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - // Add all the file dialog results to a string list. - const QStringList *inputLine = uiwidget_creator.get_string_list (); - - for (auto it = inputLine->begin (); it != inputLine->end (); it++) - retval.push_back (it->toStdString ()); - - retval.push_back (uiwidget_creator.get_dialog_path ()->toStdString ()); - retval.push_back ((QString ("%1").arg ( - uiwidget_creator.get_dialog_result ())).toStdString ()); - - uiwidget_creator.unlock (); - - return retval; - } - - // Prompt to allow file to be run by setting cwd (or if addpath_option==true, - // alternatively setting the path). - // This uses a QMessageBox unlike other functions in this file, - // because uiwidget_creator.waitcondition.wait hangs when called from - // file_editor_tab::handle_context_menu_break_condition(). (FIXME: why hang?) - int octave_qt_link_events::do_debug_cd_or_addpath_error (const std::string& file, - const std::string& dir, - bool addpath_option) - { - int retval = -1; - - QString qdir = QString::fromStdString (dir); - QString qfile = QString::fromStdString (file); - QString msg - = (addpath_option - ? tr ("The file %1 does not exist in the load path. To run or debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg (qfile).arg (qdir) - : tr ("The file %1 is shadowed by a file with the same name in the load path. To run or debug the function you are editing, change to the directory %2.").arg (qfile).arg (qdir)); - - QString title = tr ("Change Directory or Add Directory to Load Path"); - - QString cd_txt = tr ("&Change Directory"); - QString addpath_txt = tr ("&Add Directory to Load Path"); - QString cancel_txt = tr ("Cancel"); - - QStringList btn; - QStringList role; - btn << cd_txt; - role << "YesRole"; - if (addpath_option) - { - btn << addpath_txt; - role << "AcceptRole"; - } - btn << cancel_txt; - role << "RejectRole"; - - // Lock mutex before signaling. - uiwidget_creator.lock (); - - uiwidget_creator.signal_dialog (msg, title, "quest", btn, cancel_txt, role); - - // Wait while the user is responding to message box. - uiwidget_creator.wait (); - - // The GUI has sent a signal and the thread has been awakened. - - QString result = uiwidget_creator.get_dialog_button (); - - uiwidget_creator.unlock (); - - if (result == cd_txt) - retval = 1; - else if (result == addpath_txt) - retval = 2; - - return retval; - } - - void octave_qt_link_events::do_change_directory (const std::string& dir) - { - emit change_directory_signal (QString::fromStdString (dir)); - } - - void octave_qt_link_events::do_file_remove (const std::string& old_name, - const std::string& new_name) - { - // Lock the mutex before signaling - lock (); - - // Emit the signal for the editor for closing the file if it is open - emit file_remove_signal (QString::fromStdString (old_name), - QString::fromStdString (new_name)); - - // Wait for the GUI and unlock when resumed - wait (); - unlock (); - } - - void octave_qt_link_events::do_file_renamed (bool load_new) - { - emit file_renamed_signal (load_new); - } - - void octave_qt_link_events::do_execute_command_in_terminal - (const std::string& command) - { - emit execute_command_in_terminal_signal (QString::fromStdString (command)); - } - - void octave_qt_link_events::do_set_workspace (bool top_level, bool debug, - const symbol_info_list& syminfo, - bool update_variable_editor) - { - if (! top_level && ! debug) - return; - - emit set_workspace_signal (top_level, debug, syminfo); - - if (update_variable_editor) - emit refresh_variable_editor_signal (); - } - - void octave_qt_link_events::do_clear_workspace (void) - { - emit clear_workspace_signal (); - } - - void octave_qt_link_events::do_set_history (const string_vector& hist) - { - QStringList qt_hist; - - for (octave_idx_type i = 0; i < hist.numel (); i++) - qt_hist.append (QString::fromStdString (hist[i])); - - emit set_history_signal (qt_hist); - } - - void octave_qt_link_events::do_append_history (const std::string& hist_entry) - { - emit append_history_signal (QString::fromStdString (hist_entry)); - } - - void octave_qt_link_events::do_clear_history (void) - { - emit clear_history_signal (); - } - - void octave_qt_link_events::do_pre_input_event (void) - { } - - void octave_qt_link_events::do_post_input_event (void) - { } - - void octave_qt_link_events::do_enter_debugger_event (const std::string& file, - int line) - { - interpreter& interp = __get_interpreter__ ( - "octave_qt_link_events::do_enter_debugger_event"); - octave_value_list fct = F__which__ (interp, ovl (file),0); - octave_map map = fct(0).map_value (); - - std::string type = map.contents ("type").data ()[0].string_value (); - if (type == "command-line function") - return; - - do_insert_debugger_pointer (file, line); - - emit enter_debugger_signal (); - } - - void octave_qt_link_events::do_execute_in_debugger_event (const std::string& file, - int line) - { - do_delete_debugger_pointer (file, line); - } - - void octave_qt_link_events::do_exit_debugger_event (void) - { - emit exit_debugger_signal (); - } - - // Display (if @insert true) or remove the appropriate symbol for a breakpoint - // in @file at @line with condition @cond. - void octave_qt_link_events::do_update_breakpoint (bool insert, - const std::string& file, - int line, - const std::string& cond) - { - emit update_breakpoint_marker_signal (insert, QString::fromStdString (file), - line, QString::fromStdString (cond)); - } - - void octave_qt_link_events::do_show_preferences (void) - { - emit show_preferences_signal (); - } - - std::string octave_qt_link_events::do_gui_preference (const std::string& key, - const std::string& value) - { - QString pref_value; - - // Lock the mutex before signaling - lock (); - - // Emit the signal for changing or getting a preference - emit gui_preference_signal (QString::fromStdString (key), - QString::fromStdString (value), &pref_value); - - // Wait for the GUI and unlock when resumed - wait (); - unlock (); - - return pref_value.toStdString (); - } - - void octave_qt_link_events::do_show_doc (const std::string& file) - { - emit show_doc_signal (QString::fromStdString (file)); - } - - void octave_qt_link_events::do_register_doc (const std::string& file) - { - emit register_doc_signal (QString::fromStdString (file)); - } - - void octave_qt_link_events::do_unregister_doc (const std::string& file) - { - emit unregister_doc_signal (QString::fromStdString (file)); - } - - void octave_qt_link_events::do_edit_variable (const std::string& expr, - const octave_value& val) - { - emit edit_variable_signal (QString::fromStdString (expr), val); - } - - bool octave_qt_link_events::file_in_path (const std::string& file, - const std::string& dir) - { - - bool ok = false; - bool addpath_option = true; - - std::string curr_dir = sys::env::get_current_directory (); - - if (same_file (curr_dir, dir)) - ok = true; - else - { - load_path& lp = __get_load_path__ ("octave_qt_link_events::file_in_path"); - - bool dir_in_load_path = lp.contains_canonical (dir); - - // get base name, allowing "@class/method.m" (bug #41514) - std::string base_file = (file.length () > dir.length ()) - ? file.substr (dir.length () + 1) - : sys::env::base_pathname (file); - - std::string lp_file = lp.find_file (base_file); - - if (dir_in_load_path) - { - if (same_file (lp_file, file)) - ok = true; - } - else - { - // File directory is not in path. Is the file in the path in - // the current directory? If so, then changing the current - // directory will be needed. Adding directory to path is - // not enough because the file in the current directory would - // still be found. - - if (same_file (lp_file, base_file)) - { - if (same_file (curr_dir, dir)) - ok = true; - else - addpath_option = false; - } - } - } - - if (! ok) - { - octave_link& olnk - = __get_octave_link__ ("octave_qt_link_events::file_in_path"); - - int action = olnk.debug_cd_or_addpath_error (file, dir, addpath_option); - - switch (action) - { - case 1: - Fcd (ovl (dir)); - ok = true; - break; - - case 2: - { - load_path& lp = __get_load_path__ ("octave_qt_link_events::file_in_path"); - - lp.prepend (dir); - ok = true; - } - break; - - default: - break; - } - } - - return ok; - } - - void octave_qt_link_events::do_insert_debugger_pointer (const std::string& file, - int line) - { - emit insert_debugger_pointer_signal (QString::fromStdString (file), line); - } - - void octave_qt_link_events::do_delete_debugger_pointer (const std::string& file, - int line) - { - emit delete_debugger_pointer_signal (QString::fromStdString (file), line); - } -}
--- a/libgui/src/octave-qt-link.h Thu Jul 18 09:58:41 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,234 +0,0 @@ -/* - -Copyright (C) 2013-2019 John W. Eaton -Copyright (C) 2011-2019 Jacob Dawid -Copyright (C) 2011-2019 John P. Swensen - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -#if ! defined (octave_qt_link_h) -#define octave_qt_link_h 1 - -#include <list> -#include <string> - -#include <QList> -#include <QObject> -#include <QString> -#include <QMutex> -#include <QWaitCondition> - -#include "octave-link.h" - -// Defined for purposes of sending QList<int> as part of signal. -typedef QList<int> QIntList; - -class octave_value; - -namespace octave -{ - //! Provides threadsafe access to octave. - //! @author Jacob Dawid - //! - //! This class is a wrapper around octave and provides thread safety by - //! buffering access operations to octave and executing them in the - //! readline event hook, which lives in the octave thread. - - class octave_qt_link_events : public QObject, public octave_link_events - { - Q_OBJECT - - public: - - octave_qt_link_events (void); - - // No copying! - - octave_qt_link_events (const octave_qt_link_events&) = delete; - - octave_qt_link_events& operator = (const octave_qt_link_events&) = delete; - - ~octave_qt_link_events (void) = default; - - bool do_confirm_shutdown (void); - - bool do_copy_image_to_clipboard (const std::string& file); - - bool do_edit_file (const std::string& file); - - bool do_prompt_new_edit_file (const std::string& file); - - std::string - do_question_dialog (const std::string& msg, const std::string& title, - const std::string& btn1, const std::string& btn2, - const std::string& btn3, const std::string& btndef); - - std::pair<std::list<int>, int> - do_list_dialog (const std::list<std::string>& list, - const std::string& mode, - int width, int height, - const std::list<int>& initial_value, - const std::string& name, - const std::list<std::string>& prompt, - const std::string& ok_string, - const std::string& cancel_string); - - std::list<std::string> - do_input_dialog (const std::list<std::string>& prompt, - const std::string& title, - const std::list<float>& nr, - const std::list<float>& nc, - const std::list<std::string>& defaults); - - std::list<std::string> - do_file_dialog (const filter_list& filter, const std::string& title, - const std::string& filename, const std::string& pathname, - const std::string& multimode); - - int - do_debug_cd_or_addpath_error (const std::string& file, - const std::string& dir, - bool addpath_option); - - void do_change_directory (const std::string& dir); - - void do_file_remove (const std::string& old_name, - const std::string& new_name); - void do_file_renamed (bool load_new = true); - - void do_execute_command_in_terminal (const std::string& command); - - uint8NDArray do_get_named_icon (const std::string& icon_name); - - void do_set_workspace (bool top_level, bool debug, - const symbol_info_list& syminfo, - bool update_variable_editor); - - void do_clear_workspace (void); - - void do_set_history (const string_vector& hist); - - void do_append_history (const std::string& hist_entry); - - void do_clear_history (void); - - void do_pre_input_event (void); - - void do_post_input_event (void); - - void do_enter_debugger_event (const std::string& file, int line); - - void do_execute_in_debugger_event (const std::string& file, int line); - - void do_exit_debugger_event (void); - - void do_update_breakpoint (bool insert, const std::string& file, int line, - const std::string& cond); - - void do_show_preferences (void); - - std::string do_gui_preference (const std::string& key, - const std::string& value); - void do_show_doc (const std::string& file); - - void do_register_doc (const std::string& file); - - void do_unregister_doc (const std::string& file); - - void do_edit_variable (const std::string& name, const octave_value& val); - - void shutdown_confirmation (bool sd) { m_shutdown_confirm_result = sd; } - - static bool file_in_path (const std::string& file, const std::string& dir); - - void lock (void) { m_mutex.lock (); } - - void wait (void) { m_waitcondition.wait (&m_mutex); } - - void unlock (void) { m_mutex.unlock (); } - - void wake_all (void) { m_waitcondition.wakeAll (); } - - private: - - void do_insert_debugger_pointer (const std::string& file, int line); - - void do_delete_debugger_pointer (const std::string& file, int line); - - bool m_shutdown_confirm_result; - - QMutex m_mutex; - - QWaitCondition m_waitcondition; - - signals: - - void copy_image_to_clipboard_signal (const QString& file, bool remove_file); - - void edit_file_signal (const QString& file); - - void change_directory_signal (const QString& dir); - - void file_remove_signal (const QString& old_name, const QString& new_name); - - void file_renamed_signal (bool load_new); - - void execute_command_in_terminal_signal (const QString& command); - - void set_workspace_signal (bool top_level, bool debug, - const symbol_info_list& syminfo); - - void clear_workspace_signal (void); - - void set_history_signal (const QStringList& hist); - - void append_history_signal (const QString& hist_entry); - - void clear_history_signal (void); - - void enter_debugger_signal (void); - - void exit_debugger_signal (void); - - void update_breakpoint_marker_signal (bool insert, const QString& file, - int line, const QString& cond); - - void insert_debugger_pointer_signal (const QString&, int); - - void delete_debugger_pointer_signal (const QString&, int); - - void show_preferences_signal (void); - - void gui_preference_signal (const QString&, const QString&, QString*); - - void show_doc_signal (const QString& file); - - void register_doc_signal (const QString& file); - - void unregister_doc_signal (const QString& file); - - void edit_variable_signal (const QString& name, const octave_value& val); - - void refresh_variable_editor_signal (void); - - void confirm_shutdown_signal (void); - }; -} - -#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/qt-interpreter-events.cc Thu Jul 18 11:23:22 2019 -0400 @@ -0,0 +1,651 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid +Copyright (C) 2011-2019 John P. Swensen + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<https://www.gnu.org/licenses/>. + +*/ + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include <QDialog> +#include <QDir> +#include <QMetaType> +#include <QPushButton> +#include <QStringList> + +#include "oct-env.h" +#include "str-vec.h" + +#include "builtin-defun-decls.h" +#include "dialog.h" +#include "error.h" +#include "interpreter-private.h" +#include "load-path.h" +#include "ov.h" +#include "octave.h" +#include "oct-map.h" +#include "syminfo.h" +#include "utils.h" + +#include "qt-interpreter-events.h" +#include "resource-manager.h" + +Q_DECLARE_METATYPE (octave_value) +Q_DECLARE_METATYPE (octave::symbol_info_list) + +namespace octave +{ + qt_interpreter_events::qt_interpreter_events (void) + : interpreter_events (), m_shutdown_confirm_result (false) + { + qRegisterMetaType<octave_value> ("octave_value"); + qRegisterMetaType<symbol_info_list> ("symbol_info_list"); + } + + bool qt_interpreter_events::do_confirm_shutdown (void) + { + // Lock the mutex before emitting signal. + lock (); + + emit confirm_shutdown_signal (); + + // Wait while the GUI shuts down. + wait (); + + // The GUI has sent a signal and the thread has been awakened. + + unlock (); + + return m_shutdown_confirm_result; + } + + bool qt_interpreter_events::do_copy_image_to_clipboard (const std::string& file) + { + emit copy_image_to_clipboard_signal (QString::fromStdString (file), true); + + return true; + } + + bool qt_interpreter_events::do_edit_file (const std::string& file) + { + emit edit_file_signal (QString::fromStdString (file)); + + return true; + } + + bool qt_interpreter_events::do_prompt_new_edit_file (const std::string& file) + { + QSettings *settings = resource_manager::get_settings (); + + if (! settings || settings->value ("editor/create_new_file",false).toBool ()) + return true; + + std::string abs_fname = sys::env::make_absolute (file); + + QStringList btn; + QStringList role; + role << "YesRole" << "RejectRole"; + btn << tr ("Create") << tr ("Cancel"); + + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_dialog ( + tr ("File\n%1\ndoes not exist. Do you want to create it?"). + arg (QString::fromStdString (abs_fname)), + tr ("Octave Editor"), "quest", btn, tr ("Create"), role); + + // Wait while the user is responding to message box. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + QString answer = uiwidget_creator.get_dialog_button (); + + uiwidget_creator.unlock (); + + return (answer == tr ("Create")); + } + + uint8NDArray qt_interpreter_events::do_get_named_icon (const std::string& icon_name) + { + uint8NDArray retval; + QIcon icon = resource_manager::icon (QString::fromStdString (icon_name)); + if (! icon.isNull ()) + { + QImage img = icon.pixmap (QSize (32, 32)).toImage (); + + if (img.format () == QImage::Format_ARGB32_Premultiplied) + { + retval.resize (dim_vector (img.height (), img.width (), 4), 0); + uint8_t* bits = img.bits (); + for (int i = 0; i < img.height (); i++) + for (int j = 0; j < img.width (); j++) + { + retval(i,j,2) = bits[0]; + retval(i,j,1) = bits[1]; + retval(i,j,0) = bits[2]; + retval(i,j,3) = bits[3]; + bits += 4; + } + } + } + return retval; + } + + std::string qt_interpreter_events::do_question_dialog (const std::string& msg, + const std::string& title, + const std::string& btn1, + const std::string& btn2, + const std::string& btn3, + const std::string& btndef) + { + QStringList btn; + QStringList role; + // Must use ResetRole which is left-aligned for all OS and WM. + role << "ResetRole" << "ResetRole" << "ResetRole"; + btn << QString::fromStdString (btn1); + if (btn2 == "") + role.removeAt (0); + else + btn << QString::fromStdString (btn2); + btn << QString::fromStdString (btn3); + + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_dialog (QString::fromStdString (msg), + QString::fromStdString (title), + "quest", + btn, + QString::fromStdString (btndef), + role); + + // Wait while the user is responding to message box. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + std::string answer = uiwidget_creator.get_dialog_button ().toStdString (); + + uiwidget_creator.unlock (); + + return answer; + } + + static QStringList + make_qstring_list (const std::list<std::string>& lst) + { + QStringList retval; + + for (auto it = lst.begin (); it != lst.end (); it++) + retval.append (QString::fromStdString (*it)); + + return retval; + } + + static QStringList + make_filter_list (const event_manager::filter_list& lst) + { + QStringList retval; + + // We have pairs of data, first being the list of extensions + // exta;exb;extc etc second the name to use as filter name + // (optional). Qt wants a list of filters in the format of + // 'FilterName (space separated exts)'. + + for (auto it = lst.begin (); it != lst.end (); it++) + { + QString ext = QString::fromStdString (it->first); + QString name = QString::fromStdString (it->second); + + // Strip out extensions from name and replace ';' with spaces in + // list. + + name.replace (QRegExp ("\\(.*\\)"), ""); + ext.replace (";", " "); + + if (name.isEmpty ()) + { + // No name field. Build one from the extensions. + name = ext.toUpper () + " Files"; + } + + retval.append (name + " (" + ext + ')'); + } + + return retval; + } + + std::pair<std::list<int>, int> + qt_interpreter_events::do_list_dialog (const std::list<std::string>& list, + const std::string& mode, + int width, int height, + const std::list<int>& initial, + const std::string& name, + const std::list<std::string>& prompt, + const std::string& ok_string, + const std::string& cancel_string) + { + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_listview (make_qstring_list (list), + QString::fromStdString (mode), + width, height, + QList<int>::fromStdList (initial), + QString::fromStdString (name), + make_qstring_list (prompt), + QString::fromStdString (ok_string), + QString::fromStdString (cancel_string)); + + // Wait while the user is responding to message box. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + const QIntList *selected = uiwidget_creator.get_list_index (); + int ok = uiwidget_creator.get_dialog_result (); + + uiwidget_creator.unlock (); + + return std::pair<std::list<int>, int> (selected->toStdList (), ok); + } + + std::list<std::string> + qt_interpreter_events::do_input_dialog (const std::list<std::string>& prompt, + const std::string& title, + const std::list<float>& nr, + const std::list<float>& nc, + const std::list<std::string>& defaults) + { + std::list<std::string> retval; + + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_inputlayout (make_qstring_list (prompt), + QString::fromStdString (title), + QFloatList::fromStdList (nr), + QFloatList::fromStdList (nc), + make_qstring_list (defaults)); + + // Wait while the user is responding to message box. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + const QStringList *inputLine = uiwidget_creator.get_string_list (); + + uiwidget_creator.unlock (); + + for (auto it = inputLine->begin (); it != inputLine->end (); it++) + retval.push_back (it->toStdString ()); + + return retval; + } + + std::list<std::string> + qt_interpreter_events::do_file_dialog (const filter_list& filter, + const std::string& title, + const std::string& filename, + const std::string& dirname, + const std::string& multimode) + { + std::list<std::string> retval; + + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_filedialog (make_filter_list (filter), + QString::fromStdString (title), + QString::fromStdString (filename), + QString::fromStdString (dirname), + QString::fromStdString (multimode)); + + // Wait while the user is responding to dialog. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + // Add all the file dialog results to a string list. + const QStringList *inputLine = uiwidget_creator.get_string_list (); + + for (auto it = inputLine->begin (); it != inputLine->end (); it++) + retval.push_back (it->toStdString ()); + + retval.push_back (uiwidget_creator.get_dialog_path ()->toStdString ()); + retval.push_back ((QString ("%1").arg ( + uiwidget_creator.get_dialog_result ())).toStdString ()); + + uiwidget_creator.unlock (); + + return retval; + } + + // Prompt to allow file to be run by setting cwd (or if addpath_option==true, + // alternatively setting the path). + // This uses a QMessageBox unlike other functions in this file, + // because uiwidget_creator.waitcondition.wait hangs when called from + // file_editor_tab::handle_context_menu_break_condition(). (FIXME: why hang?) + int qt_interpreter_events::do_debug_cd_or_addpath_error (const std::string& file, + const std::string& dir, + bool addpath_option) + { + int retval = -1; + + QString qdir = QString::fromStdString (dir); + QString qfile = QString::fromStdString (file); + QString msg + = (addpath_option + ? tr ("The file %1 does not exist in the load path. To run or debug the function you are editing, you must either change to the directory %2 or add that directory to the load path.").arg (qfile).arg (qdir) + : tr ("The file %1 is shadowed by a file with the same name in the load path. To run or debug the function you are editing, change to the directory %2.").arg (qfile).arg (qdir)); + + QString title = tr ("Change Directory or Add Directory to Load Path"); + + QString cd_txt = tr ("&Change Directory"); + QString addpath_txt = tr ("&Add Directory to Load Path"); + QString cancel_txt = tr ("Cancel"); + + QStringList btn; + QStringList role; + btn << cd_txt; + role << "YesRole"; + if (addpath_option) + { + btn << addpath_txt; + role << "AcceptRole"; + } + btn << cancel_txt; + role << "RejectRole"; + + // Lock mutex before signaling. + uiwidget_creator.lock (); + + uiwidget_creator.signal_dialog (msg, title, "quest", btn, cancel_txt, role); + + // Wait while the user is responding to message box. + uiwidget_creator.wait (); + + // The GUI has sent a signal and the thread has been awakened. + + QString result = uiwidget_creator.get_dialog_button (); + + uiwidget_creator.unlock (); + + if (result == cd_txt) + retval = 1; + else if (result == addpath_txt) + retval = 2; + + return retval; + } + + void qt_interpreter_events::do_change_directory (const std::string& dir) + { + emit change_directory_signal (QString::fromStdString (dir)); + } + + void qt_interpreter_events::do_file_remove (const std::string& old_name, + const std::string& new_name) + { + // Lock the mutex before signaling + lock (); + + // Emit the signal for the editor for closing the file if it is open + emit file_remove_signal (QString::fromStdString (old_name), + QString::fromStdString (new_name)); + + // Wait for the GUI and unlock when resumed + wait (); + unlock (); + } + + void qt_interpreter_events::do_file_renamed (bool load_new) + { + emit file_renamed_signal (load_new); + } + + void qt_interpreter_events::do_execute_command_in_terminal + (const std::string& command) + { + emit execute_command_in_terminal_signal (QString::fromStdString (command)); + } + + void qt_interpreter_events::do_set_workspace (bool top_level, bool debug, + const symbol_info_list& syminfo, + bool update_variable_editor) + { + if (! top_level && ! debug) + return; + + emit set_workspace_signal (top_level, debug, syminfo); + + if (update_variable_editor) + emit refresh_variable_editor_signal (); + } + + void qt_interpreter_events::do_clear_workspace (void) + { + emit clear_workspace_signal (); + } + + void qt_interpreter_events::do_set_history (const string_vector& hist) + { + QStringList qt_hist; + + for (octave_idx_type i = 0; i < hist.numel (); i++) + qt_hist.append (QString::fromStdString (hist[i])); + + emit set_history_signal (qt_hist); + } + + void qt_interpreter_events::do_append_history (const std::string& hist_entry) + { + emit append_history_signal (QString::fromStdString (hist_entry)); + } + + void qt_interpreter_events::do_clear_history (void) + { + emit clear_history_signal (); + } + + void qt_interpreter_events::do_pre_input_event (void) + { } + + void qt_interpreter_events::do_post_input_event (void) + { } + + void qt_interpreter_events::do_enter_debugger_event (const std::string& file, + int line) + { + interpreter& interp = __get_interpreter__ ( + "qt_interpreter_events::do_enter_debugger_event"); + octave_value_list fct = F__which__ (interp, ovl (file),0); + octave_map map = fct(0).map_value (); + + std::string type = map.contents ("type").data ()[0].string_value (); + if (type == "command-line function") + return; + + do_insert_debugger_pointer (file, line); + + emit enter_debugger_signal (); + } + + void qt_interpreter_events::do_execute_in_debugger_event (const std::string& file, + int line) + { + do_delete_debugger_pointer (file, line); + } + + void qt_interpreter_events::do_exit_debugger_event (void) + { + emit exit_debugger_signal (); + } + + // Display (if @insert true) or remove the appropriate symbol for a breakpoint + // in @file at @line with condition @cond. + void qt_interpreter_events::do_update_breakpoint (bool insert, + const std::string& file, + int line, + const std::string& cond) + { + emit update_breakpoint_marker_signal (insert, QString::fromStdString (file), + line, QString::fromStdString (cond)); + } + + void qt_interpreter_events::do_show_preferences (void) + { + emit show_preferences_signal (); + } + + std::string qt_interpreter_events::do_gui_preference (const std::string& key, + const std::string& value) + { + QString pref_value; + + // Lock the mutex before signaling + lock (); + + // Emit the signal for changing or getting a preference + emit gui_preference_signal (QString::fromStdString (key), + QString::fromStdString (value), &pref_value); + + // Wait for the GUI and unlock when resumed + wait (); + unlock (); + + return pref_value.toStdString (); + } + + void qt_interpreter_events::do_show_doc (const std::string& file) + { + emit show_doc_signal (QString::fromStdString (file)); + } + + void qt_interpreter_events::do_register_doc (const std::string& file) + { + emit register_doc_signal (QString::fromStdString (file)); + } + + void qt_interpreter_events::do_unregister_doc (const std::string& file) + { + emit unregister_doc_signal (QString::fromStdString (file)); + } + + void qt_interpreter_events::do_edit_variable (const std::string& expr, + const octave_value& val) + { + emit edit_variable_signal (QString::fromStdString (expr), val); + } + + bool qt_interpreter_events::file_in_path (const std::string& file, + const std::string& dir) + { + + bool ok = false; + bool addpath_option = true; + + std::string curr_dir = sys::env::get_current_directory (); + + if (same_file (curr_dir, dir)) + ok = true; + else + { + load_path& lp = __get_load_path__ ("qt_interpreter_events::file_in_path"); + + bool dir_in_load_path = lp.contains_canonical (dir); + + // get base name, allowing "@class/method.m" (bug #41514) + std::string base_file = (file.length () > dir.length ()) + ? file.substr (dir.length () + 1) + : sys::env::base_pathname (file); + + std::string lp_file = lp.find_file (base_file); + + if (dir_in_load_path) + { + if (same_file (lp_file, file)) + ok = true; + } + else + { + // File directory is not in path. Is the file in the path in + // the current directory? If so, then changing the current + // directory will be needed. Adding directory to path is + // not enough because the file in the current directory would + // still be found. + + if (same_file (lp_file, base_file)) + { + if (same_file (curr_dir, dir)) + ok = true; + else + addpath_option = false; + } + } + } + + if (! ok) + { + event_manager& evmgr + = __get_event_manager__ ("qt_interpreter_events::file_in_path"); + + int action = evmgr.debug_cd_or_addpath_error (file, dir, addpath_option); + + switch (action) + { + case 1: + Fcd (ovl (dir)); + ok = true; + break; + + case 2: + { + load_path& lp = __get_load_path__ ("qt_interpreter_events::file_in_path"); + + lp.prepend (dir); + ok = true; + } + break; + + default: + break; + } + } + + return ok; + } + + void qt_interpreter_events::do_insert_debugger_pointer (const std::string& file, + int line) + { + emit insert_debugger_pointer_signal (QString::fromStdString (file), line); + } + + void qt_interpreter_events::do_delete_debugger_pointer (const std::string& file, + int line) + { + emit delete_debugger_pointer_signal (QString::fromStdString (file), line); + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libgui/src/qt-interpreter-events.h Thu Jul 18 11:23:22 2019 -0400 @@ -0,0 +1,234 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid +Copyright (C) 2011-2019 John P. Swensen + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<https://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_qt_interpreter_events_h) +#define octave_qt_interpreter_events_h 1 + +#include <list> +#include <string> + +#include <QList> +#include <QObject> +#include <QString> +#include <QMutex> +#include <QWaitCondition> + +#include "event-manager.h" + +// Defined for purposes of sending QList<int> as part of signal. +typedef QList<int> QIntList; + +class octave_value; + +namespace octave +{ + //! Provides threadsafe access to octave. + //! @author Jacob Dawid + //! + //! This class is a wrapper around octave and provides thread safety by + //! buffering access operations to octave and executing them in the + //! readline event hook, which lives in the octave thread. + + class qt_interpreter_events : public QObject, public interpreter_events + { + Q_OBJECT + + public: + + qt_interpreter_events (void); + + // No copying! + + qt_interpreter_events (const qt_interpreter_events&) = delete; + + qt_interpreter_events& operator = (const qt_interpreter_events&) = delete; + + ~qt_interpreter_events (void) = default; + + bool do_confirm_shutdown (void); + + bool do_copy_image_to_clipboard (const std::string& file); + + bool do_edit_file (const std::string& file); + + bool do_prompt_new_edit_file (const std::string& file); + + std::string + do_question_dialog (const std::string& msg, const std::string& title, + const std::string& btn1, const std::string& btn2, + const std::string& btn3, const std::string& btndef); + + std::pair<std::list<int>, int> + do_list_dialog (const std::list<std::string>& list, + const std::string& mode, + int width, int height, + const std::list<int>& initial_value, + const std::string& name, + const std::list<std::string>& prompt, + const std::string& ok_string, + const std::string& cancel_string); + + std::list<std::string> + do_input_dialog (const std::list<std::string>& prompt, + const std::string& title, + const std::list<float>& nr, + const std::list<float>& nc, + const std::list<std::string>& defaults); + + std::list<std::string> + do_file_dialog (const filter_list& filter, const std::string& title, + const std::string& filename, const std::string& pathname, + const std::string& multimode); + + int + do_debug_cd_or_addpath_error (const std::string& file, + const std::string& dir, + bool addpath_option); + + void do_change_directory (const std::string& dir); + + void do_file_remove (const std::string& old_name, + const std::string& new_name); + void do_file_renamed (bool load_new = true); + + void do_execute_command_in_terminal (const std::string& command); + + uint8NDArray do_get_named_icon (const std::string& icon_name); + + void do_set_workspace (bool top_level, bool debug, + const symbol_info_list& syminfo, + bool update_variable_editor); + + void do_clear_workspace (void); + + void do_set_history (const string_vector& hist); + + void do_append_history (const std::string& hist_entry); + + void do_clear_history (void); + + void do_pre_input_event (void); + + void do_post_input_event (void); + + void do_enter_debugger_event (const std::string& file, int line); + + void do_execute_in_debugger_event (const std::string& file, int line); + + void do_exit_debugger_event (void); + + void do_update_breakpoint (bool insert, const std::string& file, int line, + const std::string& cond); + + void do_show_preferences (void); + + std::string do_gui_preference (const std::string& key, + const std::string& value); + void do_show_doc (const std::string& file); + + void do_register_doc (const std::string& file); + + void do_unregister_doc (const std::string& file); + + void do_edit_variable (const std::string& name, const octave_value& val); + + void shutdown_confirmation (bool sd) { m_shutdown_confirm_result = sd; } + + static bool file_in_path (const std::string& file, const std::string& dir); + + void lock (void) { m_mutex.lock (); } + + void wait (void) { m_waitcondition.wait (&m_mutex); } + + void unlock (void) { m_mutex.unlock (); } + + void wake_all (void) { m_waitcondition.wakeAll (); } + + private: + + void do_insert_debugger_pointer (const std::string& file, int line); + + void do_delete_debugger_pointer (const std::string& file, int line); + + bool m_shutdown_confirm_result; + + QMutex m_mutex; + + QWaitCondition m_waitcondition; + + signals: + + void copy_image_to_clipboard_signal (const QString& file, bool remove_file); + + void edit_file_signal (const QString& file); + + void change_directory_signal (const QString& dir); + + void file_remove_signal (const QString& old_name, const QString& new_name); + + void file_renamed_signal (bool load_new); + + void execute_command_in_terminal_signal (const QString& command); + + void set_workspace_signal (bool top_level, bool debug, + const symbol_info_list& syminfo); + + void clear_workspace_signal (void); + + void set_history_signal (const QStringList& hist); + + void append_history_signal (const QString& hist_entry); + + void clear_history_signal (void); + + void enter_debugger_signal (void); + + void exit_debugger_signal (void); + + void update_breakpoint_marker_signal (bool insert, const QString& file, + int line, const QString& cond); + + void insert_debugger_pointer_signal (const QString&, int); + + void delete_debugger_pointer_signal (const QString&, int); + + void show_preferences_signal (void); + + void gui_preference_signal (const QString&, const QString&, QString*); + + void show_doc_signal (const QString& file); + + void register_doc_signal (const QString& file); + + void unregister_doc_signal (const QString& file); + + void edit_variable_signal (const QString& name, const octave_value& val); + + void refresh_variable_editor_signal (void); + + void confirm_shutdown_signal (void); + }; +} + +#endif
--- a/libgui/src/variable-editor-model.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libgui/src/variable-editor-model.cc Thu Jul 18 11:23:22 2019 -0400 @@ -35,7 +35,7 @@ #include <QString> #include <QTableView> -#include "octave-qt-link.h" +#include "qt-interpreter-events.h" #include "variable-editor-model.h" #include "interpreter.h" @@ -1012,9 +1012,9 @@ std::string expr = os.str (); - octave_link& olnk = __get_octave_link__ ("variable_editor_model::setData"); + event_manager& evmgr = __get_event_manager__ ("variable_editor_model::setData"); - olnk.post_event + evmgr.post_event ([this, nm, expr, idx] (void) { // INTERPRETER THREAD @@ -1166,10 +1166,10 @@ { std::string expr = expr_arg.toStdString (); - octave_link& olnk - = __get_octave_link__ ("variable_editor_model::eval_expr_event"); + event_manager& evmgr + = __get_event_manager__ ("variable_editor_model::eval_expr_event"); - olnk.post_event + evmgr.post_event ([this, expr] (void) { // INTERPRETER THREAD @@ -1240,10 +1240,10 @@ void variable_editor_model::update_data_cache (void) { - octave_link& olnk - = __get_octave_link__ ("variable_editor_model::update_data_cache"); + event_manager& evmgr + = __get_event_manager__ ("variable_editor_model::update_data_cache"); - olnk.post_event + evmgr.post_event ([this] (void) { // INTERPRETER_THREAD
--- a/libinterp/corefcn/debug.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/debug.cc Thu Jul 18 11:23:22 2019 -0400 @@ -535,7 +535,7 @@ /* %!test %! if (isguirunning ()) -%! orig_show_dbg = __octave_link_gui_preference__ ("editor/show_dbg_file", +%! orig_show_dbg = __event_manager_gui_preference__ ("editor/show_dbg_file", %! "0"); %! endif %! unwind_protect @@ -553,7 +553,7 @@ %! assert (s(2).file(end-10:end), [filesep "@ftp" filesep "dir.m"]); %! unwind_protect_cleanup %! if (isguirunning ()) -%! __octave_link_gui_preference__ ("editor/show_dbg_file", orig_show_dbg); +%! __event_manager_gui_preference__ ("editor/show_dbg_file", orig_show_dbg); %! endif %! end_unwind_protect */
--- a/libinterp/corefcn/dirfns.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/dirfns.cc Thu Jul 18 11:23:22 2019 -0400 @@ -47,10 +47,10 @@ #include "dirfns.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" #include "input.h" #include "load-path.h" #include "octave.h" -#include "octave-link.h" #include "ovl.h" #include "pager.h" #include "procstream.h" @@ -90,9 +90,9 @@ lp.update (); - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); - olnk.change_directory (octave::sys::env::get_current_directory ()); + evmgr.change_directory (octave::sys::env::get_current_directory ()); return cd_ok; } @@ -284,7 +284,7 @@ int status = -1; std::string msg; - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); if (nargin == 2) { @@ -306,17 +306,17 @@ if (doit) { - olnk.file_remove (fulldir, ""); + evmgr.file_remove (fulldir, ""); status = octave::sys::recursive_rmdir (fulldir, msg); } } else { - olnk.file_remove (fulldir, ""); + evmgr.file_remove (fulldir, ""); status = octave::sys::rmdir (fulldir, msg); } - olnk.file_renamed (status >= 0); + evmgr.file_renamed (status >= 0); if (status < 0) return ovl (false, msg, "rmdir"); @@ -439,20 +439,20 @@ std::string msg; - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); - olnk.file_remove (from, to); + evmgr.file_remove (from, to); int status = octave::sys::rename (from, to, msg); if (status < 0) { - olnk.file_renamed (false); + evmgr.file_renamed (false); return ovl (-1.0, msg); } else { - olnk.file_renamed (true); + evmgr.file_renamed (true); return ovl (status, ""); } }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/event-manager.cc Thu Jul 18 11:23:22 2019 -0400 @@ -0,0 +1,564 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid +Copyright (C) 2011-2019 John P. Swensen + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<https://www.gnu.org/licenses/>. + +*/ + +#if defined (HAVE_CONFIG_H) +# include "config.h" +#endif + +#include "builtin-defun-decls.h" +#include "cmd-edit.h" +#include "defun.h" +#include "event-manager.h" +#include "interpreter.h" +#include "interpreter-private.h" +#include "oct-env.h" +#include "oct-mutex.h" +#include "ovl.h" +#include "pager.h" +#include "syminfo.h" + +namespace octave +{ + static int readline_event_hook (void) + { + event_manager& evmgr = __get_event_manager__ ("octave_readline_hook"); + + evmgr.process_events (); + + return 0; + } + + event_manager::event_manager (void) + : instance (nullptr), event_queue_mutex (new mutex ()), + gui_event_queue (), debugging (false), link_enabled (false) + { + command_editor::add_event_hook (readline_event_hook); + } + + event_manager::~event_manager (void) + { + delete event_queue_mutex; + } + + // Programming Note: It is possible to disable the link without deleting + // the connection. This allows it to be temporarily disabled. But if + // the link is removed, we also set the link_enabled flag to false + // because if there is no link, it can't be enabled. Also, access to + // instance is only protected by a check on the link_enabled flag. + + void + event_manager::connect_link (const std::shared_ptr<interpreter_events>& obj) + { + if (! obj) + disable (); + + instance = obj; + } + + bool event_manager::enable (void) + { + bool retval = link_enabled; + + if (instance) + link_enabled = true; + else + warning ("event_manager: must have connected link to enable"); + + return retval; + } + + void event_manager::process_events (bool disable_flag) + { + if (enabled ()) + { + if (disable_flag) + disable (); + + event_queue_mutex->lock (); + + gui_event_queue.run (); + + event_queue_mutex->unlock (); + } + } + + void event_manager::discard_events (void) + { + if (enabled ()) + { + event_queue_mutex->lock (); + + gui_event_queue.discard (); + + event_queue_mutex->unlock (); + } + } + + void event_manager::set_workspace (void) + { + if (enabled ()) + { + tree_evaluator& tw + = __get_evaluator__ ("event_manager::set_workspace"); + + instance->do_set_workspace (tw.at_top_level (), debugging, + tw.get_symbol_info (), true); + } + } +} + +DEFMETHOD (__event_manager_enabled__, interp, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_enabled__ () +Undocumented internal function. +@end deftypefn */) +{ + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.enabled ()); +} + +DEFMETHOD (__event_manager_edit_file__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_edit_file__ (@var{file}) +Undocumented internal function. +@end deftypefn */) +{ + octave_value retval; + + octave::event_manager& evmgr = interp.get_event_manager (); + + if (args.length () == 1) + { + std::string file = args(0).xstring_value ("first argument must be filename"); + + octave::flush_stdout (); + + retval = evmgr.edit_file (file); + } + else if (args.length () == 2) + { + std::string file = args(0).xstring_value ("first argument must be filename"); + + octave::flush_stdout (); + + retval = evmgr.prompt_new_edit_file (file); + } + + return retval; +} + +DEFMETHOD (__event_manager_question_dialog__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_question_dialog__ (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default}) +Undocumented internal function. +@end deftypefn */) +{ + octave_value retval; + + if (args.length () == 6) + { + std::string msg = args(0).xstring_value ("invalid arguments"); + std::string title = args(1).xstring_value ("invalid arguments"); + std::string btn1 = args(2).xstring_value ("invalid arguments"); + std::string btn2 = args(3).xstring_value ("invalid arguments"); + std::string btn3 = args(4).xstring_value ("invalid arguments"); + std::string btndef = args(5).xstring_value ("invalid arguments"); + + octave::flush_stdout (); + + octave::event_manager& evmgr = interp.get_event_manager (); + + retval = evmgr.question_dialog (msg, title, btn1, btn2, btn3, btndef); + } + + return retval; +} + +DEFMETHOD (__event_manager_file_dialog__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_file_dialog__ (@var{filterlist}, @var{title}, @var{filename}, @var{size} @var{multiselect}, @var{pathname}) +Undocumented internal function. +@end deftypefn */) +{ + if (args.length () != 6) + return ovl (); + + octave_value_list retval (3); + + const Array<std::string> flist = args(0).cellstr_value (); + std::string title = args(1).string_value (); + std::string filename = args(2).string_value (); + Matrix pos = args(3).matrix_value (); + std::string multi_on = args(4).string_value (); // on, off, create + std::string pathname = args(5).string_value (); + + octave_idx_type nel; + + octave::event_manager::filter_list filter_lst; + + for (octave_idx_type i = 0; i < flist.rows (); i++) + filter_lst.push_back (std::make_pair (flist(i,0), + (flist.columns () > 1 + ? flist(i,1) : ""))); + + octave::flush_stdout (); + + octave::event_manager& evmgr = interp.get_event_manager (); + + std::list<std::string> items_lst + = evmgr.file_dialog (filter_lst, title, filename, pathname, multi_on); + + nel = items_lst.size (); + + // If 3, then retval is filename, directory, and selected index. + if (nel <= 3) + { + if (items_lst.front ().empty ()) + retval = ovl (octave_value (0.), octave_value (0.), octave_value (0.)); + else + { + int idx = 0; + for (auto& str : items_lst) + { + if (idx != 2) + retval(idx++) = str; + else + retval(idx++) = atoi (str.c_str ()); + } + } + } + else + { + // Multiple files. + nel -= 2; + Cell items (dim_vector (1, nel)); + + auto it = items_lst.begin (); + + for (int idx = 0; idx < nel; idx++, it++) + items.xelem (idx) = *it; + + retval = ovl (items, *it++, atoi (it->c_str ())); + } + + return retval; +} + +DEFMETHOD (__event_manager_list_dialog__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_list_dialog__ (@var{list}, @var{mode}, @var{size}, @var{initial}, @var{name}, @var{prompt}, @var{ok_string}, @var{cancel_string}) +Undocumented internal function. +@end deftypefn */) +{ + if (args.length () != 8) + return ovl (); + + Cell list = args(0).cell_value (); + const Array<std::string> tlist = list.cellstr_value (); + octave_idx_type nel = tlist.numel (); + std::list<std::string> list_lst; + for (octave_idx_type i = 0; i < nel; i++) + list_lst.push_back (tlist(i)); + + std::string mode = args(1).string_value (); + + Matrix size_matrix = args(2).matrix_value (); + int width = size_matrix(0); + int height = size_matrix(1); + + Matrix initial_matrix = args(3).matrix_value (); + nel = initial_matrix.numel (); + std::list<int> initial_lst; + for (octave_idx_type i = 0; i < nel; i++) + initial_lst.push_back (initial_matrix(i)); + + std::string name = args(4).string_value (); + list = args(5).cell_value (); + const Array<std::string> plist = list.cellstr_value (); + nel = plist.numel (); + std::list<std::string> prompt_lst; + for (octave_idx_type i = 0; i < nel; i++) + prompt_lst.push_back (plist(i)); + std::string ok_string = args(6).string_value (); + std::string cancel_string = args(7).string_value (); + + octave::flush_stdout (); + + octave::event_manager& evmgr = interp.get_event_manager (); + + std::pair<std::list<int>, int> result + = evmgr.list_dialog (list_lst, mode, width, height, initial_lst, + name, prompt_lst, ok_string, cancel_string); + + std::list<int> items_lst = result.first; + nel = items_lst.size (); + Matrix items (dim_vector (1, nel)); + octave_idx_type i = 0; + for (const auto& int_el : items_lst) + items.xelem(i++) = int_el; + + return ovl (items, result.second); +} + +DEFMETHOD (__event_manager_input_dialog__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_input_dialog__ (@var{prompt}, @var{title}, @var{rowscols}, @var{defaults}) +Undocumented internal function. +@end deftypefn */) +{ + if (args.length () != 4) + return ovl (); + + Cell prompt = args(0).cell_value (); + Array<std::string> tmp = prompt.cellstr_value (); + octave_idx_type nel = tmp.numel (); + std::list<std::string> prompt_lst; + for (octave_idx_type i = 0; i < nel; i++) + prompt_lst.push_back (tmp(i)); + + std::string title = args(1).string_value (); + + Matrix rc = args(2).matrix_value (); + nel = rc.rows (); + std::list<float> nr; + std::list<float> nc; + for (octave_idx_type i = 0; i < nel; i++) + { + nr.push_back (rc(i,0)); + nc.push_back (rc(i,1)); + } + + Cell defaults = args(3).cell_value (); + tmp = defaults.cellstr_value (); + nel = tmp.numel (); + std::list<std::string> defaults_lst; + for (octave_idx_type i = 0; i < nel; i++) + defaults_lst.push_back (tmp(i)); + + octave::flush_stdout (); + + octave::event_manager& evmgr = interp.get_event_manager (); + + std::list<std::string> items_lst + = evmgr.input_dialog (prompt_lst, title, nr, nc, defaults_lst); + + nel = items_lst.size (); + Cell items (dim_vector (nel, 1)); + octave_idx_type i = 0; + for (const auto& str_el : items_lst) + items.xelem(i++) = str_el; + + return ovl (items); +} + + +DEFMETHOD (__event_manager_named_icon__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_dialog_icons__ (@var{icon_name}) +Undocumented internal function. +@end deftypefn */) +{ + uint8NDArray retval; + + if (args.length () > 0) + { + std::string icon_name = args(0).xstring_value ("invalid arguments"); + + octave::event_manager& evmgr = interp.get_event_manager (); + + retval = evmgr.get_named_icon (icon_name); + } + + return ovl (retval); +} + +DEFMETHOD (__event_manager_show_preferences__, interp, , , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_show_preferences__ () +Undocumented internal function. +@end deftypefn */) +{ + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.show_preferences ()); +} + +DEFMETHOD (__event_manager_gui_preference__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_gui_preference__ () +Undocumented internal function. +@end deftypefn */) +{ + std::string key; + std::string value = ""; + + if (args.length () >= 1) + key = args(0).string_value(); + else + error ("__event_manager_gui_preference__: " + "first argument must be the preference key"); + + if (args.length () >= 2) + value = args(1).string_value(); + + if (octave::application::is_gui_running ()) + { + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.gui_preference (key, value)); + } + else + return ovl (value); +} + +DEFMETHOD (__event_manager_file_remove__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_file_remove__ () +Undocumented internal function. +@end deftypefn */) +{ + std::string old_name, new_name; + + if (args.length () == 2) + { + old_name = args(0).string_value(); + new_name = args(1).string_value(); + } + else + error ("__event_manager_file_remove__: " + "old and new name expected as arguments"); + + octave::event_manager& evmgr = interp.get_event_manager (); + + evmgr.file_remove (old_name, new_name); + + return ovl (); +} + +DEFMETHOD (__event_manager_file_renamed__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_file_renamed__ () +Undocumented internal function. +@end deftypefn */) +{ + bool load_new; + + if (args.length () == 1) + load_new = args(0).bool_value(); + else + error ("__event_manager_file_renamed__: " + "first argument must be boolean for reload new named file"); + + octave::event_manager& evmgr = interp.get_event_manager (); + + evmgr.file_renamed (load_new); + + return ovl (); +} + +DEFMETHOD (openvar, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} openvar (@var{name}) +Open the variable @var{name} in the graphical Variable Editor. +@end deftypefn */) +{ + if (args.length () != 1) + print_usage (); + + if (! args(0).is_string ()) + error ("openvar: NAME must be a string"); + + std::string name = args(0).string_value (); + + if (! (Fisguirunning ())(0).is_true ()) + warning ("openvar: GUI is not running, can't start Variable Editor"); + else + { + octave_value val = interp.varval (name); + + if (val.is_undefined ()) + error ("openvar: '%s' is not a variable", name.c_str ()); + + octave::event_manager& evmgr = interp.get_event_manager (); + + evmgr.edit_variable (name, val); + } + + return ovl (); +} + +/* +%!error openvar () +%!error openvar ("a", "b") +%!error <NAME must be a string> openvar (1:10) +*/ + +DEFMETHOD (__event_manager_show_doc__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_show_doc__ (@var{filename}) +Undocumented internal function. +@end deftypefn */) +{ + std::string file; + + if (args.length () >= 1) + file = args(0).string_value(); + + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.show_doc (file)); +} + +DEFMETHOD (__event_manager_register_doc__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_register_doc__ (@var{filename}) +Undocumented internal function. +@end deftypefn */) +{ + std::string file; + + if (args.length () >= 1) + file = args(0).string_value(); + + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.register_doc (file)); +} + +DEFMETHOD (__event_manager_unregister_doc__, interp, args, , + doc: /* -*- texinfo -*- +@deftypefn {} {} __event_manager_unregister_doc__ (@var{filename}) +Undocumented internal function. +@end deftypefn */) +{ + std::string file; + + if (args.length () >= 1) + file = args(0).string_value(); + + octave::event_manager& evmgr = interp.get_event_manager (); + + return ovl (evmgr.unregister_doc (file)); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/libinterp/corefcn/event-manager.h Thu Jul 18 11:23:22 2019 -0400 @@ -0,0 +1,548 @@ +/* + +Copyright (C) 2013-2019 John W. Eaton +Copyright (C) 2011-2019 Jacob Dawid +Copyright (C) 2011-2019 John P. Swensen + +This file is part of Octave. + +Octave is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License as published by +the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +Octave is distributed in the hope that it will be useful, but +WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with Octave; see the file COPYING. If not, see +<https://www.gnu.org/licenses/>. + +*/ + +#if ! defined (octave_event_manager_h) +#define octave_event_manager_h 1 + +#include "octave-config.h" + +#include <list> +#include <memory> +#include <string> + +#include "oct-mutex.h" +#include "octave.h" +#include "event-queue.h" +#include "uint8NDArray.h" + +class octave_value; +class string_vector; + +namespace octave +{ + class symbol_info_list; + + class interpreter_events + { + public: + + interpreter_events (void) = default; + + interpreter_events (const interpreter_events&) = default; + + interpreter_events& operator = (const interpreter_events&) = default; + + virtual ~interpreter_events (void) = default; + + virtual bool do_confirm_shutdown (void) { return false; } + + virtual bool do_copy_image_to_clipboard (const std::string& /*file*/) + { + return false; + } + + virtual bool do_edit_file (const std::string& /*file*/) { return false; } + + virtual bool do_prompt_new_edit_file (const std::string& /*file*/) + { + return false; + } + + virtual std::string + do_question_dialog (const std::string& /*msg*/, + const std::string& /*title*/, + const std::string& /*btn1*/, + const std::string& /*btn2*/, + const std::string& /*btn3*/, + const std::string& /*btndef*/) + { + return ""; + } + + virtual std::pair<std::list<int>, int> + do_list_dialog (const std::list<std::string>& /*list*/, + const std::string& /*mode*/, + int /*width*/, int /*height*/, + const std::list<int>& /*initial_value*/, + const std::string& /*name*/, + const std::list<std::string>& /*prompt*/, + const std::string& /*ok_string*/, + const std::string& /*cancel_string*/) + { + return std::pair<std::list<int>, int> (); + } + + virtual std::list<std::string> + do_input_dialog (const std::list<std::string>& /*prompt*/, + const std::string& /*title*/, + const std::list<float>& /*nr*/, + const std::list<float>& /*nc*/, + const std::list<std::string>& /*defaults*/) + { + return std::list<std::string> (); + } + + typedef std::list<std::pair<std::string, std::string>> filter_list; + + virtual std::list<std::string> + do_file_dialog (const filter_list& /*filter*/, + const std::string& /*title*/, + const std::string& /*filename*/, + const std::string& /*dirname*/, + const std::string& /*multimode*/) + { + return std::list<std::string> (); + } + + virtual int + do_debug_cd_or_addpath_error (const std::string& /*file*/, + const std::string& /*dir*/, + bool /*addpath_option*/) + { + return -1; + } + + virtual void do_change_directory (const std::string& /*dir*/) { } + + virtual void do_file_remove (const std::string& /*old_name*/, + const std::string& /*new_name*/) + { } + + virtual void do_file_renamed (bool) { } + + virtual void + do_execute_command_in_terminal (const std::string& /*command*/) { } + + virtual uint8NDArray do_get_named_icon (const std::string& /*icon_name*/) + { + return uint8NDArray (); + } + + virtual void do_set_workspace (bool /*top_level*/, bool /*debug*/, + const octave::symbol_info_list& /*syminfo*/, + bool /*update_variable_editor*/) + { } + + virtual void do_clear_workspace (void) { } + + virtual void do_set_history (const string_vector& /*hist*/) { } + + virtual void do_append_history (const std::string& /*hist_entry*/) { } + + virtual void do_clear_history (void) { } + + virtual void do_pre_input_event (void) { } + + virtual void do_post_input_event (void) { } + + virtual void + do_enter_debugger_event (const std::string& /*file*/, int /*line*/) { } + + virtual void + do_execute_in_debugger_event (const std::string& /*file*/, int /*line*/) { } + + virtual void do_exit_debugger_event (void) { } + + virtual void do_update_breakpoint (bool /*insert*/, + const std::string& /*file*/, + int /*line*/, const std::string& /*cond*/) + { } + + virtual void do_show_preferences (void) { } + + virtual std::string do_gui_preference (const std::string& /*key*/, + const std::string& /*value*/) + { + return ""; + } + + virtual void do_show_doc (const std::string& /*file*/) { } + + virtual void do_register_doc (const std::string& /*file*/) { } + + virtual void do_unregister_doc (const std::string& /*file*/) { } + + virtual void do_edit_variable (const std::string& /*name*/, + const octave_value& /*val*/) + { } + }; + + //! Provides threadsafe access to octave. + //! @author Jacob Dawid + //! + //! This class is a wrapper around octave and provides thread safety by + //! buffering access operations to octave and executing them in the + //! readline event hook, which lives in the octave thread. + + class + OCTINTERP_API + event_manager + { + public: + + event_manager (void); + + // No copying! + + event_manager (const event_manager&) = delete; + + event_manager& + operator = (const event_manager&) = delete; + + virtual ~event_manager (void); + + // OBJ should be an object of a class that is derived from the base + // class interpreter_events, or nullptr to disconnect and delete the + // previous link. + + void connect_link (const std::shared_ptr<interpreter_events>& obj); + + bool enable (void); + + bool disable (void) + { + bool retval = link_enabled; + link_enabled = false; + return retval; + } + + bool enabled (void) const + { + return link_enabled; + } + + // If disable is TRUE, then no additional events will be processed + // other than exit. + + void process_events (bool disable = false); + + void discard_events (void); + + bool confirm_shutdown (void) + { + bool retval = true; + + if (enabled ()) + retval = instance->do_confirm_shutdown (); + + return retval; + } + + template <typename F, typename... Args> + void post_event (F&& fcn, Args&&... args) + { + if (enabled ()) + gui_event_queue.add (fcn, std::forward<Args> (args)...); + } + + template <typename T, typename... Params, typename... Args> + void post_event (T *obj, void (T::*method) (Params...), Args&&... args) + { + if (enabled ()) + gui_event_queue.add_method (obj, method, std::forward<Args> (args)...); + } + + void post_exception (const std::exception_ptr& p) + { + if (enabled ()) + post_event (this, &event_manager::rethrow_exception_callback, p); + } + + bool copy_image_to_clipboard (const std::string& file) + { + return enabled () ? instance->do_copy_image_to_clipboard (file) : false; + } + + bool edit_file (const std::string& file) + { + return enabled () ? instance->do_edit_file (file) : false; + } + + bool prompt_new_edit_file (const std::string& file) + { + return enabled () ? instance->do_prompt_new_edit_file (file) : false; + } + + std::string + question_dialog (const std::string& msg, const std::string& title, + const std::string& btn1, const std::string& btn2, + const std::string& btn3, const std::string& btndef) + { + return enabled () ? instance->do_question_dialog (msg, title, btn1, + btn2, btn3, btndef) : ""; + } + + std::pair<std::list<int>, int> + list_dialog (const std::list<std::string>& list, + const std::string& mode, + int width, int height, + const std::list<int>& initial_value, + const std::string& name, + const std::list<std::string>& prompt, + const std::string& ok_string, + const std::string& cancel_string) + { + return (enabled () + ? instance->do_list_dialog (list, mode, width, height, + initial_value, name, prompt, + ok_string, cancel_string) + : std::pair<std::list<int>, int> ()); + } + + std::list<std::string> + input_dialog (const std::list<std::string>& prompt, + const std::string& title, + const std::list<float>& nr, + const std::list<float>& nc, + const std::list<std::string>& defaults) + { + return (enabled () + ? instance->do_input_dialog (prompt, title, nr, nc, defaults) + : std::list<std::string> ()); + } + + typedef std::list<std::pair<std::string, std::string>> filter_list; + + std::list<std::string> + file_dialog (const filter_list& filter, const std::string& title, + const std::string& filename, const std::string& dirname, + const std::string& multimode) + { + return (enabled () + ? instance->do_file_dialog (filter, title, filename, dirname, + multimode) + : std::list<std::string> ()); + } + + int debug_cd_or_addpath_error (const std::string& file, + const std::string& dir, bool addpath_option) + { + return (enabled () + ? instance->do_debug_cd_or_addpath_error (file, dir, addpath_option) + : 0); + } + + void change_directory (const std::string& dir) + { + if (enabled ()) + instance->do_change_directory (dir); + } + + // Methods for removing/renaming files which might be open in editor + void file_remove (const std::string& old_name, const std::string& new_name) + { + if (octave::application::is_gui_running () && enabled ()) + instance->do_file_remove (old_name, new_name); + } + + void file_renamed (bool load_new) + { + if (octave::application::is_gui_running () && enabled ()) + instance->do_file_renamed (load_new); + } + + // Preserves pending input. + void execute_command_in_terminal (const std::string& command) + { + if (enabled ()) + instance->do_execute_command_in_terminal (command); + } + + uint8NDArray get_named_icon (const std::string& icon_name) + { + return (enabled () ? + instance->do_get_named_icon (icon_name) : uint8NDArray ()); + } + + void set_workspace (void); + + void set_workspace (bool top_level, const octave::symbol_info_list& syminfo, + bool update_variable_editor = true) + { + if (enabled ()) + instance->do_set_workspace (top_level, debugging, syminfo, + update_variable_editor); + } + + void clear_workspace (void) + { + if (enabled ()) + instance->do_clear_workspace (); + } + + void set_history (const string_vector& hist) + { + if (enabled ()) + instance->do_set_history (hist); + } + + void append_history (const std::string& hist_entry) + { + if (enabled ()) + instance->do_append_history (hist_entry); + } + + void clear_history (void) + { + if (enabled ()) + instance->do_clear_history (); + } + + void pre_input_event (void) + { + if (enabled ()) + instance->do_pre_input_event (); + } + + void post_input_event (void) + { + if (enabled ()) + instance->do_post_input_event (); + } + + void enter_debugger_event (const std::string& file, int line) + { + if (enabled ()) + { + debugging = true; + + instance->do_enter_debugger_event (file, line); + } + } + + void execute_in_debugger_event (const std::string& file, int line) + { + if (enabled ()) + instance->do_execute_in_debugger_event (file, line); + } + + void exit_debugger_event (void) + { + if (enabled () && debugging) + { + debugging = false; + + instance->do_exit_debugger_event (); + } + } + + void update_breakpoint (bool insert, const std::string& file, + int line, const std::string& cond = "") + { + if (enabled ()) + instance->do_update_breakpoint (insert, file, line, cond); + } + + bool show_preferences (void) + { + if (enabled ()) + { + instance->do_show_preferences (); + return true; + } + else + return false; + } + + std::string gui_preference (const std::string& key, const std::string& value) + { + if (enabled ()) + { + return instance->do_gui_preference (key, value); + } + else + return ""; + } + + bool show_doc (const std::string& file) + { + if (enabled ()) + { + instance->do_show_doc (file); + return true; + } + else + return false; + } + + bool register_doc (const std::string& file) + { + if (enabled ()) + { + instance->do_register_doc (file); + return true; + } + else + return false; + } + + bool unregister_doc (const std::string& file) + { + if (enabled ()) + { + instance->do_unregister_doc (file); + return true; + } + else + return false; + + } + + bool edit_variable (const std::string& name, const octave_value& val) + { + if (enabled ()) + { + instance->do_edit_variable (name, val); + return true; + } + else + return false; + } + + private: + + // Using a shared_ptr to manage the link_events object ensures that it + // will be valid until it is no longer needed. + + std::shared_ptr<interpreter_events> instance; + + protected: + + // Semaphore to lock access to the event queue. + octave::mutex *event_queue_mutex; + + // Event Queue. + octave::event_queue gui_event_queue; + + bool debugging; + bool link_enabled; + + void rethrow_exception_callback (const std::exception_ptr& p) + { + std::rethrow_exception (p); + } + }; +} + +#endif
--- a/libinterp/corefcn/input.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/input.cc Thu Jul 18 11:23:22 2019 -0400 @@ -48,6 +48,7 @@ #include "dirfns.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" #include "help.h" #include "hook-fcn.h" #include "input.h" @@ -56,11 +57,10 @@ #include "lex.h" #include "load-path.h" #include "octave.h" -#include "octave-link.h" #include "oct-map.h" #include "oct-hist.h" #include "interpreter.h" -#include "octave-link.h" +#include "event-manager.h" #include "ovl.h" #include "ov-fcn-handle.h" #include "ov-usr-fcn.h" @@ -522,7 +522,7 @@ } // Synchronize the related gui preference for editor encoding - feval ("__octave_link_gui_preference__", + feval ("__event_manager_gui_preference__", ovl ("editor/default_encoding", m_mfile_encoding)); return retval; @@ -706,16 +706,16 @@ tree_evaluator& tw = interp.get_evaluator (); - octave_link& olnk = interp.get_octave_link (); + event_manager& evmgr = interp.get_event_manager (); if (application::interactive ()) { if (! tw.in_debug_repl ()) - olnk.exit_debugger_event (); + evmgr.exit_debugger_event (); - olnk.pre_input_event (); + evmgr.pre_input_event (); - olnk.set_workspace (); + evmgr.set_workspace (); } bool history_skip_auto_repeated_debugging_command = false; @@ -761,7 +761,7 @@ if (! history_skip_auto_repeated_debugging_command) { if (command_history::add (retval)) - olnk.append_history (retval); + evmgr.append_history (retval); } octave_diary << retval; @@ -776,7 +776,7 @@ // list has been updated. if (application::interactive ()) - olnk.post_input_event (); + evmgr.post_input_event (); return retval; }
--- a/libinterp/corefcn/interpreter-private.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/interpreter-private.cc Thu Jul 18 11:23:22 2019 -0400 @@ -31,6 +31,7 @@ #include "cdef-manager.h" #include "child-list.h" #include "error.h" +#include "event-manager.h" #include "gtk-manager.h" #include "help.h" #include "input.h" @@ -39,7 +40,6 @@ #include "load-path.h" #include "load-save.h" #include "oct-hist.h" -#include "octave-link.h" #include "ov.h" #include "ov-fcn-inline.h" #include "pager.h" @@ -116,11 +116,11 @@ return interp.get_load_save_system (); } - octave_link& __get_octave_link__ (const std::string& who) + event_manager& __get_event_manager__ (const std::string& who) { interpreter& interp = __get_interpreter__ (who); - return interp.get_octave_link (); + return interp.get_event_manager (); } type_info& __get_type_info__ (const std::string& who)
--- a/libinterp/corefcn/interpreter-private.h Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/interpreter-private.h Thu Jul 18 11:23:22 2019 -0400 @@ -30,8 +30,6 @@ #include "symtab.h" -class octave_link; - namespace octave { class bp_table; @@ -39,6 +37,7 @@ class child_list; class dynamic_loader; class error_system; + class event_manager; class gtk_manager; class help_system; class history_system; @@ -66,7 +65,7 @@ extern load_save_system& __get_load_save_system__ (const std::string& who); - extern octave_link& __get_octave_link__ (const std::string& who); + extern event_manager& __get_event_manager__ (const std::string& who); extern output_system& __get_output_system__ (const std::string& who);
--- a/libinterp/corefcn/interpreter.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/interpreter.cc Thu Jul 18 11:23:22 2019 -0400 @@ -46,6 +46,7 @@ #include "defun.h" #include "display.h" #include "error.h" +#include "event-manager.h" #include "file-io.h" #include "graphics.h" #include "help.h" @@ -54,7 +55,6 @@ #include "interpreter.h" #include "load-path.h" #include "load-save.h" -#include "octave-link.h" #include "octave.h" #include "oct-hist.h" #include "oct-map.h" @@ -151,9 +151,9 @@ // to overriding polymorphism for which the GUI can install its own "quit" // yet call this base "quit" could be nice. No link would be needed here. - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); - if (! olnk.confirm_shutdown ()) + if (! evmgr.confirm_shutdown ()) return ovl (); if (! quit_allowed) @@ -380,7 +380,7 @@ m_url_handle_manager (), m_cdef_manager (*this), m_gtk_manager (), - m_octave_link (), + m_event_manager (), m_interactive (false), m_read_site_files (true), m_read_init_files (m_app_context != nullptr), @@ -1021,8 +1021,8 @@ // If we are attached to a GUI, process pending events and // disable the link. - m_octave_link.process_events (true); - m_octave_link.disable (); + m_event_manager.process_events (true); + m_event_manager.disable (); OCTAVE_SAFE_CALL (m_input_system.clear_input_event_hooks, ());
--- a/libinterp/corefcn/interpreter.h Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/interpreter.h Thu Jul 18 11:23:22 2019 -0400 @@ -36,6 +36,7 @@ #include "dynamic-ld.h" #include "environment.h" #include "error.h" +#include "event-manager.h" #include "gtk-manager.h" #include "help.h" #include "input.h" @@ -43,7 +44,6 @@ #include "load-save.h" #include "oct-hist.h" #include "oct-stream.h" -#include "octave-link.h" #include "ov-typeinfo.h" #include "pager.h" #include "pt-eval.h" @@ -238,9 +238,9 @@ return m_gtk_manager; } - octave_link& get_octave_link (void) + event_manager& get_event_manager (void) { - return m_octave_link; + return m_event_manager; } void mlock (void); @@ -455,7 +455,7 @@ gtk_manager m_gtk_manager; - octave_link m_octave_link; + event_manager m_event_manager; // TRUE means this is an interactive interpreter (forced or not). bool m_interactive;
--- a/libinterp/corefcn/module.mk Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/module.mk Thu Jul 18 11:23:22 2019 -0400 @@ -33,6 +33,7 @@ %reldir%/environment.h \ %reldir%/error.h \ %reldir%/errwarn.h \ + %reldir%/event-manager.h \ %reldir%/event-queue.h \ %reldir%/fcn-info.h \ %reldir%/file-io.h \ @@ -74,7 +75,6 @@ %reldir%/oct-strstrm.h \ %reldir%/oct.h \ %reldir%/octave-default-image.h \ - %reldir%/octave-link.h \ %reldir%/pager.h \ %reldir%/pr-flt-fmt.h \ %reldir%/pr-output.h \ @@ -153,6 +153,7 @@ %reldir%/environment.cc \ %reldir%/error.cc \ %reldir%/errwarn.cc \ + %reldir%/event-manager.cc \ %reldir%/event-queue.cc \ %reldir%/fcn-info.cc \ %reldir%/fft.cc \ @@ -215,7 +216,6 @@ %reldir%/oct-tex-lexer.ll \ %reldir%/oct-tex-parser.h \ %reldir%/oct-tex-parser.yy \ - %reldir%/octave-link.cc \ %reldir%/ordschur.cc \ %reldir%/pager.cc \ %reldir%/pinv.cc \
--- a/libinterp/corefcn/oct-hist.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/oct-hist.cc Thu Jul 18 11:23:22 2019 -0400 @@ -44,7 +44,6 @@ #include "cmd-hist.h" #include "file-ops.h" #include "lo-mappers.h" -#include "octave-link.h" #include "oct-env.h" #include "oct-time.h" #include "str-vec.h" @@ -53,6 +52,7 @@ #include "defun.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" #include "input.h" #include "oct-hist.h" #include "ovl.h" @@ -138,10 +138,10 @@ { if (command_history::add (tmp)) { - octave_link& olnk - = __get_octave_link__ ("edit_history_add_hist"); + event_manager& evmgr + = __get_event_manager__ ("edit_history_add_hist"); - olnk.append_history (tmp); + evmgr.append_history (tmp); } } } @@ -274,9 +274,9 @@ default_size (), sys::env::getenv ("OCTAVE_HISTCONTROL")); - octave_link& olnk = m_interpreter.get_octave_link (); + event_manager& evmgr = m_interpreter.get_event_manager (); - olnk.set_history (command_history::list ()); + evmgr.set_history (command_history::list ()); } void history_system::write_timestamp (void) @@ -289,9 +289,9 @@ { if (command_history::add (timestamp)) { - octave_link& olnk = m_interpreter.get_octave_link (); + event_manager& evmgr = m_interpreter.get_event_manager (); - olnk.append_history (timestamp); + evmgr.append_history (timestamp); } } } @@ -352,7 +352,7 @@ else err_wrong_type_arg ("history", arg); - octave_link& olnk = m_interpreter.get_octave_link (); + event_manager& evmgr = m_interpreter.get_event_manager (); if (option == "-r" || option == "-w" || option == "-a" || option == "-n") @@ -380,14 +380,14 @@ { // Read entire file. command_history::read (); - olnk.set_history (command_history::list ()); + evmgr.set_history (command_history::list ()); } else if (option == "-n") { // Read 'new' history from file. command_history::read_range (); - olnk.set_history (command_history::list ()); + evmgr.set_history (command_history::list ()); } else @@ -398,7 +398,7 @@ else if (option == "-c") { command_history::clear (); - olnk.clear_history (); + evmgr.clear_history (); } else if (option == "-q") numbered_output = false;
--- a/libinterp/corefcn/octave-link.cc Thu Jul 18 09:58:41 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,566 +0,0 @@ -/* - -Copyright (C) 2013-2019 John W. Eaton -Copyright (C) 2011-2019 Jacob Dawid -Copyright (C) 2011-2019 John P. Swensen - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -#if defined (HAVE_CONFIG_H) -# include "config.h" -#endif - -#include "builtin-defun-decls.h" -#include "cmd-edit.h" -#include "defun.h" -#include "interpreter.h" -#include "interpreter-private.h" -#include "octave-link.h" -#include "oct-env.h" -#include "oct-mutex.h" -#include "ovl.h" -#include "pager.h" -#include "syminfo.h" - -static int -octave_readline_hook (void) -{ - octave_link& olnk = octave::__get_octave_link__ ("octave_readline_hook"); - - olnk.process_events (); - - return 0; -} - -octave_link::octave_link (void) - : instance (nullptr), event_queue_mutex (new octave::mutex ()), - gui_event_queue (), debugging (false), link_enabled (false) -{ - octave::command_editor::add_event_hook (octave_readline_hook); -} - -octave_link::~octave_link (void) -{ - delete event_queue_mutex; -} - -// Programming Note: It is possible to disable the link without deleting -// the connection. This allows it to be temporarily disabled. But if -// the link is removed, we also set the link_enabled flag to false -// because if there is no link, it can't be enabled. Also, access to -// instance is only protected by a check on the link_enabled flag. - -void -octave_link::connect_link (const std::shared_ptr<octave_link_events>& obj) -{ - if (! obj) - disable (); - - instance = obj; -} - -bool -octave_link::enable (void) -{ - bool retval = link_enabled; - - if (instance) - link_enabled = true; - else - warning ("octave_link: must have connected link to enable"); - - return retval; -} - -void -octave_link::process_events (bool disable_flag) -{ - if (enabled ()) - { - if (disable_flag) - disable (); - - event_queue_mutex->lock (); - - gui_event_queue.run (); - - event_queue_mutex->unlock (); - } -} - -void -octave_link::discard_events (void) -{ - if (enabled ()) - { - event_queue_mutex->lock (); - - gui_event_queue.discard (); - - event_queue_mutex->unlock (); - } -} - -void -octave_link::set_workspace (void) -{ - if (enabled ()) - { - octave::tree_evaluator& tw - = octave::__get_evaluator__ ("octave_link::set_workspace"); - - instance->do_set_workspace (tw.at_top_level (), debugging, - tw.get_symbol_info (), true); - } -} - -DEFMETHOD (__octave_link_enabled__, interp, , , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_enabled__ () -Undocumented internal function. -@end deftypefn */) -{ - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.enabled ()); -} - -DEFMETHOD (__octave_link_edit_file__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_edit_file__ (@var{file}) -Undocumented internal function. -@end deftypefn */) -{ - octave_value retval; - - octave_link& olnk = interp.get_octave_link (); - - if (args.length () == 1) - { - std::string file = args(0).xstring_value ("first argument must be filename"); - - octave::flush_stdout (); - - retval = olnk.edit_file (file); - } - else if (args.length () == 2) - { - std::string file = args(0).xstring_value ("first argument must be filename"); - - octave::flush_stdout (); - - retval = olnk.prompt_new_edit_file (file); - } - - return retval; -} - -DEFMETHOD (__octave_link_question_dialog__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_question_dialog__ (@var{msg}, @var{title}, @var{btn1}, @var{btn2}, @var{btn3}, @var{default}) -Undocumented internal function. -@end deftypefn */) -{ - octave_value retval; - - if (args.length () == 6) - { - std::string msg = args(0).xstring_value ("invalid arguments"); - std::string title = args(1).xstring_value ("invalid arguments"); - std::string btn1 = args(2).xstring_value ("invalid arguments"); - std::string btn2 = args(3).xstring_value ("invalid arguments"); - std::string btn3 = args(4).xstring_value ("invalid arguments"); - std::string btndef = args(5).xstring_value ("invalid arguments"); - - octave::flush_stdout (); - - octave_link& olnk = interp.get_octave_link (); - - retval = olnk.question_dialog (msg, title, btn1, btn2, btn3, btndef); - } - - return retval; -} - -DEFMETHOD (__octave_link_file_dialog__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_file_dialog__ (@var{filterlist}, @var{title}, @var{filename}, @var{size} @var{multiselect}, @var{pathname}) -Undocumented internal function. -@end deftypefn */) -{ - if (args.length () != 6) - return ovl (); - - octave_value_list retval (3); - - const Array<std::string> flist = args(0).cellstr_value (); - std::string title = args(1).string_value (); - std::string filename = args(2).string_value (); - Matrix pos = args(3).matrix_value (); - std::string multi_on = args(4).string_value (); // on, off, create - std::string pathname = args(5).string_value (); - - octave_idx_type nel; - - octave_link::filter_list filter_lst; - - for (octave_idx_type i = 0; i < flist.rows (); i++) - filter_lst.push_back (std::make_pair (flist(i,0), - (flist.columns () > 1 - ? flist(i,1) : ""))); - - octave::flush_stdout (); - - octave_link& olnk = interp.get_octave_link (); - - std::list<std::string> items_lst - = olnk.file_dialog (filter_lst, title, filename, pathname, multi_on); - - nel = items_lst.size (); - - // If 3, then retval is filename, directory, and selected index. - if (nel <= 3) - { - if (items_lst.front ().empty ()) - retval = ovl (octave_value (0.), octave_value (0.), octave_value (0.)); - else - { - int idx = 0; - for (auto& str : items_lst) - { - if (idx != 2) - retval(idx++) = str; - else - retval(idx++) = atoi (str.c_str ()); - } - } - } - else - { - // Multiple files. - nel -= 2; - Cell items (dim_vector (1, nel)); - - auto it = items_lst.begin (); - - for (int idx = 0; idx < nel; idx++, it++) - items.xelem (idx) = *it; - - retval = ovl (items, *it++, atoi (it->c_str ())); - } - - return retval; -} - -DEFMETHOD (__octave_link_list_dialog__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_list_dialog__ (@var{list}, @var{mode}, @var{size}, @var{initial}, @var{name}, @var{prompt}, @var{ok_string}, @var{cancel_string}) -Undocumented internal function. -@end deftypefn */) -{ - if (args.length () != 8) - return ovl (); - - Cell list = args(0).cell_value (); - const Array<std::string> tlist = list.cellstr_value (); - octave_idx_type nel = tlist.numel (); - std::list<std::string> list_lst; - for (octave_idx_type i = 0; i < nel; i++) - list_lst.push_back (tlist(i)); - - std::string mode = args(1).string_value (); - - Matrix size_matrix = args(2).matrix_value (); - int width = size_matrix(0); - int height = size_matrix(1); - - Matrix initial_matrix = args(3).matrix_value (); - nel = initial_matrix.numel (); - std::list<int> initial_lst; - for (octave_idx_type i = 0; i < nel; i++) - initial_lst.push_back (initial_matrix(i)); - - std::string name = args(4).string_value (); - list = args(5).cell_value (); - const Array<std::string> plist = list.cellstr_value (); - nel = plist.numel (); - std::list<std::string> prompt_lst; - for (octave_idx_type i = 0; i < nel; i++) - prompt_lst.push_back (plist(i)); - std::string ok_string = args(6).string_value (); - std::string cancel_string = args(7).string_value (); - - octave::flush_stdout (); - - octave_link& olnk = interp.get_octave_link (); - - std::pair<std::list<int>, int> result - = olnk.list_dialog (list_lst, mode, width, height, initial_lst, - name, prompt_lst, ok_string, cancel_string); - - std::list<int> items_lst = result.first; - nel = items_lst.size (); - Matrix items (dim_vector (1, nel)); - octave_idx_type i = 0; - for (const auto& int_el : items_lst) - items.xelem(i++) = int_el; - - return ovl (items, result.second); -} - -DEFMETHOD (__octave_link_input_dialog__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_input_dialog__ (@var{prompt}, @var{title}, @var{rowscols}, @var{defaults}) -Undocumented internal function. -@end deftypefn */) -{ - if (args.length () != 4) - return ovl (); - - Cell prompt = args(0).cell_value (); - Array<std::string> tmp = prompt.cellstr_value (); - octave_idx_type nel = tmp.numel (); - std::list<std::string> prompt_lst; - for (octave_idx_type i = 0; i < nel; i++) - prompt_lst.push_back (tmp(i)); - - std::string title = args(1).string_value (); - - Matrix rc = args(2).matrix_value (); - nel = rc.rows (); - std::list<float> nr; - std::list<float> nc; - for (octave_idx_type i = 0; i < nel; i++) - { - nr.push_back (rc(i,0)); - nc.push_back (rc(i,1)); - } - - Cell defaults = args(3).cell_value (); - tmp = defaults.cellstr_value (); - nel = tmp.numel (); - std::list<std::string> defaults_lst; - for (octave_idx_type i = 0; i < nel; i++) - defaults_lst.push_back (tmp(i)); - - octave::flush_stdout (); - - octave_link& olnk = interp.get_octave_link (); - - std::list<std::string> items_lst - = olnk.input_dialog (prompt_lst, title, nr, nc, defaults_lst); - - nel = items_lst.size (); - Cell items (dim_vector (nel, 1)); - octave_idx_type i = 0; - for (const auto& str_el : items_lst) - items.xelem(i++) = str_el; - - return ovl (items); -} - - -DEFMETHOD (__octave_link_named_icon__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_dialog_icons__ (@var{icon_name}) -Undocumented internal function. -@end deftypefn */) -{ - uint8NDArray retval; - - if (args.length () > 0) - { - std::string icon_name = args(0).xstring_value ("invalid arguments"); - - octave_link& olnk = interp.get_octave_link (); - - retval = olnk.get_named_icon (icon_name); - } - - return ovl (retval); -} - -DEFMETHOD (__octave_link_show_preferences__, interp, , , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_show_preferences__ () -Undocumented internal function. -@end deftypefn */) -{ - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.show_preferences ()); -} - -DEFMETHOD (__octave_link_gui_preference__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_gui_preference__ () -Undocumented internal function. -@end deftypefn */) -{ - std::string key; - std::string value = ""; - - if (args.length () >= 1) - key = args(0).string_value(); - else - error ("__octave_link_gui_preference__: " - "first argument must be the preference key"); - - if (args.length () >= 2) - value = args(1).string_value(); - - if (octave::application::is_gui_running ()) - { - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.gui_preference (key, value)); - } - else - return ovl (value); -} - -DEFMETHOD (__octave_link_file_remove__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_file_remove__ () -Undocumented internal function. -@end deftypefn */) -{ - std::string old_name, new_name; - - if (args.length () == 2) - { - old_name = args(0).string_value(); - new_name = args(1).string_value(); - } - else - error ("__octave_link_file_remove__: " - "old and new name expected as arguments"); - - octave_link& olnk = interp.get_octave_link (); - - olnk.file_remove (old_name, new_name); - - return ovl (); -} - -DEFMETHOD (__octave_link_file_renamed__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_file_renamed__ () -Undocumented internal function. -@end deftypefn */) -{ - bool load_new; - - if (args.length () == 1) - load_new = args(0).bool_value(); - else - error ("__octave_link_file_renamed__: " - "first argument must be boolean for reload new named file"); - - octave_link& olnk = interp.get_octave_link (); - - olnk.file_renamed (load_new); - - return ovl (); -} - -DEFMETHOD (openvar, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} openvar (@var{name}) -Open the variable @var{name} in the graphical Variable Editor. -@end deftypefn */) -{ - if (args.length () != 1) - print_usage (); - - if (! args(0).is_string ()) - error ("openvar: NAME must be a string"); - - std::string name = args(0).string_value (); - - if (! (Fisguirunning ())(0).is_true ()) - warning ("openvar: GUI is not running, can't start Variable Editor"); - else - { - octave_value val = interp.varval (name); - - if (val.is_undefined ()) - error ("openvar: '%s' is not a variable", name.c_str ()); - - octave_link& olnk = interp.get_octave_link (); - - olnk.edit_variable (name, val); - } - - return ovl (); -} - -/* -%!error openvar () -%!error openvar ("a", "b") -%!error <NAME must be a string> openvar (1:10) -*/ - -DEFMETHOD (__octave_link_show_doc__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_show_doc__ (@var{filename}) -Undocumented internal function. -@end deftypefn */) -{ - std::string file; - - if (args.length () >= 1) - file = args(0).string_value(); - - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.show_doc (file)); -} - -DEFMETHOD (__octave_link_register_doc__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_register_doc__ (@var{filename}) -Undocumented internal function. -@end deftypefn */) -{ - std::string file; - - if (args.length () >= 1) - file = args(0).string_value(); - - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.register_doc (file)); -} - -DEFMETHOD (__octave_link_unregister_doc__, interp, args, , - doc: /* -*- texinfo -*- -@deftypefn {} {} __octave_link_unregister_doc__ (@var{filename}) -Undocumented internal function. -@end deftypefn */) -{ - std::string file; - - if (args.length () >= 1) - file = args(0).string_value(); - - octave_link& olnk = interp.get_octave_link (); - - return ovl (olnk.unregister_doc (file)); -}
--- a/libinterp/corefcn/octave-link.h Thu Jul 18 09:58:41 2019 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,548 +0,0 @@ -/* - -Copyright (C) 2013-2019 John W. Eaton -Copyright (C) 2011-2019 Jacob Dawid -Copyright (C) 2011-2019 John P. Swensen - -This file is part of Octave. - -Octave is free software: you can redistribute it and/or modify it -under the terms of the GNU General Public License as published by -the Free Software Foundation, either version 3 of the License, or -(at your option) any later version. - -Octave is distributed in the hope that it will be useful, but -WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with Octave; see the file COPYING. If not, see -<https://www.gnu.org/licenses/>. - -*/ - -#if ! defined (octave_octave_link_h) -#define octave_octave_link_h 1 - -#include "octave-config.h" - -#include <list> -#include <memory> -#include <string> - -#include "oct-mutex.h" -#include "octave.h" -#include "event-queue.h" -#include "uint8NDArray.h" - -class octave_value; -class string_vector; - -namespace octave -{ - class symbol_info_list; -} - -class -octave_link_events -{ -public: - - octave_link_events (void) = default; - - octave_link_events (const octave_link_events&) = default; - - octave_link_events& operator = (const octave_link_events&) = default; - - virtual ~octave_link_events (void) = default; - - virtual bool do_confirm_shutdown (void) { return false; } - - virtual bool do_copy_image_to_clipboard (const std::string& /*file*/) - { - return false; - } - - virtual bool do_edit_file (const std::string& /*file*/) { return false; } - - virtual bool do_prompt_new_edit_file (const std::string& /*file*/) - { - return false; - } - - virtual std::string - do_question_dialog (const std::string& /*msg*/, - const std::string& /*title*/, - const std::string& /*btn1*/, - const std::string& /*btn2*/, - const std::string& /*btn3*/, - const std::string& /*btndef*/) - { - return ""; - } - - virtual std::pair<std::list<int>, int> - do_list_dialog (const std::list<std::string>& /*list*/, - const std::string& /*mode*/, - int /*width*/, int /*height*/, - const std::list<int>& /*initial_value*/, - const std::string& /*name*/, - const std::list<std::string>& /*prompt*/, - const std::string& /*ok_string*/, - const std::string& /*cancel_string*/) - { - return std::pair<std::list<int>, int> (); - } - - virtual std::list<std::string> - do_input_dialog (const std::list<std::string>& /*prompt*/, - const std::string& /*title*/, - const std::list<float>& /*nr*/, - const std::list<float>& /*nc*/, - const std::list<std::string>& /*defaults*/) - { - return std::list<std::string> (); - } - - typedef std::list<std::pair<std::string, std::string>> filter_list; - - virtual std::list<std::string> - do_file_dialog (const filter_list& /*filter*/, - const std::string& /*title*/, - const std::string& /*filename*/, - const std::string& /*dirname*/, - const std::string& /*multimode*/) - { - return std::list<std::string> (); - } - - virtual int - do_debug_cd_or_addpath_error (const std::string& /*file*/, - const std::string& /*dir*/, - bool /*addpath_option*/) - { - return -1; - } - - virtual void do_change_directory (const std::string& /*dir*/) { } - - virtual void do_file_remove (const std::string& /*old_name*/, - const std::string& /*new_name*/) - { } - - virtual void do_file_renamed (bool) { } - - virtual void - do_execute_command_in_terminal (const std::string& /*command*/) { } - - virtual uint8NDArray do_get_named_icon (const std::string& /*icon_name*/) - { - return uint8NDArray (); - } - - virtual void do_set_workspace (bool /*top_level*/, bool /*debug*/, - const octave::symbol_info_list& /*syminfo*/, - bool /*update_variable_editor*/) - { } - - virtual void do_clear_workspace (void) { } - - virtual void do_set_history (const string_vector& /*hist*/) { } - - virtual void do_append_history (const std::string& /*hist_entry*/) { } - - virtual void do_clear_history (void) { } - - virtual void do_pre_input_event (void) { } - - virtual void do_post_input_event (void) { } - - virtual void - do_enter_debugger_event (const std::string& /*file*/, int /*line*/) { } - - virtual void - do_execute_in_debugger_event (const std::string& /*file*/, int /*line*/) { } - - virtual void do_exit_debugger_event (void) { } - - virtual void do_update_breakpoint (bool /*insert*/, - const std::string& /*file*/, - int /*line*/, const std::string& /*cond*/) - { } - - virtual void do_show_preferences (void) { } - - virtual std::string do_gui_preference (const std::string& /*key*/, - const std::string& /*value*/) - { - return ""; - } - - virtual void do_show_doc (const std::string& /*file*/) { } - - virtual void do_register_doc (const std::string& /*file*/) { } - - virtual void do_unregister_doc (const std::string& /*file*/) { } - - virtual void do_edit_variable (const std::string& /*name*/, - const octave_value& /*val*/) - { } -}; - -//! Provides threadsafe access to octave. -//! @author Jacob Dawid -//! -//! This class is a wrapper around octave and provides thread safety by -//! buffering access operations to octave and executing them in the -//! readline event hook, which lives in the octave thread. - -class -OCTINTERP_API -octave_link -{ -public: - - octave_link (void); - - // No copying! - - octave_link (const octave_link&) = delete; - - octave_link& operator = (const octave_link&) = delete; - - virtual ~octave_link (void); - - // OBJ should be an object of a class that is derived from the base - // class octave_link_events, or nullptr to disconnect and delete the - // previous link. - - void connect_link (const std::shared_ptr<octave_link_events>& obj); - - bool enable (void); - - bool disable (void) - { - bool retval = link_enabled; - link_enabled = false; - return retval; - } - - bool enabled (void) const - { - return link_enabled; - } - - // If disable is TRUE, then no additional events will be processed - // other than exit. - - void process_events (bool disable = false); - - void discard_events (void); - - bool confirm_shutdown (void) - { - bool retval = true; - - if (enabled ()) - retval = instance->do_confirm_shutdown (); - - return retval; - } - - template <typename F, typename... Args> - void post_event (F&& fcn, Args&&... args) - { - if (enabled ()) - gui_event_queue.add (fcn, std::forward<Args> (args)...); - } - - template <typename T, typename... Params, typename... Args> - void post_event (T *obj, void (T::*method) (Params...), Args&&... args) - { - if (enabled ()) - gui_event_queue.add_method (obj, method, std::forward<Args> (args)...); - } - - void post_exception (const std::exception_ptr& p) - { - if (enabled ()) - post_event (this, &octave_link::rethrow_exception_callback, p); - } - - bool copy_image_to_clipboard (const std::string& file) - { - return enabled () ? instance->do_copy_image_to_clipboard (file) : false; - } - - bool edit_file (const std::string& file) - { - return enabled () ? instance->do_edit_file (file) : false; - } - - bool prompt_new_edit_file (const std::string& file) - { - return enabled () ? instance->do_prompt_new_edit_file (file) : false; - } - - std::string - question_dialog (const std::string& msg, const std::string& title, - const std::string& btn1, const std::string& btn2, - const std::string& btn3, const std::string& btndef) - { - return enabled () ? instance->do_question_dialog (msg, title, btn1, - btn2, btn3, btndef) : ""; - } - - std::pair<std::list<int>, int> - list_dialog (const std::list<std::string>& list, - const std::string& mode, - int width, int height, - const std::list<int>& initial_value, - const std::string& name, - const std::list<std::string>& prompt, - const std::string& ok_string, - const std::string& cancel_string) - { - return (enabled () - ? instance->do_list_dialog (list, mode, width, height, - initial_value, name, prompt, - ok_string, cancel_string) - : std::pair<std::list<int>, int> ()); - } - - std::list<std::string> - input_dialog (const std::list<std::string>& prompt, - const std::string& title, - const std::list<float>& nr, - const std::list<float>& nc, - const std::list<std::string>& defaults) - { - return (enabled () - ? instance->do_input_dialog (prompt, title, nr, nc, defaults) - : std::list<std::string> ()); - } - - typedef std::list<std::pair<std::string, std::string>> filter_list; - - std::list<std::string> - file_dialog (const filter_list& filter, const std::string& title, - const std::string& filename, const std::string& dirname, - const std::string& multimode) - { - return (enabled () - ? instance->do_file_dialog (filter, title, filename, dirname, - multimode) - : std::list<std::string> ()); - } - - int debug_cd_or_addpath_error (const std::string& file, - const std::string& dir, bool addpath_option) - { - return (enabled () - ? instance->do_debug_cd_or_addpath_error (file, dir, addpath_option) - : 0); - } - - void change_directory (const std::string& dir) - { - if (enabled ()) - instance->do_change_directory (dir); - } - - // Methods for removing/renaming files which might be open in editor - void file_remove (const std::string& old_name, const std::string& new_name) - { - if (octave::application::is_gui_running () && enabled ()) - instance->do_file_remove (old_name, new_name); - } - - void file_renamed (bool load_new) - { - if (octave::application::is_gui_running () && enabled ()) - instance->do_file_renamed (load_new); - } - - // Preserves pending input. - void execute_command_in_terminal (const std::string& command) - { - if (enabled ()) - instance->do_execute_command_in_terminal (command); - } - - uint8NDArray get_named_icon (const std::string& icon_name) - { - return (enabled () ? - instance->do_get_named_icon (icon_name) : uint8NDArray ()); - } - - void set_workspace (void); - - void set_workspace (bool top_level, const octave::symbol_info_list& syminfo, - bool update_variable_editor = true) - { - if (enabled ()) - instance->do_set_workspace (top_level, debugging, syminfo, - update_variable_editor); - } - - void clear_workspace (void) - { - if (enabled ()) - instance->do_clear_workspace (); - } - - void set_history (const string_vector& hist) - { - if (enabled ()) - instance->do_set_history (hist); - } - - void append_history (const std::string& hist_entry) - { - if (enabled ()) - instance->do_append_history (hist_entry); - } - - void clear_history (void) - { - if (enabled ()) - instance->do_clear_history (); - } - - void pre_input_event (void) - { - if (enabled ()) - instance->do_pre_input_event (); - } - - void post_input_event (void) - { - if (enabled ()) - instance->do_post_input_event (); - } - - void enter_debugger_event (const std::string& file, int line) - { - if (enabled ()) - { - debugging = true; - - instance->do_enter_debugger_event (file, line); - } - } - - void execute_in_debugger_event (const std::string& file, int line) - { - if (enabled ()) - instance->do_execute_in_debugger_event (file, line); - } - - void exit_debugger_event (void) - { - if (enabled () && debugging) - { - debugging = false; - - instance->do_exit_debugger_event (); - } - } - - void update_breakpoint (bool insert, const std::string& file, - int line, const std::string& cond = "") - { - if (enabled ()) - instance->do_update_breakpoint (insert, file, line, cond); - } - - bool show_preferences (void) - { - if (enabled ()) - { - instance->do_show_preferences (); - return true; - } - else - return false; - } - - std::string gui_preference (const std::string& key, const std::string& value) - { - if (enabled ()) - { - return instance->do_gui_preference (key, value); - } - else - return ""; - } - - bool show_doc (const std::string& file) - { - if (enabled ()) - { - instance->do_show_doc (file); - return true; - } - else - return false; - } - - bool register_doc (const std::string& file) - { - if (enabled ()) - { - instance->do_register_doc (file); - return true; - } - else - return false; - } - - bool unregister_doc (const std::string& file) - { - if (enabled ()) - { - instance->do_unregister_doc (file); - return true; - } - else - return false; - - } - - bool edit_variable (const std::string& name, const octave_value& val) - { - if (enabled ()) - { - instance->do_edit_variable (name, val); - return true; - } - else - return false; - } - -private: - - // Using a shared_ptr to manage the link_events object ensures that it - // will be valid until it is no longer needed. - - std::shared_ptr<octave_link_events> instance; - -protected: - - // Semaphore to lock access to the event queue. - octave::mutex *event_queue_mutex; - - // Event Queue. - octave::event_queue gui_event_queue; - - bool debugging; - bool link_enabled; - - void rethrow_exception_callback (const std::exception_ptr& p) - { - std::rethrow_exception (p); - } -}; - -#endif
--- a/libinterp/corefcn/syscalls.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/syscalls.cc Thu Jul 18 11:23:22 2019 -0400 @@ -42,20 +42,21 @@ #include "oct-env.h" #include "oct-syscalls.h" #include "oct-uname.h" + #include "defun.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" +#include "input.h" #include "interpreter.h" #include "oct-hist.h" #include "oct-map.h" -#include "ovl.h" #include "oct-stdstrm.h" #include "oct-stream.h" -#include "octave-link.h" +#include "ovl.h" #include "sysdep.h" #include "utils.h" #include "variables.h" -#include "input.h" static octave_scalar_map mk_stat_map (const octave::sys::base_file_stat& fs) @@ -1088,13 +1089,13 @@ std::string msg; - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); - olnk.file_remove (name, ""); + evmgr.file_remove (name, ""); int status = octave::sys::unlink (name, msg); - olnk.file_renamed (status == 0); + evmgr.file_renamed (status == 0); return ovl (status, msg); }
--- a/libinterp/corefcn/variables.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/corefcn/variables.cc Thu Jul 18 11:23:22 2019 -0400 @@ -45,13 +45,13 @@ #include "dirfns.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" #include "help.h" #include "input.h" #include "interpreter-private.h" #include "interpreter.h" #include "lex.h" #include "load-path.h" -#include "octave-link.h" #include "octave-preserve-stream-state.h" #include "oct-map.h" #include "ovl.h" @@ -1229,9 +1229,9 @@ { do_clear_variables (interp, argv, argc, true); - octave_link& olnk = interp.get_octave_link (); + octave::event_manager& evmgr = interp.get_event_manager (); - olnk.clear_workspace (); + evmgr.clear_workspace (); } else {
--- a/libinterp/dldfcn/__init_fltk__.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/dldfcn/__init_fltk__.cc Thu Jul 18 11:23:22 2019 -0400 @@ -30,7 +30,7 @@ */ -// PKG_ADD: if (__have_feature__ ("FLTK") && __have_feature__ ("OPENGL") && have_window_system () && ! (ismac () && __octave_link_enabled__ ())) register_graphics_toolkit ("fltk"); endif +// PKG_ADD: if (__have_feature__ ("FLTK") && __have_feature__ ("OPENGL") && have_window_system () && ! (ismac () && __event_manager_enabled__ ())) register_graphics_toolkit ("fltk"); endif #if defined (HAVE_CONFIG_H) # include "config.h"
--- a/libinterp/octave-value/ov-usr-fcn.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Thu Jul 18 11:23:22 2019 -0400 @@ -72,10 +72,10 @@ // FIXME: shouldn't this happen automatically when deleting cmd_list? if (cmd_list) { - octave_link& olnk - = octave::__get_octave_link__ ("octave_user_code::~octave_user_code"); + octave::event_manager& evmgr + = octave::__get_event_manager__ ("octave_user_code::~octave_user_code"); - cmd_list->remove_all_breakpoints (olnk, file_name); + cmd_list->remove_all_breakpoints (evmgr, file_name); } delete cmd_list;
--- a/libinterp/parse-tree/bp-table.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/parse-tree/bp-table.cc Thu Jul 18 11:23:22 2019 -0400 @@ -37,10 +37,10 @@ #include "bp-table.h" #include "defun-int.h" #include "error.h" +#include "event-manager.h" #include "interpreter.h" #include "interpreter-private.h" #include "oct-map.h" -#include "octave-link.h" #include "ov-usr-fcn.h" #include "ov.h" #include "ovl.h" @@ -186,9 +186,9 @@ { interpreter& interp = m_evaluator.get_interpreter (); - octave_link& olnk = interp.get_octave_link (); + event_manager& evmgr = interp.get_event_manager (); - retval = cmds->add_breakpoint (olnk, file, line, condition); + retval = cmds->add_breakpoint (evmgr, file, line, condition); for (auto& idx_line_p : retval) { @@ -666,7 +666,7 @@ { interpreter& interp = m_evaluator.get_interpreter (); - octave_link& olnk = interp.get_octave_link (); + event_manager& evmgr = interp.get_event_manager (); octave_idx_type len = line.size (); @@ -681,7 +681,7 @@ cmds->delete_breakpoint (lineno); if (! file.empty ()) - olnk.update_breakpoint (false, file, lineno); + evmgr.update_breakpoint (false, file, lineno); } } @@ -766,9 +766,9 @@ { interpreter& interp = m_evaluator.get_interpreter (); - octave_link& olnk = interp.get_octave_link (); + event_manager& evmgr = interp.get_event_manager (); - retval = cmds->remove_all_breakpoints (olnk, file); + retval = cmds->remove_all_breakpoints (evmgr, file); auto it = m_bp_set.find (fname); if (it != m_bp_set.end ())
--- a/libinterp/parse-tree/pt-eval.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Thu Jul 18 11:23:22 2019 -0400 @@ -42,10 +42,10 @@ #include "defun.h" #include "error.h" #include "errwarn.h" +#include "event-manager.h" #include "input.h" #include "interpreter-private.h" #include "interpreter.h" -#include "octave-link.h" #include "octave.h" #include "ov-classdef.h" #include "ov-fcn-handle.h" @@ -174,15 +174,15 @@ frm->display_stopped_in_message (buf); } - octave_link& olnk = m_interpreter.get_octave_link (); - - olnk.enter_debugger_event (nm, curr_debug_line); - - olnk.set_workspace (); - - frame.add ([nm, curr_debug_line] (octave_link& ol) { + event_manager& evmgr = m_interpreter.get_event_manager (); + + evmgr.enter_debugger_event (nm, curr_debug_line); + + evmgr.set_workspace (); + + frame.add ([nm, curr_debug_line] (event_manager& ol) { ol.execute_in_debugger_event (nm, curr_debug_line); - }, std::ref (olnk)); + }, std::ref (evmgr)); if (! silent) {
--- a/libinterp/parse-tree/pt-stmt.cc Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/parse-tree/pt-stmt.cc Thu Jul 18 11:23:22 2019 -0400 @@ -30,9 +30,9 @@ #include "bp-table.h" #include "comment-list.h" +#include "event-manager.h" #include "input.h" #include "oct-lvalue.h" -#include "octave-link.h" #include "ov.h" #include "pager.h" #include "pt-bp.h" @@ -243,11 +243,11 @@ // Add breakpoints to file at multiple lines (the second arguments // of line), to stop only if condition is true. - // Updates GUI via octave_link::update_breakpoint. + // Updates GUI via event_manager::update_breakpoint. // FIXME: COME BACK TO ME. bp_table::intmap - tree_statement_list::add_breakpoint (octave_link& olnk, + tree_statement_list::add_breakpoint (event_manager& evmgr, const std::string& file, const bp_table::intmap& line, const std::string& condition) @@ -267,7 +267,7 @@ retval[i] = set_breakpoint (lineno, condition); if (retval[i] != 0 && ! file.empty ()) - olnk.update_breakpoint (true, file, retval[i], condition); + evmgr.update_breakpoint (true, file, retval[i], condition); } } @@ -275,7 +275,7 @@ } bp_table::intmap - tree_statement_list::remove_all_breakpoints (octave_link& olnk, + tree_statement_list::remove_all_breakpoints (event_manager& evmgr, const std::string& file) { bp_table::intmap retval; @@ -291,7 +291,7 @@ retval[i] = lineno; if (! file.empty ()) - olnk.update_breakpoint (false, file, lineno); + evmgr.update_breakpoint (false, file, lineno); } return retval;
--- a/libinterp/parse-tree/pt-stmt.h Thu Jul 18 09:58:41 2019 -0400 +++ b/libinterp/parse-tree/pt-stmt.h Thu Jul 18 11:23:22 2019 -0400 @@ -34,7 +34,7 @@ #include "pt.h" #include "pt-walk.h" -class octave_link; +class event_manager; namespace octave { @@ -185,12 +185,12 @@ std::list<bp_type> breakpoints_and_conds (void); - bp_table::intmap add_breakpoint (octave_link& olnk, + bp_table::intmap add_breakpoint (event_manager& evmgr, const std::string& file, const bp_table::intmap& line, const std::string& condition); - bp_table::intmap remove_all_breakpoints (octave_link& olnk, + bp_table::intmap remove_all_breakpoints (event_manager& evmgr, const std::string& file); void accept (tree_walker& tw)
--- a/scripts/gui/inputdlg.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/inputdlg.m Thu Jul 18 11:23:22 2019 -0400 @@ -156,8 +156,8 @@ ## convert numeric values in defaults cell array to strings defs = cellfun (@num2str, defaults, "UniformOutput", false); - if (__octave_link_enabled__ ()) - cstr = __octave_link_input_dialog__ (prompt, title, rowscols, defs); + if (__event_manager_enabled__ ()) + cstr = __event_manager_input_dialog__ (prompt, title, rowscols, defs); else error ("inputdlg is not available in this version of Octave"); endif
--- a/scripts/gui/listdlg.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/listdlg.m Thu Jul 18 11:23:22 2019 -0400 @@ -147,11 +147,11 @@ error ('listdlg: "SelectionMode" must be "single" or "multiple"'); endif - if (! __octave_link_enabled__ ()) + if (! __event_manager_enabled__ ()) error ("listdlg is not available in this version of Octave"); endif - [sel, ok] = __octave_link_list_dialog__ (listcell, selmode, listsize, + [sel, ok] = __event_manager_list_dialog__ (listcell, selmode, listsize, initialvalue, name, prompt, okstring, cancelstring);
--- a/scripts/gui/msgbox.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/msgbox.m Thu Jul 18 11:23:22 2019 -0400 @@ -166,7 +166,7 @@ endif ## Make a GUI element or print to console - if (__octave_link_enabled__ ()) + if (__event_manager_enabled__ ()) retval = __msgbox__ (msg, tit, icon, windowstyle, interpreter); else if (iscellstr (msg)) @@ -231,7 +231,7 @@ elseif (strcmp (icon_name, "warn")) icon_name = "warning"; endif - tmp = __octave_link_named_icon__ (["dialog-" icon_name]); + tmp = __event_manager_named_icon__ (["dialog-" icon_name]); ## Fake transparency until the opengl renderer handles it: ## RGB data from Qt are premultiplied, we only need to add the ## background part
--- a/scripts/gui/private/__get_funcname__.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/private/__get_funcname__.m Thu Jul 18 11:23:22 2019 -0400 @@ -28,7 +28,7 @@ function funcname = __get_funcname__ (basename) - if (! __octave_link_enabled__ ()) + if (! __event_manager_enabled__ ()) tk = graphics_toolkit (); funcname = [ "__" basename "_" tk "__"]; if (numel (tk) > 0 && ! strcmp (tk, "fltk")
--- a/scripts/gui/questdlg.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/questdlg.m Thu Jul 18 11:23:22 2019 -0400 @@ -117,8 +117,8 @@ endswitch - if (__octave_link_enabled__ ()) - btn = __octave_link_question_dialog__ (msg, title, options{1}, options{2}, + if (__event_manager_enabled__ ()) + btn = __event_manager_question_dialog__ (msg, title, options{1}, options{2}, options{3}, options{4}); else error ("questdlg is not available in this version of Octave");
--- a/scripts/gui/uigetdir.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/uigetdir.m Thu Jul 18 11:23:22 2019 -0400 @@ -44,14 +44,14 @@ init_path = fileparts (init_path); endif - if (__octave_link_enabled__ ()) + if (__event_manager_enabled__ ()) file_filter = cell (0, 2); default_file_name = ""; dialog_position = [240, 120]; dialog_mode = "dir"; [filename, dirname, filterindex] ... - = __octave_link_file_dialog__ (file_filter, dialog_name, + = __event_manager_file_dialog__ (file_filter, dialog_name, default_file_name, dialog_position, dialog_mode, init_path); else
--- a/scripts/gui/uigetfile.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/uigetfile.m Thu Jul 18 11:23:22 2019 -0400 @@ -170,8 +170,8 @@ endfor endif - if (__octave_link_enabled__ ()) - [retfile, retpath, retindex] = __octave_link_file_dialog__ (outargs{:}); + if (__event_manager_enabled__ ()) + [retfile, retpath, retindex] = __event_manager_file_dialog__ (outargs{:}); else funcname = __get_funcname__ (mfilename ()); [retfile, retpath, retindex] = feval (funcname, outargs{:});
--- a/scripts/gui/uiputfile.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/gui/uiputfile.m Thu Jul 18 11:23:22 2019 -0400 @@ -107,8 +107,8 @@ endif endif - if (__octave_link_enabled__ ()) - [retfile, retpath, retindex] = __octave_link_file_dialog__ (outargs{:}); + if (__event_manager_enabled__ ()) + [retfile, retpath, retindex] = __event_manager_file_dialog__ (outargs{:}); else funcname = __get_funcname__ (mfilename ()); [retfile, retpath, retindex] = feval (funcname, outargs{:});
--- a/scripts/help/doc.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/help/doc.m Thu Jul 18 11:23:22 2019 -0400 @@ -53,7 +53,7 @@ ## if GUI is running, let it display the function if (isguirunning ()) - status = ! __octave_link_show_doc__ (function_name); + status = ! __event_manager_show_doc__ (function_name); else if (ftype == 2 || ftype == 3) ffile = which (function_name);
--- a/scripts/miscellaneous/edit.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/miscellaneous/edit.m Thu Jul 18 11:23:22 2019 -0400 @@ -341,7 +341,7 @@ ## If editing a new file, prompt for creation if GUI is running if (isguirunning ()) - if (! __octave_link_edit_file__ (file, "prompt")) + if (! __event_manager_edit_file__ (file, "prompt")) return; endif endif @@ -564,7 +564,7 @@ function do_edit (editor, file, mode) if (isguirunning ()) - __octave_link_edit_file__ (file); + __event_manager_edit_file__ (file); else system (sprintf (undo_string_escapes (editor), ['"' file '"']), [], mode); endif
--- a/scripts/miscellaneous/menu.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/miscellaneous/menu.m Thu Jul 18 11:23:22 2019 -0400 @@ -55,7 +55,7 @@ error ("menu: OPTIONS must be string or cell array of strings"); endif - if (__octave_link_enabled__ ()) # GUI menu + if (__event_manager_enabled__ ()) # GUI menu [choice, ok] = listdlg ("Name", "menu", "PromptString", title, "ListString", varargin, "SelectionMode", "Single"); if (! ok)
--- a/scripts/miscellaneous/movefile.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/miscellaneous/movefile.m Thu Jul 18 11:23:22 2019 -0400 @@ -118,7 +118,7 @@ endif ## Close old file(s) in editor - __octave_link_file_remove__ (p1, p2); + __event_manager_file_remove__ (p1, p2); ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) @@ -126,7 +126,7 @@ msgid = "movefile"; endif ## Load new file(s) in editor - __octave_link_file_renamed__ (status); + __event_manager_file_renamed__ (status); endwhile else if (ispc () && ! isunix () @@ -136,7 +136,7 @@ endif ## Close old file(s) in editor - __octave_link_file_remove__ (p1, p2); + __event_manager_file_remove__ (p1, p2); ## Move the file(s). [err, msg] = system (sprintf ('%s %s "%s"', cmd, p1, p2)); if (err != 0) @@ -144,7 +144,7 @@ msgid = "movefile"; endif ## Load new file(s) in editor - __octave_link_file_renamed__ (status); + __event_manager_file_renamed__ (status); endif endfunction
--- a/scripts/prefs/preferences.m Thu Jul 18 09:58:41 2019 -0400 +++ b/scripts/prefs/preferences.m Thu Jul 18 11:23:22 2019 -0400 @@ -26,7 +26,7 @@ function preferences () if (isguirunning ()) - __octave_link_show_preferences__ (); + __event_manager_show_preferences__ (); else warning ("preferences: GUI must be running to use preferences dialog"); endif