GNU Octave  4.0.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
main-window.h
Go to the documentation of this file.
1 /*
2 
3 Copyright (C) 2013-2015 John W. Eaton
4 Copyright (C) 2011-2015 Jacob Dawid
5 
6 This file is part of Octave.
7 
8 Octave is free software; you can redistribute it and/or modify it
9 under the terms of the GNU General Public License as published by the
10 Free Software Foundation; either version 3 of the License, or (at your
11 option) any later version.
12 
13 Octave is distributed in the hope that it will be useful, but WITHOUT
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
16 for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Octave; see the file COPYING. If not, see
20 <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #if !defined (octave_main_window_h)
25 #define octave_main_window_h 1
26 
27 // Qt includes
28 #include <QMainWindow>
29 #include <QThread>
30 #include <QTabWidget>
31 #include <QMdiArea>
32 #include <QStatusBar>
33 #include <QToolBar>
34 #include <QQueue>
35 #include <QMdiSubWindow>
36 #include <QCloseEvent>
37 #include <QToolButton>
38 #include <QComboBox>
39 #include <QSemaphore>
40 #include <QPointer>
41 
42 // Editor includes
43 #include "file-editor-interface.h"
44 
45 // QTerminal includes
46 #include "QTerminal.h"
47 
48 // Own includes
49 #include "dialog.h"
50 #include "resource-manager.h"
51 #include "workspace-model.h"
52 #include "workspace-view.h"
53 #include "history-dock-widget.h"
54 #include "files-dock-widget.h"
55 #include "terminal-dock-widget.h"
57 #include "octave-qt-link.h"
58 #include "octave-dock-widget.h"
59 #include "find-files-dialog.h"
60 #include "octave-cmd.h"
61 
63 
64 /**
65  * @class MainWindow
66  *
67  * Represents the main window.
68  */
69 class main_window : public QMainWindow
70 {
71  Q_OBJECT
72 
73 public:
74 
75  typedef std::pair <std::string, std::string> name_pair;
76  typedef std::pair <int, int> int_pair;
77 
78  main_window (QWidget *parent = 0, bool start_gui = true);
79 
80  ~main_window (void);
81 
82  bool command_window_has_focus (void) const;
83 
84  void focus_command_window (void);
85 
86 signals:
87 
89  void editor_focus_changed (bool);
90 
91  void settings_changed (const QSettings *);
92  void init_terminal_size_signal (void);
93  void new_file_signal (const QString&);
94  void open_file_signal (const QString&);
95 
96  void show_doc_signal (const QString&);
97 
98  void insert_debugger_pointer_signal (const QString& file, int line);
99  void delete_debugger_pointer_signal (const QString& file, int line);
100  void update_breakpoint_marker_signal (bool insert, const QString& file,
101  int line);
102 
103  void copyClipboard_signal (void);
104  void pasteClipboard_signal (void);
105  void selectAll_signal (void);
106  void undo_signal (void);
107 
108  void add_actions_signal (QList <QAction *> action_list);
109 
110 public slots:
111 
112  void focus_changed (QWidget *w_old, QWidget *w_new);
113  void request_reload_settings ();
114 
115  void report_status_message (const QString& statusMessage);
116  void handle_save_workspace_request (void);
117  void handle_load_workspace_request (const QString& file = QString ());
119  void handle_clear_workspace_request (void);
120  void handle_clear_history_request (void);
121  void handle_rename_variable_request (const QString& old_name,
122  const QString& new_name);
123  void handle_undo_request (void);
124  void new_file (const QString& commands = QString ());
125  void open_file (const QString& file_name = QString ());
126  void open_online_documentation_page (void);
127  void display_release_notes (void);
128  void load_and_display_community_news (int serial = -1);
129  void display_community_news (const QString& news);
130  void open_bug_tracker_page (void);
131  void open_octave_packages_page (void);
132  void open_agora_page (void);
133  void open_contribute_page (void);
134  void open_developer_page (void);
135  void process_settings_dialog_request (const QString& desired_tab
136  = QString ());
137 
138  void copy_image_to_clipboard (const QString& file, bool remove_file);
139 
140  void show_about_octave (void);
141  void notice_settings (const QSettings *settings);
142  void confirm_shutdown_octave (void);
143  void prepare_to_exit (void);
144  void exit_app (int status);
145  void reset_windows (void);
146 
147  void change_directory (const QString& dir);
148  void browse_for_directory (void);
149  void set_current_working_directory (const QString& dir);
150  void change_directory_up (void);
151  void accept_directory_line_edit (void);
152 
153  void execute_command_in_terminal (const QString& dir);
154  void run_file_in_terminal (const QFileInfo& info);
155 
156  void handle_new_figure_request (void);
157 
158  void handle_enter_debugger (void);
159  void handle_exit_debugger (void);
160  void debug_continue (void);
161  void debug_step_into (void);
162  void debug_step_over (void);
163  void debug_step_out (void);
164  void debug_quit (void);
165 
166  void handle_insert_debugger_pointer_request (const QString& file, int line);
167  void handle_delete_debugger_pointer_request (const QString& file, int line);
168  void handle_update_breakpoint_marker_request (bool insert,
169  const QString& file, int line);
170 
171  void read_settings (void);
172  void init_terminal_size (void);
173  void set_window_layout (QSettings *settings);
174  void write_settings (void);
175  void connect_visibility_changed (void);
176 
177  void copyClipboard (void);
178  void pasteClipboard (void);
179  void selectAll (void);
180 
181  void connect_uiwidget_links (void);
182 
183  void handle_create_dialog (const QString& message, const QString& title,
184  const QString& icon, const QStringList& button,
185  const QString& defbutton,
186  const QStringList& role);
187 
188  void handle_create_listview (const QStringList& list, const QString& mode,
189  int width, int height,
190  const QIntList& initial,
191  const QString& name,
192  const QStringList& prompt,
193  const QString& ok_string,
194  const QString& cancel_string);
195 
196  void handle_create_inputlayout (const QStringList&, const QString&,
197  const QFloatList&, const QFloatList&,
198  const QStringList&);
199 
200  void handle_create_filedialog (const QStringList &filters,
201  const QString& title, const QString& filename,
202  const QString &dirname,
203  const QString& multimode);
204 
205  void handle_show_doc (const QString &file);
206 
207  void handle_octave_ready ();
208 
209  // find files dialog
210  void find_files (const QString &startdir=QDir::currentPath ());
211  void find_files_finished (int);
212 
213  // setting global shortcuts
214  void set_global_shortcuts (bool enable);
215  void set_global_edit_shortcuts (bool enable);
216 
217  void set_screen_size (int ht, int wd);
218 
219  // handling the clipboard
220  void clipboard_has_changed (QClipboard::Mode);
221  void clear_clipboard ();
222 
223  // get the dockwidgets
225  { return dock_widget_list (); }
226 
227 protected:
228  void closeEvent (QCloseEvent * closeEvent);
229 
230 private:
231 
232  void construct (void);
233 
234  void construct_octave_qt_link (void);
235 
236  QAction *add_action (QMenu *menu, const QIcon &icon, const QString &text,
237  const char *member, const QWidget *receiver = 0);
238 
239  void enable_menu_shortcuts (bool enable);
240  QMenu* m_add_menu (QMenuBar *p, QString text);
241  void construct_menu_bar (void);
242  void construct_file_menu (QMenuBar *p);
243  void construct_new_menu (QMenu *p);
244  void construct_edit_menu (QMenuBar *p);
245  QAction *construct_debug_menu_item (const char *icon, const QString& item,
246  const char* member);
247  void construct_debug_menu (QMenuBar *p);
248  QAction *construct_window_menu_item (QMenu *p, const QString& item,
249  bool checkable, QWidget*);
251  void construct_help_menu (QMenuBar *p);
252  void construct_documentation_menu (QMenu *p);
253 
254  void construct_news_menu (QMenuBar *p);
255 
256  void construct_tool_bar (void);
257 
258  void establish_octave_link (void);
259 
260  void save_workspace_callback (const std::string& file);
261 
262  void load_workspace_callback (const std::string& file);
263 
264  void rename_variable_callback (const name_pair& names);
265 
266  void command_window_undo_callback (void);
267 
268  void clear_command_window_callback (void);
269 
270  void resize_command_window_callback (void);
271 
272  void set_screen_size_callback (const int_pair&);
273 
274  void clear_workspace_callback (void);
275 
276  void clear_history_callback (void);
277 
278  void execute_command_callback ();
279  void run_file_callback (const QFileInfo& info);
281 
282  void new_figure_callback (void);
283 
284  void change_directory_callback (const std::string& directory);
285 
286  void queue_command (octave_cmd *cmd);
287 
288  void queue_debug (QString command);
289 
290  void execute_debug_callback ();
291 
292  void configure_shortcuts ();
293 
295 
296  QHash<QMenu*, QStringList> _hash_menu_text;
297 
298 
299  // Toolbars.
300  QStatusBar *status_bar;
301 
302  // Subwindows.
310  {
312  list.append (static_cast<octave_dock_widget *> (command_window));
313  list.append (static_cast<octave_dock_widget *> (history_window));
314  list.append (static_cast<octave_dock_widget *> (file_browser_window));
315  list.append (static_cast<octave_dock_widget *> (doc_browser_window));
316 #ifdef HAVE_QSCINTILLA
317  list.append (static_cast<octave_dock_widget *> (editor_window));
318 #endif
319  list.append (static_cast<octave_dock_widget *> (workspace_window));
320  return list;
321  }
323 
325 
326  QToolBar *_main_tool_bar;
327 
328  QMenu *_debug_menu;
329 
330  QAction *_debug_continue;
333  QAction *_debug_step_out;
334  QAction *_debug_quit;
335 
338  QAction *_open_action;
343  QAction *_exit_action;
344 
345  QAction *_copy_action;
346  QAction *_paste_action;
348  QAction *_undo_action;
354 
362  QAction *_history_action;
365  QAction *_editor_action;
368 
373  QAction *_agora_action;
377 
380 
381  // Toolbars.
383  static const int current_directory_max_visible = 16;
384  static const int current_directory_max_count = 16;
386 
387  // settings dialog as guarded pointer (set to 0 when deleted)
388  QPointer<settings_dialog> _settings_dlg;
389 
390  // Find files dialog
392 
393  // release notes window
395 
397 
399 
400  QClipboard *_clipboard;
401 
402  // Flag for closing whole application.
403  bool _closing;
404 
405  // command queue and semaphore to synchronize execution signals
406  // and related callback
407 
408  // the queue for the command structures
410  // semaphores used for handling the queue
411  QSemaphore _cmd_processing;
413 
414  // semaphore to synchronize debug signals and related callbacks
415  QStringList *_dbg_queue;
416  QSemaphore _dbg_processing;
418 
422 };
423 
424 class news_reader : public QObject
425 {
426  Q_OBJECT
427 
428 public:
429 
430  news_reader (const QString& xbase_url, const QString& xpage,
431  int xserial = -1, bool xconnect_to_web = false)
432  : QObject (), base_url (xbase_url), page (xpage), serial (xserial),
433  connect_to_web (xconnect_to_web)
434  { }
435 
436 public slots:
437 
438  void process (void);
439 
440 signals:
441 
442  void display_news_signal (const QString& news);
443 
444  void finished (void);
445 
446 private:
447 
448  QString base_url;
449  QString page;
450  int serial;
452 };
453 
454 #endif // MAINWINDOW_H
QAction * _clear_command_history_action
Definition: main-window.h:350
void show_about_octave(void)
void handle_octave_ready()
void handle_undo_request(void)
Definition: main-window.cc:294
QAction * _octave_packages_action
Definition: main-window.h:372
void reset_windows(void)
Definition: main-window.cc:841
QAction * _open_action
Definition: main-window.h:338
QAction * _online_doc_action
Definition: main-window.h:370
QAction * _paste_action
Definition: main-window.h:346
void clear_history_callback(void)
void execute_command_callback()
void request_reload_settings()
Definition: main-window.cc:694
void handle_insert_debugger_pointer_request(const QString &file, int line)
Definition: main-window.cc:983
QSemaphore _cmd_processing
Definition: main-window.h:411
static const int current_directory_max_visible
Definition: main-window.h:383
void debug_quit(void)
Definition: main-window.cc:977
void delete_debugger_pointer_signal(const QString &file, int line)
void pasteClipboard(void)
QAction * _documentation_action
Definition: main-window.h:366
QString base_url
Definition: main-window.h:448
QAction * _workspace_action
Definition: main-window.h:363
void queue_command(octave_cmd *cmd)
Definition: main-window.cc:346
void set_global_shortcuts(bool enable)
void construct_debug_menu(QMenuBar *p)
~main_window(void)
Definition: main-window.cc:131
void rename_variable_callback(const name_pair &names)
void read_settings(void)
terminal_dock_widget * command_window
Definition: main-window.h:303
void handle_create_inputlayout(const QStringList &, const QString &, const QFloatList &, const QFloatList &, const QStringList &)
void handle_create_filedialog(const QStringList &filters, const QString &title, const QString &filename, const QString &dirname, const QString &multimode)
void handle_clear_history_request(void)
Definition: main-window.cc:309
QAction * _reset_windows_action
Definition: main-window.h:367
void display_release_notes(void)
Definition: main-window.cc:369
void open_file(const QString &file_name=QString())
Definition: main-window.cc:239
void clear_clipboard()
QAction * _debug_step_into
Definition: main-window.h:331
QAction * _about_octave_action
Definition: main-window.h:376
QList< octave_dock_widget * > dock_widget_list()
Definition: main-window.h:309
bool command_window_has_focus(void) const
Definition: main-window.cc:221
bool _suppress_dbg_location
Definition: main-window.h:420
QAction * construct_window_menu_item(QMenu *p, const QString &item, bool checkable, QWidget *)
void selectAll(void)
void establish_octave_link(void)
void open_file_signal(const QString &)
void exit_app(int status)
Definition: main-window.cc:835
void copy_image_to_clipboard(const QString &file, bool remove_file)
Definition: main-window.cc:675
QMenu * m_add_menu(QMenuBar *p, QString text)
QAction * _command_window_action
Definition: main-window.h:361
void clear_command_window_callback(void)
void handle_load_workspace_request(const QString &file=QString())
Definition: main-window.cc:263
QAction * _show_documentation_action
Definition: main-window.h:360
static string_vector names(const map_type &lst)
Definition: help.cc:782
QAction * _report_bug_action
Definition: main-window.h:371
QAction * add_action(QMenu *menu, const QIcon &icon, const QString &text, const char *member, const QWidget *receiver=0)
void show_doc_signal(const QString &)
void confirm_shutdown_octave(void)
Definition: main-window.cc:792
QToolBar * _main_tool_bar
Definition: main-window.h:326
void display_community_news(const QString &news)
Definition: main-window.cc:580
void copyClipboard(void)
void write_settings(void)
void load_and_display_community_news(int serial=-1)
Definition: main-window.cc:544
octave_dock_widget * _active_dock
Definition: main-window.h:322
file_editor_interface * editor_window
Definition: main-window.h:307
void browse_for_directory(void)
Definition: main-window.cc:866
files_dock_widget * file_browser_window
Definition: main-window.h:305
QList< octave_cmd * > _cmd_queue
Definition: main-window.h:409
bool _prevent_readline_conflicts
Definition: main-window.h:419
workspace_view * workspace_window
Definition: main-window.h:308
void find_files_finished(int)
QAction * _preferences_action
Definition: main-window.h:342
QStatusBar * status_bar
Definition: main-window.h:300
void handle_clear_workspace_request(void)
Definition: main-window.cc:277
void change_directory_callback(const std::string &directory)
void update_breakpoint_marker_signal(bool insert, const QString &file, int line)
void construct(void)
QAction * _agora_action
Definition: main-window.h:373
QMutex _cmd_queue_mutex
Definition: main-window.h:412
news_reader(const QString &xbase_url, const QString &xpage, int xserial=-1, bool xconnect_to_web=false)
Definition: main-window.h:430
void accept_directory_line_edit(void)
Definition: main-window.cc:906
void message(const char *name, const char *fmt,...)
Definition: error.cc:380
void resize_command_window_callback(void)
workspace_model * _workspace_model
Definition: main-window.h:294
QAction * _clear_clipboard_action
Definition: main-window.h:347
void set_screen_size(int ht, int wd)
void debug_step_into(void)
Definition: main-window.cc:959
void construct_octave_qt_link(void)
void handle_create_dialog(const QString &message, const QString &title, const QString &icon, const QStringList &button, const QString &defbutton, const QStringList &role)
void command_window_undo_callback(void)
QHash< QMenu *, QStringList > _hash_menu_text
Definition: main-window.h:296
void handle_exit_debugger(void)
Definition: main-window.cc:937
void open_octave_packages_page(void)
Definition: main-window.cc:631
void change_directory(const QString &dir)
Definition: main-window.cc:850
documentation_dock_widget * doc_browser_window
Definition: main-window.h:306
void finished(void)
void handle_create_listview(const QStringList &list, const QString &mode, int width, int height, const QIntList &initial, const QString &name, const QStringList &prompt, const QString &ok_string, const QString &cancel_string)
bool connect_to_web
Definition: main-window.h:451
void settings_changed(const QSettings *)
QAction * _copy_action
Definition: main-window.h:345
void notice_settings(const QSettings *settings)
Definition: main-window.cc:703
QAction * _debug_step_over
Definition: main-window.h:332
QAction * _contribute_action
Definition: main-window.h:374
void connect_visibility_changed(void)
QAction * _new_script_action
Definition: main-window.h:336
void execute_command_in_terminal(const QString &dir)
Definition: main-window.cc:322
void clipboard_has_changed(QClipboard::Mode)
QComboBox * _current_directory_combo_box
Definition: main-window.h:382
QAction * _current_news_action
Definition: main-window.h:379
QAction * _undo_action
Definition: main-window.h:348
void execute_debug_callback()
void construct_file_menu(QMenuBar *p)
void save_workspace_callback(const std::string &file)
void open_developer_page(void)
Definition: main-window.cc:649
QString page
Definition: main-window.h:449
QClipboard * _clipboard
Definition: main-window.h:400
void set_screen_size_callback(const int_pair &)
void new_figure_callback(void)
void copyClipboard_signal(void)
void clear_workspace_callback(void)
void closeEvent(QCloseEvent *closeEvent)
static const int current_directory_max_count
Definition: main-window.h:384
QPointer< settings_dialog > _settings_dlg
Definition: main-window.h:388
void queue_debug(QString command)
void configure_shortcuts()
QAction * _select_all_action
Definition: main-window.h:353
void enable_menu_shortcuts(bool enable)
void process_settings_dialog_request(const QString &desired_tab=QString())
Definition: main-window.cc:655
void display_news_signal(const QString &news)
QAction * _new_figure_action
Definition: main-window.h:339
void handle_rename_variable_request(const QString &old_name, const QString &new_name)
Definition: main-window.cc:283
void connect_uiwidget_links(void)
main_window(QWidget *parent=0, bool start_gui=true)
Definition: main-window.cc:76
QString _release_notes_icon
Definition: main-window.h:324
void load_workspace_callback(const std::string &file)
QAction * _show_editor_action
Definition: main-window.h:359
void construct_documentation_menu(QMenu *p)
void run_file_callback(const QFileInfo &info)
Definition: main-window.cc:339
void selectAll_signal(void)
QAction * _show_file_browser_action
Definition: main-window.h:358
QAction * _new_function_action
Definition: main-window.h:337
void debug_continue(void)
Definition: main-window.cc:953
void open_online_documentation_page(void)
Definition: main-window.cc:363
void handle_show_doc(const QString &file)
QAction * _clear_workspace_action
Definition: main-window.h:351
QStringList * _dbg_queue
Definition: main-window.h:415
void undo_signal(void)
QAction * _debug_step_out
Definition: main-window.h:333
QAction * _developer_action
Definition: main-window.h:375
void editor_focus_changed(bool)
std::pair< int, int > int_pair
Definition: main-window.h:76
bool focus_console_after_command()
Definition: main-window.cc:315
QAction * _file_browser_action
Definition: main-window.h:364
QAction * _release_notes_action
Definition: main-window.h:378
QAction * _clear_command_window_action
Definition: main-window.h:349
QAction * _find_files_action
Definition: main-window.h:352
void focus_command_window(void)
Definition: main-window.cc:227
void set_window_layout(QSettings *settings)
void run_file_in_terminal(const QFileInfo &info)
Definition: main-window.cc:331
void handle_new_figure_request(void)
Definition: main-window.cc:357
void open_contribute_page(void)
Definition: main-window.cc:643
QWidget * release_notes_window
Definition: main-window.h:394
void debug_step_over(void)
Definition: main-window.cc:965
void open_bug_tracker_page(void)
Definition: main-window.cc:625
void construct_news_menu(QMenuBar *p)
QSemaphore _dbg_processing
Definition: main-window.h:416
void debug_step_out(void)
Definition: main-window.cc:971
history_dock_widget * history_window
Definition: main-window.h:304
QAction * _show_command_window_action
Definition: main-window.h:355
void construct_menu_bar(void)
void construct_window_menu(QMenuBar *p)
QList< octave_dock_widget * > get_dock_widget_list()
Definition: main-window.h:224
void find_files(const QString &startdir=QDir::currentPath())
QAction * _exit_action
Definition: main-window.h:343
QAction * _history_action
Definition: main-window.h:362
QAction * _show_workspace_action
Definition: main-window.h:357
Dock widget to display files in the current directory.
void handle_clear_command_window_request(void)
Definition: main-window.cc:303
void set_current_working_directory(const QString &dir)
Definition: main-window.cc:882
void open_agora_page(void)
Definition: main-window.cc:637
void init_terminal_size(void)
QList< int > QIntList
Definition: dialog.h:38
static bool start_gui
Definition: octave.cc:169
void new_file(const QString &commands=QString())
Definition: main-window.cc:233
QAction * _show_history_action
Definition: main-window.h:356
void process(void)
Definition: main-window.cc:433
void construct_help_menu(QMenuBar *p)
void init_terminal_size_signal(void)
void active_dock_changed(octave_dock_widget *, octave_dock_widget *)
void construct_tool_bar(void)
QAction * _load_workspace_action
Definition: main-window.h:340
QAction * _debug_continue
Definition: main-window.h:330
QAction * construct_debug_menu_item(const char *icon, const QString &item, const char *member)
void focus_changed(QWidget *w_old, QWidget *w_new)
Definition: main-window.cc:169
QMenu * _debug_menu
Definition: main-window.h:328
QAction * _debug_quit
Definition: main-window.h:334
QLineEdit * _current_directory_line_edit
Definition: main-window.h:385
void construct_new_menu(QMenu *p)
bool _start_gui
Definition: main-window.h:421
std::pair< std::string, std::string > name_pair
Definition: main-window.h:75
void new_file_signal(const QString &)
void construct_edit_menu(QMenuBar *p)
void handle_enter_debugger(void)
Definition: main-window.cc:921
void change_directory_up(void)
Definition: main-window.cc:896
find_files_dialog * find_files_dlg
Definition: main-window.h:391
void pasteClipboard_signal(void)
QMutex _dbg_queue_mutex
Definition: main-window.h:417
QWidget * community_news_window
Definition: main-window.h:396
QAction * _ondisk_doc_action
Definition: main-window.h:369
void prepare_to_exit(void)
Definition: main-window.cc:829
void handle_save_workspace_request(void)
Definition: main-window.cc:251
octave_qt_link * _octave_qt_link
Definition: main-window.h:398
void add_actions_signal(QList< QAction * > action_list)
void handle_update_breakpoint_marker_request(bool insert, const QString &file, int line)
QAction * _editor_action
Definition: main-window.h:365
void handle_delete_debugger_pointer_request(const QString &file, int line)
Definition: main-window.cc:995
void set_global_edit_shortcuts(bool enable)
QAction * _save_workspace_action
Definition: main-window.h:341
void insert_debugger_pointer_signal(const QString &file, int line)
void report_status_message(const QString &statusMessage)
Definition: main-window.cc:245