Skip to content

Commit 6efd94a

Browse files
committed
Add settings string extraction script and config
j Constant
1 parent 2df0978 commit 6efd94a

File tree

7 files changed

+360
-0
lines changed

7 files changed

+360
-0
lines changed
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"AdvancedPage": [
3+
"ExportSettings",
4+
"ImportSettings",
5+
"EditSettingsFile",
6+
"SettingsOpenInLogin",
7+
"SettingsLeaveAppRunning",
8+
"ShowSystemTrayIcon",
9+
"SettingsSetAsDefaultFileManager",
10+
"SettingsSetAsOpenDialog",
11+
"ShowFlattenOptions",
12+
"Advanced",
13+
"ExperimentalFeatureFlags"
14+
],
15+
"AboutPage": [
16+
"SponsorUsOnGitHub",
17+
"Documentation",
18+
"QuestionsAndDiscussions",
19+
"SubmitFeatureRequest",
20+
"SubmitBugReport",
21+
"OpenLogLocation",
22+
"ImproveTranslation",
23+
"OpenGitHubRepo",
24+
"Privacy",
25+
"Feedback",
26+
"ThirdPartyLibraries",
27+
"About",
28+
"HelpAndSupport",
29+
"OpenSource"
30+
],
31+
"LayoutPage": [
32+
"SyncFolderPreferencesAcrossDirectories",
33+
"LayoutType",
34+
"SortInDescendingOrder",
35+
"SortPriority",
36+
"GroupInDescendingOrder",
37+
"GroupByDateUnit",
38+
"TagColumn",
39+
"SizeColumn",
40+
"TypeColumn",
41+
"DateColumn",
42+
"DateCreatedColumn",
43+
"SortBy",
44+
"GroupBy",
45+
"Columns",
46+
"Layout",
47+
"SortingAndGrouping",
48+
"DetailsView"
49+
],
50+
"GeneralPage": [
51+
"Language",
52+
"DateFormat",
53+
"OpenTabInExistingInstance",
54+
"AlwaysSwitchToNewlyOpenedTab",
55+
"QuickAccess",
56+
"Drives",
57+
"NetworkLocations",
58+
"FileTags",
59+
"RecentFiles",
60+
"SettingsMultitaskingAlwaysOpenDualPane",
61+
"DualPaneSplitDirection",
62+
"ShowOpenInNewTab",
63+
"ShowOpenInNewWindow",
64+
"ShowOpenInNewPane",
65+
"ShowCopyPath",
66+
"ShowCreateFolderWithSelection",
67+
"ShowCreateAlternateDataStream",
68+
"ShowCreateShortcut",
69+
"ShowPinToSideBar",
70+
"ShowCompressionOptions",
71+
"ShowFlattenOptions",
72+
"ShowSendToMenu",
73+
"ShowOpenTerminal",
74+
"ShowEditTagsMenu",
75+
"ShowPinToStart",
76+
"SettingsContextMenuOverflow",
77+
"EnableSmoothScrolling",
78+
"StartupSettings",
79+
"Widgets",
80+
"ContextMenuOptions",
81+
"General",
82+
"DualPane",
83+
"Scrolling"
84+
],
85+
"AppearancePage": [
86+
"SettingsAppearanceTheme",
87+
"BackdropMaterial",
88+
"Opacity",
89+
"ImageFit",
90+
"VerticalAlignment",
91+
"HorizontalAlignment",
92+
"ShowTabActions",
93+
"ShowShelfPaneButtonInAddressBar",
94+
"ShowToolbar",
95+
"ShowStatusCenterButton",
96+
"ShowStatusBar",
97+
"BackgroundColor",
98+
"BackgroundImage",
99+
"Toolbars",
100+
"Appearance"
101+
],
102+
"FoldersPage": [
103+
"SettingsFilesAndFoldersShowHiddenItems",
104+
"ShowDotFiles",
105+
"ShowProtectedSystemFiles",
106+
"ShowAlternateStreams",
107+
"SettingsFilesAndFoldersShowFileExtensions",
108+
"SettingsFilesAndFoldersShowThumbnails",
109+
"ShowCheckboxesWhenSelectingItems",
110+
"SettingsOpenItemsWithOneClick",
111+
"OpenFolderWithOneClick",
112+
"OpenFoldersInNewTab",
113+
"ShowConfirmationWhenDeletingItems",
114+
"ShowFileExtensionWarning",
115+
"SelectFilesAndFoldersOnHover",
116+
"DoubleClickBlankSpaceToGoUp",
117+
"ScrollToPreviousFolderWhenNavigatingUp",
118+
"SizeFormat",
119+
"HiddenItems",
120+
"OpeningItems",
121+
"CalculateFolderSizes",
122+
"FilesAndFolders",
123+
"Display",
124+
"Behaviors"
125+
],
126+
"DevToolsPage": [
127+
"ConnectToGitHub",
128+
"ConnectedToGitHub",
129+
"DisplayOpenIDE",
130+
"DevTools"
131+
],
132+
"ActionsPage": [
133+
"Actions",
134+
"Commands"
135+
],
136+
"TagsPage": [
137+
"FileTags"
138+
]
139+
}

