@SuppressWarnings("unchecked")
@Override
protected void configureTextViewer(TextViewer textViewer) {
if (!(textViewer instanceof SourceViewer))
return;
final SourceViewer sourceViewer = (SourceViewer) textViewer;
final IIndentPrefs indentPrefs = new DefaultIndentPrefs();
//Hack to provide the source viewer configuration that'll only be created later (there's a cycle there).
final WeakReference<PyEditConfigurationWithoutEditor>[] sourceViewerConfigurationObj = new WeakReference[1];
IPreferenceStore chainedPrefStore = PydevPrefs.getChainedPrefStore();
final ColorAndStyleCache c = new ColorAndStyleCache(chainedPrefStore);
this.getColorCache().add(c); //add for it to be disposed later.
IPySyntaxHighlightingAndCodeCompletionEditor editor = new IPySyntaxHighlightingAndCodeCompletionEditor() {
public void resetForceTabs() {
}
public void resetIndentPrefixes() {
SourceViewerConfiguration configuration = getEditConfiguration();
String[] types = configuration.getConfiguredContentTypes(sourceViewer);
for (int i = 0; i < types.length; i++) {
String[] prefixes = configuration.getIndentPrefixes(sourceViewer, types[i]);
if (prefixes != null && prefixes.length > 0)
sourceViewer.setIndentPrefixes(prefixes, types[i]);
}
}
public IIndentPrefs getIndentPrefs() {
return indentPrefs;
}
public ISourceViewer getEditorSourceViewer() {
return sourceViewer;
}
public PyEditConfigurationWithoutEditor getEditConfiguration() {
return sourceViewerConfigurationObj[0].get();
}
public ColorAndStyleCache getColorCache() {
return c;
}
public PySelection createPySelection() {
ISelection selection = sourceViewer.getSelection();
if (selection instanceof ITextSelection) {
return new PySelection(sourceViewer.getDocument(), (ITextSelection) selection);
} else {
return null;
}
}
public File getEditorFile() {
IResource file = PyMergeViewer.this.getResource(PyMergeViewer.this.getInput());
if (file != null && file instanceof IFile) {
IPath path = file.getLocation().makeAbsolute();
return path.toFile();
}
return null;
}
public IPythonNature getPythonNature() throws MisconfigurationException {
return PyMergeViewer.this.getPythonNature(PyMergeViewer.this.getInput());
}
public Object getAdapter(Class adapter) {
if (adapter == IResource.class) {
return PyMergeViewer.this.getResource(PyMergeViewer.this.getInput());
}
if (adapter == IFile.class) {
IResource resource = PyMergeViewer.this.getResource(PyMergeViewer.this.getInput());
if (resource instanceof IFile) {
return resource;
}
}
return null;
}
};
final PyEditConfiguration sourceViewerConfiguration = new PyEditConfiguration(c, editor, chainedPrefStore);
sourceViewerConfigurationObj[0] = new WeakReference<PyEditConfigurationWithoutEditor>(sourceViewerConfiguration);
sourceViewer.configure(sourceViewerConfiguration);
IPropertyChangeListener prefChangeListener = PyEdit.createPrefChangeListener(editor);
getPrefChangeListeners().add(prefChangeListener);
chainedPrefStore.addPropertyChangeListener(prefChangeListener);
}