Package org.vimplugin

Examples of org.vimplugin.VimPlugin


    String event = ve.getEvent();
    // workaround for not using buggy startDocumentListen support of vim's
    // netbeans protocol.
    if (event.equals("modified") ||
        (event.equals("keyCommand") && ve.getArgument(0).equals("\"modified\""))){
      VimPlugin plugin = VimPlugin.getDefault();
      VimConnection vc = ve.getConnection();
      VimServer server = vc != null ? plugin.getVimserver(vc.getVimID()) : null;
      if (server != null){
        for (VimEditor editor : server.getEditors()){
          if (editor != null && editor.getBufferID() == ve.getBufferID()){
            editor.setDirty(true);
          }
View Full Code Here


   */
  public void handleEvent(VimEvent ve) throws VimException {
    String event = ve.getEvent();

    if (event.equals("disconnect") || event.equals("killed")) {
      VimPlugin plugin = VimPlugin.getDefault();
      VimServer server = plugin.getVimserver(ve.getConnection().getVimID());

      for (final VimEditor veditor : server.getEditors()) {
        if (veditor != null) {
          if (event.equals("disconnect") ||
              veditor.getBufferID() == ve.getBufferID())
          {
            veditor.forceDispose();
          }
        }
      }

      if (event.equals("disconnect") || server.getEditors().size() == 0){
        try {
          ve.getConnection().close();
        } catch (IOException e) {
          throw new VimException("could not close the vim connection", e);
        }

        plugin.stopVimServer(server.getID());
      }
    }
  }
View Full Code Here

  @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);
      }
    }
  }
View Full Code Here

   * @param parent
   */
  private VimConnection createVim(
      String workingDir, String filePath, Composite parent)
  {
    VimPlugin plugin = VimPlugin.getDefault();

    //get bufferId
    bufferID = plugin.getNumberOfBuffers();
    plugin.setNumberOfBuffers(bufferID + 1);

    IStatus status = null;
    VimConnection vc = null;
    if (embedded) {
      try {
        vc = createEmbeddedVim(workingDir, filePath, editorGUI);
      } catch (Exception e) {
        embedded = false;
        vc = createExternalVim(workingDir, filePath, parent);

        String message = plugin.getMessage(
            e instanceof NoSuchFieldException ?
            "embed.unsupported" : "embed.fallback");
        status = new Status(IStatus.ERROR, PlatformUI.PLUGIN_ID, 0, message, e);
      }
    } else {
      vc = createExternalVim(workingDir, filePath, parent);
      String message = plugin.getMessage("gvim.external.success");
      status = new Status(IStatus.OK, PlatformUI.PLUGIN_ID, message);
    }

    if (status != null){
      editorGUI.dispose();
      editorGUI = null;
      new StatusPart(parent, status);
      // remove the "Show the Error Log View" button if the status is OK
      if (status.getSeverity() == IStatus.OK){
        for (Control c : parent.getChildren()){
          if (c instanceof Composite){
            for (Control ch : ((Composite)c).getChildren()){
              if (ch instanceof Button){
                ch.setVisible(false);
              }
            }
          }
        }
      }
    }

    plugin.getVimserver(serverID).getEditors().add(this);

    return vc;
  }
