Search in sources :

Example 6 with DiffRequest

use of com.intellij.diff.requests.DiffRequest in project intellij-community by JetBrains.

the class ChangeDiffRequestProducer method loadCurrentContents.

@NotNull
protected DiffRequest loadCurrentContents(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator) throws DiffRequestProducerException {
    DiffRequestProducerException wrapperException = null;
    DiffRequestProducerException requestException = null;
    DiffViewerWrapper wrapper = null;
    try {
        for (ChangeDiffViewerWrapperProvider provider : ChangeDiffViewerWrapperProvider.EP_NAME.getExtensions()) {
            if (provider.canCreate(myProject, myChange)) {
                wrapper = provider.process(this, context, indicator);
                break;
            }
        }
    } catch (DiffRequestProducerException e) {
        wrapperException = e;
    }
    DiffRequest request = null;
    try {
        for (ChangeDiffRequestProvider provider : ChangeDiffRequestProvider.EP_NAME.getExtensions()) {
            if (provider.canCreate(myProject, myChange)) {
                request = provider.process(this, context, indicator);
                break;
            }
        }
        if (request == null)
            request = createRequest(myProject, myChange, context, indicator);
    } catch (DiffRequestProducerException e) {
        requestException = e;
    }
    if (requestException != null && wrapperException != null) {
        String message = requestException.getMessage() + "\n\n" + wrapperException.getMessage();
        throw new DiffRequestProducerException(message);
    }
    if (requestException != null) {
        request = new ErrorDiffRequest(getRequestTitle(myChange), requestException);
        LOG.info("Request: " + requestException.getMessage());
    }
    if (wrapperException != null) {
        LOG.info("Wrapper: " + wrapperException.getMessage());
    }
    request.putUserData(CHANGE_KEY, myChange);
    request.putUserData(DiffViewerWrapper.KEY, wrapper);
    for (Map.Entry<Key, Object> entry : myChangeContext.entrySet()) {
        request.putUserData(entry.getKey(), entry.getValue());
    }
    DiffUtil.putDataKey(request, VcsDataKeys.CURRENT_CHANGE, myChange);
    return request;
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) ErrorDiffRequest(com.intellij.diff.requests.ErrorDiffRequest) DiffViewerWrapper(com.intellij.diff.impl.DiffViewerWrapper) ErrorDiffRequest(com.intellij.diff.requests.ErrorDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) Map(java.util.Map) Key(com.intellij.openapi.util.Key) NotNull(org.jetbrains.annotations.NotNull)

Example 7 with DiffRequest

use of com.intellij.diff.requests.DiffRequest in project intellij-plugins by JetBrains.

the class DiffWindowOpener method showDiff.

public void showDiff() {
    String title = "Diff for " + myVFile.getDisplayName();
    String title1 = "My Version";
    String title2 = myRemoteUser.getDisplayName() + "'s Version";
    DiffContent content1 = DiffContentFactory.getInstance().create(myProject, myVirtualFile);
    DiffContent content2 = DiffContentFactory.getInstance().create(myRemoteText, myVirtualFile.getFileType());
    DiffRequest request = new SimpleDiffRequest(title, content1, content2, title1, title2);
    DiffManagerEx.getInstance().showDiff(myProject, request, DiffDialogHints.NON_MODAL);
}
Also used : SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) SimpleDiffRequest(com.intellij.diff.requests.SimpleDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) DiffContent(com.intellij.diff.contents.DiffContent)

Example 8 with DiffRequest

use of com.intellij.diff.requests.DiffRequest in project intellij-community by JetBrains.

the class ExternalDiffTool method show.

public static void show(@Nullable final Project project, @NotNull final DiffRequestChain chain, @NotNull final DiffDialogHints hints) {
    try {
        //noinspection unchecked
        final Ref<List<DiffRequest>> requestsRef = new Ref<>();
        final Ref<Throwable> exceptionRef = new Ref<>();
        ProgressManager.getInstance().run(new Task.Modal(project, "Loading Requests", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                try {
                    requestsRef.set(collectRequests(project, chain, indicator));
                } catch (Throwable e) {
                    exceptionRef.set(e);
                }
            }
        });
        if (!exceptionRef.isNull())
            throw exceptionRef.get();
        List<DiffRequest> showInBuiltin = new ArrayList<>();
        for (DiffRequest request : requestsRef.get()) {
            if (canShow(request)) {
                showRequest(project, request);
            } else {
                showInBuiltin.add(request);
            }
        }
        if (!showInBuiltin.isEmpty()) {
            DiffManagerEx.getInstance().showDiffBuiltin(project, new SimpleDiffRequestChain(showInBuiltin), hints);
        }
    } catch (ProcessCanceledException ignore) {
    } catch (Throwable e) {
        LOG.warn(e);
        Messages.showErrorDialog(project, e.getMessage(), "Can't Show Diff In External Tool");
    }
}
Also used : Task(com.intellij.openapi.progress.Task) ArrayList(java.util.ArrayList) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) Ref(com.intellij.openapi.util.Ref) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) ArrayList(java.util.ArrayList) List(java.util.List) SimpleDiffRequestChain(com.intellij.diff.chains.SimpleDiffRequestChain) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException)

