-
Notifications
You must be signed in to change notification settings - Fork 8.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
sanely pass around a cache instead of... whatever that was.
- Loading branch information
1 parent
17075d6
commit 0a11643
Showing
14 changed files
with
196 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "TerminalSettingsCache.h" | ||
#include "TerminalSettingsCache.g.cpp" | ||
|
||
namespace winrt | ||
{ | ||
namespace MUX = Microsoft::UI::Xaml; | ||
namespace WUX = Windows::UI::Xaml; | ||
namespace MTSM = Microsoft::Terminal::Settings::Model; | ||
} | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
TerminalSettingsCache::TerminalSettingsCache(const MTSM::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings) : | ||
_settings{ settings }, | ||
_bindings{ bindings } | ||
{ | ||
// Mapping by GUID isn't _excellent_ because the defaults profile doesn't have a stable GUID; however, | ||
// when we stabilize its guid this will become fully safe. | ||
const auto profileDefaults{ _settings.ProfileDefaults() }; | ||
const auto allProfiles{ _settings.AllProfiles() }; | ||
|
||
profileGuidSettingsMap.reserve(allProfiles.Size() + 1); | ||
|
||
// Include the Defaults profile for consideration | ||
profileGuidSettingsMap.insert_or_assign(profileDefaults.Guid(), std::pair{ profileDefaults, nullptr }); | ||
for (const auto& newProfile : allProfiles) | ||
{ | ||
// Avoid creating a TerminalSettings right now. They're not totally cheap, and we suspect that users with many | ||
// panes may not be using all of their profiles at the same time. Lazy evaluation is king! | ||
profileGuidSettingsMap.insert_or_assign(newProfile.Guid(), std::pair{ newProfile, nullptr }); | ||
} | ||
} | ||
|
||
MTSM::TerminalSettingsCreateResult TerminalSettingsCache::TryLookup(const MTSM::Profile& profile) | ||
{ | ||
const auto found{ profileGuidSettingsMap.find(profile.Guid()) }; | ||
// GH#2455: If there are any panes with controls that had been | ||
// initialized with a Profile that no longer exists in our list of | ||
// profiles, we'll leave it unmodified. The profile doesn't exist | ||
// anymore, so we can't possibly update its settings. | ||
if (found != profileGuidSettingsMap.cend()) | ||
{ | ||
auto& pair{ found->second }; | ||
if (!pair.second) | ||
{ | ||
pair.second = MTSM::TerminalSettings::CreateWithProfile(_settings, pair.first, _bindings); | ||
} | ||
return pair.second; | ||
} | ||
|
||
return nullptr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/*++ | ||
Copyright (c) Microsoft Corporation | ||
Licensed under the MIT license. | ||
Class Name: | ||
- ContentManager.h | ||
Abstract: | ||
- This is a helper class for tracking all of the terminal "content" instances of | ||
the Terminal. These are all the ControlInteractivity & ControlCore's of each | ||
of our TermControls. These are each assigned a GUID on creation, and stored in | ||
a map for later lookup. | ||
- This is used to enable moving panes between windows. TermControl's are not | ||
thread-agile, so they cannot be reused on other threads. However, the content | ||
is. This helper, which exists as a singleton across all the threads in the | ||
Terminal app, allows each thread to create content, assign it to a | ||
TermControl, detach it from that control, and reattach to new controls on | ||
other threads. | ||
- When you want to create a new TermControl, call CreateCore to instantiate a | ||
new content with a GUID for later reparenting. | ||
- Detach can be used to temporarily remove a content from its hosted | ||
TermControl. After detaching, you can still use LookupCore & | ||
TermControl::AttachContent to re-attach to the content. | ||
--*/ | ||
#pragma once | ||
|
||
#include "TerminalSettingsCache.g.h" | ||
#include <inc/cppwinrt_utils.h> | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
class TerminalSettingsCache : public TerminalSettingsCacheT<TerminalSettingsCache> | ||
{ | ||
public: | ||
TerminalSettingsCache(const Microsoft::Terminal::Settings::Model::CascadiaSettings& settings, const TerminalApp::AppKeyBindings& bindings); | ||
Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult TryLookup(const Microsoft::Terminal::Settings::Model::Profile& profile); | ||
|
||
private: | ||
Microsoft::Terminal::Settings::Model::CascadiaSettings _settings{ nullptr }; | ||
TerminalApp::AppKeyBindings _bindings{ nullptr }; | ||
std::unordered_map<winrt::guid, std::pair<Microsoft::Terminal::Settings::Model::Profile, Microsoft::Terminal::Settings::Model::TerminalSettingsCreateResult>> profileGuidSettingsMap; | ||
}; | ||
} | ||
|
||
namespace winrt::TerminalApp::factory_implementation | ||
{ | ||
BASIC_FACTORY(TerminalSettingsCache); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import "AppKeyBindings.idl"; | ||
|
||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
namespace TerminalApp | ||
{ | ||
[default_interface] runtimeclass TerminalSettingsCache | ||
{ | ||
TerminalSettingsCache(Microsoft.Terminal.Settings.Model.CascadiaSettings settings, AppKeyBindings bindings); | ||
Microsoft.Terminal.Settings.Model.TerminalSettingsCreateResult TryLookup(Microsoft.Terminal.Settings.Model.Profile profile); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters