mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
## Summary of the Pull Request Adds a new Hosts File Editor setting “No leading spaces” that prevents prepending spaces to active lines when saving the hosts file (when any entry is disabled). Default is Off to preserve current behavior. ## PR Checklist - [x] Closes: #36386 - [ ] Communication: N/A (small, scoped option) - [x] Tests: Added/updated and all pass - [x] Localization: New en-US strings added; other locales handled by loc pipeline - [ ] Dev docs: N/A - [x] New binaries: None - [x] Documentation updated: N/A ## Detailed Description of the Pull Request / Additional comments - Settings surface: - `src/settings-ui/Settings.UI.Library/HostsProperties.cs`: add `NoLeadingSpaces` - `src/modules/Hosts/HostsUILib/Settings/IUserSettings.cs`: add `NoLeadingSpaces` - `src/modules/Hosts/Hosts/Settings/UserSettings.cs`: load/save value from settings.json - `src/settings-ui/Settings.UI/ViewModels/HostsViewModel.cs`: expose `NoLeadingSpaces` - `src/settings-ui/Settings.UI/SettingsXAML/Views/HostsPage.xaml`: new SettingsCard toggle - `src/settings-ui/Settings.UI/Strings/en-us/Resources.resw`: add `Hosts_NoLeadingSpaces.Header/Description` - Writer change: - `src/modules/Hosts/HostsUILib/Helpers/HostsService.cs`: gate indent with `anyDisabled && !_userSettings.NoLeadingSpaces` - Tests: - `src/modules/Hosts/Hosts.Tests/HostsServiceTest.cs`: `NoLeadingSpaces_Disabled_RemovesIndent` Backward compatibility: default Off, current formatting unchanged unless the user enables the option. ## Validation Steps Performed - Automated: `HostsEditor.UnitTests` including `NoLeadingSpaces_Disabled_RemovesIndent` passing. - Manual: 1. Run PowerToys (runner) as Admin. 2. Settings → Hosts File Editor → enable “No leading spaces”. 3. In editor, add active `127.0.0.10 example1` and disabled `127.0.0.11 example2`; Save. 4. Open `C:\Windows\System32\drivers\etc\hosts` in Notepad. - ON: active line starts at column 0; disabled is `# 127...`. - OFF: active line begins with two spaces when a disabled entry exists.
77 lines
5.1 KiB
XML
77 lines
5.1 KiB
XML
<Page
|
|
x:Class="Microsoft.PowerToys.Settings.UI.Views.HostsPage"
|
|
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
|
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
|
xmlns:controls="using:Microsoft.PowerToys.Settings.UI.Controls"
|
|
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
|
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
|
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
|
xmlns:ui="using:CommunityToolkit.WinUI"
|
|
mc:Ignorable="d">
|
|
|
|
<controls:SettingsPageControl x:Uid="Hosts" ModuleImageSource="ms-appx:///Assets/Settings/Modules/HostsFileEditor.png">
|
|
<controls:SettingsPageControl.ModuleContent>
|
|
<StackPanel ChildrenTransitions="{StaticResource SettingsCardsAnimations}" Orientation="Vertical">
|
|
<tkcontrols:SettingsCard
|
|
x:Uid="Hosts_EnableToggleControl_HeaderText"
|
|
HeaderIcon="{ui:BitmapIcon Source=/Assets/Settings/Icons/Hosts.png}"
|
|
IsEnabled="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay, Converter={StaticResource BoolNegationConverter}}">
|
|
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.IsEnabled, Mode=TwoWay}" />
|
|
</tkcontrols:SettingsCard>
|
|
<InfoBar
|
|
x:Uid="GPO_SettingIsManaged"
|
|
IsClosable="False"
|
|
IsOpen="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}"
|
|
IsTabStop="{x:Bind ViewModel.IsEnabledGpoConfigured, Mode=OneWay}"
|
|
Severity="Informational">
|
|
<InfoBar.IconSource>
|
|
<FontIconSource FontFamily="{StaticResource SymbolThemeFontFamily}" Glyph="" />
|
|
</InfoBar.IconSource>
|
|
</InfoBar>
|
|
<controls:SettingsGroup x:Uid="Hosts_Activation_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
|
<tkcontrols:SettingsCard
|
|
x:Uid="Hosts_LaunchButtonControl"
|
|
ActionIcon="{ui:FontIcon Glyph=}"
|
|
Command="{x:Bind ViewModel.LaunchEventHandler}"
|
|
HeaderIcon="{ui:FontIcon Glyph=}"
|
|
IsClickEnabled="True" />
|
|
<tkcontrols:SettingsCard
|
|
x:Uid="Hosts_Toggle_LaunchAdministrator"
|
|
HeaderIcon="{ui:FontIcon Glyph=}"
|
|
IsEnabled="{x:Bind ViewModel.LaunchAdministratorEnabled, Mode=OneWay}">
|
|
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.LaunchAdministrator, Mode=TwoWay}" />
|
|
</tkcontrols:SettingsCard>
|
|
<tkcontrols:SettingsCard x:Uid="Hosts_Toggle_ShowStartupWarning" HeaderIcon="{ui:FontIcon Glyph=}">
|
|
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.ShowStartupWarning, Mode=TwoWay}" />
|
|
</tkcontrols:SettingsCard>
|
|
</controls:SettingsGroup>
|
|
|
|
<controls:SettingsGroup x:Uid="Hosts_Behavior_GroupSettings" IsEnabled="{x:Bind ViewModel.IsEnabled, Mode=OneWay}">
|
|
<tkcontrols:SettingsCard x:Uid="Hosts_AdditionalLinesPosition" HeaderIcon="{ui:FontIcon Glyph=}">
|
|
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.AdditionalLinesPosition, Mode=TwoWay}">
|
|
<ComboBoxItem x:Uid="Hosts_AdditionalLinesPosition_Top" />
|
|
<ComboBoxItem x:Uid="Hosts_AdditionalLinesPosition_Bottom" />
|
|
</ComboBox>
|
|
</tkcontrols:SettingsCard>
|
|
<tkcontrols:SettingsCard x:Uid="Hosts_Toggle_LoopbackDuplicates" HeaderIcon="{ui:FontIcon Glyph=}">
|
|
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.LoopbackDuplicates, Mode=TwoWay}" />
|
|
</tkcontrols:SettingsCard>
|
|
<tkcontrols:SettingsCard x:Uid="Hosts_NoLeadingSpaces" HeaderIcon="{ui:FontIcon Glyph=}">
|
|
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.NoLeadingSpaces, Mode=TwoWay}" />
|
|
</tkcontrols:SettingsCard>
|
|
<tkcontrols:SettingsCard x:Uid="Hosts_Encoding">
|
|
<ComboBox MinWidth="{StaticResource SettingActionControlMinWidth}" SelectedIndex="{x:Bind Path=ViewModel.Encoding, Mode=TwoWay}">
|
|
<ComboBoxItem x:Uid="Hosts_Encoding_Utf8" />
|
|
<ComboBoxItem x:Uid="Hosts_Encoding_Utf8Bom" />
|
|
</ComboBox>
|
|
</tkcontrols:SettingsCard>
|
|
</controls:SettingsGroup>
|
|
</StackPanel>
|
|
</controls:SettingsPageControl.ModuleContent>
|
|
|
|
<controls:SettingsPageControl.PrimaryLinks>
|
|
<controls:PageLink x:Uid="LearnMore_Hosts" Link="https://aka.ms/PowerToysOverview_HostsFileEditor" />
|
|
</controls:SettingsPageControl.PrimaryLinks>
|
|
</controls:SettingsPageControl>
|
|
</Page>
|