# HG changeset patch # User Michael Barnes # Date 1495210548 -7200 # Fri May 19 18:15:48 2017 +0200 # Node ID aef5a030985cae3c2dd1ebede7dba2b564d8523d # Parent 293dec4952566e730320ebcb06fe411f69d089cc variable-editor patch update to Octave-4.3.0+ July 12, 2017 This patch is the work of RĂ¼diger Sonderfeld Philip Nienhuis Michael Barnes jwe diff --git a/libgui/src/main-window.cc b/libgui/src/main-window.cc --- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -151,9 +151,9 @@ main_window::main_window (QWidget *p, oc m_interpreter (new octave_interpreter (app_context)), m_main_thread (new QThread ()), _workspace_model (0), status_bar (0), command_window (0), history_window (0), file_browser_window (0), - doc_browser_window (0), editor_window (0), workspace_window (0), - _settings_dlg (0), find_files_dlg (0), release_notes_window (0), - community_news_window (0), _octave_qt_link (0), + doc_browser_window (0), editor_window (0),variable_editor_window (0), + workspace_window (0), _settings_dlg (0), find_files_dlg (0), + release_notes_window (0), community_news_window (0), _octave_qt_link (0), _clipboard (QApplication::clipboard ()), _prevent_readline_conflicts (true), _suppress_dbg_location (true), @@ -169,6 +169,7 @@ main_window::main_window (QWidget *p, oc file_browser_window = new files_dock_widget (this); doc_browser_window = new documentation_dock_widget (this); editor_window = create_default_editor (this); + variable_editor_window = new variable_editor (this); workspace_window = new workspace_view (this); } @@ -230,6 +231,11 @@ main_window::~main_window (void) delete history_window; delete status_bar; delete _workspace_model; + if(variable_editor_window) + { + delete variable_editor_window; + variable_editor_window = 0; + } delete m_interpreter; delete m_main_thread; if (find_files_dlg) @@ -1301,7 +1307,7 @@ main_window::selectAll (void) // is not a global variable and not accessible for connecting. void -main_window::connect_uiwidget_links (void) +main_window::connect_uiwidget_links () { connect (&uiwidget_creator, SIGNAL (create_dialog (const QString&, const QString&, @@ -1677,11 +1683,26 @@ main_window::construct (void) connect (_workspace_model, SIGNAL (model_changed (void)), workspace_window, SLOT (handle_model_changed (void))); + connect (_octave_qt_link, + SIGNAL (open_variable (const QString&)), + this, + SLOT (edit_variable (const QString&))); + + connect (_octave_qt_link, + SIGNAL (refresh_variable_editor()), + this, + SLOT (clear_variable_editor_cache())); + connect (_workspace_model, SIGNAL (rename_variable (const QString&, const QString&)), this, SLOT (handle_rename_variable_request (const QString&, - const QString&))); + const QString&))); + + connect (variable_editor_window, + SIGNAL (updated()), + this, + SLOT (variable_editor_callback ())); connect (command_window, SIGNAL (interrupt_signal (void)), this, SLOT (interrupt_interpreter (void))); @@ -1752,6 +1773,8 @@ main_window::construct (void) addDockWidget (Qt::RightDockWidgetArea, editor_window); tabifyDockWidget (command_window, editor_window); #endif + addDockWidget (Qt::TopDockWidgetArea, variable_editor_window); + tabifyDockWidget (command_window, variable_editor_window); addDockWidget (Qt::LeftDockWidgetArea, file_browser_window); addDockWidget (Qt::LeftDockWidgetArea, workspace_window); @@ -2283,6 +2306,9 @@ main_window::construct_window_menu (QMen _show_documentation_action = construct_window_menu_item (window_menu, tr ("Show Documentation"), true, doc_browser_window); + _show_variable_editor_action = construct_window_menu_item + (window_menu, tr ("Show Variable Editor"), true, variable_editor_window); + window_menu->addSeparator (); _command_window_action = construct_window_menu_item @@ -2303,6 +2329,9 @@ main_window::construct_window_menu (QMen _documentation_action = construct_window_menu_item (window_menu, tr ("Documentation"), false, doc_browser_window); + _variable_editor_action = construct_window_menu_item + (window_menu, tr ("Documentation"), false, variable_editor_window); + window_menu->addSeparator (); _reset_windows_action = add_action (window_menu, QIcon (), @@ -2373,6 +2402,7 @@ main_window::construct_tool_bar (void) _main_tool_bar->addAction (_copy_action); _main_tool_bar->addAction (_paste_action); + _main_tool_bar->addAction (_undo_action); _main_tool_bar->addSeparator (); @@ -2416,6 +2446,23 @@ main_window::construct_tool_bar (void) } void +main_window::variable_editor_callback() +{ + // Called when the variable editor makes changes. + octave_link::post_event(this, &main_window::force_refresh_workspace); +} + +void +main_window::force_refresh_workspace() +{ + octave::symbol_table::scope *scope + = octave::__get_current_scope__ ("main_window::load_workspace_callback"); + + if (scope) + octave_link::set_workspace (true, scope->workspace_info (), false); +} + +void main_window::save_workspace_callback (const std::string& file) { Fsave (ovl (file)); @@ -2602,6 +2649,7 @@ main_window::configure_shortcuts () "main_window:file_browser"); shortcut_manager::set_shortcut (_editor_action, "main_window:editor"); shortcut_manager::set_shortcut (_documentation_action, "main_window:doc"); + shortcut_manager::set_shortcut (_variable_editor_action, "main_window:variable_editor"); shortcut_manager::set_shortcut (_reset_windows_action, "main_window:reset"); // help menu @@ -2687,6 +2735,8 @@ main_window::dock_widget_list () list.append (static_cast (editor_window)); #endif list.append (static_cast (workspace_window)); + //if (variable_editor_window) + list.append (static_cast (variable_editor_window)); return list; } @@ -2729,6 +2779,25 @@ main_window::clear_clipboard () } void +main_window::edit_variable (const QString &expr) +{ + variable_editor_window->edit_variable (expr); + + if (! variable_editor_window->isVisible ()) + { + variable_editor_window->show (); + variable_editor_window->raise (); + } + +} + +void +main_window::clear_variable_editor_cache () +{ + variable_editor_window->clear_data_cache (); +} + +void main_window::interrupt_interpreter (void) { m_interpreter->interrupt (); diff --git a/libgui/src/main-window.h b/libgui/src/main-window.h --- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -57,6 +57,7 @@ along with Octave; see the file COPYING. #include "octave-qt-link.h" #include "resource-manager.h" #include "terminal-dock-widget.h" +#include "variable-editor.h" #include "thread-manager.h" #include "workspace-model.h" #include "workspace-view.h" @@ -272,6 +273,15 @@ private slots: void set_file_encoding (const QString& new_encoding); void request_open_files (const QStringList& open_file_names); + // open variable_editor + void + edit_variable (const QString &name); + + void + clear_variable_editor_cache (); + + void variable_editor_callback(); + protected: void closeEvent (QCloseEvent *closeEvent); @@ -340,6 +350,10 @@ private: QThread *m_main_thread; + bool confirm_exit_octave (); + + void force_refresh_workspace(); + workspace_model *_workspace_model; QHash _hash_menu_text; @@ -354,6 +368,7 @@ private: documentation_dock_widget *doc_browser_window; file_editor_interface *editor_window; workspace_view *workspace_window; + variable_editor *variable_editor_window; external_editor_interface *_external_editor; QWidget *_active_editor; @@ -399,12 +414,14 @@ private: QAction *_show_file_browser_action; QAction *_show_editor_action; QAction *_show_documentation_action; + QAction *_show_variable_editor_action; QAction *_command_window_action; QAction *_history_action; QAction *_workspace_action; QAction *_file_browser_action; QAction *_editor_action; QAction *_documentation_action; + QAction *_variable_editor_action; QAction *_reset_windows_action; QAction *_ondisk_doc_action; diff --git a/libgui/src/module.mk b/libgui/src/module.mk --- a/libgui/src/module.mk +++ b/libgui/src/module.mk @@ -114,6 +114,8 @@ OCTAVE_GUI_SRC_MOC = \ %reldir%/moc-welcome-wizard.cc \ %reldir%/moc-workspace-model.cc \ %reldir%/moc-workspace-view.cc \ + %reldir%/moc-variable-editor.cc \ + %reldir%/moc-variable-editor-model.cc \ %reldir%/moc-find-files-dialog.cc \ %reldir%/moc-find-files-model.cc \ %reldir%/qtinfo/moc-parser.cc \ @@ -170,7 +172,9 @@ noinst_HEADERS += \ %reldir%/find-files-dialog.h \ %reldir%/find-files-model.h \ %reldir%/workspace-model.h \ - %reldir%/workspace-view.h + %reldir%/workspace-view.h \ + %reldir%/variable-editor.h \ + %reldir%/variable-editor-model.h %canon_reldir%_%canon_reldir%_la_SOURCES = \ %reldir%/dialog.cc \ @@ -201,7 +205,9 @@ noinst_HEADERS += \ %reldir%/find-files-dialog.cc \ %reldir%/find-files-model.cc \ %reldir%/workspace-model.cc \ - %reldir%/workspace-view.cc + %reldir%/workspace-view.cc \ + %reldir%/variable-editor.cc \ + %reldir%/variable-editor-model.cc nodist_%canon_reldir%_%canon_reldir%_la_SOURCES = \ $(octave_gui_MOC) \ diff --git a/libgui/src/octave-qt-link.cc b/libgui/src/octave-qt-link.cc --- a/libgui/src/octave-qt-link.cc +++ b/libgui/src/octave-qt-link.cc @@ -429,7 +429,8 @@ octave_qt_link::do_execute_command_in_te void octave_qt_link::do_set_workspace (bool top_level, bool debug, - const std::list& ws) + const std::list& ws, + const bool& update_variable_editor) { if (! top_level && ! debug) return; @@ -457,6 +458,9 @@ octave_qt_link::do_set_workspace (bool t emit set_workspace_signal (top_level, debug, scopes, symbols, class_names, dimensions, values, complex_flags); + + if (update_variable_editor) + emit refresh_variable_editor(); } void @@ -632,6 +636,12 @@ octave_qt_link::do_show_preferences () } void +octave_qt_link::do_openvar (const std::string &expr) +{ + emit open_variable (QString::fromStdString (expr)); +} + +void octave_qt_link::do_show_doc (const std::string& file) { emit show_doc_signal (QString::fromStdString (file)); diff --git a/libgui/src/octave-qt-link.h b/libgui/src/octave-qt-link.h --- a/libgui/src/octave-qt-link.h +++ b/libgui/src/octave-qt-link.h @@ -105,7 +105,8 @@ public: void do_execute_command_in_terminal (const std::string& command); void do_set_workspace (bool top_level, bool debug, - const std::list& ws); + const std::list& ws, + const bool& variable_editor_too = true); void do_clear_workspace (void); @@ -138,6 +139,7 @@ public: void update_directory (void); + void do_openvar (const std::string &name); private: bool _shutdown_confirm_result; @@ -192,6 +194,10 @@ signals: void show_doc_signal (const QString& file); + void open_variable (const QString &name); + + void refresh_variable_editor(); + void confirm_shutdown_signal (void); }; diff --git a/libgui/src/resource-manager.cc b/libgui/src/resource-manager.cc --- a/libgui/src/resource-manager.cc +++ b/libgui/src/resource-manager.cc @@ -45,6 +45,7 @@ along with Octave; see the file COPYING. #include "QTerminal.h" #include "workspace-model.h" +#include "variable-editor.h" #include "resource-manager.h" resource_manager *resource_manager::instance = nullptr; @@ -319,6 +320,18 @@ resource_manager::terminal_default_color return QTerminal::default_colors (); } +QList +resource_manager::varedit_default_colors(void) +{ + return variable_editor::default_colors (); +} + +QStringList +resource_manager::varedit_color_names(void) +{ + return variable_editor::color_names (); +} + QIcon resource_manager::do_icon (const QString& icon_name, bool fallback) { diff --git a/libgui/src/resource-manager.h b/libgui/src/resource-manager.h --- a/libgui/src/resource-manager.h +++ b/libgui/src/resource-manager.h @@ -118,6 +118,10 @@ public slots: static void cleanup_instance (void) { delete instance; instance = 0; } + static QString varedit_color_chars (void) {return "fbsha"; } + static QStringList varedit_color_names (void); + static QList varedit_default_colors (void); + private: static bool instance_ok (void); diff --git a/libgui/src/settings-dialog.cc b/libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc +++ b/libgui/src/settings-dialog.cc @@ -26,6 +26,7 @@ along with Octave; see the file COPYING. #include "resource-manager.h" #include "shortcut-manager.h" +#include "variable-editor.h" #include "workspace-model.h" #include "settings-dialog.h" #include "ui-settings-dialog.h" @@ -576,6 +577,21 @@ settings_dialog::settings_dialog (QWidge // terminal colors read_terminal_colors (settings); + // variable editor + ui->varedit_columnWidth->setText(settings->value("variable_editor/column_width","100").toString()); + ui->varedit_autoFitColumnWidth->setChecked(settings->value("variable_editor/autofit_column_width",false).toBool()); + ui->varedit_autofitType->setCurrentIndex(settings->value("autofit_type",0).toInt()); + ui->varedit_rowHeight->setText(settings->value("variable_editor/row_height","2").toString()); + ui->varedit_rowAutofit->setChecked(settings->value("variable_editor/autofit_row_height",true).toBool()); + ui->varedit_font->setFont(QFont(settings->value("variable_editor/font",settings->value("terminal/FontName","Courier New")).toString())); + ui->varedit_fontSize->setValue(settings->value("variable_editor/font_size",QVariant(10)).toInt()); + ui->varedit_useTerminalFont->setChecked(settings->value("variable_editor/use_terminal_font",false).toBool()); + ui->varedit_alternate->setChecked(settings->value("variable_editor/alternate_rows",QVariant(false)).toBool()); + ui->varedit_toolbarSize->setValue(settings->value("variable_editor/toolbar_size",24).toInt()); + + // variable editor colors + read_varedit_colors(settings); + // shortcuts ui->cb_prevent_readline_conflicts->setChecked ( @@ -739,6 +755,64 @@ settings_dialog::read_terminal_colors (Q } void +settings_dialog::write_varedit_colors (QSettings *settings) +{ + QString class_chars = resource_manager::varedit_color_chars (); + color_picker *color; + + for (int i = 0; i < class_chars.length (); i++) + { + color = ui->varedit_colors_box->findChild ( + "varedit_color_"+class_chars.mid (i,1)); + if (color) + settings->setValue ("variable_editor/color_"+class_chars.mid (i,1), + color->color ()); + } + settings->sync (); +} + + +void +settings_dialog::read_varedit_colors (QSettings *settings) +{ + QList default_colors = variable_editor::default_colors (); + QStringList class_names = variable_editor::color_names (); + QString class_chars = resource_manager::varedit_color_chars (); + int nr_of_classes = class_chars.length (); + + QGridLayout *style_grid = new QGridLayout (); + QVector description (nr_of_classes); + QVector color (nr_of_classes); + + int column = 0; + int row = 0; + for (int i = 0; i < nr_of_classes; i++) + { + description[i] = new QLabel (" " + class_names.at (i)); + description[i]->setAlignment (Qt::AlignRight); + QVariant default_var = default_colors.at (i); + QColor setting_color = settings->value ("variable_editor/color_" + + class_chars.mid (i,1), + default_var).value (); + color[i] = new color_picker (setting_color); + color[i]->setObjectName ("varedit_color_"+class_chars.mid (i, 1)); + color[i]->setMinimumSize (30, 10); + style_grid->addWidget (description[i], row, 2*column); + style_grid->addWidget (color[i], row, 2*column+1); + if (++column == 2) + { + style_grid->setColumnStretch (3*column, 10); + row++; + column = 0; + } + } + + // place grid with elements into the tab + ui->varedit_colors_box->setLayout (style_grid); + +} + +void settings_dialog::write_changed_settings (bool closing) { QSettings *settings = resource_manager::get_settings (); @@ -968,6 +1042,19 @@ settings_dialog::write_changed_settings // Terminal write_terminal_colors (settings); + // Variable editor + settings->setValue("variable_editor/autofit_column_width",ui->varedit_autoFitColumnWidth->isChecked()); + settings->setValue("variable_editor/autofit_type",ui->varedit_autofitType->currentIndex()); + settings->setValue("variable_editor/column_width",ui->varedit_columnWidth->text()); + settings->setValue("variable_editor/row_height", ui->varedit_rowHeight->text()); + settings->setValue("variable_editor/autofit_row_height",ui->varedit_rowAutofit->isChecked()); + settings->setValue("variable_editor/use_terminal_font",ui->varedit_useTerminalFont->isChecked()); + settings->setValue("variable_editor/alternate_rows",ui->varedit_alternate->isChecked()); + settings->setValue("variable_editor/font_name",ui->varedit_font->currentFont().family()); + settings->setValue("variable_editor/font_size",ui->varedit_fontSize->value()); + settings->setValue("variable_editor/toolbar_size",ui->varedit_toolbarSize->value()); + write_varedit_colors(settings); + // shortcuts settings->setValue ("shortcuts/prevent_readline_conflicts", ui->cb_prevent_readline_conflicts->isChecked ()); diff --git a/libgui/src/settings-dialog.h b/libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h +++ b/libgui/src/settings-dialog.h @@ -70,6 +70,9 @@ private: void read_terminal_colors (QSettings *settings); void write_terminal_colors (QSettings *settings); + void read_varedit_colors (QSettings *settings); + void write_varedit_colors (QSettings *settings); + color_picker *_widget_title_bg_color; color_picker *_widget_title_bg_color_active; color_picker *_widget_title_fg_color; diff --git a/libgui/src/settings-dialog.ui b/libgui/src/settings-dialog.ui --- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -2655,6 +2655,228 @@ + + + Variable Editor + + + + + + true + + + + + 0 + 0 + 678 + 384 + + + + + + 0 + 0 + 678 + 384 + + + + + + + + + + Default row height + + + + + + + Font + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 20 + + + + + + + Default column width + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Use Terminal Font + + + true + + + + + + + 10 + + + + + + + Font size + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 2 + + + + + + + + Liberation Mono + + + + + + + + Autofit + + + + + + + Plus font height + + + true + + + + + + + 0 + + + + By Column + + + + + Uniform + + + + + + + + Toolbar Size + + + Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter + + + + + + + 8 + + + 64 + + + 8 + + + 32 + + + + + + + + + Variable Editor Colours + + + + + + + + + true + + + Use alternating row colours + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + + + diff --git a/libgui/src/workspace-model.h b/libgui/src/workspace-model.h --- a/libgui/src/workspace-model.h +++ b/libgui/src/workspace-model.h @@ -88,6 +88,7 @@ public slots: signals: void model_changed (void); + void prompt_variable_editor(void); void rename_variable (const QString& old_name, const QString& new_name); diff --git a/libgui/src/workspace-view.cc b/libgui/src/workspace-view.cc --- a/libgui/src/workspace-view.cc +++ b/libgui/src/workspace-view.cc @@ -152,6 +152,9 @@ workspace_view::workspace_view (QWidget connect (this, SIGNAL (command_requested (const QString&)), p, SLOT (execute_command_in_terminal (const QString&))); + + connect (this, SIGNAL (edit_variable_signal (const QString&)), + p, SLOT (edit_variable (const QString&))); } void @@ -324,6 +327,9 @@ workspace_view::contextmenu_requested (c rename->setToolTip (tr ("Only top-level symbols may be renamed")); } + menu.addAction (tr ("Open in Variable Editor"), this, + SLOT (handle_contextmenu_edit ())); + menu.addSeparator (); menu.addAction ("disp (" + var_name + ")", this, @@ -413,6 +419,25 @@ workspace_view::handle_contextmenu_renam } void +workspace_view::handle_contextmenu_edit (void) +{ + QModelIndex index = view->currentIndex (); + + if (index.isValid ()) + { + index = index.sibling (index.row (), 0); + + QAbstractItemModel *m = view->model (); + + QMap item_data = m->itemData (index); + + QString var_name = item_data[0].toString (); + + emit edit_variable_signal (var_name); + } +} + +void workspace_view::handle_contextmenu_disp (void) { relay_contextmenu_command ("disp"); diff --git a/libgui/src/workspace-view.h b/libgui/src/workspace-view.h --- a/libgui/src/workspace-view.h +++ b/libgui/src/workspace-view.h @@ -58,6 +58,9 @@ signals: /** signal that user had requested a command on a variable */ void command_requested (const QString& cmd); + /// signal that user wants to edit a variable + void edit_variable_signal (const QString&); + protected: void closeEvent (QCloseEvent *event); @@ -70,6 +73,7 @@ protected slots: void handle_contextmenu_copy (void); void handle_contextmenu_copy_value (void); void handle_contextmenu_rename (void); + void handle_contextmenu_edit (void); void handle_contextmenu_disp (void); void handle_contextmenu_plot (void); void handle_contextmenu_stem (void); diff --git a/libinterp/corefcn/octave-link.cc b/libinterp/corefcn/octave-link.cc --- a/libinterp/corefcn/octave-link.cc +++ b/libinterp/corefcn/octave-link.cc @@ -381,7 +381,28 @@ Undocumented internal function. { return ovl (octave_link::show_preferences ()); } + +DEFUN (openvar, args, , + "-*- texinfo -*-\n\ +@deftypefn {Built-in Function} openvar (@var{name})\n\ +Open the variable @var{name} in the GUI Variable Editor.\n\ +@end deftypefn") +{ + octave_value retval; + if (args.length () == 1) + { + std::string name = args (0).string_value (); + if (! error_state) + octave_link::openvar (name); + else + error ("invalid arguments"); + } + else + print_usage (); + + return retval; +} DEFUN (__octave_link_show_doc__, args, , doc: /* -*- texinfo -*- @deftypefn {} {} __octave_link_show_doc__ (@var{filename}) diff --git a/libinterp/corefcn/octave-link.h b/libinterp/corefcn/octave-link.h --- a/libinterp/corefcn/octave-link.h +++ b/libinterp/corefcn/octave-link.h @@ -120,6 +120,33 @@ public: instance->do_post_event (obj, method, arg); } + template + static void post_event (T *obj, void (T::*method) (A, B), + A arg_a, B arg_b) + { + if (enabled ()) + instance->do_post_event (obj, method, arg_a, arg_b); + } + + template + static void post_event (T *obj, + void (T::*method) (A, B, C), + A arg_a, B arg_b, C arg_c) + { + if (enabled ()) + instance->do_post_event (obj, method, arg_a, arg_b, arg_c); + } + + template + static void post_event (T *obj, + void (T::*method) (A, B, C, D), + A arg_a, B arg_b, C arg_c, D arg_d) + { + if (enabled ()) + instance->do_post_event + (obj, method, arg_a, arg_b, arg_c, arg_d); + } + static void entered_readline_hook (void) { if (enabled ()) @@ -233,10 +260,10 @@ public: static void set_workspace (void); static void set_workspace (bool top_level, - const std::list& ws) + const std::list& ws, const bool& update_variable_editor = true) { if (enabled ()) - instance->do_set_workspace (top_level, instance->debugging, ws); + instance->do_set_workspace (top_level, instance->debugging, ws, update_variable_editor); } static void clear_workspace (void) @@ -388,6 +415,18 @@ public: } + static bool + openvar (const std::string &name) + { + if (enabled ()) + { + instance->do_openvar (name); + return true; + } + else + return false; + } + private: static octave_link *instance; @@ -427,6 +466,30 @@ protected: gui_event_queue.add_method (obj, method, arg); } + template + void do_post_event (T *obj, void (T::*method) (A, B), + A arg_a, B arg_b) + { + gui_event_queue.add_method + (obj, method, arg_a, arg_b); + } + + template + void do_post_event (T *obj, void (T::*method) (A, B, C), + A arg_a, B arg_b, C arg_c) + { + gui_event_queue.add_method + (obj, method, arg_a, arg_b, arg_c); + } + + template + void do_post_event (T *obj, void (T::*method) (A, B, C, D), + A arg_a, B arg_b, C arg_c, D arg_d) + { + gui_event_queue.add_method + (obj, method, arg_a, arg_b, arg_c, arg_d); + } + void do_entered_readline_hook (void) { } void do_finished_readline_hook (void) { } @@ -479,7 +542,8 @@ protected: virtual void do_set_workspace (bool top_level, bool debug, - const std::list& ws) = 0; + const std::list& ws, + const bool& variable_editor_too = true) = 0; virtual void do_clear_workspace (void) = 0; @@ -508,6 +572,8 @@ protected: virtual void do_show_preferences (void) = 0; virtual void do_show_doc (const std::string& file) = 0; + + virtual void do_openvar (const std::string& name) = 0; }; #endif diff --git a/libinterp/corefcn/variables.cc b/libinterp/corefcn/variables.cc --- a/libinterp/corefcn/variables.cc +++ b/libinterp/corefcn/variables.cc @@ -482,6 +482,15 @@ symbol_exist (octave::interpreter& inter return 0; } +int +symbol_exist (const std::string& name, const std::string& type) +{ + octave::interpreter& interp = octave::__get_interpreter__ ("symbol_exist"); + + return symbol_exist (interp, name, type); +} + + #define GET_IDX(LEN) \ static_cast ((LEN-1) * static_cast (rand ()) / RAND_MAX) diff --git a/libinterp/corefcn/variables.h b/libinterp/corefcn/variables.h --- a/libinterp/corefcn/variables.h +++ b/libinterp/corefcn/variables.h @@ -70,6 +70,9 @@ generate_struct_completions (const std:: extern OCTINTERP_API bool looks_like_struct (const std::string& text, char prev_char); +extern OCTINTERP_API int +symbol_exist (const std::string& name, const std::string& type = "any"); + extern OCTINTERP_API std::string unique_symbol_name (const std::string& basename); diff --git a/liboctave/util/action-container.h b/liboctave/util/action-container.h --- a/liboctave/util/action-container.h +++ b/liboctave/util/action-container.h @@ -213,6 +213,91 @@ namespace octave A e_arg; }; + /// An element for calling a member function with two arguments + template + class method_arg2_elem : public elem + { + public: + method_arg2_elem (T *obj, void (T::*method) (A, B), + A arg_a, B arg_b) + : e_obj (obj), e_method (method), + e_arg_a (arg_a), e_arg_b (arg_b) { } + + void run (void) { (e_obj->*e_method) (e_arg_a, e_arg_b); } + + private: + + T *e_obj; + void (T::*e_method) (A, B); + A e_arg_a; + B e_arg_b; + + // No copying! + + method_arg2_elem (const method_arg2_elem&); + + method_arg2_elem operator = (const method_arg2_elem&); + }; + + /// An element for calling a member function with three arguments + template + class method_arg3_elem : public elem + { + public: + method_arg3_elem (T *obj, void (T::*method) (A, B, C), + A arg_a, B arg_b, C arg_c) + : e_obj (obj), e_method (method), + e_arg_a (arg_a), e_arg_b (arg_b), e_arg_c (arg_c) + { } + + void run (void) { (e_obj->*e_method) (e_arg_a, e_arg_b, e_arg_c); } + + private: + + T *e_obj; + void (T::*e_method) (A, B, C); + A e_arg_a; + B e_arg_b; + C e_arg_c; + + // No copying! + + method_arg3_elem (const method_arg3_elem&); + + method_arg3_elem operator = (const method_arg3_elem&); + }; + + /// An element for calling a member function with three arguments + template + class method_arg4_elem : public elem + { + public: + method_arg4_elem (T *obj, void (T::*method) (A, B, C, D), + A arg_a, B arg_b, C arg_c, D arg_d) + : e_obj (obj), e_method (method), + e_arg_a (arg_a), e_arg_b (arg_b), e_arg_c (arg_c), e_arg_d (arg_d) + { } + + void run (void) { + (e_obj->*e_method) (e_arg_a, e_arg_b, e_arg_c, e_arg_d); + } + + private: + + T *e_obj; + void (T::*e_method) (A, B, C, D); + A e_arg_a; + B e_arg_b; + C e_arg_c; + D e_arg_d; + + // No copying! + + method_arg4_elem (const method_arg4_elem&); + + method_arg4_elem operator = (const method_arg4_elem&); + }; + // An element that stores arbitrary variable, and restores it. template @@ -330,6 +415,33 @@ namespace octave add (new method_crefarg_elem (obj, method, arg)); } + // Call to T::method (A, B). + template + void add_method (T *obj, void (T::*method) (A, B), + A arg_a, B arg_b) + { + add (new method_arg2_elem (obj, method, arg_a, arg_b)); + } + + // Call to T::method (A, B, C). + template + void add_method (T *obj, void (T::*method) (A, B, C), + A arg_a, B arg_b, C arg_c) + { + add (new method_arg3_elem (obj, method, arg_a, + arg_b, arg_c)); + } + + // Call to T::method (A, B, C, D). + template + void add_method (T *obj, void (T::*method) (A, B, C, D), + A arg_a, B arg_b, + C arg_c, D arg_d) + { + add (new method_arg4_elem (obj, method, arg_a, + arg_b, arg_c, arg_d)); + } + // Call to delete (T*). template