Search in sources :

Example 91 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class EditorPlaceHolder method setContent.

public void setContent(final DiffContent content) {
    runRegisteredDisposables();
    myContent = content;
    if (myContent != null) {
        Document document = myContent.getDocument();
        if (myContent.isBinary() || document == null || myContent.getContentType() instanceof UIBasedFileType) {
            final VirtualFile file = myContent.getFile();
            if (file != null) {
                final FileEditorProvider[] providers = FileEditorProviderManager.getInstance().getProviders(getProject(), file);
                if (providers.length > 0) {
                    myFileEditor = providers[0].createEditor(getProject(), file);
                    if (myFileEditor instanceof TextEditor) {
                        myEditor = (EditorEx) ((TextEditor) myFileEditor).getEditor();
                        ContentDocumentListener.install(myContent, this);
                    }
                    myFileEditorProvider = providers[0];
                    addDisposable(new Disposable() {

                        @Override
                        public void dispose() {
                            myFileEditorProvider.disposeEditor(myFileEditor);
                            myFileEditor = null;
                            myFileEditorProvider = null;
                            myEditor = null;
                        }
                    });
                } else {
                    document = new DocumentImpl("Can not show", true);
                    final EditorFactory editorFactory = EditorFactory.getInstance();
                    myEditor = DiffUtil.createEditor(document, getProject(), true, content.getContentType());
                    addDisposable(new Disposable() {

                        public void dispose() {
                            editorFactory.releaseEditor(myEditor);
                            myEditor = null;
                        }
                    });
                }
            }
        } else {
            final EditorFactory editorFactory = EditorFactory.getInstance();
            myEditor = DiffUtil.createEditor(document, getProject(), false, content.getContentType());
            addDisposable(new Disposable() {

                public void dispose() {
                    editorFactory.releaseEditor(myEditor);
                    myEditor = null;
                }
            });
            ContentDocumentListener.install(myContent, this);
        }
    }
    fireContentChanged();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Disposable(com.intellij.openapi.Disposable) UIBasedFileType(com.intellij.openapi.fileTypes.UIBasedFileType) EditorFactory(com.intellij.openapi.editor.EditorFactory) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) Document(com.intellij.openapi.editor.Document) DocumentImpl(com.intellij.openapi.editor.impl.DocumentImpl)

Example 92 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class FrameDiffTool method checkNoDifferenceAndNotify.

// TODO remove check?
private boolean checkNoDifferenceAndNotify(DiffPanel diffPanel, DiffRequest data, final Window window, final boolean showMessage) {
    if (diffPanel.hasDifferences() || data.getHints().contains(HINT_ALLOW_NO_DIFFERENCES)) {
        return false;
    }
    DiffManagerImpl manager = (DiffManagerImpl) DiffManager.getInstance();
    ComparisonPolicy oldPolicy = manager.getComparisonPolicy();
    if (oldPolicy != ComparisonPolicy.DEFAULT) {
        manager.setComparisonPolicy(ComparisonPolicy.DEFAULT);
        Disposable parentDisposable = Disposer.newDisposable();
        DiffPanel maybeDiffPanel = DiffManagerImpl.createDiffPanel(data, window, parentDisposable, this);
        manager.setComparisonPolicy(oldPolicy);
        boolean hasDiffs = maybeDiffPanel.hasDifferences();
        Disposer.dispose(parentDisposable);
        if (hasDiffs) {
            return false;
        }
    }
    return !showMessage || !askForceOpenDiff(data);
}
Also used : Disposable(com.intellij.openapi.Disposable) ComparisonPolicy(com.intellij.openapi.diff.impl.ComparisonPolicy)

Example 93 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class MultiLevelDiffTool method createPanel.

