All Downloads are FREE. Search and download functionalities are using the official Maven repository.

macros.Search.txt Maven / Gradle / Ivy

Go to download

ImageJ is an open source Java image processing program inspired by NIH Image for the Macintosh.

There is a newer version: 1.54m
Show newest version
// "Search"
// This macro searches for text in files contained in a directory.
// TF, 2011.02 Added support for scripts; Recordable.

  str = "";
  contents = true;
  ignore = false;
  search = "Macros";
  firstLine = true;
  arg = getArgument;
  if (arg!="") {
      args = split(arg, "|");
      if (args.length==4) {
          str = args[0];
          contents = parseInt(args[1]);
          ignore = parseInt(args[2]);
          search = args[3];
       }
  }
  extensions = newArray(".java", ".txt", ".ijm", ".js", ".py", ".rb", ".clj", ".bsh", ".html");
  IJdir = getDirectory("imagej");

  Dialog.create("Search");
  Dialog.addString("_", str, 20);
  items = newArray("Macros", "Scripts", "Java", "ImageJ folder", "Choose...");
  Dialog.setInsets(2,20,0);
  Dialog.addRadioButtonGroup("Search:", items, 5, 1, search);
  Dialog.setInsets(0, 20, 0);
  Dialog.addCheckbox("Search_contents", contents);
  Dialog.addCheckbox("Ignore case", ignore);
  Dialog.setInsets(10, 0, 0);
  Dialog.addMessage("In the Log window, to open a file,\ndouble-click on its file path.");
  Dialog.show();
  str = Dialog.getString();
  contents = Dialog.getCheckbox();
  ignore = Dialog.getCheckbox();
  search = Dialog.getRadioButton();
  if (str=="")
     exit("Search string is empty");

  sourceExists = File.exists(IJdir+"source");
  searchNames = false;
  dir1=""; dir2=""; dir3="";
  if (search=="Scripts") {
      dir1 = getDirectory("macros");   
      dir2 = getDirectory("plugins");     
      dir3 = IJdir+"scripts/";
      extensions = newArray(".js", ".py", ".rb", ".clj", ".bsh");
  } else if (search=="Java") {
      dir1 = getDirectory("plugins"); 
      if (sourceExists)
         dir2 = IJdir+"source"+"/";
      extensions = newArray(".java");
  } else if (search=="ImageJ folder") {
      dir1 = getDirectory("imagej");
      searchNames = true;
  } else if (search=="Choose...") {
      dir1 = getDirectory("Choose a Directory");
      searchNames = true;
  } else {
      dir1 = getDirectory("macros");   
      dir2 = getDirectory("plugins");     
      extensions = newArray(".txt", ".ijm");
  }
  if (ignore)
      str = toLowerCase(str);
  count = 0;
  if (dir1!="") find(dir1);
  if (dir2!="") find(dir2);
  if (dir3!="") find(dir3);
  if (indexOf(str, "|")==-1)
      return ""+str+"|"+contents+"|"+ignore+"|"+search;
  exit; 

  function find(dir) {
      list = getFileList(dir);
      for (i=0; i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy