forked from qt-creator/qt-creator
Merge branch 'copylines'
Conflicts: src/plugins/texteditor/texteditorconstants.h
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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";
|
||||
|
||||
Reference in New Issue
Block a user