comparison gui/src/FileEditorMdiSubWindow.cpp @ 13562:a89aa9e05e19

editor: menu bar, run editor file in octave
author ttl <ttl@justmail.de>
date Sun, 31 Jul 2011 22:33:50 +0200
parents 248b897d9f36
children d22b9973120f
comparison
equal deleted inserted replaced
13561:dd029759f57e 13562:a89aa9e05e19
15 * You should have received a copy of the GNU General Public License 15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */ 17 */
18 18
19 #include "FileEditorMdiSubWindow.h" 19 #include "FileEditorMdiSubWindow.h"
20 #include "MainWindow.h"
20 #include <QVBoxLayout> 21 #include <QVBoxLayout>
21 #include <QApplication> 22 #include <QApplication>
22 #include <QFile> 23 #include <QFile>
23 #include <QFileDialog> 24 #include <QFileDialog>
24 #include <QMessageBox> 25 #include <QMessageBox>
209 if(saveFileName.isEmpty()) 210 if(saveFileName.isEmpty())
210 return; 211 return;
211 saveFile(saveFileName); 212 saveFile(saveFileName);
212 } 213 }
213 214
214 void 215 // handle the run command
215 FileEditorMdiSubWindow::setEditorLexer (LexerOctaveGui* lexer) 216 void
217 FileEditorMdiSubWindow::runFile ()
218 {
219 if (m_editor->isModified ())
220 saveFile(m_fileName);
221 m_octave->sendText (QString ("run \'%1\'\n").arg (m_fileName));
222 m_octave->setFocus ();
223 }
224
225 // function for setting the already existing lexer from MainWindow
226 void
227 FileEditorMdiSubWindow::initEditor (OctaveTerminal* terminal,
228 LexerOctaveGui* lexer)
216 { 229 {
217 m_editor->setLexer(lexer); 230 m_editor->setLexer(lexer);
231 m_octave = terminal; // for sending commands to octave
232 // TODO: make a global commandOctave function?
218 } 233 }
219 234
220 // TODO: Do we still need tool tips in the status bar? Tool tips are now 235 // TODO: Do we still need tool tips in the status bar? Tool tips are now
221 // shown directly at the theme icons 236 // shown directly at the theme icons
222 void 237 void
264 void 279 void
265 FileEditorMdiSubWindow::construct () 280 FileEditorMdiSubWindow::construct ()
266 { 281 {
267 QStyle *style = QApplication::style (); 282 QStyle *style = QApplication::style ();
268 setWidget (new QWidget ()); 283 setWidget (new QWidget ());
284 m_menuBar = new QMenuBar (this);
269 m_toolBar = new QToolBar (this); 285 m_toolBar = new QToolBar (this);
270 m_statusBar = new QStatusBar (this); 286 m_statusBar = new QStatusBar (this);
271 m_editor = new QsciScintilla (this); 287 m_editor = new QsciScintilla (this);
272 288
273 m_editor->setMarginType (1, QsciScintilla::SymbolMargin); 289 m_editor->setMarginType (1, QsciScintilla::SymbolMargin);
285 m_editor->setIndentationsUseTabs (false); 301 m_editor->setIndentationsUseTabs (false);
286 m_editor->autoCompleteFromAll(); 302 m_editor->autoCompleteFromAll();
287 m_editor->setAutoCompletionSource(QsciScintilla::AcsAPIs); 303 m_editor->setAutoCompletionSource(QsciScintilla::AcsAPIs);
288 m_editor->setAutoCompletionThreshold (3); 304 m_editor->setAutoCompletionThreshold (3);
289 305
306 // The Actions
307
290 // Theme icons with QStyle icons as fallback 308 // Theme icons with QStyle icons as fallback
291 m_toolBar->setIconSize(QSize(20,20)); // smaller icons (make configurable in user settings?)
292 QAction *closeAction = new QAction ( 309 QAction *closeAction = new QAction (
293 QIcon::fromTheme("window-close",style->standardIcon (QStyle::SP_DialogCloseButton)), 310 QIcon::fromTheme("window-close",style->standardIcon (QStyle::SP_DialogCloseButton)),
294 tr("&Close File"), m_toolBar); 311 tr("&Close File"), m_toolBar);
295 QAction *newAction = new QAction ( 312 QAction *newAction = new QAction (
296 QIcon::fromTheme("document-new",style->standardIcon (QStyle::SP_FileIcon)), 313 QIcon::fromTheme("document-new",style->standardIcon (QStyle::SP_FileIcon)),
308 QIcon::fromTheme("edit-undo",style->standardIcon (QStyle::SP_ArrowLeft)), 325 QIcon::fromTheme("edit-undo",style->standardIcon (QStyle::SP_ArrowLeft)),
309 tr("&Undo"), m_toolBar); 326 tr("&Undo"), m_toolBar);
310 QAction *redoAction = new QAction ( 327 QAction *redoAction = new QAction (
311 QIcon::fromTheme("edit-redo",style->standardIcon (QStyle::SP_ArrowRight)), 328 QIcon::fromTheme("edit-redo",style->standardIcon (QStyle::SP_ArrowRight)),
312 tr("&Redo"), m_toolBar); 329 tr("&Redo"), m_toolBar);
330 QAction *copyAction = new QAction (QIcon::fromTheme("edit-copy"),tr("&Copy"),m_toolBar);
331 QAction *cutAction = new QAction (QIcon::fromTheme("edit-cut"),tr("Cu&t"),m_toolBar);
332 QAction *pasteAction = new QAction (QIcon::fromTheme("edit-paste"),tr("&Paste"),m_toolBar);
333 QAction *runAction = new QAction (
334 QIcon::fromTheme("media-play",style->standardIcon (QStyle::SP_MediaPlay)),
335 tr("&Run File"), m_toolBar);
313 336
314 // short cuts 337 // short cuts
315 newAction->setShortcut(QKeySequence::New); 338 newAction->setShortcut(QKeySequence::New);
316 openAction->setShortcut(QKeySequence::Open); 339 openAction->setShortcut(QKeySequence::Open);
317 saveAction->setShortcut(QKeySequence::Save); 340 saveAction->setShortcut(QKeySequence::Save);
318 saveAsAction->setShortcut(QKeySequence::SaveAs); 341 saveAsAction->setShortcut(QKeySequence::SaveAs);
319 undoAction->setShortcut(QKeySequence::Undo); 342 undoAction->setShortcut(QKeySequence::Undo);
320 redoAction->setShortcut(QKeySequence::Redo); 343 redoAction->setShortcut(QKeySequence::Redo);
321 344 copyAction->setShortcut(QKeySequence::Copy);
345 cutAction->setShortcut(QKeySequence::Cut);
346 pasteAction->setShortcut(QKeySequence::Paste);
347 runAction->setShortcut(Qt::Key_F5);
348
349 // toolbar
350 m_toolBar->setIconSize(QSize(20,20)); // smaller icons (make configurable in user settings?)
322 m_toolBar->addAction (closeAction); 351 m_toolBar->addAction (closeAction);
323 m_toolBar->addAction (newAction); 352 m_toolBar->addAction (newAction);
324 m_toolBar->addAction (openAction); 353 m_toolBar->addAction (openAction);
325 m_toolBar->addAction (saveAction); 354 m_toolBar->addAction (saveAction);
326 m_toolBar->addAction (saveAsAction); 355 m_toolBar->addAction (saveAsAction);
356 m_toolBar->addSeparator();
327 m_toolBar->addAction (undoAction); 357 m_toolBar->addAction (undoAction);
328 m_toolBar->addAction (redoAction); 358 m_toolBar->addAction (redoAction);
359 m_toolBar->addAction (copyAction);
360 m_toolBar->addAction (cutAction);
361 m_toolBar->addAction (pasteAction);
362 m_toolBar->addSeparator();
363 m_toolBar->addAction (runAction);
364
365 // menu bar
366 QMenu *fileMenu = new QMenu(tr("&File"),m_menuBar);
367 fileMenu->addAction(newAction);
368 fileMenu->addAction(openAction);
369 fileMenu->addAction(saveAction);
370 fileMenu->addAction(saveAsAction);
371 fileMenu->addSeparator();
372 fileMenu->addAction (closeAction);
373 m_menuBar->addMenu(fileMenu);
374 QMenu *editMenu = new QMenu(tr("&Edit"),m_menuBar);
375 editMenu->addAction(undoAction);
376 editMenu->addAction(redoAction);
377 fileMenu->addSeparator();
378 editMenu->addAction(copyAction);
379 editMenu->addAction(cutAction);
380 editMenu->addAction(pasteAction);
381 m_menuBar->addMenu(editMenu);
382 QMenu *runMenu = new QMenu(tr("&Run"),m_menuBar);
383 runMenu->addAction(runAction);
384 m_menuBar->addMenu(runMenu);
329 385
330 QVBoxLayout *layout = new QVBoxLayout (); 386 QVBoxLayout *layout = new QVBoxLayout ();
387 layout->addWidget (m_menuBar);
331 layout->addWidget (m_toolBar); 388 layout->addWidget (m_toolBar);
332 layout->addWidget (m_editor); 389 layout->addWidget (m_editor);
333 layout->addWidget (m_statusBar); 390 layout->addWidget (m_statusBar);
334 layout->setMargin (2); 391 layout->setMargin (2);
335 widget ()->setLayout (layout); 392 widget ()->setLayout (layout);
337 connect (closeAction, SIGNAL (triggered()), this, SLOT (close())); 394 connect (closeAction, SIGNAL (triggered()), this, SLOT (close()));
338 connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ())); 395 connect (newAction, SIGNAL (triggered ()), this, SLOT (newFile ()));
339 connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ())); 396 connect (openAction, SIGNAL (triggered ()), this, SLOT (openFile ()));
340 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ())); 397 connect (undoAction, SIGNAL (triggered ()), m_editor, SLOT (undo ()));
341 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ())); 398 connect (redoAction, SIGNAL (triggered ()), m_editor, SLOT (redo ()));
399 connect (copyAction, SIGNAL (triggered ()), m_editor, SLOT (copy ()));
400 connect (cutAction, SIGNAL (triggered ()), m_editor, SLOT (cut ()));
401 connect (pasteAction, SIGNAL (triggered ()), m_editor, SLOT (paste ()));
342 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ())); 402 connect (saveAction, SIGNAL (triggered ()), this, SLOT (saveFile ()));
343 connect (saveAsAction, SIGNAL (triggered ()), this, SLOT (saveFileAs ())); 403 connect (saveAsAction, SIGNAL (triggered ()), this, SLOT (saveFileAs ()));
404 connect (runAction, SIGNAL (triggered ()), this, SLOT (runFile ()));
344 405
345 // TODO: Do we still need tool tips in the status bar? Tool tips are now 406 // TODO: Do we still need tool tips in the status bar? Tool tips are now
346 // shown directly at the theme icons 407 // shown directly at the theme icons
347 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ())); 408 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ()));
348 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ())); 409 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ()));