Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for hiding the tab close button #13348

Merged
84 commits merged into from Aug 1, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
84 commits
Select commit Hold shift + click to select a range
15e4fd9
Settings project builds at least
zadjii-msft Mar 24, 2022
7e0ae35
this fixes the App bits as well
zadjii-msft Mar 24, 2022
00c135b
on reload, this changes the BG of the titlebar, but not the tab view
zadjii-msft Mar 24, 2022
b4cd7b3
this is better. Apphost is gonna need to be involved anyways so fuck it
zadjii-msft Mar 24, 2022
9627483
okay so i bet that resource changed. Whatever, we'll work with it.
zadjii-msft Mar 24, 2022
84805f5
dumbly accept alpha channel in colors
zadjii-msft Mar 24, 2022
9670d13
mica works, but the titlebar looks DUMB
zadjii-msft Mar 24, 2022
c555e6e
this did seem to work, but will it work for acrylic?
zadjii-msft Mar 25, 2022
01f07be
okay so you can't change a solid brush to an acylic one at runtime
zadjii-msft Mar 25, 2022
ee9333a
A pile of dead ends.
zadjii-msft Mar 25, 2022
9eff0a2
i feel like I'm getting closer
zadjii-msft Mar 25, 2022
44112fc
really, no good progress here. It's rough
zadjii-msft Mar 28, 2022
f92724d
We can't be clever here. Just make an observable property and slam th…
zadjii-msft Apr 25, 2022
cd0012a
guess what, it works
zadjii-msft Apr 25, 2022
ac49459
change color based on if the window is activated or now
zadjii-msft Apr 26, 2022
03211c8
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 26, 2022
1d0a5d7
Merge remote-tracking branch 'origin/dev/migrie/titebar-colors' into …
zadjii-msft Apr 26, 2022
e22046f
accept accent color as a ThemeColor
zadjii-msft Apr 26, 2022
99dc75d
this actually works now. Remember kids, break statements in switch/ca…
zadjii-msft Apr 26, 2022
a7ce860
cleanup, works on start and when unset
zadjii-msft Apr 26, 2022
4f42661
Lookup themes from a list of themes, use that one to style the window
zadjii-msft Apr 26, 2022
5081118
This is horrifying and yet I'm totally shipping it. Move the objects …
zadjii-msft Apr 26, 2022
fe26114
better, better,
zadjii-msft Apr 26, 2022
7fcfda3
wow
zadjii-msft Apr 26, 2022
df0efff
stragglers
zadjii-msft Apr 26, 2022
7243603
hey this is easier
zadjii-msft Apr 26, 2022
606db76
this is like 99% of the work here
zadjii-msft Apr 26, 2022
de22df0
switches when a tab does, not the pane
zadjii-msft Apr 26, 2022
01d6907
I think that's everything
zadjii-msft Apr 26, 2022
39b6fdd
Some minor todos
zadjii-msft Apr 26, 2022
9bebb74
Some settings saving roundtripping bugs
zadjii-msft Apr 27, 2022
cfb99d9
Change theme with the SUI and actually have it persist
zadjii-msft Apr 27, 2022
a57187b
include the themes
zadjii-msft Apr 27, 2022
b6b9aea
Use better display names
zadjii-msft Apr 27, 2022
e2318b4
This is horrifying
zadjii-msft Apr 27, 2022
bc8bb8e
more comments
zadjii-msft Apr 27, 2022
446e17b
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 27, 2022
fd2dd3a
cleanup for the review
zadjii-msft Apr 27, 2022
a1ea0fd
forgot you
zadjii-msft Apr 28, 2022
9b9a644
spell
zadjii-msft Apr 28, 2022
03da3b7
runformat
zadjii-msft Apr 28, 2022
24f945a
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Apr 29, 2022
49c580c
well, this is like all of it
zadjii-msft Apr 29, 2022
3281a3a
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 3, 2022
476c5bb
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 3, 2022
68d70a0
this is REALLY janky but seems to work
zadjii-msft May 3, 2022
99bc963
this is simpler
zadjii-msft May 3, 2022
6c28ba6
make the code a lot cleaner
zadjii-msft May 3, 2022
342eb2b
Removes the ability to add Mica in the titlebar, but good enough for v0
zadjii-msft May 4, 2022
cd2fd43
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 5, 2022
44319a1
Fixes the Settings UI terminalBackground settings
zadjii-msft May 5, 2022
d73e450
this fixes the terminalBG + runtime change
zadjii-msft May 5, 2022
e52b7a9
well, this was part of it...
zadjii-msft May 5, 2022
3af471a
derp
zadjii-msft May 5, 2022
b2abca6
Add comments
zadjii-msft May 6, 2022
cae5218
Start by just adding a test file
zadjii-msft May 6, 2022
45fb4b1
Fill in more tests
zadjii-msft May 6, 2022
28119c7
This is what I was looking for
zadjii-msft May 6, 2022
2712e46
Fix having a null window, cause that was actually very possible
zadjii-msft May 6, 2022
331b98f
sensible defaults
zadjii-msft May 6, 2022
f38dc5c
typos
zadjii-msft May 6, 2022
cb788b0
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 6, 2022
4f55646
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 9, 2022
f5007fa
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft May 25, 2022
87a9222
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft May 25, 2022
9c3b861
cleanup for review
zadjii-msft May 25, 2022
d9b383f
that's not even that bad
zadjii-msft May 25, 2022
861cd2a
the more important color thing
zadjii-msft May 26, 2022
c07b01e
more nits and such
zadjii-msft May 26, 2022
72904b9
typo
zadjii-msft May 26, 2022
c8254b2
this wouldn't happen if there was just an operator?.()
zadjii-msft May 26, 2022
8d86538
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Jun 16, 2022
0e13b7b
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft Jun 16, 2022
465f45d
basically all of it
zadjii-msft Jun 16, 2022
95790a5
this works pretty dang well
zadjii-msft Jun 16, 2022
ee4ae62
Merge remote-tracking branch 'origin/main' into dev/migrie/fhl/themin…
zadjii-msft Jul 6, 2022
9806d64
just disable mica for now
zadjii-msft Jul 6, 2022
4245964
This is what happens when a PR has been open for ages
zadjii-msft Jul 6, 2022
9ab99b3
nits across the board
zadjii-msft Jul 6, 2022
a80dc6a
Merge branch 'dev/migrie/fhl/theming-2022-prototype' into dev/migrie/…
zadjii-msft Jul 6, 2022
27ed738
Merge branch 'dev/migrie/f/702-link-tab-to-terminal' into dev/migrie/…
zadjii-msft Jul 6, 2022
1ad6ef4
Merge remote-tracking branch 'origin/main' into dev/migrie/f/3335-tab…
zadjii-msft Jul 12, 2022
9e75f67
fix build breaks
zadjii-msft Jul 12, 2022
dab4501
the null deref we were talking about
zadjii-msft Jul 12, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/cascadia/TerminalApp/TabManagement.cpp
Expand Up @@ -234,6 +234,9 @@ namespace winrt::TerminalApp::implementation
auto tabViewItem = newTabImpl->TabViewItem();
_tabView.TabItems().InsertAt(insertPosition, tabViewItem);

