-
Notifications
You must be signed in to change notification settings - Fork 852
Expand file tree
/
Copy pathPackageManagerPage.axaml.cs
More file actions
595 lines (531 loc) · 25.5 KB
/
Copy pathPackageManagerPage.axaml.cs
File metadata and controls
595 lines (531 loc) · 25.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
using Avalonia.Automation;
using Avalonia.Controls;
using Avalonia.Input.Platform;
using Avalonia.Layout;
using Avalonia.Media;
using UniGetUI.Avalonia.Infrastructure;
using UniGetUI.Avalonia.ViewModels;
using UniGetUI.Avalonia.ViewModels.Pages.SettingsPages;
using UniGetUI.Avalonia.Views.Controls;
using UniGetUI.Avalonia.Views.Controls.Settings;
using UniGetUI.Core.SettingsEngine.SecureSettings;
using UniGetUI.Core.Tools;
using UniGetUI.Interface.Enums;
using UniGetUI.PackageEngine.Interfaces;
using UniGetUI.PackageEngine.ManagerClasses.Manager;
using UniGetUI.PackageEngine.Managers.VcpkgManager;
using CoreSettings = UniGetUI.Core.SettingsEngine.Settings;
using CornerRadius = global::Avalonia.CornerRadius;
using Thickness = global::Avalonia.Thickness;
namespace UniGetUI.Avalonia.Views.Pages.SettingsPages;
public sealed partial class PackageManagerPage : UserControl, ISettingsPage
{
private PackageManagerViewModel ViewModel => (PackageManagerViewModel)DataContext!;
public bool CanGoBack => true;
public string ShortTitle => ViewModel.PageTitle;
public event EventHandler? RestartRequired;
public event EventHandler<Type>? NavigationRequested;
public PackageManagerPage(IPackageManager manager)
{
DataContext = new PackageManagerViewModel(manager);
InitializeComponent();
ViewModel.PropertyChanged += (_, e) =>
{
if (e.PropertyName is nameof(PackageManagerViewModel.Severity)
or nameof(PackageManagerViewModel.StatusTitle)
or nameof(PackageManagerViewModel.StatusMessage))
ApplyStatusBrushes();
};
ViewModel.RestartRequired += (s, e) => RestartRequired?.Invoke(s, e);
ViewModel.NavigateToAdministratorRequested += (_, _) => NavigationRequested?.Invoke(this, typeof(Administrator));
BuildPage();
ApplyStatusBrushes();
}
// ── Dynamic UI construction ───────────────────────────────────────────────
private void BuildPage()
{
var manager = ViewModel.Manager;
// ── Enable/Disable toggle
EnableManager.DictionaryName = CoreSettings.K.DisabledManagers;
EnableManager.KeyName = manager.Name;
EnableManager.Text = CoreTools.Translate("Enable {pm}").Replace("{pm}", manager.DisplayName);
ExtraControls.IsEnabled = manager.IsEnabled();
EnableManager.StateChanged += (_, _) =>
{
ExtraControls.IsEnabled = manager.IsEnabled();
_ = ViewModel.ReloadManagerCommand.ExecuteAsync(null);
};
// ── Executable picker card
bool customPathsAllowed = SecureSettings.Get(SecureSettings.K.AllowCustomManagerPaths);
var execGrid = new Grid
{
ColumnDefinitions = new ColumnDefinitions("*,Auto"),
RowDefinitions = new RowDefinitions("Auto,Auto,Auto"),
HorizontalAlignment = HorizontalAlignment.Stretch,
};
var execHint = new TextBlock
{
Text = CoreTools.Translate("Not finding the file you are looking for? Make sure it has been added to path."),
FontSize = 12,
FontWeight = FontWeight.SemiBold,
Opacity = 0.7,
TextWrapping = TextWrapping.Wrap,
};
Grid.SetColumnSpan(execHint, 2);
execGrid.Children.Add(execHint);
var execCombo = new ComboBox { HorizontalAlignment = HorizontalAlignment.Stretch };
AutomationProperties.SetName(execCombo, CoreTools.Translate("Select the executable to be used. The following list shows the executables found by UniGetUI"));
foreach (var path in manager.FindCandidateExecutableFiles())
execCombo.Items.Add(path);
string savedPath = CoreSettings.GetDictionaryItem<string, string>(CoreSettings.K.ManagerPaths, manager.Name) ?? "";
if (string.IsNullOrEmpty(savedPath))
{
var (found, path) = manager.GetExecutableFile();
savedPath = found ? path : "";
}
execCombo.SelectedItem = savedPath;
execCombo.IsEnabled = customPathsAllowed;
execCombo.SelectionChanged += (s, _) =>
{
if (s is ComboBox combo && combo.SelectedItem?.ToString() is { Length: > 0 } selected)
ViewModel.OnExecutableSelected(selected);
};
Grid.SetRow(execCombo, 1);
Grid.SetColumnSpan(execCombo, 2);
execGrid.Children.Add(execCombo);
if (!customPathsAllowed)
{
var securityWarning = new TextBlock
{
Text = CoreTools.Translate("For security reasons, changing the executable file is disabled by default"),
FontSize = 12,
FontWeight = FontWeight.SemiBold,
Opacity = 0.7,
TextWrapping = TextWrapping.Wrap,
Classes = { "setting-warning-text" },
};
Grid.SetRow(securityWarning, 2);
execGrid.Children.Add(securityWarning);
var goToSecureBtn = new Button
{
Content = new TextBlock { Text = CoreTools.Translate("Change this"), FontSize = 12, Classes = { "hyperlink" } },
Background = Brushes.Transparent,
BorderThickness = new Thickness(0),
Padding = new Thickness(0),
};
goToSecureBtn.Click += (_, _) => ViewModel.NavigateToAdministratorCommand.Execute(null);
Grid.SetRow(goToSecureBtn, 2);
Grid.SetColumn(goToSecureBtn, 1);
execGrid.Children.Add(goToSecureBtn);
}
ExecutableHolder.Content = new SettingsCard
{
BorderThickness = new Thickness(1, 0, 1, 0),
CornerRadius = new CornerRadius(0),
Header = CoreTools.Translate("Select the executable to be used. The following list shows the executables found by UniGetUI"),
Description = execGrid,
Margin = new Thickness(0, 2, 0, 2),
};
// ── Current path card
var copyIcon = new SvgIcon
{
Path = "avares://UniGetUI.Avalonia/Assets/Symbols/copy.svg",
Width = 24,
Height = 24,
};
var copyBtn = new Button
{
Content = copyIcon,
Padding = new Thickness(8),
VerticalAlignment = VerticalAlignment.Center,
Background = Brushes.Transparent,
BorderThickness = new Thickness(0),
};
AutomationProperties.SetName(copyBtn, CoreTools.Translate("Copy path"));
var pathCard = new SettingsCard
{
BorderThickness = new Thickness(1, 0, 1, 1),
CornerRadius = new CornerRadius(0, 0, 8, 8),
Header = CoreTools.Translate("Current executable file:"),
Content = copyBtn,
};
var pathLabel = new TextBlock
{
FontFamily = new FontFamily("Courier New"),
FontSize = 14,
TextWrapping = TextWrapping.Wrap,
};
pathLabel.Text = ViewModel.PathLabelText;
ViewModel.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(PackageManagerViewModel.PathLabelText))
pathLabel.Text = ViewModel.PathLabelText;
};
pathCard.Description = pathLabel;
copyBtn.Click += (_, _) => _ = CopyPathAndFlashIcon(pathLabel.Text, copyBtn, copyIcon);
PathHolder.Content = pathCard;
// ── Install options panel
var installOptions = new InstallOptionsPanel(manager);
installOptions.NavigateToAdministratorRequested += (_, _) =>
NavigationRequested?.Invoke(this, typeof(Administrator));
InstallOptionsHolder.Content = installOptions;
// ── Disable notifications card
var disableNotifsCard = new CheckboxCard_Dict
{
Text = CoreTools.Translate("Ignore packages from {pm} when showing a notification about updates")
.Replace("{pm}", manager.DisplayName),
DictionaryName = CoreSettings.K.DisabledPackageManagerNotifications,
ForceInversion = true,
KeyName = manager.Name,
};
BuildExtraControls(disableNotifsCard);
// ── Per-manager minimum update age
ExtraControls.Children.Add(new TextBlock
{
Margin = new Thickness(44, 24, 4, 8),
FontWeight = FontWeight.SemiBold,
Text = CoreTools.Translate("Update security"),
});
(string Label, string Value)[] ageItems =
[
(CoreTools.Translate("Use global setting"), ""),
(CoreTools.Translate("No minimum age"), "0"),
(CoreTools.Translate("1 day"), "1"),
(CoreTools.Translate("{0} days", 3), "3"),
(CoreTools.Translate("{0} days", 7), "7"),
(CoreTools.Translate("{0} days", 14), "14"),
(CoreTools.Translate("{0} days", 30), "30"),
(CoreTools.Translate("Custom..."), "custom"),
];
var ageCombo = new ComboBox { MinWidth = 200 };
AutomationProperties.SetName(ageCombo, CoreTools.Translate("Minimum age for updates"));
foreach (var (label, _) in ageItems)
ageCombo.Items.Add(label);
string? savedAge = CoreSettings.GetDictionaryItem<string, string>(
CoreSettings.K.PerManagerMinimumUpdateAge, manager.Name);
int savedAgeIdx = Array.FindIndex(ageItems, i => i.Value == (savedAge ?? ""));
ageCombo.SelectedIndex = savedAgeIdx >= 0 ? savedAgeIdx : 0;
var customAgeInput = new TextBox
{
MinWidth = 200,
PlaceholderText = CoreTools.Translate("e.g. 10"),
[AutomationProperties.NameProperty] = CoreTools.Translate("Custom minimum age (days)"),
Text = CoreSettings.GetDictionaryItem<string, string>(
CoreSettings.K.PerManagerMinimumUpdateAgeCustom, manager.Name) ?? "",
};
customAgeInput.TextChanged += (_, _) =>
{
string current = customAgeInput.Text ?? "";
string filtered = string.Concat(current.Where(char.IsDigit));
if (filtered != current)
{
customAgeInput.Text = filtered;
return;
}
if (filtered.Length > 0)
CoreSettings.SetDictionaryItem(
CoreSettings.K.PerManagerMinimumUpdateAgeCustom, manager.Name, filtered);
else
CoreSettings.RemoveDictionaryKey<string, string>(
CoreSettings.K.PerManagerMinimumUpdateAgeCustom, manager.Name);
};
bool initiallyCustom = savedAge == "custom";
var releaseDateSupport = manager.Capabilities.KnowsPackageReleaseDate;
bool ageSupported = releaseDateSupport != PackageReleaseDateSupport.No;
object ageDescription = releaseDateSupport switch
{
PackageReleaseDateSupport.No => new TextBlock
{
Text = CoreTools.Translate("{pm} does not provide release dates for its packages, so this setting will have no effect")
.Replace("{pm}", manager.DisplayName),
Foreground = new SolidColorBrush(Color.Parse("#e05252")),
TextWrapping = TextWrapping.Wrap,
FontSize = 12,
},
PackageReleaseDateSupport.Partial => new TextBlock
{
Text = CoreTools.Translate("{pm} only provides release dates for some of its packages, so this setting will only apply to those packages")
.Replace("{pm}", manager.DisplayName),
Foreground = new SolidColorBrush(Color.FromRgb(224, 168, 0)),
TextWrapping = TextWrapping.Wrap,
FontSize = 12,
},
_ => CoreTools.Translate("Override the global minimum update age for this package manager"),
};
ageCombo.IsEnabled = ageSupported;
customAgeInput.IsEnabled = ageSupported;
var minimumAgeCard = new SettingsCard
{
Header = CoreTools.Translate("Minimum age for updates"),
Description = ageDescription,
Content = ageCombo,
CornerRadius = initiallyCustom ? new CornerRadius(8, 8, 0, 0) : new CornerRadius(8),
BorderThickness = new Thickness(1),
};
var customAgeCard = new SettingsCard
{
Header = CoreTools.Translate("Custom minimum age (days)"),
Content = customAgeInput,
IsVisible = initiallyCustom,
CornerRadius = new CornerRadius(0, 0, 8, 8),
BorderThickness = new Thickness(1, 0, 1, 1),
};
ageCombo.SelectionChanged += (_, _) =>
{
int idx = ageCombo.SelectedIndex;
if (idx < 0) return;
string val = ageItems[idx].Value;
bool isCustom = val == "custom";
customAgeCard.IsVisible = isCustom;
minimumAgeCard.CornerRadius = isCustom ? new CornerRadius(8, 8, 0, 0) : new CornerRadius(8);
if (string.IsNullOrEmpty(val))
CoreSettings.RemoveDictionaryKey<string, string>(
CoreSettings.K.PerManagerMinimumUpdateAge, manager.Name);
else
CoreSettings.SetDictionaryItem(
CoreSettings.K.PerManagerMinimumUpdateAge, manager.Name, val);
};
ExtraControls.Children.Add(minimumAgeCard);
ExtraControls.Children.Add(customAgeCard);
// ── Logs card
ManagerLogs.Text = CoreTools.Translate("View {0} logs", manager.DisplayName);
ManagerLogs.Icon = UniGetUI.Interface.Enums.IconType.Console;
ManagerLogs.Click += (_, _) =>
{
if (TopLevel.GetTopLevel(this) is Window { DataContext: MainWindowViewModel vm })
vm.OpenManagerLogs(manager);
};
// ── pip AppExecution Alias warning
if (manager.Name == "Pip")
{
ManagerLogs.CornerRadius = new CornerRadius(8, 8, 0, 0);
AppExecutionAliasWarning.IsVisible = true;
AppExecutionAliasLabel.Text = CoreTools.Translate(
"If Python cannot be found or is not listing packages but is installed on the system, " +
"you may need to disable the \"python.exe\" App Execution Alias in the settings.");
}
}
private void BuildExtraControls(CheckboxCard_Dict disableNotifsCard)
{
ExtraControls.Children.Clear();
var manager = ViewModel.Manager;
bool managerHasSources = manager.Capabilities.SupportsCustomSources && manager.Name != "vcpkg";
if (managerHasSources)
{
ExtraControls.Children.Add(new SourceManagerCard(manager)
{
Margin = new Thickness(0, 0, 0, 16),
});
ExtraControls.Children.Add(new TextBlock
{
Margin = new Thickness(44, 24, 4, 8),
FontWeight = FontWeight.SemiBold,
Text = CoreTools.Translate("Advanced options"),
});
}
switch (manager.Name)
{
case "Winget":
disableNotifsCard.CornerRadius = new CornerRadius(8, 8, 0, 0);
disableNotifsCard.BorderThickness = new Thickness(1, 1, 1, 0);
ExtraControls.Children.Add(disableNotifsCard);
var wingetCliToolPreference = new ComboboxCard
{
Text = CoreTools.Translate("WinGet command-line tool"),
Description = CoreTools.Translate(
"Choose which command-line tool UniGetUI uses for WinGet operations when the COM API is not used"
),
SettingName = CoreSettings.K.WinGetCliToolPreference,
CornerRadius = new CornerRadius(0),
BorderThickness = new Thickness(1, 0, 1, 1),
};
wingetCliToolPreference.AddItem("Default", "default");
wingetCliToolPreference.AddItem("WinGet", "winget", false);
wingetCliToolPreference.AddItem("Pinget", "pinget", false);
wingetCliToolPreference.ShowAddedItems();
wingetCliToolPreference.ValueChanged += (_, _) =>
_ = ViewModel.ReloadManagerCommand.ExecuteAsync(null);
ExtraControls.Children.Add(wingetCliToolPreference);
var wingetComApiPolicy = new ComboboxCard
{
Text = CoreTools.Translate("WinGet COM API"),
Description = CoreTools.Translate(
"Choose whether UniGetUI can use the WinGet COM API before falling back to the command-line tool"
),
SettingName = CoreSettings.K.WinGetComApiPolicy,
CornerRadius = new CornerRadius(0),
BorderThickness = new Thickness(1, 0, 1, 1),
};
wingetComApiPolicy.AddItem("Default", "default");
wingetComApiPolicy.AddItem("Enabled", "enabled");
wingetComApiPolicy.AddItem("Disabled", "disabled");
wingetComApiPolicy.ShowAddedItems();
wingetComApiPolicy.ValueChanged += (_, _) =>
_ = ViewModel.ReloadManagerCommand.ExecuteAsync(null);
ExtraControls.Children.Add(wingetComApiPolicy);
var wingetResetBtn = new ButtonCard
{
Text = CoreTools.Translate("Reset WinGet")
+ $" ({CoreTools.Translate("This may help if no packages are listed")})",
ButtonText = CoreTools.AutoTranslated("Reset"),
CornerRadius = new CornerRadius(0),
BorderThickness = new Thickness(1, 0, 1, 1),
};
wingetResetBtn.Click += (_, _) => _ = AvaloniaPackageOperationHelper.HandleBrokenWinGetAsync();
ExtraControls.Children.Add(wingetResetBtn);
ExtraControls.Children.Add(new CheckboxCard
{
Text = CoreTools.Translate("Force install location parameter when updating packages with custom locations"),
SettingName = CoreSettings.K.WinGetForceLocationOnUpdate,
CornerRadius = new CornerRadius(0, 0, 8, 8),
BorderThickness = new Thickness(1, 0, 1, 1),
});
break;
case "Scoop":
disableNotifsCard.CornerRadius = new CornerRadius(8, 8, 0, 0);
disableNotifsCard.BorderThickness = new Thickness(1, 1, 1, 0);
ExtraControls.Children.Add(disableNotifsCard);
var scoopInstall = new ButtonCard
{
Text = CoreTools.AutoTranslated("Install Scoop"),
ButtonText = CoreTools.AutoTranslated("Install"),
CornerRadius = new CornerRadius(0),
};
scoopInstall.Click += (_, _) => ViewModel.ScoopInstallCommand.Execute(null);
ExtraControls.Children.Add(scoopInstall);
var scoopUninstall = new ButtonCard
{
Text = CoreTools.AutoTranslated("Uninstall Scoop (and its packages)"),
ButtonText = CoreTools.AutoTranslated("Uninstall"),
CornerRadius = new CornerRadius(0),
BorderThickness = new Thickness(1, 0, 1, 0),
};
scoopUninstall.Click += (_, _) => ViewModel.ScoopUninstallCommand.Execute(null);
ExtraControls.Children.Add(scoopUninstall);
var scoopCleanup = new ButtonCard
{
Text = CoreTools.AutoTranslated("Run cleanup and clear cache"),
ButtonText = CoreTools.AutoTranslated("Run"),
CornerRadius = new CornerRadius(0),
};
scoopCleanup.Click += (_, _) => ViewModel.ScoopCleanupCommand.Execute(null);
ExtraControls.Children.Add(scoopCleanup);
ExtraControls.Children.Add(new CheckboxCard
{
CornerRadius = new CornerRadius(0, 0, 8, 8),
BorderThickness = new Thickness(1, 0, 1, 1),
SettingName = CoreSettings.K.EnableScoopCleanup,
Text = CoreTools.AutoTranslated("Enable Scoop cleanup on launch"),
});
break;
case "Bun":
disableNotifsCard.CornerRadius = new CornerRadius(8, 8, 0, 0);
disableNotifsCard.BorderThickness = new Thickness(1, 1, 1, 0);
ExtraControls.Children.Add(disableNotifsCard);
ExtraControls.Children.Add(new CheckboxCard
{
CornerRadius = new CornerRadius(0, 0, 8, 8),
BorderThickness = new Thickness(1, 0, 1, 1),
SettingName = CoreSettings.K.BunPreferLatestVersions,
Text = CoreTools.Translate("Prefer latest versions (may include breaking changes) instead of recommended safe updates"),
});
break;
case "vcpkg":
disableNotifsCard.CornerRadius = new CornerRadius(8, 8, 0, 0);
disableNotifsCard.BorderThickness = new Thickness(1, 1, 1, 0);
ExtraControls.Children.Add(disableNotifsCard);
CoreSettings.SetValue(CoreSettings.K.DefaultVcpkgTriplet, Vcpkg.GetDefaultTriplet());
var vcpkgTriplet = new ComboboxCard
{
Text = CoreTools.Translate("Default vcpkg triplet"),
SettingName = CoreSettings.K.DefaultVcpkgTriplet,
CornerRadius = new CornerRadius(0),
};
foreach (string triplet in Vcpkg.GetSystemTriplets())
vcpkgTriplet.AddItem(triplet, triplet, false);
vcpkgTriplet.ShowAddedItems();
ExtraControls.Children.Add(vcpkgTriplet);
ExtraControls.Children.Add(BuildVcpkgRootCard());
break;
default:
disableNotifsCard.CornerRadius = new CornerRadius(8);
disableNotifsCard.BorderThickness = new Thickness(1);
ExtraControls.Children.Add(disableNotifsCard);
break;
}
}
private ButtonCard BuildVcpkgRootCard()
{
var vcpkgRootCard = new ButtonCard
{
Text = CoreTools.AutoTranslated("Change vcpkg root location"),
ButtonText = CoreTools.AutoTranslated("Select"),
CornerRadius = new CornerRadius(0, 0, 8, 8),
BorderThickness = new Thickness(1, 0, 1, 1),
};
var rootLabel = new TextBlock
{
VerticalAlignment = VerticalAlignment.Center,
Text = ViewModel.VcpkgRootPath,
};
var resetBtn = new Button
{
Content = CoreTools.Translate("Reset"),
IsEnabled = ViewModel.IsCustomVcpkgRootSet,
Margin = new Thickness(4, 0),
};
AutomationProperties.SetName(resetBtn, CoreTools.Translate("Reset vcpkg root location"));
var openBtn = new Button
{
Content = CoreTools.Translate("Open"),
IsEnabled = ViewModel.IsCustomVcpkgRootSet,
Margin = new Thickness(4, 0),
};
AutomationProperties.SetName(openBtn, CoreTools.Translate("Open vcpkg root location"));
ViewModel.PropertyChanged += (_, e) =>
{
if (e.PropertyName == nameof(PackageManagerViewModel.VcpkgRootPath))
rootLabel.Text = ViewModel.VcpkgRootPath;
if (e.PropertyName == nameof(PackageManagerViewModel.IsCustomVcpkgRootSet))
{
resetBtn.IsEnabled = ViewModel.IsCustomVcpkgRootSet;
openBtn.IsEnabled = ViewModel.IsCustomVcpkgRootSet;
}
};
resetBtn.Click += (_, _) => ViewModel.ResetVcpkgRootCommand.Execute(null);
openBtn.Click += (_, _) => ViewModel.OpenVcpkgRootCommand.Execute(null);
var descPanel = new StackPanel { Orientation = Orientation.Horizontal, Spacing = 4 };
descPanel.Children.Add(rootLabel);
descPanel.Children.Add(resetBtn);
descPanel.Children.Add(openBtn);
vcpkgRootCard.Description = descPanel;
vcpkgRootCard.Command = ViewModel.PickVcpkgRootCommand;
vcpkgRootCard.CommandParameter = vcpkgRootCard;
return vcpkgRootCard;
}
// ── View-only: brush lookup (needs ActualThemeVariant) ───────────────────
private void ApplyStatusBrushes()
{
StatusBar.Classes.Remove("status-success");
StatusBar.Classes.Remove("status-warning");
StatusBar.Classes.Remove("status-error");
StatusBar.Classes.Remove("status-info");
string cls = ViewModel.Severity switch
{
ManagerStatusSeverity.Success => "status-success",
ManagerStatusSeverity.Warning => "status-warning",
ManagerStatusSeverity.Error => "status-error",
_ => "status-info",
};
StatusBar.Classes.Add(cls);
}
private async Task CopyPathAndFlashIcon(string? text, Button btn, SvgIcon icon)
{
if (string.IsNullOrEmpty(text)) return;
if (TopLevel.GetTopLevel(this)?.Clipboard is { } clipboard)
await clipboard.SetTextAsync(text);
btn.Content = new TextBlock { Text = "✓", FontSize = 20, VerticalAlignment = VerticalAlignment.Center };
await Task.Delay(1000);
btn.Content = icon;
}
}