Skip to content

Commit 501522d

Browse files
authored
Add an experimental "scratchpad pane", for testing (#16171)
## Summary of the Pull Request Builds upon #16170. This PR simply adds a singly type of non-terminal pane - a "scratchpad pane". This is literally just a single text box, in a pane. It's on the `{ "command": "experimental.openScratchpad" }` action. ## References and Relevant Issues See: #997 ## Detailed Description of the Pull Request / Additional comments I also put it behind velocity so it won't even go into preview while this bakes. This is really just here to demonstrate that this works, and is viable. The next PR is much more interesting. ## Validation Steps Performed Screenshot below. ## other PRs * #16170 * #16171 <-- you are here * #16172
1 parent e8f18ea commit 501522d

File tree

8 files changed

+134
-1
lines changed

8 files changed

+134
-1
lines changed

src/cascadia/TerminalApp/AppActionHandlers.cpp

+20
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "App.h"
66

77
#include "TerminalPage.h"
8+
#include "ScratchpadContent.h"
89
#include "../WinRTUtils/inc/WtExeUtils.h"
910
#include "../../types/inc/utils.hpp"
1011
#include "Utils.h"
@@ -1416,6 +1417,25 @@ namespace winrt::TerminalApp::implementation
14161417
}
14171418
args.Handled(true);
14181419
}
1420+
1421+
void TerminalPage::_HandleOpenScratchpad(const IInspectable& /*sender*/,
1422+
const ActionEventArgs& args)
1423+
{
1424+
if (Feature_ScratchpadPane::IsEnabled())
1425+
{
1426+
const auto& scratchPane{ winrt::make_self<ScratchpadContent>() };
1427+
1428+
// This is maybe a little wacky - add our key event handler to the pane
1429+
// we made. So that we can get actions for keys that the content didn't
1430+
// handle.
1431+
scratchPane->GetRoot().KeyDown({ this, &TerminalPage::_KeyDownHandler });
1432+
1433+
const auto resultPane = std::make_shared<Pane>(*scratchPane);
1434+
_SplitPane(_GetFocusedTabImpl(), SplitDirection::Automatic, 0.5f, resultPane);
1435+
args.Handled(true);
1436+
}
1437+
}
1438+
14191439
void TerminalPage::_HandleOpenAbout(const IInspectable& /*sender*/,
14201440
const ActionEventArgs& args)
14211441
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#include "pch.h"
5+
#include "ScratchpadContent.h"
6+
7+
using namespace winrt::Windows::Foundation;
8+
using namespace winrt::Windows::UI::Xaml;
9+
using namespace winrt::Microsoft::Terminal::Settings::Model;
10+
11+
namespace winrt::TerminalApp::implementation
12+
{
13+
ScratchpadContent::ScratchpadContent()
14+
{
15+
_root = winrt::Windows::UI::Xaml::Controls::Grid{};
16+
// Vertical and HorizontalAlignment are Stretch by default
17+
18+
auto res = Windows::UI::Xaml::Application::Current().Resources();
19+
auto bg = res.Lookup(winrt::box_value(L"UnfocusedBorderBrush"));
20+
_root.Background(bg.try_as<Media::Brush>());
21+
22+
_box = winrt::Windows::UI::Xaml::Controls::TextBox{};
23+
_box.Margin({ 10, 10, 10, 10 });
24+
_box.AcceptsReturn(true);
25+
_box.TextWrapping(TextWrapping::Wrap);
26+
_root.Children().Append(_box);
27+
}
28+
29+
winrt::Windows::UI::Xaml::FrameworkElement ScratchpadContent::GetRoot()
30+
{
31+
return _root;
32+
}
33+
winrt::Windows::Foundation::Size ScratchpadContent::MinimumSize()
34+
{
35+
return { 1, 1 };
36+
}
37+
void ScratchpadContent::Focus(winrt::Windows::UI::Xaml::FocusState reason)
38+
{
39+
_box.Focus(reason);
40+
}
41+
void ScratchpadContent::Close()
42+
{
43+
CloseRequested.raise(*this, nullptr);
44+
}
45+
46+
NewTerminalArgs ScratchpadContent::GetNewTerminalArgs(const bool /* asContent */) const
47+
{
48+
return nullptr;
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT license.
3+
4+
#pragma once
5+
#include "winrt/TerminalApp.h"
6+
7+
namespace winrt::TerminalApp::implementation
8+
{
9+
class ScratchpadContent : public winrt::implements<ScratchpadContent, IPaneContent>
10+
{
11+
public:
12+
ScratchpadContent();
13+
14+
winrt::Windows::UI::Xaml::FrameworkElement GetRoot();
15+
16+
winrt::Windows::Foundation::Size MinimumSize();
17+
18+
void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic);
19+
void Close();
20+
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const bool asContent) const;
21+
22+
winrt::hstring Title() { return L"Scratchpad"; }
23+
uint64_t TaskbarState() { return 0; }
24+
uint64_t TaskbarProgress() { return 0; }
25+
bool ReadOnly() { return false; }
26+
27+
til::typed_event<> ConnectionStateChanged;
28+
til::typed_event<IPaneContent> CloseRequested;
29+
til::typed_event<IPaneContent, winrt::TerminalApp::BellEventArgs> BellRequested;
30+
til::typed_event<IPaneContent> TitleChanged;
31+
til::typed_event<IPaneContent> TabColorChanged;
32+
til::typed_event<IPaneContent> TaskbarProgressChanged;
33+
til::typed_event<IPaneContent> ReadOnlyChanged;
34+
til::typed_event<IPaneContent> FocusRequested;
35+
36+
private:
37+
winrt::Windows::UI::Xaml::Controls::Grid _root{ nullptr };
38+
winrt::Windows::UI::Xaml::Controls::TextBox _box{ nullptr };
39+
};
40+
}

