GNU Octave  6.2.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
main-window.h
Go to the documentation of this file.
1 ////////////////////////////////////////////////////////////////////////
2 //
3 // Copyright (C) 2011-2021 The Octave Project Developers
4 //
5 // See the file COPYRIGHT.md in the top-level directory of this
6 // distribution or <https://octave.org/copyright/>.
7 //
8 // This file is part of Octave.
9 //
10 // Octave is free software: you can redistribute it and/or modify it
11 // under the terms of the GNU General Public License as published by
12 // the Free Software Foundation, either version 3 of the License, or
13 // (at your option) any later version.
14 //
15 // Octave is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with Octave; see the file COPYING. If not, see
22 // <https://www.gnu.org/licenses/>.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 
26 #if ! defined (octave_main_window_h)
27 #define octave_main_window_h 1
28 
29 // Qt includes
30 #include <QCloseEvent>
31 #include <QComboBox>
32 #include <QMainWindow>
33 #include <QPointer>
34 #include <QQueue>
35 #include <QStatusBar>
36 #include <QTabWidget>
37 #include <QThread>
38 #include <QToolBar>
39 #include <QToolButton>
40 #include <QTranslator>
41 
42 // Editor includes
44 #include "file-editor-interface.h"
45 
46 // QTerminal includes
47 #include "QTerminal.h"
48 
49 // Own includes
50 #include "dialog.h"
52 #include "files-dock-widget.h"
53 #include "find-files-dialog.h"
54 #include "history-dock-widget.h"
55 #include "interpreter-qobject.h"
56 #include "octave-dock-widget.h"
57 #include "octave-qobject.h"
58 #include "qt-interpreter-events.h"
59 #include "set-path-dialog.h"
60 #include "terminal-dock-widget.h"
61 #include "variable-editor.h"
62 #include "workspace-model.h"
63 #include "workspace-view.h"
64 
65 class octave_value;
66 
67 namespace octave
68 {
69  class interpreter;
70 
71  class settings_dialog;
72 
73  //! Represents the main window.
74 
75  class main_window : public QMainWindow
76  {
77  Q_OBJECT
78 
79  public:
80 
81  typedef std::pair <std::string, std::string> name_pair;
82  typedef std::pair <int, int> int_pair;
83 
84  main_window (base_qobject& oct_qobj);
85 
86  ~main_window (void);
87 
88  bool command_window_has_focus (void) const;
89 
90  void focus_command_window (void);
91 
92  bool confirm_shutdown (void);
93 
94  signals:
95 
97  void editor_focus_changed (bool);
98 
101  void new_file_signal (const QString&);
102  void open_file_signal (const QString&);
103  void open_file_signal (const QString& file, const QString& enc, int line);
105 
106  void show_doc_signal (const QString&);
107  void register_doc_signal (const QString&);
108  void unregister_doc_signal (const QString&);
109 
110  void insert_debugger_pointer_signal (const QString& file, int line);
111  void delete_debugger_pointer_signal (const QString& file, int line);
112  void update_breakpoint_marker_signal (bool insert, const QString& file,
113  int line, const QString& cond);
114 
115  void copyClipboard_signal (void);
117  void selectAll_signal (void);
118  void undo_signal (void);
119 
121 
123 
124  void interpreter_event (const fcn_callback& fcn);
125  void interpreter_event (const meth_callback& meth);
126 
127  public slots:
128 
129  void focus_changed (QWidget *w_old, QWidget *w_new);
130  void focus_window (const QString& win_name);
131  void request_reload_settings (void);
132 
133  void report_status_message (const QString& statusMessage);
134  void handle_save_workspace_request (void);
135  void handle_load_workspace_request (const QString& file = QString ());
136  void handle_open_any_request (const QString& file = QString ());
137  void handle_clear_workspace_request (void);
139  void handle_clear_history_request (void);
140  void handle_undo_request (void);
141  void handle_rename_variable_request (const QString& old_name,
142  const QString& new_name);
143  void modify_path (const octave_value_list& dir_list, bool rm, bool subdirs);
144  void new_file (const QString& commands = QString ());
145  void open_file (const QString& file_name = QString (), int line = -1);
146  void edit_mfile (const QString&, int);
147  void file_remove_proxy (const QString& o, const QString& n);
148  void open_online_documentation_page (void);
149  void display_release_notes (void);
150  void load_and_display_community_news (int serial = -1);
151  void display_community_news (const QString& news);
152  void open_bug_tracker_page (void);
153  void open_octave_packages_page (void);
154  void open_contribute_page (void);
155  void open_donate_page (void);
156  void process_settings_dialog_request (const QString& desired_tab
157  = QString ());
158 
159  void show_about_octave (void);
161  bool update_by_worker = false);
162  void prepare_to_exit (void);
163  void go_to_previous_widget (void);
164  void reset_windows (void);
165  void do_reset_windows (bool show_it = true);
166 
167  void update_octave_directory (const QString& dir);
168  void browse_for_directory (void);
169  void set_current_working_directory (const QString& dir);
170  void change_directory_up (void);
171  void accept_directory_line_edit (void);
172 
173  void execute_command_in_terminal (const QString& dir);
174  void run_file_in_terminal (const QFileInfo& info);
175 
176  void handle_new_figure_request (void);
177 
178  void handle_enter_debugger (void);
179  void handle_exit_debugger (void);
180  void debug_continue (void);
181  void debug_step_into (void);
182  void debug_step_over (void);
183  void debug_step_out (void);
184  void debug_quit (void);
185  void editor_tabs_changed (bool);
186 
187  void request_open_file (void);
188  void request_new_script (const QString& commands = QString ());
189  void request_new_function (bool triggered = true);
190  void handle_edit_mfile_request (const QString& name, const QString& file,
191  const QString& curr_dir, int line);
192 
193  void handle_insert_debugger_pointer_request (const QString& file, int line);
194  void handle_delete_debugger_pointer_request (const QString& file, int line);
195  void handle_update_breakpoint_marker_request (bool insert,
196  const QString& file, int line,
197  const QString& cond);
198 
199  void read_settings (void);
200  void init_terminal_size (void);
202  void write_settings (void);
203  void connect_visibility_changed (void);
204 
205  void copyClipboard (void);
206  void pasteClipboard (void);
207  void selectAll (void);
208 
209  void focus_console_after_command (void);
210  void handle_show_doc (const QString& file);
211  void handle_register_doc (const QString& file);
212  void handle_unregister_doc (const QString& file);
213 
214  void handle_octave_ready ();
215 
216  void handle_set_path_dialog_request (void);
217 
218  //! Find files dialog.
219  //!@{
220  void find_files (const QString& startdir = QDir::currentPath ());
221  void find_files_finished (int) { }
222  //!@}
223 
224  //! Setting global shortcuts.
225 
226  void set_global_shortcuts (bool enable);
227 
228  void set_screen_size (int ht, int wd);
229 
230  //! Handling the clipboard.
231  //!@{
232  void clipboard_has_changed (void);
233  void clear_clipboard ();
234  //!@}
235 
236  //! Returns a list of dock widgets.
237 
239  {
240  return dock_widget_list ();
241  }
242 
243  private slots:
244 
245  void disable_menu_shortcuts (bool disable);
246  void restore_create_file_setting (void);
247  void set_file_encoding (const QString& new_encoding);
248  void request_open_files (const QStringList& open_file_names);
249 
250  void warning_function_not_found (const QString& message);
251 
252  //! Opens the variable editor for @p name.
253 
254  void edit_variable (const QString &name, const octave_value&);
255 
256  void refresh_variable_editor (void);
257 
258  void handle_variable_editor_update (void);
259 
260  protected:
261 
262  void closeEvent (QCloseEvent *closeEvent);
263 
264  private:
265 
266  void construct_central_widget (void);
267 
268  void construct (void);
269 
270  void construct_octave_qt_link (void);
271 
272  QAction * add_action (QMenu *menu, const QIcon& icon,
273  const QString& text, const char *member,
274  const QWidget *receiver = nullptr);
275 
276  QMenu * m_add_menu (QMenuBar *p, QString text);
277  void construct_menu_bar (void);
278  void construct_file_menu (QMenuBar *p);
279  void construct_new_menu (QMenu *p);
280  void construct_edit_menu (QMenuBar *p);
281  QAction * construct_debug_menu_item (const char *icon, const QString& item,
282  const char *member);
283  void construct_debug_menu (QMenuBar *p);
284  QAction * construct_window_menu_item (QMenu *p, const QString& item,
285  bool checkable, QWidget*);
287  void construct_help_menu (QMenuBar *p);
289 
290  void construct_news_menu (QMenuBar *p);
291 
292  void construct_tool_bar (void);
293 
294  void configure_shortcuts (void);
295 
297 
298  void update_default_encoding (const QString& default_encoding);
299 
300  void get_screen_geometry (int *width, int *height);
301  void set_default_geometry (void);
302  void resize_dock (QDockWidget *dw, int width, int height);
303 
305 
307 
308  QHash<QMenu*, QStringList> m_hash_menu_text;
309 
311 
313 
314  //! Toolbar.
315 
316  QStatusBar *m_status_bar;
317 
318  //! Dock widgets.
319  //!@{
327  //!@}
328 
331 
334 
336 
337  QToolBar *m_main_tool_bar;
338 
340 
345  QAction *m_debug_quit;
346 
349  QAction *m_open_action;
355  QAction *m_exit_action;
356 
357  QAction *m_copy_action;
358  QAction *m_paste_action;
360  QAction *m_undo_action;
366 
378  QAction *m_editor_action;
383 
391 
394 
395  //! For Toolbars.
396  //!@{
398  static const int current_directory_max_visible = 16;
399  static const int current_directory_max_count = 16;
401  //!@}
402 
403  //! Settings dialog as guarded pointer (set to 0 when deleted).
404 
405  QPointer<settings_dialog> m_settings_dlg;
406 
407  //! Find files dialog.
408 
410 
411  //! Set path dialog
412  QPointer<set_path_dialog> m_set_path_dlg;
413 
414  //! Release notes window.
415 
417 
419 
420  QClipboard *m_clipboard;
421 
422  //! Some class global flags.
423  //!@{
427 
428  //! Flag for closing the whole application.
429 
430  bool m_closing;
431  //!@}
432 
434  };
435 }
436 
437 #endif
Base class for Octave interfaces that use Qt.
Dock widget to display files in the current directory.
Represents the main window.
Definition: main-window.h:76
void debug_step_over(void)
QAction * m_reset_windows_action
Definition: main-window.h:382
bool command_window_has_focus(void) const
Definition: main-window.cc:262
void construct_edit_menu(QMenuBar *p)
void handle_update_breakpoint_marker_request(bool insert, const QString &file, int line, const QString &cond)
QAction * m_save_workspace_action
Definition: main-window.h:352
void construct_window_menu(QMenuBar *p)
void change_directory_up(void)
void warning_function_not_found(const QString &message)
QAction * m_new_function_action
Definition: main-window.h:348
void file_remove_proxy(const QString &o, const QString &n)
Definition: main-window.cc:601
octave_dock_widget * m_previous_dock
Definition: main-window.h:332
QAction * m_ondisk_doc_action
Definition: main-window.h:384
bool m_prevent_readline_conflicts
Some class global flags.
Definition: main-window.h:424
static const int current_directory_max_count
For Toolbars.
Definition: main-window.h:399
external_editor_interface * m_external_editor
Definition: main-window.h:329
QAction * m_release_notes_action
Definition: main-window.h:392
QAction * m_show_workspace_action
Definition: main-window.h:369
QAction * m_documentation_action
Definition: main-window.h:379
QAction * m_copy_action
Definition: main-window.h:357
void construct_help_menu(QMenuBar *p)
QAction * m_octave_packages_action
Definition: main-window.h:387
void handle_exit_debugger(void)
QAction * m_clear_clipboard_action
Definition: main-window.h:359
void report_status_message(const QString &statusMessage)
Definition: main-window.cc:387
QAction * m_show_variable_editor_action
Definition: main-window.h:373
void settings_changed(const gui_settings *)
QStatusBar * m_status_bar
Toolbar.
Definition: main-window.h:316
void interpreter_event(const meth_callback &meth)
void notice_settings(const gui_settings *settings, bool update_by_worker=false)
Definition: main-window.cc:827
QList< octave_dock_widget * > get_dock_widget_list(void)
Returns a list of dock widgets.
Definition: main-window.h:238
void undo_signal(void)
octave_dock_widget * m_active_dock
Definition: main-window.h:333
QAction * m_show_file_browser_action
Definition: main-window.h:370
void set_window_layout(gui_settings *settings)
QAction * m_about_octave_action
Definition: main-window.h:390
void do_reset_windows(bool show_it=true)
QPointer< set_path_dialog > m_set_path_dlg
Set path dialog.
Definition: main-window.h:412
void handle_clear_command_window_request(void)
Definition: main-window.cc:485
QAction * m_previous_dock_action
Definition: main-window.h:381
QPointer< settings_dialog > m_settings_dlg
Settings dialog as guarded pointer (set to 0 when deleted).
Definition: main-window.h:405
QAction * m_editor_action
Definition: main-window.h:378
void handle_save_workspace_request(void)
Definition: main-window.cc:392
void handle_clear_workspace_request(void)
Definition: main-window.cc:474
void set_current_working_directory(const QString &dir)
Definition: main-window.cc:995
QString m_release_notes_icon
Definition: main-window.h:335
bool m_suppress_dbg_location
Some class global flags.
Definition: main-window.h:425
find_files_dialog * m_find_files_dlg
Find files dialog.
Definition: main-window.h:409
history_dock_widget * m_history_window
Dock widgets.
Definition: main-window.h:321
void construct_tool_bar(void)
void find_files_finished(int)
Find files dialog.
Definition: main-window.h:221
QLineEdit * m_current_directory_line_edit
For Toolbars.
Definition: main-window.h:400
bool m_closing
Flag for closing the whole application.
Definition: main-window.h:430
void construct_documentation_menu(QMenu *p)
void new_file(const QString &commands=QString())
Definition: main-window.cc:583
void handle_open_any_request(const QString &file=QString())
Definition: main-window.cc:450
QAction * m_history_action
Definition: main-window.h:375
void clear_clipboard()
Handling the clipboard.
void focus_command_window(void)
Definition: main-window.cc:267
QAction * m_developer_action
Definition: main-window.h:389
static const int current_directory_max_visible
For Toolbars.
Definition: main-window.h:398
QAction * m_select_all_action
Definition: main-window.h:365
QAction * m_command_window_action
Definition: main-window.h:374
void construct_debug_menu(QMenuBar *p)
void load_and_display_community_news(int serial=-1)
Definition: main-window.cc:690
void init_terminal_size(void)
void handle_clear_history_request(void)
Definition: main-window.cc:497
void show_doc_signal(const QString &)
void handle_show_doc(const QString &file)
QAction * m_preferences_action
Definition: main-window.h:354
workspace_model * m_workspace_model
Definition: main-window.h:306
void run_file_in_terminal(const QFileInfo &info)
void handle_rename_variable_request(const QString &old_name, const QString &new_name)
Definition: main-window.cc:527
void accept_directory_line_edit(void)
void handle_set_path_dialog_request(void)
void focus_console_after_command(void)
terminal_dock_widget * m_command_window
Dock widgets.
Definition: main-window.h:320
QAction * m_find_files_action
Definition: main-window.h:364
void modify_path(const octave_value_list &dir_list, bool rm, bool subdirs)
Definition: main-window.cc:557
QAction * m_debug_step_out
Definition: main-window.h:344
void focus_changed(QWidget *w_old, QWidget *w_new)
Definition: main-window.cc:313
void write_settings(void)
void construct_central_widget(void)
void request_open_file(void)
workspace_view * m_workspace_window
Dock widgets.
Definition: main-window.h:325
QClipboard * m_clipboard
Definition: main-window.h:420
void editor_focus_changed(bool)
QAction * m_undo_action
Definition: main-window.h:360
QToolBar * m_main_tool_bar
Definition: main-window.h:337
void interpreter_event(const fcn_callback &fcn)
void warning_function_not_found_signal(const QString &message)
void request_new_function(bool triggered=true)
documentation_dock_widget * m_doc_browser_window
Dock widgets.
Definition: main-window.h:323
QAction * m_show_documentation_action
Definition: main-window.h:372
QAction * m_open_action
Definition: main-window.h:349
void open_bug_tracker_page(void)
Definition: main-window.cc:778
void request_new_script(const QString &commands=QString())
QAction * m_clear_command_window_action
Definition: main-window.h:361
void new_file_signal(const QString &)
QAction * m_contribute_action
Definition: main-window.h:388
void set_default_geometry(void)
void disable_menu_shortcuts(bool disable)
void handle_edit_mfile_request(const QString &name, const QString &file, const QString &curr_dir, int line)
bool confirm_shutdown(void)
Definition: main-window.cc:284
QAction * m_paste_action
Definition: main-window.h:358
main_window(base_qobject &oct_qobj)
Definition: main-window.cc:110
QAction * m_show_history_action
Definition: main-window.h:368
QAction * m_show_command_window_action
Definition: main-window.h:367
void handle_insert_debugger_pointer_request(const QString &file, int line)
void handle_unregister_doc(const QString &file)
QComboBox * m_current_directory_combo_box
For Toolbars.
Definition: main-window.h:397
void refresh_variable_editor(void)
void display_release_notes(void)
Definition: main-window.cc:629
QAction * m_online_doc_action
Definition: main-window.h:385
void editor_tabs_changed(bool)
void active_dock_changed(octave_dock_widget *, octave_dock_widget *)
file_editor_interface * m_editor_window
Dock widgets.
Definition: main-window.h:324
QAction * construct_debug_menu_item(const char *icon, const QString &item, const char *member)
void handle_register_doc(const QString &file)
void browse_for_directory(void)
Definition: main-window.cc:974
void update_default_encoding(const QString &default_encoding)
QAction * m_variable_editor_action
Definition: main-window.h:380
QAction * m_clear_workspace_action
Definition: main-window.h:363
void read_settings(void)
QHash< QMenu *, QStringList > m_hash_menu_text
Definition: main-window.h:308
void handle_new_figure_request(void)
void construct_file_menu(QMenuBar *p)
void open_octave_packages_page(void)
Definition: main-window.cc:783
QAction * m_file_browser_action
Definition: main-window.h:377
void open_file(const QString &file_name=QString(), int line=-1)
Definition: main-window.cc:588
void open_contribute_page(void)
Definition: main-window.cc:788
void pasteClipboard(void)
void construct_news_menu(QMenuBar *p)
void focus_window(const QString &win_name)
Definition: main-window.cc:272
QAction * m_debug_step_over
Definition: main-window.h:343
void update_breakpoint_marker_signal(bool insert, const QString &file, int line, const QString &cond)
QList< octave_dock_widget * > dock_widget_list(void)
std::pair< int, int > int_pair
Definition: main-window.h:82
QAction * m_load_workspace_action
Definition: main-window.h:351
variable_editor * m_variable_editor_window
Dock widgets.
Definition: main-window.h:326
void add_actions_signal(QList< QAction * > action_list)
void debug_step_into(void)
void edit_mfile(const QString &, int)
Definition: main-window.cc:596
QString m_default_encoding
Definition: main-window.h:310
void step_into_file_signal(void)
QAction * m_clear_command_history_action
Definition: main-window.h:362
void handle_enter_debugger(void)
void register_doc_signal(const QString &)
void set_file_encoding(const QString &new_encoding)
QAction * m_new_figure_action
Definition: main-window.h:350
QAction * m_report_bug_action
Definition: main-window.h:386
QWidget * m_release_notes_window
Release notes window.
Definition: main-window.h:416
void construct_new_menu(QMenu *p)
void handle_variable_editor_update(void)
QAction * m_debug_continue
Definition: main-window.h:341
void configure_shortcuts(void)
void clipboard_has_changed(void)
Handling the clipboard.
void debug_continue(void)
QAction * m_exit_action
Definition: main-window.h:355
base_qobject & m_octave_qobj
Definition: main-window.h:304
std::pair< std::string, std::string > name_pair
Definition: main-window.h:81
void pasteClipboard_signal(void)
QAction * add_action(QMenu *menu, const QIcon &icon, const QString &text, const char *member, const QWidget *receiver=nullptr)
QAction * m_current_news_action
Definition: main-window.h:393
files_dock_widget * m_file_browser_window
Dock widgets.
Definition: main-window.h:322
QAction * m_set_path_action
Definition: main-window.h:353
void execute_command_in_terminal(const QString &dir)
void display_community_news(const QString &news)
Definition: main-window.cc:726
void handle_delete_debugger_pointer_request(const QString &file, int line)
void find_files(const QString &startdir=QDir::currentPath())
Find files dialog.
void open_file_signal(const QString &file, const QString &enc, int line)
QAction * m_show_editor_action
Definition: main-window.h:371
void get_screen_geometry(int *width, int *height)
void resize_dock(QDockWidget *dw, int width, int height)
QWidget * m_active_editor
Definition: main-window.h:330
void reset_windows(void)
QWidget * m_community_news_window
Definition: main-window.h:418
void connect_visibility_changed(void)
void selectAll_signal(void)
QAction * m_new_script_action
Definition: main-window.h:347
void insert_debugger_pointer_signal(const QString &file, int line)
void show_about_octave(void)
Definition: main-window.cc:818
void copyClipboard(void)
void handle_load_workspace_request(const QString &file=QString())
Definition: main-window.cc:417
void request_reload_settings(void)
Definition: main-window.cc:378
void restore_create_file_setting(void)
void construct_octave_qt_link(void)
void open_donate_page(void)
Definition: main-window.cc:793
void update_octave_directory(const QString &dir)
Definition: main-window.cc:959
void handle_undo_request(void)
Definition: main-window.cc:510
bool m_editor_has_tabs
Some class global flags.
Definition: main-window.h:426
void request_open_files(const QStringList &open_file_names)
void closeEvent(QCloseEvent *closeEvent)
void set_screen_size(int ht, int wd)
void process_settings_dialog_request(const QString &desired_tab=QString())
Definition: main-window.cc:798
void open_online_documentation_page(void)
Definition: main-window.cc:623
void delete_debugger_pointer_signal(const QString &file, int line)
void copyClipboard_signal(void)
void debug_step_out(void)
void edit_variable(const QString &name, const octave_value &)
Opens the variable editor for name.
void unregister_doc_signal(const QString &)
void prepare_to_exit(void)
Definition: main-window.cc:940
void construct_menu_bar(void)
QAction * m_debug_quit
Definition: main-window.h:345
void go_to_previous_widget(void)
Definition: main-window.cc:954
void set_global_shortcuts(bool enable)
Setting global shortcuts.
void init_terminal_size_signal(void)
void open_file_signal(const QString &)
QAction * m_debug_step_into
Definition: main-window.h:342
QAction * m_workspace_action
Definition: main-window.h:376
QMenu * m_add_menu(QMenuBar *p, QString text)
QAction * construct_window_menu_item(QMenu *p, const QString &item, bool checkable, QWidget *)
void message(const char *name, const char *fmt,...)
Definition: error.cc:936
QString name
octave_idx_type n
Definition: mx-inlines.cc:753
std::function< void(octave::interpreter &)> meth_callback
Definition: event-manager.h:47
std::function< void(void)> fcn_callback
Definition: event-manager.h:46