forked from qt-creator/qt-creator
add explicit "Clean Whitespace" advanced action
This commit is contained in:
@@ -302,6 +302,18 @@ void BaseTextDocument::setSyntaxHighlighter(QSyntaxHighlighter *highlighter)
|
|||||||
m_highlighter->setDocument(m_document);
|
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)
|
void BaseTextDocument::cleanWhitespace(QTextCursor& cursor, bool inEntireDocument)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -118,6 +118,8 @@ public:
|
|||||||
|
|
||||||
void reload(QTextCodec *codec);
|
void reload(QTextCodec *codec);
|
||||||
|
|
||||||
|
void cleanWhitespace();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void titleChanged(QString title);
|
void titleChanged(QString title);
|
||||||
void changed();
|
void changed();
|
||||||
|
|||||||
@@ -685,6 +685,10 @@ void BaseTextEditor::selectBlockDown()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void BaseTextEditor::cleanWhitespace()
|
||||||
|
{
|
||||||
|
d->m_document->cleanWhitespace();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -329,6 +329,8 @@ public slots:
|
|||||||
void selectBlockUp();
|
void selectBlockUp();
|
||||||
void selectBlockDown();
|
void selectBlockDown();
|
||||||
|
|
||||||
|
void cleanWhitespace();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void changed();
|
void changed();
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ TextEditorActionHandler::TextEditorActionHandler(Core::ICore *core,
|
|||||||
{
|
{
|
||||||
m_undoAction = m_redoAction = m_copyAction = m_cutAction = m_pasteAction
|
m_undoAction = m_redoAction = m_copyAction = m_cutAction = m_pasteAction
|
||||||
= m_selectAllAction = m_gotoAction = m_printAction = m_formatAction
|
= m_selectAllAction = m_gotoAction = m_printAction = m_formatAction
|
||||||
= m_visualizeWhitespaceAction = m_textWrappingAction
|
= m_visualizeWhitespaceAction = m_cleanWhitespaceAction = m_textWrappingAction
|
||||||
= m_unCommentSelectionAction = m_unCollapseAllAction
|
= m_unCommentSelectionAction = m_unCollapseAllAction
|
||||||
= m_collapseAction = m_expandAction
|
= m_collapseAction = m_expandAction
|
||||||
= m_deleteLineAction = m_selectEncodingAction
|
= m_deleteLineAction = m_selectEncodingAction
|
||||||
@@ -128,17 +128,23 @@ void TextEditorActionHandler::createActions()
|
|||||||
connect(m_formatAction, SIGNAL(triggered(bool)), this, SLOT(formatAction()));
|
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);
|
m_visualizeWhitespaceAction->setCheckable(true);
|
||||||
command = am->registerAction(m_visualizeWhitespaceAction,
|
command = am->registerAction(m_visualizeWhitespaceAction,
|
||||||
TextEditor::Constants::VISUALIZE_WHITESPACE, m_contextId);
|
TextEditor::Constants::VISUALIZE_WHITESPACE, m_contextId);
|
||||||
#ifndef Q_OS_MAC
|
#ifndef Q_OS_MAC
|
||||||
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+E, Ctrl+V")));
|
command->setDefaultKeySequence(QKeySequence(tr("Ctrl+E, Ctrl+V")));
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
advancedMenu->addAction(command);
|
advancedMenu->addAction(command);
|
||||||
connect(m_visualizeWhitespaceAction, SIGNAL(triggered(bool)), this, SLOT(setVisualizeWhitespace(bool)));
|
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 = new QAction(tr("Enable Text &Wrapping"), this);
|
||||||
m_textWrappingAction->setCheckable(true);
|
m_textWrappingAction->setCheckable(true);
|
||||||
command = am->registerAction(m_textWrappingAction,
|
command = am->registerAction(m_textWrappingAction,
|
||||||
@@ -285,6 +291,7 @@ void TextEditorActionHandler::updateActions(UpdateMode um)
|
|||||||
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
|
m_visualizeWhitespaceAction->setEnabled(um != NoEditor);
|
||||||
if (m_currentEditor)
|
if (m_currentEditor)
|
||||||
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
|
m_visualizeWhitespaceAction->setChecked(m_currentEditor->displaySettings().m_visualizeWhitespace);
|
||||||
|
m_cleanWhitespaceAction->setEnabled(um != NoEditor);
|
||||||
if (m_textWrappingAction) {
|
if (m_textWrappingAction) {
|
||||||
m_textWrappingAction->setEnabled(um != NoEditor);
|
m_textWrappingAction->setEnabled(um != NoEditor);
|
||||||
if (m_currentEditor)
|
if (m_currentEditor)
|
||||||
@@ -317,42 +324,6 @@ void TextEditorActionHandler::updateCopyAction()
|
|||||||
m_copyAction->setEnabled(hasCopyableText);
|
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()
|
void TextEditorActionHandler::gotoAction()
|
||||||
{
|
{
|
||||||
QuickOpen::QuickOpenManager *quickopen = QuickOpen::QuickOpenManager::instance();
|
QuickOpen::QuickOpenManager *quickopen = QuickOpen::QuickOpenManager::instance();
|
||||||
@@ -367,13 +338,6 @@ void TextEditorActionHandler::printAction()
|
|||||||
m_currentEditor->print(m_core->printer());
|
m_currentEditor->print(m_core->printer());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TextEditorActionHandler::formatAction()
|
|
||||||
{
|
|
||||||
if (m_currentEditor)
|
|
||||||
m_currentEditor->format();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void TextEditorActionHandler::setVisualizeWhitespace(bool checked)
|
void TextEditorActionHandler::setVisualizeWhitespace(bool checked)
|
||||||
{
|
{
|
||||||
if (m_currentEditor) {
|
if (m_currentEditor) {
|
||||||
@@ -403,6 +367,15 @@ void TextEditorActionHandler::setTextWrapping(bool checked)
|
|||||||
m_currentEditor->funcname2 ();\
|
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(unCommentSelection)
|
||||||
FUNCTION(deleteLine)
|
FUNCTION(deleteLine)
|
||||||
FUNCTION(unCollapseAll)
|
FUNCTION(unCollapseAll)
|
||||||
|
|||||||
@@ -100,6 +100,7 @@ private slots:
|
|||||||
void printAction();
|
void printAction();
|
||||||
void formatAction();
|
void formatAction();
|
||||||
void setVisualizeWhitespace(bool);
|
void setVisualizeWhitespace(bool);
|
||||||
|
void cleanWhitespace();
|
||||||
void setTextWrapping(bool);
|
void setTextWrapping(bool);
|
||||||
void unCommentSelection();
|
void unCommentSelection();
|
||||||
void unCollapseAll();
|
void unCollapseAll();
|
||||||
@@ -128,6 +129,7 @@ private:
|
|||||||
QAction *m_printAction;
|
QAction *m_printAction;
|
||||||
QAction *m_formatAction;
|
QAction *m_formatAction;
|
||||||
QAction *m_visualizeWhitespaceAction;
|
QAction *m_visualizeWhitespaceAction;
|
||||||
|
QAction *m_cleanWhitespaceAction;
|
||||||
QAction *m_textWrappingAction;
|
QAction *m_textWrappingAction;
|
||||||
QAction *m_unCommentSelectionAction;
|
QAction *m_unCommentSelectionAction;
|
||||||
QAction *m_unCollapseAllAction;
|
QAction *m_unCollapseAllAction;
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ namespace Constants {
|
|||||||
const char * const C_TEXTEDITOR = "Text Editor";
|
const char * const C_TEXTEDITOR = "Text Editor";
|
||||||
const char * const COMPLETE_THIS = "TextEditor.CompleteThis";
|
const char * const COMPLETE_THIS = "TextEditor.CompleteThis";
|
||||||
const char * const VISUALIZE_WHITESPACE = "TextEditor.VisualizeWhitespace";
|
const char * const VISUALIZE_WHITESPACE = "TextEditor.VisualizeWhitespace";
|
||||||
|
const char * const CLEAN_WHITESPACE = "TextEditor.CleanWhitespace";
|
||||||
const char * const TEXT_WRAPPING = "TextEditor.TextWrapping";
|
const char * const TEXT_WRAPPING = "TextEditor.TextWrapping";
|
||||||
const char * const UN_COMMENT_SELECTION = "TextEditor.UnCommentSelection";
|
const char * const UN_COMMENT_SELECTION = "TextEditor.UnCommentSelection";
|
||||||
const char * const COLLAPSE = "TextEditor.Collapse";
|
const char * const COLLAPSE = "TextEditor.Collapse";
|
||||||
|
|||||||
Reference in New Issue
Block a user