forked from qt-creator/qt-creator
added Move Line Up and Move Line Down actions. Can be extended to
support statements later.
This commit is contained in:
@@ -684,6 +684,64 @@ void BaseTextEditor::selectBlockDown()
|
|||||||
_q_matchParentheses();
|
_q_matchParentheses();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::moveLineUp()
|
||||||
|
{
|
||||||
|
moveLineUpDown(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::moveLineDown()
|
||||||
|
{
|
||||||
|
moveLineUpDown(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
void BaseTextEditor::moveLineUpDown(bool up)
|
||||||
|
{
|
||||||
|
QTextCursor cursor = textCursor();
|
||||||
|
QTextCursor move = cursor;
|
||||||
|
move.beginEditBlock();
|
||||||
|
|
||||||
|
bool hasSelection = cursor.hasSelection();
|
||||||
|
|
||||||
|
if (cursor.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();
|
||||||
|
move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor);
|
||||||
|
move.removeSelectedText();
|
||||||
|
|
||||||
|
if (up) {
|
||||||
|
move.movePosition(QTextCursor::PreviousBlock);
|
||||||
|
move.insertBlock();
|
||||||
|
move.movePosition(QTextCursor::Left);
|
||||||
|
} else {
|
||||||
|
move.movePosition(QTextCursor::EndOfBlock);
|
||||||
|
if (move.atBlockStart()) { // empty block
|
||||||
|
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.endEditBlock();
|
||||||
|
if (hasSelection) {
|
||||||
|
move.setPosition(start);
|
||||||
|
move.setPosition(end, QTextCursor::KeepAnchor);
|
||||||
|
}
|
||||||
|
|
||||||
|
setTextCursor(move);
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditor::cleanWhitespace()
|
void BaseTextEditor::cleanWhitespace()
|
||||||
{
|
{
|
||||||
@@ -740,9 +798,13 @@ void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
|||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
if (d->m_inBlockSelectionMode)
|
if (d->m_inBlockSelectionMode)
|
||||||
cursor.clearSelection();
|
cursor.clearSelection();
|
||||||
cursor.insertBlock();
|
|
||||||
if (d->m_document->tabSettings().m_autoIndent) {
|
if (d->m_document->tabSettings().m_autoIndent) {
|
||||||
|
cursor.beginEditBlock();
|
||||||
|
cursor.insertBlock();
|
||||||
indent(document(), cursor, QChar::Null);
|
indent(document(), cursor, QChar::Null);
|
||||||
|
cursor.endEditBlock();
|
||||||
|
} else {
|
||||||
|
cursor.insertBlock();
|
||||||
}
|
}
|
||||||
e->accept();
|
e->accept();
|
||||||
setTextCursor(cursor);
|
setTextCursor(cursor);
|
||||||
|
|||||||
@@ -329,6 +329,9 @@ public slots:
|
|||||||
void selectBlockUp();
|
void selectBlockUp();
|
||||||
void selectBlockDown();
|
void selectBlockDown();
|
||||||
|
|
||||||
|
void moveLineUp();
|
||||||
|
void moveLineDown();
|
||||||
|
|
||||||
void cleanWhitespace();
|
void cleanWhitespace();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
@@ -447,6 +450,7 @@ private:
|
|||||||
void indentOrUnindent(bool doIndent);
|
void indentOrUnindent(bool doIndent);
|
||||||
void handleHomeKey(bool anchor);
|
void handleHomeKey(bool anchor);
|
||||||
void handleBackspaceKey();
|
void handleBackspaceKey();
|
||||||
|
void moveLineUpDown(bool up);
|
||||||
|
|
||||||
void toggleBlockVisible(const QTextBlock &block);
|
void toggleBlockVisible(const QTextBlock &block);
|
||||||
QRect collapseBox(const QTextBlock &block);
|
QRect collapseBox(const QTextBlock &block);
|
||||||
|
|||||||
@@ -71,6 +71,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core,
|
|||||||
= m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction
|
= m_gotoBlockStartAction = m_gotoBlockStartWithSelectionAction
|
||||||
= m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction
|
= m_gotoBlockEndAction = m_gotoBlockEndWithSelectionAction
|
||||||
= m_selectBlockUpAction = m_selectBlockDownAction
|
= m_selectBlockUpAction = m_selectBlockDownAction
|
||||||
|
= m_moveLineUpAction = m_moveLineDownAction
|
||||||
= 0;
|
= 0;
|
||||||
|
|
||||||
m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context);
|
m_contextId << m_core->uniqueIDManager()->uniqueIdentifier(context);
|
||||||
@@ -223,6 +224,16 @@ void TextEditorActionHandler::createActions()
|
|||||||
command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId);
|
command = am->registerAction(m_selectBlockDownAction, Constants::SELECT_BLOCK_DOWN, m_contextId);
|
||||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+U")));
|
||||||
connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown()));
|
connect(m_selectBlockDownAction, SIGNAL(triggered()), this, SLOT(selectBlockDown()));
|
||||||
|
|
||||||
|
m_moveLineUpAction= new QAction(tr("Move Line Up"), this);
|
||||||
|
command = am->registerAction(m_moveLineUpAction, Constants::MOVE_LINE_UP, m_contextId);
|
||||||
|
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Up")));
|
||||||
|
connect(m_moveLineUpAction, SIGNAL(triggered()), this, SLOT(moveLineUp()));
|
||||||
|
|
||||||
|
m_moveLineDownAction= new QAction(tr("Move Line Down"), this);
|
||||||
|
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()));
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
|
bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
|
||||||
@@ -287,6 +298,8 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
|
|||||||
m_gotoBlockEndWithSelectionAction->setEnabled(um != NoEditor);
|
m_gotoBlockEndWithSelectionAction->setEnabled(um != NoEditor);
|
||||||
m_selectBlockUpAction->setEnabled(um != NoEditor);
|
m_selectBlockUpAction->setEnabled(um != NoEditor);
|
||||||
m_selectBlockDownAction->setEnabled(um != NoEditor);
|
m_selectBlockDownAction->setEnabled(um != NoEditor);
|
||||||
|
m_moveLineUpAction->setEnabled(um != NoEditor);
|
||||||
|
m_moveLineDownAction->setEnabled(um != NoEditor);
|
||||||
|
|
||||||
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
|
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
|
||||||
if (m_currentEditor)
|
if (m_currentEditor)
|
||||||
@@ -390,6 +403,8 @@ FUNCTION(gotoBlockStartWithSelection)
|
|||||||
FUNCTION(gotoBlockEndWithSelection)
|
FUNCTION(gotoBlockEndWithSelection)
|
||||||
FUNCTION(selectBlockUp)
|
FUNCTION(selectBlockUp)
|
||||||
FUNCTION(selectBlockDown)
|
FUNCTION(selectBlockDown)
|
||||||
|
FUNCTION(moveLineUp)
|
||||||
|
FUNCTION(moveLineDown)
|
||||||
|
|
||||||
void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object)
|
void TextEditorActionHandler::updateCurrentEditor(Core::IContext *object)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -116,6 +116,8 @@ private slots:
|
|||||||
void gotoBlockEndWithSelection();
|
void gotoBlockEndWithSelection();
|
||||||
void selectBlockUp();
|
void selectBlockUp();
|
||||||
void selectBlockDown();
|
void selectBlockDown();
|
||||||
|
void moveLineUp();
|
||||||
|
void moveLineDown();
|
||||||
void updateCurrentEditor(Core::IContext *object);
|
void updateCurrentEditor(Core::IContext *object);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -145,6 +147,8 @@ private:
|
|||||||
QAction *m_gotoBlockEndWithSelectionAction;
|
QAction *m_gotoBlockEndWithSelectionAction;
|
||||||
QAction *m_selectBlockUpAction;
|
QAction *m_selectBlockUpAction;
|
||||||
QAction *m_selectBlockDownAction;
|
QAction *m_selectBlockDownAction;
|
||||||
|
QAction *m_moveLineUpAction;
|
||||||
|
QAction *m_moveLineDownAction;
|
||||||
|
|
||||||
uint m_optionalActions;
|
uint m_optionalActions;
|
||||||
QPointer<BaseTextEditor> m_currentEditor;
|
QPointer<BaseTextEditor> m_currentEditor;
|
||||||
|
|||||||
@@ -55,6 +55,8 @@ const char * const GOTO_BLOCK_END = "TextEditor.GotoBlockEnd";
|
|||||||
const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection";
|
const char * const GOTO_BLOCK_END_WITH_SELECTION = "TextEditor.GotoBlockEndWithSelection";
|
||||||
const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp";
|
const char * const SELECT_BLOCK_UP = "TextEditor.SelectBlockUp";
|
||||||
const char * const SELECT_BLOCK_DOWN = "TextEditor.SelectBlockDown";
|
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 DELETE_LINE = "TextEditor.DeleteLine";
|
const char * const DELETE_LINE = "TextEditor.DeleteLine";
|
||||||
const char * const DELETE_WORD = "TextEditor.DeleteWord";
|
const char * const DELETE_WORD = "TextEditor.DeleteWord";
|
||||||
const char * const SELECT_ENCODING = "TextEditor.SelectEncoding";
|
const char * const SELECT_ENCODING = "TextEditor.SelectEncoding";
|
||||||
|
|||||||
Reference in New Issue
Block a user