protected override void BeginProcessing() { if (!(Far.Api.Panel is Panel panel)) { WriteWarning("This is not a module panel."); return; } // setup the search var search = new SearchFileCommand(panel.Explorer) { XPath = XPath, XFile = XFile, Depth = Depth, Recurse = Recurse, Directory = Directory }; if (Mask != null) { search.Filter = delegate(Explorer explorer, FarFile file) { return(Far.Api.IsMaskMatch(file.Name, Mask)); }; } else if (Script != null) { search.Filter = delegate(Explorer explorer, FarFile file) { return(LanguagePrimitives.IsTrue(Script.InvokeReturnAsIs(explorer, file))); }; } // go if (Asynchronous) { search.InvokeAsync(panel); } else { search.Invoke(panel); } }
public override void Invoke(object sender, ModuleCommandEventArgs e) { // tokenize var tokens = Parser.Tokenize(e.Command, "-XPath"); // open the empty panel if (tokens.Count == 0) { (new SuperExplorer()).OpenPanel(); return; } // the module panel Panel panel = Far.Api.Panel as Panel; if (panel == null) { Far.Api.Message("This is not a module panel."); return; } // the search var search = new SearchFileCommand(panel.Explorer); // parameters var parameters = new string[] { "-Asynchronous", "-Depth", "-Directory", "-Recurse", "-XFile", "-XPath", }; // parse, setup the search bool async = false; for (int iToken = 0; iToken < tokens.Count; ++iToken) { var token = tokens[iToken]; var parameter = Parser.ResolveName(token, parameters); // mask if (parameter == null) { if (search.Filter != null) { throw new ModuleException("Invalid command line."); } var mask = token; if (!Far.Api.IsMaskValid(mask)) { throw new ModuleException("Invalid mask."); } search.Filter = delegate(Explorer explorer, FarFile file) { return(Far.Api.IsMaskMatch(file.Name, mask)); }; continue; } switch (parameter) { case "-XPath": { search.XPath = tokens[iToken + 1]; if (search.XPath.Length == 0) { throw new ModuleException("Invalid -XPath."); } iToken = tokens.Count; break; } case "-XFile": { if (++iToken >= token.Length) { throw new ModuleException("Invalid -XFile."); } search.XFile = tokens[iToken]; break; } case "-Depth": { if (++iToken >= token.Length) { throw new ModuleException("Invalid -Depth."); } search.Depth = int.Parse(tokens[iToken]); break; } case "-Directory": { search.Directory = true; break; } case "-Recurse": { search.Recurse = true; break; } case "-Asynchronous": { async = true; break; } } } // go if (async) { search.InvokeAsync(panel); } else { search.Invoke(panel); } }