public int install(String text, Menu menu) {
   this.text = text;
   macrosMenu = menu;
   install();
   int count = nShortcuts + toolCount;
   if (count == 0 && nMacros > 1) count = nMacros;
   return count;
 }
 /** Installs a macro set contained in ij.jar. */
 public void installFromIJJar(String path) {
   String text = openFromIJJar(path);
   if (text == null) return;
   if (path.endsWith("StartupMacros.txt")) {
     if (Toolbar.installStartupMacrosTools()) install(text);
     Toolbar tb = Toolbar.getInstance();
     if (tb != null) tb.installStartupTools();
   } else installSingleTool(text);
 }
  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);
    }
  }
 public int install(String text) {
   if (text == null && pgm == null) return 0;
   this.text = text;
   macrosMenu = Menus.getMacrosMenu();
   if (listener != null) macrosMenu.removeActionListener(listener);
   macrosMenu.addActionListener(this);
   listener = this;
   install();
   return nShortcuts;
 }
 public void installFile(String path) {
   String text = open(path);
   if (text == null) return;
   boolean isStartupMacros = path.contains("StartupMacros");
   if (isStartupMacros && !Toolbar.installStartupMacrosTools()) installTools = false;
   // IJ.log("installFile: "+path+" "+isStartupMacros+" "+installTools);
   install(text);
   installTools = true;
   if (isStartupMacros) {
     Toolbar tb = Toolbar.getInstance();
     if (tb != null) tb.installStartupTools();
   }
 }
 public void run(String path) {
   if (path == null || path.equals("")) path = showDialog();
   if (path == null) return;
   openingStartupMacrosInEditor = path.indexOf("StartupMacros") != -1;
   String text = open(path);
   if (text != null) {
     String functions = Interpreter.getAdditionalFunctions();
     if (functions != null) {
       if (!(text.endsWith("\n") || functions.startsWith("\n"))) text = text + "\n" + functions;
       else text = text + functions;
     }
     install(text);
   }
 }
 public void installSingleTool(String text) {
   this.text = text;
   macrosMenu = null;
   install();
 }