Example 9 with DiffRequest

use of com.intellij.diff.requests.DiffRequest in project intellij-community by JetBrains.

the class ExternalDiffTool method collectRequests.

@NotNull
private static List<DiffRequest> collectRequests(@Nullable Project project, @NotNull final DiffRequestChain chain, @NotNull ProgressIndicator indicator) {
    List<DiffRequest> requests = new ArrayList<>();
    UserDataHolderBase context = new UserDataHolderBase();
    List<String> errorRequests = new ArrayList<>();
    // TODO: show all changes on explicit selection
    List<? extends DiffRequestProducer> producers = Collections.singletonList(chain.getRequests().get(chain.getIndex()));
    for (DiffRequestProducer producer : producers) {
        try {
            requests.add(producer.process(context, indicator));
        } catch (DiffRequestProducerException e) {
            LOG.warn(e);
            errorRequests.add(producer.getName());
        }
    }
    if (!errorRequests.isEmpty()) {
        new Notification("diff", "Can't load some changes", StringUtil.join(errorRequests, "<br>"), NotificationType.ERROR).notify(project);
    }
    return requests;
}
Also used : DiffRequestProducerException(com.intellij.diff.chains.DiffRequestProducerException) UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) ArrayList(java.util.ArrayList) ContentDiffRequest(com.intellij.diff.requests.ContentDiffRequest) DiffRequest(com.intellij.diff.requests.DiffRequest) DiffRequestProducer(com.intellij.diff.chains.DiffRequestProducer) Notification(com.intellij.notification.Notification) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with DiffRequest

use of com.intellij.diff.requests.DiffRequest in project intellij-community by JetBrains.

the class DiffApplication method processCommand.

@Override
public void processCommand(@NotNull String[] args, @Nullable String currentDirectory) throws Exception {
    Project project = getProject();
    List<String> filePaths = Arrays.asList(args).subList(1, args.length);
    List<VirtualFile> files = findFiles(filePaths, currentDirectory);
    DiffRequest request;
    if (files.size() == 3) {
        request = DiffRequestFactory.getInstance().createFromFiles(project, files.get(0), files.get(2), files.get(1));
    } else {
        request = DiffRequestFactory.getInstance().createFromFiles(project, files.get(0), files.get(1));
    }
    DiffManagerEx.getInstance().showDiffBuiltin(project, request, DiffDialogHints.MODAL);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DiffRequest(com.intellij.diff.requests.DiffRequest)

Aggregations

DiffRequest (com.intellij.diff.requests.DiffRequest)17 SimpleDiffRequest (com.intellij.diff.requests.SimpleDiffRequest)7 DiffContent (com.intellij.diff.contents.DiffContent)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 NotNull (org.jetbrains.annotations.NotNull)5 DiffRequestProducerException (com.intellij.diff.chains.DiffRequestProducerException)4 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)4 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)4 ContentDiffRequest (com.intellij.diff.requests.ContentDiffRequest)3 Project (com.intellij.openapi.project.Project)3 FilePath (com.intellij.openapi.vcs.FilePath)3 IOException (java.io.IOException)3 DocumentContent (com.intellij.diff.contents.DocumentContent)2 UnknownFileTypeDiffRequest (com.intellij.diff.requests.UnknownFileTypeDiffRequest)2 FileType (com.intellij.openapi.fileTypes.FileType)2 Task (com.intellij.openapi.progress.Task)2 Ref (com.intellij.openapi.util.Ref)2 UserDataHolder (com.intellij.openapi.util.UserDataHolder)2 Change (com.intellij.openapi.vcs.changes.Change)2 File (java.io.File)2