Skip to content

Commit 8e6e006

Browse files
committed
Fix EnVarsViewModel View type & Use new GetDialog
1 parent 0db5fdd commit 8e6e006

File tree

2 files changed

+70
-62
lines changed

2 files changed

+70
-62
lines changed

StabilityMatrix.Avalonia/ViewModels/Dialogs/EnvVarsViewModel.cs

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
1-
using System;
2-
using System.Collections.ObjectModel;
1+
using System.Collections.ObjectModel;
32
using System.Diagnostics;
43
using Avalonia.Collections;
54
using CommunityToolkit.Mvvm.ComponentModel;
65
using CommunityToolkit.Mvvm.Input;
76
using Injectio.Attributes;
7+
using StabilityMatrix.Avalonia.Controls;
88
using StabilityMatrix.Avalonia.Languages;
99
using StabilityMatrix.Avalonia.ViewModels.Base;
10+
using StabilityMatrix.Avalonia.Views.Dialogs;
1011
using StabilityMatrix.Core.Attributes;
1112
using StabilityMatrix.Core.Models;
1213

1314
namespace StabilityMatrix.Avalonia.ViewModels.Dialogs;
1415

15-
[View(typeof(EnvVarsViewModel))]
16+
[View(typeof(EnvVarsDialog))]
1617
[ManagedService]
1718
[RegisterTransient<EnvVarsViewModel>]
1819
public partial class EnvVarsViewModel : ContentDialogViewModelBase
@@ -43,4 +44,15 @@ private void RemoveSelectedRow(int selectedIndex)
4344
Debug.WriteLine($"RemoveSelectedRow: Index {selectedIndex} out of range");
4445
}
4546
}
47+
48+
public override BetterContentDialog GetDialog()
49+
{
50+
var dialog = base.GetDialog();
51+
52+
dialog.PrimaryButtonText = Resources.Action_Save;
53+
dialog.IsPrimaryButtonEnabled = true;
54+
dialog.CloseButtonText = Resources.Action_Cancel;
55+
56+
return dialog;
57+
}
4658
}

StabilityMatrix.Avalonia/ViewModels/Settings/MainSettingsViewModel.cs

Lines changed: 55 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
9797
[ObservableProperty]
9898
private string? selectedTheme;
9999

100-
public IReadOnlyList<string> AvailableThemes { get; } = new[] { "Light", "Dark", "System", };
100+
public IReadOnlyList<string> AvailableThemes { get; } = new[] { "Light", "Dark", "System" };
101101

102102
[ObservableProperty]
103103
private CultureInfo selectedLanguage;
@@ -112,7 +112,7 @@ public partial class MainSettingsViewModel : PageViewModelBase
112112
Enum.GetValues<NumberFormatMode>().Where(mode => mode != default).ToList();
113113

114114
public IReadOnlyList<float> AnimationScaleOptions { get; } =
115-
new[] { 0f, 0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f, };
115+
new[] { 0f, 0.25f, 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1.75f, 2f };
116116

117117
public IReadOnlyList<HolidayMode> HolidayModes { get; } = Enum.GetValues<HolidayMode>().ToList();
118118

@@ -179,8 +179,10 @@ public partial class MainSettingsViewModel : PageViewModelBase
179179
[ObservableProperty]
180180
private MemoryInfo memoryInfo;
181181

182-
private readonly DispatcherTimer hardwareInfoUpdateTimer =
183-
new() { Interval = TimeSpan.FromSeconds(2.627) };
182+
private readonly DispatcherTimer hardwareInfoUpdateTimer = new()
183+
{
184+
Interval = TimeSpan.FromSeconds(2.627),
185+
};
184186

185187
public Task<CpuInfo> CpuInfoAsync => HardwareHelper.GetCpuInfoAsync();
186188

@@ -343,8 +345,8 @@ public override async Task OnLoadedAsync()
343345
var gpuInfos = HardwareHelper.IterGpuInfo();
344346
GpuInfoCollection = new ObservableCollection<GpuInfo>(gpuInfos);
345347
PreferredGpu ??=
346-
GpuInfos.FirstOrDefault(
347-
gpu => gpu.Name?.Contains("nvidia", StringComparison.InvariantCultureIgnoreCase) ?? false
348+
GpuInfos.FirstOrDefault(gpu =>
349+
gpu.Name?.Contains("nvidia", StringComparison.InvariantCultureIgnoreCase) ?? false
348350
) ?? GpuInfos.FirstOrDefault();
349351

350352
// Start accounts update
@@ -405,7 +407,7 @@ partial void OnSelectedThemeChanged(string? value)
405407
{
406408
"Dark" => ThemeVariant.Dark,
407409
"Light" => ThemeVariant.Light,
408-
_ => ThemeVariant.Default
410+
_ => ThemeVariant.Default,
409411
};
410412
}
411413

