2019-05-03 00:29:04 +02:00
|
|
|
// Copyright (c) Microsoft Corporation.
|
|
|
|
// Licensed under the MIT license.
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "Tab.h"
|
|
|
|
#include "CascadiaSettings.h"
|
|
|
|
#include "App.g.h"
|
2019-06-25 22:06:11 +02:00
|
|
|
#include "App.base.h"
|
2019-05-03 00:29:04 +02:00
|
|
|
#include "../../cascadia/inc/cppwinrt_utils.h"
|
|
|
|
|
|
|
|
#include <winrt/Microsoft.Terminal.TerminalControl.h>
|
2019-06-28 19:55:46 +02:00
|
|
|
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
#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
|
|
|
|
{
|
2019-06-25 22:06:11 +02:00
|
|
|
struct App : AppT2<App>
|
2019-05-03 00:29:04 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
App();
|
|
|
|
|
|
|
|
Windows::UI::Xaml::UIElement GetRoot() noexcept;
|
2019-06-25 22:06:11 +02:00
|
|
|
|
|
|
|
// Gets the current dragglable area in the non client region of the top level window
|
|
|
|
Windows::UI::Xaml::Controls::Border GetDragBar() noexcept;
|
|
|
|
|
|
|
|
void Create(uint64_t hParentWnd);
|
2019-05-03 00:29:04 +02:00
|
|
|
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);
|
2019-05-15 14:22:16 +02:00
|
|
|
DECLARE_EVENT(LastTabClosed, _lastTabClosedHandlers, winrt::TerminalApp::LastTabClosedEventArgs);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
private:
|
|
|
|
// 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.)
|
2019-07-09 23:47:30 +02:00
|
|
|
Windows::UI::Xaml::Controls::Control _root{ nullptr };
|
2019-05-03 00:29:04 +02:00
|
|
|
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 };
|
2019-06-25 22:06:11 +02:00
|
|
|
winrt::TerminalApp::MinMaxCloseControl _minMaxCloseControl{ nullptr };
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
std::vector<std::shared_ptr<Tab>> _tabs;
|
|
|
|
|
|
|
|
std::unique_ptr<::TerminalApp::CascadiaSettings> _settings;
|
|
|
|
|
2019-05-23 22:09:35 +02:00
|
|
|
HRESULT _settingsLoadedResult;
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
bool _loadedInitialSettings;
|
2019-05-23 22:09:35 +02:00
|
|
|
std::shared_mutex _dialogLock;
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
wil::unique_folder_change_reader_nothrow _reader;
|
|
|
|
|
2019-06-19 21:51:59 +02:00
|
|
|
std::atomic<bool> _settingsReloadQueued{ false };
|
|
|
|
|
2019-06-25 22:06:11 +02:00
|
|
|
void _Create(uint64_t parentHWnd);
|
2019-05-03 00:29:04 +02:00
|
|
|
void _CreateNewTabFlyout();
|
|
|
|
|
2019-06-12 22:32:09 +02:00
|
|
|
fire_and_forget _ShowDialog(const winrt::Windows::Foundation::IInspectable& titleElement,
|
|
|
|
const winrt::Windows::Foundation::IInspectable& contentElement,
|
|
|
|
const winrt::hstring& closeButtonText);
|
|
|
|
void _ShowOkDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey);
|
|
|
|
void _ShowAboutDialog();
|
2019-05-23 22:09:35 +02:00
|
|
|
|
2019-06-11 22:27:09 +02:00
|
|
|
[[nodiscard]] HRESULT _TryLoadSettings(const bool saveOnLoad) noexcept;
|
2019-05-03 00:29:04 +02:00
|
|
|
void _LoadSettings();
|
2019-05-14 03:02:06 +02:00
|
|
|
void _OpenSettings();
|
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
void _HookupKeyBindings(TerminalApp::AppKeyBindings bindings) noexcept;
|
|
|
|
|
|
|
|
void _RegisterSettingsChange();
|
2019-06-19 21:51:59 +02:00
|
|
|
fire_and_forget _DispatchReloadSettings();
|
2019-05-03 00:29:04 +02:00
|
|
|
void _ReloadSettings();
|
|
|
|
|
|
|
|
void _SettingsButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
|
|
|
void _FeedbackButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
2019-06-12 22:32:09 +02:00
|
|
|
void _AboutButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
void _UpdateTabView();
|
2019-06-07 23:56:44 +02:00
|
|
|
void _UpdateTabIcon(std::shared_ptr<Tab> tab);
|
|
|
|
void _UpdateTitle(std::shared_ptr<Tab> tab);
|
|
|
|
|
|
|
|
void _RegisterTerminalEvents(Microsoft::Terminal::TerminalControl::TermControl term, std::shared_ptr<Tab> hostingTab);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
void _CreateNewTabFromSettings(GUID profileGuid, winrt::Microsoft::Terminal::Settings::TerminalSettings settings);
|
|
|
|
|
|
|
|
void _OpenNewTab(std::optional<int> profileIndex);
|
2019-07-02 19:45:51 +02:00
|
|
|
void _DuplicateTabViewItem();
|
2019-05-03 00:29:04 +02:00
|
|
|
void _CloseFocusedTab();
|
|
|
|
void _SelectNextTab(const bool bMoveRight);
|
2019-05-10 18:48:36 +02:00
|
|
|
void _SelectTab(const int tabIndex);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
void _SetFocusedTabIndex(int tabIndex);
|
|
|
|
int _GetFocusedTabIndex() const;
|
|
|
|
|
2019-05-15 15:21:14 +02:00
|
|
|
void _Scroll(int delta);
|
2019-05-03 00:29:04 +02:00
|
|
|
void _CopyText(const bool trimTrailingWhitespace);
|
2019-06-25 21:17:02 +02:00
|
|
|
void _PasteText();
|
2019-06-07 23:56:44 +02:00
|
|
|
void _SplitVertical(const std::optional<GUID>& profileGuid);
|
|
|
|
void _SplitHorizontal(const std::optional<GUID>& profileGuid);
|
|
|
|
void _SplitPane(const Pane::SplitState splitType, const std::optional<GUID>& profileGuid);
|
2019-06-25 21:17:02 +02:00
|
|
|
|
2019-05-03 00:29:04 +02:00
|
|
|
// Todo: add more event implementations here
|
|
|
|
// MSFT:20641986: Add keybindings for New Window
|
2019-05-15 15:21:14 +02:00
|
|
|
void _ScrollPage(int delta);
|
Enable resizing the panes with the keyboard. (#1207)
Adds the ability to resize panes with the keyboard.
This is accomplished by making the Column/RowDefinitions for a Pane use `GridLengthHelper::FromPixels` to set their size. We store a pair of floats that represents the relative amount that each pane takes out of the parent pane. When the window is resized, we use that percentage to figure out the new size of each child in pixels, and manually size each column.
Then, when the user presses the keybindings for resizePane{Left/Right/Up/Down}, we'll adjust those percentages, and resize the rows/cols as appropriate.
Currently, each pane adjusts the width/height by 5% of the total size at a time. I am not in love with this, but it works for now. I think when we get support for keybindings with arbitrary arg blobs, then we could do either a percent movement, or a number of characters at a time. The number of characters one would be trickier, because we'd have to get the focused control, and get the number of pixels per character, as adjacent panes might not have the same font sizes.
2019-07-10 15:27:12 +02:00
|
|
|
void _ResizePane(const Direction& direction);
|
2019-07-17 16:30:15 +02:00
|
|
|
void _MoveFocus(const Direction& direction);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
2019-05-23 22:09:35 +02:00
|
|
|
void _OnLoaded(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
|
2019-05-03 00:29:04 +02:00
|
|
|
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);
|
Enable resizing the panes with the keyboard. (#1207)
Adds the ability to resize panes with the keyboard.
This is accomplished by making the Column/RowDefinitions for a Pane use `GridLengthHelper::FromPixels` to set their size. We store a pair of floats that represents the relative amount that each pane takes out of the parent pane. When the window is resized, we use that percentage to figure out the new size of each child in pixels, and manually size each column.
Then, when the user presses the keybindings for resizePane{Left/Right/Up/Down}, we'll adjust those percentages, and resize the rows/cols as appropriate.
Currently, each pane adjusts the width/height by 5% of the total size at a time. I am not in love with this, but it works for now. I think when we get support for keybindings with arbitrary arg blobs, then we could do either a percent movement, or a number of characters at a time. The number of characters one would be trickier, because we'd have to get the focused control, and get the number of pixels per character, as adjacent panes might not have the same font sizes.
2019-07-10 15:27:12 +02:00
|
|
|
void _OnContentSizeChanged(const IInspectable& sender, Windows::UI::Xaml::SizeChangedEventArgs const& e);
|
2019-05-03 00:29:04 +02:00
|
|
|
|
|
|
|
void _RemoveTabViewItem(const IInspectable& tabViewItem);
|
|
|
|
|
|
|
|
void _ApplyTheme(const Windows::UI::Xaml::ElementTheme& newTheme);
|
|
|
|
|
|
|
|
static Windows::UI::Xaml::Controls::IconElement _GetIconFromProfile(const ::TerminalApp::Profile& profile);
|
2019-06-07 23:56:44 +02:00
|
|
|
|
|
|
|
winrt::Microsoft::Terminal::TerminalControl::TermControl _GetFocusedControl();
|
|
|
|
|
|
|
|
void _CopyToClipboardHandler(const winrt::hstring& copiedData);
|
|
|
|
void _PasteFromClipboardHandler(const IInspectable& sender, const Microsoft::Terminal::TerminalControl::PasteFromClipboardEventArgs& eventArgs);
|
|
|
|
|
2019-05-22 22:01:33 +02:00
|
|
|
static void _SetAcceleratorForMenuItem(Windows::UI::Xaml::Controls::MenuFlyoutItem& menuItem, const winrt::Microsoft::Terminal::Settings::KeyChord& keyChord);
|
2019-05-03 00:29:04 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace winrt::TerminalApp::factory_implementation
|
|
|
|
{
|
|
|
|
struct App : AppT<App, implementation::App>
|
|
|
|
{
|
|
|
|
};
|
|
|
|
}
|