Commands
Summary
Represents the collection of plugin commands.
Signature
| public abstract interface Commands
|
Namespace
cAlgo.API
Examples
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74 | using cAlgo.API;
namespace cAlgo.Plugins;
[Plugin(AccessRights = AccessRights.None)]
public class Test : Plugin
{
private const string CommandSvgIcon = "<svg width='800px' height='800px' viewBox='0 0 1024 1024' class='icon' version='1.1' xmlns='http://www.w3.org/2000/svg'><path d='M512 960c-92.8 0-160-200-160-448S419.2 64 512 64s160 200 160 448-67.2 448-160 448z m0-32c65.6 0 128-185.6 128-416S577.6 96 512 96s-128 185.6-128 416 62.4 416 128 416z' fill='#050D42' /><path d='M124.8 736c-48-80 92.8-238.4 307.2-363.2S852.8 208 899.2 288 806.4 526.4 592 651.2 171.2 816 124.8 736z m27.2-16c33.6 57.6 225.6 17.6 424-97.6S905.6 361.6 872 304 646.4 286.4 448 401.6 118.4 662.4 152 720z' fill='#050D42' /><path d='M899.2 736c-46.4 80-254.4 38.4-467.2-84.8S76.8 368 124.8 288s254.4-38.4 467.2 84.8S947.2 656 899.2 736z m-27.2-16c33.6-57.6-97.6-203.2-296-318.4S184 246.4 152 304 249.6 507.2 448 622.4s392 155.2 424 97.6z' fill='#050D42' /><path d='M512 592c-44.8 0-80-35.2-80-80s35.2-80 80-80 80 35.2 80 80-35.2 80-80 80zM272 312c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48zM416 880c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z m448-432c-27.2 0-48-20.8-48-48s20.8-48 48-48 48 20.8 48 48-20.8 48-48 48z' fill='#2F4BFF' /></svg>";
protected override void OnStart()
{
var addCommandWithResultButton = new Button {Text = "Add Command with Result"};
addCommandWithResultButton.Click += args =>
{
Commands.Add(CommandType.ChartContainerToolbar, OnCommandWithResultExecuted, new SvgIcon(CommandSvgIcon));
};
var addCommandThatShowWindowButton = new Button {Text = "Add Command That Show Window"};
addCommandThatShowWindowButton.Click += args =>
{
Commands.Add(CommandType.ChartContainerToolbar, OnShowWindowCommandExecuted);
};
var disableAllCommandsButton = new Button {Text = "Disable All Commands"};
disableAllCommandsButton.Click += args =>
{
foreach (var command in Commands)
{
command.IsEnabled = false;
}
};
var enableAllCommandsButton = new Button {Text = "Enable All Commands"};
enableAllCommandsButton.Click += args =>
{
foreach (var command in Commands)
{
command.IsEnabled = true;
}
};
var removeAllCommandsButton = new Button {Text = "Remove All Commands"};
removeAllCommandsButton.Click += args =>
{
foreach (var command in Commands)
{
Commands.Remove(command.Id);
}
};
var panel = new StackPanel {Orientation = Orientation.Vertical};
panel.AddChild(addCommandWithResultButton);
panel.AddChild(addCommandThatShowWindowButton);
panel.AddChild(disableAllCommandsButton);
panel.AddChild(enableAllCommandsButton);
panel.AddChild(removeAllCommandsButton);
var aspBlock = Asp.SymbolTab.AddBlock("Commands Manager");
aspBlock.Child = panel;
}
private CommandResult OnCommandWithResultExecuted(CommandArgs commandArgs)
{
Print($"Command {commandArgs.Command.Id} Executed");
var panel = new StackPanel {Orientation = Orientation.Vertical};
var firstNameTextBox = new TextBox {Text = "First Name"};
var lastNameTextBox = new TextBox {Text = "Last Name"};
var submitButton = new Button {Text = "Submit"};
submitButton.Click += args => Print("Form submitted");
panel.AddChild(firstNameTextBox);
panel.AddChild(lastNameTextBox);
panel.AddChild(submitButton);
return new CommandResult(panel);
}
private void OnShowWindowCommandExecuted(CommandArgs commandArgs)
{
Print($"Command {commandArgs.Command.Id} Executed");
var webView = new WebView();
webView.NavigateAsync("https://ctrader.com/");
var window = new Window();
window.Child = webView;
window.Show();
}
}
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62 | import clr
clr.AddReference("cAlgo.API")
from cAlgo.API import *
from System import Action, Func
class Test():
CommandSvgIcon = "<svg xmlns=\"http://www.w3.org/2000/svg\" shape-rendering=\"geometricPrecision\" text-rendering=\"geometricPrecision\" image-rendering=\"optimizeQuality\" fill-rule=\"evenodd\" clip-rule=\"evenodd\" viewBox=\"0 0 512 475.957\"><path fill-rule=\"nonzero\" d=\"M57.705 238.569V281H21.216C9.5 281 0 271.5 0 259.786c0-11.717 9.5-21.217 21.216-21.217h36.489zM244.873 0h103.279c12.371 0 23.607 5.058 31.744 13.195 8.143 8.143 13.198 19.388 13.198 31.748s-5.062 23.602-13.203 31.743c-8.14 8.14-19.383 13.203-31.739 13.203H244.873c-12.359 0-23.605-5.056-31.747-13.199-8.137-8.137-13.195-19.373-13.195-31.744 0-12.315 5.051-23.538 13.192-31.703l.081-.08C221.366 5.038 232.578 0 244.873 0zM390.17 418.092l16.693 38.83a13.188 13.188 0 011.322 5.776c0 7.321-5.937 13.259-13.259 13.259H198.667v-.053c-1.479 0-2.982-.249-4.454-.776-6.864-2.459-10.436-10.021-7.977-16.884l14.386-40.152H163.42c-12.047 0-23.006-4.936-30.956-12.882l-.051-.051c-7.946-7.949-12.882-18.909-12.882-30.956v-13.741H79.938c-6.111 0-11.679-2.5-15.703-6.525-4.017-4.016-6.522-9.573-6.522-15.7V181.332c0-6.123 2.496-11.684 6.518-15.706 4.023-4.023 9.583-6.519 15.707-6.519h39.593v-13.741c0-12.047 4.936-23.006 12.882-30.956l.051-.051c7.95-7.946 18.909-12.882 30.956-12.882h240.492c29.737 0 56.762 12.156 76.346 31.741C499.843 152.802 512 179.828 512 209.565v107.642c0 27.758-11.346 52.982-29.625 71.26-18.279 18.279-43.504 29.625-71.26 29.625H390.17z\"/><path fill=\"#2A6F80\" d=\"M375.75 418.093l-161.334.652-15.75 43.952h196.261z\"/><path fill=\"#6BAEC0\" d=\"M79.938 172.366h39.592v174.838H79.938c-4.908 0-8.967-4.034-8.967-8.966V181.332c0-4.933 4.034-8.966 8.967-8.966z\"/><path fill=\"#B2EEFD\" d=\"M163.42 114.736h233.097v290.041l.001.056H163.42c-16.846 0-30.63-13.782-30.63-30.63V145.366c0-16.847 13.784-30.63 30.63-30.63zm35.713 228.48a9.508 9.508 0 010-19.016h143.743c5.25 0 9.508 4.258 9.508 9.508 0 5.251-4.258 9.508-9.508 9.508H199.133zm0-144.96a9.508 9.508 0 010-19.015h143.743c5.25 0 9.508 4.257 9.508 9.507 0 5.251-4.258 9.508-9.508 9.508H199.133zm0 72.481a9.508 9.508 0 010-19.016h143.743c5.25 0 9.508 4.257 9.508 9.508 0 5.25-4.258 9.508-9.508 9.508H199.133zm212.174-155.712c48.735 3.805 87.434 44.871 87.434 94.54v107.642c0 48.132-39.328 87.519-87.436 87.623l.002-.053V115.025z\"/><path fill=\"#F5DAA8\" d=\"M244.873 13.267h103.279c17.423 0 31.676 14.285 31.676 31.676v.003c0 17.391-14.284 31.675-31.676 31.675H244.873c-17.391 0-31.675-14.253-31.675-31.675v-.003c0-17.423 14.253-31.676 31.675-31.676z\"/></svg>"
def on_start(self):
addCommandWithResultButton = Button()
addCommandWithResultButton.Text = "Add Command with Result"
addCommandWithResultButton.Click += lambda _: api.Commands.Add(CommandType.ChartContainerToolbar, Func[CommandArgs, CommandResult](self.on_command_with_result_executed), SvgIcon(self.CommandSvgIcon))
addCommandThatShowWindowButton = Button()
addCommandThatShowWindowButton.Text = "Add Command That Show Window"
addCommandThatShowWindowButton.Click += lambda _: api.Commands.Add(CommandType.ChartContainerToolbar, Action[CommandArgs](self.on_show_window_command_executed))
disableAllCommandsButton = Button()
disableAllCommandsButton.Text = "Disable All Commands"
disableAllCommandsButton.Click += self.on_disable_all_commands_button_click
enableAllCommandsButton = Button()
enableAllCommandsButton.Text = "Enable All Commands"
enableAllCommandsButton.Click += self.on_enable_all_commands_button_click
removeAllCommandsButton = Button()
removeAllCommandsButton.Text = "Remove All Commands"
removeAllCommandsButton.Click += self.on_remove_all_commands_button_click
panel = StackPanel()
panel.Orientation = Orientation.Vertical
panel.AddChild(addCommandWithResultButton)
panel.AddChild(addCommandThatShowWindowButton)
panel.AddChild(disableAllCommandsButton)
panel.AddChild(enableAllCommandsButton)
panel.AddChild(removeAllCommandsButton)
aspBlock = api.Asp.SymbolTab.AddBlock("Commands Manager")
aspBlock.Child = panel
def on_command_with_result_executed(self, args):
print(f"Command {args.Command.Id} Executed")
panel = StackPanel()
panel.Orientation = Orientation.Vertical
firstNameTextBox = TextBox()
firstNameTextBox.Text = "First Name"
lastNameTextBox = TextBox()
lastNameTextBox.Text = "Last Name"
submitButton = Button()
submitButton.Text = "Submit"
submitButton.Click += lambda _: print("Form submitted")
panel.AddChild(firstNameTextBox)
panel.AddChild(lastNameTextBox)
panel.AddChild(submitButton)
return CommandResult(panel)
def on_show_window_command_executed(self, args):
print(f"Command {args.Command.Id} Executed")
webView = WebView()
webView.NavigateAsync("https://ctrader.com/")
window = Window()
window.Child = webView
window.Show()
def on_disable_all_commands_button_click(self, args):
for command in api.Commands:
command.IsEnabled = False
def on_enable_all_commands_button_click(self, args):
for command in api.Commands:
command.IsEnabled = True
def on_remove_all_commands_button_click(self, args):
for command in api.Commands:
api.Commands.Remove(command.Id)
|
Methods
GetByType
Summary
Returns all commands based on type.
Signature
| public abstract Command[] GetByType(CommandType type)
|
Parameters
| Name | Type | Description |
| type | CommandType | Command Type |
Return Value
Command[]
GetById
Summary
Returns a command by Id.
Signature
| public abstract Command GetById(Guid id)
|
Parameters
| Name | Type | Description |
| id | Guid | Command Id |
Return Value
Command
Add (4)
Add (1 of 4)
Summary
Adds a new command with a callback.
Signature
| public abstract Command Add(CommandType type, Action<CommandArgs> callback)
|
Parameters
| Name | Type | Description |
| type | CommandType | Command Type |
| callback | Action | Command callback action without result. |
Return Value
Command
Add (2 of 4)
Summary
Adds a new command with a callback.
Signature
| public abstract Command Add(CommandType type, Action<CommandArgs> callback, SvgIcon icon)
|
Parameters
| Name | Type | Description |
| type | CommandType | Command Type |
| callback | Action | Command callback action without result. |
| icon | SvgIcon | Command Icon |
Return Value
Command
Add (3 of 4)
Summary
Adds a new command with a callback.
Signature
| public abstract Command Add(CommandType type, Func<CommandArgs, CommandResult> callback)
|
Parameters
| Name | Type | Description |
| type | CommandType | Command Type |
| callback | Func | Command callback that returns command result. |
Return Value
Command
Add (4 of 4)
Summary
Adds a new command with a callback and icon.
Signature
| public abstract Command Add(CommandType type, Func<CommandArgs, CommandResult> callback, SvgIcon icon)
|
Parameters
| Name | Type | Description |
| type | CommandType | Command Type |
| callback | Func | Command callback that returns command result. |
| icon | SvgIcon | Command Icon |
Return Value
Command
Remove
Summary
Removes a command by Id.
Signature
| public abstract bool Remove(Guid id)
|
Parameters
| Name | Type | Description |
| id | Guid | Command Id |
Return Value
bool
Properties
Count
Summary
Returns number of all commands.
Signature
| public abstract int Count {get;}
|
Return Value
int