8564b269c4
A redo of #6290. That PR was overkill. In that one, we'd toss focus back to the active control any time that the tab view item got focus. That's maybe not the _best_ solution. Instead, this PR is precision strikes. We're re-using a lot of what we already have from #9260. * When the context menu is closed, yeet focus to the control. * When the renamer is dismissed, yeet focus to the control. * When the TabViewItem is tapped (meaning no one else handled it), yeet focus to the control. ### checklist * [x] I work here * [ ] This is UI so it doesn't have tests * [x] Closes #3609 * [x] Closes #5750 * [x] Closes #6680 ### scenarios: * [x] focus the window by clicking on the tab -> Control is focused. * [x] Open the color picker with the context menu, can move the focus inside the picker with the arrow keys. * [x] Dismiss the picker with esc -> Control is focused. * [x] Dismiss the picker with enter -> Control is focused. * [x] Dismiss the renamer with esc -> Control is focused. * [x] Dismiss the renamer with enter -> Control is focused. * [x] Dismiss the context menu with esc -> Control is focused. * [x] Start renaming, then click on the tab -> Rename is committed, Control is focused. * [x] Start renaming, then click on the text box -> focus is still in the text box
69 lines
2.9 KiB
C++
69 lines
2.9 KiB
C++
// Copyright (c) Microsoft Corporation.
|
|
// Licensed under the MIT license.
|
|
|
|
#pragma once
|
|
#include "inc/cppwinrt_utils.h"
|
|
#include "TabBase.g.h"
|
|
|
|
// fwdecl unittest classes
|
|
namespace TerminalAppLocalTests
|
|
{
|
|
class TabTests;
|
|
};
|
|
|
|
namespace winrt::TerminalApp::implementation
|
|
{
|
|
struct TabBase : TabBaseT<TabBase>
|
|
{
|
|
public:
|
|
virtual void Focus(winrt::Windows::UI::Xaml::FocusState focusState) = 0;
|
|
winrt::Windows::UI::Xaml::FocusState FocusState() const noexcept;
|
|
|
|
virtual void Shutdown();
|
|
void SetDispatch(const winrt::TerminalApp::ShortcutActionDispatch& dispatch);
|
|
|
|
void UpdateTabViewIndex(const uint32_t idx, const uint32_t numTabs);
|
|
void SetActionMap(const Microsoft::Terminal::Settings::Model::IActionMapView& actionMap);
|
|
|
|
WINRT_CALLBACK(RequestFocusActiveControl, winrt::delegate<void()>);
|
|
|
|
WINRT_CALLBACK(Closed, winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>);
|
|
WINRT_CALLBACK(CloseRequested, winrt::Windows::Foundation::EventHandler<winrt::Windows::Foundation::IInspectable>);
|
|
WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler);
|
|
|
|
// The TabViewIndex is the index this Tab object resides in TerminalPage's _tabs vector.
|
|
WINRT_PROPERTY(uint32_t, TabViewIndex, 0);
|
|
// The TabViewNumTabs is the number of Tab objects in TerminalPage's _tabs vector.
|
|
WINRT_PROPERTY(uint32_t, TabViewNumTabs, 0);
|
|
|
|
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers);
|
|
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Icon, _PropertyChangedHandlers);
|
|
WINRT_OBSERVABLE_PROPERTY(bool, ReadOnly, _PropertyChangedHandlers, false);
|
|
WINRT_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewItem, TabViewItem, nullptr);
|
|
|
|
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Xaml::FrameworkElement, Content, _PropertyChangedHandlers, nullptr);
|
|
|
|
protected:
|
|
winrt::Windows::UI::Xaml::FocusState _focusState{ winrt::Windows::UI::Xaml::FocusState::Unfocused };
|
|
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _closeOtherTabsMenuItem{};
|
|
winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _closeTabsAfterMenuItem{};
|
|
winrt::TerminalApp::ShortcutActionDispatch _dispatch;
|
|
Microsoft::Terminal::Settings::Model::IActionMapView _actionMap{ nullptr };
|
|
winrt::hstring _keyChord{};
|
|
|
|
virtual void _CreateContextMenu();
|
|
virtual winrt::hstring _CreateToolTipTitle();
|
|
|
|
virtual void _MakeTabViewItem();
|
|
|
|
void _AppendCloseMenuItems(winrt::Windows::UI::Xaml::Controls::MenuFlyout flyout);
|
|
void _EnableCloseMenuItems();
|
|
void _CloseTabsAfter();
|
|
void _CloseOtherTabs();
|
|
winrt::fire_and_forget _UpdateSwitchToTabKeyChord();
|
|
void _UpdateToolTip();
|
|
|
|
friend class ::TerminalAppLocalTests::TabTests;
|
|
};
|
|
}
|