Mercurial > hg > octave-lyh
changeset 16457:10edb6f1ae98
improve encapsulation of file editor window object
* file-editor-interface.h
(file_editor_interface::connect_visibility_changed): New function.
* file-editor.h, file-editor.cc (file_editor::handle_visibility,
file_editor::focus, file_editor::connect_visibility_changed):
New functions.
(file_editor::construct): Connect main_window::new_file_signal to
file_editor::new_file.
* main-window.cc (main_window::editor_window): Rename from
_file_editor. Change all uses.
(create_default_editor): New static function.
(main_window::main_window): Use it to initialize editor_window.
(main_window::new_file_signal, main_window::open_file_signal):
New signals.
(main_window::new_file, main_window::open_file): Emit signals instead
of calling file_editor functions directly.
(main_window::focus_editor, main_window::handle_editor_visible):
Delete.
(main_window::connect_visibility_changed): Call
editor_window->connect_visibility_changed.
(main_window::construct): Don't create _file_editor.
(main_window::construct_file_menu): Connect _open_action::triggered to
editor_window::request_open_file instead of main_window::open_file.
Connect _new_script_action::triggered to
editor_window::request_new_file instead of main_window::new_file.
(main_window::construct_new_menu): Connect editor_action::triggered to
editor_window::focus instead of main_window::focus_editor.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 07 Apr 2013 05:45:23 -0400 |
parents | 203efbbcea63 |
children | a3513fc13cdb |
files | libgui/src/m-editor/file-editor-interface.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 | 5 files changed, 75 insertions(+), 75 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-interface.h +++ b/libgui/src/m-editor/file-editor-interface.h @@ -61,6 +61,8 @@ virtual void set_focus () = 0; + virtual void connect_visibility_changed (void) = 0; + public slots: virtual void request_new_file (const QString& command = QString ()) = 0; virtual void request_open_file () = 0;
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -73,6 +73,26 @@ delete _mru_file_menu; } +void +file_editor::focus (void) +{ + set_focus (); +} + +void +file_editor::handle_visibility (bool visible) +{ + if (visible && ! isFloating ()) + focus (); +} + +void +file_editor::connect_visibility_changed (void) +{ + connect (this, SIGNAL (visibilityChanged (bool)), + this, SLOT (handle_visibility (bool))); +} + // set focus to editor and its current tab void file_editor::set_focus () @@ -804,6 +824,12 @@ connect (parent (), SIGNAL (settings_changed (const QSettings *)), this, SLOT (notice_settings (const QSettings *))); + connect (parent (), SIGNAL (new_file_signal (const QString&)), + this, SLOT (request_new_file (const QString&))); + + connect (parent (), SIGNAL (open_file_signal (const QString&)), + this, SLOT (request_open_file (const QString&))); + connect (new_action, SIGNAL (triggered ()), this, SLOT (request_new_file ())); connect (open_action,
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -47,9 +47,13 @@ { Q_OBJECT - public: +public: + file_editor (QWidget *p); ~file_editor (); + + void connect_visibility_changed (void); + void loadFile (const QString& fileName); QMenu * get_mru_menu ( ) { return _mru_file_menu; } @@ -96,6 +100,9 @@ void fetab_set_focus (const QWidget* ID); public slots: + void focus (void); + void handle_visibility (bool visible); + void request_new_file (const QString& commands); void request_open_file (); void request_mru_open_file ();
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -55,6 +55,16 @@ #include "cmd-hist.h" #include "oct-env.h" +static file_editor_interface * +create_default_editor (QWidget *p) +{ +#ifdef HAVE_QSCINTILLA + return new file_editor (p); +#else + return 0; +#endif +} + main_window::main_window (QWidget *p) : QMainWindow (p), _workspace_model (new workspace_model ()), @@ -62,7 +72,8 @@ command_window (new terminal_dock_widget (this)), history_window (new history_dock_widget (this)), file_browser_window (new files_dock_widget (this)), - doc_browser_window (new documentation_dock_widget (this)) + doc_browser_window (new documentation_dock_widget (this)), + editor_window (create_default_editor (this)) { // We have to set up all our windows, before we finally launch octave. construct (); @@ -76,6 +87,7 @@ delete history_window; delete file_browser_window; delete doc_browser_window; + delete editor_window; // Clean up all dynamically created objects to ensure they are // deleted before this main_window is. Otherwise, some will be @@ -87,11 +99,6 @@ octave_link::connect_link (0); delete _octave_qt_link; -#ifdef HAVE_QSCINTILLA - if (_file_editor) - delete _file_editor; -#endif - delete _workspace_view; } @@ -104,25 +111,13 @@ void main_window::new_file (const QString& commands) { -#ifdef HAVE_QSCINTILLA - _file_editor->request_new_file (commands); -#endif -} - -void -main_window::open_file (void) -{ -#ifdef HAVE_QSCINTILLA - _file_editor->request_open_file (); -#endif + emit new_file_signal (commands); } void main_window::open_file (const QString& file_name) { -#ifdef HAVE_QSCINTILLA - _file_editor->request_open_file (file_name); -#endif + emit open_file_signal (file_name); } void @@ -372,15 +367,6 @@ void -main_window::focus_editor (void) -{ -#ifdef HAVE_QSCINTILLA - // call own function of editor in order to set focus to the current editor tab - _file_editor->set_focus (); -#endif -} - -void main_window::handle_workspace_visible (bool visible) { // if changed to visible and widget is not floating @@ -389,16 +375,6 @@ } void -main_window::handle_editor_visible (bool visible) -{ - // if changed to visible and widget is not floating -#ifdef HAVE_QSCINTILLA - if (visible && !_file_editor->isFloating ()) - focus_editor (); -#endif -} - -void main_window::handle_enter_debugger (void) { setWindowTitle ("Octave (Debugging)"); @@ -410,7 +386,7 @@ _debug_quit->setEnabled (true); #ifdef HAVE_QSCINTILLA - _file_editor->handle_enter_debug_mode (); + editor_window->handle_enter_debug_mode (); #endif } @@ -426,7 +402,7 @@ _debug_quit->setEnabled (false); #ifdef HAVE_QSCINTILLA - _file_editor->handle_exit_debug_mode (); + editor_window->handle_exit_debug_mode (); #endif } @@ -564,15 +540,12 @@ history_window->connect_visibility_changed (); file_browser_window->connect_visibility_changed (); doc_browser_window->connect_visibility_changed (); +#ifdef HAVE_QSCINTILLA + editor_window->connect_visibility_changed (); +#endif connect (_workspace_view, SIGNAL (visibilityChanged (bool)), this, SLOT (handle_workspace_visible (bool))); - -#ifdef HAVE_QSCINTILLA - connect (_file_editor, SIGNAL (visibilityChanged (bool)), - this, SLOT (handle_editor_visible (bool))); -#endif - } @@ -603,10 +576,6 @@ dummyWidget->hide (); setCentralWidget (dummyWidget); -#ifdef HAVE_QSCINTILLA - _file_editor = new file_editor (this); -#endif - construct_menu_bar (); construct_tool_bar (); @@ -628,8 +597,8 @@ tabifyDockWidget (command_window, doc_browser_window); #ifdef HAVE_QSCINTILLA - addDockWidget (Qt::RightDockWidgetArea, _file_editor); - tabifyDockWidget (command_window, _file_editor); + addDockWidget (Qt::RightDockWidgetArea, editor_window); + tabifyDockWidget (command_window, editor_window); #endif addDockWidget (Qt::LeftDockWidgetArea, file_browser_window); @@ -690,22 +659,22 @@ connect (_octave_qt_link, SIGNAL (update_breakpoint_marker_signal (bool, const QString&, int)), - _file_editor, + editor_window, SLOT (handle_update_breakpoint_marker_request (bool, const QString&, int))); connect (_octave_qt_link, SIGNAL (edit_file_signal (const QString&)), - _file_editor, + editor_window, SLOT (handle_edit_file_request (const QString&))); connect (_octave_qt_link, SIGNAL (insert_debugger_pointer_signal (const QString&, int)), - _file_editor, + editor_window, SLOT (handle_insert_debugger_pointer_request (const QString&, int))); connect (_octave_qt_link, SIGNAL (delete_debugger_pointer_signal (const QString&, int)), - _file_editor, + editor_window, SLOT (handle_delete_debugger_pointer_request (const QString&, int))); _octave_qt_link->execute_interpreter (); @@ -747,7 +716,7 @@ _open_action->setShortcutContext (Qt::ApplicationShortcut); #ifdef HAVE_QSCINTILLA - file_menu->addMenu (_file_editor->get_mru_menu ()); + file_menu->addMenu (editor_window->get_mru_menu ()); #endif QAction *close_command_window_action @@ -794,7 +763,7 @@ this, SLOT (process_settings_dialog_request ())); connect (_open_action, SIGNAL (triggered ()), - this, SLOT (open_file ())); + editor_window, SLOT (request_open_file ())); connect (save_workspace_action, SIGNAL (triggered ()), this, SLOT (handle_save_workspace_request ())); @@ -835,7 +804,7 @@ new_gui_action->setEnabled (false); // TODO: Make this work. connect (_new_script_action, SIGNAL (triggered ()), - this, SLOT (new_file ())); + editor_window, SLOT (request_new_file ())); } void @@ -929,8 +898,8 @@ action->setShortcut (Qt::Key_F10); #ifdef HAVE_QSCINTILLA - _file_editor->debug_menu ()->addAction (action); - _file_editor->toolbar ()->addAction (action); + editor_window->debug_menu ()->addAction (action); + editor_window->toolbar ()->addAction (action); #endif return action; @@ -956,7 +925,7 @@ _debug_menu->addSeparator (); #ifdef HAVE_QSCINTILLA - _file_editor->debug_menu ()->addSeparator (); + editor_window->debug_menu ()->addSeparator (); #endif _debug_quit = construct_debug_menu_item @@ -1083,9 +1052,9 @@ #ifdef HAVE_QSCINTILLA connect (show_editor_action, SIGNAL (toggled (bool)), - _file_editor, SLOT (setVisible (bool))); + editor_window, SLOT (setVisible (bool))); - connect (_file_editor, SIGNAL (active_changed (bool)), + connect (editor_window, SIGNAL (active_changed (bool)), show_editor_action, SLOT (setChecked (bool))); #endif @@ -1108,7 +1077,7 @@ file_browser_window, SLOT (focus ())); connect (editor_action, SIGNAL (triggered ()), - this, SLOT (focus_editor ())); + editor_window, SLOT (focus ())); connect (documentation_action, SIGNAL (triggered ()), doc_browser_window, SLOT (focus ()));
--- a/libgui/src/main-window.h +++ b/libgui/src/main-window.h @@ -74,6 +74,8 @@ signals: void settings_changed (const QSettings *); void relay_command_signal (const QString&); + void new_file_signal (const QString&); + void open_file_signal (const QString&); public slots: void report_status_message (const QString& statusMessage); @@ -82,8 +84,7 @@ void handle_clear_workspace_request (void); void handle_clear_history_request (void); void new_file (const QString& commands = QString ()); - void open_file (void); - void open_file (const QString& file_name); + void open_file (const QString& file_name = QString ()); void open_online_documentation_page (void); void open_bug_tracker_page (void); void open_octave_forge_page (void); @@ -104,9 +105,7 @@ void handle_command_double_clicked (const QString& command); void focus_workspace (void); - void focus_editor (void); void handle_workspace_visible (bool); - void handle_editor_visible (bool); void handle_enter_debugger (void); void handle_exit_debugger (void); @@ -184,10 +183,7 @@ history_dock_widget *history_window; files_dock_widget *file_browser_window; documentation_dock_widget *doc_browser_window; - -#ifdef HAVE_QSCINTILLA - file_editor_interface *_file_editor; -#endif + file_editor_interface *editor_window; QMenu *_debug_menu;