// Update the state of the close button to match the current theme
_updateTabCloseButton(tabViewItem);

// Set this tab's icon to the icon from the user's profile
if (const auto profile{ newTabImpl->GetFocusedProfile() })
{
Expand Down
103 changes: 100 additions & 3 deletions src/cascadia/TerminalApp/TerminalPage.cpp
Expand Up @@ -225,6 +225,26 @@ namespace winrt::TerminalApp::implementation
}
_updateThemeColors();

// Initialize the state of the the CloseButtonOverlayMode property of
// our TabView, to match the tab.showCloseButton property in the theme.
if (const auto theme = _settings.GlobalSettings().CurrentTheme())
{
const auto visibility = theme.Tab() ? theme.Tab().ShowCloseButton() : Settings::Model::TabCloseButtonVisibility::Always;

switch (visibility)
{
case Settings::Model::TabCloseButtonVisibility::Never:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Auto);
break;
case Settings::Model::TabCloseButtonVisibility::Hover:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::OnPointerOver);
break;
default:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Always);
break;
}
}

// Hookup our event handlers to the ShortcutActionDispatch
_RegisterActionCallbacks();

Expand Down Expand Up @@ -2703,6 +2723,48 @@ namespace winrt::TerminalApp::implementation
////////////////////////////////////////////////////////////////////////
// Begin Theme handling
_updateThemeColors();

// Update the state of the the CloseButtonOverlayMode property of
// our TabView, to match the tab.showCloseButton property in the theme.
//
// Also update every tab's individual IsClosable to match.
//
// This is basically the same as _updateTabCloseButton, but with some
// code moved around to better facilitate updating every tab view item
// at once
Comment on lines +2732 to +2734
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally, I'd rather prioritize having the code de-duplicated in case we need to make a bugfix or any code changes down the road. But that's just my 2 cents. Not gonna block over it.

if (const auto theme = _settings.GlobalSettings().CurrentTheme())
{
const auto visibility = theme.Tab() ? theme.Tab().ShowCloseButton() : Settings::Model::TabCloseButtonVisibility::Always;

for (const auto& tab : _tabs)
{
switch (visibility)
{
case Settings::Model::TabCloseButtonVisibility::Never:
tab.TabViewItem().IsClosable(false);
break;
case Settings::Model::TabCloseButtonVisibility::Hover:
tab.TabViewItem().IsClosable(true);
break;
default:
tab.TabViewItem().IsClosable(true);
break;
}
}

switch (visibility)
{
case Settings::Model::TabCloseButtonVisibility::Never:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Auto);
break;
case Settings::Model::TabCloseButtonVisibility::Hover:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::OnPointerOver);
break;
default:
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Always);
break;
}
}
}

