Commit Graph

6 Commits

Author SHA1 Message Date
Mohammed Saalim K
6130d2ad39 Hosts: add “No leading spaces” option and honor it when saving (#41206)
## 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.
2025-08-19 13:58:10 +08:00
Jeremy Sinclair
195c6f588a [Analyzers] Resolve Stylecop SA1516 violations and others to enable fully building on VS 17.12 (#35248)
* [Analyzers][Settings] Fix SA1516

* [Analyzers][Workspaces] Fix SA1516

* [Analyzers][Awake] Fix SA1516

* [Analyzers][Wox] Fix SA1516

* [MWB] Disable CA1716 warning on class name

* [Wox] Update ExecuteFilePath property visibility for Json Source Generator

* [Analyzers][MWB] Fix CA1716 on NativeMethods.

---------

Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2024-10-17 05:14:57 -04:00
Andrey Nekrasov
f23fa3f592 [DSC] Implement Microsoft.PowerToys.Configure DSCResource & winget support (#30918)
* [DSC] Microsoft.PowerToys.Configure module + winget configuration file support

* f: fix for an incorrect directory id reference

* f: update comment

* f: address review comments

* f: file locksmith bug fix

* f: add explorer preview switches in samples

* f: remove debug

* Sign DSC files

* f: implement docs/samples generator

* [ci]Sign FancyZonesEditorCommon.dll

* Sign DSC files in the Generated folder

* f: address review comments

* f: update usable options

* f: add autogenerated sample

* [Installer] Don't use same GUID for different components

* [Installer]Don't remove folders shared by other modules

* Allow configuring PTRun MaximumNumberOfResults

* Remove all settings DSC sample. Just random data

* Allow configuring Hosts Run as Administrator

* Revert "[Installer]Don't remove folders shared by other modules"

This reverts commit 6da3d6cfd5.

* Add all PTRun plugins and Global and keyboard to DSC sample

* Fix issues with context menu modules not disabling

* Fix default enabled values when setting with DSC

* Fix tests regarding default modules in Settings

* Fix merge error

* Restart PowerToys process if we stopped it

---------

Co-authored-by: Andrey Nekrasov <1828123+yuyoyuppe@users.noreply.github.com>
Co-authored-by: Jaime Bernardo <jaime@janeasystems.com>
2024-04-02 00:09:47 +01:00
Davide Giacometti
9960d2d536 [Hosts]Add setting to select the file encoding (#26495) 2023-06-06 16:11:37 +01:00
Davide Giacometti
3e651b8de6 [Hosts] Improved duplicate hosts finding (#24294)
* improved duplicate hosts finding

* improved filters with AdvancedCollectionView

* cancel FindDuplicates when file is reloaded
2023-02-27 18:11:57 +00:00
Davide Giacometti
b2e1337d4e Hosts file editor (#20462) 2022-10-13 13:05:43 +02:00