2608e94822
Introduces a new TerminalSettingsModel (TSM) project. This project is responsible for (de)serializing and exposing Windows Terminal's settings as WinRT objects. ## References #885: TSM epic #1564: Settings UI is dependent on this for data binding and settings access #6904: TSM Spec In the process of ripping out TSM from TerminalApp, a few other changes were made to make this possible: 1. AppLogic's `ApplicationDisplayName` and `ApplicationVersion` was moved to `CascadiaSettings` - These are defined as static functions. They also no longer check if `AppLogic::Current()` is nullptr. 2. `enum LaunchMode` was moved from TerminalApp to TSM 3. `AzureConnectionType` and `TelnetConnectionType` were moved from the profile generators to their respective TerminalConnections 4. CascadiaSettings' `SettingsPath` and `DefaultSettingsPath` are exposed as `hstring` instead of `std::filesystem::path` 5. `Command::ExpandCommands()` was exposed via the IDL - This required some of the warnings to be saved to an `IVector` instead of `std::vector`, among some other small changes. 6. The localization resources had to be split into two halves. - Resource file linked in init.cpp. Verified at runtime thanks to the StaticResourceLoader. 7. Added constructors to some `ActionArgs` 8. Utils.h/cpp were moved to `cascadia/inc`. `JsonKey()` was moved to `JsonUtils`. Both TermApp and TSM need access to Utils.h/cpp. A large amount of work includes moving to the new namespace (`TerminalApp` --> `Microsoft::Terminal::Settings::Model`). Fixing the tests had its own complications. Testing required us to split up TSM into a DLL and LIB, similar to TermApp. Discussion on creating a non-local test variant can be found in #7743. Closes #885
129 lines
5.5 KiB
C++
129 lines
5.5 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
#include "Pane.h"
|
|
#include "ColorPickupFlyout.h"
|
|
#include "Tab.g.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace TerminalAppLocalTests
|
|
{
|
|
class TabTests;
|
|
};
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
struct Tab : public TabT<Tab>
|
|
{
|
|
public:
|
|
Tab() = delete;
|
|
Tab(const GUID& profile, const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
|
|
|
|
// Called after construction to perform the necessary setup, which relies on weak_ptr
|
|
void Initialize(const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
|
|
|
|
winrt::Microsoft::UI::Xaml::Controls::TabViewItem GetTabViewItem();
|
|
winrt::Windows::UI::Xaml::UIElement GetRootElement();
|
|
winrt::Microsoft::Terminal::TerminalControl::TermControl GetActiveTerminalControl() const;
|
|
std::optional<GUID> GetFocusedProfile() const noexcept;
|
|
|
|
bool IsFocused() const noexcept;
|
|
void SetFocused(const bool focused);
|
|
|
|
winrt::fire_and_forget Scroll(const int delta);
|
|
|
|
bool CanSplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType);
|
|
void SplitPane(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType, const GUID& profile, winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
|
|
|
|
winrt::fire_and_forget UpdateIcon(const winrt::hstring iconPath);
|
|
|
|
float CalcSnappedDimension(const bool widthOrHeight, const float dimension) const;
|
|
winrt::Microsoft::Terminal::Settings::Model::SplitState PreCalculateAutoSplit(winrt::Windows::Foundation::Size rootSize) const;
|
|
bool PreCalculateCanSplit(winrt::Microsoft::Terminal::Settings::Model::SplitState splitType, winrt::Windows::Foundation::Size availableSpace) const;
|
|
|
|
void ResizeContent(const winrt::Windows::Foundation::Size& newSize);
|
|
void ResizePane(const winrt::Microsoft::Terminal::Settings::Model::Direction& direction);
|
|
void NavigateFocus(const winrt::Microsoft::Terminal::Settings::Model::Direction& direction);
|
|
|
|
void UpdateSettings(const winrt::TerminalApp::TerminalSettings& settings, const GUID& profile);
|
|
winrt::hstring GetActiveTitle() const;
|
|
|
|
void Shutdown();
|
|
void ClosePane();
|
|
|
|
void SetTabText(winrt::hstring title);
|
|
void ResetTabText();
|
|
|
|
std::optional<winrt::Windows::UI::Color> GetTabColor();
|
|
|
|
void SetRuntimeTabColor(const winrt::Windows::UI::Color& color);
|
|
void ResetRuntimeTabColor();
|
|
void ActivateColorPicker();
|
|
|
|
void ToggleZoom();
|
|
bool IsZoomed();
|
|
void EnterZoom();
|
|
void ExitZoom();
|
|
|
|
int GetLeafPaneCount() const noexcept;
|
|
|
|
void UpdateTabViewIndex(const uint32_t idx);
|
|
|
|
WINRT_CALLBACK(Closed, winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>);
|
|
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
|
DECLARE_EVENT(ActivePaneChanged, _ActivePaneChangedHandlers, winrt::delegate<>);
|
|
DECLARE_EVENT(ColorSelected, _colorSelected, winrt::delegate<winrt::Windows::UI::Color>);
|
|
DECLARE_EVENT(ColorCleared, _colorCleared, winrt::delegate<>);
|
|
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers);
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::Windows::UI::Xaml::Controls::IconSource, IconSource, _PropertyChangedHandlers, nullptr);
|
|
OBSERVABLE_GETSET_PROPERTY(winrt::Microsoft::Terminal::Settings::Model::Command, SwitchToTabCommand, _PropertyChangedHandlers, nullptr);
|
|
|
|
// The TabViewIndex is the index this Tab object resides in TerminalPage's _tabs vector.
|
|
// This is needed since Tab is going to be managing its own SwitchToTab command.
|
|
OBSERVABLE_GETSET_PROPERTY(uint32_t, TabViewIndex, _PropertyChangedHandlers, 0);
|
|
|
|
private:
|
|
std::shared_ptr<Pane> _rootPane{ nullptr };
|
|
std::shared_ptr<Pane> _activePane{ nullptr };
|
|
std::shared_ptr<Pane> _zoomedPane{ nullptr };
|
|
winrt::hstring _lastIconPath{};
|
|
winrt::TerminalApp::ColorPickupFlyout _tabColorPickup{};
|
|
std::optional<winrt::Windows::UI::Color> _themeTabColor{};
|
|
std::optional<winrt::Windows::UI::Color> _runtimeTabColor{};
|
|
|
|
bool _focused{ false };
|
|
winrt::Microsoft::UI::Xaml::Controls::TabViewItem _tabViewItem{ nullptr };
|
|
|
|
winrt::hstring _runtimeTabText{};
|
|
bool _inRename{ false };
|
|
winrt::Windows::UI::Xaml::Controls::TextBox::LayoutUpdated_revoker _tabRenameBoxLayoutUpdatedRevoker;
|
|
|
|
void _MakeTabViewItem();
|
|
void _Focus();
|
|
|
|
void _CreateContextMenu();
|
|
void _RefreshVisualState();
|
|
|
|
void _BindEventHandlers(const winrt::Microsoft::Terminal::TerminalControl::TermControl& control) noexcept;
|
|
|
|
void _AttachEventHandlersToControl(const winrt::Microsoft::Terminal::TerminalControl::TermControl& control);
|
|
void _AttachEventHandlersToPane(std::shared_ptr<Pane> pane);
|
|
|
|
void _UpdateActivePane(std::shared_ptr<Pane> pane);
|
|
|
|
void _UpdateTabHeader();
|
|
winrt::fire_and_forget _UpdateTitle();
|
|
void _ConstructTabRenameBox(const winrt::hstring& tabText);
|
|
|
|
void _RecalculateAndApplyTabColor();
|
|
void _ApplyTabColor(const winrt::Windows::UI::Color& color);
|
|
void _ClearTabBackgroundColor();
|
|
|
|
void _MakeSwitchToTabCommand();
|
|
|
|
friend class ::TerminalAppLocalTests::TabTests;
|
|
};
|
|
}
|