Skip to content

Commit 490cbbc

Browse files
committed
Version 1.0.2.0
1 parent 683b977 commit 490cbbc

File tree

42 files changed

+646
-257
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+646
-257
lines changed

Docs/DialogService.md

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# DialogServices
2+
3+
The **DialogService** contains some static helper for you to present dialogs
4+
5+
## ListDialog
6+
7+
The ```ListDialog``` is an easy way to let the user select items from a list of strings.
8+
9+
https://github.com/PowerCommands/PowerCommands2022/assets/102176789/10945ee0-947d-4af3-aef5-27ad8ff6be4b
10+
11+
```
12+
[PowerCommandDesign( description: "A demo of the DialogService.List.",
13+
example: "list")]
14+
public class ListCommand : CommandBase<PowerCommandsConfiguration>
15+
{
16+
public ListCommand(string identifier, PowerCommandsConfiguration configuration) : base(identifier, configuration) { }
17+
18+
public override RunResult Run()
19+
{
20+
var selectedItems = DialogService.ListDialog("Which teams participated in the Stanley Cup final season 2022/23?", new() { "New York Rangers", "Colorado Avalanche", "Vegas Knights", "Pittsburgh Penguins", "Florida Panthers", "Detroit Red Wings", "Toronto Maple Leafs" });
21+
WriteHeadLine("You selected");
22+
foreach (var item in selectedItems) WriteLine(item);
23+
if (selectedItems.Count == 2 && selectedItems.Any(t => t == "Vegas Knights") && selectedItems.Any(t => t == "Florida Panthers"))
24+
{
25+
WriteSuccessLine("\nYour absolutely right, and Vegas Knights won the Stanley Cup title!");
26+
}
27+
else
28+
{
29+
WriteFailureLine("\nIncorrect, the participants in the final was Vegas Knights Vs Florida Panthers and Vegas won the Stanley Cup title!");
30+
}
31+
return Ok();
32+
}
33+
}
34+
```
35+
## SecretPromptDialog
36+
The ```SecretPromptDialog``` is a helper dialog to collect password, tokens or other sensitive stuff. The input is masked, the user must confirm the secret, and the secret is not logged to the log file.
37+
It is very simple to use, just like this.
38+
```
39+
var password = DialogService.SecretPromptDialog("Enter secret:");
40+
```
41+
42+
## QuestionAnswerDialog and YesNoDialog
43+
This dialog either prompt a question and returns the answer as an string or with the ```YesNoDialog``` prompts a question and returns a bool.
44+
45+
46+
47+
48+
Read more about:
49+
50+
[Design your Command](Design_command.md)
51+
52+
[Input](Input.md)
53+
54+
[PowerCommands Attribute](PowerCommandAttribute.md)
55+
56+
[Back to start](https://github.com/PowerCommands/PowerCommands2022/blob/main/Docs/README.md)

Docs/Input.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ The path is a special value if your command only should have an input that is a
5656

5757
Read more about:
5858

59+
[Dialog services](DialogService.md)
60+
5961
[Design your Command](Design_command.md)
6062

6163
[Options](Options.md)

Docs/images/VS_solution_option.png

19.2 KB
Loading

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ https://github.com/PowerCommands/PowerCommands2022/assets/102176789/d8ad92f0-93a
3535

3636
[Handling the Input](Docs/Input.md)
3737

38+
[Dialog services](Docs/DialogService.md)
39+
40+
https://github.com/PowerCommands/PowerCommands2022/assets/102176789/10945ee0-947d-4af3-aef5-27ad8ff6be4b
41+
3842
[Using Options](Docs/Options.md)
3943

4044
[Simple automated test](Docs/Test.md)

Templates/PowerCommands.zip

3.22 KB
Binary file not shown.

Templates/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,19 @@ Copy the .zip file into the user project template directory. By default, this di
88

99
Open Visual Studio and write Power in the searchbox, you should find the PowerCommand template.
1010

11+
I recommend you to use the option ```Place solution in the same directory``` some experimental features for update and create commands using a template the Core depends on that.
12+
13+
![Alt text](../Docs/images/VS_solution_option.png?raw=true "Command Base")
14+
1115

1216
# What is new?
1317

18+
**Released 2023-06-30**
19+
- Toolbar functionality moved to own ```ToolbarService``` and reworked it completely, not using timers anymore that caused problems, so it is now a more stable feature (but still a bit experimental).
20+
- Added PasswordPromptDialog to the ```DialogService```.
21+
- New List feature, display a list which selectable items.
22+
- ```DirCommand``` is now a Core command instead of a Demo command.
23+
- It is now possible to move the cursor up and down with ```CTRL``` + (```⬆️``` or ⬇️).
1424
## Version 1.0.1.0
1525
**Released 2023-06-20**
1626
### Toolbar styled Commands
Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
using PainKiller.PowerCommands.ReadLine;
22
using PainKiller.PowerCommands.ReadLine.Events;
3-
using System.Timers;
43

54
namespace $safeprojectname$.BaseClasses
65
{
76
public abstract class CommandWithToolbarBase<TConfig> : CommandBase<TConfig> where TConfig : new()
87
{
98
protected string LatestHighlightedCommand = string.Empty;
10-
private readonly System.Timers.Timer _overflowTimer;
9+
10+
private bool _toolbarIsInitialized;
1111
private readonly bool _autoShowToolbar;
12-
private readonly ConsoleColor[]? _colors;
12+
private ConsoleColor[]? _colors;
1313
protected List<string> Labels = new();
1414
protected PowerCommandsToolbarAttribute? ToolbarAttribute;
1515
protected CommandWithToolbarBase(string identifier, TConfig configuration, bool autoShowToolbar = true, ConsoleColor[]? colors = null) : base(identifier, configuration)
@@ -18,47 +18,41 @@ protected CommandWithToolbarBase(string identifier, TConfig configuration, bool
1818
_colors = colors;
1919
ReadLineService.CommandHighlighted += ReadLineService_CommandHighlighted;
2020
ToolbarAttribute = this.GetToolbarAttribute();
21-
var overflowMilliseconds = ToolbarAttribute?.Timer ?? 500;
22-
_overflowTimer = new System.Timers.Timer(Math.Clamp(overflowMilliseconds, 500, 5000));
23-
ReadLineService.CmdLineTextChanged += ReadLineService_CmdLineTextChanged;
24-
}
25-
protected virtual void ReadLineService_CmdLineTextChanged(object? sender, CmdLineTextChangedArgs e)
26-
{
27-
if (!e.CmdText.StartsWith(Identifier) && LatestHighlightedCommand == Identifier) ClearToolbar();
2821
}
22+
2923
public override RunResult Run()
3024
{
31-
ClearToolbar();
3225
return Ok();
3326
}
34-
protected void ReadLineService_CommandHighlighted(object? sender, CommandHighlightedArgs e)
27+
28+
public override void RunCompleted()
29+
{
30+
ToolbarService.ClearToolbar();
31+
base.RunCompleted();
32+
}
33+
34+
protected virtual void ReadLineService_CommandHighlighted(object? sender, CommandHighlightedArgs e)
3535
{
3636
LatestHighlightedCommand = e.CommandName;
3737
if (e.CommandName != Identifier) return;
38-
if (_autoShowToolbar)
39-
{
40-
_overflowTimer.Elapsed += InitializeToolbar;
41-
_overflowTimer.AutoReset = true;
42-
_overflowTimer.Enabled = true;
43-
}
38+
if (_autoShowToolbar) DrawToolbar();
4439
}
45-
private void InitializeToolbar(object? sender, ElapsedEventArgs e)
40+
private void InitializeToolbar()
4641
{
4742
var attribute = this.GetPowerCommandAttribute();
4843
var suggestions = ToolbarAttribute == null ? Labels.ToList() : ToolbarAttribute.Labels.Split(ConfigurationGlobals.ArraySplitter).ToList();
4944
if (suggestions.Count == 0) suggestions.AddRange(attribute.Suggestions.Split(ConfigurationGlobals.ArraySplitter));
5045
if (suggestions.Count == 0) return;
5146
Labels.Clear();
5247
Labels.AddRange(suggestions);
53-
DrawToolbar();
48+
var attributeToolbar = this.GetToolbarAttribute();
49+
if (attributeToolbar != null) _colors = attributeToolbar.Colors;
50+
_toolbarIsInitialized = true;
5451
}
5552
protected void DrawToolbar()
5653
{
57-
DialogService.DrawToolbar(Labels.ToArray(), _colors);
58-
59-
_overflowTimer.Elapsed -= InitializeToolbar;
60-
_overflowTimer.Stop();
54+
if(!_toolbarIsInitialized) InitializeToolbar();
55+
ToolbarService.DrawToolbar(Labels.ToArray(), _colors);
6156
}
62-
protected void ClearToolbar() => DialogService.ClearToolbar(Labels.ToArray());
6357
}
6458
}

src/PainKiller.PowerCommands/PainKiller.PowerCommands.MyExampleCommands/Commands/DirCommand.cs renamed to Templates/src/Core/PainKiller.PowerCommands.Core/COMMANDS/DirCommand.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
using PainKiller.PowerCommands.Core.Commands;
2-
3-
namespace PainKiller.PowerCommands.MyExampleCommands.Commands;
1+
namespace $safeprojectname$.Commands;
42

53
[PowerCommandDesign(description: "List the content of the working directory or this applications app directory, with the option to open the directory with the File explorer ",
64
options: "open|app",

Templates/src/Core/PainKiller.PowerCommands.Core/COMMANDS/SecretCommand.cs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -75,17 +75,9 @@ private RunResult Get()
7575
private RunResult Create()
7676
{
7777
var name = Input.SingleQuote;
78-
Console.Write("Enter secret: ");
79-
var password = PasswordPromptService.Service.ReadPassword();
80-
Console.WriteLine();
81-
Console.Write("Confirm secret: ");
82-
var passwordConfirm = PasswordPromptService.Service.ReadPassword();
83-
84-
if (password != passwordConfirm)
85-
{
86-
Console.WriteLine();
87-
return BadParameterError("Passwords do not match");
88-
}
78+
var password = DialogService.SecretPromptDialog("Enter secret:");
79+
if (string.IsNullOrEmpty(password)) return BadParameterError("Passwords do not match");
80+
8981
var secret = new SecretItemConfiguration { Name = name };
9082
var val = SecretService.Service.SetSecret(name, password, secret.Options, EncryptionService.Service.EncryptString);
9183

Templates/src/Core/PainKiller.PowerCommands.Core/MyTemplate.vstemplate

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
</TemplateData>
1717
<TemplateContent>
1818
<Project TargetFileName="PainKiller.PowerCommands.Core.csproj" File="PainKiller.PowerCommands.Core.csproj" ReplaceParameters="true">
19-
<Folder Name="Properties" TargetFolderName="Properties" />
2019
<Folder Name="BaseClasses" TargetFolderName="BaseClasses">
2120
<ProjectItem ReplaceParameters="true" TargetFileName="CommandBase.cs">CommandBase.cs</ProjectItem>
2221
<ProjectItem ReplaceParameters="true" TargetFileName="CommandWithToolbarBase.cs">CommandWithToolbarBase.cs</ProjectItem>
@@ -30,6 +29,7 @@
3029
<ProjectItem ReplaceParameters="true" TargetFileName="CommandTemplate.cs">CommandTemplate.cs</ProjectItem>
3130
<ProjectItem ReplaceParameters="true" TargetFileName="CommandUpdate.cs">CommandUpdate.cs</ProjectItem>
3231
<ProjectItem ReplaceParameters="true" TargetFileName="DescribeCommand.cs">DescribeCommand.cs</ProjectItem>
32+
<ProjectItem ReplaceParameters="true" TargetFileName="DirCommand.cs">DirCommand.cs</ProjectItem>
3333
<ProjectItem ReplaceParameters="true" TargetFileName="ExitCommand.cs">ExitCommand.cs</ProjectItem>
3434
<ProjectItem ReplaceParameters="true" TargetFileName="LogCommand.cs">LogCommand.cs</ProjectItem>
3535
<ProjectItem ReplaceParameters="true" TargetFileName="MasterCommando.cs">MasterCommando.cs</ProjectItem>
@@ -72,6 +72,7 @@
7272
<ProjectItem ReplaceParameters="true" TargetFileName="ReflectionService.cs">ReflectionService.cs</ProjectItem>
7373
<ProjectItem ReplaceParameters="true" TargetFileName="ShellService.cs">ShellService.cs</ProjectItem>
7474
<ProjectItem ReplaceParameters="true" TargetFileName="StorageService.cs">StorageService.cs</ProjectItem>
75+
<ProjectItem ReplaceParameters="true" TargetFileName="ToolbarService.cs">ToolbarService.cs</ProjectItem>
7576
<ProjectItem ReplaceParameters="true" TargetFileName="ZipService.cs">ZipService.cs</ProjectItem>
7677
</Folder>
7778
<ProjectItem ReplaceParameters="false" TargetFileName="DocsDB.data">DocsDB.data</ProjectItem>

0 commit comments

Comments
 (0)