Skip to content

Commit 427a9b2

Browse files
authored
Feature: Added simple header to search results (#17399)
1 parent c1d9e84 commit 427a9b2

File tree

5 files changed

+86
-5
lines changed

5 files changed

+86
-5
lines changed

src/Files.App/Constants.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public static class ImageRes
5656
public const int Libraries = 1023;
5757
public const int Folder = 3;
5858
public const int ShieldIcon = 78;
59+
public const int SearchIcon = 177;
5960
}
6061

6162
public static class Shell32

src/Files.App/Helpers/UI/UIHelpers.cs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ public static void CloseAllDialogs()
106106

107107
private static IconFileInfo ShieldIconResource = LoadShieldIconResource();
108108

109+
private static IconFileInfo SearchIconResource = LoadSearchIconResource();
110+
109111
public static IconFileInfo GetSidebarIconResourceInfo(int index)
110112
{
111113
var icons = UIHelpers.SidebarIconResources;
@@ -128,6 +130,13 @@ public static IconFileInfo GetSidebarIconResourceInfo(int index)
128130
: null;
129131
}
130132

133+
public static async Task<BitmapImage?> GetSearchIconResource()
134+
{
135+
return SearchIconResource is not null
136+
? await SearchIconResource.IconData.ToBitmapAsync()
137+
: null;
138+
}
139+
131140
private static IEnumerable<IconFileInfo> LoadSidebarIconResources()
132141
{
133142
string imageres = Path.Combine(Constants.UserEnvironmentPaths.SystemRootPath, "System32", "imageres.dll");
@@ -153,5 +162,15 @@ private static IconFileInfo LoadShieldIconResource()
153162

154163
return imageResList.FirstOrDefault();
155164
}
165+
166+
private static IconFileInfo LoadSearchIconResource()
167+
{
168+
string imageres = Path.Combine(Constants.UserEnvironmentPaths.SystemRootPath, "System32", "imageres.dll");
169+
var imageResList = Win32Helper.ExtractSelectedIconsFromDLL(imageres, new List<int>() {
170+
Constants.ImageRes.SearchIcon
171+
}, 48);
172+
173+
return imageResList.FirstOrDefault();
174+
}
156175
}
157176
}

src/Files.App/Strings/en-US/Resources.resw

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1010,6 +1010,9 @@
10101010
<data name="SearchPagePathBoxOverrideText" xml:space="preserve">
10111011
<value>Search results in {1} for {0}</value>
10121012
</data>
1013+
<data name="SearchResultsFor" xml:space="preserve">
1014+
<value>Search results for `{0}`</value>
1015+
</data>
10131016
<data name="Details" xml:space="preserve">
10141017
<value>Details</value>
10151018
</data>

src/Files.App/ViewModels/ShellViewModel.cs

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ public ImageSource? FolderThumbnailImageSource
121121
private set => SetProperty(ref _FolderThumbnailImageSource, value);
122122
}
123123

124+
private BitmapImage? _SearchIconBitmapImage;
125+
public BitmapImage? SearchIconBitmapImage
126+
{
127+
get => _SearchIconBitmapImage;
128+
private set => SetProperty(ref _SearchIconBitmapImage, value);
129+
}
130+
131+
124132
public bool ShowFilterHeader =>
125133
UserSettingsService.GeneralSettingsService.ShowFilterHeader &&
126134
WorkingDirectory != "Home" &&
@@ -739,7 +747,26 @@ public void CancelExtendedPropertiesLoadingForItem(ListedItem item)
739747
itemLoadQueue.TryUpdate(item.ItemPath, true, false);
740748
}
741749

742-
private bool IsSearchResults { get; set; }
750+
private bool _isSearchResults;
751+
public bool IsSearchResults
752+
{
753+
get => _isSearchResults;
754+
set
755+
{
756+
if (SetProperty(ref _isSearchResults, value))
757+
{
758+
if (!value)
759+
SearchHeaderTitle = string.Empty;
760+
}
761+
}
762+
}
763+
764+
private string? _searchHeaderTitle;
765+
public string? SearchHeaderTitle
766+
{
767+
get => _searchHeaderTitle;
768+
set => SetProperty(ref _searchHeaderTitle, value);
769+
}
743770