View Full Code Here

   * @param parent
   */
  private VimConnection createExternalVim(
      String workingDir, String filePath, Composite parent)
  {
    VimPlugin plugin = VimPlugin.getDefault();
    boolean first = plugin.getVimserver(VimPlugin.DEFAULT_VIMSERVER_ID) == null;
    serverID = tabbed ? plugin.getDefaultVimServer() : plugin.createVimServer();
    plugin.getVimserver(serverID).start(workingDir, filePath, tabbed, first);

    VimConnection vc = plugin.getVimserver(serverID).getVc();
    vc.command(bufferID, "editFile", "\"" + filePath + "\"");

    if (documentListen){
      vc.command(bufferID, "startDocumentListen", "");
    }else{
View Full Code Here

      f = Control.class.getField(VimEditor.win32WID);
    }

    wid = f.getLong(parent);

    VimPlugin plugin = VimPlugin.getDefault();
    serverID = plugin.createVimServer();
    plugin.getVimserver(serverID).start(workingDir, wid);

    //int h = parent.getClientArea().height;
    //int w = parent.getClientArea().width;

    VimConnection vc = plugin.getVimserver(serverID).getVc();
    //vc.command(bufferID, "setLocAndSize", h + " " + w);
    vc.command(bufferID, "editFile", "\"" + filePath + "\"");
    if (documentListen){
      vc.command(bufferID, "startDocumentListen", "");
    }else{
View Full Code Here

    if (this.alreadyClosed) {
      super.close(false);
      return;
    }

    VimPlugin plugin = VimPlugin.getDefault();

    alreadyClosed = true;
    VimServer server = plugin.getVimserver(serverID);
    if (server != null){
      server.getEditors().remove(this);

      if (save && dirty) {
        server.getVc().command(bufferID, "save", "");
        dirty = false;
        firePropertyChange(PROP_DIRTY);
      }

      if (server.getEditors().size() > 0) {
        server.getVc().command(bufferID, "close", "");
        String gvim = VimPlugin.getDefault().getPreferenceStore().getString(
            PreferenceConstants.P_GVIM);
        String[] args = new String[5];
        args[0] = gvim;
        args[1] = "--servername";
        args[2] = String.valueOf(server.getID());
        args[3] = "--remote-send";
        args[4] = "<esc>:redraw!<cr>";
        try{
          CommandExecutor.execute(args, 1000);
        }catch(Exception e){
          logger.error("Error redrawing vim after file close.", e);
        }
      } else {
        try {
          VimConnection vc = server.getVc();
          if (vc != null){
            server.getVc().function(bufferID, "saveAndExit", "");
          }
          plugin.stopVimServer(serverID);
        } catch (IOException e) {
          message(plugin.getMessage("server.stop.failed"), e);
        }
      }
    }

    super.close(false);
View Full Code Here

    setSite(site);
    setInput(input);
    try {
      document = documentProvider.createDocument(input);
    } catch (Exception e) {
      VimPlugin plugin = VimPlugin.getDefault();
      message(plugin.getMessage("document.create.failed"), e);
    }
  }
View Full Code Here

    // let the parent composite handle setting the focus on the tab first.
    if (embedded){
      parent.setFocus();
    }

    VimPlugin plugin = VimPlugin.getDefault();
    VimConnection conn = plugin.getVimserver(serverID).getVc();

    // get the current offset which "setDot" requires.
    //String offset = "0";
    try{
      String cursor = conn.function(bufferID, "getCursor", "");
      if (cursor == null){
        // the only case that i know of where this happens is if the file is
        // open somewhere else and gvim is prompting the user as to how to
        // proceed.  Exit now or the gvim prompt will be sent to the background.
        return;
      }
    }catch(IOException ioe){
      logger.error("Unable to get cursor position.", ioe);
    }
    // Brings the corresponding buffer to top
    //conn.command(bufferID, "setDot", offset);
    // Brings the vim editor window to top
    conn.command(bufferID, "raise", "");

    // to fully focus gvim, we need to simulate a mouse click.
    // Should this be optional, via a preference? There is the potential for
    // weirdness here.
    if (embedded && parent.getDisplay().getActiveShell() != null){
      boolean autoClickFocus = plugin.getPreferenceStore()
        .getBoolean(PreferenceConstants.P_FOCUS_AUTO_CLICK);
      if (autoClickFocus){
        // hack: setFocus may be called more than once, so attempt to only
        // simulate a click only on the first one.
        long now = System.currentTimeMillis();
View Full Code Here

        first = first + text + last;
      }
      document.set(first);
      setDirty(true);
    } catch(Exception e) {
      VimPlugin plugin = VimPlugin.getDefault();
      logger.error(plugin.getMessage("document.insert.failed"), e);
    }
  }
View Full Code Here

TOP

Related Classes of org.vimplugin.VimPlugin

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.