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

Create a new page for "Add new profile" in the SUI #9352

Merged
36 commits merged into from
May 5, 2021
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
3402193
initial
PankajBhojwani Mar 3, 2021
7d94b5e
add new works
PankajBhojwani Mar 3, 2021
ff4971c
events
PankajBhojwani Mar 4, 2021
0fc1578
duplicate button
PankajBhojwani Mar 5, 2021
b3adf6b
works now
PankajBhojwani Mar 6, 2021
e4d1a02
okay now it works
PankajBhojwani Mar 6, 2021
c472b60
addressing comments
PankajBhojwani Mar 10, 2021
2b23b94
conflict
PankajBhojwani Mar 10, 2021
4326dd8
abstract, localize
PankajBhojwani Mar 10, 2021
9d9a733
nits
PankajBhojwani Mar 12, 2021
981dfdc
address comments
PankajBhojwani Mar 15, 2021
44dbab6
test
PankajBhojwani Mar 15, 2021
6e7f158
throw if null
PankajBhojwani Mar 22, 2021
b91af0c
nits, dynamic profile test
PankajBhojwani Mar 25, 2021
c4b165c
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Mar 31, 2021
0cd2739
dynamic
PankajBhojwani Mar 31, 2021
962fa05
line
PankajBhojwani Mar 31, 2021
5ed77c6
format
PankajBhojwani Apr 1, 2021
cd9373f
user defaults tag
PankajBhojwani Apr 2, 2021
6cc15fb
format
PankajBhojwani Apr 2, 2021
109e347
automation property, nits
PankajBhojwani Apr 7, 2021
7e5cd28
spaces
PankajBhojwani Apr 7, 2021
ad73ab6
comment
PankajBhojwani Apr 7, 2021
2b0416c
format
PankajBhojwani Apr 7, 2021
7a57a99
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 9, 2021
d24b425
appearance setting macro
PankajBhojwani Apr 12, 2021
dec8950
duplicate now includes unfocusedAppearance
PankajBhojwani Apr 12, 2021
2d31527
conflict
PankajBhojwani Apr 12, 2021
1b9bb9b
format
PankajBhojwani Apr 12, 2021
aa5e0d7
rename the create new button
PankajBhojwani Apr 26, 2021
51ec91c
check for user default profile settings before using it
PankajBhojwani Apr 26, 2021
2c31c87
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 26, 2021
db1358e
deduplication counter
PankajBhojwani Apr 28, 2021
62ff394
conflict
PankajBhojwani Apr 28, 2021
947efeb
Merge branch 'main' of https://github.com/microsoft/terminal into dev…
PankajBhojwani Apr 30, 2021
294d4e2
fix copy number
PankajBhojwani May 5, 2021
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
42 changes: 42 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

#include "pch.h"
#include "AddProfile.h"
#include "AddProfile.g.cpp"
#include "AddProfilePageNavigationState.g.cpp"
#include "EnumEntry.h"

using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::System;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::UI::Xaml::Navigation;
using namespace winrt::Microsoft::Terminal::Settings::Model;

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
AddProfile::AddProfile()
{
InitializeComponent();
}

void AddProfile::OnNavigatedTo(const NavigationEventArgs& e)
{
_State = e.Parameter().as<Editor::AddProfilePageNavigationState>();
DHowett marked this conversation as resolved.
Show resolved Hide resolved
}

void AddProfile::_AddNewClick(const IInspectable& /*sender*/,
const Windows::UI::Xaml::RoutedEventArgs& /*eventArgs*/)
{
_State.RequestAddNew();
}

void AddProfile::_DuplicateClick(const IInspectable& /*sender*/,
const Windows::UI::Xaml::RoutedEventArgs& /*eventArgs*/)
{
if (const auto selected = Profiles().SelectedItem())
{
_State.RequestDuplicate(selected.try_as<Model::Profile>().Guid());
}
}
}
52 changes: 52 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

#pragma once