@@ -428,7 +430,7 @@ partial void OnSelectedLanguageChanged(CultureInfo? oldValue, CultureInfo newVal
428430
Content = Resources.Text_RelaunchRequiredToApplyLanguage,
429431
DefaultButton = ContentDialogButton.Primary,
430432
PrimaryButtonText = Resources.Action_Relaunch,
431-
CloseButtonText = Resources.Action_RelaunchLater
433+
CloseButtonText = Resources.Action_RelaunchLater,
432434
};
433435

434436
Dispatcher.UIThread.InvokeAsync(async () =>
@@ -496,13 +498,7 @@ private async Task OpenEnvVarsDialog()
496498
current.Select(kvp => new EnvVarKeyPair(kvp.Key, kvp.Value))
497499
);
498500

499-
var dialog = new BetterContentDialog
500-
{
501-
Content = new EnvVarsDialog { DataContext = viewModel },
502-
PrimaryButtonText = Resources.Action_Save,
503-
IsPrimaryButtonEnabled = true,
504-
CloseButtonText = Resources.Action_Cancel,
505-
};
501+
var dialog = viewModel.GetDialog();
506502

507503
if (await dialog.ShowAsync() == ContentDialogResult.Primary)
508504
{
@@ -539,7 +535,7 @@ private async Task CheckPythonVersion()
539535
Title = Resources.Label_PythonVersionInfo,
540536
Content = result,
541537
PrimaryButtonText = Resources.Action_OK,
542-
IsPrimaryButtonEnabled = true
538+
IsPrimaryButtonEnabled = true,
543539
};
544540
await dialog.ShowAsync();
545541
}
@@ -568,7 +564,7 @@ await DialogHelper.GetTextEntryDialogResultAsync(
568564
FileName = processPath,
569565
Args = dialogResult.Value.Text,
570566
WorkingDirectory = Compat.AppCurrentDir,
571-
EnvironmentVariables = settingsManager.Settings.EnvironmentVariables.ToImmutableDictionary()
567+
EnvironmentVariables = settingsManager.Settings.EnvironmentVariables.ToImmutableDictionary(),
572568
};
573569

574570
ConsoleProcessRunner.RunProcessStepAsync(step).SafeFireAndForget();
@@ -607,7 +603,7 @@ await DialogHelper.GetTextEntryDialogResultAsync(
607603
FileName = processPath,
608604
Args = dialogResult.Value.Text,
609605
WorkingDirectory = Compat.AppCurrentDir,
610-
EnvironmentVariables = settingsManager.Settings.EnvironmentVariables.ToImmutableDictionary()
606+
EnvironmentVariables = settingsManager.Settings.EnvironmentVariables.ToImmutableDictionary(),
611607
};
612608

613609
ConsoleProcessRunner.RunProcessStepAsync(step).SafeFireAndForget();
@@ -646,8 +642,8 @@ private async Task FixGitLongPaths()
646642
Resources.Label_AppData
647643
),
648644
new CommandItem(
649-
new AsyncRelayCommand(
650-
() => ProcessRunner.OpenFolderBrowser(Compat.AppDataHome.JoinDir("Logs"))
645+
new AsyncRelayCommand(() =>
646+
ProcessRunner.OpenFolderBrowser(Compat.AppDataHome.JoinDir("Logs"))
651647
),
652648
Resources.Label_Logs
653649
),
@@ -660,11 +656,11 @@ private async Task FixGitLongPaths()
660656
Resources.Label_Checkpoints
661657
),
662658
new CommandItem(
663-
new AsyncRelayCommand(
664-
() => ProcessRunner.OpenFolderBrowser(settingsManager.LibraryDir.JoinDir("Packages"))
659+
new AsyncRelayCommand(() =>
660+
ProcessRunner.OpenFolderBrowser(settingsManager.LibraryDir.JoinDir("Packages"))
665661
),
666662
Resources.Label_Packages
667-
)
663+
),
668664
];
669665

