Skip to content

Commit 597ca55

Browse files
committed
bug fix
1 parent 2f40590 commit 597ca55

File tree

9 files changed

+84
-20
lines changed

9 files changed

+84
-20
lines changed

Guify.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
<OutputType>Exe</OutputType>
44
<TargetFramework>net6.0</TargetFramework>
55
<Nullable>enable</Nullable>
6+
<RepositoryUrl>https://github.com/Quantumzhao/Guify</RepositoryUrl>
7+
<Authors>Quantumzhao</Authors>
8+
<Version>0.1.0</Version>
9+
<Company>Quantum</Company>
610
<!--Avalonia doesen't support TrimMode=link currently,but we are working on that https://github.com/AvaloniaUI/Avalonia/issues/6892 -->
711
<TrimMode>copyused</TrimMode>
812
<BuiltInComInteropSupport>true</BuiltInComInteropSupport>
@@ -36,8 +40,4 @@
3640
<PackageReference Include="MessageBox.Avalonia" Version="2.0.1" />
3741
<PackageReference Include="XamlNameReferenceGenerator" Version="1.3.4" />
3842
</ItemGroup>
39-
<ItemGroup>
40-
<UpToDateCheckInput Remove="Views\Resources\Brushes.axaml" />
41-
<UpToDateCheckInput Remove="Views\Resources\Index.axaml" />
42-
</ItemGroup>
4343
</Project>

Guify.wiki

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
Subproject commit cedcce287fb63ced39bc0b64dc813241eb734fee
1+
Subproject commit 736fd13aadea20f1469b76c65969762436392a3d

