Mercurial > octave-nkf
comparison gui/src/FileEditorMdiSubWindow.cpp @ 13654:c67f7d390a1a
editor: comment/uncomment selected text
author | ttl <ttl@justmail.de> |
---|---|
date | Thu, 25 Aug 2011 20:12:31 +0200 |
parents | b93bfa9486ad |
children | 1347d498959c |
comparison
equal
deleted
inserted
replaced
13653:0ee1b81a0538 | 13654:c67f7d390a1a |
---|---|
244 if (m_editor->isModified ()) | 244 if (m_editor->isModified ()) |
245 saveFile(m_fileName); | 245 saveFile(m_fileName); |
246 m_terminalEmulation->transmitText (QString ("run \'%1\'\n").arg (m_fileName)); | 246 m_terminalEmulation->transmitText (QString ("run \'%1\'\n").arg (m_fileName)); |
247 //m_terminalEmulation->setFocus (); | 247 //m_terminalEmulation->setFocus (); |
248 } | 248 } |
249 | |
250 | |
251 // (un)comment selected text | |
252 void | |
253 FileEditorMdiSubWindow::commentSelectedText () | |
254 { | |
255 doCommentSelectedText (true); | |
256 } | |
257 void | |
258 FileEditorMdiSubWindow::uncommentSelectedText () | |
259 { | |
260 doCommentSelectedText (false); | |
261 } | |
262 void | |
263 FileEditorMdiSubWindow::doCommentSelectedText (bool comment) | |
264 { | |
265 if ( m_editor->hasSelectedText() ) | |
266 { | |
267 int lineFrom, lineTo, colFrom, colTo, i; | |
268 m_editor->getSelection (&lineFrom,&colFrom,&lineTo,&colTo); | |
269 if ( colTo == 0 ) // the beginning of last line is not selected | |
270 lineTo--; // stop at line above | |
271 for ( i=lineFrom; i<=lineTo; i++ ) | |
272 { | |
273 if ( comment ) | |
274 m_editor->insertAt("%",i,0); | |
275 else | |
276 { | |
277 QString line(m_editor->text(i)); | |
278 if ( line.startsWith("%") ) | |
279 { | |
280 m_editor->setSelection(i,0,i,1); | |
281 m_editor->removeSelectedText(); | |
282 } | |
283 } | |
284 } | |
285 } | |
286 } | |
287 | |
249 | 288 |
250 // remove bookmarks | 289 // remove bookmarks |
251 void | 290 void |
252 FileEditorMdiSubWindow::removeBookmark () | 291 FileEditorMdiSubWindow::removeBookmark () |
253 { | 292 { |
412 m_cutAction = new QAction (QIcon::fromTheme("edit-cut"),tr("Cu&t"),m_toolBar); | 451 m_cutAction = new QAction (QIcon::fromTheme("edit-cut"),tr("Cu&t"),m_toolBar); |
413 QAction *pasteAction = new QAction (QIcon::fromTheme("edit-paste"),tr("&Paste"),m_toolBar); | 452 QAction *pasteAction = new QAction (QIcon::fromTheme("edit-paste"),tr("&Paste"),m_toolBar); |
414 QAction *nextBookmarkAction = new QAction (tr("&Next Bookmark"),m_toolBar); | 453 QAction *nextBookmarkAction = new QAction (tr("&Next Bookmark"),m_toolBar); |
415 QAction *prevBookmarkAction = new QAction (tr("Pre&vious Bookmark"),m_toolBar); | 454 QAction *prevBookmarkAction = new QAction (tr("Pre&vious Bookmark"),m_toolBar); |
416 QAction *toggleBookmarkAction = new QAction (tr("Toggle &Bookmark"),m_toolBar); | 455 QAction *toggleBookmarkAction = new QAction (tr("Toggle &Bookmark"),m_toolBar); |
417 QAction *removeBookmarkAction = new QAction (tr("&Remove All &Bookmarks"),m_toolBar); | 456 QAction *removeBookmarkAction = new QAction (tr("&Remove All Bookmarks"),m_toolBar); |
457 QAction *commentSelectedAction = new QAction (tr("&Comment Selected Text"),m_toolBar); | |
458 QAction *uncommentSelectedAction = new QAction (tr("&Uncomment Selected Text"),m_toolBar); | |
418 QAction *runAction = new QAction ( | 459 QAction *runAction = new QAction ( |
419 QIcon::fromTheme("media-play",style->standardIcon (QStyle::SP_MediaPlay)), | 460 QIcon::fromTheme("media-play",style->standardIcon (QStyle::SP_MediaPlay)), |
420 tr("&Run File"), m_toolBar); | 461 tr("&Run File"), m_toolBar); |
421 | 462 |
422 // some actions are disabled from the beginning | 463 // some actions are disabled from the beginning |
436 pasteAction->setShortcut(QKeySequence::Paste); | 477 pasteAction->setShortcut(QKeySequence::Paste); |
437 runAction->setShortcut(Qt::Key_F5); | 478 runAction->setShortcut(Qt::Key_F5); |
438 nextBookmarkAction->setShortcut(Qt::Key_F2); | 479 nextBookmarkAction->setShortcut(Qt::Key_F2); |
439 prevBookmarkAction->setShortcut(Qt::SHIFT + Qt::Key_F2); | 480 prevBookmarkAction->setShortcut(Qt::SHIFT + Qt::Key_F2); |
440 toggleBookmarkAction->setShortcut(Qt::Key_F7); | 481 toggleBookmarkAction->setShortcut(Qt::Key_F7); |
482 commentSelectedAction->setShortcut(Qt::CTRL + Qt::Key_T); | |
483 uncommentSelectedAction->setShortcut(Qt::CTRL + Qt::Key_U); | |
441 | 484 |
442 // toolbar | 485 // toolbar |
443 m_toolBar->setIconSize(QSize(16,16)); // smaller icons (make configurable in user settings?) | 486 m_toolBar->setIconSize(QSize(16,16)); // smaller icons (make configurable in user settings?) |
444 m_toolBar->addAction (closeAction); | 487 m_toolBar->addAction (closeAction); |
445 m_toolBar->addAction (newAction); | 488 m_toolBar->addAction (newAction); |
470 editMenu->addSeparator(); | 513 editMenu->addSeparator(); |
471 editMenu->addAction(m_copyAction); | 514 editMenu->addAction(m_copyAction); |
472 editMenu->addAction(m_cutAction); | 515 editMenu->addAction(m_cutAction); |
473 editMenu->addAction(pasteAction); | 516 editMenu->addAction(pasteAction); |
474 editMenu->addSeparator(); | 517 editMenu->addSeparator(); |
518 editMenu->addAction(commentSelectedAction); | |
519 editMenu->addAction(uncommentSelectedAction); | |
520 editMenu->addSeparator(); | |
475 editMenu->addAction(toggleBookmarkAction); | 521 editMenu->addAction(toggleBookmarkAction); |
476 editMenu->addAction(nextBookmarkAction); | 522 editMenu->addAction(nextBookmarkAction); |
477 editMenu->addAction(prevBookmarkAction); | 523 editMenu->addAction(prevBookmarkAction); |
478 editMenu->addAction(removeBookmarkAction); | 524 editMenu->addAction(removeBookmarkAction); |
479 m_menuBar->addMenu(editMenu); | 525 m_menuBar->addMenu(editMenu); |
503 connect (runAction, SIGNAL (triggered ()), this, SLOT (runFile ())); | 549 connect (runAction, SIGNAL (triggered ()), this, SLOT (runFile ())); |
504 connect (toggleBookmarkAction, SIGNAL (triggered ()), this, SLOT (toggleBookmark ())); | 550 connect (toggleBookmarkAction, SIGNAL (triggered ()), this, SLOT (toggleBookmark ())); |
505 connect (nextBookmarkAction, SIGNAL (triggered ()), this, SLOT (nextBookmark ())); | 551 connect (nextBookmarkAction, SIGNAL (triggered ()), this, SLOT (nextBookmark ())); |
506 connect (prevBookmarkAction, SIGNAL (triggered ()), this, SLOT (prevBookmark ())); | 552 connect (prevBookmarkAction, SIGNAL (triggered ()), this, SLOT (prevBookmark ())); |
507 connect (removeBookmarkAction, SIGNAL (triggered ()), this, SLOT (removeBookmark ())); | 553 connect (removeBookmarkAction, SIGNAL (triggered ()), this, SLOT (removeBookmark ())); |
554 connect (commentSelectedAction, SIGNAL (triggered ()), this, SLOT (commentSelectedText ())); | |
555 connect (uncommentSelectedAction, SIGNAL (triggered ()), this, SLOT (uncommentSelectedText ())); | |
508 | 556 |
509 // TODO: Do we still need tool tips in the status bar? Tool tips are now | 557 // TODO: Do we still need tool tips in the status bar? Tool tips are now |
510 // shown directly at the theme icons | 558 // shown directly at the theme icons |
511 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ())); | 559 connect (newAction, SIGNAL (hovered ()), this, SLOT (showToolTipNew ())); |
512 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ())); | 560 connect (openAction, SIGNAL (hovered ()), this, SLOT (showToolTipOpen ())); |