// This is a helper to aid in sorting commands by their `Name`s, alphabetically.
Expand Down Expand Up @@ -3256,6 +3318,9 @@ namespace winrt::TerminalApp::implementation
auto tabViewItem = newTabImpl->TabViewItem();
_tabView.TabItems().Append(tabViewItem);

// Update the state of the close button to match the current theme
_updateTabCloseButton(tabViewItem);

tabViewItem.PointerPressed({ this, &TerminalPage::_OnTabClick });

// When the tab requests close, try to close it (prompt for approval, if required)
Expand Down Expand Up @@ -4100,9 +4165,9 @@ namespace winrt::TerminalApp::implementation

TitlebarBrush(acrylicBrush);
}
else if (const auto tabRowBg{ _activated ? theme.TabRow().Background() :
theme.TabRow().UnfocusedBackground() };
tabRowBg != nullptr && theme.TabRow() != nullptr)
else if (auto tabRowBg{ theme.TabRow() ? (_activated ? theme.TabRow().Background() :
theme.TabRow().UnfocusedBackground()) :
ThemeColor{ nullptr } })
{
const auto terminalBrush = [this]() -> Media::Brush {
if (const auto& control{ _GetActiveControl() })
Expand Down Expand Up @@ -4137,6 +4202,38 @@ namespace winrt::TerminalApp::implementation
_SetNewTabButtonColor(bgColor, bgColor);
}

void TerminalPage::_updateTabCloseButton(const winrt::Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem)
{
// Update the state of the close button to match the current theme.
// IMPORTANT: Should be called AFTER the tab view item is added to the TabView.
if (const auto theme = _settings.GlobalSettings().CurrentTheme())
{
const auto visibility = theme.Tab() ? theme.Tab().ShowCloseButton() : Settings::Model::TabCloseButtonVisibility::Always;

// Update both the tab item's IsClosable, but also the TabView's
// CloseButtonOverlayMode here. Because the TabViewItem was created
// outside the context of the TabView, it doesn't get the
// CloseButtonOverlayMode assigned on creation. We have to update
// that property again here, when we add the tab, so that the
// TabView will re-apply the value.
switch (visibility)
{
case Settings::Model::TabCloseButtonVisibility::Never:
tabViewItem.IsClosable(false);
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Auto);
break;
case Settings::Model::TabCloseButtonVisibility::Hover:
tabViewItem.IsClosable(true);
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::OnPointerOver);
break;
default:
tabViewItem.IsClosable(true);
_tabView.CloseButtonOverlayMode(MUX::Controls::TabViewCloseButtonOverlayMode::Always);
break;
}
}
}

void TerminalPage::WindowActivated(const bool activated)
{
// Stash if we're activated. Use that when we reload
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TerminalPage.h
Expand Up @@ -447,6 +447,7 @@ namespace winrt::TerminalApp::implementation
static void _DismissMessage(const winrt::Microsoft::Terminal::Settings::Model::InfoBarMessage& message);

void _updateThemeColors();
void _updateTabCloseButton(const winrt::Microsoft::UI::Xaml::Controls::TabViewItem& tabViewItem);

winrt::fire_and_forget _ShowWindowChangedHandler(const IInspectable sender, const winrt::Microsoft::Terminal::Control::ShowWindowArgs args);

Expand Down
5 changes: 3 additions & 2 deletions src/cascadia/TerminalSettingsModel/MTSMSettings.h
Expand Up @@ -129,5 +129,6 @@ Author(s):
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, UnfocusedBackground, "unfocusedBackground", nullptr)

#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr)
#define MTSM_THEME_TAB_SETTINGS(X) \
X(winrt::Microsoft::Terminal::Settings::Model::ThemeColor, Background, "background", nullptr) \
X(winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVisibility, ShowCloseButton, "showCloseButton", winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVisibility::Always)
Expand Up @@ -631,6 +631,15 @@ struct ::Microsoft::Terminal::Settings::Model::JsonUtils::ConversionTrait<winrt:
}
};

JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Settings::Model::TabCloseButtonVisibility)
{
JSON_MAPPINGS(3) = {
pair_type{ "always", ValueType::Always },
pair_type{ "hover", ValueType::Hover },
pair_type{ "never", ValueType::Never },
};
};

// Possible ScrollToMarkDirection values
JSON_ENUM_MAPPER(::winrt::Microsoft::Terminal::Control::ScrollToMarkDirection)
{
Expand Down
8 changes: 8 additions & 0 deletions src/cascadia/TerminalSettingsModel/Theme.idl
Expand Up @@ -11,6 +11,13 @@ namespace Microsoft.Terminal.Settings.Model
TerminalBackground
};

enum TabCloseButtonVisibility
{
Always,
Hover,
Never
};

runtimeclass ThemeColor
{
ThemeColor();
Expand Down Expand Up @@ -39,6 +46,7 @@ namespace Microsoft.Terminal.Settings.Model

runtimeclass TabTheme {
ThemeColor Background { get; };
TabCloseButtonVisibility ShowCloseButton { get; };
}

[default_interface] runtimeclass Theme : Windows.Foundation.IStringable {
Expand Down