Introduce a Delete Line action that doesn't copy to clipboard

The version that does copy to clipboard is now called Cut Line, and is
still mapped to Shift+Delete by default.
This commit is contained in:
Thorbjørn Lindeijer
2009-05-14 17:24:35 +02:00
parent 4e7f2f8d7f
commit 9a79a06930
5 changed files with 29 additions and 6 deletions

View File

@@ -3622,8 +3622,7 @@ void BaseTextEditor::changeEvent(QEvent *e)
} }
} }
// shift+del void BaseTextEditor::maybeSelectLine()
void BaseTextEditor::deleteLine()
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
if (!cursor.hasSelection()) { if (!cursor.hasSelection()) {
@@ -3638,9 +3637,21 @@ void BaseTextEditor::deleteLine()
} }
setTextCursor(cursor); setTextCursor(cursor);
} }
}
// shift+del
void BaseTextEditor::cutLine()
{
maybeSelectLine();
cut(); cut();
} }
void BaseTextEditor::deleteLine()
{
maybeSelectLine();
textCursor().removeSelectedText();
}
void BaseTextEditor::setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections) void BaseTextEditor::setExtraSelections(ExtraSelectionKind kind, const QList<QTextEdit::ExtraSelection> &selections)
{ {
if (selections.isEmpty() && d->m_extraSelections[kind].isEmpty()) if (selections.isEmpty() && d->m_extraSelections[kind].isEmpty())

View File

@@ -370,6 +370,7 @@ public slots:
void zoomIn(int range = 1); void zoomIn(int range = 1);
void zoomOut(int range = 1); void zoomOut(int range = 1);
void cutLine();
void deleteLine(); void deleteLine();
void unCollapseAll(); void unCollapseAll();
void collapse(); void collapse();
@@ -406,6 +407,9 @@ protected:
bool canInsertFromMimeData(const QMimeData *source) const; bool canInsertFromMimeData(const QMimeData *source) const;
void insertFromMimeData(const QMimeData *source); void insertFromMimeData(const QMimeData *source);
private:
void maybeSelectLine();
public: public:
void duplicateFrom(BaseTextEditor *editor); void duplicateFrom(BaseTextEditor *editor);

View File

@@ -72,6 +72,7 @@ TextEditorActionHandler::TextEditorActionHandler(const QString &context,
m_unCollapseAllAction = 0; m_unCollapseAllAction = 0;
m_collapseAction = 0; m_collapseAction = 0;
m_expandAction = 0; m_expandAction = 0;
m_cutLineAction = 0;
m_deleteLineAction = 0; m_deleteLineAction = 0;
m_selectEncodingAction = 0; m_selectEncodingAction = 0;
m_increaseFontSizeAction = 0; m_increaseFontSizeAction = 0;
@@ -173,9 +174,13 @@ void TextEditorActionHandler::createActions()
connect(m_unCommentSelectionAction, SIGNAL(triggered()), this, SLOT(unCommentSelection())); connect(m_unCommentSelectionAction, SIGNAL(triggered()), this, SLOT(unCommentSelection()));
advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT); advancedMenu->addAction(command, Core::Constants::G_EDIT_FORMAT);
m_cutLineAction = new QAction(tr("Cut &Line"), this);
command = am->registerAction(m_cutLineAction, Constants::CUT_LINE, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Shift+Del")));
connect(m_cutLineAction, SIGNAL(triggered()), this, SLOT(cutLine()));
m_deleteLineAction = new QAction(tr("Delete &Line"), this); m_deleteLineAction = new QAction(tr("Delete &Line"), this);
command = am->registerAction(m_deleteLineAction, Constants::DELETE_LINE, m_contextId); command = am->registerAction(m_deleteLineAction, Constants::DELETE_LINE, m_contextId);
command->setDefaultKeySequence(QKeySequence(tr("Shift+Del")));
connect(m_deleteLineAction, SIGNAL(triggered()), this, SLOT(deleteLine())); connect(m_deleteLineAction, SIGNAL(triggered()), this, SLOT(deleteLine()));
m_collapseAction = new QAction(tr("Collapse"), this); m_collapseAction = new QAction(tr("Collapse"), this);
@@ -385,6 +390,7 @@ FUNCTION2(formatAction, format)
FUNCTION2(selectAllAction, selectAll) FUNCTION2(selectAllAction, selectAll)
FUNCTION(cleanWhitespace) FUNCTION(cleanWhitespace)
FUNCTION(unCommentSelection) FUNCTION(unCommentSelection)
FUNCTION(cutLine)
FUNCTION(deleteLine) FUNCTION(deleteLine)
FUNCTION(unCollapseAll) FUNCTION(unCollapseAll)
FUNCTION(collapse) FUNCTION(collapse)
@@ -416,7 +422,6 @@ void TextEditorActionHandler::updateCurrentEditor(Core::IEditor *editor)
} }
} }
const QPointer<BaseTextEditor> &TextEditorActionHandler::currentEditor() const const QPointer<BaseTextEditor> &TextEditorActionHandler::currentEditor() const
{ {
return m_currentEditor; return m_currentEditor;

View File

@@ -98,6 +98,7 @@ private slots:
void unCollapseAll(); void unCollapseAll();
void collapse(); void collapse();
void expand(); void expand();
void cutLine();
void deleteLine(); void deleteLine();
void selectEncoding(); void selectEncoding();
void increaseFontSize(); void increaseFontSize();
@@ -129,6 +130,7 @@ private:
QAction *m_unCollapseAllAction; QAction *m_unCollapseAllAction;
QAction *m_collapseAction; QAction *m_collapseAction;
QAction *m_expandAction; QAction *m_expandAction;
QAction *m_cutLineAction;
QAction *m_deleteLineAction; QAction *m_deleteLineAction;
QAction *m_selectEncodingAction; QAction *m_selectEncodingAction;
QAction *m_increaseFontSizeAction; QAction *m_increaseFontSizeAction;

View File

@@ -53,6 +53,7 @@ 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_UP = "TextEditor.MoveLineUp";
const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown"; const char * const MOVE_LINE_DOWN = "TextEditor.MoveLineDown";
const char * const CUT_LINE = "TextEditor.CutLine";
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";