Skip to content

v0.3.1 #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Apr 26, 2021
Merged
4 changes: 3 additions & 1 deletion pglet.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ New-Alias -Name Checkbox -Value New-PgletCheckbox
New-Alias -Name ChoiceGroup -Value New-PgletChoiceGroup
New-Alias -Name ChoiceGroupOption -Value New-PgletChoiceGroupOption
New-Alias -Name Dialog -Value New-PgletDialog
New-Alias -Name DatePicker -Value New-PgletDatePicker
New-Alias -Name Dropdown -Value New-PgletDropdown
New-Alias -Name DropdownOption -Value New-PgletDropdownOption
New-Alias -Name GridColumn -Value New-PgletGridColumn
New-Alias -Name Grid -Value New-PgletGrid
New-Alias -Name Icon -Value New-PgletIcon
New-Alias -Name Image -Value New-PgletImage
New-Alias -Name LineChart -Value New-PgletLineChart
New-Alias -Name LineChartData -Value New-PgletLineChartPoint
New-Alias -Name LineChartData -Value New-PgletLineChartData
New-Alias -Name LineChartDataPoint -Value New-PgletLineChartDataPoint
New-Alias -Name Link -Value New-PgletLink
New-Alias -Name MenuItem -Value New-PgletMenuItem
Expand All @@ -36,6 +37,7 @@ New-Alias -Name Progress -Value New-PgletProgress
New-Alias -Name SearchBox -Value New-PgletSearchBox
New-Alias -Name Slider -Value New-PgletSlider
New-Alias -Name SpinButton -Value New-PgletSpinButton
New-Alias -Name Spinner -Value New-PgletSpinner
New-Alias -Name Stack -Value New-PgletStack
New-Alias -Name Tab -Value New-PgletTab
New-Alias -Name Tabs -Value New-PgletTabs
Expand Down
2 changes: 1 addition & 1 deletion src/Pglet.PowerShell/ClearPgletPageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ protected override void ProcessRecord()
throw new Exception("There are no active Pglet connections.");
}

page.Clean(true);
page.Clean();
}
}
}
23 changes: 16 additions & 7 deletions src/Pglet.PowerShell/ConnectPgletAppCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Pglet.PowerShell.Controls;
using System;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
Expand Down Expand Up @@ -46,13 +47,21 @@ protected override void ProcessRecord()
{
using CancellationTokenRegistration ctr = _cancellationSource.Token.Register(() => ps.Stop());

ps.Runspace = runspace;
runspace.Open();
runspace.SessionStateProxy.PSVariable.Set(new PSVariable(Constants.PGLET_PAGE, page, ScopedItemOptions.Private));
ps.AddScript($"Import-Module '{pgletModulePath}'");
ps.AddScript(ScriptBlock.ToString());
ps.AddScript("\nSwitch-PgletEvents");
ps.Invoke();
try
{
ps.Runspace = runspace;
runspace.Open();
runspace.SessionStateProxy.PSVariable.Set(new PSVariable(Constants.PGLET_PAGE, page, ScopedItemOptions.Private));
ps.AddScript($"Import-Module '{pgletModulePath}'");
ps.AddScript(ScriptBlock.ToString());
ps.AddScript("\nSwitch-PgletEvents");
ps.Invoke();
}
catch (RuntimeException ex)
{
Host.UI.WriteErrorLine(ex.ErrorRecord.ToString() + "\n" + ex.ErrorRecord.InvocationInfo.PositionMessage);
throw;
}
}
}
});
Expand Down
34 changes: 34 additions & 0 deletions src/Pglet.PowerShell/Controls/PsDatePicker.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
using Pglet.Controls;
using System;
using System.Collections.Generic;
using System.Management.Automation;

namespace Pglet.PowerShell.Controls
{
public class PsDatePicker : DatePicker, IPsEventControl
{
readonly Dictionary<string, ScriptBlock> _psEvents = new Dictionary<string, ScriptBlock>(StringComparer.OrdinalIgnoreCase);

public new ScriptBlock OnChange
{
get
{
return GetEventHandlerScript("change");
}
set
{
_psEvents["change"] = value;
}
}

public ScriptBlock GetEventHandlerScript(ControlEvent e)
{
return GetEventHandlerScript(e.Name);
}

private ScriptBlock GetEventHandlerScript(string eventName)
{
return _psEvents.ContainsKey(eventName) ? _psEvents[eventName] : null;
}
}
}
12 changes: 0 additions & 12 deletions src/Pglet.PowerShell/Controls/PsSearchBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,6 @@ public class PsSearchBox : SearchBox, IPsEventControl
}
}

