diff options
author | Miguel Costa <miguel.costa@qt.io> | 2020-03-23 17:22:35 +0100 |
---|---|---|
committer | Miguel Costa <miguel.costa@qt.io> | 2020-03-31 09:55:15 +0000 |
commit | 94f0dd11bdce516bd7e916cab80b4e3acccda52b (patch) | |
tree | 3728fdc1e8c410d853e5372bdceb00f3deba58cb | |
parent | 2a8f8abd198f6e676b0fac69a34869e8d368e3e5 (diff) |
Update new-project wizards
Wizard support classes for new Qt projects will now be based on the
recently introduced abstract class ProjectTemplateWizard. This base
class provides behavior common to all new-project wizards, which can
then be overridden and tailored for the specific case of each wizard.
Project templates are also updated to reflect changes in the
corresponding wizard classes.
Task-number: QTVSADDINBUG-589
Task-number: QTVSADDINBUG-737
Change-Id: If18215543e354e8caa0d54b5f67669b035e3d569
Reviewed-by: Joerg Bornemann <joerg.bornemann@qt.io>
22 files changed, 755 insertions, 1533 deletions
diff --git a/src/qttemplates/console/console.vcxproj b/src/qttemplates/console/console.vcxproj index 286e5859..dd19ec05 100644 --- a/src/qttemplates/console/console.vcxproj +++ b/src/qttemplates/console/console.vcxproj @@ -1,33 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|$Platform$"> - <Configuration>Debug</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|$Platform$"> - <Configuration>Release</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> +$ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> - $if$ ($isSet_WindowsTargetPlatformVersion$ == true) - <WindowsTargetPlatformVersion>$WindowsTargetPlatformVersion$</WindowsTargetPlatformVersion> - $endif$ +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -37,24 +21,12 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> + $QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> diff --git a/src/qttemplates/designer/designer.vcxproj b/src/qttemplates/designer/designer.vcxproj index 37b2d8fa..7fea204a 100644 --- a/src/qttemplates/designer/designer.vcxproj +++ b/src/qttemplates/designer/designer.vcxproj @@ -1,33 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|$Platform$"> - <Configuration>Debug</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|$Platform$"> - <Configuration>Release</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> +$ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> - $if$ ($isSet_WindowsTargetPlatformVersion$ == true) - <WindowsTargetPlatformVersion>$WindowsTargetPlatformVersion$</WindowsTargetPlatformVersion> - $endif$ +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -37,47 +21,23 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> +$QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> +$BuildSettings$ <ItemGroup> - <None Include="$pluginsourcefilename$" /> - <None Include="$pluginheaderfilename$" /> + <QtMoc Include="$headerfilename$"/> + <ClCompile Include="$sourcefilename$"/> + <QtMoc Include="$pluginheaderfilename$"/> + <ClCompile Include="$pluginsourcefilename$"/> <None Include="$plugin_json$" /> - $precompiledsource$ - $precompiledheader$ - <None Include="$sourcefilename$" /> - <None Include="$headerfilename$" /> +$ProjectItems$ </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> diff --git a/src/qttemplates/designer/designer.vcxproj.filters b/src/qttemplates/designer/designer.vcxproj.filters index 33eb1738..4ee6edec 100644 --- a/src/qttemplates/designer/designer.vcxproj.filters +++ b/src/qttemplates/designer/designer.vcxproj.filters @@ -19,4 +19,22 @@ <ParseFiles>false</ParseFiles> </Filter> </ItemGroup> + <ItemGroup> + <QtMoc Include="$headerfilename$"> + <Filter>Header Files</Filter> + </QtMoc> + <ClCompile Include="$sourcefilename$"> + <Filter>Source Files</Filter> + </ClCompile> + <QtMoc Include="$pluginheaderfilename$"> + <Filter>Header Files</Filter> + </QtMoc> + <ClCompile Include="$pluginsourcefilename$"> + <Filter>Source Files</Filter> + </ClCompile> + <None Include="$plugin_json$"> + <Filter>Resource Files</Filter> + </None> +$FilterItems$ + </ItemGroup> </Project> diff --git a/src/qttemplates/designer/plugin.cpp b/src/qttemplates/designer/plugin.cpp index 86b73dc6..8c04ffc3 100644 --- a/src/qttemplates/designer/plugin.cpp +++ b/src/qttemplates/designer/plugin.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ #include "$pluginheaderfilename$" #include <QtCore/QtPlugin> diff --git a/src/qttemplates/designer/widget.cpp b/src/qttemplates/designer/widget.cpp index cab39716..177f7c3f 100644 --- a/src/qttemplates/designer/widget.cpp +++ b/src/qttemplates/designer/widget.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ $classname$::$classname$(QWidget *parent) : $baseclass$(parent) diff --git a/src/qttemplates/empty/empty.vcxproj b/src/qttemplates/empty/empty.vcxproj index df924c18..56270fb3 100644 --- a/src/qttemplates/empty/empty.vcxproj +++ b/src/qttemplates/empty/empty.vcxproj @@ -1,30 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|x64"> - <Configuration>Debug</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|x64"> - <Configuration>Release</Configuration> - <Platform>x64</Platform> - </ProjectConfiguration> + $ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -34,33 +21,19 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - </PropertyGroup> +$QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'"> - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'"> - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> +$BuildSettings$ + <ItemGroup> +$ProjectItems$ + </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> <Import Project="$(QtMsBuild)\qt.targets" /> diff --git a/src/qttemplates/gui/gui.vcxproj b/src/qttemplates/gui/gui.vcxproj index 17f031af..446a2b40 100644 --- a/src/qttemplates/gui/gui.vcxproj +++ b/src/qttemplates/gui/gui.vcxproj @@ -1,49 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|$Platform$"> - <Configuration>Debug</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|$Platform$"> - <Configuration>Release</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> +$ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> - $if$ ($QtWinRT$ == true) - <MinimumVisualStudioVersion>$MinimumVisualStudioVersion$</MinimumVisualStudioVersion> - <DefaultLanguage>en</DefaultLanguage> - <AppContainerApplication>true</AppContainerApplication> - <ApplicationType>Windows Store</ApplicationType> - <ApplicationTypeRevision>$ApplicationTypeRevision$</ApplicationTypeRevision> - <WindowsTargetPlatformMinVersion>$WindowsTargetPlatformMinVersion$</WindowsTargetPlatformMinVersion> - $endif$ - $if$ ($isSet_WindowsTargetPlatformVersion$ == true) - <WindowsTargetPlatformVersion>$WindowsTargetPlatformVersion$</WindowsTargetPlatformVersion> - $endif$ +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - $if$ ($QtWinRT$ == true) - <GenerateManifest>false</GenerateManifest> - <EmbedManifest>false</EmbedManifest> - $endif$ - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - $if$ ($QtWinRT$ == true) - <GenerateManifest>false</GenerateManifest> - <EmbedManifest>false</EmbedManifest> - $endif$ - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -53,102 +21,24 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> +$QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> - $if$ ($QtWinRT$ == true) - <Target Name="WinDeployQt" - Inputs="$(OutDir)\$(TargetName).exe" Outputs="$(TargetName).windeployqt.$(Platform).$(Configuration)"> - <Message Text="$(QTDIR)\bin\windeployqt.exe -qmldir "$(MSBuildProjectDirectory)" -list relative -dir "$(MSBuildProjectDirectory)" "$(OutDir)\$(TargetName).exe" > "$(TargetName).windeployqt.$(Platform).$(Configuration)"" /> - <Exec Command="$(QTDIR)\bin\windeployqt.exe -qmldir "$(MSBuildProjectDirectory)" -list relative -dir "$(MSBuildProjectDirectory)" "$(OutDir)\$(TargetName).exe" > "$(TargetName).windeployqt.$(Platform).$(Configuration)"" /> - </Target> - <Target Name="PopulateWinDeployQtItems" AfterTargets="Link" DependsOnTargets="WinDeployQt"> - <ReadLinesFromFile File="$(TargetName).windeployqt.$(Platform).$(Configuration)"> - <Output TaskParameter="Lines" ItemName="DeploymentItems" /> - </ReadLinesFromFile> - <ItemGroup> - <None Include="@(DeploymentItems)"> - <DeploymentContent>true</DeploymentContent> - </None> - </ItemGroup> - </Target> - $endif$ - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - $if$ ($QtWinRT$ == true) - <CompileAsWinRT>false</CompileAsWinRT> - <PrecompiledHeader>NotUsing</PrecompiledHeader> - <RuntimeTypeInfo>true</RuntimeTypeInfo> - $endif$ - </ClCompile> - $if$ ($QtWinRT$ == true) - <Link> - <AdditionalOptions>/APPCONTAINER %(AdditionalOptions)</AdditionalOptions> - <GenerateManifest>false</GenerateManifest> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - <TargetMachine>$Link_TargetMachine$</TargetMachine> - </Link> - $endif$ - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - $if$ ($QtWinRT$ == true) - <CompileAsWinRT>false</CompileAsWinRT> - <PrecompiledHeader>NotUsing</PrecompiledHeader> - <RuntimeTypeInfo>true</RuntimeTypeInfo> - $endif$ - </ClCompile> - $if$ ($QtWinRT$ == true) - <Link> - <AdditionalOptions>/APPCONTAINER %(AdditionalOptions)</AdditionalOptions> - <GenerateManifest>false</GenerateManifest> - <GenerateWindowsMetadata>false</GenerateWindowsMetadata> - <TargetMachine>$Link_TargetMachine$</TargetMachine> - </Link> - $endif$ - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="main.cpp" /> - </ItemGroup> - <ItemGroup> - $precompiledheader$ - $precompiledsource$ - $DefaultApplicationIcon$ - <None Include="$uifilename$" /> - <None Include="$headerfilename$" /> - <None Include="$sourcefilename$" /> - </ItemGroup> - $if$ ($QtWinRT$ == true) +$BuildSettings$ <ItemGroup> - <AppxManifest Include="Package.appxmanifest" /> - <Image Include="assets/logo_150x150.png" /> - <Image Include="assets/logo_44x44.png" /> - <Image Include="assets/logo_store.png" /> - <Image Include="assets/logo_620x300.png" /> + <QtRcc Include="$qrcfilename$"/> + <QtUic Include="$uifilename$"/> + <QtMoc Include="$headerfilename$"/> + <ClCompile Include="$sourcefilename$"/> + <ClCompile Include="main.cpp"/> +$ProjectItems$ </ItemGroup> - $endif$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> <Import Project="$(QtMsBuild)\qt.targets" /> diff --git a/src/qttemplates/gui/gui.vcxproj.filters b/src/qttemplates/gui/gui.vcxproj.filters index ff119fc9..e8f582b7 100644 --- a/src/qttemplates/gui/gui.vcxproj.filters +++ b/src/qttemplates/gui/gui.vcxproj.filters @@ -24,8 +24,23 @@ </Filter> </ItemGroup> <ItemGroup> - <ClCompile Include="main.cpp"> + <QtUic Include="$uifilename$"> + <Filter>Resource Files</Filter> + </QtUic> + <QtMoc Include="$headerfilename$"> + <Filter>Header Files</Filter> + </QtMoc> + <ClCompile Include="$sourcefilename$"> <Filter>Source Files</Filter> </ClCompile> + <ResourceCompile Include="$pro_name$.rc"> + </ResourceCompile> + <None Include="$pro_name$.ico"> + <Filter>Resource Files</Filter> + </None> + <None Include="$pro_name$.def"> + <Filter>Resource Files</Filter> + </None> +$FilterItems$ </ItemGroup> </Project> diff --git a/src/qttemplates/gui/main.cpp b/src/qttemplates/gui/main.cpp index defbc683..df591883 100644 --- a/src/qttemplates/gui/main.cpp +++ b/src/qttemplates/gui/main.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ #include <QtWidgets/QApplication> int main(int argc, char *argv[]) diff --git a/src/qttemplates/gui/widget.cpp b/src/qttemplates/gui/widget.cpp index dfda4024..2a11cc5e 100644 --- a/src/qttemplates/gui/widget.cpp +++ b/src/qttemplates/gui/widget.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ $classname$::$classname$(QWidget *parent) : $baseclass$(parent) diff --git a/src/qttemplates/lib/lib.vcxproj b/src/qttemplates/lib/lib.vcxproj index d0e861a9..42283ba2 100644 --- a/src/qttemplates/lib/lib.vcxproj +++ b/src/qttemplates/lib/lib.vcxproj @@ -1,33 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|$Platform$"> - <Configuration>Debug</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|$Platform$"> - <Configuration>Release</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> +$ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> - $if$ ($isSet_WindowsTargetPlatformVersion$ == true) - <WindowsTargetPlatformVersion>$WindowsTargetPlatformVersion$</WindowsTargetPlatformVersion> - $endif$ +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -37,49 +21,21 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> +$QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> - <ItemGroup> - <ClCompile Include="$sourcefilename$" /> - </ItemGroup> - <ItemGroup> - <ClInclude Include="$headerfilename$" /> - <ClInclude Include="$saveglobal$_global.h" /> - </ItemGroup> +$BuildSettings$ <ItemGroup> - $precompiledheader$ - $precompiledsource$ + <ClInclude Include="$saveglobal$_global.h"/> + <QtMoc Include="$headerfilename$"/> + <ClCompile Include="$sourcefilename$"/> +$ProjectItems$ </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> diff --git a/src/qttemplates/lib/lib.vcxproj.filters b/src/qttemplates/lib/lib.vcxproj.filters index 7c9f93ac..e8012cfe 100644 --- a/src/qttemplates/lib/lib.vcxproj.filters +++ b/src/qttemplates/lib/lib.vcxproj.filters @@ -20,18 +20,15 @@ </Filter> </ItemGroup> <ItemGroup> - <ClCompile Include="$sourcefilename$"> - <Filter>Source Files</Filter> - </ClCompile> - </ItemGroup> - <ItemGroup> - <ClInclude Include="$headerfilename$"> - <Filter>Header Files</Filter> - </ClInclude> - </ItemGroup> - <ItemGroup> <ClInclude Include="$saveglobal$_global.h"> <Filter>Header Files</Filter> </ClInclude> + <QtMoc Include="$headerfilename$"> + <Filter>Header Files</Filter> + </QtMoc> + <ClCompile Include="$sourcefilename$"> + <Filter>Source Files</Filter> + </ClCompile> +$FilterItems$ </ItemGroup> </Project> diff --git a/src/qttemplates/lib/source.cpp b/src/qttemplates/lib/source.cpp index 85941329..67126b70 100644 --- a/src/qttemplates/lib/source.cpp +++ b/src/qttemplates/lib/source.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ $classname$::$classname$() { diff --git a/src/qttemplates/server/server.vcxproj b/src/qttemplates/server/server.vcxproj index aa2ba3fe..b1e65070 100644 --- a/src/qttemplates/server/server.vcxproj +++ b/src/qttemplates/server/server.vcxproj @@ -1,33 +1,17 @@ <?xml version="1.0" encoding="utf-8"?> <Project DefaultTargets="Build" ToolsVersion="$ToolsVersion$" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <ItemGroup Label="ProjectConfigurations"> - <ProjectConfiguration Include="Debug|$Platform$"> - <Configuration>Debug</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> - <ProjectConfiguration Include="Release|$Platform$"> - <Configuration>Release</Configuration> - <Platform>$Platform$</Platform> - </ProjectConfiguration> +$ProjectConfigurations$ </ItemGroup> <PropertyGroup Label="Globals"> <ProjectGuid>$ProjectGuid$</ProjectGuid> <Keyword>$Keyword$</Keyword> - $if$ ($isSet_WindowsTargetPlatformVersion$ == true) - <WindowsTargetPlatformVersion>$WindowsTargetPlatformVersion$</WindowsTargetPlatformVersion> - $endif$ +$Globals$ <QtMsBuild Condition="'$(QtMsBuild)'=='' OR !Exists('$(QtMsBuild)\qt.targets')" >$(MSBuildProjectDirectory)\QtMsBuild</QtMsBuild> </PropertyGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" /> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> - <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'" Label="Configuration"> - <ConfigurationType>Application</ConfigurationType> - <PlatformToolset>v$PlatformToolset$</PlatformToolset> - </PropertyGroup> +$Configurations$ <Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" /> <Target Name="QtMsBuildNotFound" BeforeTargets="CustomBuild;ClCompile" @@ -37,48 +21,24 @@ </Target> <ImportGroup Label="ExtensionSettings" /> <ImportGroup Label="Shared" /> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> - <ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" /> - </ImportGroup> +$PropertySheets$ <PropertyGroup Label="UserMacros" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt_defaults.props')"> <Import Project="$(QtMsBuild)\qt_defaults.props" /> </ImportGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> - <PropertyGroup Label="QtSettings" Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - <QtInstall>$DefaultQtVersion$</QtInstall> - <QtModules>$QtModules$</QtModules> - </PropertyGroup> +$QtSettings$ <ImportGroup Condition="Exists('$(QtMsBuild)\qt.props')"> <Import Project="$(QtMsBuild)\qt.props" /> </ImportGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> - <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|$Platform$'"> - $QtMoc$ - <ClCompile> - <MultiProcessorCompilation>true</MultiProcessorCompilation> - </ClCompile> - </ItemDefinitionGroup> +$BuildSettings$ <ItemGroup> - $precompiledheader$ - $precompiledsource$ - <None Include="$uifilename$" /> - <None Include="$pro_name$.rc" /> + <QtUic Include="$uifilename$" /> + <QtMoc Include="$headerfilename$" /> + <ClCompile Include="$sourcefilename$" /> + <ResourceCompile Include="$pro_name$.rc" /> <None Include="$pro_name$.ico" /> <None Include="$pro_name$.def" /> - <None Include="$headerfilename$" /> - <None Include="$sourcefilename$" /> +$ProjectItems$ </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Condition="Exists('$(QtMsBuild)\qt.targets')"> diff --git a/src/qttemplates/server/source.cpp b/src/qttemplates/server/source.cpp index 350f5c11..36a3c6bb 100644 --- a/src/qttemplates/server/source.cpp +++ b/src/qttemplates/server/source.cpp @@ -1,4 +1,4 @@ -#include "$include$" +$include$ #include <ActiveQt/QAxFactory> diff --git a/src/qtwizard/Wizards/ProjectWizard/ConfigPage.xaml.cs b/src/qtwizard/Wizards/ProjectWizard/ConfigPage.xaml.cs index b6f41353..487489d1 100644 --- a/src/qtwizard/Wizards/ProjectWizard/ConfigPage.xaml.cs +++ b/src/qtwizard/Wizards/ProjectWizard/ConfigPage.xaml.cs @@ -196,6 +196,13 @@ namespace QtVsTools.Wizards.ProjectWizard Validate(); } + /// <summary> + /// Callback to validate selected configurations. + /// Must return an error message in case of failed validation. + /// Otherwise, return empty string or null. + /// </summary> + public Func<IEnumerable<IWizardConfiguration>, string> ValidateConfigs { get; set; } + void Validate() { if (currentConfigs // "$(Configuration)|$(Platform)" must be unique @@ -206,8 +213,15 @@ namespace QtVsTools.Wizards.ProjectWizard ErrorPanel.Visibility = Visibility.Visible; NextButton.IsEnabled = false; FinishButton.IsEnabled = false; + } else if (ValidateConfigs != null + && ValidateConfigs(currentConfigs) is string errorMsg + && !string.IsNullOrEmpty(errorMsg)) { + ErrorMsg.Content = errorMsg; + ErrorPanel.Visibility = Visibility.Visible; + NextButton.IsEnabled = false; + FinishButton.IsEnabled = false; } else { - ErrorMsg.Content = ""; + ErrorMsg.Content = string.Empty; ErrorPanel.Visibility = Visibility.Hidden; NextButton.IsEnabled = initialNextButtonIsEnabled; FinishButton.IsEnabled = initialFinishButtonIsEnabled; diff --git a/src/qtwizard/Wizards/ProjectWizard/Console/ConsoleWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Console/ConsoleWizard.cs index c053976f..4557eae4 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Console/ConsoleWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Console/ConsoleWizard.cs @@ -26,171 +26,63 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; +using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Windows.Forms; +using QtVsTools.Common; namespace QtVsTools.Wizards.ProjectWizard { - public class ConsoleWizard : IWizard + public class ConsoleWizard : ProjectTemplateWizard { - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var serviceProvider = new ServiceProvider(automation as IServiceProvider); - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - - iVsUIShell.EnableModeless(0); - - var versionMgr = QtVersionManager.The(); - var versionName = versionMgr.GetDefaultVersion(); - var versionInfo = VersionInformation.Get(versionMgr.GetInstallPath(versionName)); - if (versionInfo.isWinRT()) { - MessageBox.Show( - string.Format( - "The Qt Console Application project type is not available\r\n" + - "for the currently selected Qt version ({0}).", versionName), - "Project Type Not Available", MessageBoxButtons.OK, MessageBoxIcon.Error); - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } - - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); - - try { - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt Console Application Wizard", - Message = @"This wizard generates a Qt console application " - + @"project. The application derives from QCoreApplication " - + @"and does not present a GUI." + System.Environment.NewLine - + System.Environment.NewLine + "To continue, click Next.", - PreviousButtonEnabled = false, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ModulePage { - Data = data, - Header = @"Welcome to the Qt Console Application Wizard", - Message = @"Select the modules you want to include in your project. The " - + @"recommended modules for this project are selected by default.", - PreviousButtonEnabled = true, - NextButtonEnabled = false, - FinishButtonEnabled = QtModuleInfo.IsInstalled(@"QtCore"), - CancelButtonEnabled = true - } - }) - { - Title = @"Qt Console Application Wizard" - }; - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception("Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact + protected override Options TemplateType => Options.Application | Options.ConsoleSystem; + + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { "QtCore" } + }); + + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt Console Application Wizard") + { + new WizardIntroPage { + Data = WizardData, + Header = @"Welcome to the Qt Console Application Wizard", + Message = @"This wizard generates a Qt console application " + + @"project. The application derives from QCoreApplication " + + @"and does not present a GUI." + System.Environment.NewLine + + System.Environment.NewLine + "To continue, click Next.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage { + Data = WizardData, + Header = @"Welcome to the Qt Console Application Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true, + ValidateConfigs = ValidateConfigsForConsoleApp } + }); - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - - replacements["$Platform$"] = versionInfo.GetVSPlatformName(); - - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - replacements["$DefaultQtVersion$"] = versionName; - replacements["$QtModules$"] = string.Join(";", data.Modules - .Select(moduleName => QtModules.Instance - .ModuleInformation(QtModules.Instance - .ModuleIdByName(moduleName)) - .proVarQT)); - -#if (VS2019 || VS2017 || VS2015) - string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); - if (!string.IsNullOrEmpty(versionWin10SDK)) { - replacements["$WindowsTargetPlatformVersion$"] = versionWin10SDK; - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; + string ValidateConfigsForConsoleApp(IEnumerable<IWizardConfiguration> configs) + { + foreach (var config in configs) { + if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { + return string.Format( + "Console Application project not available for the '{0}' target.", + config.Target); } -#endif - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } - - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); } - - iVsUIShell.EnableModeless(1); + return string.Empty; } - - public bool ShouldAddProjectItem(string filePath) - { - return true; - } - - public void ProjectFinishedGenerating(Project project) - { - var qtProject = QtProject.Create(project); - - QtVSIPSettings.SaveUicDirectory(project, null); - QtVSIPSettings.SaveMocDirectory(project, null); - QtVSIPSettings.SaveMocOptions(project, null); - QtVSIPSettings.SaveRccDirectory(project, null); - QtVSIPSettings.SaveLUpdateOnBuild(project); - QtVSIPSettings.SaveLUpdateOptions(project, null); - QtVSIPSettings.SaveLReleaseOptions(project, null); - - var vm = QtVersionManager.The(); - var qtVersion = vm.GetDefaultVersion(); - var vi = VersionInformation.Get(vm.GetInstallPath(qtVersion)); - if (vi.GetVSPlatformName() != "Win32") - qtProject.SelectSolutionPlatform(vi.GetVSPlatformName()); - - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - - var type = TemplateType.Application | TemplateType.ConsoleSystem; - qtProject.WriteProjectBasicConfigurations(type, false); - - foreach (VCFile file in (IVCCollection) qtProject.VCProject.Files) - qtProject.AdjustWhitespace(file.FullPath); - - qtProject.SetQtEnvironment(qtVersion); - qtProject.Finish(); // Collapses all project nodes. - } - - public void ProjectItemFinishedGenerating(ProjectItem projectItem) - { - } - - public void BeforeOpeningFile(ProjectItem projectItem) - { - } - - public void RunFinished() - { - } - - private readonly WizardData data = new WizardData - { - DefaultModules = new List<string> { @"QtCore" } - }; } } diff --git a/src/qtwizard/Wizards/ProjectWizard/Designer/DesignerWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Designer/DesignerWizard.cs index f4ad5da1..087f9781 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Designer/DesignerWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Designer/DesignerWizard.cs @@ -26,254 +26,157 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using IServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Controls; -using System.Windows.Forms; +using EnvDTE; +using QtVsTools.Common; namespace QtVsTools.Wizards.ProjectWizard { - public class DesignerWizard : IWizard - { - public void BeforeOpeningFile(ProjectItem projectItem) - { - } - - public void ProjectFinishedGenerating(Project project) - { - var qtProject = QtProject.Create(project); - - QtVSIPSettings.SaveUicDirectory(project, null); - QtVSIPSettings.SaveMocDirectory(project, null); - QtVSIPSettings.SaveMocOptions(project, null); - QtVSIPSettings.SaveRccDirectory(project, null); - QtVSIPSettings.SaveLUpdateOnBuild(project); - QtVSIPSettings.SaveLUpdateOptions(project, null); - QtVSIPSettings.SaveLReleaseOptions(project, null); - - var vm = QtVersionManager.The(); - var qtVersion = vm.GetDefaultVersion(); - var vi = VersionInformation.Get(vm.GetInstallPath(qtVersion)); - if (vi.GetVSPlatformName() != "Win32") - qtProject.SelectSolutionPlatform(vi.GetVSPlatformName()); - - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - - var type = TemplateType.PluginProject | TemplateType.DynamicLibrary | TemplateType.GUISystem; - qtProject.WriteProjectBasicConfigurations(type, data.UsePrecompiledHeader); + using static EnumExt; - var vcProject = qtProject.VCProject; - var files = vcProject.GetFilesWithItemType(@"None") as IVCCollection; - foreach (var vcFile in files) - vcProject.RemoveFile(vcFile); - - if (data.UsePrecompiledHeader) { - qtProject.AddFileToProject(@"stdafx.cpp", Filters.SourceFiles()); - qtProject.AddFileToProject(@"stdafx.h", Filters.HeaderFiles()); - } - - qtProject.AddFileToProject(data.ClassSourceFile, Filters.SourceFiles()); - qtProject.AddFileToProject(data.ClassHeaderFile, Filters.HeaderFiles()); - - qtProject.AddFileToProject(data.PluginSourceFile, Filters.SourceFiles()); - qtProject.AddFileToProject(data.PluginHeaderFile, Filters.HeaderFiles()); - - qtProject.AddFileToProject(data.PluginClass.ToLower() + @".json", Filters.OtherFiles()); - - foreach (VCFile file in (IVCCollection) qtProject.VCProject.Files) - qtProject.AdjustWhitespace(file.FullPath); - - qtProject.SetQtEnvironment(qtVersion); - qtProject.Finish(); // Collapses all project nodes. - } + public class DesignerWizard : ProjectTemplateWizard + { + protected override Options TemplateType => + Options.PluginProject | Options.DynamicLibrary | Options.GUISystem; - public void ProjectItemFinishedGenerating(ProjectItem projectItem) + enum NewClass { + [String("classname")] ClassName, + [String("baseclass")] BaseClass, + [String("sourcefilename")] SourceFileName, + [String("headerfilename")] HeaderFileName, + [String("include")] Include, } - public void RunFinished() + enum NewDesignerPlugin { + [String("plugin_class")] ClassName, + [String("objname")] ObjectName, + [String("pluginsourcefilename")] SourceFileName, + [String("pluginheaderfilename")] HeaderFileName, + [String("plugin_json")] JsonFileName, } - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var qtMoc = new StringBuilder(); - var serviceProvider = new ServiceProvider(automation as IServiceProvider); - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - - iVsUIShell.EnableModeless(0); - - var versionMgr = QtVersionManager.The(); - var versionName = versionMgr.GetDefaultVersion(); - var versionInfo = VersionInformation.Get(versionMgr.GetInstallPath(versionName)); - if (versionInfo.isWinRT()) { - MessageBox.Show( - string.Format( - "The Qt Custom Designer Widget project type is not available\r\n" + - "for the currently selected Qt version ({0}).", versionName), - "Project Type Not Available", MessageBoxButtons.OK, MessageBoxIcon.Error); - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } - - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); - - try { - var className = replacements["$safeprojectname$"]; - className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty); - className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty); - className = Regex.Replace(className, @"[pP][lL][uU][gG][iI][nN]$", string.Empty); - var result = new Util.ClassNameValidationRule().Validate(className, null); - if (result != ValidationResult.ValidResult) - className = @"MyDesignerWidget"; - - data.ClassName = className; - data.BaseClass = @"QWidget"; - data.ClassHeaderFile = className + @".h"; - data.ClassSourceFile = className + @".cpp"; - data.PluginClass = className + @"Plugin"; - data.PluginHeaderFile = data.PluginClass + @".h"; - data.PluginSourceFile = data.PluginClass + @".cpp"; - - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt Custom Designer Widget", - Message = @"This wizard generates a custom designer widget which can be " - + @"used in Qt Designer or Visual Studio." - + System.Environment.NewLine + System.Environment.NewLine - + "To continue, click Next.", - PreviousButtonEnabled = false, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ModulePage { - Data = data, - Header = @"Welcome to the Qt Custom Designer Widget", - Message = @"Select the modules you want to include in your project. The " - + @"recommended modules for this project are selected by default.", - PreviousButtonEnabled = true, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new DesignerPage { - Data = data, - Header = @"Welcome to the Qt Custom Designer Widget", - Message = @"This wizard generates a custom designer widget which can be " - + @"used in Qt Designer or Visual Studio.", - PreviousButtonEnabled = true, - NextButtonEnabled = false, - FinishButtonEnabled = data.DefaultModules.All(QtModuleInfo.IsInstalled), - CancelButtonEnabled = true - } - }) - { - Title = @"Qt Custom Designer Widget" - }; - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception("Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { + "QtCore", "QtGui", "QtWidgets", "QtXml" } - - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - - replacements["$Platform$"] = versionInfo.GetVSPlatformName(); - - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - replacements["$DefaultQtVersion$"] = versionName; - replacements["$QtModules$"] = string.Join(";", data.Modules - .Select(moduleName => QtModules.Instance - .ModuleInformation(QtModules.Instance - .ModuleIdByName(moduleName)) - .proVarQT) - .Union(new[] { "designer " }) - .ToDictionary(x => x, StringComparer.InvariantCultureIgnoreCase).Keys); - - replacements["$classname$"] = data.ClassName; - replacements["$baseclass$"] = data.BaseClass; - replacements["$sourcefilename$"] = data.ClassSourceFile; - replacements["$headerfilename$"] = data.ClassHeaderFile; - - replacements["$plugin_class$"] = data.PluginClass; - replacements["$pluginsourcefilename$"] = data.PluginSourceFile; - replacements["$pluginheaderfilename$"] = data.PluginHeaderFile; - - replacements["$plugin_json$"] = data.PluginClass.ToLower() + @".json"; - replacements["$objname$"] = char.ToLower(data.ClassName[0]) + data.ClassName - .Substring(1); - - replacements["$precompiledheader$"] = string.Empty; - replacements["$precompiledsource$"] = string.Empty; - - var strHeaderInclude = data.ClassHeaderFile; - if (data.UsePrecompiledHeader) { - strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile; - replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />"; - replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />"; - qtMoc.Append("<PrependInclude>stdafx.h</PrependInclude>"); + }); + + string[] _ExtraModules; + protected override IEnumerable<string> ExtraModules => _ExtraModules + ?? (_ExtraModules = new[] { "designer" }); + + string[] _ExtraDefines; + protected override IEnumerable<string> ExtraDefines => _ExtraDefines + ?? (_ExtraDefines = new[] { "QT_PLUGIN" }); + + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt Custom Designer Widget") + { + new WizardIntroPage { + Data = WizardData, + Header = @"Welcome to the Qt Custom Designer Widget", + Message = @"This wizard generates a custom designer widget which can be " + + @"used in Qt Designer or Visual Studio." + + System.Environment.NewLine + System.Environment.NewLine + + "To continue, click Next.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage { + Data = WizardData, + Header = @"Welcome to the Qt GUI Application Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true, + ValidateConfigs = ValidateConfigsForDesignerWidget + }, + new DesignerPage { + Data = WizardData, + Header = @"Welcome to the Qt Custom Designer Widget", + Message = @"This wizard generates a custom designer widget which can be " + + @"used in Qt Designer or Visual Studio.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true } - replacements["$include$"] = strHeaderInclude; + } + ); -#if (VS2019 || VS2017 || VS2015) - string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); - if (!string.IsNullOrEmpty(versionWin10SDK)) { - replacements["$WindowsTargetPlatformVersion$"] = versionWin10SDK; - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; + string ValidateConfigsForDesignerWidget(IEnumerable<IWizardConfiguration> configs) + { + foreach (var config in configs) { + if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { + return string.Format( + "Custom Designer Widget project not available for the '{0}' target.", + config.Target); } - - if (qtMoc.Length > 0) - replacements["$QtMoc$"] = string.Format("<QtMoc>{0}</QtMoc>", qtMoc); - else - replacements["$QtMoc$"] = string.Empty; -#endif - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } - - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); } + return string.Empty; + } - iVsUIShell.EnableModeless(1); + protected override void BeforeWizardRun() + { + var className = Parameter[NewProject.SafeName]; + className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty); + className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty); + var result = new Util.ClassNameValidationRule().Validate(className, null); + if (result != ValidationResult.ValidResult) + className = @"MyDesignerWidget"; + + WizardData.ClassName = className; + WizardData.BaseClass = @"QWidget"; + WizardData.ClassHeaderFile = className + @".h"; + WizardData.ClassSourceFile = className + @".cpp"; + + WizardData.PluginClass = className + @"Plugin"; + WizardData.PluginHeaderFile = WizardData.PluginClass + @".h"; + WizardData.PluginSourceFile = WizardData.PluginClass + @".cpp"; } - public bool ShouldAddProjectItem(string filePath) + protected override void BeforeTemplateExpansion() { - return true; + Parameter[NewClass.ClassName] = WizardData.ClassName; + Parameter[NewClass.BaseClass] = WizardData.BaseClass; + Parameter[NewClass.HeaderFileName] = WizardData.ClassHeaderFile; + Parameter[NewClass.SourceFileName] = WizardData.ClassSourceFile; + + var include = new StringBuilder(); + include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + if (UsePrecompiledHeaders) + include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); + Parameter[NewClass.Include] = FormatParam(include); + + Parameter[NewDesignerPlugin.ClassName] = WizardData.PluginClass; + Parameter[NewDesignerPlugin.HeaderFileName] = WizardData.PluginHeaderFile; + Parameter[NewDesignerPlugin.SourceFileName] = WizardData.PluginSourceFile; + Parameter[NewDesignerPlugin.JsonFileName] = WizardData.PluginClass.ToLower() + ".json"; + Parameter[NewDesignerPlugin.ObjectName] = string.Format("{0}{1}", + WizardData.ClassName[0], + WizardData.ClassName.Substring(1)); } - private readonly WizardData data = new WizardData + protected override void OnProjectGenerated(Project project) { - DefaultModules = new List<string> { - @"QtCore", @"QtGui", @"QtWidgets", @"QtXml" - } - }; + project.Globals["IsDesignerPlugin"] = true.ToString(); + if (!project.Globals.get_VariablePersists("IsDesignerPlugin")) + project.Globals.set_VariablePersists("IsDesignerPlugin", true); + } } } diff --git a/src/qtwizard/Wizards/ProjectWizard/Empty/EmptyWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Empty/EmptyWizard.cs index 0557f329..61a0e89f 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Empty/EmptyWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Empty/EmptyWizard.cs @@ -26,109 +26,48 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; +using System; using System.Collections.Generic; -using System.IO; -using System.Linq; -using System.Text; -using System.Text.RegularExpressions; -using System.Windows.Controls; namespace QtVsTools.Wizards.ProjectWizard { - public class EmptyWizard : IWizard + public class EmptyWizard : ProjectTemplateWizard { - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - iVsUIShell.EnableModeless(0); + protected override Options TemplateType => Options.Application | Options.GUISystem; - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { } + }); - try { - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt Empty Application Wizard", - Message = @"This wizard generates an empty Qt application project." - + System.Environment.NewLine - + "Click Finish to create the project.", - PreviousButtonEnabled = false, - NextButtonEnabled = false, - FinishButtonEnabled = true, - CancelButtonEnabled = true - }, - }) - { - Title = @"Qt Empty Application Wizard" - }; - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception("Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt Empty Application Wizard") + { + new WizardIntroPage { + Data = WizardData, + Header = @"Welcome to the Qt Empty Application Wizard", + Message = @"This wizard generates an empty Qt application project." + + System.Environment.NewLine + + "Click Finish to create the project.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage { + Data = WizardData, + Header = @"Welcome to the Qt Empty Application Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true, } - - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } - - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } - - iVsUIShell.EnableModeless(1); - } - - public bool ShouldAddProjectItem(string filePath) - { - return true; - } - - public void ProjectFinishedGenerating(Project project) - { - var qtProject = QtProject.Create(project); - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - qtProject.WriteProjectBasicConfigurations( - TemplateType.Application | TemplateType.GUISystem, false); - qtProject.Finish(); // Collapses all project nodes. - } - - public void ProjectItemFinishedGenerating(ProjectItem projectItem) - { - } - - public void BeforeOpeningFile(ProjectItem projectItem) - { - } - - public void RunFinished() - { - } - - private readonly WizardData data = new WizardData - { - DefaultModules = new List<string> { } - }; + }); } } diff --git a/src/qtwizard/Wizards/ProjectWizard/Gui/GuiWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Gui/GuiWizard.cs index 46a9c568..4a656f5b 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Gui/GuiWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Gui/GuiWizard.cs @@ -26,308 +26,261 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; +using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Controls; +using EnvDTE; +using QtProjectLib; +using QtVsTools.Common; namespace QtVsTools.Wizards.ProjectWizard { - public class GuiWizard : IWizard - { - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var qtMoc = new StringBuilder(); - var serviceProvider = new ServiceProvider(automation as IServiceProvider); - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - - iVsUIShell.EnableModeless(0); - - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); - - try { - var className = replacements["$safeprojectname$"]; - className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty); - className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty); - var result = new Util.ClassNameValidationRule().Validate(className, null); - if (result != ValidationResult.ValidResult) - className = @"QtGuiApplication"; - - data.ClassName = className; - data.BaseClass = @"QMainWindow"; - data.ClassHeaderFile = className + @".h"; - data.ClassSourceFile = className + @".cpp"; - data.UiFile = data.ClassName + @".ui"; - data.QrcFile = data.ClassName + @".qrc"; - - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt GUI Application Wizard", - Message = @"This wizard generates a Qt GUI application project. The " - + @"application derives from QApplication and includes an empty " - + @"widget." + System.Environment.NewLine - + System.Environment.NewLine + "To continue, click Next.", - PreviousButtonEnabled = false, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ModulePage { - Data = data, - Header = @"Welcome to the Qt GUI Application Wizard", - Message = @"Select the modules you want to include in your project. The " - + @"recommended modules for this project are selected by default.", - PreviousButtonEnabled = true, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new GuiPage { - Data = data, - Header = @"Welcome to the Qt GUI Application Wizard", - Message = @"This wizard generates a Qt GUI application project. The " - + @"application derives from QApplication and includes an empty " - + @"widget.", - PreviousButtonEnabled = true, - NextButtonEnabled = false, - FinishButtonEnabled = data.DefaultModules.All(QtModuleInfo.IsInstalled), - CancelButtonEnabled = true - } - }) - { - Title = @"Qt GUI Application Wizard" - }; - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception("Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact - } - - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - - var vm = QtVersionManager.The(); - var vi = VersionInformation.Get(vm.GetInstallPath(vm.GetDefaultVersion())); - replacements["$Platform$"] = vi.GetVSPlatformName(); - - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - replacements["$DefaultQtVersion$"] = vm.GetDefaultVersion(); - replacements["$QtModules$"] = string.Join(";", data.Modules - .Select(moduleName => QtModules.Instance - .ModuleInformation(QtModules.Instance - .ModuleIdByName(moduleName)) - .proVarQT)); + using static EnumExt; - replacements["$classname$"] = data.ClassName; - replacements["$baseclass$"] = data.BaseClass; - replacements["$sourcefilename$"] = data.ClassSourceFile; - replacements["$headerfilename$"] = data.ClassHeaderFile; - replacements["$uifilename$"] = data.UiFile; - - replacements["$precompiledheader$"] = string.Empty; - replacements["$precompiledsource$"] = string.Empty; - replacements["$DefaultApplicationIcon$"] = string.Empty; - replacements["$centralwidget$"] = string.Empty; - - var strHeaderInclude = data.ClassHeaderFile; - if (data.UsePrecompiledHeader) { - strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile; - replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />"; - replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />"; - qtMoc.Append("<PrependInclude>stdafx.h</PrependInclude>"); - } - - replacements["$include$"] = strHeaderInclude; - replacements["$ui_hdr$"] = "ui_" + Path.GetFileNameWithoutExtension(data.UiFile) - + ".h"; - replacements["$qrcfilename$"] = data.QrcFile; - - if (data.BaseClass == "QMainWindow") { - replacements["$centralwidget$"] = - "\r\n <widget class=\"QMenuBar\" name=\"menuBar\" />" - + "\r\n <widget class=\"QToolBar\" name=\"mainToolBar\" />" - + "\r\n <widget class=\"QWidget\" name=\"centralWidget\" />" - + "\r\n <widget class=\"QStatusBar\" name=\"statusBar\" />"; - } - - if (data.AddDefaultAppIcon) - replacements["$DefaultApplicationIcon$"] = "<None Include=\"gui.ico\" />"; - - if (vi.isWinRT()) { - replacements["$QtWinRT$"] = "true"; - - var projDir = replacements["$destinationdirectory$"]; - - var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp"); - Directory.CreateDirectory(qmakeTmpDir); - - var dummyPro = Path.Combine(qmakeTmpDir, - string.Format("{0}.pro", replacements["$projectname$"])); - File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n"); - - var qmake = new QMake(null, dummyPro, false, vi); - qmake.RunQMake(); - - var assetsDir = Path.Combine(qmakeTmpDir, "assets"); - if (Directory.Exists(assetsDir)) - Directory.Move(assetsDir, Path.Combine(projDir, "assets")); + public class GuiWizard : ProjectTemplateWizard + { + protected override Options TemplateType => Options.Application | Options.GUISystem; - var manifestFile = Path.Combine(qmakeTmpDir, "Package.appxmanifest"); - if (File.Exists(manifestFile)) - File.Move(manifestFile, Path.Combine(projDir, "Package.appxmanifest")); + readonly Func<IWizardConfiguration, bool> whereConfigTargetIsWindowsStore + = (IWizardConfiguration config) => config.Target.EqualTo(ProjectTargets.WindowsStore); - var projFile = Path.Combine(qmakeTmpDir, - string.Format("{0}.vcxproj", replacements["$projectname$"])); + enum NewClass + { + [String("classname")] ClassName, + [String("baseclass")] BaseClass, + [String("sourcefilename")] SourceFileName, + [String("headerfilename")] HeaderFileName, + [String("include")] Include, + } - var proj = MsBuildProject.Load(projFile); - replacements["$MinimumVisualStudioVersion$"] = - proj.GetProperty("MinimumVisualStudioVersion"); - replacements["$ApplicationTypeRevision$"] = - proj.GetProperty("ApplicationTypeRevision"); - replacements["$WindowsTargetPlatformVersion$"] = - proj.GetProperty("WindowsTargetPlatformVersion"); - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; - replacements["$WindowsTargetPlatformMinVersion$"] = - proj.GetProperty("WindowsTargetPlatformMinVersion"); - replacements["$Link_TargetMachine$"] = - proj.GetProperty("Link", "TargetMachine"); + enum NewGuiProject + { + [String("centralwidget")] CentralWidget, + [String("qrcfilename")] QrcFileName, + [String("uifilename")] UiFileName, + [String("ui_hdr")] UiHeaderName, + } - Directory.Delete(qmakeTmpDir, true); + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { "QtCore", "QtGui", "QtWidgets" } + }); + + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt GUI Application Wizard") + { + new WizardIntroPage + { + Data = WizardData, + Header = @"Welcome to the Qt GUI Application Wizard", + Message = @"This wizard generates a Qt GUI application project. The " + + @"application derives from QApplication and includes an empty " + + @"widget." + System.Environment.NewLine + + System.Environment.NewLine + "To continue, click Next.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage + { + Data = WizardData, + Header = @"Welcome to the Qt GUI Application Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new GuiPage + { + Data = WizardData, + Header = @"Welcome to the Qt GUI Application Wizard", + Message = @"This wizard generates a Qt GUI application project. The " + + @"application derives from QApplication and includes an empty " + + @"widget.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true } -#if (VS2019 || VS2017 || VS2015) - else { - string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); - if (!string.IsNullOrEmpty(versionWin10SDK)) { - replacements["$WindowsTargetPlatformVersion$"] = versionWin10SDK; - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; - } - } - - if (qtMoc.Length > 0) - replacements["$QtMoc$"] = string.Format("<QtMoc>{0}</QtMoc>", qtMoc); - else - replacements["$QtMoc$"] = string.Empty; -#endif - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } + }); - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } + List<ItemDef> _ExtraItems; + protected override IEnumerable<ItemDef> ExtraItems => _ExtraItems; - iVsUIShell.EnableModeless(1); + public GuiWizard() + { + _ExtraItems = new List<ItemDef> + { + new ItemDef + { + ItemType = "AppxManifest", + Include = "Package.appxmanifest", + Filter = "Resource Files", + WhereConfig = whereConfigTargetIsWindowsStore + }, + new ItemDef + { + ItemType = "Image", + Include = "assets/logo_store.png", + Filter = "Resource Files", + WhereConfig = whereConfigTargetIsWindowsStore + }, + new ItemDef + { + ItemType = "Image", + Include = "assets/logo_620x300.png", + Filter = "Resource Files", + WhereConfig = whereConfigTargetIsWindowsStore + }, + new ItemDef + { + ItemType = "Image", + Include = "assets/logo_150x150.png", + Filter = "Resource Files", + WhereConfig = whereConfigTargetIsWindowsStore + }, + new ItemDef + { + ItemType = "Image", + Include = "assets/logo_44x44.png", + Filter = "Resource Files", + WhereConfig = whereConfigTargetIsWindowsStore + }, + }; } - public bool ShouldAddProjectItem(string filePath) + protected override void BeforeWizardRun() { - return true; + var className = Parameter[NewProject.SafeName]; + className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty); + className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty); + var result = new Util.ClassNameValidationRule().Validate(className, null); + if (result != ValidationResult.ValidResult) + className = @"QtGuiApplication"; + + WizardData.ClassName = className; + WizardData.BaseClass = @"QMainWindow"; + WizardData.ClassHeaderFile = className + @".h"; + WizardData.ClassSourceFile = className + @".cpp"; + WizardData.UiFile = WizardData.ClassName + @".ui"; + WizardData.QrcFile = WizardData.ClassName + @".qrc"; } - public void ProjectFinishedGenerating(Project project) + protected override void BeforeTemplateExpansion() { - var qtProject = QtProject.Create(project); - - var vm = QtVersionManager.The(); - var qtVersion = vm.GetDefaultVersion(); - var vi = VersionInformation.Get(vm.GetInstallPath(qtVersion)); - if (vi.GetVSPlatformName() != "Win32") - qtProject.SelectSolutionPlatform(vi.GetVSPlatformName()); - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - - var type = TemplateType.Application | TemplateType.GUISystem; - qtProject.WriteProjectBasicConfigurations(type, data.UsePrecompiledHeader); - - var vcProject = qtProject.VCProject; - var files = vcProject.GetFilesWithItemType(@"None") as IVCCollection; - foreach (var vcFile in files) - vcProject.RemoveFile(vcFile); - - if (data.UsePrecompiledHeader) { - qtProject.AddFileToProject(@"stdafx.cpp", Filters.SourceFiles()); - qtProject.AddFileToProject(@"stdafx.h", Filters.HeaderFiles()); + Parameter[NewClass.ClassName] = WizardData.ClassName; + Parameter[NewClass.BaseClass] = WizardData.BaseClass; + Parameter[NewClass.HeaderFileName] = WizardData.ClassHeaderFile; + Parameter[NewClass.SourceFileName] = WizardData.ClassSourceFile; + Parameter[NewGuiProject.UiFileName] = WizardData.UiFile; + + var include = new StringBuilder(); + include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + if (UsePrecompiledHeaders) + include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); + Parameter[NewClass.Include] = FormatParam(include); + + Parameter[NewGuiProject.UiHeaderName] = string.Format("ui_{0}.h", + Path.GetFileNameWithoutExtension(WizardData.UiFile)); + + Parameter[NewGuiProject.QrcFileName] = WizardData.QrcFile; + + if (WizardData.BaseClass == "QMainWindow") { + Parameter[NewGuiProject.CentralWidget] = FormatParam(@" + <widget class=""QMenuBar"" name=""menuBar"" /> + <widget class=""QToolBar"" name=""mainToolBar"" /> + <widget class=""QWidget"" name=""centralWidget"" /> + <widget class=""QStatusBar"" name=""statusBar"" />"); } - qtProject.AddFileToProject(data.ClassSourceFile, Filters.SourceFiles()); - qtProject.AddFileToProject(data.ClassHeaderFile, Filters.HeaderFiles()); - qtProject.AddFileToProject(data.UiFile, Filters.FormFiles()); - var qrc = qtProject.CreateQrcFile(data.ClassName, data.QrcFile); - qtProject.AddFileToProject(qrc, Filters.ResourceFiles()); - - if (data.AddDefaultAppIcon) { - try { - var icon = vcProject.ProjectDirectory + "\\" + vcProject.ItemName + ".ico"; - if (!File.Exists(icon)) { - File.Move(vcProject.ProjectDirectory + "\\gui.ico", icon); - var attribs = File.GetAttributes(icon); - File.SetAttributes(icon, attribs & (~FileAttributes.ReadOnly)); - } - - var rcFile = vcProject.ProjectDirectory + "\\" + vcProject.ItemName + ".rc"; - if (!File.Exists(rcFile)) { - FileStream fs = null; - try { - fs = File.Create(rcFile); - using (var sw = new StreamWriter(fs)) { - fs = null; - sw.WriteLine("IDI_ICON1\t\tICON\t\tDISCARDABLE\t\"" - + vcProject.ItemName + ".ico\"" + sw.NewLine); - } - } finally { - if (fs != null) - fs.Dispose(); - } - vcProject.AddFile(rcFile); - } - } catch { } + StringBuilder winRcFile = new StringBuilder(); + + if (WizardData.AddDefaultAppIcon) { + _ExtraItems.Add(new ItemDef + { + ItemType = "None", + Include = Parameter[NewProject.SafeName] + ".ico", + Filter = "Resource Files" + }); + var projectIcon = Path.Combine( + Parameter[NewProject.DestinationDirectory], + Parameter[NewProject.SafeName] + ".ico"); + var templateIcon = Path.Combine( + Parameter[NewProject.DestinationDirectory], + "gui.ico"); + if (!File.Exists(projectIcon)) { + File.Move(templateIcon, projectIcon); + File.SetAttributes(projectIcon, + File.GetAttributes(projectIcon) & (~FileAttributes.ReadOnly)); + } + winRcFile.AppendLine( + string.Format("IDI_ICON1\t\tICON\t\tDISCARDABLE\t\"{0}.ico", + /*{0}*/ Parameter[NewProject.SafeName])); } - foreach (VCFile file in (IVCCollection) qtProject.VCProject.Files) - qtProject.AdjustWhitespace(file.FullPath); - - qtProject.SetQtEnvironment(qtVersion); - qtProject.Finish(); // Collapses all project nodes. - } - - public void ProjectItemFinishedGenerating(ProjectItem projectItem) - { + if (winRcFile.Length > 0) { + _ExtraItems.Add(new ItemDef + { + ItemType = "ResourceCompile", + Include = Parameter[NewProject.SafeName] + ".rc", + Filter = "Resource Files" + }); + File.WriteAllText( + Path.Combine( + Parameter[NewProject.DestinationDirectory], + Parameter[NewProject.SafeName] + ".rc"), + winRcFile.ToString()); + } } - public void BeforeOpeningFile(ProjectItem projectItem) + protected override void OnProjectGenerated(Project project) { - } + var qtProject = QtProject.Create(project); + qtProject.CreateQrcFile(WizardData.ClassName, WizardData.QrcFile); + + IWizardConfiguration configWinRT = Configurations + .Where(whereConfigTargetIsWindowsStore) + .FirstOrDefault(); + + if (configWinRT != null) { + var versionInfo = VersionManager.GetVersionInfo(configWinRT.QtVersion); + var projDir = Parameter[NewProject.DestinationDirectory]; + var qmakeTmpDir = Path.Combine(projDir, "qmake_tmp"); + Directory.CreateDirectory(qmakeTmpDir); + + var dummyPro = Path.Combine(qmakeTmpDir, + string.Format("{0}.pro", Parameter[NewProject.SafeName])); + File.WriteAllText(dummyPro, "SOURCES = main.cpp\r\n"); + + var qmake = new QMake(null, dummyPro, false, versionInfo); + qmake.RunQMake(); + + var qmakeAssetsDir = Path.Combine(qmakeTmpDir, "assets"); + var projAssetsDir = Path.Combine(projDir, "assets"); + if (Directory.Exists(qmakeAssetsDir)) { + if (Directory.Exists(projAssetsDir)) + Directory.Delete(projAssetsDir, recursive: true); + Directory.Move(qmakeAssetsDir, projAssetsDir); + } - public void RunFinished() - { - } + var manifestFile = Path.Combine(qmakeTmpDir, "Package.appxmanifest"); + if (File.Exists(manifestFile)) { + File.Move(manifestFile, Path.Combine(projDir, "Package.appxmanifest")); + } - private readonly WizardData data = new WizardData - { - DefaultModules = new List<string> { - @"QtCore", @"QtGui", @"QtWidgets" + Directory.Delete(qmakeTmpDir, recursive: true); } - }; + } } } diff --git a/src/qtwizard/Wizards/ProjectWizard/Library/LibraryWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Library/LibraryWizard.cs index 819fefb1..4c98e7c5 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Library/LibraryWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Library/LibraryWizard.cs @@ -26,230 +26,117 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; +using System; using System.Collections.Generic; -using System.IO; -using System.Linq; using System.Text; using System.Text.RegularExpressions; using System.Windows.Controls; +using QtVsTools.Common; namespace QtVsTools.Wizards.ProjectWizard { - public class LibraryWizard : IWizard - { - public void BeforeOpeningFile(ProjectItem projectItem) - { - } - - public void ProjectFinishedGenerating(Project project) - { - var qtProject = QtProject.Create(project); - - QtVSIPSettings.SaveUicDirectory(project, null); - QtVSIPSettings.SaveMocDirectory(project, null); - QtVSIPSettings.SaveMocOptions(project, null); - QtVSIPSettings.SaveRccDirectory(project, null); - QtVSIPSettings.SaveLUpdateOnBuild(project); - QtVSIPSettings.SaveLUpdateOptions(project, null); - QtVSIPSettings.SaveLReleaseOptions(project, null); - - var vm = QtVersionManager.The(); - var qtVersion = vm.GetDefaultVersion(); - var vi = VersionInformation.Get(vm.GetInstallPath(qtVersion)); - if (vi.GetVSPlatformName() != "Win32") - qtProject.SelectSolutionPlatform(vi.GetVSPlatformName()); - - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - - var type = TemplateType.GUISystem | (data.CreateStaticLibrary - ? TemplateType.StaticLibrary : TemplateType.DynamicLibrary); - qtProject.WriteProjectBasicConfigurations(type, data.UsePrecompiledHeader); - - var vcProject = qtProject.VCProject; - var files = vcProject.GetFilesWithItemType(@"None") as IVCCollection; - foreach (var vcFile in files) - vcProject.RemoveFile(vcFile); - - if (data.UsePrecompiledHeader) { - qtProject.AddFileToProject(@"stdafx.cpp", Filters.SourceFiles()); - qtProject.AddFileToProject(@"stdafx.h", Filters.HeaderFiles()); - } + using static EnumExt; - foreach (VCFile file in (IVCCollection) qtProject.VCProject.Files) - qtProject.AdjustWhitespace(file.FullPath); - - qtProject.AddDefine(projectDefine, BuildConfig.Both); - if (data.CreateStaticLibrary) - qtProject.AddDefine("BUILD_STATIC", BuildConfig.Both); - - qtProject.SetQtEnvironment(qtVersion); - qtProject.Finish(); // Collapses all project nodes. - } - - public void ProjectItemFinishedGenerating(ProjectItem projectItem) - { - } + public class LibraryWizard : ProjectTemplateWizard + { + protected override Options TemplateType => Options.GUISystem + | (WizardData.CreateStaticLibrary ? Options.StaticLibrary : Options.DynamicLibrary); - public void RunFinished() + enum NewLibClass { + [String("classname")] ClassName, + [String("baseclass")] BaseClass, + [String("sourcefilename")] SourceFileName, + [String("headerfilename")] HeaderFileName, + [String("include")] Include, + [String("saveglobal")] GlobalHeader, + [String("pro_lib_define")] LibDefine, + [String("pro_lib_export")] LibExport, } - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var qtMoc = new StringBuilder(); - var serviceProvider = new ServiceProvider(automation as IServiceProvider); - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - - iVsUIShell.EnableModeless(0); - - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); - - var safeprojectname = replacements["$safeprojectname$"]; - safeprojectname = Regex.Replace(safeprojectname, @"[^a-zA-Z0-9_]", string.Empty); - safeprojectname = Regex.Replace(safeprojectname, @"^[\d-]*\s*", string.Empty); - var result = new Util.ClassNameValidationRule().Validate(safeprojectname, null); - if (result != ValidationResult.ValidResult) - safeprojectname = @"QtClassLibrary"; - - try { - data.ClassName = safeprojectname; - data.ClassHeaderFile = safeprojectname + @".h"; - data.ClassSourceFile = safeprojectname + @".cpp"; - - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt Class Library Wizard", - Message = @"This wizard generates a Qt Class Library project. The " - + @"resulting library is linked dynamically with Qt." - + System.Environment.NewLine + System.Environment.NewLine - + @"To continue, click Next.", - PreviousButtonEnabled = false, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ModulePage { - Data = data, - Header = @"Welcome to the Qt Class Library Wizard", - Message = @"Select the modules you want to include in your project. The " - + @"recommended modules for this project are selected by default.", - PreviousButtonEnabled = true, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new LibraryClassPage { - Data = data, - Header = @"Welcome to the Qt Class Library Wizard", - Message = @"This wizard generates a Qt Class Library project. The " - + @"resulting library is linked dynamically with Qt.", - PreviousButtonEnabled = true, - NextButtonEnabled = false, - FinishButtonEnabled = QtModuleInfo.IsInstalled(@"QtCore"), - CancelButtonEnabled = true - } - }) - { - Title = @"Qt Class Library Wizard" - }; - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception(@"Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact - } - - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - - var vm = QtVersionManager.The(); - var vi = VersionInformation.Get(vm.GetInstallPath(vm.GetDefaultVersion())); - replacements["$Platform$"] = vi.GetVSPlatformName(); - - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - replacements["$DefaultQtVersion$"] = vm.GetDefaultVersion(); - replacements["$QtModules$"] = string.Join(";", data.Modules - .Select(moduleName => QtModules.Instance - .ModuleInformation(QtModules.Instance - .ModuleIdByName(moduleName)) - .proVarQT)); - - replacements["$classname$"] = data.ClassName; - replacements["$sourcefilename$"] = data.ClassSourceFile; - replacements["$headerfilename$"] = data.ClassHeaderFile; - - replacements["$precompiledheader$"] = string.Empty; - replacements["$precompiledsource$"] = string.Empty; - - var strHeaderInclude = data.ClassHeaderFile; - if (data.UsePrecompiledHeader) { - strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile; - replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />"; - replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />"; - qtMoc.Append("<PrependInclude>stdafx.h</PrependInclude>"); + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { "QtCore" } + }); + + List<string> _ExtraDefines = new List<string>(); + protected override IEnumerable<string> ExtraDefines => _ExtraDefines; + + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt Class Library Wizard") + { + new WizardIntroPage { + Data = WizardData, + Header = @"Welcome to the Qt Class Library Wizard", + Message = @"This wizard generates a Qt Class Library project. The " + + @"resulting library is linked dynamically with Qt." + + System.Environment.NewLine + System.Environment.NewLine + + @"To continue, click Next.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage { + Data = WizardData, + Header = @"Welcome to the Qt Class Library Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new LibraryClassPage { + Data = WizardData, + Header = @"Welcome to the Qt Class Library Wizard", + Message = @"This wizard generates a Qt Class Library project. The " + + @"resulting library is linked dynamically with Qt.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true } + }); - replacements["$include$"] = strHeaderInclude; - replacements["$saveglobal$"] = safeprojectname.ToLower(); - - projectDefine = safeprojectname.ToUpper() + @"_LIB"; - replacements["$pro_lib_define$"] = projectDefine; - replacements["$pro_lib_export$"] = safeprojectname.ToUpper() + @"_EXPORT"; - - if (vi.isWinRT()) - replacements["$QtWinRT$"] = "true"; - -#if (VS2019 || VS2017 || VS2015) - string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); - if (!string.IsNullOrEmpty(versionWin10SDK)) { - replacements["$WindowsTargetPlatformVersion$"] = versionWin10SDK; - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; - } -#endif - - if (qtMoc.Length > 0) - replacements["$QtMoc$"] = string.Format("<QtMoc>{0}</QtMoc>", qtMoc); - else - replacements["$QtMoc$"] = string.Empty; - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } - - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } - - iVsUIShell.EnableModeless(1); - } - - public bool ShouldAddProjectItem(string filePath) + protected override void BeforeWizardRun() { - return true; + var safeprojectname = Parameter[NewProject.SafeName]; + safeprojectname = Regex.Replace(safeprojectname, @"[^a-zA-Z0-9_]", string.Empty); + safeprojectname = Regex.Replace(safeprojectname, @"^[\d-]*\s*", string.Empty); + var result = new Util.ClassNameValidationRule().Validate(safeprojectname, null); + if (result != ValidationResult.ValidResult) + safeprojectname = @"QtClassLibrary"; + + WizardData.ClassName = safeprojectname; + WizardData.ClassHeaderFile = safeprojectname + @".h"; + WizardData.ClassSourceFile = safeprojectname + @".cpp"; } - private string projectDefine; - private readonly WizardData data = new WizardData + protected override void BeforeTemplateExpansion() { - DefaultModules = new List<string> { @"QtCore" } - }; + Parameter[NewLibClass.ClassName] = WizardData.ClassName; + Parameter[NewLibClass.HeaderFileName] = WizardData.ClassHeaderFile; + Parameter[NewLibClass.SourceFileName] = WizardData.ClassSourceFile; + + var include = new StringBuilder(); + include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + if (UsePrecompiledHeaders) + include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); + Parameter[NewLibClass.Include] = FormatParam(include); + + var safeprojectname = Parameter[NewProject.SafeName]; + Parameter[NewLibClass.GlobalHeader] = safeprojectname.ToLower(); + Parameter[NewLibClass.LibDefine] = safeprojectname.ToUpper() + "_LIB"; + Parameter[NewLibClass.LibExport] = safeprojectname.ToUpper() + "_EXPORT"; + + _ExtraDefines.Add(Parameter[NewLibClass.LibDefine]); + if (WizardData.CreateStaticLibrary) + _ExtraDefines.Add("BUILD_STATIC"); + } } } diff --git a/src/qtwizard/Wizards/ProjectWizard/Server/ServerWizard.cs b/src/qtwizard/Wizards/ProjectWizard/Server/ServerWizard.cs index fca08f00..3f1f40d9 100644 --- a/src/qtwizard/Wizards/ProjectWizard/Server/ServerWizard.cs +++ b/src/qtwizard/Wizards/ProjectWizard/Server/ServerWizard.cs @@ -26,249 +26,142 @@ ** ****************************************************************************/ -using EnvDTE; -using Microsoft.Internal.VisualStudio.PlatformUI; -using Microsoft.VisualStudio.OLE.Interop; -using Microsoft.VisualStudio.Shell; -using Microsoft.VisualStudio.Shell.Interop; -using Microsoft.VisualStudio.TemplateWizard; -using Microsoft.VisualStudio.VCProjectEngine; -using QtProjectLib; -using QtVsTools.VisualStudio; using System.Collections.Generic; using System.IO; -using System.Linq; using System.Text; +using System.Text.RegularExpressions; using System.Windows.Controls; -using System.Windows.Forms; +using EnvDTE; +using QtProjectLib; +using QtVsTools.Common; namespace QtVsTools.Wizards.ProjectWizard { - public class ServerWizard : IWizard - { - public void BeforeOpeningFile(ProjectItem projectItem) - { - } - - public void ProjectFinishedGenerating(Project project) - { - var qtProject = QtProject.Create(project); - - QtVSIPSettings.SaveUicDirectory(project, null); - QtVSIPSettings.SaveMocDirectory(project, null); - QtVSIPSettings.SaveMocOptions(project, null); - QtVSIPSettings.SaveRccDirectory(project, null); - QtVSIPSettings.SaveLUpdateOnBuild(project); - QtVSIPSettings.SaveLUpdateOptions(project, null); - QtVSIPSettings.SaveLReleaseOptions(project, null); - - var vm = QtVersionManager.The(); - var qtVersion = vm.GetDefaultVersion(); - var vi = VersionInformation.Get(vm.GetInstallPath(qtVersion)); - if (vi.GetVSPlatformName() != "Win32") - qtProject.SelectSolutionPlatform(vi.GetVSPlatformName()); + using static EnumExt; - qtProject.MarkAsQtProject(); - qtProject.AddDirectories(); - - var type = TemplateType.DynamicLibrary | TemplateType.GUISystem; - qtProject.WriteProjectBasicConfigurations(type, data.UsePrecompiledHeader); - - var vcProject = qtProject.VCProject; - var files = vcProject.GetFilesWithItemType(@"None") as IVCCollection; - foreach (var vcFile in files) - vcProject.RemoveFile(vcFile); - - if (data.UsePrecompiledHeader) { - qtProject.AddFileToProject(@"stdafx.cpp", Filters.SourceFiles()); - qtProject.AddFileToProject(@"stdafx.h", Filters.HeaderFiles()); - } - - qtProject.AddFileToProject(data.ClassSourceFile, Filters.SourceFiles()); - qtProject.AddFileToProject(data.ClassHeaderFile, Filters.HeaderFiles()); - qtProject.AddFileToProject(data.UiFile, Filters.FormFiles()); - qtProject.AddFileToProject(safeprojectname + @".rc", null); - qtProject.AddFileToProject(safeprojectname + @".ico", null); - qtProject.AddFileToProject(safeprojectname + @".def", Filters.SourceFiles()); - - qtProject.AddActiveQtBuildStep(@"1.0", safeprojectname + @".def"); - - foreach (VCFile file in (IVCCollection) qtProject.VCProject.Files) - qtProject.AdjustWhitespace(file.FullPath); - - qtProject.SetQtEnvironment(qtVersion); - qtProject.Finish(); // Collapses all project nodes. - } + public class ServerWizard : ProjectTemplateWizard + { + protected override Options TemplateType => Options.DynamicLibrary | Options.GUISystem; - public void ProjectItemFinishedGenerating(ProjectItem projectItem) + enum NewClass { + [String("classname")] ClassName, + [String("sourcefilename")] SourceFileName, + [String("headerfilename")] HeaderFileName, + [String("include")] Include, } - public void RunFinished() + enum NewActiveQtProject { + [String("pro_name")] Name, + [String("uifilename")] UiFileName, + [String("ui_hdr")] UiHeaderName, } - public void RunStarted(object automation, Dictionary<string, string> replacements, - WizardRunKind runKind, object[] customParams) - { - var qtMoc = new StringBuilder(); - var serviceProvider = new ServiceProvider(automation as IServiceProvider); - var iVsUIShell = VsServiceProvider.GetService<SVsUIShell, IVsUIShell>(); - - iVsUIShell.EnableModeless(0); - - var versionMgr = QtVersionManager.The(); - var versionName = versionMgr.GetDefaultVersion(); - var versionInfo = VersionInformation.Get(versionMgr.GetInstallPath(versionName)); - if (versionInfo.isWinRT()) { - MessageBox.Show( - string.Format( - "The Qt ActiveQt Server project type is not available\r\n" + - "for the currently selected Qt version ({0}).", versionName), - "Project Type Not Available", MessageBoxButtons.OK, MessageBoxIcon.Error); - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); - } - - try { - System.IntPtr hwnd; - iVsUIShell.GetDialogOwnerHwnd(out hwnd); - - try { - // midl.exe does not support spaces in project name. Fails while generating the - // IDL file (library attribute), e.g. 'library Active QtServer1Lib' is illegal. - if (replacements["$safeprojectname$"].Contains(" ")) - throw new QtVSException("Project name shall not contain spaces."); - - safeprojectname = replacements["$safeprojectname$"]; - var result = new Util.ClassNameValidationRule().Validate(safeprojectname, null); - if (result != ValidationResult.ValidResult) - safeprojectname = @"ActiveQtServer"; - - data.ClassName = safeprojectname; - data.ClassHeaderFile = safeprojectname + @".h"; - data.ClassSourceFile = safeprojectname + @".cpp"; - data.UiFile = data.ClassName + @".ui"; - - var wizard = new WizardWindow(new List<WizardPage> { - new WizardIntroPage { - Data = data, - Header = @"Welcome to the Qt ActiveQt Server Wizard", - Message = @"This wizard generates a Qt ActiveQt server project. It " - + @"creates a simple ActiveQt widget with the required files." - + System.Environment.NewLine + System.Environment.NewLine - + "To continue, click Next.", - PreviousButtonEnabled = false, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ModulePage { - Data = data, - Header = @"Welcome to the Qt ActiveQt Server Wizard", - Message = @"Select the modules you want to include in your project. The " - + @"recommended modules for this project are selected by default.", - PreviousButtonEnabled = true, - NextButtonEnabled = true, - FinishButtonEnabled = false, - CancelButtonEnabled = true - }, - new ServerPage { - Data = data, - Header = @"Welcome to the Qt ActiveQt Server Wizard", - Message = @"This wizard generates a Qt ActiveQt server project. It " - + @"creates a simple ActiveQt widget with the required files.", - PreviousButtonEnabled = true, - NextButtonEnabled = false, - FinishButtonEnabled = data.DefaultModules.All(QtModuleInfo.IsInstalled), - CancelButtonEnabled = true - } - }) - { - Title = @"Qt ActiveQt Server Wizard" - }; - - WindowHelper.ShowModal(wizard, hwnd); - if (!wizard.DialogResult.HasValue || !wizard.DialogResult.Value) - throw new System.Exception("Unexpected wizard return value."); - } catch (QtVSException exception) { - Messages.DisplayErrorMessage(exception.Message); - throw; // re-throw, but keep the original exception stack intact - } - - var version = (automation as DTE).Version; - replacements["$ToolsVersion$"] = version; - - replacements["$Platform$"] = versionInfo.GetVSPlatformName(); - - replacements["$Keyword$"] = Resources.qtProjectKeyword; - replacements["$ProjectGuid$"] = HelperFunctions.NewProjectGuid(); - replacements["$PlatformToolset$"] = BuildConfig.PlatformToolset(version); - replacements["$DefaultQtVersion$"] = versionName; - replacements["$QtModules$"] = string.Join(";", data.Modules - .Select(moduleName => QtModules.Instance - .ModuleInformation(QtModules.Instance - .ModuleIdByName(moduleName)) - .proVarQT)); - - replacements["$classname$"] = data.ClassName; - replacements["$sourcefilename$"] = data.ClassSourceFile; - replacements["$headerfilename$"] = data.ClassHeaderFile; - replacements["$uifilename$"] = data.UiFile; - - replacements["$precompiledheader$"] = string.Empty; - replacements["$precompiledsource$"] = string.Empty; - var strHeaderInclude = data.ClassHeaderFile; - if (data.UsePrecompiledHeader) { - strHeaderInclude = "stdafx.h\"\r\n#include \"" + data.ClassHeaderFile; - replacements["$precompiledheader$"] = "<None Include=\"stdafx.h\" />"; - replacements["$precompiledsource$"] = "<None Include=\"stdafx.cpp\" />"; - qtMoc.Append("<PrependInclude>stdafx.h</PrependInclude>"); + WizardData _WizardData; + protected override WizardData WizardData => _WizardData + ?? (_WizardData = new WizardData + { + DefaultModules = new List<string> { "QtCore", "QtGui", "QtWidgets", "QtAxServer" } + }); + + WizardWindow _WizardWindow; + protected override WizardWindow WizardWindow => _WizardWindow + ?? (_WizardWindow = new WizardWindow(title: "Qt ActiveQt Server Wizard") + { + new WizardIntroPage { + Data = WizardData, + Header = @"Welcome to the Qt ActiveQt Server Wizard", + Message = @"This wizard generates a Qt ActiveQt server project. It " + + @"creates a simple ActiveQt widget with the required files." + + System.Environment.NewLine + System.Environment.NewLine + + "To continue, click Next.", + PreviousButtonEnabled = false, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true + }, + new ConfigPage { + Data = WizardData, + Header = @"Welcome to the Qt GUI Application Wizard", + Message = + @"Setup the configurations you want to include in your project. " + + @"The recommended settings for this project are selected by default.", + PreviousButtonEnabled = true, + NextButtonEnabled = true, + FinishButtonEnabled = false, + CancelButtonEnabled = true, + ValidateConfigs = ValidateConfigsForActiveQtServer + }, + new ServerPage { + Data = WizardData, + Header = @"Welcome to the Qt ActiveQt Server Wizard", + Message = @"This wizard generates a Qt ActiveQt server project. It " + + @"creates a simple ActiveQt widget with the required files.", + PreviousButtonEnabled = true, + NextButtonEnabled = false, + FinishButtonEnabled = true, + CancelButtonEnabled = true } + }); - replacements["$include$"] = strHeaderInclude; - replacements["$ui_hdr$"] = "ui_" + Path.GetFileNameWithoutExtension(data.UiFile) - + ".h"; - - safeprojectname = data.LowerCaseFileNames ? safeprojectname.ToLower() : safeprojectname; - replacements["$pro_name$"] = safeprojectname; - -#if (VS2019 || VS2017 || VS2015) - string versionWin10SDK = HelperFunctions.GetWindows10SDKVersion(); - if (!string.IsNullOrEmpty(versionWin10SDK)) { - replacements["$WindowsTargetPlatformVersion$"] = versionWin10SDK; - replacements["$isSet_WindowsTargetPlatformVersion$"] = "true"; + string ValidateConfigsForActiveQtServer(IEnumerable<IWizardConfiguration> configs) + { + foreach (var config in configs) { + if (config.Target.EqualTo(ProjectTargets.WindowsStore)) { + return string.Format( + "ActiveQt Server project not available for the '{0}' target.", + config.Target); } -#endif - - if (qtMoc.Length > 0) - replacements["$QtMoc$"] = string.Format("<QtMoc>{0}</QtMoc>", qtMoc); - else - replacements["$QtMoc$"] = string.Empty; - } catch { - try { - Directory.Delete(replacements["$destinationdirectory$"]); - Directory.Delete(replacements["$solutiondirectory$"]); - } catch { } - - iVsUIShell.EnableModeless(1); - throw new WizardBackoutException(); } + return string.Empty; + } - iVsUIShell.EnableModeless(1); + protected override void BeforeWizardRun() + { + // midl.exe does not support spaces in project name. Fails while generating the + // IDL file (library attribute), e.g. 'library Active QtServer1Lib' is illegal. + if (Parameter[NewProject.SafeName].Contains(" ")) + throw new QtVSException("Project name shall not contain spaces."); + + var className = Parameter[NewProject.SafeName]; + className = Regex.Replace(className, @"[^a-zA-Z0-9_]", string.Empty); + className = Regex.Replace(className, @"^[\d-]*\s*", string.Empty); + var result = new Util.ClassNameValidationRule().Validate(className, null); + if (result != ValidationResult.ValidResult) + className = @"ActiveQtServer"; + + WizardData.ClassName = className; + WizardData.ClassHeaderFile = className + @".h"; + WizardData.ClassSourceFile = className + @".cpp"; + WizardData.UiFile = WizardData.ClassName + @".ui"; } - public bool ShouldAddProjectItem(string filePath) + protected override void BeforeTemplateExpansion() { - return true; + Parameter[NewClass.ClassName] = WizardData.ClassName; + Parameter[NewClass.HeaderFileName] = WizardData.ClassHeaderFile; + Parameter[NewClass.SourceFileName] = WizardData.ClassSourceFile; + Parameter[NewActiveQtProject.UiFileName] = WizardData.UiFile; + + var include = new StringBuilder(); + include.AppendLine(string.Format("#include \"{0}\"", WizardData.ClassHeaderFile)); + if (UsePrecompiledHeaders) + include.AppendLine(string.Format("#include \"{0}\"", PrecompiledHeader.Include)); + Parameter[NewClass.Include] = FormatParam(include); + + Parameter[NewActiveQtProject.UiHeaderName] = string.Format("ui_{0}.h", + Path.GetFileNameWithoutExtension(WizardData.UiFile)); + + Parameter[NewActiveQtProject.Name] = WizardData.LowerCaseFileNames + ? Parameter[NewProject.SafeName].ToLower() + : Parameter[NewProject.SafeName]; } - private string safeprojectname; - private readonly WizardData data = new WizardData + protected override void OnProjectGenerated(Project project) { - DefaultModules = new List<string> { - @"QtCore", @"QtGui", @"QtWidgets", @"QtAxServer" - } - }; + var qtProject = QtProject.Create(project); + qtProject.AddActiveQtBuildStep("1.0", Parameter[NewProject.SafeName] + ".def"); + } } } |