@Override
public void createPartControl(Composite parent) {
this.parent = parent;
this.shell = parent.getShell();
VimPlugin plugin = VimPlugin.getDefault();
if (!plugin.gvimAvailable()) {
MessageDialog dialog = new MessageDialog(
shell, "Vimplugin", null,
plugin.getMessage("gvim.not.found.dialog"),
MessageDialog.ERROR,
new String[]{IDialogConstants.OK_LABEL, IDialogConstants.CANCEL_LABEL}, 0)
{
protected void buttonPressed(int buttonId) {
super.buttonPressed(buttonId);
if (buttonId == IDialogConstants.OK_ID){
PreferenceDialog prefs = PreferencesUtil.createPreferenceDialogOn(
shell, "org.vimplugin.preferences.VimPreferences", null, null);
if (prefs != null){
prefs.open();
}
}
}
};
dialog.open();
if (!plugin.gvimAvailable()) {
throw new RuntimeException(plugin.getMessage("gvim.not.found"));
}
}
IPreferenceStore prefs = plugin.getPreferenceStore();
tabbed = prefs.getBoolean(PreferenceConstants.P_TABBED);
embedded = prefs.getBoolean(PreferenceConstants.P_EMBED);
// disabling documentListen until there is a really good reason to have,
// cause it is by far the buggest part of vim's netbeans interface.
documentListen = false; //plugin.gvimNbDocumentListenSupported();
if (embedded){
if (!plugin.gvimEmbedSupported()){
String message = plugin.getMessage(
"gvim.not.supported",
plugin.getMessage("gvim.embed.not.supported"));
throw new RuntimeException(message);
}
}
if (!plugin.gvimNbSupported()){
String message = plugin.getMessage(
"gvim.not.supported",
plugin.getMessage("gvim.nb.not.enabled"));
throw new RuntimeException(message);
}
//set some flags
alreadyClosed = false;
dirty = false;
String projectPath = null;
String filePath = null;
IEditorInput input = getEditorInput();
if (input instanceof IFileEditorInput){
selectedFile = ((IFileEditorInput)input).getFile();
IProject project = selectedFile.getProject();
IPath path = project.getRawLocation();
if(path == null){
String name = project.getName();
path = ResourcesPlugin.getWorkspace().getRoot().getRawLocation();
path = path.append(name);
}
projectPath = path.toPortableString();
filePath = selectedFile.getRawLocation().toPortableString();
if (filePath.toLowerCase().indexOf(projectPath.toLowerCase()) != -1){
filePath = filePath.substring(projectPath.length() + 1);
}
}else{
URI uri = ((IURIEditorInput)input).getURI();
filePath = uri.toString().substring("file:".length());
filePath = filePath.replaceFirst("^/([A-Za-z]:)", "$1");
}
if (filePath != null){
editorGUI = new Canvas(parent, SWT.EMBEDDED);
//create a vim instance
VimConnection vc = createVim(projectPath, filePath, parent);
viewer = new VimViewer(
bufferID, vc, editorGUI != null ? editorGUI : parent, SWT.EMBEDDED);
viewer.getTextWidget().setVisible(false);
viewer.setDocument(document);
viewer.setEditable(isEditable());
try{
Field fSourceViewer =
AbstractTextEditor.class.getDeclaredField("fSourceViewer");
fSourceViewer.setAccessible(true);
fSourceViewer.set(this, viewer);
}catch(Exception e){
logger.error("Unable to access source viewer field.", e);
}
// open eclimd view if necessary
boolean startEclimd = plugin.getPreferenceStore()
.getBoolean(PreferenceConstants.P_START_ECLIMD);
if (startEclimd){
IWorkbenchPage page = PlatformUI.getWorkbench()
.getActiveWorkbenchWindow().getActivePage();
try{
if (page != null && page.findView(ECLIMD_VIEW_ID) == null){
page.showView(ECLIMD_VIEW_ID);
}
}catch(PartInitException pie){
logger.error("Unable to open eclimd view.", pie);
}
}
// on initial open, our part listener isn't firing for some reason.
if(embedded){
plugin.getPartListener().partOpened(this);
plugin.getPartListener().partBroughtToTop(this);
plugin.getPartListener().partActivated(this);
}
}
}