Skip to content

Commit

Permalink
update SUI after settings changes are made
Browse files Browse the repository at this point in the history
  • Loading branch information
carlos-zamora committed Nov 23, 2020
1 parent 1442661 commit 23f08e8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 3 deletions.
72 changes: 70 additions & 2 deletions src/cascadia/TerminalSettingsEditor/MainPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,77 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
_InitializeProfilesList();
}

void MainPage::UpdateSettings(Model::CascadiaSettings settings)
fire_and_forget MainPage::UpdateSettings(Model::CascadiaSettings settings)
{
_settingsSource = settings;
_settingsClone = settings.Copy();

co_await winrt::resume_foreground(Dispatcher());

// reconstruct our list of profiles
auto menuItems{ SettingsNav().MenuItems() };
unsigned int i = 0;
while (i < menuItems.Size())
{
if (const auto navViewItem{ menuItems.GetAt(i).try_as<MUX::Controls::NavigationViewItem>() })
{
const auto tag{ navViewItem.Tag() };
if (tag.try_as<Model::Profile>())
{
// remove NavViewItem pointing to a Profile
menuItems.RemoveAt(i);
continue;
}
else if (const auto stringTag{ tag.try_as<hstring>() })
{
if (stringTag == addProfileTag)
{
// remove NavViewItem pointing to "Add Profile"
menuItems.RemoveAt(i);
continue;
}
}
}
++i;
}
_InitializeProfilesList();

_RefreshCurrentPage();
}

void MainPage::_RefreshCurrentPage()
{
auto navigationMenu{ SettingsNav() };
if (const auto selectedItem{ navigationMenu.SelectedItem() })
{
if (const auto tag{ selectedItem.as<MUX::Controls::NavigationViewItem>().Tag() })
{
if (const auto profile{ tag.try_as<Model::Profile>() })
{
// check if the profile still exists
if (_settingsClone.FindProfile(profile.Guid()))
{
// Navigate to the page with the given profile
contentFrame().Navigate(xaml_typename<Editor::Profiles>(), winrt::make<ProfilePageNavigationState>(profile, _settingsClone.GlobalSettings().ColorSchemes()));
return;
}
}
else if (const auto stringTag{ tag.try_as<hstring>() })
{
// navigate to the page with this tag
_Navigate(*stringTag);
return;
}
}
}

// could not find the page we were on, fallback to first menu item
const auto firstItem{ navigationMenu.MenuItems().GetAt(0) };
navigationMenu.SelectedItem(firstItem);
if (const auto tag{ navigationMenu.SelectedItem().as<NavigationViewItem>().Tag() })
{
_Navigate(unbox_value<hstring>(tag));
}
}

// Function Description:
Expand Down Expand Up @@ -164,6 +231,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
void MainPage::ResetButton_Click(IInspectable const& /*sender*/, RoutedEventArgs const& /*args*/)
{
_settingsClone = _settingsSource.Copy();
_RefreshCurrentPage();
}

void MainPage::_InitializeProfilesList()
Expand All @@ -181,7 +249,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
// Top off (the end of the nav view) with the Add Profile item
MUX::Controls::NavigationViewItem addProfileItem;
addProfileItem.Content(box_value(RS_(L"Nav_AddNewProfile/Content")));
addProfileItem.Tag(box_value(L"AddProfile"));
addProfileItem.Tag(box_value(addProfileTag));
addProfileItem.SelectsOnInvoked(false);

FontIcon icon;
Expand Down
3 changes: 2 additions & 1 deletion src/cascadia/TerminalSettingsEditor/MainPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
MainPage() = delete;
MainPage(const Model::CascadiaSettings& settings);

void UpdateSettings(Model::CascadiaSettings settings);
fire_and_forget UpdateSettings(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);
Expand All @@ -34,6 +34,7 @@ namespace winrt::Microsoft::Terminal::Settings::Editor::implementation
winrt::Microsoft::UI::Xaml::Controls::NavigationViewItem _CreateProfileNavViewItem(const Model::Profile& profile);

void _Navigate(hstring clickedItemTag);
void _RefreshCurrentPage();
};
}

Expand Down

0 comments on commit 23f08e8

Please sign in to comment.