src/Files.App/Constants.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ public static class ResourceFilePaths
189189
/// The path to the json file containing a list of file properties to be loaded in the preview pane.
190190
/// </summary>
191191
public const string PreviewPaneDetailsPropertiesJsonPath = @"ms-appx:///Assets/Resources/PreviewPanePropertiesInformation.json";
192+
193+
/// <summary>
194+
/// The path to the json file containing settings string keys used for localized settings search.
195+
/// </summary>
196+
public const string SettingsStringKeysJsonPath = @"ms-appx:///Assets/Data/settings_string_keys.json";
192197
}
193198

194199
public static class Filesystem

src/Files.App/Dialogs/SettingsDialog.xaml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,26 @@
8181
OpenPaneLength="260"
8282
PaneDisplayMode="Left"
8383
SelectionChanged="MainSettingsNavigationView_SelectionChanged">
84+
<NavigationView.AutoSuggestBox>
85+
<AutoSuggestBox
86+
x:Name="SettingsSearchBox"
87+
AutomationProperties.Name="{helpers:ResourceString Name=Search}"
88+
PlaceholderText="{helpers:ResourceString Name=Search}"
89+
QueryIcon="Find"
90+
QuerySubmitted="SettingsSearchBox_QuerySubmitted"
91+
SuggestionChosen="SettingsSearchBox_SuggestionChosen"
92+
TextChanged="SettingsSearchBox_TextChanged">
93+
<AutoSuggestBox.ItemTemplate>
94+
<DataTemplate>
95+
<TextBlock
96+
Padding="0,8,0,8"
97+
AutomationProperties.Name="{Binding Localized}"
98+
Text="{Binding Localized}"
99+
TextWrapping="Wrap" />
100+
</DataTemplate>
101+
</AutoSuggestBox.ItemTemplate>
102+
</AutoSuggestBox>
103+
</NavigationView.AutoSuggestBox>
84104

85105
<!-- Menu Items -->
86106
<NavigationView.MenuItems>

src/Files.App/Dialogs/SettingsDialog.xaml.cs

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,12 @@
55
using Microsoft.UI.Xaml;
66
using Microsoft.UI.Xaml.Controls;
77
using Microsoft.UI.Xaml.Media.Animation;
8+
using CommunityToolkit.WinUI.Controls;
9+
using Microsoft.UI.Xaml.Media;
10+
using System.Threading.Tasks;
11+
using System.IO;
12+
using Windows.Storage;
13+
using Windows.Foundation;
814

915
namespace Files.App.Dialogs
1016
{
@@ -15,12 +21,18 @@ public sealed partial class SettingsDialog : ContentDialog, IDialog<SettingsDial
1521
private FrameworkElement RootAppElement
1622
=> (FrameworkElement)MainWindow.Instance.Content;
1723

24+
25+
26+
27+
1828
public SettingsDialog()
1929
{
2030
InitializeComponent();
2131

2232
MainWindow.Instance.SizeChanged += Current_SizeChanged;
33+
2334
UpdateDialogLayout();
35+
LoadSettingsKeysAsync();
2436
}
2537

2638
public new async Task<DialogResult> ShowAsync()
@@ -79,6 +91,134 @@ private void MainSettingsNavigationView_SelectionChanged(NavigationView sender,
7991
};
8092
}
8193

