# HG changeset patch
# User Daniel J Sebald <daniel.sebald@ieee.org>
# Date 1347930979 18000
# Node ID 5b73a9e4dc3bb88aa8eba14f21292e916f468a56
# Parent  7a009eea571aa47113a05199251b24669da450b6
Move lexer_api code inside lexer_octave_gui constructor, delete lexer_api in destructor.  Make save-file-as reload lexer to match file extension.  Update settings only after all window objects created.

diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/m-editor/file-editor-tab.cc
--- a/libgui/src/m-editor/file-editor-tab.cc	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Mon Sep 17 20:16:19 2012 -0500
@@ -29,8 +29,6 @@
 #include "find-dialog.h"
 #include "octave-link.h"
 
-
-#include <Qsci/qsciapis.h>
 // Not available in the Debian repos yet!
 // #include <Qsci/qscilexeroctave.h>
 #include "lexer-octave-gui.h"
@@ -224,31 +222,6 @@
   if (_file_name.endsWith (".m") || _file_name.endsWith (".M"))
     {
       lexer = new lexer_octave_gui ();
-
-      // The API info that is used for auto completion
-      // TODO: Where to store a file with API info (raw or prepared?)?
-      // TODO: Also provide infos on octave-forge functions?
-      // TODO: Also provide infos on function parameters?
-      // By now, use the keywords-list from syntax highlighting
-
-      QsciAPIs *lexer_api = new QsciAPIs (lexer);
-
-      QString keyword;
-      QStringList keywordList;
-
-      // get whole string with all keywords
-      keyword = lexer->keywords (1);
-      // split into single strings
-      keywordList = keyword.split (QRegExp ("\\s+"));
-
-      int i;
-      for (i = 0; i < keywordList.size (); i++)
-        {
-          // add single strings to the API
-          lexer_api->add (keywordList.at (i));
-        }
-      // prepare API info ... this make take some time
-      lexer_api->prepare ();
     }
   else if (_file_name.endsWith (".c")
            || _file_name.endsWith (".cc")
@@ -416,7 +389,7 @@
   int decision = QMessageBox::Yes;
   if (_edit_area->isModified ())
     {
-      // file is modified but not saved, aks user what to do
+      // file is modified but not saved, ask user what to do
       decision = QMessageBox::warning (this,
                                        msg,
                                        tr ("The file %1\n"
@@ -623,9 +596,6 @@
   QApplication::restoreOverrideCursor ();
 
   set_file_name (fileName);
-  update_tracked_file ();
-
-
   update_window_title (false); // window title (no modification)
   _edit_area->setModified (false); // loaded file is not modified yet
 
@@ -660,10 +630,6 @@
       return save_file_as();
     }
 
-  QStringList watched_files = _file_system_watcher.files();
-  if (!watched_files.isEmpty ())
-    _file_system_watcher.removePaths(watched_files);
-
   // open the file for writing
   QFile file (saveFileName);
   if (!file.open (QFile::WriteOnly))
@@ -671,7 +637,6 @@
       QMessageBox::warning (this, tr ("Octave Editor"),
                             tr ("Could not open file %1 for write:\n%2.").
                             arg (saveFileName).arg (file.errorString ()));
-      _file_system_watcher.addPaths (watched_files);
       return false;
     }
 
@@ -680,17 +645,15 @@
   QApplication::setOverrideCursor (Qt::WaitCursor);
   out << _edit_area->text ();
   QApplication::restoreOverrideCursor ();
+  file.close();
 
-  // save file name for later use
-  _file_name = saveFileName;
+  // save file name after closing file otherwise tracker will notice file change
+  set_file_name (saveFileName);
   // set the window title to actual file name (not modified)
   update_window_title (false);
   // files is save -> not modified
   _edit_area->setModified (false);
-  file.close();
 
-  if (!watched_files.isEmpty ())
-    _file_system_watcher.addPaths (watched_files);
   return true;
 }
 
@@ -793,7 +756,6 @@
               set_file_name (UNNAMED_FILE);
               update_window_title (true); // window title (no modification)
               set_modified (true);
-              update_tracked_file ();
             }
         }
       else
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/m-editor/file-editor.cc
--- a/libgui/src/m-editor/file-editor.cc	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Mon Sep 17 20:16:19 2012 -0500
@@ -594,8 +594,8 @@
     {
       QStringList sessionFileNames = settings->value("editor/savedSessionTabs", QStringList()).toStringList ();
 
-      for (int n=0;n<sessionFileNames.count();++n)
-        request_open_file(sessionFileNames.at(n), true);
+      for (int n=0; n < sessionFileNames.count (); ++n)
+        request_open_file (sessionFileNames.at (n), true);
     }
 }
 
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/m-editor/lexer-octave-gui.cc
--- a/libgui/src/m-editor/lexer-octave-gui.cc	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/m-editor/lexer-octave-gui.cc	Mon Sep 17 20:16:19 2012 -0500
@@ -34,10 +34,37 @@
 lexer_octave_gui::lexer_octave_gui (QObject *p)
   : QsciLexer (p)
 {
+  // The API info that is used for auto completion
+  // TODO: Where to store a file with API info (raw or prepared?)?
+  // TODO: Also provide infos on octave-forge functions?
+  // TODO: Also provide infos on function parameters?
+  // By now, use the keywords-list from syntax highlighting
+
+  QString keyword;
+  QStringList keywordList;
+
+  // get whole string with all keywords
+  keyword = this->keywords (1);
+  // split into single strings
+  keywordList = keyword.split (QRegExp ("\\s+"));
+
+  lexer_api = new QsciAPIs (this);
+  if (lexer_api)
+    {
+      for (int i = 0; i < keywordList.size (); i++)
+        {
+          // add single strings to the API
+          lexer_api->add (keywordList.at (i));
+        }
+      // prepare API info ... this may take some time
+      lexer_api->prepare ();
+    }
 }
 
 lexer_octave_gui::~lexer_octave_gui()
 {
+  if (lexer_api)
+    delete lexer_api;
 }
 
 const char *lexer_octave_gui::language() const
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/m-editor/lexer-octave-gui.h
--- a/libgui/src/m-editor/lexer-octave-gui.h	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/m-editor/lexer-octave-gui.h	Mon Sep 17 20:16:19 2012 -0500
@@ -27,7 +27,7 @@
 #include <QObject>
 #include <Qsci/qsciglobal.h>
 #include <Qsci/qscilexer.h>
