Mercurial > octave
changeset 27243:c6807f5cc48b
replace some explicit callback functions with lambda expressions
* main-window.h, main-window.cc (main_window::open_any_callback,
main_window::rename_variable_callback,
main_window::command_window_undo_callback,
main_window::clear_command_window_callback,
main_window::resize_command_window_callback,
main_window::set_screen_size_callback,
main_window::clear_history_callback,
main_window::refresh_workspace_callback,
main_window::new_figure_callback): Delete. Replace uses with
equivalent lambda expressions in calls to octave_link::post_event.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 12 Jul 2019 13:14:50 -0500 |
parents | 61701d1317a1 |
children | 3f354ef16400 |
files | libgui/src/main-window.cc libgui/src/main-window.h |
diffstat | 2 files changed, 108 insertions(+), 131 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/main-window.cc Fri Jul 12 12:14:43 2019 -0400 +++ b/libgui/src/main-window.cc Fri Jul 12 13:14:50 2019 -0500 @@ -368,8 +368,24 @@ void main_window::handle_open_any_request (const QString& file_arg) { if (! file_arg.isEmpty ()) - octave_link::post_event (this, &main_window::open_any_callback, - file_arg.toStdString ()); + { + std::string file = file_arg.toStdString (); + + octave_link::post_event + ([file] (void) + { + // INTERPRETER THREAD + + feval ("open", ovl (file)); + + // Update the workspace since open.m may have loaded new + // variables. + tree_evaluator& tw + = __get_evaluator__ ("main_window::handle_open_any_request"); + + octave_link::set_workspace (true, tw.get_symbol_info ()); + }); + } } void main_window::handle_clear_workspace_request (void) @@ -381,30 +397,75 @@ void main_window::handle_clear_command_window_request (void) { - octave_link::post_event (this, &main_window::clear_command_window_callback); + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + command_editor::kill_full_line (); + command_editor::clear_screen (); + }); } void main_window::handle_clear_history_request (void) { - octave_link::post_event (this, &main_window::clear_history_callback); + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + history_system& history_sys + = __get_history_system__ ("main_window::clear_history_request"); + + history_sys.do_history (ovl ("-c")); + }); } void main_window::handle_undo_request (void) { if (command_window_has_focus ()) - octave_link::post_event (this, &main_window::command_window_undo_callback); + { + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + command_editor::undo (); + command_editor::redisplay (); + }); + } else emit undo_signal (); } - void main_window::handle_rename_variable_request (const QString& old_name, - const QString& new_name) + void main_window::handle_rename_variable_request (const QString& old_name_arg, + const QString& new_name_arg) { - name_pair names (old_name.toStdString (), new_name.toStdString ()); - - octave_link::post_event (this, &main_window::rename_variable_callback, - names); + std::string old_name = old_name_arg.toStdString (); + std::string new_name = new_name_arg.toStdString (); + + octave_link::post_event + ([old_name, new_name] (void) + { + // INTERPRETER THREAD + + symbol_scope scope + = __get_current_scope__ ("main_window::rename_variable_request"); + + if (scope) + { + scope.rename (old_name, new_name); + + tree_evaluator& tw + = __get_evaluator__ ("main_window::rename_variable_request"); + + octave_link::set_workspace (true, tw.get_symbol_info ()); + } + + // FIXME: if this action fails, do we need a way to display that info + // in the GUI? + }); } void main_window::new_file (const QString& commands) @@ -932,7 +993,17 @@ void main_window::handle_new_figure_request (void) { - octave_link::post_event (this, &main_window::new_figure_callback); + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + interpreter& interp + = __get_interpreter__ ("main_window::new_figure_request"); + + Fbuiltin (interp, ovl ("figure")); + Fdrawnow (); + }); } void main_window::handle_enter_debugger (void) @@ -1091,7 +1162,7 @@ int line) { interpreter& interp - = __get_interpreter__ ("main_window::clear_workspace_callback"); + = __get_interpreter__ ("main_window::handle_edit_mfile_request"); // Split possible subfuntions QStringList fcn_list = fname.split ('>'); @@ -1540,8 +1611,13 @@ void main_window::set_screen_size (int ht, int wd) { - octave_link::post_event (this, &main_window::set_screen_size_callback, - int_pair (ht, wd)); + octave_link::post_event + ([ht, wd] (void) + { + // INTERPRETER THREAD + + command_editor::set_screen_size (ht, wd); + }); } void main_window::clipboard_has_changed (void) @@ -1621,7 +1697,16 @@ // interpreter. That will eventually cause the workspace view in the // GUI to be updated. - octave_link::post_event (this, &main_window::refresh_workspace_callback); + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + tree_evaluator& tw + = __get_evaluator__ ("main_window::handle_variable_editor_update"); + + octave_link::set_workspace (true, tw.get_symbol_info (), false); + }); } void main_window::closeEvent (QCloseEvent *e) @@ -1830,8 +1915,13 @@ SIGNAL (file_remove_signal (const QString&, const QString&)), this, SLOT (file_remove_proxy (const QString&, const QString&))); - octave_link::post_event (this, - &main_window::resize_command_window_callback); + octave_link::post_event + ([] (void) + { + // INTERPRETER THREAD + + command_editor::resize_terminal (); + }); configure_shortcuts (); } @@ -2461,107 +2551,12 @@ qt_link->wake_all (); } - void main_window::rename_variable_callback (const main_window::name_pair& names) - { - // INTERPRETER THREAD - - symbol_scope scope - = __get_current_scope__ ("main_window::rename_variable_callback"); - - if (scope) - { - scope.rename (names.first, names.second); - - tree_evaluator& tw - = __get_evaluator__ ("main_window::rename_variable_callback"); - - octave_link::set_workspace (true, tw.get_symbol_info ()); - } - - // FIXME: if this action fails, do we need a way to display that info - // in the GUI? - } - - void main_window::command_window_undo_callback (void) - { - // INTERPRETER THREAD - - command_editor::undo (); - command_editor::redisplay (); - } - - void main_window::clear_command_window_callback (void) - { - // INTERPRETER THREAD - - command_editor::kill_full_line (); - command_editor::clear_screen (); - } - - void main_window::resize_command_window_callback (void) - { - // INTERPRETER THREAD - - command_editor::resize_terminal (); - } - - void main_window::set_screen_size_callback (const int_pair& sz) - { - // INTERPRETER THREAD - - command_editor::set_screen_size (sz.first, sz.second); - } - - void main_window::open_any_callback (const std::string& file) - { - // INTERPRETER THREAD - - feval ("open", ovl (file)); - - // Update the workspace since open.m may have loaded new variables. - tree_evaluator& tw - = __get_evaluator__ ("main_window::open_any_callback"); - - octave_link::set_workspace (true, tw.get_symbol_info ()); - } - - void main_window::clear_history_callback (void) - { - // INTERPRETER THREAD - - history_system& history_sys - = __get_history_system__ ("main_window::clear_history_callback"); - - history_sys.do_history (ovl ("-c")); - } - - void main_window::refresh_workspace_callback (void) - { - // INTERPRETER THREAD - - tree_evaluator& tw - = __get_evaluator__ ("main_window::force_refresh_workspace"); - - octave_link::set_workspace (true, tw.get_symbol_info (), false); - } - bool main_window::focus_console_after_command (void) { QSettings *settings = resource_manager::get_settings (); return settings->value ("terminal/focus_after_command",false).toBool (); } - void main_window::new_figure_callback (void) - { - // INTERPRETER THREAD - - interpreter& interp - = __get_interpreter__ ("main_window::new_figure_callback"); - - Fbuiltin (interp, ovl ("figure")); - Fdrawnow (); - } - void main_window::configure_shortcuts (void) { // file menu
--- a/libgui/src/main-window.h Fri Jul 12 12:14:43 2019 -0400 +++ b/libgui/src/main-window.h Fri Jul 12 13:14:50 2019 -0500 @@ -282,26 +282,8 @@ QString gui_preference_adjust (const QString& key, const QString& value); - void open_any_callback (const std::string& file); - - void rename_variable_callback (const name_pair& names); - - void command_window_undo_callback (void); - - void clear_command_window_callback (void); - - void resize_command_window_callback (void); - - void set_screen_size_callback (const int_pair&); - - void clear_history_callback (void); - - void refresh_workspace_callback (void); - bool focus_console_after_command (void); - void new_figure_callback (void); - void configure_shortcuts (void); QList<octave_dock_widget *> dock_widget_list (void);