@Override
  public void dispose() {
    toplevel.kill();
    toplevel.dispose();
    super.dispose();

    if (this.equals(OcamlPlugin.getLastFocusedToplevelInstance()))
      OcamlPlugin.setLastFocusedToplevelInstance(null);
  }
示例#2
0
  public void run(IAction action) {

    IWorkbenchPage page = window.getActivePage();

    if (page == null) {
      OcamlPlugin.logWarning(GotoDefinition.class.getSimpleName() + ": page is null");
      return;
    }

    IEditorPart editorPart = page.getActiveEditor();
    if (editorPart == null) {
      OcamlPlugin.logError(GotoDefinition.class.getSimpleName() + ": editorPart is null");
      return;
    }

    if (!(editorPart instanceof OcamlEditor)) {
      OcamlPlugin.logError(
          GotoDefinition.class.getSimpleName() + ": only works on ml and mli files");
      return;
    }

    final OcamlEditor editor = (OcamlEditor) editorPart;
    ITextViewer viewer = editor.getTextViewer();
    IEditorInput editorInput = editor.getEditorInput();
    IDocument doc = editor.getDocumentProvider().getDocument(editorInput);
    Control control = (Control) editor.getAdapter(Control.class);

    if (!(control instanceof StyledText)) {
      OcamlPlugin.logError(GotoDefinition.class.getSimpleName() + ": Cannot get caret position");
      return;
    }

    final StyledText styledText = (StyledText) control;
    int offset = styledText.getCaretOffset();

    OcamlTextHover hover = new OcamlTextHover(editor);
    IRegion region = hover.getHoverRegion(viewer, offset);
    final String hoverInfo = hover.getHoverInfoOneLine(viewer, region);

    Display.getCurrent()
        .asyncExec(
            new Runnable() {
              public void run() {
                if (!hoverInfo.equals("")) editor.setStatusLineMessage(hoverInfo);
                else editor.setStatusLineMessage("");
              }
            });
  }
示例#3
0
 /** Wait for the process to end */
 public void join() {
   try {
     if (process != null) process.waitFor();
     process = null;
   } catch (InterruptedException e) {
     OcamlPlugin.logError("ocaml plugin error", e);
   }
 }
  public static void eval(String expression) {
    final OcamlToplevelView lastFocusedInstance = OcamlPlugin.getLastFocusedToplevelInstance();
    if (lastFocusedInstance == null) {
      Shell shell = Display.getDefault().getActiveShell();
      MessageDialog.openInformation(shell, "Ocaml Plugin", "Please open a toplevel view first.");
      return;
    }

    lastFocusedInstance.toplevel.eval(expression);
  }
