Skip to content

Commit

Permalink
omg bind to the IsSelected
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 16, 2024
1 parent 0bb13f9 commit 8418d6a
Show file tree
Hide file tree
Showing 4 changed files with 106 additions and 5 deletions.
15 changes: 12 additions & 3 deletions src/cascadia/TerminalApp/TasksPaneContent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "TasksPaneContent.h"
#include "PaneArgs.h"
#include "TasksPaneContent.g.cpp"
#include "TaskViewModel.g.cpp"

using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Terminal::Settings;
Expand Down Expand Up @@ -53,13 +54,21 @@ namespace winrt::TerminalApp::implementation
}
void TasksPaneContent::UpdateSettings(const CascadiaSettings& settings)
{
_treeView().RootNodes().Clear();
// _treeView().RootNodes().Clear();
const auto tasks = settings.GlobalSettings().ActionMap().FilterToSendInput(L""); // IVector<Model::Command>
// for (const auto& t : tasks)
// {
// const auto& treeNode = _buildTreeViewNode(t);
// _treeView().RootNodes().Append(treeNode);
// }

auto itemSource = winrt::single_threaded_observable_vector<TerminalApp::TaskViewModel>();
for (const auto& t : tasks)
{
const auto& treeNode = _buildTreeViewNode(t);
_treeView().RootNodes().Append(treeNode);
// const auto& treeNode = _buildTreeViewNode(t);
itemSource.Append(winrt::make<TaskViewModel>(t));
}
_treeView().ItemsSource(itemSource);
}

winrt::Windows::UI::Xaml::FrameworkElement TasksPaneContent::GetRoot()
Expand Down
35 changes: 35 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#pragma once
#include "TasksPaneContent.g.h"
#include "TaskViewModel.g.h"

namespace winrt::TerminalApp::implementation
{
Expand Down Expand Up @@ -40,9 +41,43 @@ namespace winrt::TerminalApp::implementation
// winrt::Windows::UI::Xaml::Controls::Grid _root{ nullptr };
// winrt::Microsoft::UI::Xaml::Controls::TreeView _treeView{ nullptr };
};

struct TaskViewModel : TaskViewModelT<TaskViewModel>
{
TaskViewModel(const winrt::Microsoft::Terminal::Settings::Model::Command& command) :
_command{ command }
{
_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{};
};
}

namespace winrt::TerminalApp::factory_implementation
{
BASIC_FACTORY(TasksPaneContent);
BASIC_FACTORY(TaskViewModel);
}
50 changes: 48 additions & 2 deletions src/cascadia/TerminalApp/TasksPaneContent.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,59 @@
AutomationProperties.Name="{x:Bind Item.Name, Mode=OneWay}"
FontSize="12" />
</DataTemplate>
<DataTemplate x:Key="TaskItemTemplate"
x:DataType="local:TaskViewModel">
<mux:TreeViewItem x:Name="asdf"
ItemsSource="{x:Bind Children}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<ContentPresenter Grid.Column="0">
<IconSourceElement Width="16"
Height="16"
IconSource="{x:Bind IconPath, 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}"/>-->
<TextBlock Grid.Column="1"
Margin="12,6,0,0"
x:Phase="1"
Style="{ThemeResource BaseTextBlockStyle}"
Text="{x:Bind Name, Mode=OneWay}" />
<TextBlock Grid.Row="1"
Grid.Column="1"
Margin="12,0,0,6"
x:Phase="2"
MaxLines="1"
Style="{ThemeResource BodyTextBlockStyle}"
Text="{x:Bind Input}"
Visibility="{Binding ElementName=asdf, Path=IsSelected}" />
</Grid>
</mux:TreeViewItem>
</DataTemplate>
</ResourceDictionary>
</UserControl.Resources>

<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="_title"
Margin="9"
FontSize="24"
Text="Tasks" />
<mux:TreeView x:Name="_treeView" />
<mux:TreeView x:Name="_treeView"
ItemTemplate="{StaticResource TaskItemTemplate}" />
</StackPanel>

</UserControl>
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/TerminalPaneContent.idl
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,17 @@ 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 TasksPaneContent : Windows.UI.Xaml.Controls.UserControl, IPaneContent
{
TasksPaneContent();
Expand Down

0 comments on commit 8418d6a

Please sign in to comment.