Skip to content

Commit

Permalink
Blindly, what if TaskViewModel was a FilteredCommand?
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 21, 2024
1 parent def6630 commit 69cb545
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 154 deletions.
146 changes: 0 additions & 146 deletions enc_temp_folder/5b479cd52f87a783d65d9ac223e3f1b/TasksPaneContent.xaml

This file was deleted.

2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/FilteredCommand.idl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import "HighlightedTextControl.idl";

namespace TerminalApp
{
[default_interface] runtimeclass FilteredCommand : Windows.UI.Xaml.Data.INotifyPropertyChanged
[default_interface] unsealed runtimeclass FilteredCommand : Windows.UI.Xaml.Data.INotifyPropertyChanged
{
FilteredCommand();
FilteredCommand(PaletteItem item);
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/TasksPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "PaneArgs.h"
#include "TasksPaneContent.g.cpp"
#include "TaskViewModel.g.cpp"
#include "FilteredTask.g.cpp"

using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Terminal::Settings;
Expand Down Expand Up @@ -44,10 +45,10 @@ namespace winrt::TerminalApp::implementation
// 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::TaskViewModel>();
auto itemSource = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
for (const auto& t : tasks)
{
itemSource.Append(winrt::make<TaskViewModel>(t));
itemSource.Append(winrt::make<FilteredTask>(t));
}

_treeView().ItemsSource(itemSource);
Expand Down
60 changes: 60 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
#pragma once
#include "TasksPaneContent.g.h"
#include "TaskViewModel.g.h"
#include "FilteredTask.g.h"
#include "FilteredCommand.h"
#include "ActionPaletteItem.h"

namespace winrt::TerminalApp::implementation
{
Expand Down Expand Up @@ -70,6 +73,7 @@ namespace winrt::TerminalApp::implementation
}
}
}

winrt::hstring Name() { return _command.Name(); }
winrt::hstring IconPath() { return _command.IconPath(); }
winrt::hstring Input()
Expand All @@ -87,6 +91,62 @@ namespace winrt::TerminalApp::implementation
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;

FilteredTask(const winrt::Microsoft::Terminal::Settings::Model::Command& command)
{
_command = command;
_Item = winrt::make<winrt::TerminalApp::implementation::ActionPaletteItem>(command);

// The Children() method must always return a non-null vector
_children = winrt::single_threaded_observable_vector<TerminalApp::FilteredTask>();
if (_command.HasNestedCommands())
{
for (const auto& [_, child] : _command.NestedCommands())
{
auto vm{ winrt::make<FilteredTask>(child) };
_children.Append(vm);
}
}
}

// FilteredCommand() = default;
// FilteredCommand(const winrt::TerminalApp::PaletteItem& item);

// void UpdateFilter(const winrt::hstring& filter);

// 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>() })
{
if (const auto& command{ actionItem.Command() })
{
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::FilteredTask> Children() { return _children; }

private:
winrt::Microsoft::Terminal::Settings::Model::Command _command{ nullptr };
winrt::Windows::Foundation::Collections::IObservableVector<TerminalApp::FilteredTask> _children{ nullptr };
};
}

namespace winrt::TerminalApp::factory_implementation
Expand Down
6 changes: 3 additions & 3 deletions src/cascadia/TerminalApp/TasksPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
FontSize="12" />
</DataTemplate>
<DataTemplate x:Key="TaskItemTemplate"
x:DataType="local:TaskViewModel">
x:DataType="local:FilteredTask">
<mux:TreeViewItem x:Name="rootItem"
ItemsSource="{x:Bind Children}">
<Grid>
Expand All @@ -46,7 +46,7 @@
<ContentPresenter Grid.Column="0">
<IconSourceElement Width="16"
Height="16"
IconSource="{x:Bind IconPath, Converter={StaticResource IconSourceConverter}}"
IconSource="{x:Bind Item.Icon, Converter={StaticResource IconSourceConverter}}"
Visibility="Collapsed" />
</ContentPresenter>
<!-- <Ellipse x:Name="Ellipse"
Expand Down Expand Up @@ -110,7 +110,7 @@
<TextBlock Grid.Column="1"
Margin="12,6,0,0"
Style="{ThemeResource BaseTextBlockStyle}"
Text="{x:Bind Name, Mode=OneWay}"
Text="{x:Bind Item.Name, Mode=OneWay}"
TextWrapping="WrapWholeWords" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Expand Down
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalPaneContent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT license.

import "IPaneContent.idl";
import "FilteredCommand.idl";

namespace TerminalApp
{
Expand Down Expand Up @@ -38,6 +39,11 @@ namespace TerminalApp
Windows.Foundation.Collections.IObservableVector<TaskViewModel> Children { get; };

}
[default_interface] runtimeclass FilteredTask : TerminalApp.FilteredCommand
{
String Input{ get; };
Windows.Foundation.Collections.IObservableVector<FilteredTask> Children { get; };
}

[default_interface] runtimeclass TasksPaneContent : Windows.UI.Xaml.Controls.UserControl, IPaneContent
{
Expand Down
4 changes: 2 additions & 2 deletions src/cascadia/inc/cppwinrt_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public: \
_##name = value; \
} \
\
private: \
protected: \
type _##name{ __VA_ARGS__ };

// Use this macro to quickly implement both the getter and setter for an
Expand All @@ -158,7 +158,7 @@ public:
} \
}; \
\
private: \
protected: \
type _##name{ __VA_ARGS__ }; \
void _set##name(const type& value) \
{ \
Expand Down

0 comments on commit 69cb545

Please sign in to comment.