-
Notifications
You must be signed in to change notification settings - Fork 8.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor the SettingsTab to be a pane (#16172)
... technically. We still won't let it actually _be_ a pane, but now it acts like one. It's hosted in a `SettingsPaneContent`. There's no more `SettingsTab`. It totally _can_ be in a pane (but don't?) ## Validation Steps Performed * Still opens the settings * Only opens a single settings tab, or re-activates the existing one * Session restores! * Updates the title of the tab appropriately * I previously _did_ use the scratchpad action to open the settings in a pane, and that worked. ## Related PRs * #16170 * #16171 * #16172 <-- you are here * #16895 Refs #997 Closes #8452
- Loading branch information
1 parent
2bcbe6b
commit 67ae9f6
Showing
25 changed files
with
440 additions
and
363 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
#include "SettingsPaneContent.h" | ||
#include "Utils.h" | ||
|
||
using namespace winrt::Windows::Foundation; | ||
using namespace winrt::Windows::UI::Xaml; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
|
||
#define ASSERT_UI_THREAD() assert(_sui.Dispatcher().HasThreadAccess()) | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
SettingsPaneContent::SettingsPaneContent(CascadiaSettings settings) | ||
{ | ||
_sui = winrt::Microsoft::Terminal::Settings::Editor::MainPage{ settings }; | ||
|
||
// Stash away the current requested theme of the app. We'll need that in | ||
// _BackgroundBrush() to do a theme-aware resource lookup | ||
_requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme(); | ||
} | ||
|
||
void SettingsPaneContent::UpdateSettings(const CascadiaSettings& settings) | ||
{ | ||
ASSERT_UI_THREAD(); | ||
_sui.UpdateSettings(settings); | ||
|
||
_requestedTheme = settings.GlobalSettings().CurrentTheme().RequestedTheme(); | ||
} | ||
|
||
winrt::Windows::UI::Xaml::FrameworkElement SettingsPaneContent::GetRoot() | ||
{ | ||
return _sui; | ||
} | ||
winrt::Windows::Foundation::Size SettingsPaneContent::MinimumSize() | ||
{ | ||
return { 1, 1 }; | ||
} | ||
void SettingsPaneContent::Focus(winrt::Windows::UI::Xaml::FocusState reason) | ||
{ | ||
if (reason != FocusState::Unfocused) | ||
{ | ||
_sui.as<Controls::Page>().Focus(reason); | ||
} | ||
} | ||
void SettingsPaneContent::Close() | ||
{ | ||
CloseRequested.raise(*this, nullptr); | ||
} | ||
|
||
NewTerminalArgs SettingsPaneContent::GetNewTerminalArgs(const BuildStartupKind /*kind*/) const | ||
{ | ||
// For now, we're doing a terrible thing in TerminalTab itself to | ||
// generate an OpenSettings action manually, without asking for the pane | ||
// structure. | ||
return nullptr; | ||
} | ||
|
||
winrt::hstring SettingsPaneContent::Icon() const | ||
{ | ||
// This is the Setting icon (looks like a gear) | ||
static constexpr std::wstring_view glyph{ L"\xE713" }; | ||
return winrt::hstring{ glyph }; | ||
} | ||
|
||
Windows::Foundation::IReference<winrt::Windows::UI::Color> SettingsPaneContent::TabColor() const noexcept | ||
{ | ||
return nullptr; | ||
} | ||
|
||
winrt::Windows::UI::Xaml::Media::Brush SettingsPaneContent::BackgroundBrush() | ||
{ | ||
// Look up the color we should use for the settings tab item from our | ||
// resources. This should only be used for when "terminalBackground" is | ||
// requested. | ||
static const auto key = winrt::box_value(L"SettingsUiTabBrush"); | ||
// You can't just do a Application::Current().Resources().TryLookup | ||
// lookup, cause the app theme never changes! Do the hacky version | ||
// instead. | ||
return ThemeLookup(Application::Current().Resources(), _requestedTheme, key).try_as<winrt::Windows::UI::Xaml::Media::Brush>(); | ||
} | ||
} |
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,46 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#pragma once | ||
#include "winrt/TerminalApp.h" | ||
#include <LibraryResources.h> | ||
|
||
namespace winrt::TerminalApp::implementation | ||
{ | ||
class SettingsPaneContent : public winrt::implements<SettingsPaneContent, IPaneContent> | ||
{ | ||
public: | ||
SettingsPaneContent(winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings settings); | ||
|
||
void UpdateSettings(const winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings& settings); | ||
|
||
winrt::Windows::UI::Xaml::FrameworkElement GetRoot(); | ||
winrt::Microsoft::Terminal::Settings::Editor::MainPage SettingsUI() { return _sui; } | ||
|
||
winrt::Windows::Foundation::Size MinimumSize(); | ||
void Focus(winrt::Windows::UI::Xaml::FocusState reason = winrt::Windows::UI::Xaml::FocusState::Programmatic); | ||
void Close(); | ||
winrt::Microsoft::Terminal::Settings::Model::NewTerminalArgs GetNewTerminalArgs(const BuildStartupKind kind) const; | ||
|
||
winrt::hstring Title() { return RS_(L"SettingsTab"); } | ||
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; | ||
winrt::Windows::UI::Xaml::Media::Brush BackgroundBrush(); | ||
|
||
til::typed_event<> ConnectionStateChanged; | ||
til::typed_event<IPaneContent> CloseRequested; | ||
til::typed_event<IPaneContent, winrt::TerminalApp::BellEventArgs> BellRequested; | ||
til::typed_event<IPaneContent> TitleChanged; | ||
til::typed_event<IPaneContent> TabColorChanged; | ||
til::typed_event<IPaneContent> TaskbarProgressChanged; | ||
til::typed_event<IPaneContent> ReadOnlyChanged; | ||
til::typed_event<IPaneContent> FocusRequested; | ||
|
||
private: | ||
winrt::Microsoft::Terminal::Settings::Editor::MainPage _sui{ nullptr }; | ||
winrt::Windows::UI::Xaml::ElementTheme _requestedTheme; | ||
}; | ||
} |
Oops, something went wrong.