#include "AddProfile.g.h"
#include "AddProfilePageNavigationState.g.h"
#include "Utils.h"

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
struct AddProfilePageNavigationState : AddProfilePageNavigationStateT<AddProfilePageNavigationState>
{
public:
AddProfilePageNavigationState(const Model::CascadiaSettings& settings) :
_Settings{ settings } {}

void RequestAddNew()
{
_AddNewHandlers(nullptr, nullptr);
}

void RequestDuplicate(GUID profile)
{
_AddNewHandlers(nullptr, winrt::box_value(profile));
}

GETSET_PROPERTY(Model::CascadiaSettings, Settings, nullptr)
TYPED_EVENT(AddNew, Windows::Foundation::IInspectable, Windows::Foundation::IInspectable);
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
};

struct AddProfile : AddProfileT<AddProfile>
{
public:
AddProfile();

void OnNavigatedTo(const winrt::Windows::UI::Xaml::Navigation::NavigationEventArgs& e);

GETSET_PROPERTY(Editor::AddProfilePageNavigationState, State, nullptr);

private:
friend struct AddProfileT<AddProfile>; // for Xaml to bind events

void _AddNewClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _DuplicateClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
};
}

namespace winrt::Microsoft::Terminal::Settings::Editor::factory_implementation
{
BASIC_FACTORY(AddProfile);
}
21 changes: 21 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.idl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

import "EnumEntry.idl";
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved

namespace Microsoft.Terminal.Settings.Editor
{
runtimeclass AddProfilePageNavigationState
{
Microsoft.Terminal.Settings.Model.CascadiaSettings Settings;
void RequestAddNew();
void RequestDuplicate(Guid profile);
event Windows.Foundation.TypedEventHandler<Object, Object> AddNew;
};

[default_interface] runtimeclass AddProfile : Windows.UI.Xaml.Controls.Page
{
AddProfile();
AddProfilePageNavigationState State { get; };
}
}
87 changes: 87 additions & 0 deletions src/cascadia/TerminalSettingsEditor/AddProfile.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under
the MIT License. See LICENSE in the project root for license information. -->
<Page
x:Class="Microsoft.Terminal.Settings.Editor.AddProfile"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Microsoft.Terminal.Settings.Editor"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:muxc="using:Microsoft.UI.Xaml.Controls"
xmlns:SettingsModel="using:Microsoft.Terminal.Settings.Model"
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
mc:Ignorable="d">

<Page.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="CommonResources.xaml"/>
</ResourceDictionary.MergedDictionaries>

<DataTemplate x:DataType="local:EnumEntry" x:Key="EnumRadioButtonTemplate">
<RadioButton Content="{x:Bind EnumName, Mode=OneWay}"/>
</DataTemplate>
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
<SettingsModel:IconPathConverter x:Key="IconSourceConverter"/>
</ResourceDictionary>
</Page.Resources>

<ScrollViewer>
<StackPanel Style="{StaticResource SettingsStackStyle}">
<Button x:Name="AddNewButton"
Click="_AddNewClick"
Style="{StaticResource AccentButtonStyle}">
<Button.Content>
<StackPanel Orientation="Horizontal">
<FontIcon Glyph="&#xE710;"
FontSize="{StaticResource StandardIconSize}"/>
<TextBlock x:Uid="AddProfile_AddNewButton"
Margin="10,0,0,0"/>
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
</StackPanel>
</Button.Content>
</Button>
<StackPanel Margin="{StaticResource StandardControlMargin}">
<local:SettingContainer x:Uid="AddProfile_Duplicate">
<muxc:RadioButtons ItemsSource="{x:Bind State.Settings.AllProfiles, Mode=OneWay}"
x:Name="Profiles">
<muxc:RadioButtons.ItemTemplate>
<DataTemplate x:DataType="SettingsModel:Profile">
<Grid HorizontalAlignment="Stretch" ColumnSpacing="8">

<Grid.ColumnDefinitions>
<!-- icon -->
<ColumnDefinition Width="16"/>
<!-- profile name -->
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>