670666
#endregion
@@ -724,7 +720,7 @@ private async Task AddToGlobalStartMenu()
724720
Content = "You will be prompted for administrator privileges. Continue?",
725721
PrimaryButtonText = Resources.Action_Yes,
726722
CloseButtonText = Resources.Action_Cancel,
727-
DefaultButton = ContentDialogButton.Primary
723+
DefaultButton = ContentDialogButton.Primary,
728724
};
729725

730726
if (await dialog.ShowAsync() != ContentDialogResult.Primary)
@@ -793,7 +789,7 @@ public async Task PickNewDataDirectory()
793789
IsPrimaryButtonEnabled = false,
794790
IsSecondaryButtonEnabled = false,
795791
IsFooterVisible = false,
796-
Content = new SelectDataDirectoryDialog { DataContext = viewModel }
792+
Content = new SelectDataDirectoryDialog { DataContext = viewModel },
797793
};
798794

799795
var result = await dialog.ShowAsync();
@@ -861,34 +857,34 @@ public void LoadDebugInfo()
861857
var assembly = Assembly.GetExecutingAssembly();
862858
var appData = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
863859
DebugPaths = $"""
864-
Current Working Directory [Environment.CurrentDirectory]
865-
"{Environment.CurrentDirectory}"
866-
App Directory [Assembly.GetExecutingAssembly().Location]
867-
"{assembly.Location}"
868-
App Directory [AppContext.BaseDirectory]
869-
"{AppContext.BaseDirectory}"
870-
AppData Directory [SpecialFolder.ApplicationData]
871-
"{appData}"
872-
""";
860+
Current Working Directory [Environment.CurrentDirectory]
861+
"{Environment.CurrentDirectory}"
862+
App Directory [Assembly.GetExecutingAssembly().Location]
863+
"{assembly.Location}"
864+
App Directory [AppContext.BaseDirectory]
865+
"{AppContext.BaseDirectory}"
866+
AppData Directory [SpecialFolder.ApplicationData]
867+
"{appData}"
868+
""";
873869

874870
// 1. Check portable mode
875871
var appDir = Compat.AppCurrentDir;
876872
var expectedPortableFile = Path.Combine(appDir, "Data", ".sm-portable");
877873
var isPortableMode = File.Exists(expectedPortableFile);
878874

879875
DebugCompatInfo = $"""
880-
Platform: {Compat.Platform}
881-
AppData: {Compat.AppData}
882-
AppDataHome: {Compat.AppDataHome}
883-
AppCurrentDir: {Compat.AppCurrentDir}
884-
ExecutableName: {Compat.GetExecutableName()}
885-
AppName: {Compat.GetAppName()}
886-
-- Settings --
887-
Expected Portable Marker file: {expectedPortableFile}
888-
Portable Marker file exists: {isPortableMode}
889-
IsLibraryDirSet = {settingsManager.IsLibraryDirSet}
890-
IsPortableMode = {settingsManager.IsPortableMode}
891-
""";
876+
Platform: {Compat.Platform}
877+
AppData: {Compat.AppData}
878+
AppDataHome: {Compat.AppDataHome}
879+
AppCurrentDir: {Compat.AppCurrentDir}
880+
ExecutableName: {Compat.GetExecutableName()}
881+
AppName: {Compat.GetAppName()}
882+
-- Settings --
883+
Expected Portable Marker file: {expectedPortableFile}
884+
Portable Marker file exists: {isPortableMode}
885+
IsLibraryDirSet = {settingsManager.IsLibraryDirSet}
886+
IsPortableMode = {settingsManager.IsPortableMode}
887+
""";
892888

893889
// Get Gpu info
894890
var gpuInfo = "";
@@ -920,7 +916,7 @@ private async Task DebugContentDialog()
920916
DefaultButton = ContentDialogButton.Primary,
921917
Title = "Test title",
922918
PrimaryButtonText = Resources.Action_OK,
923-
CloseButtonText = Resources.Action_Close
919+
CloseButtonText = Resources.Action_Close,
924920
};
925921

926922
var result = await dialog.ShowAsync();
@@ -968,7 +964,7 @@ private async Task DebugMakeImageGrid()
968964

969965
var bitmap = WriteableBitmap.Decode(stream);
970966

