Search in sources :

Example 86 with Disposable

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

the class MacUtil method adjustFocusTraversal.

public static void adjustFocusTraversal(@NotNull Disposable disposable) {
    if (!SystemInfo.isMacOSSnowLeopard)
        return;
    final AWTEventListener listener = new AWTEventListener() {

        @Override
        public void eventDispatched(AWTEvent event) {
            if (event instanceof KeyEvent && ((KeyEvent) event).getKeyCode() == KeyEvent.VK_TAB && (!(event.getSource() instanceof JTextComponent)) && (!(event.getSource() instanceof JList)) && !isFullKeyboardAccessEnabled())
                ((KeyEvent) event).consume();
        }
    };
    Disposer.register(disposable, new Disposable() {

        @Override
        public void dispose() {
            Toolkit.getDefaultToolkit().removeAWTEventListener(listener);
        }
    });
    Toolkit.getDefaultToolkit().addAWTEventListener(listener, AWTEvent.KEY_EVENT_MASK);
}
Also used : KeyEvent(java.awt.event.KeyEvent) Disposable(com.intellij.openapi.Disposable) AWTEventListener(java.awt.event.AWTEventListener) JTextComponent(javax.swing.text.JTextComponent)

Example 87 with Disposable

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

the class DisposerTest method testIncest.

public void testIncest() {
    Disposable parent = newDisposable("parent");
    Disposable child = newDisposable("child");
    Disposer.register(parent, child);
    Disposable grand = newDisposable("grand");
    Disposer.register(child, grand);
    try {
        Disposer.register(grand, parent);
        fail("must not allow");
    } catch (IncorrectOperationException e) {
        assertEquals("'grand' was already added as a child of 'parent'", e.getMessage());
    } finally {
        Disposer.dispose(grand);
        Disposer.dispose(child);
        Disposer.dispose(parent);
    }
}
Also used : Disposer.newDisposable(com.intellij.openapi.util.Disposer.newDisposable) Disposable(com.intellij.openapi.Disposable) IncorrectOperationException(com.intellij.util.IncorrectOperationException)

Example 88 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 89 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 90 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)

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