forked from qt-creator/qt-creator
TextEditor: Add a convenience overload for RefactoringFile::apply()
... and make use of it. In most contexts, apply() immediately follows setChangeSet(), so combining the two can save a lot of code on the call site. Change-Id: I421001bd47000cb64678a57b19760becf59a4863 Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -71,10 +71,7 @@ QString ClangFixItOperation::firstRefactoringFileContent_forTestOnly() const
|
||||
void ClangFixItOperation::applyFixitsToFile(TextEditor::RefactoringFile &refactoringFile,
|
||||
const QList<ClangFixIt> fixIts)
|
||||
{
|
||||
const Utils::ChangeSet changeSet = toChangeSet(refactoringFile, fixIts);
|
||||
|
||||
refactoringFile.setChangeSet(changeSet);
|
||||
refactoringFile.apply();
|
||||
refactoringFile.apply(toChangeSet(refactoringFile, fixIts));
|
||||
}
|
||||
|
||||
Utils::ChangeSet ClangFixItOperation::toChangeSet(
|
||||
|
||||
@@ -328,8 +328,7 @@ void DiagnosticView::suppressCurrentDiagnosticInline()
|
||||
changeSet.insert(insertStart, newText);
|
||||
}
|
||||
}
|
||||
refactoringFile->setChangeSet(changeSet);
|
||||
refactoringFile->apply();
|
||||
refactoringFile->apply(changeSet);
|
||||
}
|
||||
|
||||
filterModel->addSuppressedDiagnostics(diags);
|
||||
|
||||
@@ -267,13 +267,11 @@ void FunctionDeclDefLink::apply(CppEditorWidget *editor, bool jumpToMatch)
|
||||
const int targetStart = newTargetFile->position(targetLine, targetColumn);
|
||||
const int targetEnd = targetStart + targetInitial.size();
|
||||
if (targetInitial == newTargetFile->textOf(targetStart, targetEnd)) {
|
||||
const ChangeSet changeset = changes(snapshot, targetStart);
|
||||
newTargetFile->setChangeSet(changeset);
|
||||
if (jumpToMatch) {
|
||||
const int jumpTarget = newTargetFile->position(targetFunction->line(), targetFunction->column());
|
||||
newTargetFile->setOpenEditor(true, jumpTarget);
|
||||
}
|
||||
newTargetFile->apply();
|
||||
newTargetFile->apply(changes(snapshot, targetStart));
|
||||
} else {
|
||||
ToolTip::show(editor->toolTipPosition(linkSelection),
|
||||
Tr::tr("Target file was changed, could not apply changes"));
|
||||
|
||||
@@ -2010,8 +2010,7 @@ void CppModelManager::renameIncludes(const QList<std::pair<FilePath, FilePath>>
|
||||
newString);
|
||||
}
|
||||
}
|
||||
file->setChangeSet(changeSet);
|
||||
file->apply();
|
||||
file->apply(changeSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -54,8 +54,7 @@ private:
|
||||
varName + QLatin1String(" = "));
|
||||
ChangeSet changes;
|
||||
changes.insert(m_insertPos, insertString);
|
||||
m_file->setChangeSet(changes);
|
||||
m_file->apply();
|
||||
m_file->apply(changes);
|
||||
|
||||
// move cursor to new variable name
|
||||
QTextCursor c = m_file->cursor();
|
||||
|
||||
@@ -292,8 +292,7 @@ private:
|
||||
insertion.append('\n');
|
||||
ChangeSet s;
|
||||
s.insert(insertPos, insertion);
|
||||
file->setChangeSet(s);
|
||||
file->apply();
|
||||
file->apply(s);
|
||||
}
|
||||
|
||||
const QString m_className;
|
||||
@@ -314,8 +313,7 @@ void AddIncludeForUndefinedIdentifierOp::perform()
|
||||
|
||||
ChangeSet changes;
|
||||
insertNewIncludeDirective(m_include, file, semanticInfo().doc, changes);
|
||||
file->setChangeSet(changes);
|
||||
file->apply();
|
||||
file->apply(changes);
|
||||
}
|
||||
|
||||
AddForwardDeclForUndefinedIdentifierOp::AddForwardDeclForUndefinedIdentifierOp(
|
||||
|
||||
@@ -87,8 +87,7 @@ public:
|
||||
changes.insert(start, QLatin1String("\ncase ")
|
||||
+ values.join(QLatin1String(":\nbreak;\ncase "))
|
||||
+ QLatin1String(":\nbreak;"));
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
CompoundStatementAST *compoundStatement;
|
||||
|
||||
@@ -67,8 +67,7 @@ public:
|
||||
break;
|
||||
}
|
||||
|
||||
m_file->setChangeSet(changes);
|
||||
m_file->apply();
|
||||
m_file->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -30,8 +30,7 @@ public:
|
||||
{
|
||||
ChangeSet changes;
|
||||
changes.replace(start, end, replacement);
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -35,8 +35,7 @@ public:
|
||||
private:
|
||||
void perform() override
|
||||
{
|
||||
currentFile()->setChangeSet(m_changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(m_changes);
|
||||
}
|
||||
|
||||
const ChangeSet m_changes;
|
||||
|
||||
@@ -275,8 +275,7 @@ public:
|
||||
changes.insert(endPos, "\"" + str + "\"");
|
||||
replace = false;
|
||||
}
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -352,8 +351,7 @@ public:
|
||||
changes.insert(startPos, leading);
|
||||
}
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -386,8 +384,7 @@ public:
|
||||
changes.insert(currentFile()->startOf(stringLiteral), QLatin1String("@"));
|
||||
}
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -55,8 +55,7 @@ private:
|
||||
if (m_test) {
|
||||
ChangeSet changeSet;
|
||||
changeSet.replace(currentFile()->range(m_nameAst), newName);
|
||||
currentFile()->setChangeSet(changeSet);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changeSet);
|
||||
} else {
|
||||
editor()->renameUsages(newName);
|
||||
}
|
||||
|
||||
@@ -100,8 +100,7 @@ private:
|
||||
}
|
||||
|
||||
// Apply the changes.
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
const CallAST * const m_callAst;
|
||||
|
||||
@@ -307,14 +307,10 @@ public:
|
||||
insertAndIndent(m_sourceFile, m_sourceFileInsertionPoint, m_sourceFileCode);
|
||||
}
|
||||
|
||||
if (!m_headerFileChangeSet.isEmpty()) {
|
||||
m_headerFile->setChangeSet(m_headerFileChangeSet);
|
||||
m_headerFile->apply();
|
||||
}
|
||||
if (!m_sourceFileChangeSet.isEmpty()) {
|
||||
m_sourceFile->setChangeSet(m_sourceFileChangeSet);
|
||||
m_sourceFile->apply();
|
||||
}
|
||||
if (!m_headerFileChangeSet.isEmpty())
|
||||
m_headerFile->apply(m_headerFileChangeSet);
|
||||
if (!m_sourceFileChangeSet.isEmpty())
|
||||
m_sourceFile->apply(m_sourceFileChangeSet);
|
||||
}
|
||||
|
||||
bool hasSourceFile() const { return m_headerFile != m_sourceFile; }
|
||||
|
||||
@@ -868,9 +868,8 @@ public:
|
||||
|
||||
// Write header file
|
||||
if (!headerChangeSet.isEmpty()) {
|
||||
headerFile->setChangeSet(headerChangeSet);
|
||||
headerFile->setOpenEditor(true, m_insertPosDecl);
|
||||
headerFile->apply();
|
||||
headerFile->apply(headerChangeSet);
|
||||
}
|
||||
|
||||
// Insert in implementation file
|
||||
@@ -921,10 +920,8 @@ public:
|
||||
implementationChangeSet.insert(insertPos, QLatin1String("\n\n") + defText);
|
||||
}
|
||||
|
||||
if (!implementationChangeSet.isEmpty()) {
|
||||
implementationFile->setChangeSet(implementationChangeSet);
|
||||
implementationFile->apply();
|
||||
}
|
||||
if (!implementationChangeSet.isEmpty())
|
||||
implementationFile->apply(implementationChangeSet);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -113,9 +113,8 @@ public:
|
||||
|
||||
ChangeSet target;
|
||||
target.insert(targetPosition, loc.prefix() + m_decl);
|
||||
targetFile->setChangeSet(target);
|
||||
targetFile->setOpenEditor(true, targetPosition);
|
||||
targetFile->apply();
|
||||
targetFile->apply(target);
|
||||
}
|
||||
|
||||
static QString generateDeclaration(const Function *function)
|
||||
@@ -206,8 +205,7 @@ private:
|
||||
const int targetPosition = targetFile->position(loc.line(), loc.column());
|
||||
ChangeSet target;
|
||||
target.insert(targetPosition, loc.prefix() + decl + ";\n");
|
||||
targetFile->setChangeSet(target);
|
||||
targetFile->apply();
|
||||
targetFile->apply(target);
|
||||
}
|
||||
|
||||
const Class * const m_class;
|
||||
@@ -242,8 +240,7 @@ public:
|
||||
changes.replace(currentFile()->startOf(binaryAST),
|
||||
currentFile()->endOf(simpleNameAST),
|
||||
declaration);
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -202,8 +202,7 @@ public:
|
||||
ChangeSet change;
|
||||
change.insert(position, funcDef);
|
||||
change.replace(m_extractionStart, m_extractionEnd, funcCall);
|
||||
currentFile()->setChangeSet(change);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(change);
|
||||
|
||||
// Write declaration, if necessary.
|
||||
if (matchingClass) {
|
||||
@@ -215,8 +214,7 @@ public:
|
||||
change.clear();
|
||||
position = declFile->position(location.line(), location.column());
|
||||
change.insert(position, location.prefix() + funcDecl + location.suffix());
|
||||
declFile->setChangeSet(change);
|
||||
declFile->apply();
|
||||
declFile->apply(change);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -201,15 +201,13 @@ public:
|
||||
ChangeSet declChanges;
|
||||
appendFunctionParameter(functionDeclaration.ast, functionDeclaration.file, &declChanges,
|
||||
true);
|
||||
functionDeclaration.file->setChangeSet(declChanges);
|
||||
functionDeclaration.file->apply();
|
||||
functionDeclaration.file->apply(declChanges);
|
||||
} else {
|
||||
appendFunctionParameter(functionDeclaration.ast, currentFile(), &changes,
|
||||
true);
|
||||
}
|
||||
}
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
QTextCursor c = currentFile()->cursor();
|
||||
c.setPosition(c.position() - parameterName().length());
|
||||
editor()->setTextCursor(c);
|
||||
|
||||
@@ -114,9 +114,8 @@ public:
|
||||
target->replace(targetPos - 1, targetPos, QLatin1String("\n {\n\n}")); // replace ';'
|
||||
|
||||
if (!changeSet) {
|
||||
targetFile->setChangeSet(*target);
|
||||
targetFile->setOpenEditor(true, targetPos);
|
||||
targetFile->apply();
|
||||
targetFile->apply(*target);
|
||||
|
||||
// Move cursor inside definition
|
||||
QTextCursor c = targetFile->cursor();
|
||||
@@ -190,9 +189,8 @@ public:
|
||||
target->insert(targetPos, loc.prefix() + defText + loc.suffix());
|
||||
|
||||
if (!changeSet) {
|
||||
targetFile->setChangeSet(*target);
|
||||
targetFile->setOpenEditor(true, targetPos);
|
||||
targetFile->apply();
|
||||
targetFile->apply(*target);
|
||||
|
||||
// Move cursor inside definition
|
||||
QTextCursor c = targetFile->cursor();
|
||||
@@ -454,11 +452,8 @@ private:
|
||||
this, loc, setting.defPos, finder.decl()->declarator_list->value,
|
||||
setting.func->asDeclaration(),targetFilePath, &changeSet);
|
||||
}
|
||||
for (auto it = changeSets.cbegin(); it != changeSets.cend(); ++it) {
|
||||
const CppRefactoringFilePtr file = refactoring.cppFile(it.key());
|
||||
file->setChangeSet(it.value());
|
||||
file->apply();
|
||||
}
|
||||
for (auto it = changeSets.cbegin(); it != changeSets.cend(); ++it)
|
||||
refactoring.cppFile(it.key())->apply(it.value());
|
||||
}
|
||||
|
||||
ClassSpecifierAST *m_classAST = nullptr;
|
||||
|
||||
@@ -41,8 +41,7 @@ public:
|
||||
if (!replacement.isEmpty())
|
||||
changes.replace(currentFile()->range(binary->binary_op_token), replacement);
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -94,8 +93,7 @@ public:
|
||||
changes.insert(currentFile()->endOf(binary), QLatin1String(")"));
|
||||
}
|
||||
changes.replace(currentFile()->range(binary->binary_op_token), replacement);
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -134,8 +132,7 @@ public:
|
||||
changes.insert(start, QLatin1String("!("));
|
||||
changes.insert(end, QLatin1String(")"));
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -441,8 +441,7 @@ private:
|
||||
.append('\n');
|
||||
changes.remove(rangeToMove);
|
||||
}
|
||||
refactoringFile->setChangeSet(changes);
|
||||
refactoringFile->apply();
|
||||
refactoringFile->apply(changes);
|
||||
}
|
||||
|
||||
if (!namespaceNames.isEmpty()) {
|
||||
@@ -455,19 +454,15 @@ private:
|
||||
if (!fileSettings.headerPragmaOnce)
|
||||
headerContent.append("\n#endif // " + headerGuard + '\n');
|
||||
|
||||
CppRefactoringFilePtr headerFile = state->factory.cppFile(headerFilePath);
|
||||
headerFilePath.ensureExistingFile();
|
||||
ChangeSet headerChanges;
|
||||
headerChanges.insert(0, headerContent);
|
||||
headerFile->setChangeSet(headerChanges);
|
||||
headerFile->apply();
|
||||
state->factory.cppFile(headerFilePath)->apply(headerChanges);
|
||||
if (hasSourceContent || mustCreateSourceFile) {
|
||||
sourceFilePath.ensureExistingFile();
|
||||
CppRefactoringFilePtr sourceFile = state->factory.cppFile(sourceFilePath);
|
||||
ChangeSet sourceChanges;
|
||||
sourceChanges.insert(0, sourceContent);
|
||||
sourceFile->setChangeSet(sourceChanges);
|
||||
sourceFile->apply();
|
||||
state->factory.cppFile(sourceFilePath)->apply(sourceChanges);
|
||||
}
|
||||
|
||||
if (!projectNode)
|
||||
|
||||
@@ -135,14 +135,10 @@ public:
|
||||
|
||||
void applyChanges()
|
||||
{
|
||||
if (!m_toFileChangeSet.isEmpty()) {
|
||||
m_toFile->setChangeSet(m_toFileChangeSet);
|
||||
m_toFile->apply();
|
||||
}
|
||||
if (!m_fromFileChangeSet.isEmpty()) {
|
||||
m_fromFile->setChangeSet(m_fromFileChangeSet);
|
||||
m_fromFile->apply();
|
||||
}
|
||||
if (!m_toFileChangeSet.isEmpty())
|
||||
m_toFile->apply(m_toFileChangeSet);
|
||||
if (!m_fromFileChangeSet.isEmpty())
|
||||
m_fromFile->apply(m_fromFileChangeSet);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -278,14 +274,12 @@ private:
|
||||
toTarget.replace(m_toRange, wholeFunctionText);
|
||||
if (m_toFilePath == m_fromFilePath)
|
||||
toTarget.remove(m_fromRange);
|
||||
toFile->setChangeSet(toTarget);
|
||||
toFile->setOpenEditor(true, m_toRange.start);
|
||||
toFile->apply();
|
||||
toFile->apply(toTarget);
|
||||
if (m_toFilePath != m_fromFilePath) {
|
||||
ChangeSet fromTarget;
|
||||
fromTarget.remove(m_fromRange);
|
||||
fromFile->setChangeSet(fromTarget);
|
||||
fromFile->apply();
|
||||
fromFile->apply(fromTarget);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,9 +41,8 @@ public:
|
||||
Utils::ChangeSet changes;
|
||||
changes.flip(currentFile()->startOf(m_currentParam), currentFile()->endOf(m_currentParam),
|
||||
currentFile()->startOf(m_targetParam), targetEndPos);
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->setOpenEditor(false, targetEndPos);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -41,8 +41,7 @@ public:
|
||||
|
||||
void perform() override
|
||||
{
|
||||
currentFile()->setChangeSet(m_change);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(m_change);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -360,14 +360,12 @@ private:
|
||||
targetChangeSet.insert(insertionPos, QString(insertionColumn, ' '));
|
||||
if (targetFile == sourceFile)
|
||||
removeAtSource(targetChangeSet);
|
||||
targetFile->setChangeSet(targetChangeSet);
|
||||
const bool targetFileSuccess = targetFile->apply();
|
||||
const bool targetFileSuccess = targetFile->apply(targetChangeSet);
|
||||
if (targetFile == sourceFile || !targetFileSuccess)
|
||||
return;
|
||||
ChangeSet sourceChangeSet;
|
||||
removeAtSource(sourceChangeSet);
|
||||
sourceFile->setChangeSet(sourceChangeSet);
|
||||
sourceFile->apply();
|
||||
sourceFile->apply(sourceChangeSet);
|
||||
}
|
||||
|
||||
const Symbol * const m_symbol;
|
||||
|
||||
@@ -179,8 +179,7 @@ public:
|
||||
changes.move(currentFile()->range(condition), insertPos);
|
||||
changes.insert(insertPos, QLatin1String(";\n"));
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
ASTMatcher matcher;
|
||||
@@ -219,8 +218,7 @@ public:
|
||||
changes.copy(currentFile()->range(core), insertPos);
|
||||
changes.insert(insertPos, QLatin1String(";\n"));
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
ASTMatcher matcher;
|
||||
@@ -265,8 +263,7 @@ public:
|
||||
changes.remove(lExprEnd, currentFile()->startOf(condition->right_expression));
|
||||
changes.insert(currentFile()->endOf(pattern), QLatin1String("\n}"));
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
void splitOrCondition() const
|
||||
@@ -293,8 +290,7 @@ public:
|
||||
const int lExprEnd = currentFile()->endOf(condition->left_expression);
|
||||
changes.remove(lExprEnd, currentFile()->startOf(condition->right_expression));
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
@@ -376,8 +372,7 @@ public:
|
||||
change.replace(exprRange, varName);
|
||||
}
|
||||
|
||||
file->setChangeSet(change);
|
||||
file->apply();
|
||||
file->apply(change);
|
||||
|
||||
// Select variable name and trigger symbol rename
|
||||
if (renamePos != -1) {
|
||||
|
||||
@@ -67,8 +67,7 @@ public:
|
||||
prevDeclarator = declarator;
|
||||
}
|
||||
|
||||
currentFile()->setChangeSet(changes);
|
||||
currentFile()->apply();
|
||||
currentFile()->apply(changes);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
@@ -629,8 +629,7 @@ bool QtCreatorIntegration::navigateToSlot(const QString &objectName,
|
||||
location.line(), location.column());
|
||||
ChangeSet changeSet;
|
||||
changeSet.insert(insertionPos, definition);
|
||||
file->setChangeSet(changeSet);
|
||||
file->apply();
|
||||
file->apply(changeSet);
|
||||
const int indentationPos = file->document()->toPlainText().indexOf('}', insertionPos) - 1;
|
||||
QTextCursor cursor(editor->textDocument()->document());
|
||||
cursor.setPosition(indentationPos);
|
||||
|
||||
@@ -97,8 +97,7 @@ bool applyTextEdits(const Client *client,
|
||||
if (edits.isEmpty())
|
||||
return true;
|
||||
const RefactoringFilePtr file = client->createRefactoringFile(filePath);
|
||||
file->setChangeSet(editsToChangeSet(edits, file->document()));
|
||||
return file->apply();
|
||||
return file->apply(editsToChangeSet(edits, file->document()));
|
||||
}
|
||||
|
||||
void applyTextEdit(TextDocumentManipulatorInterface &manipulator,
|
||||
|
||||
@@ -189,8 +189,7 @@ public:
|
||||
|
||||
Utils::ChangeSet changes;
|
||||
changes.replace(start, end, replacement);
|
||||
currentFile->setChangeSet(changes);
|
||||
currentFile->apply();
|
||||
currentFile->apply(changes);
|
||||
|
||||
Core::IVersionControl *versionControl = Core::VcsManager::findVersionControlForDirectory(
|
||||
path);
|
||||
|
||||
@@ -70,8 +70,7 @@ public:
|
||||
changes.insert(currentFile->startOf(_objectInitializer->rbraceToken),
|
||||
QLatin1String("\n"));
|
||||
|
||||
currentFile->setChangeSet(changes);
|
||||
currentFile->apply();
|
||||
currentFile->apply(changes);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -120,8 +119,7 @@ public:
|
||||
Utils::ChangeSet changes;
|
||||
const int insertLoc = _message.location.begin() - _message.location.startColumn + 1;
|
||||
changes.insert(insertLoc, QString::fromLatin1("// %1\n").arg(_message.suppressionString()));
|
||||
currentFile->setChangeSet(changes);
|
||||
currentFile->apply();
|
||||
currentFile->apply(changes);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -146,8 +146,7 @@ public:
|
||||
" id: %2\n"
|
||||
" sourceComponent: %1\n"
|
||||
"}\n").arg(componentId, loaderId));
|
||||
currentFile->setChangeSet(changes);
|
||||
currentFile->apply();
|
||||
currentFile->apply(changes);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -897,10 +897,8 @@ void QmlOutlineModel::reparentNodes(QmlOutlineItem *targetItem, int row, QList<Q
|
||||
changedRanges << range;
|
||||
}
|
||||
|
||||
QmlJSRefactoringChanges refactoring(ModelManagerInterface::instance(), m_semanticInfo.snapshot);
|
||||
TextEditor::RefactoringFilePtr file = refactoring.file(m_semanticInfo.document->fileName());
|
||||
file->setChangeSet(changeSet);
|
||||
file->apply();
|
||||
QmlJSRefactoringChanges(ModelManagerInterface::instance(), m_semanticInfo.snapshot)
|
||||
.file(m_semanticInfo.document->fileName())->apply(changeSet);
|
||||
}
|
||||
|
||||
void QmlOutlineModel::moveObjectMember(AST::Node *toMove,
|
||||
|
||||
@@ -594,8 +594,7 @@ FilePaths BaseFileFind::replaceAll(const QString &text, const SearchResultItems
|
||||
item.mainRange().end.column + 1);
|
||||
changeSet.replace(start, end, replacement);
|
||||
}
|
||||
file->setChangeSet(changeSet);
|
||||
file->apply();
|
||||
file->apply(changeSet);
|
||||
}
|
||||
|
||||
return changes.keys();
|
||||
|
||||
@@ -287,6 +287,12 @@ bool RefactoringFile::apply()
|
||||
return result;
|
||||
}
|
||||
|
||||
bool RefactoringFile::apply(const Utils::ChangeSet &changeSet)
|
||||
{
|
||||
setChangeSet(changeSet);
|
||||
return apply();
|
||||
}
|
||||
|
||||
void RefactoringFile::setupFormattingRanges(const QList<ChangeSet::EditOp> &replaceList)
|
||||
{
|
||||
QTextDocument * const doc = m_editor ? m_editor->document() : m_document;
|
||||
@@ -359,7 +365,7 @@ void RefactoringFile::doFormatting()
|
||||
Utils::sort(m_formattingCursors, [](const auto &tc1, const auto &tc2) {
|
||||
return tc1.first.selectionStart() < tc2.first.selectionStart();
|
||||
});
|
||||
static const QString clangFormatLineRemovalBlocker("// QTC_TEMP");
|
||||
static const QString clangFormatLineRemovalBlocker("");
|
||||
for (auto &[formattingCursor, _] : m_formattingCursors) {
|
||||
const QTextBlock firstBlock = document->findBlock(formattingCursor.selectionStart());
|
||||
const QTextBlock lastBlock = document->findBlock(formattingCursor.selectionEnd());
|
||||
|
||||
@@ -60,6 +60,7 @@ public:
|
||||
void setChangeSet(const Utils::ChangeSet &changeSet);
|
||||
void setOpenEditor(bool activate = false, int pos = -1);
|
||||
bool apply();
|
||||
bool apply(const Utils::ChangeSet &changeSet);
|
||||
bool create(const QString &contents, bool reindent, bool openInEditor);
|
||||
|
||||
protected:
|
||||
|
||||
@@ -522,10 +522,7 @@ bool TextDocument::applyChangeSet(const ChangeSet &changeSet)
|
||||
{
|
||||
if (changeSet.isEmpty())
|
||||
return true;
|
||||
PlainRefactoringFileFactory changes;
|
||||
const RefactoringFilePtr file = changes.file(filePath());
|
||||
file->setChangeSet(changeSet);
|
||||
return file->apply();
|
||||
return PlainRefactoringFileFactory().file(filePath())->apply(changeSet);
|
||||
}
|
||||
|
||||
// the blocks list must be sorted
|
||||
|
||||
Reference in New Issue
Block a user