Skip to content

Commit

Permalink
add a feature of auto name setting
Browse files Browse the repository at this point in the history
  • Loading branch information
ktxiaok committed Dec 6, 2024
1 parent 915c002 commit 7690fcd
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 0 deletions.
18 changes: 18 additions & 0 deletions L4D2AddonAssistant.GUI/Resources/Texts.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions L4D2AddonAssistant.GUI/Resources/Texts.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<data name="AuthorColon" xml:space="preserve">
<value>Author:</value>
</data>
<data name="AutoSetName" xml:space="preserve">
<value>Set the name automatically</value>
</data>
<data name="AutoUpdateStrategy" xml:space="preserve">
<value>Auto Update Strategy</value>
</data>
Expand Down Expand Up @@ -336,6 +339,9 @@
<data name="No" xml:space="preserve">
<value>No</value>
</data>
<data name="NoAvailableName" xml:space="preserve">
<value>No available name</value>
</data>
<data name="Null" xml:space="preserve">
<value>Null</value>
</data>
Expand Down
6 changes: 6 additions & 0 deletions L4D2AddonAssistant.GUI/Resources/Texts.zh-Hans.resx
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,9 @@
<data name="AuthorColon" xml:space="preserve">
<value>作者:</value>
</data>
<data name="AutoSetName" xml:space="preserve">
<value>自动设置名称</value>
</data>
<data name="AutoUpdateStrategy" xml:space="preserve">
<value>自动更新策略</value>
</data>
Expand Down Expand Up @@ -336,6 +339,9 @@
<data name="No" xml:space="preserve">
<value>否</value>
</data>
<data name="NoAvailableName" xml:space="preserve">
<value>无可用名称</value>
</data>
<data name="Null" xml:space="preserve">
<value>空</value>
</data>
Expand Down
4 changes: 4 additions & 0 deletions L4D2AddonAssistant.GUI/Views/AddonNodeView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@

<!--name-->
<v:EditableTextBlock
Name="nameControl"
Value="{Binding AddonNode.Name}"
HorizontalAlignment="Center">
<v:EditableTextBlock.Styles>
Expand Down Expand Up @@ -81,6 +82,9 @@
<Setter Property="HorizontalContentAlignment" Value="Center"/>
</Style>
</StackPanel.Styles>
<Button
Name="autoSetNameButton"
Content="{x:Static r:Texts.AutoSetName}"/>
<Button
Content="{x:Static r:Texts.Check}"
Command="{Binding Check}"/>
Expand Down
50 changes: 50 additions & 0 deletions L4D2AddonAssistant.GUI/Views/AddonNodeView.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia.Controls;
using Avalonia.ReactiveUI;
using L4D2AddonAssistant.ViewModels;
using L4D2AddonAssistant.Resources;
using ReactiveUI;
using System;
using System.Reactive.Disposables;
Expand Down Expand Up @@ -47,6 +48,55 @@ public AddonNodeView()
});

InitializeComponent();

autoSetNameButton.Click += AutoSetNameButton_Click;
}

private void AutoSetNameButton_Click(object? sender, Avalonia.Interactivity.RoutedEventArgs e)
{
if (DataContext != null)
{
if (DataContext is WorkshopVpkAddonViewModel workshopVpkAddonViewModel)
{
if (workshopVpkAddonViewModel.PublishedFileDetails is var details && details != null)
{
if (TrySetName(details.Title))
{
return;
}
}
}

if (DataContext is VpkAddonViewModel vpkAddonViewModel)
{
if (vpkAddonViewModel.Info is var info && info != null)
{
if (TrySetName(info.Title))
{
return;
}
}
}
}

TrySetName(Texts.NoAvailableName);

bool TrySetName(string name)
{
name = name.Trim();
if (name.Length == 0)
{
return false;
}

nameControl.IsEditing = true;
var textBox = nameControl.TextBox;
if (textBox != null)
{
textBox.Text = name;
}
return true;
}
}

private void ClearSectionViews()
Expand Down
12 changes: 12 additions & 0 deletions L4D2AddonAssistant.GUI/Views/EditableTextBlock.axaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public EditableTextBlock()
});
}

public bool IsEditing
{
get => _isEditing;
set
{
_isEditing = value;
UpdateVisibility();
}
}

public TextBox? TextBox => _textBox;

public string Value
{
get => GetValue(ValueProperty);
Expand Down

0 comments on commit 7690fcd

Please sign in to comment.