IO/ShellUtils.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public static async void Bash(string cmd)
3030
var thread = new Thread(() => {
3131
while (flag)
3232
{
33-
Thread.Sleep(100);
33+
Thread.Sleep(500);
3434

3535
if (flag && !process.StandardOutput.EndOfStream)
3636
{

IO/XMLUtils.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ private static SelectFolderField LoadSelectFolderField(XElement node)
146146

147147
private static ComponentBase LoadYesNoField(XElement node)
148148
{
149-
var defaultValue = node.GetDefaultValue().ToBool() ?? false;
149+
var defaultValue = node.GetDefaultValue().ToBool();
150150
var desc = node.GetDescription();
151151
var isRequired = node.GetIsRequired();
152152
var longName = node.GetLongName();
@@ -159,8 +159,8 @@ private static ComponentBase LoadYesNoField(XElement node)
159159
return new CheckBoxField(
160160
defaultValue, isFlag, isRequired, longName, shortName, desc, connector);
161161
else
162-
return new RadioButtonField(defaultValue, isFlag, isRequired, longName, shortName, desc
163-
, group, connector);
162+
return new RadioButtonField(defaultValue ?? false, isFlag, isRequired, longName
163+
, shortName, desc, group, connector);
164164
}
165165

166166
private static ComponentBase LoadNumberField(XElement node)

Models/Components/CheckBoxField.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,25 @@ public CheckBoxField(bool? defaultValue, bool? isFlag, bool isRequired, string?
1111

1212
public bool IsFlag { get; init; }
1313

14+
public override bool? Value
15+
{
16+
get => base.Value;
17+
set
18+
{
19+
if (_Value is null && value is false) base.Value = true;
20+
else base.Value = value;
21+
}
22+
}
23+
1424
public override string Compile()
15-
=> IsFlag ? GetFlag() : base.Compile();
25+
{
26+
if (IsFlag)
27+
{
28+
if (Value ?? false) return GetFlag();
29+
else return string.Empty;
30+
}
31+
else return base.Compile();
32+
}
1633

1734
public override string ValueToString(bool? value)
1835
=> (value ?? false) ? "true" : "false";

Models/Components/FieldBase.cs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ public virtual T Value
4848
get => _Value;
4949
set
5050
{
51-
// because binded control will automatically set any nullable struct to a non-null default
52-
// therefore using null as default value is prone to change
53-
// if (_Value?.Equals(DefaultValue) ?? DefaultValue == null) UsingDefault = true;
54-
// else UsingDefault = false;
55-
5651
if (!(_Value?.Equals(value) ?? false))
5752
{
5853
_Value = value;
@@ -68,14 +63,14 @@ public override string Compile()
6863

6964
if (IsRequired)
7065
{
71-
if (Value is not null) return string.Join(' ', flag, Value);
66+
if (Value is not null) return string.Join(Connector, flag, Value);
7267
else throw new WarningException(nameof(Value)
7368
, $"Value of {GetName()} is required");
7469
}
7570
else
7671
{
77-
if (Value is not null) return string.Join(' ', flag, ValueToString(Value));
78-
else if (DefaultValue != null) return string.Join(' ', flag, ValueToString(DefaultValue));
72+
if (Value is not null) return string.Join(Connector, flag, ValueToString(Value));
73+
else if (DefaultValue != null) return string.Join(Connector, flag, ValueToString(DefaultValue));
7974
else return string.Empty;
8075
}
8176
}

Models/Components/NumberField.cs

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,53 @@ public NumberField(float? defaultValue, float? max, float? min, bool isRequired
1919

2020
public float Max { get; init; }
2121
public float Min { get; init; }
22+
23+
// number box cannot have null as a valid value, so if the default value is null,
24+
// i.e. don't care, there must be an extra flag storing the info that "0" is indeed
25+
// representing the null value
26+
public override float? Value
27+
{
28+
get => base.Value;
29+
set
30+
{
31+
if (DefaultValue is not null)
32+
{
33+
base.Value = value;
34+
return;
35+
}
36+
else if (value == null)
37+
{
38+
_IsUsingDefault = true;
39+
base.Value = DefaultValue ?? 0;
40+
41+
if (_Value == 0) InvokePropertyChanged(nameof(IsValueChanged));
42+
}
43+
else
44+
{
45+
_IsUsingDefault = false;
46+
base.Value = value;
47+
}
48+
}
49+
}
50+
51+
private bool _IsUsingDefault = true;
52+
public override bool IsValueChanged => !_IsUsingDefault;
53+
54+
public override string Compile()
55+
{
56+
var flag = GetFlag();
57+
58+
if (IsRequired)
59+
{
60+
if (!_IsUsingDefault) return string.Join(Connector, flag, Value);
61+
else throw new WarningException(nameof(Value)
62+
, $"Value of {GetName()} is required");
63+
}
64+
else
65+
{
66+
if (!_IsUsingDefault) return string.Join(Connector, flag, ValueToString(Value));
67+
else if (DefaultValue != null) return string.Join(Connector, flag, ValueToString(DefaultValue));
68+
else return string.Empty;
69+
}
70+
}
2271
}

Models/Components/RadioButtonField.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@ public override string ValueToString(bool value)
6060
=> value ? "true" : "false";
6161

6262
public override bool IsValueChanged
63-
=> Value || AllGroups[Group].Any(r => r.Value);
63+
=> Value != DefaultValue || AllGroups[Group].Any(r => r.Value != r.DefaultValue);
64+
65+
public override void Reset()
66+
=> AllGroups[Group].ForEach(r => r.Value = r.DefaultValue);
6467
}
6568
}

UI/publish

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<root command="dotnet" reusable="true" xmlns="urn:Guify" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="urn:Guify ./Schemas/Root.xsd">
33
<verb name="publish">
44
<infix code="--configuration Release" />
5-
<pickValue description="Platforms &amp; Architecture" longName="--runtime " shortName="-r">
5+
<pickValue description="Platforms &amp; Architecture" longName="--runtime" shortName="-r">
66
<candidate value="win-x64" />
77
<candidate value="linux-x64" />
88
<candidate value="osx-x64" />

0 commit comments

Comments
 (0)