Search in sources :

Example 1 with UndoHandler

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");
    }
}
Also used : UndoHandler(com.thoughtworks.gauge.undo.UndoHandler) Api(gauge.messages.Api) PsiElement(com.intellij.psi.PsiElement)

Example 2 with UndoHandler

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));
    });
}
Also used : GaugeService(com.thoughtworks.gauge.core.GaugeService) UndoHandler(com.thoughtworks.gauge.undo.UndoHandler) Api(gauge.messages.Api) Module(com.intellij.openapi.module.Module)

Aggregations

UndoHandler (com.thoughtworks.gauge.undo.UndoHandler)2 Api (gauge.messages.Api)2 Module (com.intellij.openapi.module.Module)1 PsiElement (com.intellij.psi.PsiElement)1 GaugeService (com.thoughtworks.gauge.core.GaugeService)1