mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-06-07 01:08:18 +08:00
[Hosts]Big hosts file loading fix and feedback (#24091)
This commit is contained in:
parent
a2e05b771b
commit
c819b287f3
@ -52,6 +52,9 @@ namespace Hosts.ViewModels
|
||||
[ObservableProperty]
|
||||
private string _additionalLines;
|
||||
|
||||
[ObservableProperty]
|
||||
private bool _isLoading;
|
||||
|
||||
private ObservableCollection<Entry> _entries;
|
||||
|
||||
public ObservableCollection<Entry> Entries => _filtered || _showOnlyDuplicates ? GetFilteredEntries() : _entries;
|
||||
@ -125,6 +128,7 @@ namespace Hosts.ViewModels
|
||||
public void ReadHosts()
|
||||
{
|
||||
FileChanged = false;
|
||||
IsLoading = true;
|
||||
|
||||
Task.Run(async () =>
|
||||
{
|
||||
@ -141,8 +145,10 @@ namespace Hosts.ViewModels
|
||||
|
||||
_entries.CollectionChanged += Entries_CollectionChanged;
|
||||
OnPropertyChanged(nameof(Entries));
|
||||
FindDuplicates();
|
||||
IsLoading = false;
|
||||
});
|
||||
|
||||
FindDuplicates();
|
||||
});
|
||||
}
|
||||
|
||||
@ -243,10 +249,12 @@ namespace Hosts.ViewModels
|
||||
{
|
||||
var hosts = entry.SplittedHosts;
|
||||
|
||||
entry.Duplicate = _entries.FirstOrDefault(e =>
|
||||
var duplicate = _entries.FirstOrDefault(e =>
|
||||
e != entry
|
||||
&& (string.Equals(e.Address, entry.Address, StringComparison.InvariantCultureIgnoreCase)
|
||||
|| hosts.Intersect(e.SplittedHosts, StringComparer.InvariantCultureIgnoreCase).Any())) != null;
|
||||
|
||||
_dispatcherQueue.TryEnqueue(DispatcherQueuePriority.Low, () => entry.Duplicate = duplicate);
|
||||
}
|
||||
|
||||
private ObservableCollection<Entry> GetFilteredEntries()
|
||||
|
@ -26,6 +26,10 @@
|
||||
NotEmptyValue="Visible" />
|
||||
<converters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
<converters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<converters:BoolToVisibilityConverter
|
||||
x:Key="BoolToInvertedVisibilityConverter"
|
||||
TrueValue="Collapsed"
|
||||
FalseValue="Visible" />
|
||||
</Page.Resources>
|
||||
|
||||
<Grid>
|
||||
@ -194,7 +198,8 @@
|
||||
IsItemClickEnabled="True"
|
||||
ItemClick="Entries_ItemClick"
|
||||
ItemsSource="{Binding Entries, Mode=TwoWay}"
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}">
|
||||
SelectedItem="{Binding Selected, Mode=TwoWay}"
|
||||
Visibility="{x:Bind ViewModel.IsLoading, Converter={StaticResource BoolToInvertedVisibilityConverter}, Mode=OneWay}">
|
||||
<ListView.ItemTemplate>
|
||||
<DataTemplate x:DataType="models:Entry">
|
||||
<Grid
|
||||
@ -333,6 +338,12 @@
|
||||
</ListView.ItemTemplate>
|
||||
</ListView>
|
||||
|
||||
<ProgressRing
|
||||
Width="48"
|
||||
Height="48"
|
||||
Grid.Row="1"
|
||||
IsActive="{x:Bind ViewModel.IsLoading, Mode=OneWay}" />
|
||||
|
||||
<ContentDialog
|
||||
x:Name="EntryDialog"
|
||||
x:Uid="EntryDialog"
|
||||
|
Loading…
Reference in New Issue
Block a user