03-31-2024, 01:35 PM
Another way.
Use code like in #9, but let the main script call TestScript.RunFile (which can be anywhere, eg in a class file added with /*/ c /*/).
Use code like in #9, but let the main script call TestScript.RunFile (which can be anywhere, eg in a class file added with /*/ c /*/).
// script "Example100.cs"
if (script.testing && TestScript.RunFile(("TaskA", TaskA.Thread), ("TaskB", () => TaskB.Thread(5)))) return;
var b = new wpfBuilder("Window").WinSize(400);
b.R.AddButton("Start TaskA", _ => { run.thread(TaskA.Thread); });
b.R.AddButton("Start TaskB", _ => { run.thread(() => TaskB.Thread(5)); });
b.R.AddOkCancel();
b.End();
if (!b.ShowDialog()) return;
static class TestScript {
/// <summary>
/// If a specified file is currently active in editor, executes <b>Action</b> and returns true.
/// </summary>
/// <param name="files">List of tuples <c>(string file, Action action)</c>, where <b>file</b> is the filename (without ".cs") of a class file from current project, and <b>action</b> is a callback function to call if that file is the active file in editor.</param>
public static bool RunFile(params (string file, Action action)[] files) {
var w = ScriptEditor.MainWindow();
var f = w.Elm["DOCUMENT", "document - *", "class=Scintilla"];
f.ResultGetProperty = 'n';
if (f.Exists()) {
var s = (f.ResultProperty as string)[11..];
foreach (var (n, a) in files) {
if (n.Eqi(s)) {
a();
return true;
}
}
}
return false;
}
}