Пример #1
0
  public void loadEmbeddedMacros() {
    boolean altDown = IJ.altKeyDown(); // 3.8.2009
    boolean shiftDown = IJ.shiftKeyDown(); // 18.8.2009
    if (shiftDown) {
      shiftDown = shiftDown && true;
    }
    if (IJ.debugMode) {
      IJ.log("alt=" + altDown + "   shift=" + shiftDown);
    }
    String macros_text = null;
    String macroFileName = null;
    if (OJ.isProjectOpen) {
      DataOJ data = OJ.getData();
      String project_name = data.getName();

      String directory = data.getDirectory();
      macroFileName = project_name + ".txt";
      File macros_file = new File(directory, macroFileName);
      MacroInstaller mi = new MacroInstaller();
      // mechanism to remove manually loaded project files
      macros_text = OJ.getData().getLinkedMacroText(); // 18.3.2010
      boolean externalMacroExists = macros_file.exists() && macros_file.isFile();
      boolean internalMacroExists = (macros_text != null);
      if (!internalMacroExists && !externalMacroExists) {
        // mi.install(macros_text);16.9.2010
        return;
      }
      if (externalMacroExists && internalMacroExists) {
        IJ.showMessage("Project has internal macro, so external macro is ignored");
      }
      if (externalMacroExists && !internalMacroExists) {
        String thisVersion = IJ.getVersion();
        boolean is143d = thisVersion.compareToIgnoreCase("1.43d") >= 0;
        if (is143d) {
          String oldMacroName = ij.plugin.MacroInstaller.getFileName();
          if (oldMacroName != null && oldMacroName.equalsIgnoreCase(macroFileName)) {
            oldMacroName = oldMacroName + "";
            String macro = "macro 'Dummy Tool-Cf00O8822' {}\n"; // kill old tools
            mi.install(macro);

            String dir = IJ.getDirectory("macros") + "StartupMacros.txt";
            File startup_file = new File(IJ.getDirectory("macros"), "StartupMacros.txt");
            if (startup_file.exists()) {
              IJ.showMessage("Macros in \"" + macroFileName + "\" will appear under ObjectJ menu");
              mi.installFile(dir);
            }
            mi.setFileName(""); // 15.7.2009
          }
        }

        macros_text = UtilsOJ.readStringFromFile(macros_file);
      }
      OJ.getData().setLinkedMacroText(macros_text);
      doInstall(macros_text);
    }
  }