Plugin samples

Dialog Window

The plugin will display dialog window and insert Canvas tag on OK.

function DpiAdjust(x) {
    return Round(x * Script.DpiScale);
}

function InsertCanvas(Sender) {
    var f = new TForm(WeBuilder);
    f.Width = DpiAdjust(200);
    f.Height = DpiAdjust(185);
    f.BorderStyle = bsSingle; //disable dialog resizing
    f.BorderIcons = biSystemMenu; //remove maximize & minimize buttons
    f.Caption = "Canvas";

    var lbID = new TLabel(f);
    lbID.Parent = f;
    lbID.Caption = "ID:";
    lbID.SetBounds(DpiAdjust(14), DpiAdjust(19), DpiAdjust(40), DpiAdjust(15));

    var txtID = new TEdit(f);
    txtID.Parent = f;
    txtID.SetBounds(DpiAdjust(72), DpiAdjust(16), DpiAdjust(98), DpiAdjust(23));

    var lbWidth = new TLabel(f);
    lbWidth.Parent = f;
    lbWidth.Caption = "Width:";
    lbWidth.SetBounds(DpiAdjust(14), DpiAdjust(48), DpiAdjust(40), DpiAdjust(15));

    var txtWidth = new TEdit(f);
    txtWidth.Parent = f;
    txtWidth.SetBounds(DpiAdjust(72), DpiAdjust(45), DpiAdjust(98), DpiAdjust(23));

    var lbHeight = new TLabel(f);
    lbHeight.Parent = f;
    lbHeight.Caption = "Height:";
    lbHeight.SetBounds(DpiAdjust(14), DpiAdjust(77), DpiAdjust(40), DpiAdjust(15));

    var txtHeight = new TEdit(f);
    txtHeight.Parent = f;
    txtHeight.SetBounds(DpiAdjust(72), DpiAdjust(74), DpiAdjust(98), DpiAdjust(23));

    var btnOk = new TButton(f);
    btnOK.Parent = f;
    btnOk.SetBounds(DpiAdjust(14), DpiAdjust(120), DpiAdjust(75), DpiAdjust(25));
    btnOk.Caption = "OK";
    btnOk.Default = True;
    btnOK.ModalResult = mrOK;

    var btnCancel = new TButton(f);
    btnCancel.Parent = f;
    btnCancel.SetBounds(DpiAdjust(95), DpiAdjust(120), DpiAdjust(75), DpiAdjust(25));
    btnCancel.Caption = "Cancel";
    btnCancel.Cancel = True;
    btnCancel.ModalResult = mrCancel;

    var r = f.ShowModal;

    if (r == mrOK) {
        InsertCanvasTagInEditor(txtId.Text, txtWidth.Text, txtHeight.Text);
    }

    delete f;
}

function InsertCanvasTagInEditor(id, width, height) {
    s = "<canvas";
    if (id != "")
        s += " id=\"" + id + "\"";
    if (width != "")
        s += " width=\"" + width + "\"";
    if (height != "")
        s += " height=\"" + height + "\"";
    s += "></canvas>";

    Editor.SelText = s;
    var Sel = Editor.Selection;
    Sel.SelStart += Sel.SelLength;
    Sel.SelLength = 0;
    Editor.Selection = Sel;
}

Script.RegisterDocumentAction("", "Insert Canvas", "", &InsertCanvas);