public new ScriptBlock OnEscape
{
get
{
return GetEventHandlerScript("escape");
}
set
{
_psEvents["escape"] = value;
}
}

public new ScriptBlock OnChange
{
get
Expand Down
6 changes: 3 additions & 3 deletions src/Pglet.PowerShell/NewPgletButtonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ namespace Pglet.PowerShell
[OutputType(typeof(PsButton))]
public class NewPgletButtonCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false, Position = 0)]
public string Text { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Primary { get; set; }

Expand All @@ -22,9 +25,6 @@ public class NewPgletButtonCommand : NewControlCmdletBase
[Parameter(Mandatory = false)]
public SwitchParameter Split { get; set; }

[Parameter(Mandatory = false)]
public string Text { get; set; }

[Parameter(Mandatory = false)]
public string SecondaryText { get; set; }

Expand Down
4 changes: 2 additions & 2 deletions src/Pglet.PowerShell/NewPgletChoiceGroupOptionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Pglet.PowerShell
[OutputType(typeof(ChoiceGroupOption))]
public class NewPgletChoiceGroupOptionCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 0)]
public string Key { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 1)]
public string Text { get; set; }

[Parameter(Mandatory = false)]
Expand Down
92 changes: 92 additions & 0 deletions src/Pglet.PowerShell/NewPgletDatePickerCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
using Pglet.Controls;
using Pglet.PowerShell.Controls;
using System;
using System.Management.Automation;

namespace Pglet.PowerShell
{
[Cmdlet(VerbsCommon.New, "PgletDatePicker")]
[OutputType(typeof(PsDatePicker))]
public class NewPgletDatePickerCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false, Position = 0)]
public string Label { get; set; }

[Parameter(Mandatory = false)]
public DateTime? Value { get; set; }

[Parameter(Mandatory = false)]
public string Placeholder { get; set; }

[Parameter(Mandatory = false)]
public string ErrorMessage { get; set; }

[Parameter(Mandatory = false)]
public string Description { get; set; }

[Parameter(Mandatory = false)]
public string Prefix { get; set; }

[Parameter(Mandatory = false)]
public string Suffix { get; set; }

[Parameter(Mandatory = false)]
public string Icon { get; set; }

[Parameter(Mandatory = false)]
public string IconColor { get; set; }

[Parameter(Mandatory = false)]
public TextBoxAlign? Align { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter AllowTextInput { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Required { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Underlined { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Borderless { get; set; }

[Parameter(Mandatory = false)]
public ScriptBlock OnChange { get; set; }

protected override void ProcessRecord()
{
var control = new PsDatePicker
{
Label = Label,
Value = Value,
Placeholder = Placeholder,
OnChange = OnChange
};

SetControlProps(control);

if (AllowTextInput.IsPresent)
{
control.AllowTextInput = AllowTextInput.ToBool();
}

if (Required.IsPresent)
{
control.Required = Required.ToBool();
}

if (Underlined.IsPresent)
{
control.Underlined = Underlined.ToBool();
}

if (Borderless.IsPresent)
{
control.Borderless = Borderless.ToBool();
}

WriteObject(control);
}
}
}
11 changes: 8 additions & 3 deletions src/Pglet.PowerShell/NewPgletDialogCommand.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Pglet.PowerShell.Controls;
using Pglet.Controls;
using Pglet.PowerShell.Controls;
using System.Management.Automation;

namespace Pglet.PowerShell
Expand Down Expand Up @@ -26,7 +27,7 @@ public class NewPgletDialogCommand : NewControlCmdletBase
public string SubText { get; set; }

[Parameter(Mandatory = false)]
public string LargeHeader { get; set; }
public DialogType? Type { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter AutoDismiss { get; set; }
Expand All @@ -47,7 +48,6 @@ protected override void ProcessRecord()
OnDismiss = OnDismiss,
Title = Title,
SubText = SubText,
LargeHeader = LargeHeader,
MaxWidth = MaxWidth
};

Expand All @@ -73,6 +73,11 @@ protected override void ProcessRecord()
ctl.Blocking = Blocking.ToBool();
}

if (Type.HasValue)
{
ctl.Type = Type.Value;
}

if (Controls != null)
{
foreach (var control in Controls)
Expand Down
4 changes: 2 additions & 2 deletions src/Pglet.PowerShell/NewPgletDropdownOptionCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ namespace Pglet.PowerShell
[OutputType(typeof(DropdownOption))]
public class NewPgletDropdownOptionCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 0)]
public string Key { get; set; }

