Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Automatically convert and include scripts when generating the exe
#14
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 /*/).
Code:
Copy      Help
// 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;
    }
}


Messages In This Thread
RE: Automatically convert and include scripts when generating the exe - by Gintaras - 03-31-2024, 01:35 PM

Forum Jump:


Users browsing this thread: 2 Guest(s)