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);
}
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);
}
}
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();
}
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);
}
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;
}
Aggregations