Mercurial > hg > octave-lojdl
changeset 15357:b6b261c3eab3
Merge in Thorsten's changes
author | Jordi Gutiérrez Hermoso <jordigh@octave.org> |
---|---|
date | Tue, 11 Sep 2012 15:12:44 -0400 |
parents | 842ab161c10a (diff) 93dff6435fe1 (current diff) |
children | b135f013679e 75f28de3a387 |
files | |
diffstat | 7 files changed, 57 insertions(+), 13 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-interface.h +++ b/libgui/src/m-editor/file-editor-interface.h @@ -57,7 +57,7 @@ public slots: virtual void request_new_file () = 0; virtual void request_open_file () = 0; - virtual void request_open_file (const QString& fileName) = 0; + virtual void request_open_file (const QString& fileName, bool silent = false) = 0; signals: void active_changed (bool active);
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -121,7 +121,7 @@ this, SLOT (file_has_changed (QString))); _file_name = ""; - _long_title = false; + _long_title = settings->value ("editor/longWindowTitle",false).toBool (); update_window_title (false); } @@ -627,8 +627,8 @@ } } -void -file_editor_tab::load_file (const QString& fileName) +bool +file_editor_tab::load_file(const QString& fileName, bool silent) { if (!_file_editor->isVisible ()) { @@ -638,10 +638,11 @@ QFile file (fileName); if (!file.open (QFile::ReadOnly)) { - QMessageBox::warning (this, tr ("Octave Editor"), - tr ("Could not open file %1 for read:\n%2.").arg (fileName). - arg (file.errorString ())); - return; + if (silent==false) + QMessageBox::warning (this, tr ("Octave Editor"), + tr ("Could not open file %1 for read:\n%2.").arg (fileName). + arg (file.errorString ())); + return false; } QTextStream in (&file); @@ -655,6 +656,8 @@ update_window_title (false); // window title (no modification) _edit_area->setModified (false); // loaded file is not modified yet + + return true; } void
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -65,7 +65,7 @@ void set_modified (bool modified = true); bool open_file (const QString& dir = QString ()); - void load_file (const QString& fileName); + bool load_file (const QString& fileName, bool silent = false); void new_file (); bool save_file (); bool save_file (const QString& saveFileName);
--- a/libgui/src/m-editor/file-editor.cc +++ b/libgui/src/m-editor/file-editor.cc @@ -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
--- a/libgui/src/m-editor/file-editor.h +++ b/libgui/src/m-editor/file-editor.h @@ -64,7 +64,7 @@ public slots: void request_new_file (); void request_open_file (); - void request_open_file (const QString& fileName); + void request_open_file (const QString& fileName, bool silent = false); void request_undo (); void request_redo ();
--- a/libgui/src/settings-dialog.cc +++ b/libgui/src/settings-dialog.cc @@ -45,7 +45,8 @@ ui->editor_codeCompletion->setChecked (settings->value ("editor/codeCompletion",true).toBool () ); ui->editor_fontName->setCurrentFont (QFont (settings->value ("editor/fontName","Courier").toString()) ); ui->editor_fontSize->setValue (settings->value ("editor/fontSize",10).toInt ()); - ui->editor_longWindowTitle->setChecked (settings->value ("editor/longWindowTitle",true).toBool ()); + ui->editor_longWindowTitle->setChecked (settings->value ("editor/longWindowTitle",false).toBool ()); + ui->editor_restoreSession->setChecked (settings->value ("editor/restoreSession",true).toBool ()); ui->terminal_fontName->setCurrentFont (QFont (settings->value ("terminal/fontName","Courier").toString()) ); ui->terminal_fontSize->setValue (settings->value ("terminal/fontSize",10).toInt ()); ui->showFilenames->setChecked (settings->value ("showFilenames").toBool()); @@ -107,6 +108,7 @@ settings->setValue ("editor/fontName", ui->editor_fontName->currentFont().family()); settings->setValue ("editor/fontSize", ui->editor_fontSize->value()); settings->setValue ("editor/longWindowTitle", ui->editor_longWindowTitle->isChecked()); + settings->setValue ("editor/restoreSession", ui->editor_restoreSession->isChecked ()); settings->setValue ("terminal/fontSize", ui->terminal_fontSize->value()); settings->setValue ("terminal/fontName", ui->terminal_fontName->currentFont().family()); settings->setValue ("showFilenames", ui->showFilenames->isChecked ());
--- a/libgui/src/settings-dialog.ui +++ b/libgui/src/settings-dialog.ui @@ -141,6 +141,13 @@ </property> </widget> </item> + <item> + <widget class="QCheckBox" name="editor_restoreSession"> + <property name="text"> + <string>Restore tabs from previous session on startup</string> + </property> + </widget> + </item> </layout> </item> <item>