Commit 2dd04664 authored by Serge Ratke's avatar Serge Ratke

implementation of copy lines up/down functionality

parent bb6f56f5
......@@ -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);
......
......@@ -387,6 +387,9 @@ public slots:
void moveLineUp();
void moveLineDown();
void copyLineUp();
void copyLineDown();
void cleanWhitespace();
signals:
......@@ -509,6 +512,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,
......
......@@ -84,6 +84,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);
......@@ -246,6 +248,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
......@@ -400,6 +412,8 @@ FUNCTION(selectBlockUp)
FUNCTION(selectBlockDown)
FUNCTION(moveLineUp)
FUNCTION(moveLineDown)
FUNCTION(copyLineUp)
FUNCTION(copyLineDown)
void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
{
......
......@@ -110,6 +110,8 @@ private slots:
void selectBlockDown();
void moveLineUp();
void moveLineDown();
void copyLineUp();
void copyLineDown();
void updateCurrentEditor(Core::IEditor *editor);
private:
......@@ -141,6 +143,8 @@ private:
QAction *m_selectBlockDownAction;
QAction *m_moveLineUpAction;
QAction *m_moveLineDownAction;
QAction *m_copyLineUpAction;
QAction *m_copyLineDownAction;
uint m_optionalActions;
QPointer<BaseTextEditor> m_currentEditor;
......
......@@ -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 DELETE_LINE = "TextEditor.DeleteLine";
const char * const DELETE_WORD = "TextEditor.DeleteWord";
const char * const SELECT_ENCODING = "TextEditor.SelectEncoding";
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment