Files
fluid-explorer/Views/SettingsDialog.xaml.cs
T

141 lines
4.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using FluidExplorer.Services;
using FluidExplorer.ViewModels;
using Microsoft.UI.Xaml.Controls;
namespace FluidExplorer.Views;
/// <summary>设置对话框:改动即时生效并写入 settings.json。</summary>
public sealed partial class SettingsDialog : ContentDialog
{
private readonly MainViewModel _main;
private bool _initializing = true;
public SettingsDialog(MainViewModel main)
{
_main = main;
InitializeComponent();
ThemeBox.SelectedIndex = main.ThemeMode switch
{
AppThemeMode.Light => 1,
AppThemeMode.Dark => 2,
_ => 0
};
AnimationSwitch.IsOn = main.AnimationsEnabled;
HiddenSwitch.IsOn = main.ShowHiddenFiles;
SystemSwitch.IsOn = main.ShowSystemFiles;
ExtensionSwitch.IsOn = main.ShowFileExtensions;
CheckBoxSwitch.IsOn = main.AlwaysShowCheckBoxes;
NewTabSwitch.IsOn = main.Settings.OpenFoldersInNewTab;
ScopeSwitch.IsOn = main.SearchInCurrentFolderOnly;
AsYouTypeSwitch.IsOn = main.Settings.SearchAsYouType;
IndexStartupSwitch.IsOn = main.Settings.IndexOnStartup;
RecycleSwitch.IsOn = main.DeleteToRecycleBin;
ConflictBox.SelectedIndex = main.Settings.DefaultConflictPolicy switch
{
ConflictPolicySetting.Replace => 1,
ConflictPolicySetting.Skip => 2,
ConflictPolicySetting.KeepBoth => 3,
_ => 0
};
IndexStatusText.Text = $"{main.IndexSummary}({Environment.ProcessorCount} 核并行扫描;NTFS 索引可让全盘搜索稳定在毫秒级)";
_initializing = false;
}
private void OnThemeChanged(object sender, SelectionChangedEventArgs e)
{
if (_initializing) return;
_main.ThemeMode = ThemeBox.SelectedIndex switch
{
1 => AppThemeMode.Light,
2 => AppThemeMode.Dark,
_ => AppThemeMode.System
};
}
private void OnAnimationToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.AnimationsEnabled = AnimationSwitch.IsOn;
}
private void OnHiddenToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.ShowHiddenFiles = HiddenSwitch.IsOn;
}
private void OnSystemToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.ShowSystemFiles = SystemSwitch.IsOn;
}
private void OnExtensionToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.ShowFileExtensions = ExtensionSwitch.IsOn;
}
private void OnCheckBoxToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.AlwaysShowCheckBoxes = CheckBoxSwitch.IsOn;
}
private void OnNewTabToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.Settings.OpenFoldersInNewTab = NewTabSwitch.IsOn;
_main.Settings.Save();
}
private void OnScopeToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.SearchInCurrentFolderOnly = ScopeSwitch.IsOn;
}
private void OnAsYouTypeToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.Settings.SearchAsYouType = AsYouTypeSwitch.IsOn;
_main.Settings.Save();
}
private void OnIndexStartupToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.Settings.IndexOnStartup = IndexStartupSwitch.IsOn;
_main.Settings.Save();
}
private void OnRecycleToggled(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
if (_initializing) return;
_main.DeleteToRecycleBin = RecycleSwitch.IsOn;
}
private void OnConflictChanged(object sender, SelectionChangedEventArgs e)
{
if (_initializing) return;
_main.Settings.DefaultConflictPolicy = ConflictBox.SelectedIndex switch
{
1 => ConflictPolicySetting.Replace,
2 => ConflictPolicySetting.Skip,
3 => ConflictPolicySetting.KeepBoth,
_ => ConflictPolicySetting.Ask
};
_main.Settings.Save();
}
private void OnBuildIndexClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
{
_main.BuildIndexCommand.Execute(null);
IndexStatusText.Text = "正在建立索引…(首次读取 MFT 通常几秒内完成,之后靠 USN 增量保持实时)";
}
private void OnRestartElevatedClick(object sender, Microsoft.UI.Xaml.RoutedEventArgs e)
=> _main.RestartElevatedCommand.Execute(null);
}