744771
public void UpdateEmptyTextType()
745772
{
@@ -2692,6 +2719,13 @@ public async Task SearchAsync(FolderSearch search)
26922719
await ApplyFilesAndFoldersChangesAsync();
26932720
EmptyTextType = EmptyTextType.None;
26942721

2722+
SearchHeaderTitle = !string.IsNullOrEmpty(search.Query)
2723+
? string.Format(Strings.SearchResultsFor.GetLocalizedResource(), search.Query)
2724+
: string.Empty;
2725+
2726+
if (SearchIconBitmapImage is null)
2727+
SearchIconBitmapImage ??= await UIHelpers.GetSearchIconResource();
2728+
26952729
ItemLoadStatusChanged?.Invoke(this, new ItemLoadStatusChangedEventArgs() { Status = ItemLoadStatusChangedEventArgs.ItemLoadStatus.InProgress });
26962730

26972731
var results = new List<ListedItem>();

src/Files.App/Views/Shells/ModernShellPage.xaml

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<ThemeShadow x:Name="ShellContentThemeShadow" x:FieldModifier="public" />
4444
</Grid.Shadow>
4545
<Grid.RowDefinitions>
46+
<RowDefinition Height="Auto" />
4647
<RowDefinition Height="Auto" />
4748
<RowDefinition Height="*" />
4849
</Grid.RowDefinitions>
@@ -58,7 +59,7 @@
5859
<!-- Swipe Backward Icon -->
5960
<Border
6061
x:Name="BackIcon"
61-
Grid.RowSpan="2"
62+
Grid.RowSpan="3"
6263
Width="48"
6364
Height="48"
6465
Margin="-4,0,0,0"
@@ -80,7 +81,7 @@
8081
<!-- Swipe Forward Icon -->
8182
<Border
8283
x:Name="ForwardIcon"
83-
Grid.RowSpan="2"
84+
Grid.RowSpan="3"
8485
Width="48"
8586
Height="48"
8687
Margin="0,0,-4,0"
@@ -99,10 +100,33 @@
99100
Symbol="Forward" />
100101
</Border>
101102

103+
<!-- Search header -->
104+
<Grid
105+
x:Name="SearchHeader"
106+
Grid.Row="0"
107+
Padding="26,16,16,16"
108+
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
109+
BorderThickness="0,0,0,1"
110+
Visibility="{x:Bind ShellViewModel.IsSearchResults, Mode=OneWay}">
111+
<StackPanel
112+
VerticalAlignment="Center"
113+
Orientation="Horizontal"
114+
Spacing="12">
115+
<Image
116+
Height="24"
117+
VerticalAlignment="Center"
118+
Source="{x:Bind ShellViewModel.SearchIconBitmapImage, Mode=OneWay}" />
119+
<TextBlock
120+
VerticalAlignment="Center"
121+
Style="{StaticResource SubtitleTextBlockStyle}"
122+
Text="{x:Bind ShellViewModel.SearchHeaderTitle, Mode=OneWay}" />
123+
</StackPanel>
124+
</Grid>
125+
102126
<!-- Filter header -->
103127
<Grid
104128
x:Name="FilterHeader"
105-
Grid.Row="0"
129+
Grid.Row="1"
106130
Padding="26,8,12,8"
107131
BorderBrush="{ThemeResource DividerStrokeColorDefaultBrush}"
108132
BorderThickness="0,0,0,1"
@@ -132,7 +156,7 @@
132156
<!-- Shell Frame -->
133157
<Frame
134158
x:Name="ItemDisplayFrame"
135-
Grid.Row="1"
159+
Grid.Row="2"
136160
x:FieldModifier="public"
137161
Navigated="ItemDisplayFrame_Navigated" />
138162

0 commit comments

Comments
 (0)