Skip to content

Commit

Permalink
this worked surprisingly quickly
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 16, 2024
1 parent 092b355 commit 81b35ff
Show file tree
Hide file tree
Showing 9 changed files with 180 additions and 1 deletion.
20 changes: 20 additions & 0 deletions src/cascadia/TerminalApp/AppActionHandlers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

#include "TerminalPage.h"
#include "ScratchpadContent.h"
#include "TasksPaneContent.h"
#include "../WinRTUtils/inc/WtExeUtils.h"
#include "../../types/inc/utils.hpp"
#include "Utils.h"
Expand Down Expand Up @@ -1442,4 +1443,23 @@ namespace winrt::TerminalApp::implementation
_ShowAboutDialog();
args.Handled(true);
}

void TerminalPage::_HandleOpenTasksPane(const IInspectable& sender,
const ActionEventArgs& args)
{
if (Feature_ScratchpadPane::IsEnabled())
{
const auto& scratchPane{ winrt::make_self<TasksPaneContent>(_settings) };

// This is maybe a little wacky - add our key event handler to the pane
// we made. So that we can get actions for keys that the content didn't
// handle.
scratchPane->GetRoot().KeyDown({ this, &TerminalPage::_KeyDownHandler });

const auto resultPane = std::make_shared<Pane>(*scratchPane);
_SplitPane(_senderOrFocusedTab(sender), SplitDirection::Automatic, 0.5f, resultPane);
args.Handled(true);
}
}

}
91 changes: 91 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "TasksPaneContent.h"
#include "PaneArgs.h"
#include "TasksPaneContent.g.cpp"

using namespace winrt::Windows::Foundation;
using namespace winrt::Microsoft::Terminal::Settings;
using namespace winrt::Microsoft::Terminal::Settings::Model;

namespace winrt
{
namespace WUX = Windows::UI::Xaml;
namespace MUX = Microsoft::UI::Xaml;
using IInspectable = Windows::Foundation::IInspectable;
}

namespace winrt::TerminalApp::implementation
{
TasksPaneContent::TasksPaneContent(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings)
{
_root = winrt::Windows::UI::Xaml::Controls::Grid{};
// Vertical and HorizontalAlignment are Stretch by default

auto res = Windows::UI::Xaml::Application::Current().Resources();
auto bg = res.Lookup(winrt::box_value(L"UnfocusedBorderBrush"));
_root.Background(bg.try_as<WUX::Media::Brush>());

_treeView = winrt::Microsoft::UI::Xaml::Controls::TreeView{};
_root.Children().Append(_treeView);
// _box.Margin({ 10, 10, 10, 10 });
// _box.AcceptsReturn(true);
// _box.TextWrapping(TextWrapping::Wrap);

UpdateSettings(settings);

settings;
}
MUX::Controls::TreeViewNode _buildTreeViewNode(Model::Command task)
{
MUX::Controls::TreeViewNode item{};
item.Content(winrt::box_value(task.Name()));
return item;
}
void TasksPaneContent::UpdateSettings(const CascadiaSettings& settings)
{
_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);
}
}

winrt::Windows::UI::Xaml::FrameworkElement TasksPaneContent::GetRoot()
{
return _root;
}
winrt::Windows::Foundation::Size TasksPaneContent::MinSize()
{
return { 1, 1 };
}
void TasksPaneContent::Focus(winrt::Windows::UI::Xaml::FocusState reason)
{
reason;
// _box.Focus(reason);
}
void TasksPaneContent::Close()
{
CloseRequested.raise(*this, nullptr);
}

NewTerminalArgs TasksPaneContent::GetNewTerminalArgs(const bool /* asContent */) const
{
return nullptr;
}

winrt::hstring TasksPaneContent::Icon() const
{
static constexpr std::wstring_view glyph{ L"\xe70b" }; // QuickNote
return winrt::hstring{ glyph };
}

winrt::Windows::UI::Xaml::Media::Brush TasksPaneContent::BackgroundBrush()
{
return _root.Background();
}
}
48 changes: 48 additions & 0 deletions src/cascadia/TerminalApp/TasksPaneContent.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

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