src/cascadia/TerminalApp/TerminalAppLib.vcxproj

+6
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@
161161
<ClInclude Include="TerminalPaneContent.h">
162162
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
163163
</ClInclude>
164+
<ClInclude Include="ScratchpadContent.h">
165+
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
166+
</ClInclude>
164167
<ClInclude Include="Toast.h" />
165168
<ClInclude Include="SuggestionsControl.h">
166169
<DependentUpon>SuggestionsControl.xaml</DependentUpon>
@@ -268,6 +271,9 @@
268271
<ClCompile Include="TerminalPaneContent.cpp">
269272
<DependentUpon>TerminalPaneContent.idl</DependentUpon>
270273
</ClCompile>
274+
<ClCompile Include="ScratchpadContent.cpp">
275+
<DependentUpon>ScratchpadContent.idl</DependentUpon>
276+
</ClCompile>
271277
<ClCompile Include="$(GeneratedFilesDir)module.g.cpp" />
272278
<ClCompile Include="Toast.cpp" />
273279
<ClCompile Include="SuggestionsControl.cpp">

src/cascadia/TerminalSettingsModel/ActionAndArgs.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ static constexpr std::string_view ShowContextMenuKey{ "showContextMenu" };
9696
static constexpr std::string_view ExpandSelectionToWordKey{ "expandSelectionToWord" };
9797
static constexpr std::string_view RestartConnectionKey{ "restartConnection" };
9898
static constexpr std::string_view ToggleBroadcastInputKey{ "toggleBroadcastInput" };
99+
static constexpr std::string_view OpenScratchpadKey{ "experimental.openScratchpad" };
99100
static constexpr std::string_view OpenAboutKey{ "openAbout" };
100101

101102
static constexpr std::string_view ActionKey{ "action" };
@@ -431,6 +432,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
431432
{ ShortcutAction::ExpandSelectionToWord, RS_(L"ExpandSelectionToWordCommandKey") },
432433
{ ShortcutAction::RestartConnection, RS_(L"RestartConnectionKey") },
433434
{ ShortcutAction::ToggleBroadcastInput, RS_(L"ToggleBroadcastInputCommandKey") },
435+
{ ShortcutAction::OpenScratchpad, RS_(L"OpenScratchpadKey") },
434436
{ ShortcutAction::OpenAbout, RS_(L"OpenAboutCommandKey") },
435437
};
436438
}();

src/cascadia/TerminalSettingsModel/AllShortcutActions.h

+1
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@
110110
ON_ALL_ACTIONS(CloseOtherPanes) \
111111
ON_ALL_ACTIONS(RestartConnection) \
112112
ON_ALL_ACTIONS(ToggleBroadcastInput) \
113+
ON_ALL_ACTIONS(OpenScratchpad) \
113114
ON_ALL_ACTIONS(OpenAbout)
114115

115116
#define ALL_SHORTCUT_ACTIONS_WITH_ARGS \

src/cascadia/TerminalSettingsModel/Resources/en-US/Resources.resw

+4-1
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,9 @@
700700
<data name="RestartConnectionKey" xml:space="preserve">
701701
<value>Restart connection</value>
702702
</data>
703+
<data name="OpenScratchpadKey" xml:space="preserve">
704+
<value>Open scratchpad</value>
705+
</data>
703706
<data name="SelectOutputNextCommandKey" xml:space="preserve">
704707
<value>Select next command output</value>
705708
</data>
@@ -724,4 +727,4 @@
724727
<value>Open about dialog</value>
725728
<comment>This will open the "about" dialog, to display version info and other documentation</comment>
726729
</data>
727-
</root>
730+
</root>

src/features.xml

+11
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,17 @@
159159
</alwaysEnabledBrandingTokens>
160160
</feature>
161161

162+
<feature>
163+
<name>Feature_ScratchpadPane</name>
164+
<description>Allow the user to create scratchpad panes. Mostly just exists to validate non-terminal panes.</description>
165+
<id>997</id>
166+
<stage>AlwaysDisabled</stage>
167+
<alwaysEnabledBrandingTokens>
168+
<brandingToken>Dev</brandingToken>
169+
<brandingToken>Canary</brandingToken>
170+
</alwaysEnabledBrandingTokens>
171+
</feature>
172+
162173
<feature>
163174
<name>Feature_KeypadModeEnabled</name>
164175
<description>Enables the DECKPAM, DECKPNM sequences to work as intended </description>

0 commit comments

Comments
 (0)