diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index a0cf9dee3b0..dc9f9282c1a 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -597,6 +597,8 @@ void BaseTextEditor::slotSelectionChanged() viewport()->update(); if (!d->m_inBlockSelectionMode) d->m_blockSelectionExtraX = 0; + if (!d->m_selectBlockAnchor.isNull() && !textCursor().hasSelection()) + d->m_selectBlockAnchor = QTextCursor(); } void BaseTextEditor::gotoBlockStart() @@ -627,6 +629,45 @@ void BaseTextEditor::gotoBlockEndWithSelection() setTextCursor(cursor); } +void BaseTextEditor::selectBlockUp() +{ + QTextCursor cursor = textCursor(); + if (!cursor.hasSelection()) + d->m_selectBlockAnchor = cursor; + else + cursor.setPosition(cursor.selectionStart()); + + + if (!TextBlockUserData::findPreviousOpenParenthesis(&cursor, false)) + return; + if (!TextBlockUserData::findNextClosingParenthesis(&cursor, true)) + return; + setTextCursor(cursor); +} + +void BaseTextEditor::selectBlockDown() +{ + QTextCursor tc = textCursor(); + QTextCursor cursor = d->m_selectBlockAnchor; + + if (!tc.hasSelection() || cursor.isNull()) + return; + tc.setPosition(tc.selectionStart()); + + forever { + QTextCursor ahead = cursor; + if (!TextBlockUserData::findPreviousOpenParenthesis(&ahead, false)) + break; + if (ahead.position() <= tc.position()) + break; + cursor = ahead; + } + if ( cursor != d->m_selectBlockAnchor) + TextBlockUserData::findNextClosingParenthesis(&cursor, true); + + setTextCursor(cursor); +} + void BaseTextEditor::keyPressEvent(QKeyEvent *e) diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 54e4728c4b4..23b9951ccb0 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -326,6 +326,9 @@ public slots: void gotoBlockStartWithSelection(); void gotoBlockEndWithSelection(); + void selectBlockUp(); + void selectBlockDown(); + signals: void changed(); diff --git a/src/plugins/texteditor/basetexteditor_p.h b/src/plugins/texteditor/basetexteditor_p.h index 87d1af0de0f..56b1071e1c6 100644 --- a/src/plugins/texteditor/basetexteditor_p.h +++ b/src/plugins/texteditor/basetexteditor_p.h @@ -216,6 +216,7 @@ public: void removeBlockSelection(const QString &text = QString()); QTextCursor m_findScope; + QTextCursor m_selectBlockAnchor; void moveCursorVisible(); }; diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index a9e955eae36..635f9654576 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -69,6 +69,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core, = m_increaseFontSizeAction = m_decreaseFontSizeAction = m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction = m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction + = m_selectBlockUpAction = m_selectBlockDownAction = 0; m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context); @@ -163,13 +164,11 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_collapseAction, Constants::COLLAPSE, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+<"))); connect(m_collapseAction, SIGNAL(triggered()), this, SLOT(collapse())); - advancedMenu->addAction(command); m_expandAction = new QAction(tr("Expand"), this); command = am->registerAction(m_expandAction, Constants::EXPAND, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+>"))); connect(m_expandAction, SIGNAL(triggered()), this, SLOT(expand())); - advancedMenu->addAction(command); m_unCollapseAllAction = new QAction(tr("(Un)&Collapse All"), this); command = am->registerAction(m_unCollapseAllAction, Constants::UN_COLLAPSE_ALL, m_contextId); @@ -208,6 +207,15 @@ void TextEditorActionHandler::createActions() command->setDefaultKeySequence(QKeySequence(tr("Ctrl+}"))); connect(m_gotoBlockEndWithSelectionAction, SIGNAL(triggered()), this, SLOT(gotoBlockEndWithSelection())); + m_selectBlockUpAction= new QAction(tr("Select Block Up"), this); + command = am->registerAction(m_selectBlockUpAction, Constants::SELECT_BLOCK_UP, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+U"))); + connect(m_selectBlockUpAction, SIGNAL(triggered()), this, SLOT(selectBlockUp())); + + m_selectBlockDownAction= new QAction(tr("Select Block Down"), this); + command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U"))); + connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown())); } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -252,35 +260,30 @@ void TextEditorActionHandler::updateActions() void TextEditorActionHandler::updateActions(UpdateMode um) { - if (m_pasteAction) - m_pasteAction->setEnabled(um != NoEditor); - if (m_selectAllAction) - m_selectAllAction->setEnabled(um != NoEditor); - if (m_gotoAction) - m_gotoAction->setEnabled(um != NoEditor); - if (m_selectEncodingAction) - m_selectEncodingAction->setEnabled(um != NoEditor); - if (m_printAction) - m_printAction->setEnabled(um != NoEditor); - if (m_formatAction) - m_formatAction->setEnabled((m_optionalActions & Format) && um != NoEditor); - if (m_unCommentSelectionAction) - m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != NoEditor); - if (m_collapseAction) - m_collapseAction->setEnabled(um != NoEditor); - if (m_expandAction) - m_expandAction->setEnabled(um != NoEditor); - if (m_unCollapseAllAction) - m_unCollapseAllAction->setEnabled((m_optionalActions & UnCollapseAll) && um != NoEditor); - if (m_decreaseFontSizeAction) - m_decreaseFontSizeAction->setEnabled(um != NoEditor); - if (m_increaseFontSizeAction) - m_increaseFontSizeAction->setEnabled(um != NoEditor); - if (m_visualizeWhitespaceAction) { - m_visualizeWhitespaceAction->setEnabled(um != NoEditor); - if (m_currentEditor) - m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace); - } + if (!m_initialized) + return; + m_pasteAction->setEnabled(um != NoEditor); + m_selectAllAction->setEnabled(um != NoEditor); + m_gotoAction->setEnabled(um != NoEditor); + m_selectEncodingAction->setEnabled(um != NoEditor); + m_printAction->setEnabled(um != NoEditor); + m_formatAction->setEnabled((m_optionalActions & Format) && um != NoEditor); + m_unCommentSelectionAction->setEnabled((m_optionalActions & UnCommentSelection) && um != NoEditor); + m_collapseAction->setEnabled(um != NoEditor); + m_expandAction->setEnabled(um != NoEditor); + m_unCollapseAllAction->setEnabled((m_optionalActions & UnCollapseAll) && um != NoEditor); + m_decreaseFontSizeAction->setEnabled(um != NoEditor); + m_increaseFontSizeAction->setEnabled(um != NoEditor); + m_gotoBlockStartAction->setEnabled(um != NoEditor); + m_gotoBlockStartWithSelectionAction->setEnabled(um != NoEditor); + m_gotoBlockEndAction->setEnabled(um != NoEditor); + m_gotoBlockEndWithSelectionAction->setEnabled(um != NoEditor); + m_selectBlockUpAction->setEnabled(um != NoEditor); + m_selectBlockDownAction->setEnabled(um != NoEditor); + + m_visualizeWhitespaceAction->setEnabled(um != NoEditor); + if (m_currentEditor) + m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace); if (m_textWrappingAction) { m_textWrappingAction->setEnabled(um != NoEditor); if (m_currentEditor) @@ -411,6 +414,8 @@ FUNCTION(gotoBlockStart) FUNCTION(gotoBlockEnd) FUNCTION(gotoBlockStartWithSelection) FUNCTION(gotoBlockEndWithSelection) +FUNCTION(selectBlockUp) +FUNCTION(selectBlockDown) void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object) { diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index f9fe9f249af..9a8c7b9f57c 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -113,6 +113,8 @@ private slots: void gotoBlockEnd(); void gotoBlockStartWithSelection(); void gotoBlockEndWithSelection(); + void selectBlockUp(); + void selectBlockDown(); void updateCurrentEditor(Core::IContext *object); private: @@ -139,6 +141,8 @@ private: QAction *m_gotoBlockEndAction; QAction *m_gotoBlockStartWithSelectionAction; QAction *m_gotoBlockEndWithSelectionAction; + QAction *m_selectBlockUpAction; + QAction *m_selectBlockDownAction; uint m_optionalActions; QPointer m_currentEditor; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 9415d732da9..9ac9fdff0e4 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -52,6 +52,8 @@ const char * const GOTO_BLOCK_START = "TextEditor.GotoBlockStart"; const char * const GOTO_BLOCK_START_WITH_SELECTION = "TextEditor.GotoBlockStartWithSelection"; const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd"; const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection"; +const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp"; +const char * const SELECT_BLOCK_DOWN = "TextEditor.SelectBlockDown"; const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_WORD = "TextEditor.DeleteWord"; const char * const SELECT_ENCODING = "TextEditor.SelectEncoding";