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: Thorbjørn Lindeijer <thorbjorn.lindeijer@nokia.com>
This commit is contained in:
André Fillipe
2010-05-03 17:03:11 +02:00
committed by Thorbjørn Lindeijer
parent b61e656493
commit 32ab9878fe
5 changed files with 44 additions and 0 deletions

View File

@@ -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);

View File

@@ -242,6 +242,9 @@ public slots:
void joinLines();
void insertLineAbove();
void insertLineBelow();
void cleanWhitespace();
signals:

View File

@@ -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)
{

View File

@@ -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;

View File

@@ -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";