[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 1)]
public string Text { get; set; }

protected override void ProcessRecord()
Expand Down
8 changes: 8 additions & 0 deletions src/Pglet.PowerShell/NewPgletGridCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ public class NewPgletGridCommand : NewControlCmdletBase
[Parameter(Mandatory = false)]
public SwitchParameter HeaderVisible { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter PreserveSelection { get; set; }

[Parameter(Mandatory = false)]
public int? ShimmerLines { get; set; }

Expand Down Expand Up @@ -62,6 +65,11 @@ protected override void ProcessRecord()
ctl.HeaderVisible = HeaderVisible.ToBool();
}

if (PreserveSelection.IsPresent)
{
ctl.PreserveSelection = PreserveSelection.ToBool();
}

if (Columns != null)
{
foreach (var column in Columns)
Expand Down
2 changes: 1 addition & 1 deletion src/Pglet.PowerShell/NewPgletIconCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pglet.PowerShell
[OutputType(typeof(Icon))]
public class NewPgletIconCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 0)]
public string Name { get; set; }

[Parameter(Mandatory = false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Pglet.PowerShell/NewPgletImageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pglet.PowerShell
[OutputType(typeof(Image))]
public class NewPgletImageCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 0)]
public string Src { get; set; }

[Parameter(Mandatory = false)]
Expand Down
2 changes: 1 addition & 1 deletion src/Pglet.PowerShell/NewPgletMenuItemCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Pglet.PowerShell
[OutputType(typeof(PsMenuItem))]
public class NewPgletMenuItemCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
[Parameter(Mandatory = false, Position = 0)]
public string Text { get; set; }

[Parameter(Mandatory = false)]
Expand Down
6 changes: 3 additions & 3 deletions src/Pglet.PowerShell/NewPgletMessageButtonCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Pglet.PowerShell
[OutputType(typeof(MessageButton))]
public class NewPgletMessageButtonCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
public string Action { get; set; }
[Parameter(Mandatory = false, Position = 0)]
public string Text { get; set; }

[Parameter(Mandatory = false)]
public string Text { get; set; }
public string Action { get; set; }

protected override void ProcessRecord()
{
Expand Down
6 changes: 3 additions & 3 deletions src/Pglet.PowerShell/NewPgletMessageCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ namespace Pglet.PowerShell
[OutputType(typeof(PsMessage))]
public class NewPgletMessageCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false, Position = 0)]
public string Value { get; set; }

[Parameter(Mandatory = false)]
public MessageButton[] Buttons { get; set; }

Expand All @@ -17,9 +20,6 @@ public class NewPgletMessageCommand : NewControlCmdletBase
[Parameter(Mandatory = false)]
public MessageType? Type { get; set; }

[Parameter(Mandatory = false)]
public string Value { get; set; }

[Parameter(Mandatory = false)]
public SwitchParameter Multiline { get; set; }

Expand Down
6 changes: 3 additions & 3 deletions src/Pglet.PowerShell/NewPgletProgressCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ namespace Pglet.PowerShell
[OutputType(typeof(Progress))]
public class NewPgletProgressCommand : NewControlCmdletBase
{
[Parameter(Mandatory = false)]
public int? Value { get; set; }
[Parameter(Mandatory = false, Position = 0)]
public string Label { get; set; }

[Parameter(Mandatory = false)]
public string Label { get; set; }
public int? Value { get; set; }

[Parameter(Mandatory = false)]
public string Description { get; set; }
Expand Down
Loading