diff --git a/templates/SimpleKit.Templates.WindowsRuntime/CppWizard.cs b/templates/SimpleKit.Templates.WindowsRuntime/CppWizard.cs new file mode 100644 index 0000000..2e028d3 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/CppWizard.cs @@ -0,0 +1,69 @@ +using EnvDTE; +using Microsoft; +using Microsoft.VisualStudio.ComponentModelHost; +using Microsoft.VisualStudio.OLE.Interop; +using Microsoft.VisualStudio.Shell; +using Microsoft.VisualStudio.TemplateWizard; +using NuGet.VisualStudio; +using System.Collections.Generic; +using System.ComponentModel.Composition; +using System.ComponentModel.Composition.Hosting; + +namespace SimpleKit.Templates.WindowsRuntime +{ + /// + /// A wizard extension that adds a root namespace dedicated to C++ + /// type definitions. + /// + internal sealed class CppWizard : IWizard + { + [Import] + internal IVsTemplateWizard Wizard { get; set; } + + private void Initialize(object automationObject) + { + ThreadHelper.ThrowIfNotOnUIThread(); + using (var serviceProvider = new ServiceProvider((IServiceProvider)automationObject)) + { + var componentModel = (IComponentModel)serviceProvider.GetService(typeof(SComponentModel)); + Assumes.Present(componentModel); + + using (var container = new CompositionContainer(componentModel.DefaultExportProvider)) + { + container.ComposeParts(this); + } + } + } + + // Code taken from here, many thanks to original author(s): + // https://github.com/sylveon/cppwinrt/blob/bb2339505debce51f9aed13703227668537da0ba/vsix/WizardExtension.cs + // Relevant thread: https://github.com/microsoft/cppwinrt/pull/918 + void IWizard.RunStarted(object automationObject, Dictionary replacementsDictionary, WizardRunKind runKind, object[] customParams) + { + ThreadHelper.ThrowIfNotOnUIThread(); + Initialize(automationObject); + + if (replacementsDictionary.TryGetValue("$rootnamespace$", out var rootNamespace)) + replacementsDictionary.Add("$cpprootnamespace$", rootNamespace.Replace(".", "::")); + else if (replacementsDictionary.TryGetValue("$projectname$", out var projectName)) + replacementsDictionary.Add("$cpprootnamespace$", projectName.Replace(".", "::")); + + Wizard.RunStarted(automationObject, replacementsDictionary, runKind, customParams); + } + + void IWizard.BeforeOpeningFile(ProjectItem projectItem) + => Wizard.BeforeOpeningFile(projectItem); + + void IWizard.ProjectFinishedGenerating(Project project) + => Wizard.ProjectFinishedGenerating(project); + + void IWizard.ProjectItemFinishedGenerating(ProjectItem projectItem) + => Wizard.ProjectItemFinishedGenerating(projectItem); + + void IWizard.RunFinished() + => Wizard.RunFinished(); + + bool IWizard.ShouldAddProjectItem(string filePath) + => Wizard.ShouldAddProjectItem(filePath); + } +} diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.cpp b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.cpp new file mode 100644 index 0000000..7124963 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.cpp @@ -0,0 +1,35 @@ +#include "pch.h" +#include "App.h" + +#include "Views/MainPage.h" + +namespace views = winrt::$cpprootnamespace$::Views::implementation; +namespace wama = winrt::Windows::ApplicationModel::Activation; +namespace wamc = winrt::Windows::ApplicationModel::Core; +namespace wux = winrt::Windows::UI::Xaml; + +namespace winrt::$cpprootnamespace$::implementation { + App::App() { +#if defined _DEBUG && !defined DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION + UnhandledException([this](const IInspectable&, const wux::UnhandledExceptionEventArgs& e) + { + if (IsDebuggerPresent()) { + const auto errorMessage = e.Message(); + __debugbreak(); + } + } + ); +#endif + } + + void App::OnLaunched(const wama::LaunchActivatedEventArgs& args) const { + const auto window = wux::Window::Current(); + if (!window.Content()) + window.Content(winrt::make()); + + if (!args.PrelaunchActivated()) { + window.Activate(); + wamc::CoreApplication::EnablePrelaunch(true); + } + } +} diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.h b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.h new file mode 100644 index 0000000..17f68b1 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.h @@ -0,0 +1,18 @@ +#pragma once +#include "App.xaml.g.h" + +namespace winrt::$cpprootnamespace$::implementation { + struct App : AppT { + /** + * @brief Creates the singleton application object. + */ + App(); + + /** + * @brief Invoked when the application is launched normally by the end user. + * + * @param args Details about the launch request and process. + */ + void OnLaunched(const Windows::ApplicationModel::Activation::LaunchActivatedEventArgs&) const; + }; +} diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.xaml b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.xaml new file mode 100644 index 0000000..d57a876 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/App.xaml @@ -0,0 +1,4 @@ + diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/LockScreenLogo.scale-200.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/LockScreenLogo.scale-200.png new file mode 100644 index 0000000..735f57a Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/LockScreenLogo.scale-200.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/SplashScreen.scale-200.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/SplashScreen.scale-200.png new file mode 100644 index 0000000..023e7f1 Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/SplashScreen.scale-200.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square150x150Logo.scale-200.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square150x150Logo.scale-200.png new file mode 100644 index 0000000..af49fec Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square150x150Logo.scale-200.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.scale-200.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.scale-200.png new file mode 100644 index 0000000..ce342a2 Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.scale-200.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png new file mode 100644 index 0000000..f6c02ce Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Square44x44Logo.targetsize-24_altform-unplated.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/StoreLogo.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/StoreLogo.png new file mode 100644 index 0000000..7385b56 Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/StoreLogo.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Wide310x150Logo.scale-200.png b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Wide310x150Logo.scale-200.png new file mode 100644 index 0000000..288995b Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Assets/Wide310x150Logo.scale-200.png differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj new file mode 100644 index 0000000..ffcf183 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj @@ -0,0 +1,171 @@ + + + + true + true + true + true + {$guid1$} + $projectname$ + $projectname$ + en-US + 15.0 + true + Windows Store + 10.0 + $targetplatformversion$ + 10.0.17134.0 + false + + + + + Debug + ARM + + + Debug + ARM64 + + + Debug + Win32 + + + Debug + x64 + + + Release + ARM + + + Release + ARM64 + + + Release + Win32 + + + Release + x64 + + + + Application + v143 + v142 + v141 + v140 + Unicode + + + true + true + + + false + true + false + + + + + + + + + + + + + Out\$(Configuration)\$(Platform)\ + Intermediate\$(Configuration)\$(Platform)\ + + + + Use + pch.h + $(IntDir)pch.pch + Level4 + %(AdditionalOptions) /bigobj + WIN32_LEAN_AND_MEAN;WINRT_LEAN_AND_MEAN;%(PreprocessorDefinitions) + stdcpp20 + stdc17 + + + false + + + + + _DEBUG;%(PreprocessorDefinitions) + + + + + NDEBUG;%(PreprocessorDefinitions) + + + true + true + + + + + + App.xaml + + + Views\MainPage.xaml + Code + + + + + Designer + + + + + Designer + + + + + + + + + + + + + + Create + + + App.xaml + + + + Views\MainPage.xaml + Code + + + + + + + + Designer + + + + + + + + + diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj.filters b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj.filters new file mode 100644 index 0000000..d8067c3 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vcxproj.filters @@ -0,0 +1,60 @@ + + + + + + + + + + + + + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + Assets + + + + + + + + {e48dc53e-40b1-40cb-970a-f89935452892} + + + {1b3d3152-68ee-45ff-aedd-fcf101422473} + + + + + + + + Views + + + + + Views + + + \ No newline at end of file diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vstemplate b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vstemplate new file mode 100644 index 0000000..d4fd5ee --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/BlankApp.vstemplate @@ -0,0 +1,52 @@ + + + SimpleKit - Blank App + A template to create a UWP XAML application. + VC + cpp + windows + uwp + 1000 + true + SimpleKit.TestApp + true + Enabled + true + TemplateIcon.ico + + + + BlankApp.vcxproj.filters + pch.cpp + pch.h + App.xaml + App.cpp + App.h + Views\MainPage.xaml + Views\MainPage.cpp + Views\MainPage.h + Views\Views.idl + Package.appxmanifest + Assets\LockScreenLogo.scale-200.png + Assets\SplashScreen.scale-200.png + Assets\Square150x150Logo.scale-200.png + Assets\Square44x44Logo.scale-200.png + Assets\Square44x44Logo.targetsize-24_altform-unplated.png + Assets\StoreLogo.png + Assets\Wide310x150Logo.scale-200.png + PropertySheet.props + + + + Microsoft.VisualStudio.WinRT.TemplateWizards, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + Microsoft.VisualStudio.WinRT.TemplateWizards.CreateProjectCertificate.Wizard + + + Microsoft.VisualStudio.Universal.TemplateWizards, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a + Microsoft.VisualStudio.Universal.TemplateWizards.PlatformVersion.Wizard + + + SimpleKit.Templates.WindowsRuntime, Version=1.0.0.0, Culture=neutral, PublicKeyToken=6947745fa0996c29 + SimpleKit.Templates.WindowsRuntime.CppWizard + + \ No newline at end of file diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/LICENSE b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/LICENSE new file mode 100644 index 0000000..c4dc89d --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/LICENSE @@ -0,0 +1,22 @@ + MIT License + + Copyright (c) YourOrdinaryCat. + Copyright (c) Microsoft Corporation. + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE \ No newline at end of file diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Package.appxmanifest b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Package.appxmanifest new file mode 100644 index 0000000..dcb22c6 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Package.appxmanifest @@ -0,0 +1,49 @@ + + + + + + + + $projectname$ + $XmlEscapedPublisher$ + Assets\StoreLogo.png + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/PropertySheet.props b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/PropertySheet.props new file mode 100644 index 0000000..ec7dcac --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/PropertySheet.props @@ -0,0 +1,16 @@ + + + + + + + + \ No newline at end of file diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/TemplateIcon.ico b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/TemplateIcon.ico new file mode 100644 index 0000000..54364ed Binary files /dev/null and b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/TemplateIcon.ico differ diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.cpp b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.cpp new file mode 100644 index 0000000..7e75098 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.cpp @@ -0,0 +1,19 @@ +#include "pch.h" +#include "MainPage.h" +#include "Views/MainPage.g.cpp" + +namespace wux = winrt::Windows::UI::Xaml; + +namespace winrt::$cpprootnamespace$::Views::implementation { + int32_t MainPage::MyProperty() const { + throw hresult_not_implemented(); + } + + void MainPage::MyProperty(int32_t /* value */) { + throw hresult_not_implemented(); + } + + void MainPage::ClickHandler(const IInspectable&, const wux::RoutedEventArgs&) { + MyButton().Content(winrt::box_value(L"Clicked")); + } +} diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.h b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.h new file mode 100644 index 0000000..2e0202d --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.h @@ -0,0 +1,25 @@ +#pragma once + +#include "Views/MainPage.g.h" + +namespace winrt::$cpprootnamespace$::Views::implementation { + /** + * @brief Shown to the user when the app is launched normally. + */ + struct MainPage : MainPageT { + MainPage() { + // Xaml objects should not call InitializeComponent during construction. + // See https://github.com/microsoft/cppwinrt/tree/master/nuget#initializecomponent + } + + int32_t MyProperty() const; + void MyProperty(int32_t value); + + void ClickHandler(const Windows::Foundation::IInspectable&, const Windows::UI::Xaml::RoutedEventArgs&); + }; +} + +namespace winrt::$cpprootnamespace$::Views::factory_implementation { + struct MainPage : MainPageT { + }; +} diff --git a/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.xaml b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.xaml new file mode 100644 index 0000000..6ffa6a0 --- /dev/null +++ b/templates/SimpleKit.Templates.WindowsRuntime/ProjectTemplates/BlankApp/Views/MainPage.xaml @@ -0,0 +1,20 @@ + + + + +