mirror of
https://github.com/Microsoft/calculator.git
synced 2025-08-22 22:23:29 -07:00
Clean up
This commit is contained in:
parent
75a08a01fd
commit
957859e393
5 changed files with 146 additions and 134 deletions
|
@ -70,21 +70,26 @@ App::App()
|
|||
this->HighContrastAdjustment = ApplicationHighContrastAdjustment::None;
|
||||
|
||||
this->Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
|
||||
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"restartApp", nullptr);
|
||||
|
||||
auto value = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||
auto DefaultTheme = ref new Windows::UI::ViewManagement::UISettings();
|
||||
auto uiTheme = DefaultTheme->GetColorValue(Windows::UI::ViewManagement::UIColorType::Background).ToString();
|
||||
|
||||
if (value != nullptr)
|
||||
{
|
||||
String ^ colorSetting = safe_cast<String ^>(value);
|
||||
|
||||
// Apply theme choice.
|
||||
if (colorSetting == L"Dark")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||
}
|
||||
else if (colorSetting == L"Light")
|
||||
if (colorSetting == L"Light")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Light;
|
||||
}
|
||||
else if (colorSetting == L"Dark")
|
||||
{
|
||||
App::Current->RequestedTheme = ApplicationTheme::Dark;
|
||||
}
|
||||
else if (colorSetting == L"System")
|
||||
{
|
||||
if (uiTheme == "#FF000000")
|
||||
|
@ -98,6 +103,7 @@ App::App()
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#if _DEBUG
|
||||
this->DebugSettings->IsBindingTracingEnabled = true;
|
||||
this->DebugSettings->BindingFailed += ref new BindingFailedEventHandler([](_In_ Object ^ /*sender*/, _In_ BindingFailedEventArgs ^ e) {
|
||||
|
|
|
@ -4735,7 +4735,7 @@
|
|||
<comment>Text for the "Settings" header</comment>
|
||||
</data>
|
||||
<data name="SettingsContribute" xml:space="preserve">
|
||||
<value>To learn how you can contribute to Windows Calculator, visit the project on %HL%GitHub%HL%.</value>
|
||||
<comment>{Locked="%HL%GitHub%HL%"}</comment>
|
||||
<value>To learn how you can contribute to Windows Calculator, visit the project on%HL%GitHub%HL%.</value>
|
||||
<comment>{Locked="%HL%GitHub%HL%"}. GitHub link, displayed on the settings page.</comment>
|
||||
</data>
|
||||
</root>
|
|
@ -1,7 +1,6 @@
|
|||
<Page x:Class="CalculatorApp.SettingsPage"
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:Windows10version1809="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract, 7)"
|
||||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
|
||||
xmlns:local="using:CalculatorApp"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
|
@ -37,14 +36,8 @@
|
|||
|
||||
<Button x:Name="BackButton"
|
||||
x:Uid="BackButton"
|
||||
HorizontalAlignment="Stretch"
|
||||
VerticalAlignment="Stretch"
|
||||
Background="{ThemeResource AppChromeAcrylicHostBackdropMediumLowBrush}"
|
||||
FontFamily="Segoe MDL2 Assets"
|
||||
FontSize="15"
|
||||
Windows10version1809:CornerRadius="0"
|
||||
Click="BackButtonClick"
|
||||
Content=""/>
|
||||
Style="{StaticResource NavigationBackButtonNormalStyle}"
|
||||
Click="BackButtonClick"/>
|
||||
|
||||
<TextBlock x:Uid="SettingsHeader"
|
||||
Grid.Column="1"
|
||||
|
@ -67,23 +60,23 @@
|
|||
|
||||
<RadioButton x:Name="SettingsLightTheme"
|
||||
x:Uid="SettingsLightTheme"
|
||||
Grid.Row="3"
|
||||
Checked="LightChecked"/>
|
||||
Checked="ThemeChecked"
|
||||
Tag="Light"/>
|
||||
|
||||
<RadioButton x:Name="SettingsDarkTheme"
|
||||
x:Uid="SettingsDarkTheme"
|
||||
Grid.Row="2"
|
||||
Checked="DarkChecked"/>
|
||||
Checked="ThemeChecked"
|
||||
Tag="Dark"/>
|
||||
|
||||
<RadioButton x:Name="SettingsSystemTheme"
|
||||
x:Uid="SettingsSystemTheme"
|
||||
Grid.Row="4"
|
||||
Checked="SystemChecked"/>
|
||||
Checked="ThemeChecked"
|
||||
Tag="System"/>
|
||||
|
||||
|
||||
<TextBlock x:Name="SettingsRestartApp"
|
||||
Style="{StaticResource CaptionTextBlockStyle}"
|
||||
Foreground="{StaticResource SystemColorGrayTextColor}"/>
|
||||
Foreground="{StaticResource SystemBaseMediumColor}"/>
|
||||
|
||||
<HyperlinkButton x:Name="ColorSettingsButton"
|
||||
Margin="0,-2"
|
||||
|
@ -141,13 +134,12 @@
|
|||
Style="{StaticResource ButtonRevealStyle}"
|
||||
Click="SettingsFeedbackButtonClick"/>
|
||||
|
||||
<RichTextBlock x:Name="SettingsContribute"
|
||||
<TextBlock x:Name="SettingsContribute"
|
||||
Margin="0,12,12,6"
|
||||
HorizontalAlignment="Left"
|
||||
Style="{ThemeResource BodyTextBlockStyle}"
|
||||
Foreground="{ThemeResource SystemControlPageTextBaseHighBrush}"
|
||||
Style="{ThemeResource BodyRichTextBlockStyle}"
|
||||
TextWrapping="Wrap">
|
||||
<Paragraph>
|
||||
<Run x:Name="ContributeRunBeforeLink"/>
|
||||
<Hyperlink NavigateUri="https://go.microsoft.com/fwlink/?linkid=2099939"
|
||||
TextDecorations="None"
|
||||
|
@ -155,8 +147,7 @@
|
|||
<Run x:Name="ContributeRunLink"/>
|
||||
</Hyperlink>
|
||||
<Run x:Name="ContributeRunAfterLink"/>
|
||||
</Paragraph>
|
||||
</RichTextBlock>
|
||||
</TextBlock>
|
||||
</StackPanel>
|
||||
</StackPanel>
|
||||
</Grid>
|
||||
|
|
|
@ -25,48 +25,65 @@ using namespace winrt::Windows::Storage;
|
|||
#define BUILD_YEAR 2021
|
||||
#endif
|
||||
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
auto themevalue = Windows::Storage::ApplicationData::Current -> LocalSettings -> Values -> Lookup(L"themeSetting");
|
||||
String ^ colorSetting = safe_cast<String ^>(themevalue);
|
||||
|
||||
SettingsPage::SettingsPage()
|
||||
{
|
||||
auto locService = LocalizationService::GetInstance();
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
auto themevalue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"themeSetting");
|
||||
auto restartValue = Windows::Storage::ApplicationData::Current->LocalSettings->Values->Lookup(L"restartApp");
|
||||
String ^ colorSetting = safe_cast<String ^>(themevalue);
|
||||
String ^ restartApp = safe_cast<String ^>(restartValue);
|
||||
|
||||
InitializeComponent();
|
||||
|
||||
Language = locService->GetLanguage();
|
||||
|
||||
this->SetVersionString();
|
||||
this->SetCopyrightString();
|
||||
|
||||
this->InitializeContributeTextBlock();
|
||||
SettingsLightTheme->Focus(::FocusState::Keyboard);
|
||||
|
||||
if (themevalue != nullptr)
|
||||
{
|
||||
if (colorSetting == L"Dark")
|
||||
{
|
||||
SettingsDarkTheme->IsChecked = true;
|
||||
}
|
||||
else if (colorSetting == L"Light")
|
||||
if (colorSetting == L"Light")
|
||||
{
|
||||
SettingsLightTheme->IsChecked = true;
|
||||
m_currentTheme = "Light";
|
||||
}
|
||||
else if (colorSetting == L"Dark")
|
||||
{
|
||||
SettingsDarkTheme->IsChecked = true;
|
||||
m_currentTheme = "Dark";
|
||||
}
|
||||
else if (colorSetting == L"System")
|
||||
{
|
||||
SettingsSystemTheme->IsChecked = true;
|
||||
m_currentTheme = "System";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsSystemTheme->IsChecked = true;
|
||||
m_currentTheme = "System";
|
||||
}
|
||||
|
||||
InitializeContributeTextBlock();
|
||||
if (restartValue != nullptr)
|
||||
{
|
||||
if (restartApp == L"True")
|
||||
{
|
||||
SettingsRestartApp->Visibility = ::Visibility::Visible;
|
||||
}
|
||||
else if (restartApp == L"False")
|
||||
{
|
||||
SettingsRestartApp->Visibility = ::Visibility::Collapsed;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsRestartApp->Visibility = ::Visibility::Collapsed;
|
||||
}
|
||||
}
|
||||
|
||||
void SettingsPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e)
|
||||
{
|
||||
MainPage ^ mainPage = (MainPage ^) e->Parameter;
|
||||
MainPage ^ mainPage = dynamic_cast<MainPage ^> (e->Parameter);
|
||||
if (mainPage != nullptr)
|
||||
{
|
||||
MainPageProperty = mainPage;
|
||||
|
@ -75,6 +92,7 @@ void SettingsPage::OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventA
|
|||
|
||||
void SettingsPage::InitializeContributeTextBlock()
|
||||
{
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
std::wstring contributeHyperlinkText = resourceLoader->GetResourceString(L"SettingsContribute")->Data();
|
||||
|
||||
// The resource string has '%HL%' wrapped around 'GitHub'
|
||||
|
@ -83,9 +101,9 @@ void SettingsPage::InitializeContributeTextBlock()
|
|||
static const size_t delimiterLength{ delimiter.length() };
|
||||
|
||||
// Find the delimiters.
|
||||
size_t firstSplitPosition = contributeHyperlinkText .find(delimiter, 0);
|
||||
size_t firstSplitPosition = contributeHyperlinkText.find(delimiter, 0);
|
||||
assert(firstSplitPosition != std::wstring::npos);
|
||||
size_t secondSplitPosition = contributeHyperlinkText .find(delimiter, firstSplitPosition + 1);
|
||||
size_t secondSplitPosition = contributeHyperlinkText.find(delimiter, firstSplitPosition + 1);
|
||||
assert(secondSplitPosition != std::wstring::npos);
|
||||
size_t hyperlinkTextLength = secondSplitPosition - (firstSplitPosition + delimiterLength);
|
||||
|
||||
|
@ -102,6 +120,14 @@ void SettingsPage::InitializeContributeTextBlock()
|
|||
|
||||
void SettingsPage::BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
{
|
||||
if (SettingsRestartApp->Visibility == ::Visibility::Visible)
|
||||
{
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"restartApp", L"True");
|
||||
}
|
||||
else
|
||||
{
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"restartApp", L"False");
|
||||
}
|
||||
MainPageProperty->CollapseSettings();
|
||||
}
|
||||
|
||||
|
@ -115,6 +141,8 @@ void SettingsPage::SetVersionString()
|
|||
|
||||
void SettingsPage::SetCopyrightString()
|
||||
{
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
|
||||
auto copyrightText = LocalizationStringUtil::GetLocalizedString(resourceLoader->GetResourceString("SettingsCopyright"), StringReference(to_wstring(BUILD_YEAR).c_str()));
|
||||
|
||||
SettingsCopyright->Text = copyrightText;
|
||||
|
@ -134,44 +162,32 @@ void SettingsPage::SettingsFeedbackButtonClick(_In_ Object ^ sender, _In_ Routed
|
|||
Launcher::LaunchUriAsync(ref new Uri("windows-feedback:?contextid=130&metadata=%7B%22Metadata%22:[%7B%22AppBuild%22:%22" + versionNumber + "%22%7D]%7D"));
|
||||
}
|
||||
|
||||
void SettingsPage::LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
void SettingsPage::ThemeChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
{
|
||||
if (colorSetting == "Light")
|
||||
auto resourceLoader = AppResourceProvider::GetInstance();
|
||||
RadioButton ^ radioButton = safe_cast<RadioButton ^>(sender);
|
||||
String ^ tag = radioButton->Tag->ToString();
|
||||
|
||||
if (m_currentTheme == tag)
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
||||
SettingsRestartApp->Visibility = ::Visibility::Collapsed;
|
||||
}
|
||||
else
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||
SettingsRestartApp->Visibility = ::Visibility::Visible;
|
||||
SettingsRestartApp->Text = resourceLoader->GetResourceString("SettingsRestartNotice");
|
||||
}
|
||||
|
||||
if (tag == "Light")
|
||||
{
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Light.ToString());
|
||||
}
|
||||
|
||||
void SettingsPage::DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
{
|
||||
if (colorSetting == "Dark")
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
||||
}
|
||||
else
|
||||
else if (tag == "Dark")
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||
SettingsRestartApp->Text = resourceLoader->GetResourceString("SettingsRestartNotice");
|
||||
}
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", ApplicationTheme::Dark.ToString());
|
||||
}
|
||||
|
||||
void SettingsPage::SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e)
|
||||
{
|
||||
if (colorSetting == "System")
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Collapsed;
|
||||
}
|
||||
else
|
||||
else if (tag == "System")
|
||||
{
|
||||
SettingsRestartApp->Visibility = Windows::UI::Xaml::Visibility::Visible;
|
||||
SettingsRestartApp->Text = resourceLoader->GetResourceString("SettingsRestartNotice");
|
||||
}
|
||||
Windows::Storage::ApplicationData::Current->LocalSettings->Values->Insert(L"themeSetting", L"System");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,14 +19,13 @@ namespace CalculatorApp
|
|||
virtual void OnNavigatedTo(Windows::UI::Xaml::Navigation::NavigationEventArgs ^ e) override;
|
||||
|
||||
private:
|
||||
Platform::String ^ m_currentTheme;
|
||||
void InitializeContributeTextBlock();
|
||||
void BackButtonClick(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void ColorSettingsButtonClicked(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SettingsFeedbackButtonClick(_In_ Platform::Object ^ sender, _In_ Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SetVersionString();
|
||||
void SetCopyrightString();
|
||||
void LightChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void DarkChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void SystemChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
void ThemeChecked(Platform::Object ^ sender, Windows::UI::Xaml::RoutedEventArgs ^ e);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue