/* Toolset Creator * IJ BAR: https://github.com/tferr/Scripts#scripts * http://imagej.nih.gov/ij/macros/toolsets/Toolset%20Creator.txt * * Creates toolsets of Built-in Tools and Menu Tools listing installed plugins. * v.13 2014.10 TF: Replace .txt with .ijm extensions in newly created files * v.12 2014.02 TF: Adds support for IJ's 1.48 expandable toolbar */ var maxTools= 10; macro "AutoRun"{ wait(15); run("Toolset Creator"); } macro "Toolset Creator" { Dialog.create("Toolset Creator"); msg = "This sequence of prompts will create a toolset grouping two types of\n" + "tools: Built-in tools (those listed at the bottom of the '>>' menu) and\n" + "Menu Tools listing commands from subfolders of ImageJ/plugins/"; Dialog.addMessage(msg); Dialog.addString(" Toolset name without extension:", getInfo("user.name") +"'s Toolset", 22); Dialog.show; name= replace(Dialog.getString, "^[.]+|[\\/:\"*?<>|]+", ""); // remove leading dots & illegal chars path= getDirectory("macros"); if (!File.exists(path)) exit("macros directory not found!\n \nToolset cannot be saved..."); path= path +"toolsets"+ File.separator; if (!File.exists(path)) File.makeDirectory(path); path= path + name + ".ijm"; if (File.exists(path)) showMessageWithCancel("Redesign previous toolset?","A file named \""+ name +".ijm\" already exists\nin ImageJ/macros/toolsets/. Overwrite?"); showStatus("Creating the toolset: An empty file will be created if you hit \"Cancel\""); for (i=0; i>' menu to switch between toolsets"); } function listPluginDirs() { plgn= getDirectory("plugins"); if (!File.exists(plgn)) return newArray(0); rawlist= getFileList(plgn); for (count=0, i=0; i< rawlist.length; i++) if (endsWith(rawlist[i], '/')) count++; if (count==0) return newArray(0); list= newArray(count); for (index=0, i=0; i< rawlist.length; i++) { if (endsWith(rawlist[i], '/')) list[index++]= substring(rawlist[i], 0, lengthOf(rawlist[i])-1); } return list; } function promptForSettings() { addMore= slot0; Dialog.create("Toolset Creator: Designing slot "+ slot+1); msg = "
For each slot you can either append 1) a Built-in Tool or 2) " + "a designed Menu Tool, a drop-down menu listing commands (i.e., executable files) " + "in subfolders of the plugins/ directory. This latter option is automatically " + "disabled if no subdirectories are found.

" + "When building menu icons, the first two characters of the folder name " + "are used if neither a symbol or a string is specified.

" + "Unfortunately, hitting Cancel or pressing Esc halfway through the design " + "will lead to an empty toolset file.
"; Dialog.addHelp(msg); Dialog.setInsets(5, 0, 0); Dialog.addMessage("Option 1) Add a Built-in Tool to slot "+ slot+1 +":"); Dialog.addChoice("Built-in tool:", bTools); if (dirs) { Dialog.setInsets(20, 0, 4); Dialog.addMessage("Option 2) Add a Menu Tool to slot "+ slot+1 + " instead:"); Dialog.addChoice(" Listing executables in:", folders); Dialog.addChoice("Icon symbol:", sIcons, sIcons[prefersymbol]); Dialog.addString("Icon text:", "", 3); Dialog.setInsets(-30, 218, 0); Dialog.addMessage("(maximum 2 characters)"); Dialog.addChoice("Icon color:", sColors, color); } if (addMore) Dialog.addCheckbox("Keep appending tools ["+ maxTools-1-slot +" slot(s) remain available]", true); Dialog.show(); btool= Dialog.getChoice; if (dirs) { folder = Dialog.getChoice; icon = Dialog.getChoice; text = Dialog.getString; color = Dialog.getChoice; } if (addMore) add= Dialog.getCheckbox; if (btool!=bTools[0]) { print(f, " macro \""+ btool +" Built-in Tool\" {}\n "); bTools= trimChosenItem(bTools, btool); } else if (dirs) { menus= true; folders = trimChosenItem(folders, folder); idx= substring(alphaCounter, slot, slot+1); mName= replace(folder, "-", ""); if (text=="" && icon==sIcons[0]) text= mName; print(f, " var "+ idx +"List= getPluginList('"+ folder +"');"); print(f, " var "+ idx +"Cmds= newMenu('"+ mName +" Menu Tool',"+ idx +"List);"); print(f, " macro '"+ mName +" Menu Tool - "+ makeIcon(text, icon, color) +"' {"); print(f, " cmd= getArgument();"); print(f, " if (cmd!='-') run(cmd);"); print(f, " }\n "); } return add; } function trimChosenItem(array, item) { trimmedarray= newArray(array.length-1); for (j=0, i=0; i>' list (e.g. drawing tools)."); print(f, " *"); print(f, " * Menu Tools:"); print(f, " * List executable files in subfolders of the ImageJ/plugins/ directory. IJ"); print(f, " * executables are all '.txt', '.class' and '.jar' files with at least one"); print(f, " * underscore in the filename and all '.ijm' and '.js' files."); print(f, " *"); print(f, " * For any Menu Tool, hold down Shift while selecting a '.ijm' or '.js' file"); print(f, " * in the dropdown list and ImageJ will open that macro or script."); print(f, " *"); print(f, " * Edit the three lines below '// Settings:' to change which files should be"); print(f, " * listed: e.g. you can exclude or rename the commands implemented by .jar"); print(f, " * files containing plugins.config instructions. N.B.: These three lines can"); print(f, " * be deleted if you have not created Menu Tools."); print(f," */\n "); print(f,"// Settings:"); print(f," var AllowedFileExtensions= newArray('class','txt','ijm','jar','js');"); print(f," var IgnoreFilenamesContaining= newArray('$');"); print(f," var ReplaceFilenames= newArray('3D Viewer:ImageJ_3D_Viewer.jar');\n \n "); } function printFoot() { print(f, "\nfunction getPluginList(subfolder) {"); print(f, " dir= getDirectory('plugins')+ subfolder +File.separator;"); print(f, " list= newArray(''+ subfolder +' not found','in the plugins directory...');"); print(f, " if (!File.exists(dir)) return list;"); print(f, " rawlist= getFileList(dir);"); print(f, " for (count=0, i=0; i< rawlist.length; i++) {"); print(f, " isMacro= endsWith(rawlist[i],'.ijm') || endsWith(rawlist[i],'.js');"); print(f, " if (indexOf(rawlist[i], '_')==-1 && !isMacro) rawlist[i]='-';"); print(f, " for (h=0; h