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

Hook up the Settings UI JSON button #8059

Merged
5 commits merged into from
Oct 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/cascadia/TerminalApp/SettingsTab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ namespace winrt

namespace winrt::TerminalApp::implementation
{
SettingsTab::SettingsTab(winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings settings)
SettingsTab::SettingsTab(winrt::Microsoft::Terminal::Settings::Editor::MainPage settingsUI)
{
Content(winrt::Microsoft::Terminal::Settings::Editor::MainPage(settings));
Content(settingsUI);

_MakeTabViewItem();
_CreateContextMenu();
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/TerminalApp/SettingsTab.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ namespace winrt::TerminalApp::implementation
struct SettingsTab : SettingsTabT<SettingsTab>
{
public:
SettingsTab(winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings settings);
SettingsTab(winrt::Microsoft::Terminal::Settings::Editor::MainPage settingsUI);
void Focus(winrt::Windows::UI::Xaml::FocusState focusState);
winrt::Windows::UI::Xaml::FocusState FocusState() const noexcept;

Expand Down
10 changes: 9 additions & 1 deletion src/cascadia/TerminalApp/TerminalPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2587,7 +2587,15 @@ namespace winrt::TerminalApp::implementation
// If we're holding the settings tab's switch command, don't create a new one, switch to the existing one.
if (!_switchToSettingsCommand)
{
auto newTabImpl = winrt::make_self<SettingsTab>(_settings);
winrt::Microsoft::Terminal::Settings::Editor::MainPage sui{ _settings };
sui.OpenJson([weakThis{ get_weak() }](auto&& /*s*/, winrt::Microsoft::Terminal::Settings::Model::SettingsTarget e) {
leonMSFT marked this conversation as resolved.
Show resolved Hide resolved
if (auto page{ weakThis.get() })
{
page->_LaunchSettings(e);
}
});

auto newTabImpl = winrt::make_self<SettingsTab>(sui);
_MakeSwitchToTabCommand(*newTabImpl, _tabs.Size());

// Add the new tab to the list of our tabs.
Expand Down
23 changes: 23 additions & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ namespace winrt
using namespace winrt::Windows::Foundation;
using namespace winrt::Windows::UI::Xaml;
using namespace winrt::Microsoft::Terminal::Settings::Model;
using namespace winrt::Windows::UI::Core;
using namespace winrt::Windows::System;

namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
{
Expand Down Expand Up @@ -236,4 +238,25 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
contentFrame.Navigate(xaml_typename<Editor::Keybindings>());
}
}

void MainPage::OpenJsonTapped(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& /*args*/)
{
const CoreWindow window = CoreWindow::GetForCurrentThread();
const auto rAltState = window.GetKeyState(VirtualKey::RightMenu);
const auto lAltState = window.GetKeyState(VirtualKey::LeftMenu);
const bool altPressed = WI_IsFlagSet(lAltState, CoreVirtualKeyStates::Down) ||
WI_IsFlagSet(rAltState, CoreVirtualKeyStates::Down);

const auto target = altPressed ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
_OpenJsonHandlers(nullptr, target);
}

void MainPage::OpenJsonKeyDown(IInspectable const& /*sender*/, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& args)
{
if (args.Key() == VirtualKey::Enter || args.Key() == VirtualKey::Space)
{
const auto target = args.KeyStatus().IsMenuKeyDown ? SettingsTarget::DefaultsFile : SettingsTarget::SettingsFile;
_OpenJsonHandlers(nullptr, target);
}
}
}
4 changes: 4 additions & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
MainPage() = delete;
MainPage(winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings settings);

void OpenJsonKeyDown(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::KeyRoutedEventArgs const& args);
void OpenJsonTapped(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::Input::TappedRoutedEventArgs const& args);
void SettingsNav_Loaded(Windows::Foundation::IInspectable const& sender, Windows::UI::Xaml::RoutedEventArgs const& args);
void SettingsNav_ItemInvoked(Microsoft::UI::Xaml::Controls::NavigationView const& sender, Microsoft::UI::Xaml::Controls::NavigationViewItemInvokedEventArgs const& args);
void SettingsNav_BackRequested(Microsoft::UI::Xaml::Controls::NavigationView const&, Microsoft::UI::Xaml::Controls::NavigationViewBackRequestedEventArgs const& args);
Expand All @@ -28,6 +30,8 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation

static winrt::Microsoft::Terminal::Settings::Model::CascadiaSettings Settings();

TYPED_EVENT(OpenJson, winrt::Windows::Foundation::IInspectable, winrt::Microsoft::Terminal::Settings::Model::SettingsTarget);

private:
// XAML should data-bind to the _settingsClone
// When "save" is pressed, _settingsSource = _settingsClone
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/MainPage.idl
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ namespace Microsoft.Terminal.Settings.Editor
runtimeclass MainPage : Windows.UI.Xaml.Controls.Page
{
MainPage(Microsoft.Terminal.Settings.Model.CascadiaSettings settings);
event Windows.Foundation.TypedEventHandler<Object, Microsoft.Terminal.Settings.Model.SettingsTarget> OpenJson;
}
}
2 changes: 1 addition & 1 deletion src/cascadia/TerminalSettingsEditor/MainPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ the MIT License. See LICENSE in the project root for license information. -->

</muxc:NavigationView.MenuItems>
<muxc:NavigationView.PaneFooter>
<muxc:NavigationViewItem x:Uid="Nav_OpenJSON">
<muxc:NavigationViewItem x:Uid="Nav_OpenJSON" Tapped="OpenJsonTapped" KeyDown="OpenJsonKeyDown">
<muxc:NavigationViewItem.Icon>
<FontIcon Glyph="&#xE713;" />
</muxc:NavigationViewItem.Icon>
Expand Down
1 change: 1 addition & 0 deletions src/cascadia/TerminalSettingsEditor/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <winrt/Windows.Storage.Pickers.h>

#include <winrt/Windows.UI.h>
#include <winrt/Windows.UI.Core.h>
#include <winrt/Windows.UI.Input.h>
#include <winrt/Windows.UI.Popups.h>
#include <winrt/Windows.UI.Xaml.h>
Expand Down