Skip to content

Commit

Permalink
I literally think this is the whole thing
Browse files Browse the repository at this point in the history
  • Loading branch information
zadjii-msft committed Feb 1, 2023
1 parent e623299 commit 1b4f1ef
Show file tree
Hide file tree
Showing 18 changed files with 137 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/cascadia/TerminalApp/AppLogic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -687,12 +687,17 @@ namespace winrt::TerminalApp::implementation
{
ReloadSettings();
}
auto window = winrt::make_self<implementation::TerminalWindow>(_settings);
auto window = winrt::make_self<implementation::TerminalWindow>(_settings, _contentManager);
this->SettingsChanged({ window->get_weak(), &implementation::TerminalWindow::UpdateSettingsHandler });
if (_hasSettingsStartupActions)
{
window->SetSettingsStartupArgs(_settingsAppArgs.GetStartupActions());
}
return *window;
}

winrt::TerminalApp::ContentManager AppLogic::ContentManager()
{
return _contentManager;
}
}
4 changes: 4 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "LanguageProfileNotifier.h"
#include "AppCommandlineArgs.h"
#include "TerminalWindow.h"
#include "ContentManager.h"

#include <inc/cppwinrt_utils.h>
#include <ThrottledFunc.h>
Expand Down Expand Up @@ -68,6 +69,7 @@ namespace winrt::TerminalApp::implementation

TerminalApp::TerminalWindow CreateNewWindow();

winrt::TerminalApp::ContentManager ContentManager();
TYPED_EVENT(SettingsChanged, winrt::Windows::Foundation::IInspectable, winrt::Windows::Foundation::IInspectable);

private:
Expand All @@ -93,6 +95,8 @@ namespace winrt::TerminalApp::implementation
winrt::com_ptr<LanguageProfileNotifier> _languageProfileNotifier;
wil::unique_folder_change_reader_nothrow _reader;

TerminalApp::ContentManager _contentManager{ *winrt::make_self<implementation::ContentManager>() };

static TerminalApp::FindTargetWindowResult _doFindTargetWindow(winrt::array_view<const hstring> args,
const Microsoft::Terminal::Settings::Model::WindowingMode& windowingBehavior);

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/AppLogic.idl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ namespace TerminalApp
void RunAsUwp();
Boolean IsElevated();

ContentManager ContentManager { get; };

Boolean HasSettingsStartupActions();

void ReloadSettings();
Expand Down
43 changes: 43 additions & 0 deletions src/cascadia/TerminalApp/ContentManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "ContentManager.h"
#include "ContentManager.g.cpp"

#include <wil/token_helpers.h>

#include "../../types/inc/utils.hpp"

using namespace winrt::Windows::ApplicationModel;
using namespace winrt::Windows::ApplicationModel::DataTransfer;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Xaml::Controls;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::System;
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::Control;
using namespace winrt::Microsoft::Terminal::Settings::Model;

namespace winrt
{
namespace MUX = Microsoft::UI::Xaml;
using IInspectable = Windows::Foundation::IInspectable;
}
namespace winrt::TerminalApp::implementation
{
ControlInteractivity ContentManager::CreateCore(Microsoft::Terminal::Control::IControlSettings settings,
IControlAppearance unfocusedAppearance,
TerminalConnection::ITerminalConnection connection)
{
auto content = ControlInteractivity{ settings, unfocusedAppearance, connection };
// winrt::guid g{ ::Microsoft::Console::Utils::CreateGuid() };
_content.Insert(content.Id(), content);
return content;
}

ControlInteractivity ContentManager::LookupCore(winrt::guid id)
{
return _content.TryLookup(id);
}
}
25 changes: 25 additions & 0 deletions src/cascadia/TerminalApp/ContentManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once

#include "ContentManager.g.h"

