Commit fe9eeece authored by Adam Treat's avatar Adam Treat Committed by Leandro Melo
Browse files

Adds two actions to indent and unindent a selection.



Add actions to the basetexteditor to indent and unindent a selection.  These actions
are equivalent to Key_Tab and Key_BackTab respectively.  The advantage of having
actions here is the user can override them and assign any key binding they want.
Thus, I could assign Ctrl+I and Shift+Ctrl+I to them and have the same behavior
as Kate.

Change-Id: I0a305a7b45018072a78f2880ea15650ea92095a1
Reviewed-by: default avatarLeandro Melo <leandro.melo@nokia.com>
parent ff083c1e
...@@ -1063,6 +1063,16 @@ void BaseTextEditorWidget::lowercaseSelection() ...@@ -1063,6 +1063,16 @@ void BaseTextEditorWidget::lowercaseSelection()
transformSelection(&QString::toLower); transformSelection(&QString::toLower);
} }
void BaseTextEditorWidget::indent()
{
indentOrUnindent(true);
}
void BaseTextEditorWidget::unindent()
{
indentOrUnindent(false);
}
void BaseTextEditorWidget::moveLineUpDown(bool up) void BaseTextEditorWidget::moveLineUpDown(bool up)
{ {
QTextCursor cursor = textCursor(); QTextCursor cursor = textCursor();
......
...@@ -322,6 +322,9 @@ public slots: ...@@ -322,6 +322,9 @@ public slots:
void cleanWhitespace(); void cleanWhitespace();
void indent();
void unindent();
signals: signals:
void changed(); void changed();
......
...@@ -102,6 +102,8 @@ TextEditorActionHandler::TextEditorActionHandler(const char *context, ...@@ -102,6 +102,8 @@ TextEditorActionHandler::TextEditorActionHandler(const char *context,
m_insertLineBelowAction(0), m_insertLineBelowAction(0),
m_upperCaseSelectionAction(0), m_upperCaseSelectionAction(0),
m_lowerCaseSelectionAction(0), m_lowerCaseSelectionAction(0),
m_indentAction(0),
m_unindentAction(0),
m_optionalActions(optionalActions), m_optionalActions(optionalActions),
m_currentEditor(0), m_currentEditor(0),
m_contextId(context), m_contextId(context),
...@@ -377,6 +379,16 @@ void TextEditorActionHandler::createActions() ...@@ -377,6 +379,16 @@ void TextEditorActionHandler::createActions()
connect(m_circularPasteAction, SIGNAL(triggered()), this, SLOT(circularPasteAction())); connect(m_circularPasteAction, SIGNAL(triggered()), this, SLOT(circularPasteAction()));
medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE); medit->addAction(command, Core::Constants::G_EDIT_COPYPASTE);
m_indentAction = new QAction(tr("Indent"), this);
m_modifyingActions << m_indentAction;
command = am->registerAction(m_indentAction, Constants::INDENT, m_contextId, true);
connect(m_indentAction, SIGNAL(triggered()), this, SLOT(indent()));
m_unindentAction = new QAction(tr("Unindent"), this);
m_modifyingActions << m_unindentAction;
command = am->registerAction(m_unindentAction, Constants::UNINDENT, m_contextId, true);
connect(m_unindentAction, SIGNAL(triggered()), this, SLOT(unindent()));
QAction *a = 0; QAction *a = 0;
a = new QAction(tr("Go to Line Start"), this); a = new QAction(tr("Go to Line Start"), this);
command = am->registerAction(a, Constants::GOTO_LINE_START, m_contextId, true); command = am->registerAction(a, Constants::GOTO_LINE_START, m_contextId, true);
...@@ -611,6 +623,8 @@ FUNCTION(uppercaseSelection) ...@@ -611,6 +623,8 @@ FUNCTION(uppercaseSelection)
FUNCTION(lowercaseSelection) FUNCTION(lowercaseSelection)
FUNCTION(insertLineAbove) FUNCTION(insertLineAbove)
FUNCTION(insertLineBelow) FUNCTION(insertLineBelow)
FUNCTION(indent)
FUNCTION(unindent)
FUNCTION(gotoLineStart) FUNCTION(gotoLineStart)
FUNCTION(gotoLineStartWithSelection) FUNCTION(gotoLineStartWithSelection)
......
...@@ -138,6 +138,8 @@ private slots: ...@@ -138,6 +138,8 @@ private slots:
void uppercaseSelection(); void uppercaseSelection();
void lowercaseSelection(); void lowercaseSelection();
void updateCurrentEditor(Core::IEditor *editor); void updateCurrentEditor(Core::IEditor *editor);
void indent();
void unindent();
void gotoLineStart(); void gotoLineStart();
void gotoLineStartWithSelection(); void gotoLineStartWithSelection();
...@@ -206,6 +208,8 @@ private: ...@@ -206,6 +208,8 @@ private:
QAction *m_insertLineBelowAction; QAction *m_insertLineBelowAction;
QAction *m_upperCaseSelectionAction; QAction *m_upperCaseSelectionAction;
QAction *m_lowerCaseSelectionAction; QAction *m_lowerCaseSelectionAction;
QAction *m_indentAction;
QAction *m_unindentAction;
QList<QAction *> m_modifyingActions; QList<QAction *> m_modifyingActions;
uint m_optionalActions; uint m_optionalActions;
......
...@@ -102,6 +102,8 @@ const char TASK_DOWNLOAD_DEFINITIONS[] = "TextEditor.Task.Download"; ...@@ -102,6 +102,8 @@ const char TASK_DOWNLOAD_DEFINITIONS[] = "TextEditor.Task.Download";
const char TASK_REGISTER_DEFINITIONS[] = "TextEditor.Task.Register"; const char TASK_REGISTER_DEFINITIONS[] = "TextEditor.Task.Register";
const char TASK_OPEN_FILE[] = "TextEditor.Task.OpenFile"; const char TASK_OPEN_FILE[] = "TextEditor.Task.OpenFile";
const char CIRCULAR_PASTE[] = "TextEditor.CircularPaste"; const char CIRCULAR_PASTE[] = "TextEditor.CircularPaste";
const char INDENT[] = "TextEditor.Indent";
const char UNINDENT[] = "TextEditor.Unindent";
// Text color and style categories // Text color and style categories
const char C_TEXT[] = "Text"; const char C_TEXT[] = "Text";
......
Supports Markdown
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