Skip to content

Commit

Permalink
Add color indicator for tab switch menu (CTRL+T)
Browse files Browse the repository at this point in the history
  • Loading branch information
nukoseer committed Aug 28, 2024
1 parent 93d592b commit c5e01b0
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/cascadia/TerminalApp/CommandPalette.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,13 @@
Visibility="{x:Bind Item.(local:TabPaletteItem.TabStatus).IsInputBroadcastActive, Mode=OneWay}" />

</StackPanel>

<Ellipse Grid.Column="4"
Width="8"
Height="8"
HorizontalAlignment="Center"
VerticalAlignment="Center"
Fill="{x:Bind mtu:Converters.ColorToBrush(Item.TabColorIndicator), Mode=OneWay}" />
</Grid>
</DataTemplate>

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/PaletteItem.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace winrt::TerminalApp::implementation

WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Name, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Icon, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Color, TabColorIndicator, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, KeyChordText, PropertyChanged.raise);
};
}
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/PaletteItem.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace TerminalApp
String Name;
String KeyChordText;
String Icon;
Windows.UI.Color TabColorIndicator;
Windows.UI.Xaml.Controls.IconElement ResolvedIcon { get; };
}
}
16 changes: 16 additions & 0 deletions src/cascadia/TerminalApp/TabBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,22 @@ namespace winrt::TerminalApp::implementation
{
_ClearTabBackgroundColor();
}

_UpdateTabColorIndicator();
}

void TabBase::_UpdateTabColorIndicator()
{
const auto currentColor = GetTabColor();

if (currentColor.has_value())
{
TabColorIndicator(currentColor.value());
}
else
{
TabColorIndicator(Windows::UI::Colors::Transparent());
}
}

// Method Description:
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/TerminalApp/TabBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace winrt::TerminalApp::implementation

WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Title, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(winrt::hstring, Icon, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(winrt::Windows::UI::Color, TabColorIndicator, PropertyChanged.raise);
WINRT_OBSERVABLE_PROPERTY(bool, ReadOnly, PropertyChanged.raise, false);
WINRT_PROPERTY(winrt::Microsoft::UI::Xaml::Controls::TabViewItem, TabViewItem, nullptr);

Expand Down Expand Up @@ -78,6 +79,7 @@ namespace winrt::TerminalApp::implementation

void _RecalculateAndApplyTabColor();
void _ApplyTabColorOnUIThread(const winrt::Windows::UI::Color& color);
void _UpdateTabColorIndicator();
void _ClearTabBackgroundColor();
void _RefreshVisualState();
virtual winrt::Windows::UI::Xaml::Media::Brush _BackgroundBrush() = 0;
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/TabBase.idl
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ namespace TerminalApp
{
String Title { get; };
String Icon { get; };
Windows.UI.Color TabColorIndicator { get; };
Boolean ReadOnly { get; };
Microsoft.Terminal.Settings.Model.TabCloseButtonVisibility CloseButtonVisibility { get; set; };

Expand Down
5 changes: 5 additions & 0 deletions src/cascadia/TerminalApp/TabPaletteItem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ namespace winrt::TerminalApp::implementation
{
Name(tab.Title());
Icon(tab.Icon());
TabColorIndicator(tab.TabColorIndicator());

_tabChangedRevoker = tab.PropertyChanged(winrt::auto_revoke, [weakThis{ get_weak() }](auto& sender, auto& e) {
auto item{ weakThis.get() };
Expand All @@ -40,6 +41,10 @@ namespace winrt::TerminalApp::implementation
{
item->Icon(senderTab.Icon());
}
else if (changedProperty == L"TabColorIndicator")
{
item->TabColorIndicator(senderTab.TabColorIndicator());
}
}
});

Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalApp/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <winrt/Windows.UI.Xaml.Automation.Peers.h>
#include <winrt/Windows.UI.Xaml.Controls.h>
#include <winrt/Windows.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.UI.Xaml.Shapes.h>
#include <winrt/Windows.UI.Xaml.Data.h>
#include <winrt/Windows.UI.Xaml.Documents.h>
#include <winrt/Windows.UI.Xaml.Input.h>
Expand Down

0 comments on commit c5e01b0

Please sign in to comment.