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();
}
}
|
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