Mercurial > hg > octave-lyh
diff gui/src/MainWindow.cpp @ 13558:248b897d9f36
editor: custom lexer, syntax highlighting, auto completion
author | ttl <ttl@justmail.de> |
---|---|
date | Sat, 30 Jul 2011 16:36:25 +0200 |
parents | cd66481d55b0 |
children | a89aa9e05e19 |
line wrap: on
line diff
--- a/gui/src/MainWindow.cpp +++ b/gui/src/MainWindow.cpp @@ -54,13 +54,57 @@ } else { - FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); - subWindow->setAttribute (Qt::WA_DeleteOnClose); - subWindow->loadFile (fileName); + openEditorFile(fileName); } } void +MainWindow::openEditor () +{ + openEditorFile(QString()); +} +void +MainWindow::openEditorFile (QString fileName) +{ + FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); + subWindow->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(); + m_lexer->setDefaultFont(QFont("Monospace",10)); + // 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 + } + subWindow->setEditorLexer(m_lexer); // set the already prepared lexer + + if ( fileName.isEmpty() ) + subWindow->newFile (); + else + subWindow->loadFile (fileName); +} + + +void MainWindow::reportStatusMessage (QString statusMessage) { m_statusBar->showMessage (statusMessage, 1000); @@ -113,14 +157,6 @@ } void -MainWindow::openEditor () -{ - FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); - subWindow->setAttribute (Qt::WA_DeleteOnClose); - subWindow->newFile (); -} - -void MainWindow::openBugTrackerPage () { QDesktopServices::openUrl (QUrl ("http://savannah.gnu.org/bugs/?group=octave")); @@ -267,6 +303,8 @@ m_ircWidgetSubWindow->setWindowIcon (QIcon ("../media/chat.png")); m_ircWidgetSubWindow->setStatusTip(tr ("Instantly chat with other Octave users for help.")); + m_lexer = NULL; // initialise the empty lexer for the edtiors + QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave")); QAction *settingsAction = controlMenu->addAction (tr ("Settings")); controlMenu->addSeparator ();