Skip to content

Commit

Permalink
Merge pull request #77 from TQLApp/edit-dialogs
Browse files Browse the repository at this point in the history
Reworked the configuration controls
  • Loading branch information
pvginkel authored Nov 25, 2023
2 parents 1ceb246 + 4596a41 commit a56f012
Show file tree
Hide file tree
Showing 69 changed files with 1,915 additions and 1,772 deletions.
2 changes: 1 addition & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
/Tql.App/Themes/**/*
/Tql.App/QuickStart/*.md
/Tql.App/QuickStart/Playbook*.md
/.github/ISSUE_TEMPLATE/*
116 changes: 116 additions & 0 deletions Build/Run-Prettier.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
################################################################################
# SUPPORT
################################################################################

Function Split-Playbook
{
foreach ($Child in Get-ChildItem "Tql.App\QuickStart\Playbook*.md")
{
$Index = 0
$Content = Get-Content $Child.FullName
$Part = @()
$First = $true

foreach ($Line in $Content)
{
if ($Line -eq "---")
{
if ($First)
{
Write-Playbook-Part -Name $Child.Name -Index $Index -Part $Part

$First = $false
$Part = @()
$Index += 1
}
else
{
$First = $true
}
}

$Part += $Line
}

Write-Playbook-Part -Name $Child.Name -Index $Index -Part $Part
}
}

Function Write-Playbook-Part([string]$Name, [int]$Index, [array]$Part)
{
if ($Part.Count -gt 0)
{
Set-Content (Get-Playbook-Part-FileName -Name $Name -Index $Index) $Part
}
}

Function Merge-Playbook
{
foreach ($Child in Get-ChildItem "Tql.App\QuickStart\Playbook*.md")
{
$Content = @()

for ($Index = 1; ; $Index += 1)
{
$Part = Read-Playbook-Part -Name $Child.Name -Index $Index

if ($Part -eq $null)
{
break
}

if ($Content.Count -gt 0)
{
$Content += ""
}

$Content += $Part
}

Set-Content $Child.FullName $Content
}
}

Function Read-Playbook-Part([string]$Name, [int]$Index)
{
$FileName = Get-Playbook-Part-FileName -Name $Name -Index $Index

if (-not (Test-Path $FileName))
{
return $null
}

return Get-Content $FileName
}

Function Get-Playbook-Part-FileName([string]$Name, [int]$Index)
{
$Name = $Name.Substring(0, $Name.Length - 3)

return "Tql.App\QuickStart\Split$Name-$Index.md"
}

################################################################################
# ENTRY POINT
################################################################################

npm install --save-dev prettier @prettier/plugin-xml

rm "Tql.App\QuickStart\SplitPlaybook*.md"

Split-Playbook

npx prettier `
--plugin=@prettier/plugin-xml `
--write "**/*.xaml" "**/*.md" `
--end-of-line crlf `
--bracket-same-line true `
--single-attribute-per-line true `
--xml-quote-attributes double `
--xml-self-closing-space true `
--xml-whitespace-sensitivity ignore `
--prose-wrap always

Merge-Playbook

rm "Tql.App\QuickStart\SplitPlaybook*.md"
1 change: 1 addition & 0 deletions Tql.App/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ PluginManager pluginManager
builder.AddTransient<GeneralConfigurationControl>();
builder.AddTransient<PluginsConfigurationControl>();
builder.AddTransient<PackageSourcesConfigurationControl>();
builder.AddTransient<PackageSourceEditWindow>();
}

private void Application_Exit(object? sender, ExitEventArgs e)
Expand Down
18 changes: 6 additions & 12 deletions Tql.App/ConfigurationUI/PackageManagerConfigurationDto.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace Tql.App.ConfigurationUI;

internal class PackageManagerConfigurationDto
{
public ObservableCollection<PackageManagerSourceDto> Sources { get; } = new();
public ObservableCollection<PackageSourceDto> Sources { get; } = new();

public static PackageManagerConfigurationDto FromConfiguration(
PackageManagerConfiguration configuration,
Expand All @@ -24,7 +24,7 @@ IEncryption encryption
.Sources
.Select(
p =>
new PackageManagerSourceDto
new PackageSourceDto
{
Url = p.Url,
UserName = p.UserName,
Expand All @@ -41,19 +41,14 @@ public PackageManagerConfiguration ToConfiguration(IEncryption encryption)
return new PackageManagerConfiguration(
Sources
.Select(
p =>
new PackageManagerSource(
p.Url!,
p.UserName,
encryption.EncryptString(p.Password)
)
p => new PackageSource(p.Url!, p.UserName, encryption.EncryptString(p.Password))
)
.ToImmutableArray()
);
}
}

internal class PackageManagerSourceDto : DtoBase
internal class PackageSourceDto : DtoBase
{
public string? Url
{
Expand All @@ -73,7 +68,7 @@ public string? Password
set => SetValue(value);
}

public PackageManagerSourceDto()
public PackageSourceDto()
{
AddProperty(
nameof(Url),
Expand All @@ -84,6 +79,5 @@ public PackageManagerSourceDto()
AddProperty(nameof(Password), null, CoerceEmptyStringToNull);
}

public PackageManagerSourceDto Clone() =>
(PackageManagerSourceDto)Clone(new PackageManagerSourceDto());
public PackageSourceDto Clone() => (PackageSourceDto)Clone(new PackageSourceDto());
}
86 changes: 86 additions & 0 deletions Tql.App/ConfigurationUI/PackageSourceEditWindow.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<utilities:BaseWindow
x:Class="Tql.App.ConfigurationUI.PackageSourceEditWindow"
x:ClassModifier="internal"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:utilities="clr-namespace:Tql.Utilities;assembly=Tql.Utilities"
xmlns:app="clr-namespace:Tql.App"
xmlns:configurationUi="clr-namespace:Tql.App.ConfigurationUI"
ResizeMode="NoResize"
SizeToContent="Height"
WindowStartupLocation="CenterOwner"
mc:Ignorable="d"
Title="{x:Static app:Labels.PackageSourceEditWindow_Title}"
Width="500"
d:DataContext="{d:DesignInstance configurationUi:PackageSourceDto}">
<Window.Resources>
<utilities:InverseBooleanConverter x:Key="IBConverter" />
</Window.Resources>

<Grid Margin="9">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

<Label
Content="{x:Static app:Labels.PackageSourceEditWindow_URLLabel}" />
<TextBox
Text="{Binding Url}"
Grid.Column="1"
Margin="3" />

<Label
Content="{x:Static app:Labels.PackageSourceEditWindow_UserNameLabel}"
Grid.Row="1" />
<TextBox
Text="{Binding UserName}"
Grid.Row="1"
Grid.Column="1"
Margin="3" />

<Label
Content="{x:Static app:Labels.PackageSourceEditWindow_PasswordLabel}"
Grid.Row="2" />
<PasswordBox
utilities:PasswordBoxHelper.BoundPassword="{Binding Password, Mode=TwoWay}"
Grid.Row="2"
Grid.Column="1"
Margin="3" />

<TextBlock
Margin="4"
Grid.Row="3"
Grid.Column="1"
TextWrapping="Wrap"
Text="{x:Static app:Labels.PackageSourceEditWindow_PasswordHelpText}" />

<StackPanel
Orientation="Horizontal"
HorizontalAlignment="Right"
Margin="0,3,0,0"
Grid.Row="4"
Grid.ColumnSpan="2">
<Button
x:Name="_acceptButton"
IsEnabled="{Binding HasErrors, Converter={StaticResource IBConverter}}"
Content="{x:Static app:Labels.Button_Save}"
Margin="3"
IsDefault="true"
Click="_acceptButton_Click" />
<Button
Content="{x:Static app:Labels.Button_Cancel}"
Margin="3"
IsCancel="true" />
</StackPanel>
</Grid>
</utilities:BaseWindow>
16 changes: 16 additions & 0 deletions Tql.App/ConfigurationUI/PackageSourceEditWindow.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Tql.Abstractions;

namespace Tql.App.ConfigurationUI;

internal partial class PackageSourceEditWindow
{
public PackageSourceEditWindow()
{
InitializeComponent();
}

private void _acceptButton_Click(object sender, RoutedEventArgs e)
{
DialogResult = true;
}
}
Loading

0 comments on commit a56f012

Please sign in to comment.