Skip to content

Commit 239bf69

Browse files
committed
remove template selector (improve accessible name)
1 parent eca3b28 commit 239bf69

File tree

4 files changed

+54
-117
lines changed

4 files changed

+54
-117
lines changed

src/cascadia/TerminalSettingsEditor/MainPage.xaml

Lines changed: 42 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -52,75 +52,6 @@
5252

5353
</ResourceDictionary.MergedDictionaries>
5454

55-
<DataTemplate x:Key="BasicSearchResultTemplate"
56-
x:DataType="local:FilteredSearchResult">
57-
<Grid HorizontalAlignment="Stretch"
58-
ColumnSpacing="8"
59-
ToolTipService.ToolTip="{x:Bind Label}">
60-
<Grid.ColumnDefinitions>
61-
<ColumnDefinition Width="Auto" />
62-
<ColumnDefinition Width="*" />
63-
</Grid.ColumnDefinitions>
64-
65-
<ContentPresenter Grid.Column="0"
66-
HorizontalAlignment="Center"
67-
VerticalAlignment="Center"
68-
Content="{x:Bind Icon}" />
69-
<TextBlock Grid.Column="1"
70-
Text="{x:Bind Label}"
71-
TextTrimming="CharacterEllipsis" />
72-
</Grid>
73-
</DataTemplate>
74-
75-
<DataTemplate x:Key="ComplexSearchResultTemplate"
76-
x:DataType="local:FilteredSearchResult">
77-
<Grid HorizontalAlignment="Stretch"
78-
ColumnSpacing="8">
79-
<Grid.ColumnDefinitions>
80-
<ColumnDefinition Width="Auto" />
81-
<ColumnDefinition Width="*" />
82-
</Grid.ColumnDefinitions>
83-
<Grid.RowDefinitions>
84-
<RowDefinition Height="Auto" />
85-
<RowDefinition Height="Auto" />
86-
</Grid.RowDefinitions>
87-
88-
<ContentPresenter Grid.Row="0"
89-
Grid.RowSpan="2"
90-
Grid.Column="0"
91-
HorizontalAlignment="Center"
92-
VerticalAlignment="Center"
93-
Content="{x:Bind Icon}" />
94-
<TextBlock Grid.Row="0"
95-
Grid.Column="1"
96-
FontSize="{ThemeResource BodyTextBlockFontSize}"
97-
Foreground="{ThemeResource TextFillColorPrimary}"
98-
Text="{x:Bind Label}"
99-
TextTrimming="CharacterEllipsis" />
100-
<TextBlock Grid.Row="1"
101-
Grid.Column="1"
102-
FontSize="{ThemeResource CaptionTextBlockFontSize}"
103-
Foreground="{ThemeResource TextFillColorSecondary}"
104-
Text="{x:Bind SecondaryLabel}"
105-
TextTrimming="CharacterEllipsis" />
106-
107-
<ToolTipService.ToolTip>
108-
<StackPanel>
109-
<TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
110-
Foreground="{ThemeResource TextFillColorPrimary}"
111-
Text="{x:Bind Label}" />
112-
<TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
113-
Foreground="{ThemeResource TextFillColorSecondary}"
114-
Text="{x:Bind SecondaryLabel}" />
115-
</StackPanel>
116-
</ToolTipService.ToolTip>
117-
</Grid>
118-
</DataTemplate>
119-
120-
<local:SearchResultTemplateSelector x:Key="SearchResultTemplateSelector"
121-
BasicTemplate="{StaticResource BasicSearchResultTemplate}"
122-
ComplexTemplate="{StaticResource ComplexSearchResultTemplate}" />
123-
12455
<SolidColorBrush x:Key="NavigationViewExpandedPaneBackground"
12556
Color="Transparent" />
12657
<SolidColorBrush x:Key="NavigationViewContentBackground"
@@ -171,11 +102,51 @@
171102
<muxc:NavigationView.AutoSuggestBox>
172103
<AutoSuggestBox x:Name="SettingsSearchBox"
173104
x:Uid="Nav_SearchBox"
174-
ItemTemplateSelector="{StaticResource SearchResultTemplateSelector}"
175105
QueryIcon="Find"
176106
QuerySubmitted="SettingsSearchBox_QuerySubmitted"
177107
SuggestionChosen="SettingsSearchBox_SuggestionChosen"
178-
TextChanged="SettingsSearchBox_TextChanged" />
108+
TextChanged="SettingsSearchBox_TextChanged">
109+
<AutoSuggestBox.ItemTemplate>
110+
<DataTemplate x:DataType="local:FilteredSearchResult">
111+
<Grid HorizontalAlignment="Stretch"
112+
ColumnSpacing="8">
113+
<Grid.ColumnDefinitions>
114+
<ColumnDefinition Width="Auto" />
115+
<ColumnDefinition Width="*" />
116+
</Grid.ColumnDefinitions>
117+
118+
<ContentPresenter Grid.Column="0"
119+
HorizontalAlignment="Center"
120+
VerticalAlignment="Center"
121+
Content="{x:Bind Icon}" />
122+
<StackPanel Grid.Column="1"
123+
VerticalAlignment="Center">
124+
<TextBlock FontSize="{ThemeResource BodyTextBlockFontSize}"
125+
Foreground="{ThemeResource TextFillColorPrimary}"
126+
Text="{x:Bind Label}"
127+
TextTrimming="CharacterEllipsis" />
128+
<TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
129+
Foreground="{ThemeResource TextFillColorSecondary}"
130+
Text="{x:Bind SecondaryLabel}"
131+
TextTrimming="CharacterEllipsis"
132+
Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SecondaryLabel)}" />
133+
</StackPanel>
134+
135+
<ToolTipService.ToolTip>
136+
<StackPanel>
137+
<TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
138+
Foreground="{ThemeResource TextFillColorPrimary}"
139+
Text="{x:Bind Label}" />
140+
<TextBlock FontSize="{ThemeResource CaptionTextBlockFontSize}"
141+
Foreground="{ThemeResource TextFillColorSecondary}"
142+
Text="{x:Bind SecondaryLabel}"
143+
Visibility="{x:Bind mtu:Converters.StringNotEmptyToVisibility(SecondaryLabel)}" />
144+
</StackPanel>
145+
</ToolTipService.ToolTip>
146+
</Grid>
147+
</DataTemplate>
148+
</AutoSuggestBox.ItemTemplate>
149+
</AutoSuggestBox>
179150
</muxc:NavigationView.AutoSuggestBox>
180151

