MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / installMacro

Method installMacro

ij/src/main/java/ij/Menus.java:705–736  ·  view source on GitHub ↗

Installs a macro or script in the Plugins menu, or submenu, with with underscores in the file name replaced by spaces.

(String name)

Source from the content-addressed store, hash-verified

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)

Callers 1

installMacrosMethod · 0.95

Calls 11

getPluginsSubmenuMethod · 0.95
getMenuMethod · 0.95
addOrderedMethod · 0.95
substringMethod · 0.80
addActionListenerMethod · 0.80
lengthMethod · 0.65
indexOfMethod · 0.45
replaceMethod · 0.45
trimMethod · 0.45
getMethod · 0.45
putMethod · 0.45

Tested by

no test coverage detected