示例#5
0
 /** For the "clean project" action : only clean, don't recompile */
 public void clean(IProject project, IProgressMonitor monitor) {
   try {
     /* We use a variable here because getProject() is final in the super-class */
     this.project = project;
     this.build(IncrementalProjectBuilder.CLEAN_BUILD, null, monitor);
   } catch (Exception e) {
     OcamlPlugin.logError("ocaml plugin error", e);
   } finally {
     this.project = null;
   }
 }
  public boolean visit(Vertex ver) {

    // Détecter les cycles pour ne pas rajouter des couches à l'infini
    if (filesBeingVisited.contains(ver)) {
      OcamlPlugin.logError(
          "error in RefreshLayersVisitor:visit:"
              + "  dependencies graph may be wrong because of a cycle");
      return false;
    }

    final List<Vertex> neededFiles = ver.getNeededFiles();
    // Rechercher le maximum des couches des noeud "parents" (ou
    // prédécesseurs : les noeud requis).
    // Par défaut on est dans la couche 0.
    int maxParentLayer = 0;
    // S'il n'y a pas de fichiers requis, alors le numéro de couche doit
    // etre mis à 0 par ce qui suit, il faut donc l'initialiser à -1.
    if (neededFiles.isEmpty()) {
      maxParentLayer = -1;
    } else {
      for (Vertex neededFile : neededFiles) {
        if (neededFile.getLayerID() > maxParentLayer) {
          maxParentLayer = neededFile.getLayerID();
        }
      }
    }
    // Si la valeur trouvée est différente de l'ancienne, propager les
    // changements.
    // + 1 car on est dans une couche supérieure à celle de son
    // prédécesseur.
    if ((maxParentLayer + 1) != ver.getLayerID()) {
      // Signaler au graphe auquel est rattaché le sommet de le changer de
      // place (et donc de changer le numéro de couche du sommet)
      ver.getGraph().moveVertex(ver, maxParentLayer + 1);

      // propager les changements :
      return true;
    }
    // Pas de changements, ne pas visiter les fichiers affectés.
    return false;
  }
  /** Initializes preferences with default values */
  @Override
  public void initializeDefaultPreferences() {
    try {

      IPreferenceStore store = OcamlPlugin.getInstance().getPreferenceStore();

      // set the default syntax coloring colors in the preference register
      store.setDefault(PreferenceConstants.P_COMMENT_COLOR, "63,127,95");
      store.setDefault(PreferenceConstants.P_STRING_COLOR, "42,0,255");
      store.setDefault(PreferenceConstants.P_KEYWORD_COLOR, "127,0,85");
      store.setDefault(PreferenceConstants.P_LETIN_COLOR, "127,0,85");
      store.setDefault(PreferenceConstants.P_FUN_COLOR, "127,0,85");
      store.setDefault(PreferenceConstants.P_CONSTANT_COLOR, "150,0,50");
      store.setDefault(PreferenceConstants.P_INTEGER_COLOR, "0,128,128");
      store.setDefault(PreferenceConstants.P_DECIMAL_COLOR, "192,64,0");
      store.setDefault(PreferenceConstants.P_CHARACTER_COLOR, "255,128,0");
      store.setDefault(PreferenceConstants.P_DOC_COMMENT_COLOR, "63,95,191");
      store.setDefault(PreferenceConstants.P_DOC_ANNOTATION_COLOR, "127,159,191");
      store.setDefault(PreferenceConstants.P_YACC_DEFINITION_COLOR, "191,63,63");
      store.setDefault(PreferenceConstants.P_PUNCTUATION_COLOR, "128,0,0");
      store.setDefault(PreferenceConstants.P_UPPERCASE_COLOR, "82,112,180");
      store.setDefault(PreferenceConstants.P_POINTED_UPPERCASE_COLOR, "162,0,185");

      // set the default syntax coloring bold attributes
      store.setDefault(PreferenceConstants.P_BOLD_CHARACTERS, false);
      store.setDefault(PreferenceConstants.P_BOLD_COMMENTS, false);
      store.setDefault(PreferenceConstants.P_BOLD_CONSTANTS, false);
      store.setDefault(PreferenceConstants.P_BOLD_KEYWORDS, true);
      store.setDefault(PreferenceConstants.P_BOLD_NUMBERS, false);
      store.setDefault(PreferenceConstants.P_BOLD_STRINGS, false);

      // set the defaults for the editor
      store.setDefault(PreferenceConstants.P_EDITOR_AUTOCOMPLETION, true);
      store.setDefault(PreferenceConstants.P_EDITOR_DISABLE_AUTOFORMAT, false);
      store.setDefault(PreferenceConstants.P_EDITOR_TABS, 2);
      store.setDefault(PreferenceConstants.P_EDITOR_SPACES_FOR_TABS, false);
      store.setDefault(PreferenceConstants.P_EDITOR_CONTINUE_COMMENTS, true);
      store.setDefault(PreferenceConstants.P_EDITOR_PIPE_AFTER_TYPE, true);
      store.setDefault(PreferenceConstants.P_EDITOR_PIPE_AFTER_WITH, true);
      store.setDefault(PreferenceConstants.P_EDITOR_PIPE_AFTER_FUN, true);
      store.setDefault(PreferenceConstants.P_EDITOR_AUTO_INDENT_CONT, true);
      store.setDefault(PreferenceConstants.P_EDITOR_KEEP_INDENT, true);
      store.setDefault(PreferenceConstants.P_EDITOR_REMOVE_PIPE, true);
      store.setDefault(PreferenceConstants.P_EDITOR_CONTINUE_PIPES, true);
      store.setDefault(PreferenceConstants.P_EDITOR_INDENT_IN, false);
      store.setDefault(PreferenceConstants.P_EDITOR_INDENT_WITH, false);
      store.setDefault(PreferenceConstants.P_EDITOR_DEDENT_SEMI_SEMI, true);
      store.setDefault(PreferenceConstants.P_EDITOR_INTELLIGENT_INDENT_START, true);
      store.setDefault(PreferenceConstants.P_EDITOR_COLON_COLON_TAB, true);
      store.setDefault(PreferenceConstants.P_EDITOR_FN_TAB, true);
      store.setDefault(PreferenceConstants.P_EDITOR_TAB_ARROW, true);
      store.setDefault(PreferenceConstants.P_EDITOR_DOUBLEQUOTES, true);

      String os = Platform.getOS();
      boolean windows = os.equals(Platform.OS_WIN32);
      store.setDefault(PreferenceConstants.P_DISABLE_UNICODE_CHARS, windows);

      store.setDefault(PreferenceConstants.P_SHOW_TYPES_IN_OUTLINE, true);
      store.setDefault(PreferenceConstants.P_SHOW_TYPES_IN_POPUPS, true);
      store.setDefault(PreferenceConstants.P_SHOW_TYPES_IN_STATUS_BAR, true);

      // set the defaults for the formatter
      store.setDefault(PreferenceConstants.P_FORMATTER_INDENT_IN, false);
      store.setDefault(PreferenceConstants.P_FORMATTER_INDENT_IN_LETS, false);
      store.setDefault(PreferenceConstants.P_FORMATTER_COMMENT_WIDTH, 78);
      store.setDefault(PreferenceConstants.P_FORMATTER_MAX_BLANK_LINES, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FORMAT_COMMENTS, true);

      store.setDefault(PreferenceConstants.P_FORMATTER_INDENT_LET_IN, false);
      store.setDefault(PreferenceConstants.P_FORMATTER_APPLICATION, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_BEGIN, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_DEF, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_ELSE, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FIRST_CATCH, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FIRST_CONSTRUCTOR, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FIRST_MATCH_CASE, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FOR, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_FUN_ARGS, 2);
      store.setDefault(PreferenceConstants.P_FORMATTER_FUNCTOR, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_IN, 0);
      store.setDefault(PreferenceConstants.P_FORMATTER_MATCH_ACTION, 2);
      store.setDefault(PreferenceConstants.P_FORMATTER_MODULE_CONSTRAINT, 2);
      store.setDefault(PreferenceConstants.P_FORMATTER_OBJECT, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_PAREN, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_RECORD, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_SIG, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_STRUCT, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_THEN, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_TRY, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_WHILE, 1);
      store.setDefault(PreferenceConstants.P_FORMATTER_WITH, 0);

      // set the default for the outline
      store.setDefault(PreferenceConstants.P_OUTLINE_LET_MINIMUM_CHARS, 0);
      store.setDefault(PreferenceConstants.P_OUTLINE_LET_IN_MINIMUM_CHARS, 0);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_CLASS, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_CLASSTYPE, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_EXCEPTION, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_EXTERNAL, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_INCLUDE, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_INITIALIZER, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_LET, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_LET_IN, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_METHOD, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_MODULE, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_MODULE_TYPE, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_OPEN, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_RECORD_CONS, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_TYPE, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_VAL, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_SHOW_VARIANT_CONS, true);

      store.setDefault(PreferenceConstants.P_OUTLINE_EXPAND_ALL, false);
      store.setDefault(PreferenceConstants.P_OUTLINE_EXPAND_MODULES, false);
      store.setDefault(PreferenceConstants.P_OUTLINE_EXPAND_CLASSES, false);

      store.setDefault(PreferenceConstants.P_OUTLINE_UNNEST_IN, true);
      store.setDefault(PreferenceConstants.P_OUTLINE_AND_BLUE, true);

      store.setDefault(PreferenceConstants.P_OUTLINE_SORT, false);

      // set the defaults for the debugger
      // checkpoints don't work on Windows
      store.setDefault(
          PreferenceConstants.P_DEBUGGER_CHECKPOINTS, OcamlPlugin.runningOnLinuxCompatibleSystem());
      store.setDefault(PreferenceConstants.P_DEBUGGER_SMALL_STEP, 1000);
      store.setDefault(PreferenceConstants.P_DEBUGGER_BIG_STEP, 10000);
      store.setDefault(PreferenceConstants.P_DEBUGGER_PROCESS_COUNT, 15);

      // spell checking comments in the editor
      store.setDefault(PreferenceConstants.P_EDITOR_SPELL_CHECKING, false);

      // Override default ocamlbuild paths by user paths
      store.setDefault(PreferenceConstants.P_OCAMLBUILD_COMPIL_PATHS_OVERRIDE, false);

      String ocamlLibPath = "";
      String ocaml = "";
      String ocamlc = "";
      String ocamlopt = "";
      String ocamldep = "";
      String ocamllex = "";
      String ocamlyacc = "";
      String ocamldoc = "";
      String ocamldebug = "";
      String camlp4 = "";
      String ocamlbuild = "";
      String make = "";
      String omake = "";

      String which = "";

      /*
       * If the operating system is Linux, then we search in the most common install
       * directories. Then, if we couldn't find the executables this way, we use the "which"
       * command (if it is available)
       */
      if (OcamlPlugin.runningOnLinuxCompatibleSystem()) {

        final String[] commonPrefixes = new String[] {"/bin", "/usr/bin", "/usr/local/bin"};

        // search in the most common install directories
        File file;
        for (String prefix : commonPrefixes) {
          if (ocaml.equals("")) {
            file = new File(prefix + "/ocaml");
            if (file.exists() && file.isFile()) ocaml = file.getPath();
          }

          if (ocamlc.equals("")) {
            file = new File(prefix + "/ocamlc.opt");
            if (file.exists() && file.isFile()) ocamlc = file.getPath();
          }

          if (ocamlc.equals("")) {
            file = new File(prefix + "/ocamlc");
            if (file.exists() && file.isFile()) ocamlc = file.getPath();
          }

          if (ocamlopt.equals("")) {
            file = new File(prefix + "/ocamlopt.opt");
            if (file.exists() && file.isFile()) ocamlopt = file.getPath();
          }

          if (ocamlopt.equals("")) {
            file = new File(prefix + "/ocamlopt");
            if (file.exists() && file.isFile()) ocamlopt = file.getPath();
          }

          if (ocamldep.equals("")) {
            file = new File(prefix + "/ocamldep.opt");
            if (file.exists() && file.isFile()) ocamldep = file.getPath();
          }

          if (ocamldep.equals("")) {
            file = new File(prefix + "/ocamldep");
            if (file.exists() && file.isFile()) ocamldep = file.getPath();
          }

          if (ocamllex.equals("")) {
            file = new File(prefix + "/ocamllex.opt");
            if (file.exists() && file.isFile()) ocamllex = file.getPath();
          }

          if (ocamllex.equals("")) {
            file = new File(prefix + "/ocamllex");
            if (file.exists() && file.isFile()) ocamllex = file.getPath();
          }

          if (ocamlyacc.equals("")) {
            file = new File(prefix + "/ocamlyacc");
            if (file.exists() && file.isFile()) ocamlyacc = file.getPath();
          }

          if (ocamldoc.equals("")) {
            file = new File(prefix + "/ocamldoc.opt");
            if (file.exists() && file.isFile()) ocamldoc = file.getPath();
          }

          if (ocamldoc.equals("")) {
            file = new File(prefix + "/ocamldoc");
            if (file.exists() && file.isFile()) ocamldoc = file.getPath();
          }

          if (ocamldebug.equals("")) {
            file = new File(prefix + "/ocamldebug");
            if (file.exists() && file.isFile()) ocamldebug = file.getPath();
          }

          if (camlp4.equals("")) {
            file = new File(prefix + "/camlp4");
            if (file.exists() && file.isFile()) camlp4 = file.getPath();
          }

          if (ocamlbuild.equals("")) {
            file = new File(prefix + "/ocamlbuild");
            if (file.exists() && file.isFile()) ocamlbuild = file.getPath();
          }

          if (make.equals("")) {
            file = new File(prefix + "/make");
            if (file.exists() && file.isFile()) make = file.getPath();
          }

          if (omake.equals("")) {
            file = new File(prefix + "/omake");
            if (file.exists() && file.isFile()) omake = file.getPath();
          }

          if (which.equals("")) {
            file = new File(prefix + "/which");
            if (file.exists() && file.isFile()) which = file.getPath();
          }
        }

        /*
         * java.io.File file = new java.io.File("/usr/lib/ocaml"); if (!file.exists() ||
         * !file.isDirectory()) { file = new java.io.File("/lib/ocaml"); if (!file.exists() ||
         * !file.isDirectory()) file = new java.io.File("/usr/local/lib/ocaml"); }
         *
         * if (file.exists() && file.isDirectory()) { for (String s : file.list()) {
         * java.io.File dir = new java.io.File(file.getAbsolutePath() + "/" + s); if
         * (dir.isDirectory()) { for (String s2 : dir.list()) { java.io.File f = new
         * java.io.File(s2); if (f.getName().equals("pervasives.mli")) { try { ocamlLibPath =
         * dir.getCanonicalPath(); } catch (IOException e) { ocamlLibPath = ""; } } } } } }
         */

        CommandRunner commandRunner;

        if (!which.equals("")) {

          if (ocamlc.equals("")) {
            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamlc.opt"}, "/");
              ocamlc = commandRunner.getStdout().trim();
              if (ocamlc.equals("")) {
                commandRunner = new CommandRunner(new String[] {which, "ocamlc"}, "/");
                ocamlc = commandRunner.getStdout().trim();
              }
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamlopt.equals("")) {
            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamlopt.opt"}, "/");
              ocamlopt = commandRunner.getStdout().trim();
              if (ocamlopt.equals("")) {
                commandRunner = new CommandRunner(new String[] {which, "ocamlopt"}, "/");
                ocamlopt = commandRunner.getStdout().trim();
              }
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocaml.equals("")) {
            try {
              commandRunner = new CommandRunner(new String[] {which, "ocaml"}, "/");
              ocaml = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamldep.equals("")) {
            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamldep"}, "/");
              ocamldep = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamllex.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamllex"}, "/");
              ocamllex = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamlyacc.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamlyacc"}, "/");
              ocamlyacc = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamldoc.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamldoc"}, "/");
              ocamldoc = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamldebug.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamldebug"}, "/");
              ocamldebug = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (ocamlbuild.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "ocamlbuild"}, "/");
              ocamlbuild = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (camlp4.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "camlp4"}, "/");
              camlp4 = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (make.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "make"}, "/");
              make = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
          if (omake.equals("")) {

            try {
              commandRunner = new CommandRunner(new String[] {which, "omake"}, "/");
              omake = commandRunner.getStdout().trim();
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
        }

        if (!ocamlc.equals("")) {
          try {
            commandRunner = new CommandRunner(new String[] {ocamlc, "-where"}, "/");
            ocamlLibPath = commandRunner.getStdout().trim();
          } catch (Throwable e) {
            OcamlPlugin.logError("ocaml plugin error", e);
          }
        }
      }
      // on Windows:
      else if (Platform.getOS().equals(Platform.OS_WIN32)) {
        /*
         * Since we can't access the register, we take the OCaml installer's default
         * install directory
         */

        String basepath = "C:\\Program Files\\Objective Caml";

        File file = new File(basepath);
        if (file.exists() && file.isDirectory()) {
          ocamlLibPath = basepath + "\\lib";
          ocaml = basepath + "\\bin\\ocaml.exe";
          ocamlc = basepath + "\\bin\\ocamlc.exe";
          ocamlopt = basepath + "\\bin\\ocamlopt.exe";
          ocamldep = basepath + "\\bin\\ocamldep.exe";
          ocamllex = basepath + "\\bin\\ocamllex.exe";
          ocamlyacc = basepath + "\\bin\\ocamlyacc.exe";
          ocamldoc = basepath + "\\bin\\ocamldoc.exe";
          camlp4 = basepath + "\\bin\\camlp4.exe";
          ocamlbuild = basepath + "\\bin\\ocamlbuild.exe";
          ocamldebug = basepath + "\\bin\\ocamldebug.exe";
        }

        file = new File("C:\\Program Files\\OMake\\bin\\omake.exe");
        if (file.exists() && file.isFile()) omake = file.getAbsolutePath();
      }

      // Save all the preferences in the preferences register
      store.setDefault(PreferenceConstants.P_LIB_PATH, ocamlLibPath);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAML, ocaml);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLC, ocamlc);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLOPT, ocamlopt);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLDEP, ocamldep);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLLEX, ocamllex);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLYACC, ocamlyacc);
      store.setDefault(PreferenceConstants.P_PATH_CAMLP4, camlp4);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLDOC, ocamldoc);
      store.setDefault(PreferenceConstants.P_COMPIL_PATH_OCAMLDEBUG, ocamldebug);
      store.setDefault(PreferenceConstants.P_PATH_OCAMLBUILD, ocamlbuild);
      store.setDefault(PreferenceConstants.P_MAKE_PATH, make);
      store.setDefault(PreferenceConstants.P_OMAKE_PATH, omake);

    } catch (Throwable e) {
      OcamlPlugin.logError("error in preference initializer", e);
    }
  }
  @Override
  public void createPartControl(Composite parent) {

    this.setPartName("Ocaml Toplevel");

    composite = new Composite(parent, SWT.BORDER);
    composite.addControlListener(
        new ControlAdapter() {
          @Override
          public void controlResized(ControlEvent e) {
            resized();
          }
        });

    userText = new StyledText(this.composite, SWT.V_SCROLL);
    userText.setWordWrap(true);
    resultText = new StyledText(this.composite, SWT.V_SCROLL);
    resultText.setWordWrap(true);

    sash = new Sash(composite, SWT.HORIZONTAL | SWT.SMOOTH);

    sash.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            sash.setBounds(e.x, e.y, e.width, e.height);
            layout();
          }
        });

    Color c =
        Display.findDisplay(Thread.currentThread()).getSystemColor(SWT.COLOR_WIDGET_NORMAL_SHADOW);
    sash.setBackground(c);

    toplevel = new Toplevel(this, userText, resultText);

    IActionBars actionBars = this.getViewSite().getActionBars();
    IMenuManager dropDownMenu = actionBars.getMenuManager();
    IToolBarManager toolBarManager = actionBars.getToolBarManager();

    ImageDescriptor iconAdd = ImageRepository.getImageDescriptor(ImageRepository.ICON_ADD);
    Action actionNewToplevel =
        new Action("New toplevel", iconAdd) {
          @Override
          public void run() {
            try {
              IWorkbenchPage page =
                  PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage();
              OcamlToplevelView.this.secondaryId = "ocamltoplevelview" + new Random().nextInt();
              page.showView(ID, OcamlToplevelView.this.secondaryId, IWorkbenchPage.VIEW_ACTIVATE);
            } catch (Exception e) {
              OcamlPlugin.logError("ocaml plugin error", e);
            }
          }
        };

    ImageDescriptor iconReset = ImageRepository.getImageDescriptor(ImageRepository.ICON_RESET);
    Action actionReset =
        new Action("Reset", iconReset) {
          @Override
          public void run() {
            toplevel.reset();
          }
        };

    ImageDescriptor iconInterrupt =
        ImageRepository.getImageDescriptor(ImageRepository.ICON_INTERRUPT);
    Action actionBreak =
        new Action("Interrupt", iconInterrupt) {
          @Override
          public void run() {
            toplevel.interrupt();
          }
        };

    ImageDescriptor iconClear = ImageRepository.getImageDescriptor(ImageRepository.ICON_CLEAR);
    Action actionClear =
        new Action("Clear", iconClear) {
          @Override
          public void run() {
            toplevel.clear();
          }
        };

    ImageDescriptor iconHelp = ImageRepository.getImageDescriptor(ImageRepository.ICON_HELP);
    Action actionHelp =
        new Action("Help", iconHelp) {
          @Override
          public void run() {
            toplevel.help();
          }
        };

    Action actionUseTopfind =
        new Action("Use Topfind") {
          @Override
          public void run() {
            toplevel.eval("#use \"topfind\";;");
          }
        };

    dropDownMenu.add(actionUseTopfind);

    toolBarManager.add(actionBreak);
    toolBarManager.add(actionClear);
    toolBarManager.add(actionReset);
    toolBarManager.add(actionNewToplevel);
    toolBarManager.add(actionHelp);

    if (bStartWhenCreated) toplevel.start();

    OcamlPlugin.setLastFocusedToplevelInstance(this);
  }
 @Override
 public void setFocus() {
   OcamlPlugin.setLastFocusedToplevelInstance(this);
   userText.setFocus();
 }
