Permalink
Browse files

added ISourceViewer implementation for the vimplugin editor

  • Loading branch information...
1 parent 105b585 commit ebaf7ec297dd7adb50a8737941f35765cf14391f @ervandew committed Jul 20, 2009
View
2 NOTICE
@@ -35,6 +35,8 @@ vimplugin (http://vimplugin.org) with changes including, but not limited to:
- Fixed cursor location restoration when re-focusing gvim editor.
- Fixed insert/remove text on internal document to handle disjunct between
vim byte offsets and java character offsets.
+ - Added an ISourceViewer implementation allowing more eclipse features to act
+ upon the gvim editor.
- Added support for feeding keys from gvim to eclipse to support user mapped
eclipse shortcuts inside of gvim.
- Fixed possible key binding conflicts between eclipse and gvim when an
@@ -48,6 +48,7 @@
import org.eclipse.swt.widgets.Canvas;
import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
@@ -64,6 +65,7 @@
import org.eclipse.ui.editors.text.TextEditor;
+import org.eclipse.ui.texteditor.AbstractTextEditor;
import org.eclipse.ui.texteditor.IDocumentProvider;
import org.vimplugin.DisplayUtils;
@@ -85,22 +87,19 @@
"org.eclim.eclipse.headed.EclimdView";
/** ID of the VimServer. */
- protected int serverID;
+ private int serverID;
/** Buffer ID in Vim instance. */
private int bufferID;
- protected Canvas editorGUI;
-
- protected IDocument document;
-
- protected VimDocumentProvider documentProvider;
-
- protected boolean dirty;
-
- protected boolean alreadyClosed = false;
-
+ private Canvas editorGUI;
private IFile selectedFile;
+ private IDocument document;
+ private VimViewer viewer;
+ private VimDocumentProvider documentProvider;
+
+ private boolean dirty;
+ private boolean alreadyClosed = false;
private Composite parent;
@@ -139,11 +138,11 @@ public VimEditor() {
@Override
public void createPartControl(Composite parent) {
this.parent = parent;
+ this.shell = parent.getShell();
VimPlugin plugin = VimPlugin.getDefault();
if (!plugin.gvimAvailable()) {
- shell = parent.getShell();
MessageDialog dialog = new MessageDialog(
shell, "Vimplugin", null,
plugin.getMessage("gvim.not.found.dialog"),
@@ -189,11 +188,6 @@ protected void buttonPressed(int buttonId) {
alreadyClosed = false;
dirty = false;
- // nice background (only needed for external)
- editorGUI = new Canvas(parent, SWT.EMBEDDED);
- Color color = new Color(parent.getDisplay(), new RGB(0x10, 0x10, 0x10));
- editorGUI.setBackground(color);
-
String projectPath = null;
String filePath = null;
IEditorInput input = getEditorInput();
@@ -220,6 +214,11 @@ protected void buttonPressed(int buttonId) {
}
if (filePath != null){
+ // nice background (only needed for external)
+ editorGUI = new Canvas(parent, SWT.EMBEDDED);
+ Color color = new Color(parent.getDisplay(), new RGB(0x10, 0x10, 0x10));
+ editorGUI.setBackground(color);
+
//create a vim instance
createVim(projectPath, editorGUI);
@@ -233,6 +232,18 @@ protected void buttonPressed(int buttonId) {
vc.command(bufferID, "editFile", "\"" + filePath + "\"");
vc.command(bufferID, "startDocumentListen", "");
+ viewer = new VimViewer(bufferID, vc, editorGUI, SWT.EMBEDDED);
+ 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);
@@ -305,15 +316,13 @@ private void createEmbeddedVim(String workingDir, Composite parent)
{
long wid = 0;
- Class<?> c = parent.getClass();
Field f = null;
-
if (Platform.getOS().equals(Platform.OS_LINUX)) {
- f = c.getField(VimEditor.linuxWID);
+ f = Composite.class.getField(VimEditor.linuxWID);
} else if (Platform.getOS().equals(Platform.OS_WIN32)) {
- f = c.getField(VimEditor.win32WID);
+ f = Control.class.getField(VimEditor.win32WID);
} else {
- f = c.getField(VimEditor.win32WID);
+ f = Control.class.getField(VimEditor.win32WID);
}
wid = f.getLong(parent);
@@ -358,6 +367,11 @@ public void dispose() {
// needed?
close(true);
+ if (viewer != null) {
+ viewer.getTextWidget().dispose();
+ viewer = null;
+ }
+
if (editorGUI != null) {
editorGUI.dispose();
editorGUI = null;
@@ -534,7 +548,7 @@ public void setFocus() {
VimConnection conn = plugin.getVimserver(serverID).getVc();
// get the current offset which "setDot" requires.
- String offset = "0";
+ //String offset = "0";
try{
String cursor = conn.function(bufferID, "getCursor", "");
if (cursor == null){
@@ -547,7 +561,7 @@ public void setFocus() {
logger.error("Unable to get cursor position.", ioe);
}
// Brings the corresponding buffer to top
- conn.command(bufferID, "setDot", offset);
+ //conn.command(bufferID, "setDot", offset);
// Brings the vim editor window to top
conn.command(bufferID, "raise", "");
@@ -744,8 +758,4 @@ private void message(String message, Throwable e) {
MessageDialog.openError(shell, "Vimplugin", message + stacktrace);
}
-
- private void message(String s) {
- MessageDialog.openError(shell, "Vimplugin", s);
- }
}
@@ -0,0 +1,38 @@
+/**
+ * Copyright (C) 2005 - 2009 Eric Van Dewoestine
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+package org.vimplugin.editors;
+
+import org.eclipse.swt.custom.StyledText;
+
+import org.eclipse.swt.widgets.Composite;
+
+/**
+ * StyledText implementation for gvim.
+ *
+ * @author Eric Van Dewoestine
+ */
+public class VimText
+ extends StyledText
+{
+ /**
+ * @see StyledText#StyledText(Composite,int)
+ */
+ public VimText(Composite parent, int style)
+ {
+ super(parent, style);
+ }
+}
Oops, something went wrong.

0 comments on commit ebaf7ec

Please sign in to comment.