#include <inc/cppwinrt_utils.h>
namespace winrt::TerminalApp::implementation
{
struct ContentManager : ContentManagerT<ContentManager>
{
public:
ContentManager() = default;
Microsoft::Terminal::Control::ControlInteractivity CreateCore(Microsoft::Terminal::Control::IControlSettings settings,
Microsoft::Terminal::Control::IControlAppearance unfocusedAppearance,
Microsoft::Terminal::TerminalConnection::ITerminalConnection connection);
Microsoft::Terminal::Control::ControlInteractivity LookupCore(winrt::guid id);

private:
Windows::Foundation::Collections::IMap<winrt::guid, Microsoft::Terminal::Control::ControlInteractivity> _content{
winrt::multi_threaded_map<winrt::guid, Microsoft::Terminal::Control::ControlInteractivity>()
};
};
}
6 changes: 6 additions & 0 deletions src/cascadia/TerminalApp/TerminalAppLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@
<ClInclude Include="AppLogic.h">
<DependentUpon>AppLogic.idl</DependentUpon>
</ClInclude>
<ClInclude Include="ContentManager.h">
<DependentUpon>TerminalPage.idl</DependentUpon>
</ClInclude>
<ClInclude Include="TerminalWindow.h">
<DependentUpon>TerminalWindow.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -234,6 +237,9 @@
<ClCompile Include="AppLogic.cpp">
<DependentUpon>AppLogic.idl</DependentUpon>
</ClCompile>
<ClCompile Include="ContentManager.cpp">
<DependentUpon>TerminalPage.idl</DependentUpon>
</ClCompile>
<ClCompile Include="TerminalWindow.cpp">
<DependentUpon>TerminalWindow.idl</DependentUpon>
</ClCompile>
Expand Down
8 changes: 6 additions & 2 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,11 @@ namespace winrt

