Installs a macro or script in the Plugins menu, or submenu, with with underscores in the file name replaced by spaces.
(String name)
| 703 | /** Installs a macro or script in the Plugins menu, or submenu, with |
| 704 | with underscores in the file name replaced by spaces. */ |
| 705 | void installMacro(String name) { |
| 706 | Menu menu = pluginsMenu; |
| 707 | String dir = null; |
| 708 | int slashIndex = name.indexOf('/'); |
| 709 | if (slashIndex>0) { |
| 710 | dir = name.substring(0, slashIndex); |
| 711 | name = name.substring(slashIndex+1, name.length()); |
| 712 | menu = getPluginsSubmenu(dir); |
| 713 | slashIndex = name.indexOf('/'); |
| 714 | if (slashIndex>0) { |
| 715 | String dir2 = name.substring(0, slashIndex); |
| 716 | name = name.substring(slashIndex+1, name.length()); |
| 717 | String menuName = "Plugins>"+dir+">"+dir2; |
| 718 | menu = getMenu(menuName); |
| 719 | dir += File.separator+dir2; |
| 720 | } |
| 721 | } |
| 722 | String command = name.replace('_',' '); |
| 723 | if (command.endsWith(".js")||command.endsWith(".py")) |
| 724 | command = command.substring(0, command.length()-3); //remove ".js" or ".py" |
| 725 | else |
| 726 | command = command.substring(0, command.length()-4); //remove ".txt", ".ijm" or ".bsh" |
| 727 | command = command.trim(); |
| 728 | if (pluginsTable.get(command)!=null) // duplicate command? |
| 729 | command = command + " Macro"; |
| 730 | MenuItem item = new MenuItem(command); |
| 731 | addOrdered(menu, item); |
| 732 | item.addActionListener(ij); |
| 733 | String path = (dir!=null?dir+File.separator:"") + name; |
| 734 | pluginsTable.put(command, "ij.plugin.Macro_Runner(\""+path+"\")"); |
| 735 | nMacros++; |
| 736 | } |
| 737 | |
| 738 | static int addPluginSeparatorIfNeeded(Menu menu) { |
| 739 | if (menuSeparators == null) |
no test coverage detected