Skip to content

Commit baaa4d8

Browse files
vanzuelei9444
authored andcommitted
Settings: Search fancy zone settings and swallow the ctrl+f event (#41437)
<!-- Enter a brief description/summary of your PR here. What does it fix/what does it change/how was it tested (even manually, if necessary)? --> ## Summary of the Pull Request This pull request primarily improves the maintainability and robustness of the FancyZones settings UI by assigning unique `Name` attributes to `SettingsCard` controls in the `FancyZonesPage.xaml` file. Additionally, it enhances the logic for retrieving element UIDs and improves fallback behavior for missing localizations. There is also a minor usability fix in the shell page to prevent unintended navigation when focusing the search box. **FancyZones settings UI improvements:** * Added unique `Name` attributes to all `tkcontrols:SettingsCard` elements in `FancyZonesPage.xaml` to facilitate easier referencing and future maintainability. This affects all relevant settings groups and controls in the file. [[1]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL73-R85) [[2]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL109-R109) [[3]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL121-R121) [[4]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL167-R188) [[5]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL202-R202) [[6]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL251-R251) [[7]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL265-R265) [[8]](diffhunk://#diff-93623d4db1d295dde0ef793053c9db0d9f673d753b787ad12fd71b8e9e40a79fL280-R280) **Element UID retrieval and localization:** * Improved `GetElementUid` in `Program.cs` to fall back to the first child's `x:Uid` if the element itself lacks one, increasing robustness when parsing XAML. * Updated `GetLocalizedSettingHeaderAndD` in `SearchIndexService.cs` to provide a fallback for missing localizations by trying the `"{elementUid}/Content"` resource key. **Shell page usability:** * Modified `CtrlF_Invoked` in `ShellPage.xaml.cs` to mark the event as handled, preventing unintended navigation when the search box is focused with Ctrl+F. <!-- Please review the items on the PR checklist before submitting--> ## PR Checklist - [ ] Closes: #xxx - [ ] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Tests:** Added/updated and all pass - [ ] **Localization:** All end-user-facing strings can be localized - [ ] **Dev docs:** Added/updated - [ ] **New binaries:** Added on the required places - [ ] [JSON for signing](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ESRPSigning_core.json) for new binaries - [ ] [WXS for installer](https://github.com/microsoft/PowerToys/blob/main/installer/PowerToysSetup/Product.wxs) for new binaries and localization folder - [ ] [YML for CI pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/ci/templates/build-powertoys-steps.yml) for new test projects - [ ] [YML for signed pipeline](https://github.com/microsoft/PowerToys/blob/main/.pipelines/release.yml) - [ ] **Documentation updated:** If checked, please file a pull request on [our docs repo](https://github.com/MicrosoftDocs/windows-uwp/tree/docs/hub/powertoys) and link it here: #xxx <!-- Provide a more detailed description of the PR, other things fixed, or any additional comments/features here --> ## Detailed Description of the Pull Request / Additional comments <!-- Describe how you validated the behavior. Add automated tests wherever possible, but list manual validation steps taken as well --> ## Validation Steps Performed https://github.com/user-attachments/assets/9cf15605-1114-4c6d-923c-d05c2733a274
1 parent 931204a commit baaa4d8

File tree

4 files changed

+51
-22
lines changed

4 files changed

+51
-22
lines changed

src/settings-ui/Settings.UI.XamlIndexBuilder/Program.cs

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,25 @@ public static string GetElementName(XElement element, XNamespace x)
288288

289289
public static string GetElementUid(XElement element, XNamespace x)
290290
{
291-
// Try x:Uid
291+
// Try x:Uid on the element itself
292292
var uid = element.Attribute(x + "Uid")?.Value;
293-
return uid;
293+
if (!string.IsNullOrWhiteSpace(uid))
294+
{
295+
return uid;
296+
}
297+
298+
// Fallback: check the first direct child element's x:Uid
299+
var firstChild = element.Elements().FirstOrDefault();
300+
if (firstChild != null)
301+
{
302+
var childUid = firstChild.Attribute(x + "Uid")?.Value;
303+
if (!string.IsNullOrWhiteSpace(childUid))
304+
{
305+
return childUid;
306+
}
307+
}
308+
309+
return null;
294310
}
295311

296312
public static string GetParentElementName(XElement element, XNamespace x)

src/settings-ui/Settings.UI/Services/SearchIndexService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ private static (string Header, string Description) GetLocalizedSettingHeaderAndD
170170

171171
if (string.IsNullOrEmpty(header))
172172
{
173-
Debug.WriteLine($"[SearchIndexService] WARNING: No header localization found for ElementUid: '{elementUid}'");
173+
header = GetString(resourceLoader, $"{elementUid}/Content");
174174
}
175175

176176
return (header, description);

src/settings-ui/Settings.UI/SettingsXAML/Views/FancyZonesPage.xaml

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -70,19 +70,19 @@
7070
x:Uid="FancyZones_ZoneBehavior_GroupSettings"
7171
IsExpanded="True">
7272
<tkcontrols:SettingsExpander.Items>
73-
<tkcontrols:SettingsCard ContentAlignment="Left">
73+
<tkcontrols:SettingsCard Name="FancyZonesShiftDragCheckBoxControlHeader" ContentAlignment="Left">
7474
<CheckBox x:Uid="FancyZones_ShiftDragCheckBoxControl_Header" IsChecked="{x:Bind ViewModel.ShiftDrag, Mode=TwoWay}" />
7575
</tkcontrols:SettingsCard>
76-
<tkcontrols:SettingsCard ContentAlignment="Left">
76+
<tkcontrols:SettingsCard Name="FancyZonesMouseDragCheckBoxControlHeader" ContentAlignment="Left">
7777
<CheckBox x:Uid="FancyZones_MouseDragCheckBoxControl_Header" IsChecked="{x:Bind ViewModel.MouseSwitch, Mode=TwoWay}" />
7878
</tkcontrols:SettingsCard>
79-
<tkcontrols:SettingsCard ContentAlignment="Left">
79+
<tkcontrols:SettingsCard Name="FancyZonesMouseMiddleClickSpanningMultipleZonesCheckBoxControlHeader" ContentAlignment="Left">
8080
<CheckBox x:Uid="FancyZones_MouseMiddleClickSpanningMultipleZonesCheckBoxControl_Header" IsChecked="{x:Bind ViewModel.MouseMiddleClickSpanningMultipleZones, Mode=TwoWay}" />
8181
</tkcontrols:SettingsCard>
82-
<tkcontrols:SettingsCard ContentAlignment="Left">
82+
<tkcontrols:SettingsCard Name="FancyZonesShowZonesOnAllMonitorsCheckBoxControl" ContentAlignment="Left">
8383
<CheckBox x:Uid="FancyZones_ShowZonesOnAllMonitorsCheckBoxControl" IsChecked="{x:Bind ViewModel.ShowOnAllMonitors, Mode=TwoWay}" />
8484
</tkcontrols:SettingsCard>
85-
<tkcontrols:SettingsCard ContentAlignment="Left">
85+
<tkcontrols:SettingsCard Name="FancyZonesSpanZonesAcrossMonitors" ContentAlignment="Left">
8686
<controls:CheckBoxWithDescriptionControl x:Uid="FancyZones_SpanZonesAcrossMonitors" IsChecked="{x:Bind ViewModel.SpanZonesAcrossMonitors, Mode=TwoWay}" />
8787
</tkcontrols:SettingsCard>
8888
<tkcontrols:SettingsCard Name="FancyZonesOverlappingZones" x:Uid="FancyZones_OverlappingZones">
@@ -106,7 +106,7 @@
106106
<ComboBoxItem x:Uid="FancyZones_Radio_Default_Theme" />
107107
</ComboBox>
108108
<tkcontrols:SettingsExpander.Items>
109-
<tkcontrols:SettingsCard ContentAlignment="Left">
109+
<tkcontrols:SettingsCard Name="FancyZonesPreviewCard" ContentAlignment="Left">
110110
<controls:FancyZonesPreviewControl
111111
Width="192"
112112
Height="108"
@@ -118,7 +118,7 @@
118118
IsSystemTheme="{x:Bind ViewModel.SystemTheme, Mode=OneWay}"
119119
ShowZoneNumber="{x:Bind Path=ViewModel.ShowZoneNumber, Mode=OneWay}" />
120120
</tkcontrols:SettingsCard>
121-
<tkcontrols:SettingsCard ContentAlignment="Left">
121+
<tkcontrols:SettingsCard Name="FancyZonesShowZoneNumberCheckBoxControl" ContentAlignment="Left">
122122
<CheckBox x:Uid="FancyZones_ShowZoneNumberCheckBoxControl" IsChecked="{x:Bind ViewModel.ShowZoneNumber, Mode=TwoWay}" />
123123
</tkcontrols:SettingsCard>
124124
<tkcontrols:SettingsCard Name="FancyZonesHighlightOpacity" x:Uid="FancyZones_HighlightOpacity">
@@ -164,28 +164,31 @@
164164
x:Uid="FancyZones_WindowBehavior_GroupSettings"
165165
IsExpanded="True">
166166
<tkcontrols:SettingsExpander.Items>
167-
<tkcontrols:SettingsCard ContentAlignment="Left">
167+
<tkcontrols:SettingsCard Name="FancyZonesDisplayOrWorkAreaChangeMoveWindowsCheckBoxControl" ContentAlignment="Left">
168168
<CheckBox x:Uid="FancyZones_DisplayOrWorkAreaChangeMoveWindowsCheckBoxControl" IsChecked="{x:Bind ViewModel.DisplayOrWorkAreaChangeMoveWindows, Mode=TwoWay}" />
169169
</tkcontrols:SettingsCard>
170-
<tkcontrols:SettingsCard ContentAlignment="Left">
170+
<tkcontrols:SettingsCard Name="FancyZonesZoneSetChangeMoveWindows" ContentAlignment="Left">
171171
<CheckBox x:Uid="FancyZones_ZoneSetChangeMoveWindows" IsChecked="{x:Bind ViewModel.ZoneSetChangeMoveWindows, Mode=TwoWay}" />
172172
</tkcontrols:SettingsCard>
173-
<tkcontrols:SettingsCard ContentAlignment="Left">
173+
<tkcontrols:SettingsCard Name="FancyZonesAppLastZoneMoveWindows" ContentAlignment="Left">
174174
<CheckBox x:Uid="FancyZones_AppLastZoneMoveWindows" IsChecked="{x:Bind ViewModel.AppLastZoneMoveWindows, Mode=TwoWay}" />
175175
</tkcontrols:SettingsCard>
176-
<tkcontrols:SettingsCard ContentAlignment="Left">
176+
<tkcontrols:SettingsCard Name="FancyZonesOpenWindowOnActiveMonitor" ContentAlignment="Left">
177177
<CheckBox x:Uid="FancyZones_OpenWindowOnActiveMonitor" IsChecked="{x:Bind ViewModel.OpenWindowOnActiveMonitor, Mode=TwoWay}" />
178178
</tkcontrols:SettingsCard>
179-
<tkcontrols:SettingsCard ContentAlignment="Left">
179+
<tkcontrols:SettingsCard Name="FancyZonesRestoreSize" ContentAlignment="Left">
180180
<CheckBox x:Uid="FancyZones_RestoreSize" IsChecked="{x:Bind ViewModel.RestoreSize, Mode=TwoWay}" />
181181
</tkcontrols:SettingsCard>
182-
<tkcontrols:SettingsCard ContentAlignment="Left">
182+
<tkcontrols:SettingsCard Name="FancyZonesMakeDraggedWindowTransparentCheckBoxControl" ContentAlignment="Left">
183183
<CheckBox x:Uid="FancyZones_MakeDraggedWindowTransparentCheckBoxControl" IsChecked="{x:Bind ViewModel.MakeDraggedWindowsTransparent, Mode=TwoWay}" />
184184
</tkcontrols:SettingsCard>
185-
<tkcontrols:SettingsCard ContentAlignment="Left">
185+
<tkcontrols:SettingsCard Name="FancyZonesAllowChildWindowSnap" ContentAlignment="Left">
186186
<CheckBox x:Uid="FancyZones_AllowChildWindowSnap" IsChecked="{x:Bind ViewModel.AllowChildWindowSnap, Mode=TwoWay}" />
187187
</tkcontrols:SettingsCard>
188-
<tkcontrols:SettingsCard ContentAlignment="Left" Visibility="{x:Bind ViewModel.Windows11, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
188+
<tkcontrols:SettingsCard
189+
Name="FancyZonesDisableRoundCornersOnWindowSnap"
190+
ContentAlignment="Left"
191+
Visibility="{x:Bind ViewModel.Windows11, Mode=OneWay, Converter={StaticResource BoolToVisibilityConverter}}">
189192
<CheckBox x:Uid="FancyZones_DisableRoundCornersOnWindowSnap" IsChecked="{x:Bind ViewModel.DisableRoundCornersOnWindowSnap, Mode=TwoWay}" />
190193
</tkcontrols:SettingsCard>
191194
</tkcontrols:SettingsExpander.Items>
@@ -199,7 +202,7 @@
199202
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.WindowSwitching, Mode=TwoWay}" />
200203
<tkcontrols:SettingsExpander.Items>
201204
<!-- HACK: For some weird reason, a Shortcut Control is not working correctly if it's the first item in the expander, so we add an invisible card as the first one. -->
202-
<tkcontrols:SettingsCard Visibility="Collapsed" />
205+
<tkcontrols:SettingsCard Name="FancyZonesWindowSwitchingPlaceholder" Visibility="Collapsed" />
203206
<tkcontrols:SettingsCard
204207
Name="FancyZonesHotkeyNextTabControl"
205208
x:Uid="FancyZones_HotkeyNextTabControl"
@@ -248,7 +251,10 @@
248251
</ComboBoxItem>
249252
</ComboBox>
250253
</tkcontrols:SettingsCard>
251-
<tkcontrols:SettingsCard ContentAlignment="Left" IsEnabled="{x:Bind ViewModel.SnapHotkeysCategoryEnabled, Mode=OneWay}">
254+
<tkcontrols:SettingsCard
255+
Name="FancyZonesMoveWindowsAcrossAllMonitorsCheckBoxControl"
256+
ContentAlignment="Left"
257+
IsEnabled="{x:Bind ViewModel.SnapHotkeysCategoryEnabled, Mode=OneWay}">
252258
<CheckBox x:Uid="FancyZones_MoveWindowsAcrossAllMonitorsCheckBoxControl" IsChecked="{x:Bind ViewModel.MoveWindowsAcrossMonitors, Mode=TwoWay}" />
253259
</tkcontrols:SettingsCard>
254260
</tkcontrols:SettingsExpander.Items>
@@ -262,7 +268,10 @@
262268
HeaderIcon="{ui:FontIcon Glyph=&#xEDA7;}">
263269
<ToggleSwitch x:Uid="ToggleSwitch" IsOn="{x:Bind ViewModel.QuickLayoutSwitch, Mode=TwoWay}" />
264270
<tkcontrols:SettingsExpander.Items>
265-
<tkcontrols:SettingsCard ContentAlignment="Left" IsEnabled="{x:Bind ViewModel.QuickSwitchEnabled, Mode=OneWay}">
271+
<tkcontrols:SettingsCard
272+
Name="FancyZonesFlashZonesOnQuickSwitch"
273+
ContentAlignment="Left"
274+
IsEnabled="{x:Bind ViewModel.QuickSwitchEnabled, Mode=OneWay}">
266275
<CheckBox x:Uid="FancyZones_FlashZonesOnQuickSwitch" IsChecked="{x:Bind ViewModel.FlashZonesOnQuickSwitch, Mode=TwoWay}" />
267276
</tkcontrols:SettingsCard>
268277
</tkcontrols:SettingsExpander.Items>
@@ -277,7 +286,10 @@
277286
HeaderIcon="{ui:FontIcon Glyph=&#xECE4;}"
278287
IsExpanded="True">
279288
<tkcontrols:SettingsExpander.Items>
280-
<tkcontrols:SettingsCard HorizontalContentAlignment="Stretch" ContentAlignment="Vertical">
289+
<tkcontrols:SettingsCard
290+
Name="FancyZonesExcludeAppsTextBoxControl"
291+
HorizontalContentAlignment="Stretch"
292+
ContentAlignment="Vertical">
281293
<TextBox
282294
x:Uid="FancyZones_ExcludeApps_TextBoxControl"
283295
MinWidth="240"

src/settings-ui/Settings.UI/SettingsXAML/Views/ShellPage.xaml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,6 +605,7 @@ private static Type GetPageTypeFromName(string pageTypeName)
605605
private void CtrlF_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args)
606606
{
607607
SearchBox.Focus(FocusState.Programmatic);
608+
args.Handled = true; // prevent further processing (e.g., unintended navigation)
608609
}
609610

610611
private void SearchBox_GotFocus(object sender, RoutedEventArgs e)

0 commit comments

Comments
 (0)