Mercurial > octave
changeset 33530:1ab09074c74b
add editor menu entries for running test or demos in current file
* files-dock-widget.cc/h: run_file_signal has second argument for
running file, tests or demos
* gui-preferences-global.h: define constants for running files,
tests or demos
* gui-preferences-sc.cc/h: define shortcuts for running tests or demos
* file-editor-tab.cc: change order of includes ensuring global preferences
are included before editor-tab and main-window header
(run_file): second argument is integer indicating what to run;
* file-editor-tab.h: run_file and run_file_signal have integer as
second argument
* file-editor.cc: reorder includes ensuring the global preferences are
included before file-editor header;
(run_file) renamed from request_run_file and using integer argument
for running file, tests or demos, pass integer argument via signal
fetab_run_file to file editor tab;
(request_run_file): action slot, now just calling run_file with
suitable run type;
(request_run_tests, request_run_demos): dito;
(request_step_into_file): use second integer argument when signaling
desired action to file editor tab;
(set_shortcuts): add shortcuts to new actions;
(construct): add new menu entries;
* file-editor.h: fetab_run_file, run_file_signal now with two arguments,
request_run_tests, request_run_demos and run_file new methods,
m_run_tests_action, m_run_demos_action new actions
* main-window.cc: reorder includes ensuring global preferences are included
before relevant header files;
(run_file_in_terminal): second integer argument, run file, demos or
tests depending on this argument
* main-window.h: run_file_in_terminal with second argument
author | Torsten Lilge <ttl-octave@mailbox.org> |
---|---|
date | Sat, 04 May 2024 16:44:52 +0200 |
parents | 6813c5c7e1b9 |
children | a22f385de6ba |
files | libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h libgui/src/gui-preferences-global.h libgui/src/gui-preferences-sc.cc libgui/src/gui-preferences-sc.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/main-window.cc libgui/src/main-window.h |
diffstat | 11 files changed, 90 insertions(+), 27 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/files-dock-widget.cc Sat May 04 16:44:52 2024 +0200 @@ -872,7 +872,7 @@ QModelIndex index = rows[0]; QFileInfo info = m_file_system_model->fileInfo (index); - emit run_file_signal (info); + emit run_file_signal (info, ED_RUN_FILE); } }
--- a/libgui/src/files-dock-widget.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/files-dock-widget.h Sat May 04 16:44:52 2024 +0200 @@ -79,7 +79,7 @@ //! Emitted, whenever the user requested to run a file. - void run_file_signal (const QFileInfo& info); + void run_file_signal (const QFileInfo& info, int ops); //! Emitted, whenever wants to search for a file .
--- a/libgui/src/gui-preferences-global.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/gui-preferences-global.h Sat May 04 16:44:52 2024 +0200 @@ -134,6 +134,15 @@ "Fusion-Dark" }; +// Different modes for running a file from editor +enum +{ + ED_RUN_FILE = 0, + ED_STEP_INTO, + ED_RUN_TESTS, + ED_RUN_DEMOS +}; + #if defined (Q_OS_MAC) // prevent native file dialogs on MAC by setting the default "false" and // setting the flag for ignoring the pref to "true" (3rd argument)
--- a/libgui/src/gui-preferences-sc.cc Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/gui-preferences-sc.cc Sat May 04 16:44:52 2024 +0200 @@ -205,6 +205,8 @@ // run sc_pref sc_edit_run_run_file (QCoreApplication::translate ("shortcuts", "Run File"), sc_edit_run + ":run_file", OCTAVE_QT_KEYCOMBINATION (PRE, Qt::Key_F5)); sc_pref sc_edit_run_run_selection (QCoreApplication::translate ("shortcuts", "Run Selection"), sc_edit_run + ":run_selection", OCTAVE_QT_KEYCOMBINATION (PRE, Qt::Key_F9)); +sc_pref sc_edit_run_run_tests (QCoreApplication::translate ("shortcuts", "Run Tests"), sc_edit_run + ":run_file", OCTAVE_QT_KEYCOMBINATION (CTRL, Qt::Key_F5)); +sc_pref sc_edit_run_run_demos (QCoreApplication::translate ("shortcuts", "Run Demos"), sc_edit_run + ":run_file", OCTAVE_QT_KEYCOMBINATION (CTRL_SHIFT, Qt::Key_F5)); // help sc_pref sc_edit_help_help_keyword (QCoreApplication::translate ("shortcuts", "Help on Keyword"), sc_edit_help + ":help_keyword", QKeySequence::HelpContents);
--- a/libgui/src/gui-preferences-sc.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/gui-preferences-sc.h Sat May 04 16:44:52 2024 +0200 @@ -255,6 +255,8 @@ const QString sc_edit_run ("editor_run"); extern sc_pref sc_edit_run_run_file; extern sc_pref sc_edit_run_run_selection; +extern sc_pref sc_edit_run_run_tests; +extern sc_pref sc_edit_run_run_demos; // help const QString sc_edit_help ("editor_help");
--- a/libgui/src/m-editor/file-editor-tab.cc Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/m-editor/file-editor-tab.cc Sat May 04 16:44:52 2024 +0200 @@ -68,13 +68,14 @@ #include <Qsci/qscilexerperl.h> #include <Qsci/qsciprinter.h> -#include "file-editor-tab.h" -#include "file-editor.h" #include "gui-preferences-cs.h" #include "gui-preferences-ed.h" #include "gui-preferences-global.h" #include "gui-settings.h" #include "gui-utils.h" +#include "main-window.h" +#include "file-editor-tab.h" +#include "file-editor.h" #include "marker.h" #include "octave-txt-lexer.h" @@ -1091,7 +1092,7 @@ } void -file_editor_tab::run_file (const QWidget *ID, bool step_into) +file_editor_tab::run_file (const QWidget *ID, int opts) { if (ID != this) return; @@ -1107,7 +1108,9 @@ return; } - if (step_into) + int actual_opts = opts; + + if (opts == ED_STEP_INTO) { // Get current first breakpoint and set breakpoint waiting for // the returned line number. Store whether to remove this breakpoint @@ -1121,10 +1124,11 @@ // Add breakpoint, storing its line number handle_request_add_breakpoint (1, QString ()); + actual_opts = ED_RUN_FILE; } QFileInfo info (m_file_name); - emit run_file_signal (info); + emit run_file_signal (info, actual_opts); } void
--- a/libgui/src/m-editor/file-editor-tab.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/m-editor/file-editor-tab.h Sat May 04 16:44:52 2024 +0200 @@ -82,7 +82,7 @@ void mru_add_file (const QString& file_name, const QString& encoding); void editor_check_conflict_save (const QString& saveFileName, bool remove_on_success); - void run_file_signal (const QFileInfo& info); + void run_file_signal (const QFileInfo& info, int opts); void request_open_file (const QString&, const QString& = QString ()); void edit_mfile_request (const QString&, const QString&, const QString&, int); @@ -150,7 +150,7 @@ bool remove_on_success); void save_file_as (const QWidget *ID); void print_file (const QWidget *ID); - void run_file (const QWidget *ID, bool step_into = false); + void run_file (const QWidget *ID, int opts); void context_run (const QWidget *ID); void toggle_bookmark (const QWidget *ID); void next_bookmark (const QWidget *ID);
--- a/libgui/src/m-editor/file-editor.cc Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/m-editor/file-editor.cc Sat May 04 16:44:52 2024 +0200 @@ -46,10 +46,10 @@ #include <QVBoxLayout> #include <Qsci/qscicommandset.h> +#include "gui-preferences-global.h" #include "file-editor.h" #include "gui-preferences-ed.h" #include "gui-preferences-sc.h" -#include "gui-preferences-global.h" #include "gui-settings.h" #include "main-window.h" @@ -714,7 +714,7 @@ } void -file_editor::request_run_file (bool) +file_editor::run_file (bool, int opts) { // The interpreter_event callback function below emits a signal. // Because we don't control when that happens, use a guarded pointer @@ -723,7 +723,7 @@ QPointer<file_editor> this_fe (this); emit interpreter_event - ([this, this_fe] (interpreter& interp) + ([this, this_fe, opts] (interpreter& interp) { // INTERPRETER THREAD @@ -745,14 +745,32 @@ if (tw.in_debug_repl ()) emit request_dbcont_signal (); else - emit fetab_run_file (m_tab_widget->currentWidget ()); + emit fetab_run_file (m_tab_widget->currentWidget (), opts); }); } void +file_editor::request_run_file (bool) +{ + run_file (true, ED_RUN_FILE); +} + +void +file_editor::request_run_tests (bool) +{ + run_file (true, ED_RUN_TESTS); +} + +void +file_editor::request_run_demos (bool) +{ + run_file (true, ED_RUN_DEMOS); +} + +void file_editor::request_step_into_file () { - emit fetab_run_file (m_tab_widget->currentWidget (), true); + emit fetab_run_file (m_tab_widget->currentWidget (), ED_STEP_INTO); } void @@ -1559,6 +1577,8 @@ // Run menu settings.set_shortcut (m_run_action, sc_edit_run_run_file); settings.set_shortcut (m_run_selection_action, sc_edit_run_run_selection); + settings.set_shortcut (m_run_tests_action, sc_edit_run_run_tests); + settings.set_shortcut (m_run_demos_action, sc_edit_run_run_demos); // Help menu settings.set_shortcut (m_context_help_action, sc_edit_help_help_keyword); @@ -2430,6 +2450,16 @@ SLOT (request_context_run (bool))); m_run_selection_action->setEnabled (false); + m_run_tests_action + = add_action (_run_menu, + tr ("Run All &Tests in File"), + SLOT (request_run_tests (bool))); + + m_run_demos_action + = add_action (_run_menu, + tr ("Run All &Demos in File"), + SLOT (request_run_demos (bool))); + // help menu QMenu *_help_menu = add_menu (m_menu_bar, tr ("&Help"));
--- a/libgui/src/m-editor/file-editor.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/m-editor/file-editor.h Sat May 04 16:44:52 2024 +0200 @@ -140,7 +140,7 @@ void fetab_save_file (const QWidget *ID); void fetab_save_file_as (const QWidget *ID); void fetab_print_file (const QWidget *ID); - void fetab_run_file (const QWidget *ID, bool step_into = false); + void fetab_run_file (const QWidget *ID, int opts); void fetab_context_run (const QWidget *ID); void fetab_toggle_bookmark (const QWidget *ID); void fetab_next_bookmark (const QWidget *ID); @@ -188,7 +188,7 @@ void update_gui_lexer_signal (bool); void execute_command_in_terminal_signal (const QString&); void focus_console_after_command_signal (); - void run_file_signal (const QFileInfo&); + void run_file_signal (const QFileInfo&, int opts); void edit_mfile_request (const QString&, const QString&, const QString&, int); void debug_quit_signal (); @@ -222,6 +222,8 @@ void request_save_file (bool); void request_save_file_as (bool); void request_run_file (bool); + void request_run_tests (bool); + void request_run_demos (bool); void request_step_into_file (); void request_context_run (bool); void request_toggle_bookmark (bool); @@ -321,6 +323,8 @@ void request_preferences (bool); void request_styles_preferences (bool); + void run_file (bool, int opts); + void show_line_numbers (bool); void show_white_space (bool); void show_eol_chars (bool); @@ -441,6 +445,8 @@ QAction *m_print_action; QAction *m_run_action; QAction *m_run_selection_action; + QAction *m_run_tests_action; + QAction *m_run_demos_action; QAction *m_edit_function_action; QAction *m_popdown_mru_action;
--- a/libgui/src/main-window.cc Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/main-window.cc Sat May 04 16:44:52 2024 +0200 @@ -56,10 +56,6 @@ // QTerminal includes #include "QTerminal.h" -#if defined (HAVE_QSCINTILLA) -# include "file-editor.h" -# include "command-widget.h" -#endif #include "gui-preferences-cs.h" #include "gui-preferences-dw.h" #include "gui-preferences-ed.h" @@ -68,6 +64,10 @@ #include "gui-preferences-nr.h" #include "gui-preferences-sc.h" #include "gui-settings.h" +#if defined (HAVE_QSCINTILLA) +# include "file-editor.h" +# include "command-widget.h" +#endif #include "gui-utils.h" #include "interpreter-qobject.h" #include "main-window.h" @@ -1191,10 +1191,10 @@ } void -main_window::run_file_in_terminal (const QFileInfo& info) +main_window::run_file_in_terminal (const QFileInfo& info, int opts) { emit interpreter_event - ([info] (interpreter& interp) + ([info, opts] (interpreter& interp) { // INTERPRETER THREAD @@ -1221,16 +1221,26 @@ std::string path = info.absolutePath ().toStdString (); if (lp.contains_file_in_dir (file_path, path)) - command_editor::replace_line (function_name.toStdString ()); + { + QString cmd; + if (opts == ED_RUN_TESTS) + cmd = "test "; + else if (opts == ED_RUN_DEMOS) + cmd = "demo "; + cmd = cmd + function_name; + command_editor::replace_line (cmd.toStdString ()); + } } else { // No valid identifier: use equivalent of Fsource (), no // debug possible. - interp.source_file (file_path); - - command_editor::replace_line (""); + if (opts == ED_RUN_FILE) + { + interp.source_file (file_path); + command_editor::replace_line (""); + } } command_editor::set_initial_input (pending_input);
--- a/libgui/src/main-window.h Fri May 03 16:04:05 2024 +0200 +++ b/libgui/src/main-window.h Sat May 04 16:44:52 2024 +0200 @@ -173,7 +173,7 @@ void accept_directory_line_edit (); void execute_command_in_terminal (const QString& dir); - void run_file_in_terminal (const QFileInfo& info); + void run_file_in_terminal (const QFileInfo& info, int opts); void handle_new_figure_request ();