changeset 16717:9ad6e7d4fa42

fix bug concerning preparing the apis info for code completion * file-editor-tab.cc(update_lexer): fix multiple use of loop counters, collect raw apis info only if prepared info can not be loaded
author Torsten <ttl@justmail.de>
date Sun, 02 Jun 2013 09:13:00 +0200
parents 23b5dde25367
children 0495339998f8
files libgui/src/m-editor/file-editor-tab.cc
diffstat 1 files changed, 29 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Jun 01 19:40:24 2013 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sun Jun 02 09:13:00 2013 +0200
@@ -267,37 +267,40 @@
   _lexer_apis = new QsciAPIs(lexer);
   if (_lexer_apis)
     {
-      // create raw apis info
-      QString keyword;
-      QStringList keyword_list;
-      int i;
-      for (i=1; i<=3; i++) // load the first 3 keyword sets
-        {
-          keyword = QString(lexer->keywords (i));           // get list
-          keyword_list = keyword.split (QRegExp ("\\s+"));  // split
-          for (i = 0; i < keyword_list.size (); i++)        // add to API
-            _lexer_apis->add (keyword_list.at (i));
-        }
-
-     // get path where to store prepared api info
-     QDesktopServices desktopServices;
-     QString prep_apis_path
+      // get path to prepared api info
+      QDesktopServices desktopServices;
+      QString prep_apis_path
           = desktopServices.storageLocation (QDesktopServices::HomeLocation)
             + "/.config/octave/"  + QString(OCTAVE_VERSION) + "/qsci/";
+      _prep_apis_file = prep_apis_path + lexer->lexer () + ".pap";
 
-      // check whether path exists or can be created
-      if (QDir("/").mkpath (prep_apis_path))
-        { // path exists, apis info can be saved there
-          _prep_apis_file = prep_apis_path + lexer->lexer () + ".pap";
-          if (!_lexer_apis->loadPrepared (_prep_apis_file))
-            { // no prepared info loaded, prepare and save
+      if (!_lexer_apis->loadPrepared (_prep_apis_file))
+        { // no prepared info loaded, prepare and save if possible
+
+          // create raw apis info
+          QString keyword;
+          QStringList keyword_list;
+          int i,j;
+          for (i=1; i<=3; i++) // test the first 5 keyword sets
+            {
+              keyword = QString(lexer->keywords (i));           // get list
+              keyword_list = keyword.split (QRegExp ("\\s+"));  // split
+              for (j = 0; j < keyword_list.size (); j++)        // add to API
+                _lexer_apis->add (keyword_list.at (j));
+            }
+
+          // dsiconnect slot for saving prepared info if already connected
+          disconnect (_lexer_apis, SIGNAL (apiPreparationFinished ()), 0, 0);
+          // check whether path for prepared info exists or can be created
+          if (QDir("/").mkpath (prep_apis_path))
+            { // path exists, apis info can be saved there
               connect (_lexer_apis, SIGNAL (apiPreparationFinished ()),
                        this, SLOT (save_apis_info ()));
-              _lexer_apis->prepare ();  // prepare apis info and save
+              _lexer_apis->prepare ();  // prepare apis info, save when finished
             }
+          else
+            _lexer_apis->prepare ();  // prepare apis info wihtout saving
         }
-      else
-        _lexer_apis->prepare ();  // prepare apis info wihtout saving
     }
 
   QSettings *settings = resource_manager::get_settings ();
@@ -306,11 +309,12 @@
 
   _edit_area->setLexer (lexer);
 
-  // adapt line number width to the font size of the lexer
+  // fix line number width with respect to the font size of the lexer
   if (settings->value ("editor/showLineNumbers", true).toBool ())
     auto_margin_width ();
   else
     _edit_area->setMarginWidth (2,0);
+
 }
 
 void