Skip to content

Commit

Permalink
Add an about dialog with the version number (#1196)
Browse files Browse the repository at this point in the history
* Add an about dialog with the version number
  • Loading branch information
zadjii-msft committed Jun 12, 2019
1 parent e60af3b commit e20dfb8
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 21 deletions.
6 changes: 6 additions & 0 deletions src/cascadia/CascadiaPackage/Resources/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,10 @@
<data name="AppNameDev" xml:space="preserve">
<value>Windows Terminal (Dev Build)</value>
</data>
<data name="AboutTitleText" xml:space="preserve">
<value>About</value>
</data>
<data name="VersionLabelText" xml:space="preserve">
<value>Version:</value>
</data>
</root>
100 changes: 83 additions & 17 deletions src/cascadia/TerminalApp/App.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@

#include "pch.h"
#include "App.h"
#include <shellapi.h>
#include <filesystem>
#include <winrt/Microsoft.UI.Xaml.XamlTypeInfo.h>
#include <winrt/Windows.ApplicationModel.Resources.h>

#include "App.g.cpp"

Expand Down Expand Up @@ -177,15 +174,18 @@ namespace winrt::TerminalApp::implementation
}

// Method Description:
// - Show a ContentDialog with a single "Ok" button to dismiss. Looks up the
// the title and text from our Resources using the provided keys.
// - Show a ContentDialog with a single button to dismiss. Uses the
// FrameworkElements provided as the title and content of this dialog, and
// displays a single button to dismiss.
// - Only one dialog can be visible at a time. If another dialog is visible
// when this is called, nothing happens.
// Arguments:
// - titleKey: The key to use to lookup the title text from our resources.
// - contentKey: The key to use to lookup the content text from our resources.
fire_and_forget App::_ShowOkDialog(const winrt::hstring& titleKey,
const winrt::hstring& contentKey)
// - titleElement: the element to use as the title of this ContentDialog
// - contentElement: the element to use as the content of this ContentDialog
// - closeButtonText: The string to use on the close button
fire_and_forget App::_ShowDialog(const IInspectable& titleElement,
const IInspectable& contentElement,
const winrt::hstring& closeButtonText)
{
// DON'T release this lock in a wil::scope_exit. The scope_exit will get
// called when we await, which is not what we want.
Expand All @@ -196,15 +196,10 @@ namespace winrt::TerminalApp::implementation
return;
}

auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
auto title = resourceLoader.GetString(titleKey);
auto message = resourceLoader.GetString(contentKey);
auto buttonText = resourceLoader.GetString(L"Ok");

Controls::ContentDialog dialog;
dialog.Title(winrt::box_value(title));
dialog.Content(winrt::box_value(message));
dialog.CloseButtonText(buttonText);
dialog.Title(titleElement);
dialog.Content(contentElement);
dialog.CloseButtonText(closeButtonText);

// IMPORTANT: Add the dialog to the _root UIElement before you show it,
// so it knows how to attach to the XAML content.
Expand All @@ -217,6 +212,54 @@ namespace winrt::TerminalApp::implementation
// be released so another can be shown.
}

// Method Description:
// - Show a ContentDialog with a single "Ok" button to dismiss. Looks up the
// the title and text from our Resources using the provided keys.
// - Only one dialog can be visible at a time. If another dialog is visible
// when this is called, nothing happens. See _ShowDialog for details
// Arguments:
// - titleKey: The key to use to lookup the title text from our resources.
// - contentKey: The key to use to lookup the content text from our resources.
void App::_ShowOkDialog(const winrt::hstring& titleKey,
const winrt::hstring& contentKey)
{
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
auto title = resourceLoader.GetString(titleKey);
auto message = resourceLoader.GetString(contentKey);
auto buttonText = resourceLoader.GetString(L"Ok");

_ShowDialog(winrt::box_value(title), winrt::box_value(message), buttonText);
}

