Mercurial > octave-dspies
diff libgui/src/m-editor/file-editor.cc @ 15356:842ab161c10a
GUI: new setting to restore tabs from previous session; allow silent load file
* settings-dialog.ui: new settings check box for previous session restore
* settings-dialog.cc (settings_dialog::settings_dialog): load/write new settings
* file-editor.h (file-editor::request_open_file): allow silent (no error msg) open file
* file_editor_interface.h (file_editor_interface::request_open_file) allow silent
(no error msg) open file
* file-editor.cc (file_editor::~file_editor): store a list of open tabs in settings
(file_editor::request_open_file): allow a silent open file with no error message
if file doesn't exist; remove added tab and restore focus, if load fails.
(file_editor::contruct): read list of previous tabs from settings (if enabled)
* file-editor-tab.h (file-editor-tab:load_file): allow silent load file, return success
* file-editor-tab.cc (file-editor-tab:load_file): allow silent load file, return success
author | Thorsten Liebig <Thorsten.Liebig@gmx.de> |
---|---|
date | Tue, 11 Sep 2012 15:24:22 +0200 |
parents | 5ddeef055df3 |
children | b4c32f245da7 |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor.cc Tue Sep 11 10:50:43 2012 +0200 +++ b/libgui/src/m-editor/file-editor.cc Tue Sep 11 15:24:22 2012 +0200 @@ -25,6 +25,7 @@ #endif #include "file-editor.h" +#include "resource-manager.h" #include <QVBoxLayout> #include <QApplication> #include <QFile> @@ -46,6 +47,20 @@ file_editor::~file_editor () { + QSettings *settings = resource_manager::get_settings (); + QStringList sessionFileNames; + if (settings->value ("editor/restoreSession",true).toBool ()) + { + for (int n=0;n<_tab_widget->count();++n) + { + file_editor_tab* tab = dynamic_cast<file_editor_tab*> (_tab_widget->widget (n)); + if (!tab) + continue; + sessionFileNames.append (tab->get_file_name ()); + } + } + settings->setValue ("editor/savedSessionTabs", sessionFileNames); + settings->sync (); } QTerminal * @@ -120,7 +135,7 @@ } void -file_editor::request_open_file (const QString& fileName) +file_editor::request_open_file (const QString& fileName, bool silent) { if (!isVisible ()) { @@ -128,10 +143,17 @@ } file_editor_tab *fileEditorTab = new file_editor_tab (this); + int curr_tab_index = _tab_widget->currentIndex (); if (fileEditorTab) { add_file_editor_tab (fileEditorTab); - fileEditorTab->load_file (fileName); + if (!fileEditorTab->load_file (fileName, silent)) + { + // If no file was loaded, remove the tab again. + _tab_widget->removeTab (_tab_widget->indexOf (fileEditorTab)); + // restore focus to previous tab + _tab_widget->setCurrentIndex (curr_tab_index); + } } } @@ -554,6 +576,16 @@ setWindowIcon (QIcon::fromTheme ("accessories-text-editor", style->standardIcon (QStyle::SP_FileIcon))); setWindowTitle ("Octave Editor"); + + //restore previous session + QSettings *settings = resource_manager::get_settings (); + if (settings->value ("editor/restoreSession",true).toBool ()) + { + QStringList sessionFileNames = settings->value("editor/savedSessionTabs", QStringList()).toStringList (); + + for (int n=0;n<sessionFileNames.count();++n) + request_open_file(sessionFileNames.at(n), true); + } } void