From 3b1a5e9418c7c3d90100c95743b30660081474d1 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 11 Nov 2020 12:10:51 -0500 Subject: [PATCH 01/10] initial --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 28 ++++++++++++++++++ src/cascadia/TerminalApp/TabHeaderControl.h | 25 ++++++++++++++++ src/cascadia/TerminalApp/TabHeaderControl.idl | 12 ++++++++ .../TerminalApp/TabHeaderControl.xaml | 29 +++++++++++++++++++ .../TerminalApp/TerminalAppLib.vcxproj | 13 +++++++++ .../TerminalAppLib.vcxproj.filters | 3 ++ src/cascadia/TerminalApp/TerminalTab.cpp | 18 +++--------- src/cascadia/TerminalApp/TerminalTab.h | 1 + 8 files changed, 115 insertions(+), 14 deletions(-) create mode 100644 src/cascadia/TerminalApp/TabHeaderControl.cpp create mode 100644 src/cascadia/TerminalApp/TabHeaderControl.h create mode 100644 src/cascadia/TerminalApp/TabHeaderControl.idl create mode 100644 src/cascadia/TerminalApp/TabHeaderControl.xaml diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp new file mode 100644 index 00000000000..090fff877df --- /dev/null +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -0,0 +1,28 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#include "pch.h" +#include "TabHeaderControl.h" + +#include "TabHeaderControl.g.cpp" + +using namespace winrt; +using namespace winrt::Microsoft::UI::Xaml; + +namespace winrt::TerminalApp::implementation +{ + TabHeaderControl::TabHeaderControl() + { + InitializeComponent(); + } + + void TabHeaderControl::UpdateHeaderText(winrt::hstring title) + { + HeaderTextBlock().Text(title); + } + + void TabHeaderControl::SetZoomIcon(Windows::UI::Xaml::Visibility state) + { + HeaderZoomIcon().Visibility(state); + } +} diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h new file mode 100644 index 00000000000..39494010211 --- /dev/null +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -0,0 +1,25 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +#pragma once + +#include "winrt/Microsoft.UI.Xaml.Controls.h" + +#include "TabHeaderControl.g.h" + +namespace winrt::TerminalApp::implementation +{ + struct TabHeaderControl : TabHeaderControlT + { + TabHeaderControl(); + void UpdateHeaderText(winrt::hstring title); + void SetZoomIcon(Windows::UI::Xaml::Visibility state); + }; +} + +namespace winrt::TerminalApp::factory_implementation +{ + struct TabHeaderControl : TabHeaderControlT + { + }; +} diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl new file mode 100644 index 00000000000..a516feb2e40 --- /dev/null +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -0,0 +1,12 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT license. + +namespace TerminalApp +{ + [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl + { + TabHeaderControl(); + void UpdateHeaderText(String title); + void SetZoomIcon(Windows.UI.Xaml.Visibility state); + } +} diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml new file mode 100644 index 00000000000..ab7ce0c1b61 --- /dev/null +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -0,0 +1,29 @@ + + + + + + + + + diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj index f653d7d4264..bffa63b7acf 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj @@ -53,6 +53,9 @@ Designer + + + Designer Designer @@ -89,6 +92,9 @@ TabRowControl.xaml + + TabHeaderControl.xaml + HighlightedTextControl.xaml @@ -154,6 +160,9 @@ TabRowControl.xaml + + TabHeaderControl.xaml + HighlightedTextControl.xaml @@ -230,6 +239,10 @@ TabRowControl.xaml Code + + TabHeaderControl.xaml + Code + HighlightedTextControl.xaml Code diff --git a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters index 8f89e58292f..3d424c3996f 100644 --- a/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters +++ b/src/cascadia/TerminalApp/TerminalAppLib.vcxproj.filters @@ -106,6 +106,9 @@ controls + + controls + controls diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 567d48a7ba1..d15bf04972a 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -37,6 +37,7 @@ namespace winrt::TerminalApp::implementation _MakeTabViewItem(); _CreateContextMenu(); + TabViewItem().Header(_headerControl); } // Method Description: @@ -589,26 +590,15 @@ namespace winrt::TerminalApp::implementation { if (_zoomedPane) { - Controls::StackPanel sp; - sp.Orientation(Controls::Orientation::Horizontal); - Controls::FontIcon ico; - ico.FontFamily(Media::FontFamily{ L"Segoe MDL2 Assets" }); - ico.Glyph(L"\xE8A3"); // "ZoomIn", a magnifying glass with a '+' in it. - ico.FontSize(12); - ico.Margin(ThicknessHelper::FromLengths(0, 0, 8, 0)); - sp.Children().Append(ico); - Controls::TextBlock tb; - tb.Text(tabText); - sp.Children().Append(tb); - - TabViewItem().Header(sp); + _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Visible); } else { // If we're not currently in the process of renaming the tab, // then just set the tab's text to whatever our active title is. - TabViewItem().Header(winrt::box_value(tabText)); + _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Collapsed); } + _headerControl.UpdateHeaderText(tabText); } else { diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index 7144a961fa4..fc8ad5f6590 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -80,6 +80,7 @@ namespace winrt::TerminalApp::implementation std::optional _runtimeTabColor{}; winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _closeOtherTabsMenuItem{}; winrt::Windows::UI::Xaml::Controls::MenuFlyoutItem _closeTabsAfterMenuItem{}; + winrt::TerminalApp::TabHeaderControl _headerControl{}; bool _receivedKeyDown{ false }; From 40c692046f73010fe403e25a05e8c9229925b2bf Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 11 Nov 2020 15:42:01 -0500 Subject: [PATCH 02/10] rename box --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 48 ++++++ src/cascadia/TerminalApp/TabHeaderControl.h | 8 + src/cascadia/TerminalApp/TabHeaderControl.idl | 1 + .../TerminalApp/TabHeaderControl.xaml | 3 +- src/cascadia/TerminalApp/TerminalTab.cpp | 157 +----------------- src/cascadia/TerminalApp/TerminalTab.h | 2 - 6 files changed, 63 insertions(+), 156 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 090fff877df..8dfe3a6f0a5 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -14,6 +14,28 @@ namespace winrt::TerminalApp::implementation TabHeaderControl::TabHeaderControl() { InitializeComponent(); + + HeaderRenamerTextBox().KeyDown([&](auto&&, auto&&) { + _receivedKeyDown = true; + }); + + HeaderRenamerTextBox().KeyUp([&](auto&&, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { + if (_receivedKeyDown) + { + if (e.OriginalKey() == Windows::System::VirtualKey::Enter) + { + // close the rename box + _CloseRenameBox(); + } + else if (e.OriginalKey() == Windows::System::VirtualKey::Escape) + { + // the user wants to discard the changes they made, + // reset the rename box text to the old text and close the rename box + HeaderRenamerTextBox().Text(HeaderTextBlock().Text()); + _CloseRenameBox(); + } + } + }); } void TabHeaderControl::UpdateHeaderText(winrt::hstring title) @@ -25,4 +47,30 @@ namespace winrt::TerminalApp::implementation { HeaderZoomIcon().Visibility(state); } + + void TabHeaderControl::ConstructTabRenameBox() + { + _receivedKeyDown = false; + + HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Collapsed); + HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Visible); + + HeaderRenamerTextBox().Text(HeaderTextBlock().Text()); + HeaderRenamerTextBox().SelectAll(); + HeaderRenamerTextBox().Focus(Windows::UI::Xaml::FocusState::Programmatic); + } + + void TabHeaderControl::RenameBoxLostFocusHandler(Windows::Foundation::IInspectable const& /*sender*/, + Windows::UI::Xaml::RoutedEventArgs const& /*e*/) + { + _CloseRenameBox(); + } + + void TabHeaderControl::_CloseRenameBox() + { + HeaderTextBlock().Text(HeaderRenamerTextBox().Text()); + + HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); + HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); + } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 39494010211..7ca487a86db 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -14,6 +14,14 @@ namespace winrt::TerminalApp::implementation TabHeaderControl(); void UpdateHeaderText(winrt::hstring title); void SetZoomIcon(Windows::UI::Xaml::Visibility state); + void ConstructTabRenameBox(); + + void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender, + winrt::Windows::UI::Xaml::RoutedEventArgs const& e); + + private: + void _CloseRenameBox(); + bool _receivedKeyDown{ false }; }; } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index a516feb2e40..598abb18835 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -8,5 +8,6 @@ namespace TerminalApp TabHeaderControl(); void UpdateHeaderText(String title); void SetZoomIcon(Windows.UI.Xaml.Visibility state); + void ConstructTabRenameBox(); } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index ab7ce0c1b61..574e1502a8b 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -24,6 +24,7 @@ the MIT License. See LICENSE in the project root for license information. --> Visibility="Collapsed" MinHeight="0" Padding="4,0,4,0" - Margin="0,-8,0,-8"/> + Margin="0,-8,0,-8" + LostFocus="RenameBoxLostFocusHandler"/> diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index d15bf04972a..f9b8363953d 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -218,7 +218,7 @@ namespace winrt::TerminalApp::implementation SwitchToTabCommand().Name(Title()); // Update the UI to reflect the changed - _UpdateTabHeader(); + _headerControl.UpdateHeaderText(Title()); } } @@ -368,9 +368,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalTab::ActivateTabRenamer() { - _inRename = true; - _receivedKeyDown = false; - _UpdateTabHeader(); + _headerControl.ConstructTabRenameBox(); } // Method Description: @@ -570,153 +568,6 @@ namespace winrt::TerminalApp::implementation TabViewItem().ContextFlyout(newTabFlyout); } - // Method Description: - // - This will update the contents of our TabViewItem for our current state. - // - If we're not in a rename, we'll set the Header of the TabViewItem to - // simply our current tab text (either the runtime tab text or the - // active terminal's text). - // - If we're in a rename, then we'll set the Header to a TextBox with the - // current tab text. The user can then use that TextBox to set a string - // to use as an override for the tab's text. - // Arguments: - // - - // Return Value: - // - - void TerminalTab::_UpdateTabHeader() - { - winrt::hstring tabText{ Title() }; - - if (!_inRename) - { - if (_zoomedPane) - { - _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Visible); - } - else - { - // If we're not currently in the process of renaming the tab, - // then just set the tab's text to whatever our active title is. - _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Collapsed); - } - _headerControl.UpdateHeaderText(tabText); - } - else - { - _ConstructTabRenameBox(tabText); - } - } - - // Method Description: - // - Create a new TextBox to use as the control for renaming the tab text. - // If the text box is already created, then this will do nothing, and - // leave the current box unmodified. - // Arguments: - // - tabText: This should be the text to initialize the rename text box with. - // Return Value: - // - - void TerminalTab::_ConstructTabRenameBox(const winrt::hstring& tabText) - { - if (TabViewItem().Header().try_as()) - { - return; - } - - Controls::TextBox tabTextBox; - tabTextBox.Text(tabText); - - // The TextBox has a MinHeight already set by default, which is - // larger than we want. Get rid of it. - tabTextBox.MinHeight(0); - // Also get rid of the internal padding on the text box, between the - // border and the text content, on the top and bottom. This will - // help the box fit within the bounds of the tab. - Thickness internalPadding = ThicknessHelper::FromLengths(4, 0, 4, 0); - tabTextBox.Padding(internalPadding); - - // Make the margin (0, -8, 0, -8), to counteract the padding that - // the TabViewItem has. - // - // This is maybe a bit fragile, as the actual value might not be exactly - // (0, 8, 0, 8), but using TabViewItemHeaderPadding to look up the real - // value at runtime didn't work. So this is good enough for now. - Thickness negativeMargins = ThicknessHelper::FromLengths(0, -8, 0, -8); - tabTextBox.Margin(negativeMargins); - - // Set up some event handlers on the text box. We need three of them: - // * A LostFocus event, so when the TextBox loses focus, we'll - // remove it and return to just the text on the tab. - // * A KeyUp event, to be able to submit the tab text on Enter or - // dismiss the text box on Escape - // * A LayoutUpdated event, so that we can auto-focus the text box - // when it's added to the tree. - auto weakThis{ get_weak() }; - - // When the text box loses focus, update the tab title of our tab. - // - If there are any contents in the box, we'll use that value as - // the new "runtime text", which will override any text set by the - // application. - // - If the text box is empty, we'll reset the "runtime text", and - // return to using the active terminal's title. - tabTextBox.LostFocus([weakThis](const IInspectable& sender, auto&&) { - auto tab{ weakThis.get() }; - auto textBox{ sender.try_as() }; - if (tab && textBox) - { - tab->_runtimeTabText = textBox.Text(); - tab->_inRename = false; - tab->UpdateTitle(); - } - }); - - // We'll only process the KeyUp event if we received an initial KeyDown event first. - // Avoids issue immediately closing the tab rename when we see the enter KeyUp event that was - // sent to the command palette to trigger the openTabRenamer action in the first place. - tabTextBox.KeyDown([weakThis](const IInspectable&, Input::KeyRoutedEventArgs const&) { - auto tab{ weakThis.get() }; - tab->_receivedKeyDown = true; - }); - - // NOTE: (Preview)KeyDown does not work here. If you use that, we'll - // remove the TextBox from the UI tree, then the following KeyUp - // will bubble to the NewTabButton, which we don't want to have - // happen. - tabTextBox.KeyUp([weakThis](const IInspectable& sender, Input::KeyRoutedEventArgs const& e) { - auto tab{ weakThis.get() }; - auto textBox{ sender.try_as() }; - if (tab && textBox && tab->_receivedKeyDown) - { - switch (e.OriginalKey()) - { - case VirtualKey::Enter: - tab->_runtimeTabText = textBox.Text(); - [[fallthrough]]; - case VirtualKey::Escape: - e.Handled(true); - textBox.Text(tab->_runtimeTabText); - tab->_inRename = false; - tab->UpdateTitle(); - break; - } - } - }); - - // As soon as the text box is added to the UI tree, focus it. We can't focus it till it's in the tree. - _tabRenameBoxLayoutUpdatedRevoker = tabTextBox.LayoutUpdated(winrt::auto_revoke, [this](auto&&, auto&&) { - // Curiously, the sender for this event is null, so we have to - // get the TextBox from the Tab's Header(). - auto textBox{ TabViewItem().Header().try_as() }; - if (textBox) - { - textBox.SelectAll(); - textBox.Focus(FocusState::Programmatic); - } - // Only let this succeed once. - _tabRenameBoxLayoutUpdatedRevoker.revoke(); - }); - - TabViewItem().Header(tabTextBox); - } - // Method Description: // Returns the tab color, if any // Arguments: @@ -989,7 +840,7 @@ namespace winrt::TerminalApp::implementation _zoomedPane = _activePane; _rootPane->Maximize(_zoomedPane); // Update the tab header to show the magnifying glass - _UpdateTabHeader(); + _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Visible); Content(_zoomedPane->GetRootElement()); } void TerminalTab::ExitZoom() @@ -997,7 +848,7 @@ namespace winrt::TerminalApp::implementation _rootPane->Restore(_zoomedPane); _zoomedPane = nullptr; // Update the tab header to hide the magnifying glass - _UpdateTabHeader(); + _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Collapsed); Content(_rootPane->GetRootElement()); } diff --git a/src/cascadia/TerminalApp/TerminalTab.h b/src/cascadia/TerminalApp/TerminalTab.h index fc8ad5f6590..ae176d44663 100644 --- a/src/cascadia/TerminalApp/TerminalTab.h +++ b/src/cascadia/TerminalApp/TerminalTab.h @@ -104,8 +104,6 @@ namespace winrt::TerminalApp::implementation void _UpdateActivePane(std::shared_ptr pane); winrt::hstring _GetActiveTitle() const; - void _UpdateTabHeader(); - void _ConstructTabRenameBox(const winrt::hstring& tabText); void _RecalculateAndApplyTabColor(); void _ApplyTabColor(const winrt::Windows::UI::Color& color); From 52cc864e790f4e6cd86d8f576b274010186e4fec Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 11 Nov 2020 17:14:44 -0500 Subject: [PATCH 03/10] inform hosting tab when title changes, comments --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 38 ++++++++++++++++++- src/cascadia/TerminalApp/TabHeaderControl.h | 4 ++ src/cascadia/TerminalApp/TabHeaderControl.idl | 5 +++ src/cascadia/TerminalApp/TerminalTab.cpp | 12 +++++- 4 files changed, 56 insertions(+), 3 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 8dfe3a6f0a5..8607741ace0 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -15,21 +15,28 @@ namespace winrt::TerminalApp::implementation { InitializeComponent(); + // We'll only process the KeyUp event if we received an initial KeyDown event first. + // Avoids issue immediately closing the tab rename when we see the enter KeyUp event that was + // sent to the command palette to trigger the openTabRenamer action in the first place. HeaderRenamerTextBox().KeyDown([&](auto&&, auto&&) { _receivedKeyDown = true; }); + // NOTE: (Preview)KeyDown does not work here. If you use that, we'll + // remove the TextBox from the UI tree, then the following KeyUp + // will bubble to the NewTabButton, which we don't want to have + // happen. HeaderRenamerTextBox().KeyUp([&](auto&&, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& e) { if (_receivedKeyDown) { if (e.OriginalKey() == Windows::System::VirtualKey::Enter) { - // close the rename box + // User is done making changes, close the rename box _CloseRenameBox(); } else if (e.OriginalKey() == Windows::System::VirtualKey::Escape) { - // the user wants to discard the changes they made, + // User wants to discard the changes they made, // reset the rename box text to the old text and close the rename box HeaderRenamerTextBox().Text(HeaderTextBlock().Text()); _CloseRenameBox(); @@ -38,16 +45,36 @@ namespace winrt::TerminalApp::implementation }); } + // Method Description + // - Retrives the current title + // Return Value: + // - The current title as a winrt hstring + winrt::hstring TabHeaderControl::CurrentHeaderText() + { + return HeaderTextBlock().Text(); + } + + // Method Description + // - Updates the current title + // Arguments: + // - The desired title void TabHeaderControl::UpdateHeaderText(winrt::hstring title) { HeaderTextBlock().Text(title); } + // Method Description: + // - Updates the zoom icon indicating whether a pane is zoomed + // Arguments: + // - The desired visibility state of the zoom icon void TabHeaderControl::SetZoomIcon(Windows::UI::Xaml::Visibility state) { HeaderZoomIcon().Visibility(state); } + // Method Description: + // - Show the tab rename box for the user to rename the tab title + // - We automatically use the previous title as the initial text of the box void TabHeaderControl::ConstructTabRenameBox() { _receivedKeyDown = false; @@ -60,17 +87,24 @@ namespace winrt::TerminalApp::implementation HeaderRenamerTextBox().Focus(Windows::UI::Xaml::FocusState::Programmatic); } + // Method Description: + // - Event handler for when the rename box loses focus void TabHeaderControl::RenameBoxLostFocusHandler(Windows::Foundation::IInspectable const& /*sender*/, Windows::UI::Xaml::RoutedEventArgs const& /*e*/) { _CloseRenameBox(); } + // Method Description: + // - Hides the rename box and displays the title text block + // - Updates the title text block with the rename box's text void TabHeaderControl::_CloseRenameBox() { HeaderTextBlock().Text(HeaderRenamerTextBox().Text()); HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); + + _HeaderTitleChangedHandlers(); } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 7ca487a86db..6f8aacc2e84 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -4,6 +4,7 @@ #pragma once #include "winrt/Microsoft.UI.Xaml.Controls.h" +#include "inc/cppwinrt_utils.h" #include "TabHeaderControl.g.h" @@ -12,6 +13,7 @@ namespace winrt::TerminalApp::implementation struct TabHeaderControl : TabHeaderControlT { TabHeaderControl(); + winrt::hstring CurrentHeaderText(); void UpdateHeaderText(winrt::hstring title); void SetZoomIcon(Windows::UI::Xaml::Visibility state); void ConstructTabRenameBox(); @@ -19,6 +21,8 @@ namespace winrt::TerminalApp::implementation void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e); + WINRT_CALLBACK(HeaderTitleChanged, TerminalApp::HeaderTitleChangedArgs); + private: void _CloseRenameBox(); bool _receivedKeyDown{ false }; diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index 598abb18835..06a04ddc7ab 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -3,11 +3,16 @@ namespace TerminalApp { + delegate void HeaderTitleChangedArgs(); + [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl { TabHeaderControl(); + String CurrentHeaderText(); void UpdateHeaderText(String title); void SetZoomIcon(Windows.UI.Xaml.Visibility state); void ConstructTabRenameBox(); + + event HeaderTitleChangedArgs HeaderTitleChanged; } } diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index f9b8363953d..c27c179895b 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -37,6 +37,16 @@ namespace winrt::TerminalApp::implementation _MakeTabViewItem(); _CreateContextMenu(); + + // Add an event handler for the header control to tell us when the title changes + _headerControl.HeaderTitleChanged([weakThis = get_weak()]() { + if (auto tab{ weakThis.get() }) + { + tab->SetTabText(tab->_headerControl.CurrentHeaderText()); + } + }); + + // Use our header control as the TabViewItem's header TabViewItem().Header(_headerControl); } @@ -217,7 +227,7 @@ namespace winrt::TerminalApp::implementation // Update SwitchToTab command's name SwitchToTabCommand().Name(Title()); - // Update the UI to reflect the changed + // Update the control to reflect the changed title _headerControl.UpdateHeaderText(Title()); } } From e37b2257112c416d3330741cb1f1b420da5f4e7a Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 11 Nov 2020 17:19:29 -0500 Subject: [PATCH 04/10] spell --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 8607741ace0..f0a2e0069f0 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -46,7 +46,7 @@ namespace winrt::TerminalApp::implementation } // Method Description - // - Retrives the current title + // - Retrieves the current title // Return Value: // - The current title as a winrt hstring winrt::hstring TabHeaderControl::CurrentHeaderText() From 613efc5903a21b2d973141ff1a270790ccbe485c Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 13 Nov 2020 11:16:22 -0500 Subject: [PATCH 05/10] store current title --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 11 ++++++----- src/cascadia/TerminalApp/TabHeaderControl.h | 4 +++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index f0a2e0069f0..c6203f25655 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -38,7 +38,7 @@ namespace winrt::TerminalApp::implementation { // User wants to discard the changes they made, // reset the rename box text to the old text and close the rename box - HeaderRenamerTextBox().Text(HeaderTextBlock().Text()); + HeaderRenamerTextBox().Text(_currentTitle); _CloseRenameBox(); } } @@ -51,7 +51,7 @@ namespace winrt::TerminalApp::implementation // - The current title as a winrt hstring winrt::hstring TabHeaderControl::CurrentHeaderText() { - return HeaderTextBlock().Text(); + return _currentTitle; } // Method Description @@ -60,7 +60,8 @@ namespace winrt::TerminalApp::implementation // - The desired title void TabHeaderControl::UpdateHeaderText(winrt::hstring title) { - HeaderTextBlock().Text(title); + _currentTitle = title; + HeaderTextBlock().Text(_currentTitle); } // Method Description: @@ -82,7 +83,7 @@ namespace winrt::TerminalApp::implementation HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Visible); - HeaderRenamerTextBox().Text(HeaderTextBlock().Text()); + HeaderRenamerTextBox().Text(_currentTitle); HeaderRenamerTextBox().SelectAll(); HeaderRenamerTextBox().Focus(Windows::UI::Xaml::FocusState::Programmatic); } @@ -100,7 +101,7 @@ namespace winrt::TerminalApp::implementation // - Updates the title text block with the rename box's text void TabHeaderControl::_CloseRenameBox() { - HeaderTextBlock().Text(HeaderRenamerTextBox().Text()); + UpdateHeaderText(HeaderRenamerTextBox().Text()); HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 6f8aacc2e84..8afd99c821e 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -24,8 +24,10 @@ namespace winrt::TerminalApp::implementation WINRT_CALLBACK(HeaderTitleChanged, TerminalApp::HeaderTitleChangedArgs); private: - void _CloseRenameBox(); + winrt::hstring _currentTitle; bool _receivedKeyDown{ false }; + + void _CloseRenameBox(); }; } From 01243cc562718ce259fc7e548ea67a5e8f5d5a11 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Mon, 16 Nov 2020 11:23:42 -0500 Subject: [PATCH 06/10] send event to tab for them to update our title --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 26 ++++++------------- src/cascadia/TerminalApp/TabHeaderControl.h | 5 ++-- src/cascadia/TerminalApp/TabHeaderControl.idl | 5 ++-- .../TerminalApp/TabHeaderControl.xaml | 3 ++- src/cascadia/TerminalApp/TerminalTab.cpp | 6 ++--- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index c6203f25655..40cccfc9e3a 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -38,7 +38,7 @@ namespace winrt::TerminalApp::implementation { // User wants to discard the changes they made, // reset the rename box text to the old text and close the rename box - HeaderRenamerTextBox().Text(_currentTitle); + HeaderRenamerTextBox().Text(Title()); _CloseRenameBox(); } } @@ -46,22 +46,12 @@ namespace winrt::TerminalApp::implementation } // Method Description - // - Retrieves the current title - // Return Value: - // - The current title as a winrt hstring - winrt::hstring TabHeaderControl::CurrentHeaderText() - { - return _currentTitle; - } - - // Method Description - // - Updates the current title + // - Updates the current title and bubbles the event up to the UI // Arguments: // - The desired title void TabHeaderControl::UpdateHeaderText(winrt::hstring title) { - _currentTitle = title; - HeaderTextBlock().Text(_currentTitle); + Title(title); } // Method Description: @@ -83,7 +73,7 @@ namespace winrt::TerminalApp::implementation HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Visible); - HeaderRenamerTextBox().Text(_currentTitle); + HeaderRenamerTextBox().Text(Title()); HeaderRenamerTextBox().SelectAll(); HeaderRenamerTextBox().Focus(Windows::UI::Xaml::FocusState::Programmatic); } @@ -98,14 +88,14 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Hides the rename box and displays the title text block - // - Updates the title text block with the rename box's text + // - Sends an event to the hosting tab to let them know we wish to change the title + // to whatever is in the renamer box right now - the tab will process that event + // and tell us to update our title void TabHeaderControl::_CloseRenameBox() { - UpdateHeaderText(HeaderRenamerTextBox().Text()); - HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); - _HeaderTitleChangedHandlers(); + _HeaderTitleChangedHandlers(HeaderRenamerTextBox().Text()); } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 8afd99c821e..2b25049d33b 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -13,7 +13,6 @@ namespace winrt::TerminalApp::implementation struct TabHeaderControl : TabHeaderControlT { TabHeaderControl(); - winrt::hstring CurrentHeaderText(); void UpdateHeaderText(winrt::hstring title); void SetZoomIcon(Windows::UI::Xaml::Visibility state); void ConstructTabRenameBox(); @@ -23,8 +22,10 @@ namespace winrt::TerminalApp::implementation WINRT_CALLBACK(HeaderTitleChanged, TerminalApp::HeaderTitleChangedArgs); + WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); + OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers); + private: - winrt::hstring _currentTitle; bool _receivedKeyDown{ false }; void _CloseRenameBox(); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index 06a04ddc7ab..b2224d34a1e 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -3,12 +3,13 @@ namespace TerminalApp { - delegate void HeaderTitleChangedArgs(); + delegate void HeaderTitleChangedArgs(String title); [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl { + String Title { get; }; + TabHeaderControl(); - String CurrentHeaderText(); void UpdateHeaderText(String title); void SetZoomIcon(Windows.UI.Xaml.Visibility state); void ConstructTabRenameBox(); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index 574e1502a8b..6b6041f0fce 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -19,7 +19,8 @@ the MIT License. See LICENSE in the project root for license information. --> FontSize="12" Margin="0,0,8,0"/> + Visibility="Visible" + Text="{x:Bind Title}"/> SetTabText(tab->_headerControl.CurrentHeaderText()); + tab->SetTabText(title); } }); From 4ef5fda069deef8bf8df3b578f92e805f3341bbe Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Mon, 16 Nov 2020 13:53:21 -0500 Subject: [PATCH 07/10] address comments --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 9 --------- src/cascadia/TerminalApp/TabHeaderControl.h | 1 - src/cascadia/TerminalApp/TabHeaderControl.idl | 5 ++--- src/cascadia/TerminalApp/TabHeaderControl.xaml | 2 +- src/cascadia/TerminalApp/TerminalTab.cpp | 5 +++-- 5 files changed, 6 insertions(+), 16 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 40cccfc9e3a..b401b69361c 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -45,15 +45,6 @@ namespace winrt::TerminalApp::implementation }); } - // Method Description - // - Updates the current title and bubbles the event up to the UI - // Arguments: - // - The desired title - void TabHeaderControl::UpdateHeaderText(winrt::hstring title) - { - Title(title); - } - // Method Description: // - Updates the zoom icon indicating whether a pane is zoomed // Arguments: diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 2b25049d33b..547f4d4c0a4 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -13,7 +13,6 @@ namespace winrt::TerminalApp::implementation struct TabHeaderControl : TabHeaderControlT { TabHeaderControl(); - void UpdateHeaderText(winrt::hstring title); void SetZoomIcon(Windows::UI::Xaml::Visibility state); void ConstructTabRenameBox(); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index b2224d34a1e..247ea9e120c 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -5,12 +5,11 @@ namespace TerminalApp { delegate void HeaderTitleChangedArgs(String title); - [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl + [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged { - String Title { get; }; + String Title { get; set; }; TabHeaderControl(); - void UpdateHeaderText(String title); void SetZoomIcon(Windows.UI.Xaml.Visibility state); void ConstructTabRenameBox(); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index 6b6041f0fce..1656e32111e 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -20,7 +20,7 @@ the MIT License. See LICENSE in the project root for license information. --> Margin="0,0,8,0"/> + Text="{x:Bind Title, Mode=OneWay}"/> Date: Mon, 16 Nov 2020 13:56:39 -0500 Subject: [PATCH 08/10] rename event --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 2 +- src/cascadia/TerminalApp/TabHeaderControl.h | 2 +- src/cascadia/TerminalApp/TabHeaderControl.idl | 4 ++-- src/cascadia/TerminalApp/TerminalTab.cpp | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index b401b69361c..8487cd046b0 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -87,6 +87,6 @@ namespace winrt::TerminalApp::implementation HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); - _HeaderTitleChangedHandlers(HeaderRenamerTextBox().Text()); + _HeaderTitleWantsToChangeHandlers(HeaderRenamerTextBox().Text()); } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 547f4d4c0a4..7ad19cb7f2d 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -19,7 +19,7 @@ namespace winrt::TerminalApp::implementation void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e); - WINRT_CALLBACK(HeaderTitleChanged, TerminalApp::HeaderTitleChangedArgs); + WINRT_CALLBACK(HeaderTitleWantsToChange, TerminalApp::HeaderTitleWantsToChangeArgs); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers); diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index 247ea9e120c..d13e9a734dc 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -3,7 +3,7 @@ namespace TerminalApp { - delegate void HeaderTitleChangedArgs(String title); + delegate void HeaderTitleWantsToChangeArgs(String title); [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged { @@ -13,6 +13,6 @@ namespace TerminalApp void SetZoomIcon(Windows.UI.Xaml.Visibility state); void ConstructTabRenameBox(); - event HeaderTitleChangedArgs HeaderTitleChanged; + event HeaderTitleWantsToChangeArgs HeaderTitleWantsToChange; } } diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index aa3c3de6cfb..37c327688e0 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -39,7 +39,7 @@ namespace winrt::TerminalApp::implementation _CreateContextMenu(); // Add an event handler for the header control to tell us when they want their title to change - _headerControl.HeaderTitleChanged([weakThis = get_weak()](auto&& title) { + _headerControl.HeaderTitleWantsToChange([weakThis = get_weak()](auto&& title) { if (auto tab{ weakThis.get() }) { tab->SetTabText(title); From b092b88f043730f1b4bad532cb6800e7e154d246 Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Wed, 18 Nov 2020 10:44:34 -0500 Subject: [PATCH 09/10] addressing comments --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 4 +++- src/cascadia/TerminalApp/TabHeaderControl.h | 6 ++---- src/cascadia/TerminalApp/TabHeaderControl.idl | 2 +- src/cascadia/TerminalApp/TerminalTab.cpp | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 8487cd046b0..4b16572ec2b 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -49,7 +49,7 @@ namespace winrt::TerminalApp::implementation // - Updates the zoom icon indicating whether a pane is zoomed // Arguments: // - The desired visibility state of the zoom icon - void TabHeaderControl::SetZoomIcon(Windows::UI::Xaml::Visibility state) + void TabHeaderControl::SetZoomIconVisibility(Windows::UI::Xaml::Visibility state) { HeaderZoomIcon().Visibility(state); } @@ -71,6 +71,8 @@ namespace winrt::TerminalApp::implementation // Method Description: // - Event handler for when the rename box loses focus + // - When the rename box loses focus, we use the text in it as the new title + // (i.e. we commit the change instead of cancelling it) void TabHeaderControl::RenameBoxLostFocusHandler(Windows::Foundation::IInspectable const& /*sender*/, Windows::UI::Xaml::RoutedEventArgs const& /*e*/) { diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index 7ad19cb7f2d..c44df7dfbcf 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -13,7 +13,7 @@ namespace winrt::TerminalApp::implementation struct TabHeaderControl : TabHeaderControlT { TabHeaderControl(); - void SetZoomIcon(Windows::UI::Xaml::Visibility state); + void SetZoomIconVisibility(Windows::UI::Xaml::Visibility state); void ConstructTabRenameBox(); void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender, @@ -33,7 +33,5 @@ namespace winrt::TerminalApp::implementation namespace winrt::TerminalApp::factory_implementation { - struct TabHeaderControl : TabHeaderControlT - { - }; + BASIC_FACTORY(TabHeaderControl); } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index d13e9a734dc..24894313378 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -10,7 +10,7 @@ namespace TerminalApp String Title { get; set; }; TabHeaderControl(); - void SetZoomIcon(Windows.UI.Xaml.Visibility state); + void SetZoomIconVisibility(Windows.UI.Xaml.Visibility state); void ConstructTabRenameBox(); event HeaderTitleWantsToChangeArgs HeaderTitleWantsToChange; diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 37c327688e0..685984c74c8 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -851,7 +851,7 @@ namespace winrt::TerminalApp::implementation _zoomedPane = _activePane; _rootPane->Maximize(_zoomedPane); // Update the tab header to show the magnifying glass - _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Visible); + _headerControl.SetZoomIconVisibility(Windows::UI::Xaml::Visibility::Visible); Content(_zoomedPane->GetRootElement()); } void TerminalTab::ExitZoom() @@ -859,7 +859,7 @@ namespace winrt::TerminalApp::implementation _rootPane->Restore(_zoomedPane); _zoomedPane = nullptr; // Update the tab header to hide the magnifying glass - _headerControl.SetZoomIcon(Windows::UI::Xaml::Visibility::Collapsed); + _headerControl.SetZoomIconVisibility(Windows::UI::Xaml::Visibility::Collapsed); Content(_rootPane->GetRootElement()); } From 47ba94936728ac14708292ac449d97e1c5ff38da Mon Sep 17 00:00:00 2001 From: Pankaj Bhojwani Date: Fri, 20 Nov 2020 10:37:24 -0500 Subject: [PATCH 10/10] addressing comments --- src/cascadia/TerminalApp/TabHeaderControl.cpp | 13 ++----------- src/cascadia/TerminalApp/TabHeaderControl.h | 6 +++--- src/cascadia/TerminalApp/TabHeaderControl.idl | 8 ++++---- src/cascadia/TerminalApp/TabHeaderControl.xaml | 3 +-- src/cascadia/TerminalApp/TerminalTab.cpp | 8 ++++---- 5 files changed, 14 insertions(+), 24 deletions(-) diff --git a/src/cascadia/TerminalApp/TabHeaderControl.cpp b/src/cascadia/TerminalApp/TabHeaderControl.cpp index 4b16572ec2b..4612ea7e481 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.cpp +++ b/src/cascadia/TerminalApp/TabHeaderControl.cpp @@ -45,19 +45,10 @@ namespace winrt::TerminalApp::implementation }); } - // Method Description: - // - Updates the zoom icon indicating whether a pane is zoomed - // Arguments: - // - The desired visibility state of the zoom icon - void TabHeaderControl::SetZoomIconVisibility(Windows::UI::Xaml::Visibility state) - { - HeaderZoomIcon().Visibility(state); - } - // Method Description: // - Show the tab rename box for the user to rename the tab title // - We automatically use the previous title as the initial text of the box - void TabHeaderControl::ConstructTabRenameBox() + void TabHeaderControl::BeginRename() { _receivedKeyDown = false; @@ -89,6 +80,6 @@ namespace winrt::TerminalApp::implementation HeaderRenamerTextBox().Visibility(Windows::UI::Xaml::Visibility::Collapsed); HeaderTextBlock().Visibility(Windows::UI::Xaml::Visibility::Visible); - _HeaderTitleWantsToChangeHandlers(HeaderRenamerTextBox().Text()); + _TitleChangeRequestedHandlers(HeaderRenamerTextBox().Text()); } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.h b/src/cascadia/TerminalApp/TabHeaderControl.h index c44df7dfbcf..367ce43178c 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.h +++ b/src/cascadia/TerminalApp/TabHeaderControl.h @@ -13,16 +13,16 @@ namespace winrt::TerminalApp::implementation struct TabHeaderControl : TabHeaderControlT { TabHeaderControl(); - void SetZoomIconVisibility(Windows::UI::Xaml::Visibility state); - void ConstructTabRenameBox(); + void BeginRename(); void RenameBoxLostFocusHandler(winrt::Windows::Foundation::IInspectable const& sender, winrt::Windows::UI::Xaml::RoutedEventArgs const& e); - WINRT_CALLBACK(HeaderTitleWantsToChange, TerminalApp::HeaderTitleWantsToChangeArgs); + WINRT_CALLBACK(TitleChangeRequested, TerminalApp::TitleChangeRequestedArgs); WINRT_CALLBACK(PropertyChanged, Windows::UI::Xaml::Data::PropertyChangedEventHandler); OBSERVABLE_GETSET_PROPERTY(winrt::hstring, Title, _PropertyChangedHandlers); + OBSERVABLE_GETSET_PROPERTY(bool, IsPaneZoomed, _PropertyChangedHandlers); private: bool _receivedKeyDown{ false }; diff --git a/src/cascadia/TerminalApp/TabHeaderControl.idl b/src/cascadia/TerminalApp/TabHeaderControl.idl index 24894313378..a9dd3f571e0 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.idl +++ b/src/cascadia/TerminalApp/TabHeaderControl.idl @@ -3,16 +3,16 @@ namespace TerminalApp { - delegate void HeaderTitleWantsToChangeArgs(String title); + delegate void TitleChangeRequestedArgs(String title); [default_interface] runtimeclass TabHeaderControl : Windows.UI.Xaml.Controls.UserControl, Windows.UI.Xaml.Data.INotifyPropertyChanged { String Title { get; set; }; + Boolean IsPaneZoomed { get; set; }; TabHeaderControl(); - void SetZoomIconVisibility(Windows.UI.Xaml.Visibility state); - void ConstructTabRenameBox(); + void BeginRename(); - event HeaderTitleWantsToChangeArgs HeaderTitleWantsToChange; + event TitleChangeRequestedArgs TitleChangeRequested; } } diff --git a/src/cascadia/TerminalApp/TabHeaderControl.xaml b/src/cascadia/TerminalApp/TabHeaderControl.xaml index 1656e32111e..4c09b3b0d8e 100644 --- a/src/cascadia/TerminalApp/TabHeaderControl.xaml +++ b/src/cascadia/TerminalApp/TabHeaderControl.xaml @@ -5,7 +5,6 @@ the MIT License. See LICENSE in the project root for license information. --> xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:TerminalApp" - xmlns:mux="using:Microsoft.UI.Xaml.Controls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> @@ -14,7 +13,7 @@ the MIT License. See LICENSE in the project root for license information. --> Orientation="Horizontal"> diff --git a/src/cascadia/TerminalApp/TerminalTab.cpp b/src/cascadia/TerminalApp/TerminalTab.cpp index 685984c74c8..88cb91011e4 100644 --- a/src/cascadia/TerminalApp/TerminalTab.cpp +++ b/src/cascadia/TerminalApp/TerminalTab.cpp @@ -39,7 +39,7 @@ namespace winrt::TerminalApp::implementation _CreateContextMenu(); // Add an event handler for the header control to tell us when they want their title to change - _headerControl.HeaderTitleWantsToChange([weakThis = get_weak()](auto&& title) { + _headerControl.TitleChangeRequested([weakThis = get_weak()](auto&& title) { if (auto tab{ weakThis.get() }) { tab->SetTabText(title); @@ -379,7 +379,7 @@ namespace winrt::TerminalApp::implementation // - void TerminalTab::ActivateTabRenamer() { - _headerControl.ConstructTabRenameBox(); + _headerControl.BeginRename(); } // Method Description: @@ -851,7 +851,7 @@ namespace winrt::TerminalApp::implementation _zoomedPane = _activePane; _rootPane->Maximize(_zoomedPane); // Update the tab header to show the magnifying glass - _headerControl.SetZoomIconVisibility(Windows::UI::Xaml::Visibility::Visible); + _headerControl.IsPaneZoomed(true); Content(_zoomedPane->GetRootElement()); } void TerminalTab::ExitZoom() @@ -859,7 +859,7 @@ namespace winrt::TerminalApp::implementation _rootPane->Restore(_zoomedPane); _zoomedPane = nullptr; // Update the tab header to hide the magnifying glass - _headerControl.SetZoomIconVisibility(Windows::UI::Xaml::Visibility::Collapsed); + _headerControl.IsPaneZoomed(false); Content(_rootPane->GetRootElement()); }