<IconSourceElement
Grid.Column="0"
Width="16"
Height="16"
IconSource="{x:Bind Icon,
Mode=OneWay,
Converter={StaticResource IconSourceConverter}}"/>

<TextBlock Grid.Column="1"
Text="{x:Bind Name}"/>

</Grid>
</DataTemplate>
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
</muxc:RadioButtons.ItemTemplate>
</muxc:RadioButtons>
</local:SettingContainer>
<Button x:Name="DuplicateButton"
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
Click="_DuplicateClick"
Style="{StaticResource AccentButtonStyle}">
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
<Button.Content>
<StackPanel Orientation="Horizontal">
<FontIcon Glyph="&#xE710;"
FontSize="{StaticResource StandardIconSize}"/>
<TextBlock x:Uid="AddProfile_DuplicateButton"
Margin="10,0,0,0"/>
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
</StackPanel>
</Button.Content>
</Button>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Page>
79 changes: 52 additions & 27 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "Profiles.h"
#include "GlobalAppearance.h"
#include "ColorSchemes.h"
#include "AddProfile.h"
#include "..\types\inc\utils.hpp"

#include <LibraryResources.h>
Expand Down Expand Up @@ -123,8 +124,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// refresh the current page using the SelectedItem data we collected before the refresh
if (selectedItemTag)
{
const auto& selectedItemStringTag{ selectedItemTag.try_as<hstring>() };
const auto& selectedItemProfileTag{ selectedItemTag.try_as<ProfileViewModel>() };
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
for (const auto& item : menuItems)
{
if (const auto& menuItem{ item.try_as<MUX::Controls::NavigationViewItem>() })
Expand All @@ -133,22 +132,28 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
if (const auto& stringTag{ tag.try_as<hstring>() })
{
if (stringTag == selectedItemStringTag)
if (const auto& selectedItemStringTag{ selectedItemTag.try_as<hstring>() })
{
// found the one that was selected before the refresh
SettingsNav().SelectedItem(item);
_Navigate(*stringTag);
co_return;
if (stringTag == selectedItemStringTag)
{
// found the one that was selected before the refresh
SettingsNav().SelectedItem(item);
_Navigate(*stringTag);
co_return;
}
}
}
else if (const auto& profileTag{ tag.try_as<ProfileViewModel>() })
{
if (profileTag->Guid() == selectedItemProfileTag->Guid())
if (const auto& selectedItemProfileTag{ selectedItemTag.try_as<ProfileViewModel>() })
{
// found the one that was selected before the refresh
SettingsNav().SelectedItem(item);
_Navigate(*profileTag);
co_return;
if (profileTag->Guid() == selectedItemProfileTag->Guid())
{
// found the one that was selected before the refresh
SettingsNav().SelectedItem(item);
_Navigate(*profileTag);
co_return;
}
}
}
}
Expand Down Expand Up @@ -223,18 +228,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

if (const auto navString = clickedItemContainer.Tag().try_as<hstring>())
{
if (navString == addProfileTag)
{
// "AddProfile" needs to create a new profile before we can navigate to it
uint32_t insertIndex;
SettingsNav().MenuItems().IndexOf(clickedItemContainer, insertIndex);
_CreateAndNavigateToNewProfile(insertIndex);
}
else
{
// Otherwise, navigate to the page
_Navigate(*navString);
}
_Navigate(*navString);
}
else if (const auto profile = clickedItemContainer.Tag().try_as<Editor::ProfileViewModel>())
{
Expand Down Expand Up @@ -288,6 +282,30 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
contentFrame().Navigate(xaml_typename<Editor::GlobalAppearance>(), winrt::make<GlobalAppearancePageNavigationState>(_settingsClone.GlobalSettings()));
}
else if (clickedItemTag == addProfileTag)
{
auto addProfileState{ winrt::make<AddProfilePageNavigationState>(_settingsClone) };
addProfileState.AddNew([weakThis = get_weak()](auto&&, auto&& profileGuid) {
if (auto self{ weakThis.get() })
{
uint32_t insertIndex;
auto selectedItem{ self->SettingsNav().SelectedItem() };
auto menuItems{ self->SettingsNav().MenuItems() };
menuItems.IndexOf(selectedItem, insertIndex);
if (profileGuid)
{
const auto profile = self->_settingsClone.FindProfile(winrt::unbox_value<GUID>(profileGuid));
const auto duplicated = self->_settingsClone.DuplicateProfile(profile);
self->_CreateAndNavigateToNewProfile(insertIndex, duplicated);
}
else
{
self->_CreateAndNavigateToNewProfile(insertIndex, nullptr);
}
}
});
contentFrame().Navigate(xaml_typename<Editor::AddProfile>(), addProfileState);
}
}

