comparison gui/src/MainWindow.cpp @ 14676:35512b788af2 gui

Editor can now handle multiple files in tabs. * FileEditorInterface (new class): Interface class fpr the file editor. * FileEditorTab (new class): File editor unit for editing a single file. * MainWindow: Adjusted includes and method calls. * FileEditor: Replaced code that allowed editing a file with code that manages tabs and delegates button clicks. * src.pro: Added new files.
author Jacob Dawid <jacob.dawid@googlemail.com>
date Wed, 23 May 2012 20:25:07 +0200
parents adad007cd018
children 66ff321cb62e
comparison
equal deleted inserted replaced
14674:252a86f8fe62 14676:35512b788af2
41 { 41 {
42 OctaveLink::instance ()->terminateOctave(); 42 OctaveLink::instance ()->terminateOctave();
43 } 43 }
44 44
45 void 45 void
46 MainWindow::openExistingFile (QString fileName)
47 {
48 reportStatusMessage (tr ("Opening file.."));
49 newEditorWindow(fileName);
50 }
51
52 void
53 MainWindow::newFile () 46 MainWindow::newFile ()
54 { 47 {
55 newEditorWindow(QString()); 48 if (!m_fileEditor->isVisible ())
56 } 49 {
57 50 m_fileEditor->show ();
58 void 51 }
59 MainWindow::newEditorWindow (QString fileName) 52 m_fileEditor->requestNewFile ();
60 { 53
61 FileEditor *fileEditor = new FileEditor (m_terminalView, m_lexer, this); 54 }
62 fileEditor->setAttribute (Qt::WA_DeleteOnClose); 55
63 56 void
64 if (fileName.isEmpty ()) 57 MainWindow::openFile ()
65 fileEditor->newFile (); 58 {
66 else 59 if (!m_fileEditor->isVisible ())
67 fileEditor->loadFile (fileName); 60 {
68 } 61 m_fileEditor->show ();
69 62 }
63 m_fileEditor->requestOpenFile ();
64
65 }
70 66
71 void 67 void
72 MainWindow::reportStatusMessage (QString statusMessage) 68 MainWindow::reportStatusMessage (QString statusMessage)
73 { 69 {
74 m_statusBar->showMessage (statusMessage, 1000); 70 m_statusBar->showMessage (statusMessage, 1000);
229 225
230 // Octave Terminal subwindow. 226 // Octave Terminal subwindow.
231 m_terminalView = new QTerminal(this); 227 m_terminalView = new QTerminal(this);
232 setCentralWidget (m_terminalView); 228 setCentralWidget (m_terminalView);
233 229
234 m_lexer = NULL; // initialise the empty lexer for the edtiors 230 m_fileEditor = new FileEditor (m_terminalView, this);
235 231
236 QMenu *fileMenu = menuBar ()->addMenu (tr ("&File")); 232 QMenu *fileMenu = menuBar ()->addMenu (tr ("&File"));
237 QAction *newFileAction 233 QAction *newFileAction
238 = fileMenu->addAction (QIcon::fromTheme ("document-new", 234 = fileMenu->addAction (QIcon::fromTheme ("document-new",
239 style->standardIcon (QStyle::SP_FileIcon)), tr ("New File")); 235 style->standardIcon (QStyle::SP_FileIcon)), tr ("New File"));
248 244
249 QMenu *editMenu = menuBar ()->addMenu (tr ("&Edit")); 245 QMenu *editMenu = menuBar ()->addMenu (tr ("&Edit"));
250 QAction *cutAction 246 QAction *cutAction
251 = editMenu->addAction (QIcon::fromTheme ("edit-cut", 247 = editMenu->addAction (QIcon::fromTheme ("edit-cut",
252 style->standardIcon (QStyle::SP_FileIcon)), tr ("Cut")); 248 style->standardIcon (QStyle::SP_FileIcon)), tr ("Cut"));
253 cutAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_X)); 249 cutAction->setShortcut (QKeySequence::Cut);
254 250
255 QAction *copyAction 251 QAction *copyAction
256 = editMenu->addAction (QIcon::fromTheme ("edit-copy", 252 = editMenu->addAction (QIcon::fromTheme ("edit-copy",
257 style->standardIcon (QStyle::SP_FileIcon)), tr ("Copy")); 253 style->standardIcon (QStyle::SP_FileIcon)), tr ("Copy"));
258 copyAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_C)); 254 copyAction->setShortcut (QKeySequence::Copy);
259 255
260 QAction *pasteAction 256 QAction *pasteAction
261 = editMenu->addAction (QIcon::fromTheme ("edit-paste", 257 = editMenu->addAction (QIcon::fromTheme ("edit-paste",
262 style->standardIcon (QStyle::SP_FileIcon)), tr ("Paste")); 258 style->standardIcon (QStyle::SP_FileIcon)), tr ("Paste"));
263 pasteAction->setShortcut(QKeySequence(Qt::CTRL + Qt::Key_V)); 259 pasteAction->setShortcut (QKeySequence::Paste);
264 260
265 QAction *undoAction 261 QAction *undoAction
266 = editMenu->addAction (QIcon::fromTheme ("edit-undo", 262 = editMenu->addAction (QIcon::fromTheme ("edit-undo",
267 style->standardIcon (QStyle::SP_FileIcon)), tr ("Undo")); 263 style->standardIcon (QStyle::SP_FileIcon)), tr ("Undo"));
264 undoAction->setShortcut (QKeySequence::Undo);
268 265
269 QAction *redoAction 266 QAction *redoAction
270 = editMenu->addAction (QIcon::fromTheme ("edit-redo", 267 = editMenu->addAction (QIcon::fromTheme ("edit-redo",
271 style->standardIcon (QStyle::SP_FileIcon)), tr ("Redo")); 268 style->standardIcon (QStyle::SP_FileIcon)), tr ("Redo"));
269 redoAction->setShortcut (QKeySequence::Redo);
272 270
273 //QMenu *debugMenu = menuBar ()->addMenu (tr ("De&bug")); 271 //QMenu *debugMenu = menuBar ()->addMenu (tr ("De&bug"));
274 //QMenu *parallelMenu = menuBar ()->addMenu (tr ("&Parallel")); 272 //QMenu *parallelMenu = menuBar ()->addMenu (tr ("&Parallel"));
275 273
276 QMenu *desktopMenu = menuBar ()->addMenu (tr ("&Desktop")); 274 QMenu *desktopMenu = menuBar ()->addMenu (tr ("&Desktop"));
294 QAction *octaveForgeAction = helpMenu->addAction (tr ("Visit Octave Forge")); 292 QAction *octaveForgeAction = helpMenu->addAction (tr ("Visit Octave Forge"));
295 helpMenu->addSeparator (); 293 helpMenu->addSeparator ();
296 QAction *aboutOctaveAction = helpMenu->addAction (tr ("About Octave")); 294 QAction *aboutOctaveAction = helpMenu->addAction (tr ("About Octave"));
297 295
298 // Toolbars 296 // Toolbars
299
300 QToolBar *mainToolBar = addToolBar ("Main"); 297 QToolBar *mainToolBar = addToolBar ("Main");
301 mainToolBar->addAction (newFileAction); 298 mainToolBar->addAction (newFileAction);
302 mainToolBar->addAction (openFileAction); 299 mainToolBar->addAction (openFileAction);
303 mainToolBar->addSeparator (); 300 mainToolBar->addSeparator ();
304 mainToolBar->addAction (cutAction); 301 mainToolBar->addAction (cutAction);
313 mainToolBar->addWidget (m_currentDirectoryUpToolButton); 310 mainToolBar->addWidget (m_currentDirectoryUpToolButton);
314 311
315 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ())); 312 connect (settingsAction, SIGNAL (triggered ()), this, SLOT (processSettingsDialogRequest ()));
316 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ())); 313 connect (exitAction, SIGNAL (triggered ()), this, SLOT (close ()));
317 connect (newFileAction, SIGNAL (triggered ()), this, SLOT (newFile ())); 314 connect (newFileAction, SIGNAL (triggered ()), this, SLOT (newFile ()));
315 connect (openFileAction, SIGNAL (triggered ()), this, SLOT (openFile ()));
318 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ())); 316 connect (reportBugAction, SIGNAL (triggered ()), this, SLOT (openBugTrackerPage ()));
319 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ())); 317 connect (agoraAction, SIGNAL (triggered ()), this, SLOT (openAgoraPage ()));
320 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ())); 318 connect (octaveForgeAction, SIGNAL (triggered ()), this, SLOT (openOctaveForgePage ()));
321 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ())); 319 connect (aboutOctaveAction, SIGNAL (triggered ()), this, SLOT (showAboutOctave ()));
322 320
329 327
330 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ())); 328 //connect (this, SIGNAL (settingsChanged ()), m_workspaceView, SLOT (noticeSettings ()));
331 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ())); 329 //connect (this, SIGNAL (settingsChanged ()), m_historyDockWidget, SLOT (noticeSettings ()));
332 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ())); 330 connect (this, SIGNAL (settingsChanged ()), m_filesDockWidget, SLOT (noticeSettings ()));
333 331
334 connect (m_filesDockWidget, SIGNAL (openFile (QString)), this, SLOT (openExistingFile (QString))); 332 connect (m_filesDockWidget, SIGNAL (openFile (QString)), m_fileEditor, SLOT (requestOpenFile (QString)));
335 connect (m_historyDockWidget, SIGNAL (information (QString)), this, SLOT (reportStatusMessage (QString))); 333 connect (m_historyDockWidget, SIGNAL (information (QString)), this, SLOT (reportStatusMessage (QString)));
336 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString))); 334 connect (m_historyDockWidget, SIGNAL (commandDoubleClicked (QString)), this, SLOT (handleCommandDoubleClicked (QString)));
337 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ())); 335 connect (saveWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleSaveWorkspaceRequest ()));
338 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ())); 336 connect (loadWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleLoadWorkspaceRequest ()));
339 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ())); 337 connect (clearWorkspaceAction, SIGNAL (triggered ()), this, SLOT (handleClearWorkspaceRequest ()));
345 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView); 343 addDockWidget (Qt::LeftDockWidgetArea, m_workspaceView);
346 addDockWidget (Qt::LeftDockWidgetArea, m_historyDockWidget); 344 addDockWidget (Qt::LeftDockWidgetArea, m_historyDockWidget);
347 addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget); 345 addDockWidget (Qt::RightDockWidgetArea, m_filesDockWidget);
348 setStatusBar (m_statusBar); 346 setStatusBar (m_statusBar);
349 347
350 // this has to be done only once, not for each editor
351 m_lexer = new LexerOctaveGui ();
352
353 // Editor font (default or from settings)
354 QSettings *settings = ResourceManager::instance ()->settings ();
355 m_lexer->setDefaultFont (QFont (
356 settings->value ("editor/fontName","Courier").toString (),
357 settings->value ("editor/fontSize",10).toInt ()));
358
359 // TODO: Autoindent not working as it should
360 m_lexer->setAutoIndentStyle (QsciScintilla::AiMaintain ||
361 QsciScintilla::AiOpening ||
362 QsciScintilla::AiClosing);
363
364 // The API info that is used for auto completion
365 // TODO: Where to store a file with API info (raw or prepared?)?
366 // TODO: Also provide infos on octave-forge functions?
367 // TODO: Also provide infos on function parameters?
368 // By now, use the keywords-list from syntax highlighting
369 m_lexerAPI = new QsciAPIs (m_lexer);
370
371 QString keyword;
372 QStringList keywordList;
373 keyword = m_lexer->keywords (1); // get whole string with all keywords
374 keywordList = keyword.split (QRegExp ("\\s+")); // split into single strings
375 int i;
376 for (i=0; i<keywordList.size(); i++)
377 {
378 m_lexerAPI->add (keywordList.at (i)); // add single strings to the API
379 }
380 m_lexerAPI->prepare (); // prepare API info ... this make take some time
381
382 readSettings (); 348 readSettings ();
383 updateTerminalFont(); 349 updateTerminalFont();
384 } 350 }
385 351