971-
var galleryImages = new List<ImageSource> { new(bitmap), };
967+
var galleryImages = new List<ImageSource> { new(bitmap) };
972968
galleryImages.AddRange(files.Select(f => new ImageSource(f.Path.ToString())));
973969

974970
var imageBox = new ImageGalleryCard
@@ -978,7 +974,7 @@ private async Task DebugMakeImageGrid()
978974
DataContext = dialogFactory.Get<ImageGalleryCardViewModel>(vm =>
979975
{
980976
vm.ImageSources.AddRange(galleryImages);
981-
})
977+
}),
982978
};
983979

984980
var dialog = new BetterContentDialog
@@ -1045,8 +1041,8 @@ private async Task DebugTrackedDownload()
10451041
{
10461042
var textFields = new TextBoxField[]
10471043
{
1048-
new() { Label = "Url", },
1049-
new() { Label = "File path" }
1044+
new() { Label = "Url" },
1045+
new() { Label = "File path" },
10501046
};
10511047

10521048
var dialog = DialogHelper.CreateTextEntryDialog("Add download", "", textFields);
@@ -1080,7 +1076,7 @@ private async Task DebugRobocopy()
10801076
var textFields = new TextBoxField[]
10811077
{
10821078
new() { Label = "Source" },
1083-
new() { Label = "Destination" }
1079+
new() { Label = "Destination" },
10841080
};
10851081

10861082
var dialog = DialogHelper.CreateTextEntryDialog("Robocopy", "", textFields);
@@ -1113,7 +1109,7 @@ private async Task DebugRobocopy()
11131109
new CommandItem(DebugShowGitVersionSelectorDialogCommand),
11141110
new CommandItem(DebugShowMockGitVersionSelectorDialogCommand),
11151111
new CommandItem(DebugWhichCommand),
1116-
new CommandItem(DebugRobocopyCommand)
1112+
new CommandItem(DebugRobocopyCommand),
11171113
];
11181114

11191115
[RelayCommand]
@@ -1124,7 +1120,7 @@ private async Task DebugShowGitVersionSelectorDialog()
11241120
GitVersionProvider = new CachedCommandGitVersionProvider(
11251121
"https://github.com/ltdrdata/ComfyUI-Manager",
11261122
prerequisiteHelper
1127-
)
1123+
),
11281124
};
11291125
var dialog = vm.GetDialog();
11301126

@@ -1192,7 +1188,7 @@ private async Task DebugFindLocalModelFromIndex()
11921188
var textFields = new TextBoxField[]
11931189
{
11941190
new() { Label = "Blake3 Hash" },
1195-
new() { Label = "SharedFolderType" }
1191+
new() { Label = "SharedFolderType" },
11961192
};
11971193

11981194
var dialog = DialogHelper.CreateTextEntryDialog("Find Local Model", "", textFields);
@@ -1293,7 +1289,7 @@ await nativeManager.ShowNotification(
12931289
{
12941290
Title = "Test Notification",
12951291
Body = "Here is some message",
1296-
Buttons = { ("Action", "__Debug_Action"), ("Close", "__Debug_Close"), }
1292+
Buttons = { ("Action", "__Debug_Action"), ("Close", "__Debug_Close") },
12971293
}
12981294
);
12991295
}
@@ -1323,8 +1319,8 @@ private async Task DebugExtractImagePromptsToTxt()
13231319
if (files.Count == 0)
13241320
return;
13251321

1326-
var images = await Task.Run(
1327-
() => files.Select(f => LocalImageFile.FromPath(f.TryGetLocalPath()!)).ToList()
1322+
var images = await Task.Run(() =>
1323+
files.Select(f => LocalImageFile.FromPath(f.TryGetLocalPath()!)).ToList()
13281324
);
13291325

13301326
var successfulFiles = new List<LocalImageFile>();
@@ -1412,7 +1408,7 @@ private async Task OnWindowsLongPathsToggleClick()
14121408
{
14131409
Title = Resources.Label_ChangesApplied,
14141410
Content = Resources.Text_RestartMayBeRequiredForSystemChanges,
1415-
CloseButtonText = Resources.Action_Close
1411+
CloseButtonText = Resources.Action_Close,
14161412
}.ShowAsync();
14171413
}
14181414
catch (Win32Exception e)

0 commit comments

Comments
 (0)