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