Moderator: kfury77
var panel1;
var panel2;
function OnReady() {
panel1.ReDock(); //if loading layouts eleminated this panel, the redock will restore it
panel2.ReDock(); //this is important on the 1st run of the plugin
}
function ShowDock1(Sender) {
panel1.Show();
}
function HideDock1(Sender) {
panel1.Close();
}
function ShowDock2(Sender) {
panel2.Show();
}
function HideDock2(Sender) {
panel2.Close();
}
function OnButtonClick(Sender) {
Script.Message("Button was clicked");
}
//create these on script initialization so that their position can be loaded from layouts if previously saved there
panel1 = new TDockPanel("DockTest_Panel1", "dockPanelFileExplorer");
panel1.Caption = "Test Script Panel";
panel2 = new TDockPanel("DockTest_Panel2", "");
panel2.Caption = "Secondary Script Panel (Empty)";
//create some form to show in the dock
var f = new TForm(WeBuilder);
f.parent = panel1;
f.BorderStyle = bsNone;
f.Align = alClient;
f.Visible = true;
var btnOk = new TButton(f);
btnOK.Parent = f;
btnOk.SetBounds(Round(12 * Script.DpiScale), Round(12 * Script.DpiScale), Round(80 * Script.DpiScale), Round(36 * Script.DpiScale));
btnOk.Caption = "OK";
btnOk.OnClick = &OnButtonClick;
//this is required for docks
Script.ConnectSignal("ready", &OnReady);
//some test actions for toggling docks
Script.RegisterAction("Test", "Show Dock 1", "", &ShowDock1);
Script.RegisterAction("Test", "Hide Dock 1", "", &HideDock1);
Script.RegisterAction("Test", "Show Dock 2", "", &ShowDock2);
Script.RegisterAction("Test", "Hide Dock 2", "", &HideDock2);
function TestPHP(Sender) {
if (CheckIsPhpAvailable()) {
var s = "";
if (ExecutePhpScript("", Script.Path + "test.php", "", s)) {
Script.Message("php script output: " + s);
} else {
Script.Message("php script failed");
}
}
}
var scriptexec = null;
var script_loaded = false;
function JavascriptCallback(res, err) {
Script.Message(res);
}
function TestJSExecuter(Sender) {
if (scriptexec == null) {
scriptexec = Script.CreateScriptableJsExecuter("");
}
var script_file = Script.Path + "javascript.js";
if (script_loaded) {
script_file = ""; //we do not need to load the script again (it's an optimization)
}
//load script (if script_file specified) and call WeBuilder_OnData in the script
scriptexec.ExecuteJavaScriptFileRequest(script_file, "", "8", &JavascriptCallback)
script_loaded = true;
}
Script.RegisterAction("Test", "Test JavaScript", "", &TestJSExecuter);
WeBuilder_OnData = function(channel, message) {
var answer = Math.cbrt(message);
WeBuilderData.SendNative(channel, answer, '');
}
function TestDPI(Sender) {
var i = Round(Script.DpiScale * 100);
Script.Message("Dpi Scale: " + _T(i) + "%");
}
function OnAutoComplete(CodeType, ACType, Strings, AKey, &AllowPopup, ShowImages) {
var i;
if (ACType == 4) {
//add this experimental HTML tag
i = AutoComplete.AddItem(Strings, "bs3-table", "bs3-table");
AutoComplete.SetImageIndex(i, 8);
}
if (ACType == 0) {
//add this experimental AC in empty space
AllowPopup = true;
i = AutoComplete.AddItem(Strings, "bs3-table", "bs3-table");
AutoComplete.SetImageIndex(i, 8);
}
}
function OnAutoCompleteInsert(ACType, ListItemAtCursorAC, &s, &ACWordStart, &ACWordLength, &ACLineOffset, &Handled) {
var table_snippet = "<table class=\"table\">\n"
+ "<thead>\n"
+ " <tr>\n"
+ " <th></th>\n"
+ " </tr>\n"
+ "</thead>\n"
+ "<tbody>\n"
+ " <tr>\n"
+ " <td></td>\n"
+ " </tr>\n"
+ "</tbody>\n"
+ "</table>\n";
if (ACType == 0) {
if (s == "bs3-table") {
s = table_snippet;
Handled = true;
}
} else if (ACType == 4) {
if (s == "bs3-table") {
//"eat" opening "<" by moving cursor to left; another way to do it would be to not include opening "<" in snippet
ACWordStart = ACWordStart - 1;
ACWordLength = ACWordLength + 1;
s = table_snippet;
Handled = true;
}
}
}
Script.ConnectSignal("auto_complete", &OnAutoComplete);
Script.ConnectSignal("auto_complete_insert", &OnAutoCompleteInsert);
var json = new TScriptableJSON();
json.Parse(jsonstring);
var cmd = json.GetValue("cmd");
var panel1;
var edMemo;
var edRich;
var dockForm;
function OnReady() {
panel1.ReDock(); //if loading layouts eleminated this panel, the redock will restore it
//remember to restore dock visibility if dock enabled/disabled
var wasvis = Script.ReadSetting("Dock visible", "0");
if (Wasvis == "1") {
panel1.Show();
Script.WriteSetting("Dock visible", "");
}
FocusMemo();
}
function OnExit() {
//this is always a good idea with forms
delete dockForm;
}
function OnDisabled() {
//save docking panel visibility so that we know whether to forecefully show panel when plugin is re-enabled
var wasvis = "0";
if (panel1.Visible)
wasvis = "1";
Script.WriteSetting("Dock visible", wasvis);
panel1.Close();
}
function ShowDock1(Sender) {
panel1.Show();
}
function HideDock1(Sender) {
panel1.Close();
}
function OnButtonClick(Sender) {
//just testing adding text to TMemo and TRichEdit and scrolling to the end
edMemo.Lines.Add(_t(Round(Random() * 1000)));
edMemo.SelStart = Length(edMemo.Lines.Text);
edMemo.SelLength = 0;
edRich.Lines.Add(_t(Round(Random() * 1000)));
edRich.SetCaretPos(0, edRich.Lines.Count);
}
function FocusMemo() {
if (panel1.Visible)
WeBuilder.ActiveControl = edMemo;
}
function OnPanelShow(Sender) {
//at this point panel is showing but the form is not visible yet, so we cannot focus the field yet
//let's do it with a timer since it's not a critical action
Script.TimeOut(0, &FocusMemo);
}
function CreatePanelForm(panel1) {
//create some form to show in the dock
dockForm = new TForm(WeBuilder);
dockForm.parent = panel1;
dockForm.BorderStyle = bsNone;
dockForm.Align = alClient;
dockForm.Visible = true;
var btnOk = new TButton(dockForm);
btnOK.Parent = dockForm;
btnOk.SetBounds(Round(12 * Script.DpiScale), Round(12 * Script.DpiScale), Round(80 * Script.DpiScale), Round(36 * Script.DpiScale));
btnOk.Caption = "OK";
btnOk.OnClick = &OnButtonClick;
edMemo = new TMemo(dockForm);
edMemo.Parent = dockForm;
edMemo.ScrollBars = ssVertical;
edMemo.SetBounds(Round(12 * Script.DpiScale), Round(52 * Script.DpiScale), Round(80 * Script.DpiScale), Round(60 * Script.DpiScale));
edRich = new TRichEdit(dockForm);
edRich.Parent = dockForm;
edRich.ScrollBars = ssVertical;
edRich.SetBounds(Round(12 * Script.DpiScale), Round(116 * Script.DpiScale), Round(80 * Script.DpiScale), Round(60 * Script.DpiScale));
}
//create these on script initialization so that their position can be loaded from layouts if previously saved there
panel1 = new TDockPanel("DockTest_Panel1", "dockPanelFileExplorer");
panel1.Caption = "Test Script Panel";
panel1.OnShow = &OnPanelShow;
CreatePanelForm(panel1);
//this is required for docks
Script.ConnectSignal("ready", &OnReady);
Script.ConnectSignal("exit", &OnExit);
Script.ConnectSignal("disabled", &OnDisabled);
//some test actions for toggling docks
Script.RegisterAction("Test", "Show Test Dock", "", &ShowDock1);
Script.RegisterAction("Test", "Hide Test Dock", "", &HideDock1);
[Properties]
Dock visible=check
[Values]
Dock visible=
[Hints]
Dock visible=Should dock appear automatically after plugin is installed/enabled.
var jsonObj = new TScriptableJSON();
jsonObj.Parse(taskJson);
var nodes = jsonObj.GetValue("nodes");
Script.Message("Length(): " + _t(Length(nodes))); // crash
Script.Message(".length: " + _t(nodes.length)); // Blank
Script.Message(".Count: " + _t(nodes.Count)); // Blank
var jsonObj = new TScriptableJSON();
jsonObj.Parse("{ \"nodes\" : [ \"one\", \"two\", \"three\" ] }");
var i = 0;
while (true) {
try {
var node = jsonObj.GetValue("nodes[" + _t(i) + "]");
Script.Message(node);
i++;
} except {
break;
}
}
/**
* JSON parser using "htmlfile" OLE object.
* The JSON result object is extended with two custom methods, making data fully
* accessible from FastScript. Custom methods:
* getProp(key/index) to access properties by index or name
* getKeys(dummy) to get list of keys
*
* @param string jsonStr The JSON string to parse
*
* @return mixed variant or empty string if failure
*/
function ParseJson(jsonStr) {
// Create htmlfile COM object
var HFO = CreateOleObject("htmlfile"), jsonObj;
// force htmlfile to load Chakra engine
HFO.write("<meta http-equiv='x-ua-compatible' content='IE=9' />");
// Add custom method to objects
HFO.write("<script type='text/javascript'>Object.prototype.getProp=function(t){return this[t]},Object.prototype.getKeys=function(){return Object.keys(this)};</script>");
// Parse JSON string
try jsonObj = HFO.parentWindow.JSON.parse(jsonStr);
except jsonObj = ""; // JSON parse error
// Unload COM object
HFO.close();
return jsonObj;
}
Return to HTMLPad / Rapid CSS / Rapid PHP / WeBuilder Support
Users browsing this forum: No registered users and 5 guests