diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 7a25b43c7fcf1cf5524550f7a3a007035fbef5f3..3ded8b3c8d84619a1bca22448c2ee8af5fd202ae 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -694,6 +694,66 @@ void BaseTextEditor::selectBlockDown() _q_matchParentheses(); } +void BaseTextEditor::copyLineUp() +{ + copyLineUpDown(true); +} + +void BaseTextEditor::copyLineDown() +{ + copyLineUpDown(false); +} + +void BaseTextEditor::copyLineUpDown(bool up) +{ + QTextCursor cursor = textCursor(); + QTextCursor move = cursor; + move.beginEditBlock(); + + bool hasSelection = cursor.hasSelection(); + + if (hasSelection) { + move.setPosition(cursor.selectionStart()); + move.movePosition(QTextCursor::StartOfBlock); + move.setPosition(cursor.selectionEnd(), QTextCursor::KeepAnchor); + move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + } else { + move.movePosition(QTextCursor::StartOfBlock); + move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + } + + QString text = move.selectedText(); + + if (up) { + move.setPosition(cursor.selectionStart()); + move.movePosition(QTextCursor::StartOfBlock); + move.insertBlock(); + move.movePosition(QTextCursor::Left); + } else { + move.movePosition(QTextCursor::EndOfBlock); + if (move.atBlockStart()) { + move.movePosition(QTextCursor::NextBlock); + move.insertBlock(); + move.movePosition(QTextCursor::Left); + } else { + move.insertBlock(); + } + } + + int start = move.position(); + move.clearSelection(); + move.insertText(text); + int end = move.position(); + + move.setPosition(start); + move.setPosition(end, QTextCursor::KeepAnchor); + + indent(document(), move, QChar::Null); + move.endEditBlock(); + + setTextCursor(move); +} + void BaseTextEditor::moveLineUp() { moveLineUpDown(true); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index e45ab281f953b2faef8e59a4c162a12f9f3ebc82..612a9fe4efa2964b1c830f9ae18a8250e513842b 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -388,6 +388,9 @@ public slots: void moveLineUp(); void moveLineDown(); + void copyLineUp(); + void copyLineDown(); + void cleanWhitespace(); signals: @@ -513,6 +516,7 @@ private: void handleHomeKey(bool anchor); void handleBackspaceKey(); void moveLineUpDown(bool up); + void copyLineUpDown(bool up); void saveCurrentCursorPositionForNavigation(); void drawFoldingMarker(QPainter *painter, const QPalette &pal, diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 9aa4e1609b2253956520c2f58acf7ee5b7ea3270..3356dc50f09b917975361dff4e582a08f13a20b0 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -85,6 +85,8 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context, m_selectBlockDownAction = 0; m_moveLineUpAction = 0; m_moveLineDownAction = 0; + m_copyLineUpAction = 0; + m_copyLineDownAction = 0; m_contextId << Core::UniqueIDManager::instance()->uniqueIdentifier(context); @@ -251,6 +253,16 @@ void TextEditorActionHandler::createActions() command = am->registerAction(m_moveLineDownAction, Constants::MOVE_LINE_DOWN, m_contextId); command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Down"))); connect(m_moveLineDownAction, SIGNAL(triggered()), this, SLOT(moveLineDown())); + + m_copyLineUpAction= new QAction(tr("Copy Line Up"), this); + command = am->registerAction(m_copyLineUpAction, Constants::COPY_LINE_UP, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Up"))); + connect(m_copyLineUpAction, SIGNAL(triggered()), this, SLOT(copyLineUp())); + + m_copyLineDownAction= new QAction(tr("Copy Line Down"), this); + command = am->registerAction(m_copyLineDownAction, Constants::COPY_LINE_DOWN, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Alt+Down"))); + connect(m_copyLineDownAction, SIGNAL(triggered()), this, SLOT(copyLineDown())); } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -406,6 +418,8 @@ FUNCTION(selectBlockUp) FUNCTION(selectBlockDown) FUNCTION(moveLineUp) FUNCTION(moveLineDown) +FUNCTION(copyLineUp) +FUNCTION(copyLineDown) void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) { diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index 1061b7a9674c6eaf60abe361477b981b0c33b893..c1140413681c01c50ec38c8c38254d7b8a106fb6 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -111,6 +111,8 @@ private slots: void selectBlockDown(); void moveLineUp(); void moveLineDown(); + void copyLineUp(); + void copyLineDown(); void updateCurrentEditor(Core::IEditor *editor); private: @@ -143,6 +145,8 @@ private: QAction *m_selectBlockDownAction; QAction *m_moveLineUpAction; QAction *m_moveLineDownAction; + QAction *m_copyLineUpAction; + QAction *m_copyLineDownAction; uint m_optionalActions; QPointer<BaseTextEditor> m_currentEditor; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index 8278a224fc549c31ff299835d4484f5baa7478e0..2545fc66a34efc6d69f359be9fcbc12b6396f8cb 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -53,6 +53,8 @@ const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp"; const char * const SELECT_BLOCK_DOWN = "TextEditor.SelectBlockDown"; const char * const MOVE_LINE_UP = "TextEditor.MoveLineUp"; const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown"; +const char * const COPY_LINE_UP = "TextEditor.CopyLineUp"; +const char * const COPY_LINE_DOWN = "TextEditor.CopyLineDown"; const char * const CUT_LINE = "TextEditor.CutLine"; const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_WORD = "TextEditor.DeleteWord";