mirror of
https://github.com/ayufan/steam-deck-tools.git
synced 2026-04-04 22:07:40 +00:00
Get rid of ProfileName and replace it with ProfileStringConverter
This commit is contained in:
parent
9b77a9f220
commit
2052724370
3 changed files with 7 additions and 52 deletions
|
|
@ -35,7 +35,7 @@ namespace SteamController
|
|||
public Controller()
|
||||
{
|
||||
// Set available profiles
|
||||
ProfilesSettings.Helpers.ProfileNameConverter.Profiles = context.Profiles.
|
||||
ProfilesSettings.Helpers.ProfileStringConverter.Profiles = context.Profiles.
|
||||
Where((profile) => profile.Visible).
|
||||
Select((profile) => profile.Name).ToArray();
|
||||
|
||||
|
|
|
|||
|
|
@ -3,28 +3,7 @@ using System.Globalization;
|
|||
|
||||
namespace SteamController.ProfilesSettings.Helpers
|
||||
{
|
||||
[TypeConverter(typeof(ProfileNameConverter))]
|
||||
public class ProfileName
|
||||
{
|
||||
public String Name { get; set; } = "";
|
||||
|
||||
public ProfileName(string name)
|
||||
{
|
||||
this.Name = name;
|
||||
}
|
||||
|
||||
public static implicit operator string(ProfileName name)
|
||||
{
|
||||
return name.Name;
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return this.Name;
|
||||
}
|
||||
}
|
||||
|
||||
internal class ProfileNameConverter : TypeConverter
|
||||
internal class ProfileStringConverter : TypeConverter
|
||||
{
|
||||
public static string[] Profiles = new string[0];
|
||||
|
||||
|
|
@ -45,33 +24,9 @@ namespace SteamController.ProfilesSettings.Helpers
|
|||
return true;
|
||||
}
|
||||
|
||||
public override bool CanConvertFrom(ITypeDescriptorContext? context, Type sourceType)
|
||||
{
|
||||
return sourceType == typeof(string) || base.CanConvertFrom(context, sourceType);
|
||||
}
|
||||
|
||||
public override object? ConvertFrom(ITypeDescriptorContext? context, System.Globalization.CultureInfo? culture, object value)
|
||||
{
|
||||
if (value is string)
|
||||
return new ProfileName(value?.ToString() ?? "");
|
||||
return base.ConvertFrom(context, culture, value);
|
||||
}
|
||||
|
||||
public override bool CanConvertTo(ITypeDescriptorContext? context, Type? destinationType)
|
||||
{
|
||||
return destinationType == typeof(string) || base.CanConvertTo(context, destinationType);
|
||||
}
|
||||
|
||||
public override object? ConvertTo(ITypeDescriptorContext? context, CultureInfo? culture, object? value, Type destinationType)
|
||||
{
|
||||
if (destinationType == typeof(string))
|
||||
return value?.ToString();
|
||||
return base.ConvertTo(context, culture, value, destinationType);
|
||||
}
|
||||
|
||||
public override bool IsValid(ITypeDescriptorContext? context, object? value)
|
||||
{
|
||||
return Profiles.Contains(value?.ToString()) || base.IsValid(context, value);
|
||||
return Profiles.Contains(value?.ToString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ namespace SteamController
|
|||
internal sealed partial class Settings : CommonHelpers.BaseSettings
|
||||
{
|
||||
public static readonly Settings Default = new Settings();
|
||||
private static readonly ProfilesSettings.Helpers.ProfileName DefaultProfileDefault = new ProfilesSettings.Helpers.ProfileName("Default");
|
||||
|
||||
public Settings() : base("Settings")
|
||||
{
|
||||
|
|
@ -23,9 +22,10 @@ namespace SteamController
|
|||
|
||||
[Description("Default profile used when going back to Desktop mode")]
|
||||
[BrowsableAttribute(true)]
|
||||
public ProfilesSettings.Helpers.ProfileName DefaultProfile
|
||||
[TypeConverter(typeof(ProfilesSettings.Helpers.ProfileStringConverter))]
|
||||
public string DefaultProfile
|
||||
{
|
||||
get { return Get<ProfilesSettings.Helpers.ProfileName>("DefaultProfile", DefaultProfileDefault); }
|
||||
get { return Get<string>("DefaultProfile", "Desktop"); }
|
||||
set { Set("DefaultProfile", value); }
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue