From ec2b738d611d8a7e422a63c8905c2a737d1c07f6 Mon Sep 17 00:00:00 2001 From: Falco Hirschenberger Date: Wed, 20 Jan 2010 16:54:06 +0100 Subject: [PATCH] Add join-line up/down feature to text editor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Merge-request: 1823 Reviewed-by: Thorbjørn Lindeijer Task-number: QTCREATORBUG-510 --- src/plugins/texteditor/basetexteditor.cpp | 34 +++++++++++++++++++ src/plugins/texteditor/basetexteditor.h | 4 +++ .../texteditor/texteditoractionhandler.cpp | 14 ++++++++ .../texteditor/texteditoractionhandler.h | 4 +++ src/plugins/texteditor/texteditorconstants.h | 2 ++ 5 files changed, 58 insertions(+) diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp index 718e757803d..b17a3c2a3db 100644 --- a/src/plugins/texteditor/basetexteditor.cpp +++ b/src/plugins/texteditor/basetexteditor.cpp @@ -877,6 +877,40 @@ void BaseTextEditor::copyLineUpDown(bool up) setTextCursor(move); } +void BaseTextEditor::joinLineUp() +{ + joinLineUpDown(true); +} + +void BaseTextEditor::joinLineDown() +{ + joinLineUpDown(false); +} + +void BaseTextEditor::joinLineUpDown(bool up) +{ + QTextCursor move = textCursor(); + move.beginEditBlock(); + + if(up) + move.movePosition(QTextCursor::Up); + else + move.movePosition(QTextCursor::Down); + move.movePosition(QTextCursor::StartOfBlock); + move.movePosition(QTextCursor::EndOfBlock, QTextCursor::KeepAnchor); + QString cutLine = move.selectedText(); + move.movePosition(QTextCursor::Right, QTextCursor::KeepAnchor); + move.removeSelectedText(); + move.clearSelection(); + + if(!up) + move.movePosition(QTextCursor::Up); + move.movePosition(QTextCursor::EndOfBlock); + move.insertText(cutLine); + move.endEditBlock(); + setTextCursor(move); +} + void BaseTextEditor::moveLineUp() { moveLineUpDown(true); diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h index 21c5bc803ae..fb295209149 100644 --- a/src/plugins/texteditor/basetexteditor.h +++ b/src/plugins/texteditor/basetexteditor.h @@ -412,6 +412,9 @@ public slots: void copyLineUp(); void copyLineDown(); + void joinLineUp(); + void joinLineDown(); + void cleanWhitespace(); signals: @@ -620,6 +623,7 @@ private: void handleBackspaceKey(); void moveLineUpDown(bool up); void copyLineUpDown(bool up); + void joinLineUpDown(bool up); void saveCurrentCursorPositionForNavigation(); void updateCurrentLineHighlight(); diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp index 90a6eb314c5..374df106867 100644 --- a/src/plugins/texteditor/texteditoractionhandler.cpp +++ b/src/plugins/texteditor/texteditoractionhandler.cpp @@ -86,6 +86,8 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context, m_moveLineDownAction(0), m_copyLineUpAction(0), m_copyLineDownAction(0), + m_joinLineUpAction(0), + m_joinLineDownAction(0), m_optionalActions(optionalActions), m_currentEditor(0), m_initialized(false) @@ -282,6 +284,16 @@ void TextEditorActionHandler::createActions() 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())); + + m_joinLineUpAction= new QAction(tr("Join Line Up"), this); + command = am->registerAction(m_joinLineUpAction, Constants::JOIN_LINE_UP, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+J"))); + connect(m_joinLineUpAction, SIGNAL(triggered()), this, SLOT(joinLineUp())); + + m_joinLineDownAction= new QAction(tr("Join Line Down"), this); + command = am->registerAction(m_joinLineDownAction, Constants::JOIN_LINE_DOWN, m_contextId); + command->setDefaultKeySequence(QKeySequence(tr("Ctrl+J"))); + connect(m_joinLineDownAction, SIGNAL(triggered()), this, SLOT(joinLineDown())); } bool TextEditorActionHandler::supportsAction(const QString & /*id */) const @@ -443,6 +455,8 @@ FUNCTION(moveLineUp) FUNCTION(moveLineDown) FUNCTION(copyLineUp) FUNCTION(copyLineDown) +FUNCTION(joinLineUp) +FUNCTION(joinLineDown) void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor) { diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h index 661932e98d2..daa30275438 100644 --- a/src/plugins/texteditor/texteditoractionhandler.h +++ b/src/plugins/texteditor/texteditoractionhandler.h @@ -115,6 +115,8 @@ private slots: void moveLineDown(); void copyLineUp(); void copyLineDown(); + void joinLineUp(); + void joinLineDown(); void updateCurrentEditor(Core::IEditor *editor); private: @@ -151,6 +153,8 @@ private: QAction *m_moveLineDownAction; QAction *m_copyLineUpAction; QAction *m_copyLineDownAction; + QAction *m_joinLineUpAction; + QAction *m_joinLineDownAction; uint m_optionalActions; QPointer m_currentEditor; diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h index d21b4f8c2e1..0c75f95ec97 100644 --- a/src/plugins/texteditor/texteditorconstants.h +++ b/src/plugins/texteditor/texteditorconstants.h @@ -60,6 +60,8 @@ 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 JOIN_LINE_UP = "TextEditor.JoinLineUp"; +const char * const JOIN_LINE_DOWN = "TextEditor.JoinLineDown"; const char * const CUT_LINE = "TextEditor.CutLine"; const char * const DELETE_LINE = "TextEditor.DeleteLine"; const char * const DELETE_WORD = "TextEditor.DeleteWord";