use of com.thoughtworks.gauge.undo.UndoHandler in project Intellij-Plugin by getgauge.
the class ExtractConceptHandler method invoke.
public void invoke(@NotNull final Project project, @NotNull final Editor editor, @NotNull final PsiFile psiFile) {
this.psiFile = psiFile;
this.editor = editor;
try {
List<PsiElement> steps = getSteps(this.editor, this.psiFile);
if (steps.size() == 0)
throw new RuntimeException("Cannot Extract to Concept, selected text contains invalid elements");
ExtractConceptInfoCollector collector = new ExtractConceptInfoCollector(editor, builder.getTextToTableMap(), steps, project);
ExtractConceptInfo info = collector.getAllInfo();
if (!info.cancelled) {
VirtualFileManager.getInstance().refreshWithoutFileWatcher(false);
FileDocumentManager.getInstance().saveAllDocuments();
Api.ExtractConceptResponse response = makeExtractConceptRequest(steps, info.fileName, info.conceptName, false, psiFile);
if (!response.getIsSuccess())
throw new RuntimeException(response.getError());
new UndoHandler(response.getFilesChangedList(), project, "Extract Concept").handle();
}
} catch (Exception e) {
Messages.showErrorDialog(e.getMessage(), "Extract To Concept");
}
}
use of com.thoughtworks.gauge.undo.UndoHandler in project Intellij-Plugin by getgauge.
the class GaugeRefactorHandler method refactor.
private void refactor(String currentStepText, String newStepText, TransactionId contextTransaction, CompileContext context, RefactorStatusCallback refactorStatusCallback) {
refactorStatusCallback.onStatusChange("Refactoring...");
Module module = GaugeUtil.moduleForPsiElement(file);
TransactionGuard.getInstance().submitTransaction(() -> {
}, contextTransaction, () -> {
Api.PerformRefactoringResponse response = null;
FileDocumentManager.getInstance().saveAllDocuments();
FileDocumentManager.getInstance().saveDocumentAsIs(editor.getDocument());
GaugeService gaugeService = Gauge.getGaugeService(module, true);
try {
response = gaugeService.getGaugeConnection().sendPerformRefactoringRequest(currentStepText, newStepText);
} catch (Exception e) {
refactorStatusCallback.onFinish(new RefactoringStatus(false, String.format("Could not execute refactor command: %s", e.toString())));
return;
}
new UndoHandler(response.getFilesChangedList(), module.getProject(), "Refactoring").handle();
if (!response.getSuccess()) {
showMessage(response, context, refactorStatusCallback);
return;
}
refactorStatusCallback.onFinish(new RefactoringStatus(true));
});
}
Aggregations