terminal/src/cascadia/TerminalApp/App.h
Dustin Howett c910045187 Merged PR 3315789: Migrate GitHub changes up until cfc72cee
* cfc72cee (origin/dev/duhowett/ibxint, github/master) Make sure cursor blinks after opening new tab (1030)
* 9ad25440 Fix #936: misuse of uninitialized objects causes AppVerifier breaks on Windows Terminal startup (1015)
* 5f938a04 Update Terminal.cpp (1034)
* 4c47631b Cleanup - termDispatch.hpp & adaptDispatch.hpp overrides (1004)
* cc304759 add audit mode to ci (948)
* 80f10796 Fix the bell sound when Alt+key is pressed. (1006)
* 42e87ed3 fix build break from using `await` instead of `co_await` (1009)
* 40b557a4 Update manifest to correct 1903 version, unref param fix (1008)
* 0f62ec81 Eat all tap keypresses no matter what. (985)
* ce0eaab9 inbox: Merge accumulated build fixes from RS_ONECORE_DEP_ACIOSS (1002)
* 1c509683 add .editorconfig file (585)
* efd69990 Add support for OSC 10 and 11 to set the default colors (891)

Related work items: #21610659, #21838182
2019-05-28 22:51:48 +00:00

131 lines
5.2 KiB
C++

// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
#pragma once
#include "Tab.h"
#include "CascadiaSettings.h"
#include "App.g.h"
#include "../../cascadia/inc/cppwinrt_utils.h"
#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include <winrt/Microsoft.UI.Xaml.Controls.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
namespace winrt::TerminalApp::implementation
{
// We dont use AppT as it does not provide access to protected constructors
template <typename D, typename... I>
using AppT_Override = App_base<D, I...>;
struct App : AppT_Override<App>
{
public:
App();
Windows::UI::Xaml::UIElement GetRoot() noexcept;
Windows::UI::Xaml::UIElement GetTabs() noexcept;
void Create();
void LoadSettings();
Windows::Foundation::Point GetLaunchDimensions(uint32_t dpi);
bool GetShowTabsInTitlebar();
~App();
hstring GetTitle();
// -------------------------------- WinRT Events ---------------------------------
DECLARE_EVENT(TitleChanged, _titleChangeHandlers, winrt::Microsoft::Terminal::TerminalControl::TitleChangedEventArgs);
DECLARE_EVENT(LastTabClosed, _lastTabClosedHandlers, winrt::TerminalApp::LastTabClosedEventArgs);
private:
App(Windows::UI::Xaml::Markup::IXamlMetadataProvider const& parentProvider);
// If you add controls here, but forget to null them either here or in
// the ctor, you're going to have a bad time. It'll mysteriously fail to
// activate the app.
// ALSO: If you add any UIElements as roots here, make sure they're
// updated in _ApplyTheme. The two roots currently are _root and _tabRow
// (which is a root when the tabs are in the titlebar.)
Windows::UI::Xaml::Controls::Grid _root{ nullptr };
Microsoft::UI::Xaml::Controls::TabView _tabView{ nullptr };
Windows::UI::Xaml::Controls::Grid _tabRow{ nullptr };
Windows::UI::Xaml::Controls::Grid _tabContent{ nullptr };
Windows::UI::Xaml::Controls::SplitButton _newTabButton{ nullptr };
std::vector<std::shared_ptr<Tab>> _tabs;
std::unique_ptr<::TerminalApp::CascadiaSettings> _settings;
std::unique_ptr<TerminalApp::AppKeyBindings> _keyBindings;
HRESULT _settingsLoadedResult;
bool _loadedInitialSettings;
std::shared_mutex _dialogLock;
wil::unique_folder_change_reader_nothrow _reader;
void _Create();
void _CreateNewTabFlyout();
fire_and_forget _ShowOkDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey);
[[nodiscard]]
HRESULT _TryLoadSettings(const bool saveOnLoad) noexcept;
void _LoadSettings();
void _OpenSettings();
void _HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept;
void _RegisterSettingsChange();
void _ReloadSettings();
void _SettingsButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _FeedbackButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _UpdateTabView();
void _CreateNewTabFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings);
void _OpenNewTab(std::optional<int> profileIndex);
void _CloseFocusedTab();
void _SelectNextTab(const bool bMoveRight);
void _SelectTab(const int tabIndex);
void _SetFocusedTabIndex(int tabIndex);
int _GetFocusedTabIndex() const;
void _Scroll(int delta);
void _CopyText(const bool trimTrailingWhitespace);
// Todo: add more event implementations here
// MSFT:20641986: Add keybindings for New Window
void _ScrollPage(int delta);
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _OnTabSelectionChanged(const IInspectable& sender, const Windows::UI::Xaml::Controls::SelectionChangedEventArgs& eventArgs);
void _OnTabClosing(const IInspectable& sender, const Microsoft::UI::Xaml::Controls::TabViewTabClosingEventArgs& eventArgs);
void _OnTabItemsChanged(const IInspectable& sender, const Windows::Foundation::Collections::IVectorChangedEventArgs& eventArgs);
void _OnTabClick(const IInspectable& sender, const Windows::UI::Xaml::Input::PointerRoutedEventArgs& eventArgs);
void _RemoveTabViewItem(const IInspectable& tabViewItem);
void _ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme);
static Windows::UI::Xaml::Controls::IconElement _GetIconFromProfile(const ::TerminalApp::Profile& profile);
static void _SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord);
};
}
namespace winrt::TerminalApp::factory_implementation
{
struct App : AppT<App, implementation::App>
{
};
}