summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormae <qtc-committer@nokia.com>2008-12-09 17:43:31 +0100
committermae <qtc-committer@nokia.com>2008-12-09 17:43:31 +0100
commit1931304da1b59fcc396b3a550d0c9817ba73f8af (patch)
tree6afbac0fa6e13a56b2def7fdf1c0ee6965752574 /src
parent98f35da62952bd7b4a4514b821395daa9b9f2bd2 (diff)
downloadqt-creator-1931304da1b59fcc396b3a550d0c9817ba73f8af.tar.gz
add explicit "Clean Whitespace" advanced action
Diffstat (limited to 'src')
-rw-r--r--src/plugins/texteditor/basetextdocument.cpp12
-rw-r--r--src/plugins/texteditor/basetextdocument.h2
-rw-r--r--src/plugins/texteditor/basetexteditor.cpp4
-rw-r--r--src/plugins/texteditor/basetexteditor.h2
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.cpp65
-rw-r--r--src/plugins/texteditor/texteditoractionhandler.h2
-rw-r--r--src/plugins/texteditor/texteditorconstants.h1
7 files changed, 42 insertions, 46 deletions
diff --git a/src/plugins/texteditor/basetextdocument.cpp b/src/plugins/texteditor/basetextdocument.cpp
index 0d5bd8c2de..3758b13327 100644
--- a/src/plugins/texteditor/basetextdocument.cpp
+++ b/src/plugins/texteditor/basetextdocument.cpp
@@ -302,6 +302,18 @@ void BaseTextDocument::setSyntaxHighlighter(QSyntaxHighlighter *highlighter)
m_highlighter->setDocument(m_document);
}
+
+
+void BaseTextDocument::cleanWhitespace()
+{
+ QTextCursor cursor(m_document);
+ cursor.beginEditBlock();
+ cleanWhitespace(cursor, true);
+ if (m_storageSettings.m_addFinalNewLine)
+ ensureFinalNewLine(cursor);
+ cursor.endEditBlock();
+}
+
void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool inEntireDocument)
{
diff --git a/src/plugins/texteditor/basetextdocument.h b/src/plugins/texteditor/basetextdocument.h
index ee8e5eb427..b945129c47 100644
--- a/src/plugins/texteditor/basetextdocument.h
+++ b/src/plugins/texteditor/basetextdocument.h
@@ -118,6 +118,8 @@ public:
void reload(QTextCodec *codec);
+ void cleanWhitespace();
+
signals:
void titleChanged(QString title);
void changed();
diff --git a/src/plugins/texteditor/basetexteditor.cpp b/src/plugins/texteditor/basetexteditor.cpp
index cb222dd9fd..db5413c344 100644
--- a/src/plugins/texteditor/basetexteditor.cpp
+++ b/src/plugins/texteditor/basetexteditor.cpp
@@ -685,6 +685,10 @@ void BaseTextEditor::selectBlockDown()
}
+void BaseTextEditor::cleanWhitespace()
+{
+ d->m_document->cleanWhitespace();
+}
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
{
diff --git a/src/plugins/texteditor/basetexteditor.h b/src/plugins/texteditor/basetexteditor.h
index 40454a9c7d..1219439fc9 100644
--- a/src/plugins/texteditor/basetexteditor.h
+++ b/src/plugins/texteditor/basetexteditor.h
@@ -329,6 +329,8 @@ public slots:
void selectBlockUp();
void selectBlockDown();
+ void cleanWhitespace();
+
signals:
void changed();
diff --git a/src/plugins/texteditor/texteditoractionhandler.cpp b/src/plugins/texteditor/texteditoractionhandler.cpp
index 5ffd79e6d0..12fc7d1fac 100644
--- a/src/plugins/texteditor/texteditoractionhandler.cpp
+++ b/src/plugins/texteditor/texteditoractionhandler.cpp
@@ -63,7 +63,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core,
{
m_undoAction = m_redoAction = m_copyAction = m_cutAction = m_pasteAction
= m_selectAllAction = m_gotoAction = m_printAction = m_formatAction
- = m_visualizeWhitespaceAction = m_textWrappingAction
+ = m_visualizeWhitespaceAction = m_cleanWhitespaceAction = m_textWrappingAction
= m_unCommentSelectionAction = m_unCollapseAllAction
= m_collapseAction = m_expandAction
= m_deleteLineAction = m_selectEncodingAction
@@ -128,17 +128,23 @@ void TextEditorActionHandler::createActions()
connect(m_formatAction, SIGNAL(triggered(bool)), this, SLOT(formatAction()));
- m_visualizeWhitespaceAction = new QAction(tr("Visualize &Whitespace"), this);
+ m_visualizeWhitespaceAction = new QAction(tr("&Visualize Whitespace"), this);
m_visualizeWhitespaceAction->setCheckable(true);
command = am->registerAction(m_visualizeWhitespaceAction,
TextEditor::Constants::VISUALIZE_WHITESPACE, m_contextId);
#ifndef Q_OS_MAC
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+E, Ctrl+V")));
#endif
-
advancedMenu->addAction(command);
connect(m_visualizeWhitespaceAction, SIGNAL(triggered(bool)), this, SLOT(setVisualizeWhitespace(bool)));
+ m_cleanWhitespaceAction = new QAction(tr("Clean Whitespace"), this);
+ command = am->registerAction(m_cleanWhitespaceAction,
+ TextEditor::Constants::CLEAN_WHITESPACE, m_contextId);
+
+ advancedMenu->addAction(command);
+ connect(m_cleanWhitespaceAction, SIGNAL(triggered()), this, SLOT(cleanWhitespace()));
+
m_textWrappingAction = new QAction(tr("Enable Text &Wrapping"), this);
m_textWrappingAction->setCheckable(true);
command = am->registerAction(m_textWrappingAction,
@@ -285,6 +291,7 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
if (m_currentEditor)
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
+ m_cleanWhitespaceAction->setEnabled(um != NoEditor);
if (m_textWrappingAction) {
m_textWrappingAction->setEnabled(um != NoEditor);
if (m_currentEditor)
@@ -317,42 +324,6 @@ void TextEditorActionHandler::updateCopyAction()
m_copyAction->setEnabled(hasCopyableText);
}
-void TextEditorActionHandler::undoAction()
-{
- if (m_currentEditor)
- m_currentEditor->undo();
-}
-
-void TextEditorActionHandler::redoAction()
-{
- if (m_currentEditor)
- m_currentEditor->redo();
-}
-
-void TextEditorActionHandler::copyAction()
-{
- if (m_currentEditor)
- m_currentEditor->copy();
-}
-
-void TextEditorActionHandler::cutAction()
-{
- if (m_currentEditor)
- m_currentEditor->cut();
-}
-
-void TextEditorActionHandler::pasteAction()
-{
- if (m_currentEditor)
- m_currentEditor->paste();
-}
-
-void TextEditorActionHandler::selectAllAction()
-{
- if (m_currentEditor)
- m_currentEditor->selectAll();
-}
-
void TextEditorActionHandler::gotoAction()
{
QuickOpen::QuickOpenManager *quickopen = QuickOpen::QuickOpenManager::instance();
@@ -367,13 +338,6 @@ void TextEditorActionHandler::printAction()
m_currentEditor->print(m_core->printer());
}
-void TextEditorActionHandler::formatAction()
-{
- if (m_currentEditor)
- m_currentEditor->format();
-}
-
-
void TextEditorActionHandler::setVisualizeWhitespace(bool checked)
{
if (m_currentEditor) {
@@ -403,6 +367,15 @@ void TextEditorActionHandler::setTextWrapping(bool checked)
m_currentEditor->funcname2 ();\
}
+
+FUNCTION2(undoAction, undo)
+FUNCTION2(redoAction, redo)
+FUNCTION2(copyAction, copy)
+FUNCTION2(cutAction, cut)
+FUNCTION2(pasteAction, paste)
+FUNCTION2(formatAction, format)
+FUNCTION2(selectAllAction, selectAll)
+FUNCTION(cleanWhitespace)
FUNCTION(unCommentSelection)
FUNCTION(deleteLine)
FUNCTION(unCollapseAll)
diff --git a/src/plugins/texteditor/texteditoractionhandler.h b/src/plugins/texteditor/texteditoractionhandler.h
index 9a8c7b9f57..520ae26ddf 100644
--- a/src/plugins/texteditor/texteditoractionhandler.h
+++ b/src/plugins/texteditor/texteditoractionhandler.h
@@ -100,6 +100,7 @@ private slots:
void printAction();
void formatAction();
void setVisualizeWhitespace(bool);
+ void cleanWhitespace();
void setTextWrapping(bool);
void unCommentSelection();
void unCollapseAll();
@@ -128,6 +129,7 @@ private:
QAction *m_printAction;
QAction *m_formatAction;
QAction *m_visualizeWhitespaceAction;
+ QAction *m_cleanWhitespaceAction;
QAction *m_textWrappingAction;
QAction *m_unCommentSelectionAction;
QAction *m_unCollapseAllAction;
diff --git a/src/plugins/texteditor/texteditorconstants.h b/src/plugins/texteditor/texteditorconstants.h
index 9ac9fdff0e..192a07c257 100644
--- a/src/plugins/texteditor/texteditorconstants.h
+++ b/src/plugins/texteditor/texteditorconstants.h
@@ -40,6 +40,7 @@ namespace Constants {
const char * const C_TEXTEDITOR = "Text Editor";
const char * const COMPLETE_THIS = "TextEditor.CompleteThis";
const char * const VISUALIZE_WHITESPACE = "TextEditor.VisualizeWhitespace";
+const char * const CLEAN_WHITESPACE = "TextEditor.CleanWhitespace";
const char * const TEXT_WRAPPING = "TextEditor.TextWrapping";
const char * const UN_COMMENT_SELECTION = "TextEditor.UnCommentSelection";
const char * const COLLAPSE = "TextEditor.Collapse";