private CompositeDiffPanel createPanel(final DiffRequest request, final Window window, @NotNull Disposable parentDisposable) {
    final CompositeDiffPanel panel = new CompositeDiffPanel(request.getProject(), this, window, parentDisposable);
    request.getGenericData().put(PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName(), panel);
    final List<Pair<String, DiffRequest>> layers = request.getOtherLayers();
    if (layers != null) {
        for (Pair<String, DiffRequest> layer : layers) {
            layer.getSecond().getGenericData().put(PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName(), panel);
        }
    }
    Disposer.register(parentDisposable, new Disposable() {

        @Override
        public void dispose() {
            final String name = PlatformDataKeys.COMPOSITE_DIFF_VIEWER.getName();
            request.getGenericData().remove(name);
            if (layers != null) {
                for (Pair<String, DiffRequest> layer : layers) {
                    layer.getSecond().getGenericData().remove(name);
                }
            }
        }
    });
    return panel;
}
Also used : Disposable(com.intellij.openapi.Disposable) CompositeDiffPanel(com.intellij.openapi.diff.impl.CompositeDiffPanel) Pair(com.intellij.openapi.util.Pair)

Example 94 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class HistoryEntry method createHeavy.

@NotNull
static HistoryEntry createHeavy(@NotNull Project project, @NotNull Element e) throws InvalidDataException {
    if (project.isDisposed())
        return createLight(project, e);
    EntryData entryData = parseEntry(project, e);
    Disposable disposable = Disposer.newDisposable();
    VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(entryData.url, disposable, null);
    HistoryEntry entry = new HistoryEntry(pointer, entryData.selectedProvider, disposable);
    for (Pair<FileEditorProvider, FileEditorState> state : entryData.providerStates) {
        entry.putState(state.first, state.second);
    }
    return entry;
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Example 95 with Disposable

use of com.intellij.openapi.Disposable in project intellij-community by JetBrains.

the class HistoryEntry method createHeavy.

@NotNull
static HistoryEntry createHeavy(@NotNull Project project, @NotNull VirtualFile file, @NotNull FileEditorProvider[] providers, @NotNull FileEditorState[] states, @NotNull FileEditorProvider selectedProvider) {
    if (project.isDisposed())
        return createLight(file, providers, states, selectedProvider);
    Disposable disposable = Disposer.newDisposable();
    VirtualFilePointer pointer = VirtualFilePointerManager.getInstance().create(file, disposable, null);
    HistoryEntry entry = new HistoryEntry(pointer, selectedProvider, disposable);
    for (int i = 0; i < providers.length; i++) {
        FileEditorProvider provider = providers[i];
        FileEditorState state = states[i];
        if (provider != null && state != null) {
            entry.putState(provider, state);
        }
    }
    return entry;
}
Also used : Disposable(com.intellij.openapi.Disposable) FileEditorProvider(com.intellij.openapi.fileEditor.FileEditorProvider) FileEditorState(com.intellij.openapi.fileEditor.FileEditorState) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Disposable (com.intellij.openapi.Disposable)282 NotNull (org.jetbrains.annotations.NotNull)52 Test (org.junit.Test)25 Project (com.intellij.openapi.project.Project)18 TestOnly (org.jetbrains.annotations.TestOnly)17 ArrayList (java.util.ArrayList)13 VirtualFile (com.intellij.openapi.vfs.VirtualFile)11 RelativePoint (com.intellij.ui.awt.RelativePoint)11 Nullable (org.jetbrains.annotations.Nullable)10 Document (com.intellij.openapi.editor.Document)9 File (java.io.File)9 ProcessHandler (com.intellij.execution.process.ProcessHandler)6 Editor (com.intellij.openapi.editor.Editor)6 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)6 VirtualFilePointer (com.intellij.openapi.vfs.pointers.VirtualFilePointer)6 Content (com.intellij.ui.content.Content)6 ProcessCanceledException (com.intellij.openapi.progress.ProcessCanceledException)5 Alarm (com.intellij.util.Alarm)5 ActionEvent (java.awt.event.ActionEvent)5 ListSelectionEvent (javax.swing.event.ListSelectionEvent)5