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