Commit 32ab9878 authored by André Fillipe's avatar André Fillipe Committed by Thorbjørn Lindeijer

Added Insert Line Above/Below actions to BaseTextEditor

The actions perform exactly like their counterparts in Eclipse: a new,
indented line is inserted above or below the current line and the text
cursor is moved to the start of the new line. The line where the cursor
was before the action was triggered remains unchanged.

The shortcuts are also like in Eclipse: "Ctrl+Shift+Return" inserts a
line above the current, "Shift+Return" inserts a line below the current.

Merge-request: 140
Reviewed-by: default avatarThorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
parent b61e6564
......@@ -882,6 +882,29 @@ void BaseTextEditor::joinLines()
setTextCursor(cursor);
}
void BaseTextEditor::insertLineAbove()
{
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::PreviousBlock, QTextCursor::MoveAnchor);
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
cursor.endEditBlock();
setTextCursor(cursor);
}
void BaseTextEditor::insertLineBelow()
{
QTextCursor cursor = textCursor();
cursor.beginEditBlock();
cursor.movePosition(QTextCursor::EndOfBlock, QTextCursor::MoveAnchor);
cursor.insertBlock();
indent(document(), cursor, QChar::Null);
cursor.endEditBlock();
setTextCursor(cursor);
}
void BaseTextEditor::moveLineUp()
{
moveLineUpDown(true);
......
......@@ -242,6 +242,9 @@ public slots:
void joinLines();
void insertLineAbove();
void insertLineBelow();
void cleanWhitespace();
signals:
......
......@@ -292,6 +292,16 @@ void TextEditorActionHandler::createActions()
command = am->registerAction(m_joinLinesAction, Constants::JOIN_LINES, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J")));
connect(m_joinLinesAction, SIGNAL(triggered()), this, SLOT(joinLines()));
m_insertLineAboveAction = new QAction(tr("Insert Line Above Current Line"), this);
command = am->registerAction(m_insertLineAboveAction, Constants::INSERT_LINE_ABOVE, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+Return")));
connect(m_insertLineAboveAction, SIGNAL(triggered()), this, SLOT(insertLineAbove()));
m_insertLineBelowAction = new QAction(tr("Insert Line Below Current Line"), this);
command = am->registerAction(m_insertLineBelowAction, Constants::INSERT_LINE_BELOW, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Shift+Return")));
connect(m_insertLineBelowAction, SIGNAL(triggered()), this, SLOT(insertLineBelow()));
}
bool TextEditorActionHandler::supportsAction(const QString & /*id */) const
......@@ -454,6 +464,8 @@ FUNCTION(moveLineDown)
FUNCTION(copyLineUp)
FUNCTION(copyLineDown)
FUNCTION(joinLines)
FUNCTION(insertLineAbove)
FUNCTION(insertLineBelow)
void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
{
......
......@@ -116,6 +116,8 @@ private slots:
void copyLineUp();
void copyLineDown();
void joinLines();
void insertLineAbove();
void insertLineBelow();
void updateCurrentEditor(Core::IEditor *editor);
private:
......@@ -153,6 +155,8 @@ private:
QAction *m_copyLineUpAction;
QAction *m_copyLineDownAction;
QAction *m_joinLinesAction;
QAction *m_insertLineAboveAction;
QAction *m_insertLineBelowAction;
uint m_optionalActions;
QPointer<BaseTextEditor> m_currentEditor;
......
......@@ -61,6 +61,8 @@ 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 JOIN_LINES = "TextEditor.JoinLines";
const char * const INSERT_LINE_ABOVE = "TextEditor.InsertLineAboveCurrentLine";
const char * const INSERT_LINE_BELOW = "TextEditor.InsertLineBelowCurrentLine";
const char * const CUT_LINE = "TextEditor.CutLine";
const char * const DELETE_LINE = "TextEditor.DeleteLine";
const char * const DELETE_WORD = "TextEditor.DeleteWord";
......
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