Files
PowerToys/src/modules/cmdpal/Microsoft.CmdPal.UI.ViewModels/FallbackSettingsViewModel.cs
Michael Jolley ba9585a663 Migrate Microsoft.CmdPal.Core.ViewModels into Microsoft.CmdPal.UI.ViewModels
- Move all source files from Core.ViewModels to UI.ViewModels
- Update namespace from Microsoft.CmdPal.Core.ViewModels to Microsoft.CmdPal.UI.ViewModels
- Remove Core.ViewModels project from solution files
- Update all using statements in dependent projects
- Delete the Core folder which is now empty
2026-01-26 16:34:38 -06:00

87 lines
2.5 KiB
C#

// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Messaging;
using Microsoft.CmdPal.UI.ViewModels;
using Microsoft.CmdPal.UI.ViewModels.Messages;
namespace Microsoft.CmdPal.UI.ViewModels;
public partial class FallbackSettingsViewModel : ObservableObject
{
private readonly SettingsModel _settings;
private readonly FallbackSettings _fallbackSettings;
public string DisplayName { get; private set; } = string.Empty;
public IconInfoViewModel Icon { get; private set; } = new(null);
public string Id { get; private set; } = string.Empty;
public bool IsEnabled
{
get => _fallbackSettings.IsEnabled;
set
{
if (value != _fallbackSettings.IsEnabled)
{
_fallbackSettings.IsEnabled = value;
if (!_fallbackSettings.IsEnabled)
{
_fallbackSettings.IncludeInGlobalResults = false;
}
Save();
OnPropertyChanged(nameof(IsEnabled));
}
}
}
public bool IncludeInGlobalResults
{
get => _fallbackSettings.IncludeInGlobalResults;
set
{
if (value != _fallbackSettings.IncludeInGlobalResults)
{
_fallbackSettings.IncludeInGlobalResults = value;
if (!_fallbackSettings.IsEnabled)
{
_fallbackSettings.IsEnabled = true;
}
Save();
OnPropertyChanged(nameof(IncludeInGlobalResults));
}
}
}
public FallbackSettingsViewModel(
TopLevelViewModel fallback,
FallbackSettings fallbackSettings,
SettingsModel settingsModel,
ProviderSettingsViewModel providerSettings)
{
_settings = settingsModel;
_fallbackSettings = fallbackSettings;
Id = fallback.Id;
DisplayName = string.IsNullOrWhiteSpace(fallback.DisplayTitle)
? (string.IsNullOrWhiteSpace(fallback.Title) ? providerSettings.DisplayName : fallback.Title)
: fallback.DisplayTitle;
Icon = new(fallback.InitialIcon);
Icon.InitializeProperties();
}
private void Save()
{
SettingsModel.SaveSettings(_settings);
WeakReferenceMessenger.Default.Send<ReloadCommandsMessage>(new());
}
}