181152
<muxc:NavigationView.MenuItems>

src/cascadia/TerminalSettingsEditor/SearchIndex.cpp

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#include "pch.h"
55
#include "SearchIndex.h"
66
#include "FilteredSearchResult.g.cpp"
7-
#include "SearchResultTemplateSelector.g.cpp"
87
#include "NavConstants.h"
98

109
#include <winrt/Windows.ApplicationModel.Resources.Core.h>
@@ -53,24 +52,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
5352
return loader;
5453
}
5554

56-
DataTemplate SearchResultTemplateSelector::SelectTemplateCore(const IInspectable& item, const DependencyObject& /*container*/)
57-
{
58-
return SelectTemplateCore(item);
59-
}
60-
61-
DataTemplate SearchResultTemplateSelector::SelectTemplateCore(const IInspectable& item)
62-
{
63-
if (const auto searchResultItem = item.try_as<FilteredSearchResult>())
64-
{
65-
if (!searchResultItem->SecondaryLabel().empty())
66-
{
67-
return ComplexTemplate();
68-
}
69-
return BasicTemplate();
70-
}
71-
return nullptr;
72-
}
73-
7455
Editor::FilteredSearchResult FilteredSearchResult::CreateNoResultsItem(const winrt::hstring& query)
7556
{
7657
return winrt::make<FilteredSearchResult>(nullptr, nullptr, hstring{ fmt::format(fmt::runtime(std::wstring{ RS_(L"Search_NoResults") }), query) });
@@ -125,6 +106,15 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
125106
return winrt::make<FilteredSearchResult>(searchIndexEntry, runtimeObj, runtimeObjLabel, runtimeObjContext);
126107
}
127108

