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 setting a tab's color at runtime w/ context menu #3789

Merged
32 commits merged into from
May 4, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
eeeed7f
Add tab colors #2994
gbaychev Oct 26, 2019
a223c8d
Merge from upstream/master
gbaychev Nov 25, 2019
524ce1c
Use events when picked color changes, adjust the preset colors (#2994)
gbaychev Nov 29, 2019
2109095
Merge from master (#2994)
gbaychev Nov 30, 2019
894d8f9
Do code formatting (#2994)
gbaychev Dec 2, 2019
a4b01b3
Merge branch 'master' into dev/tabs-color
gbaychev Dec 2, 2019
306a8da
Remove unwanted merge artifact (#2994)
gbaychev Dec 4, 2019
3fcfe7f
Merge from master
gbaychev Dec 14, 2019
a92a0e7
Merge branch 'master' into dev/tabs-color
gbaychev Dec 16, 2019
a5aa717
Merge branch 'master' into dev/tabs-color
gbaychev Jan 6, 2020
1cf9407
Incorporate PR feedback #2994
gbaychev Jan 6, 2020
1487ffe
Fix code formatting errors #2994
gbaychev Jan 6, 2020
851b4d4
Merge from master #2994
gbaychev Jan 12, 2020
701b7b3
Improve the ColorPickupFlyout UI #2994
gbaychev Jan 14, 2020
8a21d91
Merge branch 'master' into gbaychev/dev/tabs-color
miniksa Feb 5, 2020
63981ef
Incorporate PR feedback and paint the non-client area #2994
gbaychev Jan 19, 2020
4e20147
Remove the non-client area painting code #2994
gbaychev Feb 7, 2020
e8edec9
Use the brush instead of the color when adjusting the tab color #2994
gbaychev Feb 7, 2020
7cf6b46
Merge branch 'master' into dev/tabs-color
gbaychev Feb 11, 2020
5e735f8
Tweak the color helper a bit for better contrast, now that not the wh…
gbaychev Feb 11, 2020
cfeda22
Merge branch 'master' into dev/tabs-color
gbaychev Feb 15, 2020
5e2490c
Remove merge artefact from a code comment in TerminalPage.cpp #2994
gbaychev Feb 20, 2020
d45b70a
Fix the code formatting and change the quotes in TerminalApp.UnitTest…
gbaychev Feb 20, 2020
226bcd6
Merge remote-tracking branch 'origin/master' into HEAD
DHowett Mar 9, 2020
6686fc2
Tidy up the resources and Xaml code a bit; change to Color...
DHowett Mar 9, 2020
81e32ee
Fix WUI; temp. disable new tab btn color; clean xaml
DHowett Mar 9, 2020
1900cfd
reduce diffs for TA UT vcxproj
DHowett Mar 9, 2020
44df3bf
Code format
DHowett Mar 9, 2020
63bc8a5
Merge remote-tracking branch 'origin/master' into HEAD
zadjii-msft May 1, 2020
a430e60
Apply spellcheck suggestions from code review
zadjii-msft May 1, 2020
611bbf6
Fix typos (hopefully)
zadjii-msft May 1, 2020
ec5be66
Merge branch 'dev/tabs-color' of https://github.com/gbaychev/terminal…
zadjii-msft May 1, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/cascadia/LocalTests_TerminalApp/TabTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace Microsoft::Console;
using namespace TerminalApp;
using namespace WEX::Logging;
using namespace WEX::TestExecution;
using namespace winrt::Windows::ApplicationModel::DataTransfer;

namespace TerminalAppLocalTests
{
Expand Down
2 changes: 2 additions & 0 deletions src/cascadia/LocalTests_TerminalApp/precomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ Author(s):
#include "../../types/inc/utils.hpp"
#include "../../inc/DefaultSettings.h"

#include <winrt/Windows.ApplicationModel.Resources.Core.h>
#include "winrt/Windows.UI.Xaml.Markup.h"
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/windows.ui.core.h>
Expand Down
43 changes: 43 additions & 0 deletions src/cascadia/TerminalApp/ColorFlyoutSubItem.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "ColorFlyoutSubItem.h"
#include "Utils.h"

#include "ColorFlyoutSubItem.g.cpp"
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

using namespace winrt;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::System;
using namespace winrt::Windows::ApplicationModel::DataTransfer;
using namespace winrt::Windows::UI::Text;
using namespace winrt::Microsoft::Terminal;
using namespace winrt::Microsoft::Terminal::TerminalControl;
using namespace winrt::Microsoft::Terminal::TerminalConnection;
using namespace winrt::Microsoft::Terminal::Settings;
using namespace ::TerminalApp;

namespace winrt
{
namespace MUX = Microsoft::UI::Xaml;
using IInspectable = Windows::Foundation::IInspectable;
}

namespace winrt::ColorFlyoutSubItem::implementation
{
ColorFlyoutSubItem::ColorFlyoutSubItem() {}

ColorFlyoutSubItem::ColorFlyoutSubItem(std::shared_ptr<ScopedResourceLoader> resourceLoader)
{
InitializeComponent();

_resourceLoader = resourceLoader;
}

void ColorFlyoutSubItem::Create()
{
}
}
37 changes: 37 additions & 0 deletions src/cascadia/TerminalApp/ColorFlyoutSubItem.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#pragma once

#include "winrt/Microsoft.UI.Xaml.Controls.h"

#include "ColorFlyoutSubItem.g.h"
#include "ScopedResourceLoader.h"

#include <winrt/Microsoft.Terminal.TerminalControl.h>
#include <winrt/Microsoft.Terminal.TerminalConnection.h>
#include <winrt/Microsoft.UI.Xaml.Controls.Primitives.h>
#include <winrt/Windows.ApplicationModel.DataTransfer.h>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>

namespace winrt::ColorFlyoutSubItem::implementation
{
struct ColorFlyoutSubItem : ColorFlyoutSubItemT<ColorFlyoutSubItem>
{
public:
ColorFlyoutSubItem();

ColorFlyoutSubItem(std::shared_ptr<ScopedResourceLoader> resourceLoader);
void Create();

private:
std::shared_ptr<ScopedResourceLoader> _resourceLoader{ nullptr };
};
}

namespace winrt::TerminalApp::factory_implementation
{
struct ColorFlyoutSubItem : ColorFlyoutSubItemT<ColorFlyoutSubItem, implementation::ColorFlyoutSubItem>
{
};
}
11 changes: 11 additions & 0 deletions src/cascadia/TerminalApp/ColorFlyoutSubItem.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
import "..\App.idl";

//namespace TerminalApp
gbaychev marked this conversation as resolved.
Show resolved Hide resolved
//{
// [default_interface] runtimeclass ColorFlyoutSubItem : Windows.UI.Xaml.Controls.MenuFlyoutSubItem
// {
// ColorFlyoutSubItem();
// }
//}
13 changes: 13 additions & 0 deletions src/cascadia/TerminalApp/ColorFlyoutSubItem.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
the MIT License. See LICENSE in the project root for license information. -->
<Grid
x:Class="TerminalApp.ColorFlyoutSubItem"
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">

</Grid>
109 changes: 109 additions & 0 deletions src/cascadia/TerminalApp/ColorPickupFlyout.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
#include "pch.h"
#include "ColorPickupFlyout.h"
#include "ColorPickupFlyout.g.cpp"
#include "winrt/Windows.UI.Xaml.Media.h"
#include "winrt/Windows.UI.Xaml.Shapes.h"
#include "winrt/Windows.UI.Xaml.Interop.h"
#include <LibraryResources.h>

namespace winrt::TerminalApp::implementation
{
// Method Description:
// - Default constructor, localizes the buttons and hooks
// up the event fired by the custom color picker, so that
// the tab color is set on the fly when selecting a non-preset color
// Arguments:
// - <none>
ColorPickupFlyout::ColorPickupFlyout()
{
InitializeComponent();

auto okText = RS_(L"Ok");
auto customColorText = RS_(L"TabCustomColorChoose");
auto clearColorText = RS_(L"TabColorClear");

btnOk().Content(winrt::box_value(okText));
btnCustomColor().Content(winrt::box_value(customColorText));
btnClearColor().Content(winrt::box_value(clearColorText));

customColorPicker().ColorChanged([this](const auto&, const Windows::UI::Xaml::Controls::ColorChangedEventArgs& args) {
gbaychev marked this conversation as resolved.
Show resolved Hide resolved
_colorSelected(args.NewColor());
});
}

// Method Description:
// - Handler of the click event for the preset color swatches.
// Reads the color from the clicked rectangle and fires an event
// with the selected color. After that hides the flyout
// Arguments:
// - sender: the rectangle that got clicked
// Return Value:
// - <none>
void ColorPickupFlyout::ColorButton_Click(IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const&)
{
auto btn{ sender.as<Windows::UI::Xaml::Controls::Button>() };
auto rectangle{ btn.Content().as<Windows::UI::Xaml::Shapes::Rectangle>() };
auto rectClr{ rectangle.Fill().as<Windows::UI::Xaml::Media::SolidColorBrush>() };
_colorSelected(rectClr.Color());
Hide();
}

// Method Description:
// - Handler of the clear color button. Clears the current
// color of the tab, if any. Hides the flyout after that
// Arguments:
// - <none>
// Return Value:
// - <none>
void ColorPickupFlyout::ClearColorButton_Click(IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
{
_colorCleared();
Hide();
}

// Method Description:
// - Handler of the select custom color button. Expands or collapses the flyout
// to show the color picker. In order to accomplish this a FlyoutPresenterStyle is used,
// in which a Style is embedded, containing the desired width
// Arguments:
// - <none>
// Return Value:
// - <none>
void ColorPickupFlyout::ShowColorPickerButton_Click(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
{
auto targetType = this->FlyoutPresenterStyle().TargetType();
auto s = Windows::UI::Xaml::Style{};
s.TargetType(targetType);
auto visibility = customColorPanel().Visibility();
if (visibility == winrt::Windows::UI::Xaml::Visibility::Collapsed)
{
customColorPanel().Visibility(winrt::Windows::UI::Xaml::Visibility::Visible);
auto setter = Windows::UI::Xaml::Setter(Windows::UI::Xaml::FrameworkElement::MinWidthProperty(), winrt::box_value(540));
s.Setters().Append(setter);
}
else
{
customColorPanel().Visibility(winrt::Windows::UI::Xaml::Visibility::Collapsed);
auto setter = Windows::UI::Xaml::Setter(Windows::UI::Xaml::FrameworkElement::MinWidthProperty(), winrt::box_value(0));
s.Setters().Append(setter);
}
this->FlyoutPresenterStyle(s);
}

// Method Description:
// - Handles the color selection of the color pickup. Gets
// the currently selected color and fires an event with it
// Arguments:
// - <none>
// Return Value:
// - <none>
void ColorPickupFlyout::CustomColorButton_Click(Windows::Foundation::IInspectable const&, Windows::UI::Xaml::RoutedEventArgs const&)
{
auto color = customColorPicker().Color();
_colorSelected(color);
Hide();
}

DEFINE_EVENT(ColorPickupFlyout, ColorSelected, _colorSelected, TerminalApp::ColorSelectedArgs);
DEFINE_EVENT(ColorPickupFlyout, ColorCleared, _colorCleared, TerminalApp::ColorClearedArgs);
}
26 changes: 26 additions & 0 deletions src/cascadia/TerminalApp/ColorPickupFlyout.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "ColorPickupFlyout.g.h"
#include "../cascadia/inc/cppwinrt_utils.h"

namespace winrt::TerminalApp::implementation
{
struct ColorPickupFlyout : ColorPickupFlyoutT<ColorPickupFlyout>
{
ColorPickupFlyout();

void ColorButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
void ShowColorPickerButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
void CustomColorButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
void ClearColorButton_Click(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);

DECLARE_EVENT(ColorSelected, _colorSelected, TerminalApp::ColorSelectedArgs);
DECLARE_EVENT(ColorCleared, _colorCleared, TerminalApp::ColorClearedArgs);
};
}

namespace winrt::TerminalApp::factory_implementation
{
struct ColorPickupFlyout : ColorPickupFlyoutT<ColorPickupFlyout, implementation::ColorPickupFlyout>
{
};
}
12 changes: 12 additions & 0 deletions src/cascadia/TerminalApp/ColorPickupFlyout.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace TerminalApp
{
delegate void ColorSelectedArgs(Windows.UI.Color color);
delegate void ColorClearedArgs();

[default_interface] runtimeclass ColorPickupFlyout : Windows.UI.Xaml.Controls.Flyout
{
ColorPickupFlyout();
event ColorSelectedArgs ColorSelected;
event ColorClearedArgs ColorCleared;
}
}
Loading