5
5
#include " SnippetsPaneContent.h"
6
6
#include " SnippetsPaneContent.g.cpp"
7
7
#include " FilteredTask.g.cpp"
8
+ #include " SnippetsItemTemplateSelector.g.cpp"
8
9
9
10
using namespace winrt ::Windows::Foundation;
10
11
using namespace winrt ::Microsoft::Terminal::Settings;
@@ -23,7 +24,8 @@ namespace winrt::TerminalApp::implementation
23
24
{
24
25
InitializeComponent ();
25
26
26
- // auto res = Windows::UI::Xaml::Application::Current().Resources();
27
+ // _itemTemplateSelector = Resources().Lookup(winrt::box_value(L"SnippetsItemTemplateSelector")).try_as<SnippetsItemTemplateSelector>();
28
+
27
29
auto bg = Resources ().Lookup (winrt::box_value (L" PageBackground" ));
28
30
Background (bg.try_as <WUX::Media::Brush>());
29
31
}
@@ -129,4 +131,108 @@ namespace winrt::TerminalApp::implementation
129
131
}
130
132
}
131
133
134
+ // // Method Description:
135
+ // // - This event is triggered when filteredActionView is looking for item container (ListViewItem)
136
+ // // to use to present the filtered actions.
137
+ // // GH#9288: unfortunately the default lookup seems to choose items with wrong data templates,
138
+ // // e.g., using DataTemplate rendering actions for tab palette items.
139
+ // // We handle this event by manually selecting an item from the cache.
140
+ // // If no item is found we allocate a new one.
141
+ // // Arguments:
142
+ // // - args: the ChoosingItemContainerEventArgs allowing to get container candidate suggested by the
143
+ // // system and replace it with another candidate if required.
144
+ // // Return Value:
145
+ // // - <none>
146
+ // void SnippetsPaneContent::_choosingItemContainer(
147
+ // const Windows::UI::Xaml::Controls::ListViewBase& /*sender*/,
148
+ // const Windows::UI::Xaml::Controls::ChoosingItemContainerEventArgs& args)
149
+ // {
150
+ // const auto dataTemplate = _itemTemplateSelector.SelectTemplate(args.Item());
151
+ // const auto itemContainer = args.ItemContainer();
152
+ // if (itemContainer && itemContainer.ContentTemplate() == dataTemplate)
153
+ // {
154
+ // // If the suggested candidate is OK simply remove it from the cache
155
+ // // (so we won't allocate it until it is released) and return
156
+ // _listViewItemsCache[dataTemplate].erase(itemContainer);
157
+ // }
158
+ // else
159
+ // {
160
+ // // We need another candidate, let's look it up inside the cache
161
+ // auto& containersByTemplate = _listViewItemsCache[dataTemplate];
162
+ // if (!containersByTemplate.empty())
163
+ // {
164
+ // // There cache contains available items for required DataTemplate
165
+ // // Let's return one of them (and remove it from the cache)
166
+ // auto firstItem = containersByTemplate.begin();
167
+ // args.ItemContainer(*firstItem);
168
+ // containersByTemplate.erase(firstItem);
169
+ // }
170
+ // else
171
+ // {
172
+ // ElementFactoryGetArgs factoryArgs{};
173
+ // const auto listViewItem = _listItemTemplate.GetElement(factoryArgs).try_as<Controls::ListViewItem>();
174
+ // listViewItem.ContentTemplate(dataTemplate);
175
+
176
+ // if (dataTemplate == _itemTemplateSelector.NestedItemTemplate())
177
+ // {
178
+ // const auto helpText = winrt::box_value(RS_(L"CommandPalette_MoreOptions/[using:Windows.UI.Xaml.Automation]AutomationProperties/HelpText"));
179
+ // listViewItem.SetValue(Automation::AutomationProperties::HelpTextProperty(), helpText);
180
+ // }
181
+
182
+ // args.ItemContainer(listViewItem);
183
+ // }
184
+ // }
185
+ // args.IsContainerPrepared(true);
186
+ // }
187
+
188
+ // // Method Description:
189
+ // // - This event is triggered when the data item associate with filteredActionView list item is changing.
190
+ // // We check if the item is being recycled. In this case we return it to the cache
191
+ // // Arguments:
192
+ // // - args: the ContainerContentChangingEventArgs describing the container change
193
+ // // Return Value:
194
+ // // - <none>
195
+ // void SnippetsPaneContent::_containerContentChanging(
196
+ // const Windows::UI::Xaml::Controls::ListViewBase& /*sender*/,
197
+ // const Windows::UI::Xaml::Controls::ContainerContentChangingEventArgs& args)
198
+ // {
199
+ // const auto itemContainer = args.ItemContainer();
200
+ // if (args.InRecycleQueue() && itemContainer && itemContainer.ContentTemplate())
201
+ // {
202
+ // _listViewItemsCache[itemContainer.ContentTemplate()].insert(itemContainer);
203
+ // itemContainer.DataContext(nullptr);
204
+ // }
205
+ // else
206
+ // {
207
+ // itemContainer.DataContext(args.Item());
208
+ // }
209
+ // }
210
+
211
+ #pragma region(SnippetsItemTemplateSelector)
212
+
213
+ WUX::DataTemplate SnippetsItemTemplateSelector::SelectTemplateCore (const winrt::IInspectable& item, const winrt::WUX::DependencyObject& /* container*/ )
214
+ {
215
+ return SelectTemplateCore (item);
216
+ }
217
+
218
+ // Method Description:
219
+ // - This method is called once command palette decides how to render a filtered command.
220
+ // Currently we support two ways to render command, that depend on its palette item type:
221
+ // - For TabPalette item we render an icon, a title, and some tab-related indicators like progress bar (as defined by TabItemTemplate)
222
+ // - All other items are currently rendered with icon, title and optional key-chord (as defined by GeneralItemTemplate)
223
+ // Arguments:
224
+ // - item - an instance of filtered command to render
225
+ // Return Value:
226
+ // - data template to use for rendering
227
+ WUX::DataTemplate SnippetsItemTemplateSelector::SelectTemplateCore (const winrt::IInspectable& item)
228
+ {
229
+ if (const auto filteredTask{ item.try_as <winrt::TerminalApp::FilteredTask>() })
230
+ {
231
+ return filteredTask.HasChildren () ? NestedItemTemplate () : GeneralItemTemplate ();
232
+ }
233
+
234
+ return GeneralItemTemplate ();
235
+ }
236
+ #pragma endregion
237
+
132
238
}
0 commit comments