diff gui/src/MainWindow.cpp @ 14602:c8453a013000 gui

Cleaned up code. Fixed bug that causes the GUI to freeze when launching another editor. * FileEditor: Now the call of another process returns immediately. Adjusted text when closing a file. * MainWindow: Moved creating a lexer into the constructor.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Mon, 07 May 2012 02:36:49 +0200
parents 772ce0204b3f
children 7605e7136b50
line wrap: on
line diff
--- a/gui/src/MainWindow.cpp	Mon May 07 01:37:26 2012 +0200
+++ b/gui/src/MainWindow.cpp	Mon May 07 02:36:49 2012 +0200
@@ -55,40 +55,9 @@
 {
   FileEditor *fileEditor = new FileEditor ();
   fileEditor->setAttribute (Qt::WA_DeleteOnClose);
-  // check whether lexer is already prepared and prepare it if not
-  if ( m_lexer == NULL )
-    {
-      // this has to be done only once, not for each editor
-      m_lexer = new LexerOctaveGui();
-      // Editor font (default or from settings)
-      QSettings *settings = ResourceManager::instance ()->settings ();
-      m_lexer->setDefaultFont( QFont(
-                  settings->value ("editor/fontName","Courier").toString (),
-                  settings->value ("editor/fontSize",10).toInt () ) );
-      // TODO: Autoindent not working as it should
-      m_lexer->setAutoIndentStyle(QsciScintilla::AiMaintain ||
-                                  QsciScintilla::AiOpening  ||
-                                  QsciScintilla::AiClosing);
-      // 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
-       m_lexerAPI = new QsciAPIs(m_lexer);
-       QString keyword;
-       QStringList keywordList;
-       keyword     = m_lexer->keywords(1);  // get whole string with all keywords
-       keywordList = keyword.split(QRegExp("\\s+"));  // split into single strings
-       int i;
-       for ( i=0; i<keywordList.size(); i++ )
-         {
-           m_lexerAPI->add(keywordList.at(i));  // add single strings to the API
-         }
-       m_lexerAPI->prepare();           // prepare API info ... this make take some time
-    }
   fileEditor->initEditor(m_terminalView, m_lexer, this);   // init necessary informations for editor
 
-  if ( fileName.isEmpty() )
+  if (fileName.isEmpty ())
     fileEditor->newFile ();
   else
     fileEditor->loadFile (fileName);
@@ -205,7 +174,7 @@
 {
   reportStatusMessage (tr ("Saving data and shutting down."));
   writeSettings ();
-  m_closeApplication = true;  // inform editor window that whole application is closed
+  m_closing = true;  // inform editor window that whole application is closed
   OctaveLink::instance ()->terminateOctave();
 
   QMainWindow::closeEvent (closeEvent);
@@ -232,7 +201,7 @@
 MainWindow::construct ()
 {
   // TODO: Check this.
-  m_closeApplication = false;   // flag for editor files when closed
+  m_closing = false;   // flag for editor files when closed
   setWindowIcon (ResourceManager::instance ()->icon (ResourceManager::Octave));
 
   // Setup dockable widgets and the status bar.
@@ -315,6 +284,38 @@
   addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget);
   setStatusBar (m_statusBar);
 
+  // this has to be done only once, not for each editor
+  m_lexer = new LexerOctaveGui ();
+
+  // Editor font (default or from settings)
+  QSettings *settings = ResourceManager::instance ()->settings ();
+  m_lexer->setDefaultFont (QFont (
+              settings->value ("editor/fontName","Courier").toString (),
+              settings->value ("editor/fontSize",10).toInt ()));
+
+  // TODO: Autoindent not working as it should
+  m_lexer->setAutoIndentStyle (QsciScintilla::AiMaintain ||
+                               QsciScintilla::AiOpening  ||
+                               QsciScintilla::AiClosing);
+
+  // 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
+   m_lexerAPI = new QsciAPIs (m_lexer);
+
+   QString keyword;
+   QStringList keywordList;
+   keyword = m_lexer->keywords (1);  // get whole string with all keywords
+   keywordList = keyword.split (QRegExp ("\\s+"));  // split into single strings
+   int i;
+   for (i=0; i<keywordList.size(); i++)
+     {
+       m_lexerAPI->add (keywordList.at (i));  // add single strings to the API
+     }
+   m_lexerAPI->prepare ();           // prepare API info ... this make take some time
+
   readSettings ();
   updateTerminalFont();
 }