94+
private Dictionary<string, List<string>> settingsKeysByPage = new();
95+
private Dictionary<string, string> keyToPage = new();
96+
private Dictionary<string, string> keyToLocalized = new();
97+
98+
public async void LoadSettingsKeysAsync()
99+
{
100+
try
101+
{
102+
var file = await StorageFile.GetFileFromApplicationUriAsync(new Uri(Constants.ResourceFilePaths.SettingsStringKeysJsonPath));
103+
using var stream = await file.OpenStreamForReadAsync();
104+
var dict = await JsonSerializer.DeserializeAsync<Dictionary<string, List<string>>>(stream);
105+
if (dict != null)
106+
{
107+
settingsKeysByPage = dict;
108+
keyToPage.Clear();
109+
keyToLocalized.Clear();
110+
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse();
111+
foreach (var kvp in dict)
112+
{
113+
foreach (var key in kvp.Value)
114+
{
115+
keyToPage[key] = kvp.Key;
116+
string localized = resourceLoader.GetString(key);
117+
if (string.IsNullOrEmpty(localized))
118+
localized = key;
119+
keyToLocalized[key] = localized;
120+
}
121+
}
122+
}
123+
}
124+
catch { }
125+
}
126+
127+
private void SettingsSearchBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
128+
{
129+
if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput)
130+
return;
131+
132+
var query = sender.Text?.Trim().ToLowerInvariant() ?? string.Empty;
133+
134+
// Debounce: Only update suggestions if query changed
135+
var resourceLoader = Windows.ApplicationModel.Resources.ResourceLoader.GetForViewIndependentUse();
136+
string noResults = resourceLoader.GetString("NoResultsFound");
137+
if (string.IsNullOrEmpty(query))
138+
{
139+
// Show a placeholder for empty search
140+
sender.ItemsSource = new List<SettingSuggestion> {
141+
new SettingSuggestion { Key = null, Localized = noResults }
142+
};
143+
return;
144+
}
145+
146+
var suggestions = keyToLocalized
147+
.Where(kvp => kvp.Value.ToLowerInvariant().Contains(query))
148+
.Select(kvp => new SettingSuggestion { Key = kvp.Key, Localized = kvp.Value })
149+
.DistinctBy(s => s.Localized)
150+
.ToList();
151+
152+
if (suggestions.Count == 0)
153+
{
154+
// Show a placeholder for no results
155+
sender.ItemsSource = new List<SettingSuggestion> {
156+
new SettingSuggestion { Key = null, Localized = noResults }
157+
};
158+
}
159+
else
160+
{
161+
sender.ItemsSource = suggestions;
162+
}
163+
}
164+
165+
private class SettingSuggestion
166+
{
167+
public string Key { get; set; }
168+
public string Localized { get; set; }
169+
public override string ToString() => Localized;
170+
}
171+
172+
private void SettingsSearchBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
173+
{
174+
if (args.SelectedItem is SettingSuggestion suggestion && !string.IsNullOrEmpty(suggestion.Key))
175+
{
176+
if (keyToPage.TryGetValue(suggestion.Key, out var page))
177+
{
178+
NavigateToPageByName(page);
179+
}
180+
}
181+
182+
// Close the suggestion dropdown
183+
sender.IsSuggestionListOpen = false;
184+
// Clear the query after a suggestion is chosen
185+
sender.Text = string.Empty;
186+
}
187+
188+
private void SettingsSearchBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
189+
{
190+
var query = args.QueryText?.Trim().ToLowerInvariant() ?? string.Empty;
191+
if (string.IsNullOrEmpty(query))
192+
{
193+
// Close dropdown and clear text
194+
sender.IsSuggestionListOpen = false;
195+
sender.Text = string.Empty;
196+
return;
197+
}
198+
199+
var match = keyToLocalized.FirstOrDefault(x => x.Value.ToLowerInvariant().Contains(query));
200+
if (!string.IsNullOrEmpty(match.Key) && keyToPage.TryGetValue(match.Key, out var page))
201+
{
202+
NavigateToPageByName(page);
203+
}
204+
205+
// Close dropdown and clear text
206+
sender.IsSuggestionListOpen = false;
207+
sender.Text = string.Empty;
208+
}
209+
210+
private void NavigateToPageByName(string pageName)
211+
{
212+
foreach (NavigationViewItem item in MainSettingsNavigationView.MenuItems)
213+
{
214+
if ((item.Tag as string) == pageName)
215+
{
216+
MainSettingsNavigationView.SelectedItem = item;
217+
break;
218+
}
219+
}
220+
}
221+
82222
private void ContentDialog_Closing(ContentDialog sender, ContentDialogClosingEventArgs args)
83223
{
84224
MainWindow.Instance.SizeChanged -= Current_SizeChanged;

src/Files.App/Files.App.csproj

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,15 @@
6060
<Content Include="7zArm64.dll">
6161
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
6262
</Content>
63+
<Content Include="Assets\Data\settings_string_keys.json">
64+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
65+
</Content>
6366
</ItemGroup>
6467

68+
<Target Name="ExtractSettingsStrings" BeforeTargets="Build">
69+
<Exec Command="powershell -ExecutionPolicy Bypass -File Scripts\extract_settings_strings.ps1" WorkingDirectory="$(ProjectDir)" />
70+
</Target>
71+
6572
<ItemGroup>
6673
<PackageReference Include="ByteSize" />
6774
<PackageReference Include="ColorCode.WinUI" />

0 commit comments

Comments
 (0)