lots of cleanup

This commit is contained in:
Mike Griese
2024-02-21 12:14:47 -06:00
parent 02a5593f5b
commit 14a00c8abf
4 changed files with 22 additions and 99 deletions

View File

@@ -34,32 +34,24 @@ namespace winrt::TerminalApp::implementation
{
const auto& queryString = _filterBox().Text();
// You'd think that `FilterToSendInput(queryString)` would work. It
// doesn't! That uses the queryString as the current command the user
// has typed, then relies on the sxnui to _also_ filter with that
// string.
// In the fullness of time, we'll actually want to filter things here.
// Probably with something that re-uses the suggestions control list
//
// huh. now that's a thought.
// const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(L""); // IVector<Model::Command>
// auto itemSource = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
// DON'T replace the itemSource here. If you do, it'll un-expand all the
// nested items the user has expanded. Instead, just update the filter.
// That'll also trigger a PropertyChanged for the Visibility property.
for (const auto& t : _allTasks)
{
// const auto& filtered{ winrt::make<FilteredTask>(t) };
t.UpdateFilter(queryString);
// itemSource.Append(filtered);
}
// _treeView().ItemsSource(itemSource);
}
void TasksPaneContent::UpdateSettings(const CascadiaSettings& settings)
{
_settings = settings;
// You'd think that `FilterToSendInput(queryString)` would work. It
// doesn't! That uses the queryString as the current command the user
// has typed, then relies on the sxnui to _also_ filter with that
// string.
const auto tasks = _settings.GlobalSettings().ActionMap().FilterToSendInput(L""); // IVector<Model::Command>
_allTasks = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
for (const auto& t : tasks)

View File

@@ -23,7 +23,8 @@ namespace winrt::TerminalApp::implementation
void Close();
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const bool asContent) const;
winrt::hstring Title() { return L"Scratchpad"; }
// TODO! lots of strings here and in XAML that need RS_-ifying
winrt::hstring Title() { return L"Tasks"; }
uint64_t TaskbarState() { return 0; }
uint64_t TaskbarProgress() { return 0; }
bool ReadOnly() { return false; }
@@ -58,42 +59,6 @@ namespace winrt::TerminalApp::implementation
void _updateFilteredCommands();
};
struct TaskViewModel : TaskViewModelT<TaskViewModel>
{
TaskViewModel(const winrt::Microsoft::Terminal::Settings::Model::Command& command) :
_command{ command }
{
// The Children() method must always return a non-null vector
_children = winrt::single_threaded_observable_vector<TerminalApp::TaskViewModel>();
if (_command.HasNestedCommands())
{
for (const auto& [_, child] : _command.NestedCommands())
{
auto vm{ winrt::make<TaskViewModel>(child) };
_children.Append(vm);
}
}
}
winrt::hstring Name() { return _command.Name(); }
winrt::hstring IconPath() { return _command.IconPath(); }
winrt::hstring Input()
{
if (const auto& sendInput{ _command.ActionAndArgs().Args().try_as<winrt::Microsoft::Terminal::Settings::Model::SendInputArgs>() })
{
return sendInput.Input();
}
return L"";
};
winrt::Windows::Foundation::Collections::IObservableVector<TerminalApp::TaskViewModel> Children() { return _children; }
winrt::Microsoft::Terminal::Settings::Model::Command Command() { return _command; }
private:
winrt::Microsoft::Terminal::Settings::Model::Command _command{ nullptr };
winrt::Windows::Foundation::Collections::IObservableVector<TerminalApp::TaskViewModel> _children{ nullptr };
};
// struct FilteredTask : public winrt::TerminalApp::implementation::FilteredCommand, FilteredTaskT<FilteredTask, FilteredCommand>
struct FilteredTask : FilteredTaskT<FilteredTask, TerminalApp::implementation::FilteredCommand>
{
FilteredTask() = default;
@@ -115,9 +80,6 @@ namespace winrt::TerminalApp::implementation
}
}
// FilteredCommand() = default;
// FilteredCommand(const winrt::TerminalApp::PaletteItem& item);
void UpdateFilter(const winrt::hstring& filter) override
{
TerminalApp::implementation::FilteredCommand::UpdateFilter(filter);
@@ -129,14 +91,6 @@ namespace winrt::TerminalApp::implementation
_PropertyChangedHandlers(*this, Windows::UI::Xaml::Data::PropertyChangedEventArgs{ L"Visibility" });
}
// static int Compare(const winrt::TerminalApp::FilteredCommand& first, const winrt::TerminalApp::FilteredCommand& second);
// WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
// WINRT_OBSERVABLE_PROPERTY(winrt::TerminalApp::PaletteItem, Item, _PropertyChangedHandlers, nullptr);
// WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Filter, _PropertyChangedHandlers);
// WINRT_OBSERVABLE_PROPERTY(winrt::TerminalApp::HighlightedText, HighlightedName, _PropertyChangedHandlers);
// WINRT_OBSERVABLE_PROPERTY(int, Weight, _PropertyChangedHandlers);
winrt::hstring Input()
{
if (const auto& actionItem{ _Item.try_as<winrt::TerminalApp::ActionPaletteItem>() })
@@ -155,12 +109,17 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::Foundation::Collections::IObservableVector<TerminalApp::FilteredTask> Children() { return _children; }
winrt::Microsoft::Terminal::Settings::Model::Command Command() { return _command; }
// Used to control if this item is visible in the TreeView. Turns out,
// TreeView is in fact sane enough to remove items entirely if they're
// Collapsed.
winrt::Windows::UI::Xaml::Visibility Visibility()
{
// Is there no filter, or do we match it?
if (_Filter.empty() || _Weight > 0)
{
return winrt::Windows::UI::Xaml::Visibility::Visible;
}
// If we don't match, maybe one of our children does
auto totalWeight = _Weight;
for (const auto& c : _children)
{

View File

@@ -20,16 +20,6 @@
<ResourceDictionary>
<model:IconPathConverter x:Key="IconSourceConverter" />
<DataTemplate x:Key="ListItemTemplate"
x:DataType="local:FilteredCommand">
<ListViewItem Height="32"
MinHeight="0"
Padding="16,0,12,0"
HorizontalContentAlignment="Stretch"
AutomationProperties.AcceleratorKey="{x:Bind Item.KeyChordText, Mode=OneWay}"
AutomationProperties.Name="{x:Bind Item.Name, Mode=OneWay}"
FontSize="12" />
</DataTemplate>
<DataTemplate x:Key="TaskItemTemplate"
x:DataType="local:FilteredTask">
<mux:TreeViewItem x:Name="rootItem"
@@ -44,20 +34,14 @@
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0">
<IconSourceElement Width="16"
Height="16"
IconSource="{x:Bind Item.Icon, Converter={StaticResource IconSourceConverter}}"
Visibility="Collapsed" />
</ContentPresenter>
<!-- <Ellipse x:Name="Ellipse"
Grid.RowSpan="2"
Width ="32"
Height="32"
Margin="6"
VerticalAlignment="Center"
HorizontalAlignment="Center"
Fill="{ThemeResource SystemControlBackgroundBaseMediumBrush}"/>-->
<Button Grid.Row="0"
Grid.RowSpan="1"
Grid.Column="0"
@@ -72,7 +56,11 @@
<FontIcon FontFamily="Segoe Fluent Icons, Segoe MDL2 Assets"
FontSize="12"
Glyph="&#xE768;" />
<!-- xF5B0 is PlaySolid, also a good option. Seemed better to have a lightweight outline though -->
<!--
xE768 is Play, which is just an outline.
xF5B0 is PlaySolid, also a good option. Seemed
better to have a lightweight outline though
-->
</Button.Content>
<Button.Resources>
@@ -109,12 +97,6 @@
</Button.Resources>
</Button>
<!-- <TextBlock Grid.Column="1"
Margin="12,6,0,0"
Style="{ThemeResource BaseTextBlockStyle}"
Text="{x:Bind Item.Name, Mode=OneWay}"
TextWrapping="WrapWholeWords" />-->
<local:HighlightedTextControl Grid.Column="1"
HorizontalAlignment="Left"
Text="{x:Bind HighlightedName, Mode=OneWay}" />

View File

@@ -29,16 +29,6 @@ namespace TerminalApp
SettingsPaneContent(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);
}
[default_interface] runtimeclass TaskViewModel
{
TaskViewModel(Microsoft.Terminal.Settings.Model.Command command);
String Name{ get; };
String IconPath{ get; };
String Input{ get; };
Microsoft.Terminal.Settings.Model.Command Command{ get; };
Windows.Foundation.Collections.IObservableVector<TaskViewModel> Children { get; };
}
[default_interface] runtimeclass FilteredTask : TerminalApp.FilteredCommand
{
String Input{ get; };