namespace winrt::TerminalApp::implementation
{
TerminalPage::TerminalPage() :
TerminalPage::TerminalPage(const TerminalApp::ContentManager& manager) :
_tabs{ winrt::single_threaded_observable_vector<TerminalApp::TabBase>() },
_mruTabs{ winrt::single_threaded_observable_vector<TerminalApp::TabBase>() },
_startupActions{ winrt::single_threaded_vector<ActionAndArgs>() },
_manager{ manager },
_hostingHwnd{}
{
InitializeComponent();
Expand Down Expand Up @@ -2645,7 +2646,10 @@ namespace winrt::TerminalApp::implementation
// Do any initialization that needs to apply to _every_ TermControl we
// create here.
// TermControl will copy the settings out of the settings passed to it.
TermControl term{ settings.DefaultSettings(), settings.UnfocusedSettings(), connection };

auto content = _manager.CreateCore(settings.DefaultSettings(), settings.UnfocusedSettings(), connection);

TermControl term{ content };

// GH#12515: ConPTY assumes it's hidden at the start. If we're not, let it know now.
if (_visible)
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ namespace winrt::TerminalApp::implementation
struct TerminalPage : TerminalPageT<TerminalPage>
{
public:
TerminalPage();
TerminalPage(const TerminalApp::ContentManager& manager);

// This implements shobjidl's IInitializeWithWindow, but due to a XAML Compiler bug we cannot
// put it in our inheritance graph. https://github.com/microsoft/microsoft-ui-xaml/issues/3331
Expand Down Expand Up @@ -253,6 +253,7 @@ namespace winrt::TerminalApp::implementation
bool _renamerPressedEnter{ false };

TerminalApp::IWindowProperties _WindowProperties{ nullptr };
TerminalApp::ContentManager _manager{ nullptr };

winrt::Windows::Foundation::IAsyncOperation<winrt::Windows::UI::Xaml::Controls::ContentDialogResult> _ShowDialogHelper(const std::wstring_view& name);

Expand Down
13 changes: 12 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ import "IDirectKeyListener.idl";

namespace TerminalApp
{

// See IDialogPresenter and TerminalPage's DialogPresenter for more
// information.
[default_interface] runtimeclass ContentManager
{
Microsoft.Terminal.Control.ControlInteractivity CreateCore(Microsoft.Terminal.Control.IControlSettings settings,
Microsoft.Terminal.Control.IControlAppearance unfocusedAppearance,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
Microsoft.Terminal.Control.ControlInteractivity LookupCore(Guid id);
}

delegate void LastTabClosedEventArgs();

[default_interface] runtimeclass RenameWindowRequestedArgs
Expand All @@ -28,7 +39,7 @@ namespace TerminalApp

[default_interface] runtimeclass TerminalPage : Windows.UI.Xaml.Controls.Page, Windows.UI.Xaml.Data.INotifyPropertyChanged, IDirectKeyListener
{
TerminalPage();
TerminalPage(ContentManager manager);

// XAML bound properties
String ApplicationDisplayName { get; };
Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalApp/TerminalWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,8 @@ static Documents::Run _BuildErrorRun(const winrt::hstring& text, const ResourceD

namespace winrt::TerminalApp::implementation
{
TerminalWindow::TerminalWindow(const CascadiaSettings& settings) :
TerminalWindow::TerminalWindow(const CascadiaSettings& settings, const TerminalApp::ContentManager& manager) :
_manager{ manager },
_settings{ settings }
{
// For your own sanity, it's better to do setup outside the ctor.
Expand All @@ -154,7 +155,7 @@ namespace winrt::TerminalApp::implementation
// - Implements the IInitializeWithWindow interface from shobjidl_core.
HRESULT TerminalWindow::Initialize(HWND hwnd)
{
_root = winrt::make_self<TerminalPage>();
_root = winrt::make_self<TerminalPage>(_manager);
_root->WindowProperties(*this);
_dialog = ContentDialog{};

Expand Down
4 changes: 3 additions & 1 deletion src/cascadia/TerminalApp/TerminalWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ namespace winrt::TerminalApp::implementation
struct TerminalWindow : TerminalWindowT<TerminalWindow, IInitializeWithWindow>
{
public:
TerminalWindow(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings);
TerminalWindow(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings, const TerminalApp::ContentManager& manager);
~TerminalWindow() = default;

STDMETHODIMP Initialize(HWND hwnd);
Expand Down Expand Up @@ -158,6 +158,8 @@ namespace winrt::TerminalApp::implementation

Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr };

TerminalApp::ContentManager _manager{ nullptr };

void _ShowLoadErrorsDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey, HRESULT settingsLoadedResult);
void _ShowLoadWarningsDialog();
bool _IsKeyboardServiceEnabled();
Expand Down
3 changes: 1 addition & 2 deletions src/cascadia/TerminalApp/TerminalWindow.idl
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ namespace TerminalApp
// information.
[default_interface] runtimeclass TerminalWindow : IDirectKeyListener, IDialogPresenter, IWindowProperties, Windows.UI.Xaml.Data.INotifyPropertyChanged
{
TerminalWindow(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);

TerminalWindow(Microsoft.Terminal.Settings.Model.CascadiaSettings settings, ContentManager manager);

// For your own sanity, it's better to do setup outside the ctor.
// If you do any setup in the ctor that ends up throwing an exception,
Expand Down
7 changes: 7 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,16 @@ namespace winrt::Microsoft::Terminal::Control::implementation
_lastMouseClickPos{},
_selectionNeedsToBeCopied{ false }
{
_guid = ::Microsoft::Console::Utils::CreateGuid();

_core = winrt::make_self<ControlCore>(settings, unfocusedAppearance, connection);
}

winrt::guid ControlInteractivity::Id()
{
return _guid;
}

// Method Description:
// - Updates our internal settings. These settings should be
// interactivity-specific. Right now, we primarily update _rowsToScroll
Expand Down
4 changes: 4 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
void SetEndSelectionPoint(const Core::Point pixelPosition);
bool ManglePathsForWsl();

winrt::guid Id();

TYPED_EVENT(OpenHyperlink, IInspectable, Control::OpenHyperlinkEventArgs);
TYPED_EVENT(PasteFromClipboard, IInspectable, Control::PasteFromClipboardEventArgs);
TYPED_EVENT(ScrollPositionChanged, IInspectable, Control::ScrollPositionChangedArgs);
Expand Down Expand Up @@ -129,6 +131,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation

std::optional<interval_tree::IntervalTree<til::point, size_t>::interval> _lastHoveredInterval{ std::nullopt };

winrt::guid _guid;

unsigned int _numberOfClicks(Core::Point clickPos, Timestamp clickTime);
void _updateSystemParameterSettings() noexcept;

Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/ControlInteractivity.idl
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace Microsoft.Terminal.Control
void GotFocus();
void LostFocus();

Guid Id { get; };

InteractivityAutomationPeer OnCreateAutomationPeer();

Boolean CopySelectionToClipboard(Boolean singleLine, Windows.Foundation.IReference<CopyFormat> formats);
Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalControl/TermControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ namespace winrt::Microsoft::Terminal::Control::implementation
TermControl::TermControl(IControlSettings settings,
Control::IControlAppearance unfocusedAppearance,
TerminalConnection::ITerminalConnection connection) :
TermControl{ winrt::make<implementation::ControlInteractivity>(settings, unfocusedAppearance, connection) }
{
}

TermControl::TermControl(Control::ControlInteractivity content) :
_interactivity{ content },
_isInternalScrollBarUpdate{ false },
_autoScrollVelocity{ 0 },
_autoScrollingPointerPoint{ std::nullopt },
Expand All @@ -61,7 +67,6 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
InitializeComponent();

_interactivity = winrt::make<implementation::ControlInteractivity>(settings, unfocusedAppearance, connection);
_core = _interactivity.Core();

// These events might all be triggered by the connection, but that
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalControl/TermControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace winrt::Microsoft::Terminal::Control::implementation
{
struct TermControl : TermControlT<TermControl>
{
TermControl(Control::ControlInteractivity content);

TermControl(IControlSettings settings,
Control::IControlAppearance unfocusedAppearance,
TerminalConnection::ITerminalConnection connection);
Expand Down
3 changes: 3 additions & 0 deletions src/cascadia/TerminalControl/TermControl.idl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

import "IMouseWheelListener.idl";
import "IControlSettings.idl";
import "ControlInteractivity.idl";
import "IDirectKeyListener.idl";
import "EventArgs.idl";
import "ICoreState.idl";
Expand All @@ -17,6 +18,8 @@ namespace Microsoft.Terminal.Control
ICoreState,
Windows.UI.Xaml.Data.INotifyPropertyChanged
{
TermControl(ControlInteractivity content);

TermControl(IControlSettings settings,
IControlAppearance unfocusedAppearance,
Microsoft.Terminal.TerminalConnection.ITerminalConnection connection);
Expand Down

1 comment on commit 1b4f1ef

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@check-spelling-bot Report

🔴 Please review

See the 📜action log for details.

Unrecognized words (4)

APeasant
connectecd
onarch
wehn

Previously acknowledged words that are now absent CLA demoable everytime Hirots inthread reingest unmark :arrow_right:
To accept ✔️ these unrecognized words as correct and remove the previously acknowledged and now absent words, run the following commands

... in a clone of the [email protected]:microsoft/terminal.git repository
on the dev/migrie/oop/3/valaquenta branch (ℹ️ how do I use this?):

curl -s -S -L 'https://raw.githubusercontent.com/check-spelling/check-spelling/v0.0.21/apply.pl' |
perl - 'https://github.com/microsoft/terminal/actions/runs/4069552779/attempts/1'
Errors (1)

See the 📜action log for details.

❌ Errors Count
❌ forbidden-pattern 1

See ❌ Event descriptions for more information.

✏️ Contributor please read this

By default the command suggestion will generate a file named based on your commit. That's generally ok as long as you add the file to your commit. Someone can reorganize it later.

⚠️ The command is written for posix shells. If it doesn't work for you, you can manually add (one word per line) / remove items to expect.txt and the excludes.txt files.

If the listed items are:

  • ... misspelled, then please correct them instead of using the command.
  • ... names, please add them to .github/actions/spelling/allow/names.txt.
  • ... APIs, you can add them to a file in .github/actions/spelling/allow/.
  • ... just things you're using, please add them to an appropriate file in .github/actions/spelling/expect/.
  • ... tokens you only need in one place and shouldn't generally be used, you can add an item in an appropriate file in .github/actions/spelling/patterns/.

See the README.md in each directory for more information.

🔬 You can test your commits without appending to a PR by creating a new branch with that extra change and pushing it to your fork. The check-spelling action will run in response to your push -- it doesn't require an open pull request. By using such a branch, you can limit the number of typos your peers see you make. 😉

If the flagged items are 🤯 false positives

If items relate to a ...

  • binary file (or some other file you wouldn't want to check at all).

    Please add a file path to the excludes.txt file matching the containing file.

    File paths are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your files.

    ^ refers to the file's path from the root of the repository, so ^README\.md$ would exclude README.md (on whichever branch you're using).

  • well-formed pattern.

    If you can write a pattern that would match it,
    try adding it to the patterns.txt file.

    Patterns are Perl 5 Regular Expressions - you can test yours before committing to verify it will match your lines.

    Note that patterns can't match multiline strings.

Please sign in to comment.