109+
winrt::hstring FilteredSearchResult::AccessibleName() const
110+
{
111+
if (const auto secondaryLabel = SecondaryLabel(); !secondaryLabel.empty())
112+
{
113+
return hstring{ fmt::format(fmt::runtime(L"{}, {}"), Label(), secondaryLabel) };
114+
}
115+
return Label();
116+
}
117+
128118
winrt::hstring FilteredSearchResult::Label() const
129119
{
130120
if (_overrideLabel)

src/cascadia/TerminalSettingsEditor/SearchIndex.h

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#pragma once
55

66
#include "FilteredSearchResult.g.h"
7-
#include "SearchResultTemplateSelector.g.h"
87
#include "GeneratedSettingsIndex.g.h"
98
#include <til/generational.h>
109
#include "..\fzf\fzf.h"
@@ -37,7 +36,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
3736
static Editor::FilteredSearchResult CreateNoResultsItem(const winrt::hstring& query);
3837
static Editor::FilteredSearchResult CreateRuntimeObjectItem(const LocalizedIndexEntry* searchIndexEntry, const Windows::Foundation::IInspectable& runtimeObj);
3938

40-
hstring ToString() { return Label(); }
39+
hstring ToString() { return AccessibleName(); }
40+
winrt::hstring AccessibleName() const;
4141
winrt::hstring Label() const;
4242
winrt::hstring SecondaryLabel() const { return _secondaryLabel; };
4343
bool IsNoResultsPlaceholder() const;
@@ -52,20 +52,9 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
5252
const LocalizedIndexEntry* _SearchIndexEntry{ nullptr };
5353
};
5454

55-
struct SearchResultTemplateSelector : SearchResultTemplateSelectorT<SearchResultTemplateSelector>
56-
{
57-
SearchResultTemplateSelector() = default;
58-
59-
Windows::UI::Xaml::DataTemplate SelectTemplateCore(const Windows::Foundation::IInspectable& item, const Windows::UI::Xaml::DependencyObject& container);
60-
Windows::UI::Xaml::DataTemplate SelectTemplateCore(const Windows::Foundation::IInspectable& item);
61-
62-
til::property<winrt::Windows::UI::Xaml::DataTemplate> BasicTemplate;
63-
til::property<winrt::Windows::UI::Xaml::DataTemplate> ComplexTemplate;
64-
};
65-
6655
// The main search index implemented as a singleton.
6756
// The index loads data generated by tools\GenerateSettingsIndex.ps1 (outputs "Generated Files\GeneratedSettingsIndex.g.h" and cpp).
68-
// Outputs FilteredSearchResult objects for UI display. UI is determined by SearchResultTemplateSelector.
57+
// Outputs FilteredSearchResult objects for UI display.
6958
class SearchIndex final
7059
{
7160
public:
@@ -110,8 +99,3 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
11099
} _index;
111100
};
112101
}
113-
114-
namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
115-
{
116-
BASIC_FACTORY(SearchResultTemplateSelector);
117-
}

src/cascadia/TerminalSettingsEditor/SearchIndex.idl

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,4 @@ namespace Microsoft.Terminal.Settings.Editor
1111
String SecondaryLabel { get; };
1212
Windows.UI.Xaml.Controls.IconElement Icon { get; };
1313
}
14-
15-
runtimeclass SearchResultTemplateSelector : Windows.UI.Xaml.Controls.DataTemplateSelector
16-
{
17-
SearchResultTemplateSelector();
18-
19-
Windows.UI.Xaml.DataTemplate BasicTemplate;
20-
Windows.UI.Xaml.DataTemplate ComplexTemplate;
21-
}
2214
}

0 commit comments

Comments
 (0)