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 43 #include "external-editor-interface.h" 44 #include "file-editor-interface.h" 45 46 // QTerminal includes 47 #include "QTerminal.h" 48 49 // Own includes 50 #include "dialog.h" 51 #include "documentation-dock-widget.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 96 void active_dock_changed (octave_dock_widget *, octave_dock_widget *); 97 void editor_focus_changed (bool); 98 99 void settings_changed (const gui_settings *); 100 void init_terminal_size_signal (void); 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); 104 void step_into_file_signal (void); 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); 116 void pasteClipboard_signal (void); 117 void selectAll_signal (void); 118 void undo_signal (void); 119 120 void add_actions_signal (QList <QAction *> action_list); 121 122 void warning_function_not_found_signal (const QString& message); 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); 138 void handle_clear_command_window_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); 160 void notice_settings (const gui_settings *settings, 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 = true, bool save = 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); 201 void set_window_layout (gui_settings *settings); 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 ()); find_files_finished(int)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 get_dock_widget_list(void)238 QList<octave_dock_widget *> get_dock_widget_list (void) 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*); 286 void construct_window_menu (QMenuBar *p); 287 void construct_help_menu (QMenuBar *p); 288 void construct_documentation_menu (QMenu *p); 289 290 void construct_news_menu (QMenuBar *p); 291 292 void construct_tool_bar (void); 293 294 void configure_shortcuts (void); 295 296 QList<octave_dock_widget *> dock_widget_list (void); 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 304 base_qobject& m_octave_qobj; 305 306 workspace_model *m_workspace_model; 307 308 QHash<QMenu*, QStringList> m_hash_menu_text; 309 310 QString m_default_encoding; 311 312 QString m_default_style; 313 314 //! Toolbar. 315 316 QStatusBar *m_status_bar; 317 318 //! Dock widgets. 319 //!@{ 320 terminal_dock_widget *m_command_window; 321 history_dock_widget *m_history_window; 322 files_dock_widget *m_file_browser_window; 323 documentation_dock_widget *m_doc_browser_window; 324 file_editor_interface *m_editor_window; 325 workspace_view *m_workspace_window; 326 variable_editor *m_variable_editor_window; 327 //!@} 328 329 external_editor_interface *m_external_editor; 330 QWidget *m_active_editor; 331 332 octave_dock_widget *m_previous_dock; 333 octave_dock_widget *m_active_dock; 334 335 QString m_release_notes_icon; 336 337 QToolBar *m_main_tool_bar; 338 339 QMenu *m_debug_menu; 340 341 QAction *m_debug_continue; 342 QAction *m_debug_step_into; 343 QAction *m_debug_step_over; 344 QAction *m_debug_step_out; 345 QAction *m_debug_quit; 346 347 QAction *m_new_script_action; 348 QAction *m_new_function_action; 349 QAction *m_open_action; 350 QAction *m_new_figure_action; 351 QAction *m_load_workspace_action; 352 QAction *m_save_workspace_action; 353 QAction *m_set_path_action; 354 QAction *m_preferences_action; 355 QAction *m_exit_action; 356 357 QAction *m_copy_action; 358 QAction *m_paste_action; 359 QAction *m_clear_clipboard_action; 360 QAction *m_undo_action; 361 QAction *m_clear_command_window_action; 362 QAction *m_clear_command_history_action; 363 QAction *m_clear_workspace_action; 364 QAction *m_find_files_action; 365 QAction *m_select_all_action; 366 367 QAction *m_show_command_window_action; 368 QAction *m_show_history_action; 369 QAction *m_show_workspace_action; 370 QAction *m_show_file_browser_action; 371 QAction *m_show_editor_action; 372 QAction *m_show_documentation_action; 373 QAction *m_show_variable_editor_action; 374 QAction *m_command_window_action; 375 QAction *m_history_action; 376 QAction *m_workspace_action; 377 QAction *m_file_browser_action; 378 QAction *m_editor_action; 379 QAction *m_documentation_action; 380 QAction *m_variable_editor_action; 381 QAction *m_previous_dock_action; 382 QAction *m_reset_windows_action; 383 384 QAction *m_ondisk_doc_action; 385 QAction *m_online_doc_action; 386 QAction *m_report_bug_action; 387 QAction *m_octave_packages_action; 388 QAction *m_contribute_action; 389 QAction *m_developer_action; 390 QAction *m_about_octave_action; 391 392 QAction *m_release_notes_action; 393 QAction *m_current_news_action; 394 395 //! For Toolbars. 396 //!@{ 397 QComboBox *m_current_directory_combo_box; 398 static const int current_directory_max_visible = 16; 399 static const int current_directory_max_count = 16; 400 QLineEdit *m_current_directory_line_edit; 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 409 find_files_dialog *m_find_files_dlg; 410 411 //! Set path dialog 412 QPointer<set_path_dialog> m_set_path_dlg; 413 414 //! Release notes window. 415 416 QWidget *m_release_notes_window; 417 418 QWidget *m_community_news_window; 419 420 QClipboard *m_clipboard; 421 422 //! Some class global flags. 423 //!@{ 424 bool m_prevent_readline_conflicts; 425 bool m_suppress_dbg_location; 426 bool m_editor_has_tabs; 427 428 //! Flag for closing the whole application. 429 430 bool m_closing; 431 //!@} 432 433 QString m_file_encoding; 434 }; 435 } 436 437 #endif 438