示例#10
0
 @Override
 public void init(IViewSite site) throws PartInitException {
   OcamlPlugin.setLastFocusedToplevelInstance(this);
   super.init(site);
 }
 /**
  * Dépiler un sommet de la pile des sommets en cours de visite une fois le sommet (et ses
  * dépendances) complètement visité.
  */
 public void popVertex(Vertex v) {
   if (!filesBeingVisited.remove(v)) {
     OcamlPlugin.logError("error in RefreshLayersVisitor:" + "popVertex: vertex not found");
   }
 }
示例#12
0
  @Override
  protected IProject[] build(
      final int kind, @SuppressWarnings("unchecked") final Map args, final IProgressMonitor monitor)
      throws CoreException {

    // don't start two builds simultaneously
    synchronized (buildMutex) {
      if (building) {
        // System.out.println("already building: aborting");
        return null;
      } else building = true;
    }

    final IProgressMonitor buildMonitor;
    if (monitor == null) buildMonitor = new NullProgressMonitor();
    else buildMonitor = monitor;

    try {
      if (kind == CLEAN_BUILD) buildMonitor.beginTask("Cleaning Project", IProgressMonitor.UNKNOWN);
      else buildMonitor.beginTask("Making Project", IProgressMonitor.UNKNOWN);

      final IProject project;
      if (this.project == null) project = this.getProject();
      else project = this.project;

      if (kind == IncrementalProjectBuilder.AUTO_BUILD) return null;

      String makeCmd = "";
      MakeUtility makeUtility = new MakeUtility(project);
      switch (makeUtility.getVariant()) {
        case GNU_MAKE:
          makeCmd = OcamlPlugin.getMakeFullPath();
          break;
        case OMAKE:
          makeCmd = OcamlPlugin.getOMakeFullPath();
          break;
      }
      makeCmd = makeCmd.trim();
      if (makeCmd.trim().equals("")) {
        OcamlPlugin.logError(
            "The "
                + MakeUtility.getName(makeUtility.getVariant())
                + " command couldn't be found. Please configure its path in the preferences.");
        return null;
      }

      String path = project.getLocation().toOSString();

      ArrayList<String> commandLine = new ArrayList<String>();
      commandLine.add(makeCmd);
      switch (makeUtility.getVariant()) {
        case OMAKE:
          commandLine.add("--no--progress");
          commandLine.add("-w");
          break;
        case GNU_MAKE:
          commandLine.add("-C" + path);
          break;
      }

      for (String option : makeUtility.getOptions()) commandLine.add(option);

      MakefileTargets makefileTargets = new MakefileTargets(project);
      String[] targets = null;
      if (kind == CLEAN_BUILD) targets = makefileTargets.getCleanTargets();
      else targets = makefileTargets.getTargets();

      for (String target : targets) commandLine.add(target);

      String[] strCommandLine = commandLine.toArray(new String[commandLine.size()]);

      final StringBuilder output = new StringBuilder();

      IExecEvents events =
          new IExecEvents() {

            public void processNewInput(final String input) {
              output.append(input);
              Display.getDefault()
                  .asyncExec(
                      new Runnable() {
                        public void run() {
                          OcamlCompilerOutput outputView = OcamlCompilerOutput.get();
                          if (outputView != null) outputView.append(input);
                        }
                      });
            }

            // not used, because the error output is merged with the standard output
            public void processNewError(String error) {}

            public void processEnded(int exitValue) {
              if (kind == CLEAN_BUILD) cleanFinished(project);
              else makefileFinished(output.toString(), project);
            }
          };

      // clean the output from the last compilation
      /*
       * Display.getDefault().syncExec(new Runnable() { public void run() { OcamlCompilerOutput output =
       * OcamlCompilerOutput.get(); if (output != null) output.clear(); } });
       */

      File dir = project.getLocation().toFile();
      ExecHelper execHelper = null;
      try {
        // use OS-inherited environment for the make process
        execHelper = ExecHelper.execMerge(events, strCommandLine, System.getenv(), dir);
      } catch (Exception e) {
        OcamlPlugin.logError("ocaml plugin error", e);
        return null;
      }

      /*
       * Check at regular intervals whether the user canceled the build. When that happens, we kill the
       * "make" process.
       */
      while (execHelper.isRunning()) {
        if (buildMonitor.isCanceled()) execHelper.kill();
        try {
          buildMonitor.worked(1);
          Thread.sleep(100);
        } catch (InterruptedException e) {
        }
      }

      execHelper.join();

      return null;
    } finally {
      buildMonitor.worked(1);
      buildMonitor.done();
      building = false;
    }
  }
示例#13
0
 public OutlinePreferencePage() {
   super(FieldEditorPreferencePage.GRID);
   this.setPreferenceStore(OcamlPlugin.getInstance().getPreferenceStore());
   this.setDescription("Preferences for the outline");
 }