comparison 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
comparison
equal deleted inserted replaced
13557:ad18a8e7fb02 13558:248b897d9f36
52 // m_centralMdiArea->addSubWindow(subWindow); 52 // m_centralMdiArea->addSubWindow(subWindow);
53 // subWindow->setWindowTitle(fileName); 53 // subWindow->setWindowTitle(fileName);
54 } 54 }
55 else 55 else
56 { 56 {
57 FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea); 57 openEditorFile(fileName);
58 subWindow->setAttribute (Qt::WA_DeleteOnClose);
59 subWindow->loadFile (fileName);
60 } 58 }
61 } 59 }
60
61 void
62 MainWindow::openEditor ()
63 {
64 openEditorFile(QString());
65 }
66 void
67 MainWindow::openEditorFile (QString fileName)
68 {
69 FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea);
70 subWindow->setAttribute (Qt::WA_DeleteOnClose);
71 // check whether lexer is already prepared and prepare it if not
72 if ( m_lexer == NULL )
73 {
74 // this has to be done only once, not for each editor
75 m_lexer = new LexerOctaveGui();
76 m_lexer->setDefaultFont(QFont("Monospace",10));
77 // TODO: Autoindent not working as it should
78 m_lexer->setAutoIndentStyle(QsciScintilla::AiMaintain ||
79 QsciScintilla::AiOpening ||
80 QsciScintilla::AiClosing);
81 // The API info that is used for auto completion
82 // TODO: Where to store a file with API info (raw or prepared?)?
83 // TODO: Also provide infos on octave-forge functions?
84 // TODO: Also provide infos on function parameters?
85 // By now, use the keywords-list from syntax highlighting
86 m_lexerAPI = new QsciAPIs(m_lexer);
87 QString keyword;
88 QStringList keywordList;
89 keyword = m_lexer->keywords(1); // get whole string with all keywords
90 keywordList = keyword.split(QRegExp("\\s+")); // split into single strings
91 int i;
92 for ( i=0; i<keywordList.size(); i++ )
93 {
94 m_lexerAPI->add(keywordList.at(i)); // add single strings to the API
95 }
96 m_lexerAPI->prepare(); // prepare API info ... this make take some time
97 }
98 subWindow->setEditorLexer(m_lexer); // set the already prepared lexer
99
100 if ( fileName.isEmpty() )
101 subWindow->newFile ();
102 else
103 subWindow->loadFile (fileName);
104 }
105
62 106
63 void 107 void
64 MainWindow::reportStatusMessage (QString statusMessage) 108 MainWindow::reportStatusMessage (QString statusMessage)
65 { 109 {
66 m_statusBar->showMessage (statusMessage, 1000); 110 m_statusBar->showMessage (statusMessage, 1000);
108 152
109 void 153 void
110 MainWindow::alignMdiWindows () 154 MainWindow::alignMdiWindows ()
111 { 155 {
112 m_centralMdiArea->tileSubWindows (); 156 m_centralMdiArea->tileSubWindows ();
113 }
114
115 void
116 MainWindow::openEditor ()
117 {
118 FileEditorMdiSubWindow *subWindow = new FileEditorMdiSubWindow (m_centralMdiArea);
119 subWindow->setAttribute (Qt::WA_DeleteOnClose);
120 subWindow->newFile ();
121 } 157 }
122 158
123 void 159 void
124 MainWindow::openBugTrackerPage () 160 MainWindow::openBugTrackerPage ()
125 { 161 {
265 m_ircWidgetSubWindow->setObjectName ("ChatWidgetSubWindow"); 301 m_ircWidgetSubWindow->setObjectName ("ChatWidgetSubWindow");
266 m_ircWidgetSubWindow->setWindowTitle (tr ("Chat")); 302 m_ircWidgetSubWindow->setWindowTitle (tr ("Chat"));
267 m_ircWidgetSubWindow->setWindowIcon (QIcon ("../media/chat.png")); 303 m_ircWidgetSubWindow->setWindowIcon (QIcon ("../media/chat.png"));
268 m_ircWidgetSubWindow->setStatusTip(tr ("Instantly chat with other Octave users for help.")); 304 m_ircWidgetSubWindow->setStatusTip(tr ("Instantly chat with other Octave users for help."));
269 305
306 m_lexer = NULL; // initialise the empty lexer for the edtiors
307
270 QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave")); 308 QMenu *controlMenu = menuBar ()->addMenu (tr ("Octave"));
271 QAction *settingsAction = controlMenu->addAction (tr ("Settings")); 309 QAction *settingsAction = controlMenu->addAction (tr ("Settings"));
272 controlMenu->addSeparator (); 310 controlMenu->addSeparator ();
273 QAction *exitAction = controlMenu->addAction (tr ("Exit")); 311 QAction *exitAction = controlMenu->addAction (tr ("Exit"));
274 312