-
+#include <Qsci/qsciapis.h>
 
 class lexer_octave_gui : public QsciLexer
 {
@@ -49,7 +49,7 @@
     };
 
   lexer_octave_gui (QObject *parent = 0);
-  virtual ~lexer_octave_gui ();
+  ~lexer_octave_gui ();
   const char *language () const;
   const char *lexer () const;
   QColor defaultColor (int style) const;
@@ -60,6 +60,7 @@
 private:
   lexer_octave_gui (const lexer_octave_gui &);
   lexer_octave_gui &operator= (const lexer_octave_gui &);
+  QsciAPIs *lexer_api;
 };
 
 #endif
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/main-window.cc
--- a/libgui/src/main-window.cc	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/main-window.cc	Mon Sep 17 20:16:19 2012 -0500
@@ -874,7 +874,6 @@
   addDockWidget (Qt::BottomDockWidgetArea, _terminal_dock_widget);
   addDockWidget (Qt::RightDockWidgetArea, _documentation_dock_widget);
   setStatusBar (_status_bar);
-  read_settings ();
 
   _octave_qt_event_listener = new octave_qt_event_listener ();
   octave_link::register_event_listener (_octave_qt_event_listener);
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/main-window.h
--- a/libgui/src/main-window.h	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/main-window.h	Mon Sep 17 20:16:19 2012 -0500
@@ -119,10 +119,11 @@
   void debug_step_out ();
   void debug_quit ();
 
+  void read_settings ();
+  void write_settings ();
+
 protected:
   void closeEvent (QCloseEvent * closeEvent);
-  void read_settings ();
-  void write_settings ();
 
 private:
   void construct ();
diff -r 7a009eea571a -r 5b73a9e4dc3b libgui/src/octave-gui.cc
--- a/libgui/src/octave-gui.cc	Mon Sep 17 08:50:46 2012 -0400
+++ b/libgui/src/octave-gui.cc	Mon Sep 17 20:16:19 2012 -0500
@@ -110,6 +110,7 @@
           resource_manager::update_network_settings ();
 
           main_window w;
+          w.read_settings ();  // Get the widget settings after construction and before showing
           w.show ();
           w.focus_command_window ();
 