// Method Description:
Expand Down Expand Up @@ -355,7 +373,6 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
MUX::Controls::NavigationViewItem addProfileItem;
addProfileItem.Content(box_value(RS_(L"Nav_AddNewProfile/Content")));
addProfileItem.Tag(box_value(addProfileTag));
addProfileItem.SelectsOnInvoked(false);

FontIcon icon;
// This is the "Add" symbol
Expand All @@ -365,9 +382,17 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
SettingsNav().MenuItems().Append(addProfileItem);
}

void MainPage::_CreateAndNavigateToNewProfile(const uint32_t index)
void MainPage::_CreateAndNavigateToNewProfile(const uint32_t index, const Model::Profile profile)
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
{
const auto newProfile{ _settingsClone.CreateNewProfile() };
Model::Profile newProfile;
if (profile)
{
newProfile = profile;
}
else
{
newProfile = _settingsClone.CreateNewProfile();
}
PankajBhojwani marked this conversation as resolved.
Show resolved Hide resolved
const auto profileViewModel{ _viewModelForProfile(newProfile) };
const auto navItem{ _CreateProfileNavViewItem(profileViewModel) };
SettingsNav().MenuItems().InsertAt(index, navItem);
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsEditor/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
std::optional<HWND> _hostingHwnd;

void _InitializeProfilesList();
void _CreateAndNavigateToNewProfile(const uint32_t index);
void _CreateAndNavigateToNewProfile(const uint32_t index, const Model::Profile profile);
winrt::Microsoft::UI::Xaml::Controls::NavigationViewItem _CreateProfileNavViewItem(const Editor::ProfileViewModel& profile);
void _DeleteProfile(const Windows::Foundation::IInspectable sender, const Editor::DeleteProfileEventArgs& args);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@
<ClInclude Include="Actions.h">
<DependentUpon>Actions.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="AddProfile.h">
<DependentUpon>AddProfile.xaml</DependentUpon>
</ClInclude>
<ClInclude Include="ColorToBrushConverter.h">
<DependentUpon>Converters.idl</DependentUpon>
</ClInclude>
Expand Down Expand Up @@ -105,6 +108,9 @@
<Page Include="Actions.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="AddProfile.xaml">
<SubType>Designer</SubType>
</Page>
<Page Include="CommonResources.xaml">
<SubType>Designer</SubType>
</Page>
Expand Down Expand Up @@ -138,6 +144,9 @@
<ClCompile Include="Actions.cpp">
<DependentUpon>Actions.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="AddProfile.cpp">
<DependentUpon>AddProfile.xaml</DependentUpon>
</ClCompile>
<ClCompile Include="ColorToBrushConverter.cpp">
<DependentUpon>Converters.idl</DependentUpon>
</ClCompile>
Expand Down Expand Up @@ -206,6 +215,10 @@
<DependentUpon>Actions.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="AddProfile.idl">
<DependentUpon>AddProfile.xaml</DependentUpon>
<SubType>Code</SubType>
</Midl>
<Midl Include="Converters.idl" />
<Midl Include="EnumEntry.idl" />
<Midl Include="GlobalAppearance.idl">
Expand Down
Loading