Commit 1931304d authored by mae's avatar mae
Browse files

add explicit "Clean Whitespace" advanced action

parent 98f35da6
......@@ -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)
{
......
......@@ -118,6 +118,8 @@ public:
void reload(QTextCodec *codec);
void cleanWhitespace();
signals:
void titleChanged(QString title);
void changed();
......
......@@ -685,6 +685,10 @@ void BaseTextEditor::selectBlockDown()
}
void BaseTextEditor::cleanWhitespace()
{
d->m_document->cleanWhitespace();
}
void BaseTextEditor::keyPressEvent(QKeyEvent *e)
{
......
......@@ -329,6 +329,8 @@ public slots:
void selectBlockUp();
void selectBlockDown();
void cleanWhitespace();
signals:
void changed();
......
......@@ -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)
......
......@@ -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;
......
......@@ -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";
......
Markdown is supported
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