diff libgui/src/main-window.cc @ 18309:024940bd5b77 gui-release

gui: provide prefernces for the octave directory at startup * settings-dialog.ui: add check box for restoring previous octave directory and line edit / file dialog for setting startup directory * settings-dialog.cc (constructor): init new input widgets from settings; (write_changed_settings): wirte values from new widgets into settings file; (get_octave_directory): new slot for settings octave dir in a file dialog * main-window.h: new slot handle_octave_ready * main-window.cc (handle_octave_ready): depending on settings set octave directory to the last one from the previous session, the one set in the settings or the current one; (construct): do not set dir here but in handle_octave_ready; (construct_octave_qt_link): pass 'this' to octave link as parent; * octave-interpreter.h: new signal inidication interpreter is initialized * octave-interpreter.cc (constructor): emit new signal after init of interpreter * octave-qt-link.cc (constructor): connect new signal with slot in main window
author Torsten <ttl@justmail.de>
date Sun, 19 Jan 2014 11:30:15 +0100
parents 78c3b4cb0c7f
children 770c525a1a2b
line wrap: on
line diff
--- a/libgui/src/main-window.cc	Sat Jan 18 08:50:03 2014 -0500
+++ b/libgui/src/main-window.cc	Sun Jan 19 11:30:15 2014 +0100
@@ -1261,19 +1261,48 @@
                                                           int)));
 #endif
 
-  QDir curr_dir;
-  set_current_working_directory (curr_dir.absolutePath ());
-
   octave_link::post_event (this, &main_window::resize_command_window_callback);
 
   set_global_shortcuts (true);
 
 }
 
+
+void
+main_window::handle_octave_ready ()
+{
+  // actions after the startup files are executed
+  QSettings *settings = resource_manager::get_settings ();
+
+  QDir startup_dir = QDir ();    // current octave dir after startup
+
+  if (settings->value ("restore_octave_dir").toBool ())
+    {
+      // restore last dir from previous session
+      QStringList curr_dirs
+        = settings->value ("MainWindow/current_directory_list").toStringList ();
+      startup_dir = QDir (curr_dirs.at (0));  // last dir in previous session
+    }
+  else if (! settings->value ("octave_startup_dir").toString ().isEmpty ())
+    {
+      // do not restore but there is a startup dir configured
+      startup_dir = QDir (settings->value ("octave_startup_dir").toString ());
+    }
+
+  if (! startup_dir.exists ())
+    {
+      // the configured startup dir does not exist, take actual one
+      startup_dir = QDir ();
+    }
+
+  set_current_working_directory (startup_dir.absolutePath ());
+}
+
+
 void
 main_window::construct_octave_qt_link (void)
 {
-  _octave_qt_link = new octave_qt_link ();
+  _octave_qt_link = new octave_qt_link (this);
 
   connect (_octave_qt_link, SIGNAL (exit_signal (int)),
            this, SLOT (exit (int)));