use of com.intellij.openapi.fileTypes.UIBasedFileType in project intellij-community by JetBrains.
the class BinaryDiffTool method show.
public void show(final DiffRequest data) {
final DiffContent current = data.getContents()[0];
final DiffContent upToDate = data.getContents()[1];
final Project project = data.getProject();
if ((current instanceof FileContent && upToDate instanceof FileContent) || (current.getContentType() instanceof UIBasedFileType && upToDate.getContentType() instanceof UIBasedFileType)) {
final VirtualFile src = current.getFile();
final VirtualFile trg = upToDate.getFile();
if (src != null && trg != null) {
final PanelCreator creator = new PanelCreator(data);
if (creator.isCanCreatePanel()) {
new DialogWrapper(data.getProject()) {
public DiffPanel myPanel;
{
setModal(false);
init();
}
@Override
protected String getDimensionServiceKey() {
return "BinaryDiffDialog";
}
@NotNull
@Override
protected Action[] createActions() {
final Action close = getCancelAction();
close.putValue(Action.NAME, "&Close");
return new Action[] { close };
}
@Override
protected JComponent createCenterPanel() {
myPanel = creator.create(getWindow(), getDisposable(), BinaryDiffTool.this);
return myPanel.getComponent();
}
}.show();
return;
} else {
final DirDiffManager diffManager = DirDiffManager.getInstance(project);
final DiffElement before = diffManager.createDiffElement(src);
final DiffElement after = diffManager.createDiffElement(trg);
if (before != null && after != null && diffManager.canShow(after, before)) {
diffManager.showDiff(before, after);
return;
}
}
}
}
try {
final boolean equal = Arrays.equals(current.getBytes(), upToDate.getBytes());
Messages.showMessageDialog(equal ? DiffBundle.message("binary.files.are.identical.message") : DiffBundle.message("binary.files.are.different.message"), equal ? DiffBundle.message("files.are.identical.dialog.title") : DiffBundle.message("files.are.different.dialog.title"), Messages.getInformationIcon());
} catch (IOException e) {
LOG.error(e);
}
}
use of com.intellij.openapi.fileTypes.UIBasedFileType 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.fileTypes.UIBasedFileType in project intellij-community by JetBrains.
the class BinaryContent method getFile.
@Override
@Nullable
public VirtualFile getFile() {
if (myFileType instanceof UIBasedFileType) {
final VirtualFile file = findVirtualFile();
if (file != null) {
final LightVirtualFile lightFile = new LightVirtualFile(file, new String(myBytes), 1);
lightFile.setOriginalFile(file);
return lightFile;
}
}
return null;
}
use of com.intellij.openapi.fileTypes.UIBasedFileType in project intellij-community by JetBrains.
the class CompositeDiffTool method chooseTool.
@Nullable
private DiffTool chooseTool(DiffRequest data) {
final DiffContent[] contents = data.getContents();
if (contents.length == 2) {
final FileType type1 = contents[0].getContentType();
final FileType type2 = contents[1].getContentType();
if (type1 == type2 && type1 instanceof UIBasedFileType) {
return BinaryDiffTool.INSTANCE;
}
//todo[kb] register or not this instance in common diff tools ?
if (type1 == type2 && type1 instanceof ArchiveFileType) {
return ArchiveDiffTool.INSTANCE;
}
}
for (DiffTool tool : myTools) {
if (tool.canShow(data))
return tool;
}
return null;
}
Aggregations