// Method Description:
// - Show a dialog with "About" information. Displays the app's Display
// Name, and the version.
void App::_ShowAboutDialog()
{
auto resourceLoader = Windows::ApplicationModel::Resources::ResourceLoader::GetForCurrentView();
const auto title = resourceLoader.GetString(L"AboutTitleText");
const auto versionLabel = resourceLoader.GetString(L"VersionLabelText");
const auto package = winrt::Windows::ApplicationModel::Package::Current();
const auto packageName = package.DisplayName();
const auto version = package.Id().Version();
std::wstringstream aboutTextStream;

// Format our about text. It will look like the following:
// <Display Name>
// Version: <Major>.<Minor>.<Build>.<Revision>

aboutTextStream << packageName.c_str() << L"\n";

aboutTextStream << versionLabel.c_str() << L" ";
aboutTextStream << version.Major << L"." << version.Minor << L"." << version.Build << L"." << version.Revision;

winrt::hstring aboutText{ aboutTextStream.str() };

const auto buttonText = resourceLoader.GetString(L"Ok");

_ShowDialog(winrt::box_value(title), winrt::box_value(aboutText), buttonText);
}

// Method Description:
// - Triggered when the application is fiished loading. If we failed to load
// the settings, then this will display the error dialog. This is done
Expand Down Expand Up @@ -360,6 +403,17 @@ namespace winrt::TerminalApp::implementation

feedbackFlyout.Click({ this, &App::_FeedbackButtonOnClick });
newTabFlyout.Items().Append(feedbackFlyout);

// Create the about button.
auto aboutFlyout = Controls::MenuFlyoutItem{};
aboutFlyout.Text(L"About");

Controls::SymbolIcon aboutIco{};
aboutIco.Symbol(Controls::Symbol::Help);
aboutFlyout.Icon(aboutIco);

aboutFlyout.Click({ this, &App::_AboutButtonOnClick });
newTabFlyout.Items().Append(aboutFlyout);
}

_newTabButton.Flyout(newTabFlyout);
Expand Down Expand Up @@ -403,6 +457,18 @@ namespace winrt::TerminalApp::implementation
winrt::Windows::System::Launcher::LaunchUriAsync({ L"https://github.com/microsoft/Terminal/issues" });
}

// Method Description:
// - Called when the about button is clicked. See _ShowAboutDialog for more info.
// Arguments:
// - <unused>
// Return Value:
// - <none>
void App::_AboutButtonOnClick(const IInspectable&,
const RoutedEventArgs&)
{
_ShowAboutDialog();
}

// Method Description:
// - Register our event handlers with the given keybindings object. This
// should be done regardless of what the events are actually bound to -
Expand Down
7 changes: 6 additions & 1 deletion src/cascadia/TerminalApp/App.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@ namespace winrt::TerminalApp::implementation
void _Create();
void _CreateNewTabFlyout();

fire_and_forget _ShowOkDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey);
fire_and_forget _ShowDialog(const winrt::Windows::Foundation::IInspectable& titleElement,
const winrt::Windows::Foundation::IInspectable& contentElement,
const winrt::hstring& closeButtonText);
void _ShowOkDialog(const winrt::hstring& titleKey, const winrt::hstring& contentKey);
void _ShowAboutDialog();

[[nodiscard]] HRESULT _TryLoadSettings(const bool saveOnLoad) noexcept;
void _LoadSettings();
Expand All @@ -85,6 +89,7 @@ namespace winrt::TerminalApp::implementation

void _SettingsButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _FeedbackButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);
void _AboutButtonOnClick(const IInspectable& sender, const Windows::UI::Xaml::RoutedEventArgs& eventArgs);

void _UpdateTabView();
void _UpdateTabIcon(std::shared_ptr<Tab> tab);
Expand Down
7 changes: 4 additions & 3 deletions src/cascadia/TerminalApp/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@

#include <winrt/coroutine.h>

#include <winrt/Windows.ApplicationModel.Resources.h>
#include <winrt/Windows.Foundation.h>
#include <winrt/Windows.Foundation.Collections.h>
#include <winrt/Windows.Data.Json.h>
#include <winrt/windows.ui.core.h>
#include <winrt/Windows.ui.input.h>
#include <winrt/Windows.UI.Text.h>
Expand All @@ -37,8 +37,6 @@

#include <windows.ui.xaml.media.dxinterop.h>

#include <winrt/windows.data.json.h>

#include <winrt/Windows.System.h>
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Storage.Streams.h>
Expand All @@ -52,3 +50,6 @@ TRACELOGGING_DECLARE_PROVIDER(g_hTerminalWin32Provider);

// JsonCpp
#include <json.h>

#include <shellapi.h>
#include <filesystem>

0 comments on commit e20dfb8

Please sign in to comment.