namespace winrt::TerminalApp::implementation
{
struct TasksPaneContent : TasksPaneContentT<TasksPaneContent>
{
TasksPaneContent(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);

winrt::Windows::UI::Xaml::FrameworkElement GetRoot();

void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);

winrt::Windows::Foundation::Size MinSize();
void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic);
void Close();
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const bool asContent) const;

winrt::hstring Title() { return L"Scratchpad"; }
uint64_t TaskbarState() { return 0; }
uint64_t TaskbarProgress() { return 0; }
bool ReadOnly() { return false; }
winrt::hstring Icon() const;
Windows::Foundation::IReference<winrt::Windows::UI::Color> TabColor() const noexcept { return nullptr; }
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush();

til::typed_event<> CloseRequested;
til::typed_event<winrt::Windows::Foundation::IInspectable, winrt::TerminalApp::BellEventArgs> BellRequested;
til::typed_event<> TitleChanged;
til::typed_event<> TabColorChanged;
til::typed_event<> TaskbarProgressChanged;
til::typed_event<> ConnectionStateChanged;
til::typed_event<> ReadOnlyChanged;
til::typed_event<> FocusRequested;

private:
winrt::Windows::UI::Xaml::Controls::Grid _root{ nullptr };
winrt::Microsoft::UI::Xaml::Controls::TreeView _treeView{ nullptr };
};
}

namespace winrt::TerminalApp::factory_implementation
{
BASIC_FACTORY(TasksPaneContent);
}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalAppLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@
<ClInclude Include="ScratchpadContent.h">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClInclude>
<ClInclude Include="TasksPaneContent.h">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClInclude>
<ClInclude Include="SettingsPaneContent.h">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -283,6 +286,9 @@
<ClCompile Include="ScratchpadContent.cpp">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClCompile>
<ClCompile Include="TasksPaneContent.cpp">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClCompile>
<ClCompile Include="SettingsPaneContent.cpp">
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
</ClCompile>
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 @@ -27,4 +27,10 @@ namespace TerminalApp
{
SettingsPaneContent(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);
}

[default_interface] runtimeclass TasksPaneContent : IPaneContent
{
TasksPaneContent(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);
}

}
2 changes: 2 additions & 0 deletions src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ static constexpr std::string_view RestartConnectionKey{ "restartConnection" };
static constexpr std::string_view ToggleBroadcastInputKey{ "toggleBroadcastInput" };
static constexpr std::string_view OpenScratchpadKey{ "experimental.openScratchpad" };
static constexpr std::string_view OpenAboutKey{ "openAbout" };
static constexpr std::string_view OpenTasksPaneKey{ "experimental.openTasks" };

static constexpr std::string_view ActionKey{ "action" };

Expand Down Expand Up @@ -434,6 +435,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
{ ShortcutAction::ToggleBroadcastInput, RS_(L"ToggleBroadcastInputCommandKey") },
{ ShortcutAction::OpenScratchpad, RS_(L"OpenScratchpadKey") },
{ ShortcutAction::OpenAbout, RS_(L"OpenAboutCommandKey") },
{ ShortcutAction::OpenTasksPane, RS_(L"OpenTasksPaneCommandKey") },
};
}();

Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsModel/AllShortcutActions.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
ON_ALL_ACTIONS(RestartConnection) \
ON_ALL_ACTIONS(ToggleBroadcastInput) \
ON_ALL_ACTIONS(OpenScratchpad) \
ON_ALL_ACTIONS(OpenAbout)
ON_ALL_ACTIONS(OpenAbout) \
ON_ALL_ACTIONS(OpenTasksPane)

#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \
ON_ALL_ACTIONS_WITH_ARGS(AdjustFontSize) \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -727,4 +727,8 @@
<value>Open about dialog</value>
<comment>This will open the "about" dialog, to display version info and other documentation</comment>
</data>
<data name="OpenTasksPaneCommandKey" xml:space="preserve">
<value>Open tasks pane</value>
<comment>This will open a pane with a list of the users's saved commands in it</comment>
</data>
</root>
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsModel/defaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,7 @@
{ "command": "quit" },
{ "command": "restoreLastClosed" },
{ "command": "openAbout" },
{ "command": "experimental.openTasks" },

// Tab Management
// "command": "closeTab" is unbound by default.
Expand Down

0 comments on commit 81b35ff

Please sign in to comment.