QuickFix: Clean up RefactoringChanges and add missing functionality.

* Can change files without opening an editor.
* Can open an editor without changing a file.
* Default to reindenting new files.
* Allow reading a file temporarily to access document and text.
This commit is contained in:
Christian Kamm
2010-08-12 11:34:48 +02:00
parent a1760fc84a
commit 235f4d1d26
8 changed files with 408 additions and 147 deletions

View File

@@ -29,6 +29,12 @@
#include "cpprefactoringchanges.h"
#include <cpptools/cppcodeformatter.h>
#include <texteditor/texteditorsettings.h>
#include <texteditor/tabsettings.h>
#include <QtGui/QTextBlock>
using namespace CppEditor;
using namespace CPlusPlus;
@@ -95,3 +101,22 @@ Document::Ptr CppRefactoringChanges::document(const QString &fileName) const
return doc;
}
void CppRefactoringChanges::indentSelection(const QTextCursor &selection) const
{
// ### shares code with CPPEditor::indent()
QTextDocument *doc = selection.document();
QTextBlock block = doc->findBlock(selection.selectionStart());
const QTextBlock end = doc->findBlock(selection.selectionEnd()).next();
const TextEditor::TabSettings &tabSettings(TextEditor::TextEditorSettings::instance()->tabSettings());
CppTools::QtStyleCodeFormatter codeFormatter;
codeFormatter.updateStateUntil(block);
do {
tabSettings.indentLine(block, codeFormatter.indentFor(block));
codeFormatter.updateLineStateChange(block);
block = block.next();
} while (block.isValid() && block != end);
}