Mercurial > hg > octave-nkf
changeset 18467:2ea741d22554 gui-release
create empty script when editor becomes visible without open files (bug #41347)
* file-editor.cc (empty_script): new function determining whether to create
an empty script or not;
(handle_visibility): reimplemented from octave_dock_widget, calls
empty_script each time the editor becomes visible;
* file-editor.h: new slot handle_visibility, new function empty_script
* file-editor-interface.h: new virtual function empty_script
* main-window.cc (connect_visibility_changed): call empty_script when main
window and all widgets are initialized
author | Torsten <ttl@justmail.de> |
---|---|
date | Sun, 26 Jan 2014 12:55:21 +0100 |
parents | 5936afdc75e1 |
children | 6ebd37faae5f |
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 |
diffstat | 4 files changed, 72 insertions(+), 0 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 empty_script (bool, bool) = 0; + public slots: virtual void request_new_file (const QString& command = QString ()) = 0; virtual void request_new_script (const QString& command = QString ()) = 0;
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -36,6 +36,7 @@ #include <QMessageBox> #include <QStyle> #include <QTextStream> +#include <QTabBar> #include <QProcess> #include <QInputDialog> @@ -1547,5 +1548,67 @@ _redo_action->setEnabled (have_tabs); } +// empty_script determines whether we have to create an empty script +// 1. At startup, when the editor has to be (really) visible +// (Here we can not use the visibility changed signal) +// 2. When the editor becomes visible when octave is running +void +file_editor::empty_script (bool startup, bool visible) +{ + bool real_visible; + + if (startup) + real_visible = isVisible (); + else + real_visible = visible; + + if (! real_visible || _tab_widget->count () > 0) + return; + + if (startup && ! isFloating ()) + { + // check is editor is really visible or hidden between tabbed widgets + QList<QTabBar *> tab_list = main_win ()->findChildren<QTabBar *>(); + + bool in_tab = false; + int i = 0; + while ((i < tab_list.count ()) && (! in_tab)) + { + QTabBar *tab = tab_list.at (i); + i++; + + int j = 0; + while ((j < tab->count ()) && (! in_tab)) + { + // check all tabs for the editor + if (tab->tabText (j) == windowTitle ()) + { + // editor is in this tab widget + in_tab = true; + int top = tab->currentIndex (); + if (top > -1 && tab->tabText (top) == windowTitle ()) + real_visible = true; // and is the current tab + else + return; // not current tab -> not visible + } + j++; + } + } + } + + request_new_file (""); +} + +// This slot is a reimplementation of the virtual slot in octave_dock_widget. +// We need this for creating an empty script when the editor has no open files +// and is made visible +void +file_editor::handle_visibility (bool visible) + { + empty_script (false, visible); + + if (visible && ! isFloating ()) + focus (); + } #endif
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -58,6 +58,8 @@ void handle_exit_debug_mode (void); void check_actions (void); + void empty_script (bool startup, bool visible); + signals: void fetab_settings_changed (const QSettings *settings); @@ -172,6 +174,8 @@ // Tells the ditor to dis- or enable some shortcuts void set_shortcuts (bool set_shortcuts); + void handle_visibility (bool visible); + protected slots: void copyClipboard ();
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -1010,6 +1010,9 @@ { foreach (octave_dock_widget *widget, dock_widget_list ()) widget->connect_visibility_changed (); + + // Main window completely shown, determine whether to create an empty script + editor_window->empty_script (true, false); } void