Skip to content

Commit 81d0746

Browse files
authored
Remove the use of the now deprecated WriteCommandAction.Simple usages (#8316)
1 parent 0942d24 commit 81d0746

File tree

1 file changed

+34
-40
lines changed

1 file changed

+34
-40
lines changed

flutter-idea/src/io/flutter/editor/FlutterSaveActionsManager.java

Lines changed: 34 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,22 @@ private void performOrganizeThenFormat(@NotNull Document document, @NotNull Virt
131131
return;
132132
}
133133

134-
new WriteCommandAction.Simple(myProject) {
135-
@Override
136-
protected void run() {
137-
if (myProject.isDisposed()) {
138-
return;
139-
}
140-
141-
AssistUtils.applySourceEdits(myProject, file, document, fileEdit.getEdits(), Collections.emptySet());
142-
143-
// Committing a document here is required in order to guarantee that DartPostFormatProcessor.processText() is called afterwards.
144-
PsiDocumentManager.getInstance(myProject).commitDocument(document);
145-
146-
// Run this in an invoke later so that we don't exeucte the initial part of performFormat in a write action.
147-
//noinspection CodeBlock2Expr
148-
OpenApiUtils.safeInvokeLater(() -> {
149-
performFormat(document, file, true, psiFile);
150-
});
134+
WriteCommandAction.writeCommandAction(myProject).run(() -> {
135+
if (myProject.isDisposed()) {
136+
return;
151137
}
152-
}.execute();
138+
139+
AssistUtils.applySourceEdits(myProject, file, document, fileEdit.getEdits(), Collections.emptySet());
140+
141+
// Committing a document here is required in order to guarantee that DartPostFormatProcessor.processText() is called afterwards.
142+
PsiDocumentManager.getInstance(myProject).commitDocument(document);
143+
144+
// Run this in an invoke later so that we don't exeucte the initial part of performFormat in a write action.
145+
//noinspection CodeBlock2Expr
146+
OpenApiUtils.safeInvokeLater(() -> {
147+
performFormat(document, file, true, psiFile);
148+
});
149+
});
153150
});
154151
}
155152
}
@@ -174,33 +171,30 @@ private void performFormat(@NotNull Document document, @NotNull VirtualFile file
174171
return;
175172
}
176173

177-
new WriteCommandAction.Simple(myProject) {
178-
@Override
179-
protected void run() {
180-
if (myProject.isDisposed()) {
181-
return;
182-
}
174+
WriteCommandAction.writeCommandAction(myProject).run(() -> {
175+
if (myProject.isDisposed()) {
176+
return;
177+
}
183178

184-
boolean didFormat = false;
179+
boolean didFormat = false;
185180

186-
final List<SourceEdit> edits = formatResult.getEdits();
187-
if (edits != null && edits.size() == 1) {
188-
final String replacement = StringUtil.convertLineSeparators(edits.get(0).getReplacement());
189-
document.replaceString(0, document.getTextLength(), replacement);
190-
PsiDocumentManager.getInstance(myProject).commitDocument(document);
181+
final List<SourceEdit> edits = formatResult.getEdits();
182+
if (edits != null && edits.size() == 1) {
183+
final String replacement = StringUtil.convertLineSeparators(edits.get(0).getReplacement());
184+
document.replaceString(0, document.getTextLength(), replacement);
185+
PsiDocumentManager.getInstance(myProject).commitDocument(document);
191186

192-
didFormat = true;
193-
}
187+
didFormat = true;
188+
}
194189

195-
// Don't perform the save in a write action - it could invoke EDT work.
196-
if (reSave || didFormat) {
197-
//noinspection CodeBlock2Expr
198-
OpenApiUtils.safeInvokeLater(() -> {
199-
FileDocumentManager.getInstance().saveDocument(document);
200-
});
201-
}
190+
// Don't perform the save in a write action - it could invoke EDT work.
191+
if (reSave || didFormat) {
192+
//noinspection CodeBlock2Expr
193+
OpenApiUtils.safeInvokeLater(() -> {
194+
FileDocumentManager.getInstance().saveDocument(document);
195+
});
202196
}
203-
}.execute();
197+
});
204198
});
205199
}
206200

0 commit comments

Comments
 (0)