diff options
author | Ian Toal <iantoal@microsoft.com> | 2020-01-22 18:41:58 +0300 |
---|---|---|
committer | Ian Toal <iantoal@microsoft.com> | 2020-01-23 20:02:25 +0300 |
commit | 0fabda6d4bc8b11e99397ee5e754f3286631272f (patch) | |
tree | 9ffcecfd09514d4a6084c079b7e45835d41d0da5 | |
parent | 920025c73b124cfb7011ec7e615ff75aa1a3f0a8 (diff) |
Enable authentication support in New Project Dialog for Asp.Net Core templates which support it
8 files changed, 261 insertions, 84 deletions
diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/GtkDotNetCoreProjectTemplateWizardPageWidget.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/GtkDotNetCoreProjectTemplateWizardPageWidget.cs index 8d0a2d02e8..fc20505330 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/GtkDotNetCoreProjectTemplateWizardPageWidget.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Gui/GtkDotNetCoreProjectTemplateWizardPageWidget.cs @@ -49,16 +49,24 @@ namespace MonoDevelop.DotNetCore.Gui EventBox configurationTopEventBox; EventBox configurationTableEventBox; Table configurationTable; + ComboBox targetFrameworkComboBox; Label targetFrameworkInformationLabel; Label targetFrameworkLabel; + + ComboBox authenticationComboBox; + Label authenticationInformationLabel; + Label authenticationLabel; + EventBox configurationBottomEventBox; EventBox backgroundLargeImageEventBox; VBox backgroundLargeImageVBox; - public GtkDotNetCoreProjectTemplateWizardPageWidget () + public GtkDotNetCoreProjectTemplateWizardPageWidget (DotNetCoreProjectTemplateWizardPage wizardPage) { - this.Build (); + this.wizardPage = wizardPage; + + Build (); // Do not use a width request for the configuration box so the left hand side of the // wizard page can expand to fit its contents. @@ -77,14 +85,16 @@ namespace MonoDevelop.DotNetCore.Gui configurationTableEventBox.ModifyBg (StateType.Normal, backgroundColor); configurationBottomEventBox.ModifyBg (StateType.Normal, backgroundColor); backgroundLargeImageEventBox.ModifyBg (StateType.Normal, backgroundColor); - } - internal GtkDotNetCoreProjectTemplateWizardPageWidget (DotNetCoreProjectTemplateWizardPage wizardPage) - : this () - { - this.wizardPage = wizardPage; - PopulateTargetFrameworks (); - targetFrameworkComboBox.Changed += TargetFrameworkComboBoxChanged; + if (wizardPage.TargetFrameworks.Count > 1) { + PopulateTargetFrameworks (); + targetFrameworkComboBox.Changed += TargetFrameworkComboBoxChanged; + } + + if (wizardPage.SupportedAuthentications.Count > 0) { + PopulateAuthentications (); + authenticationComboBox.Changed += AuthenticationsComboBoxChanged; + } } void PopulateTargetFrameworks () @@ -101,10 +111,24 @@ namespace MonoDevelop.DotNetCore.Gui wizardPage.SelectedTargetFrameworkIndex = targetFrameworkComboBox.Active; } + void PopulateAuthentications () + { + foreach (var authentication in wizardPage.SupportedAuthentications) { + authenticationComboBox.AppendText (authentication.Description); + } + + authenticationComboBox.Active = wizardPage.SelectedAuthenticationIndex; + } + + void AuthenticationsComboBoxChanged (object sender, EventArgs e) + { + wizardPage.SelectedAuthenticationIndex = authenticationComboBox.Active; + } + protected virtual void Build () { MonoDevelop.Components.Gui.Initialize (this); - BinContainer.Attach (this); + MonoDevelop.Components.BinContainer.Attach (this); Name = "MonoDevelop.DotNetCore.Gui.GtkDotNetCoreProjectTemplateWizardPageWidget"; @@ -134,11 +158,62 @@ namespace MonoDevelop.DotNetCore.Gui configurationTableEventBox = new EventBox (); configurationTableEventBox.Name = "configurationTableEventBox"; - configurationTable = new Table (2, 3, false); + var showFrameworkSelection = wizardPage.TargetFrameworks.Count > 1; + var showAuthenticationSelection = wizardPage.SupportedAuthentications.Count > 0; + + uint tableRows = (uint)(showFrameworkSelection && showAuthenticationSelection ? 4 : 2); + configurationTable = new Table (tableRows, 3, false); configurationTable.Name = "configurationTable"; configurationTable.RowSpacing = 7; configurationTable.ColumnSpacing = 6; + if (showFrameworkSelection) + AddFrameworkSelection (); + + if (showAuthenticationSelection) + AddAuthenticationSelection ((uint)(showFrameworkSelection ? 2 : 0)); + + configurationTableEventBox.Add (configurationTable); + configurationVBox.Add (configurationTableEventBox); + + var w7 = (Box.BoxChild)configurationVBox [configurationTableEventBox]; + w7.Position = 1; + w7.Expand = false; + w7.Fill = false; + + configurationBottomEventBox = new EventBox (); + configurationBottomEventBox.Name = "configurationBottomEventBox"; + configurationVBox.Add (configurationBottomEventBox); + + var w8 = (Box.BoxChild)configurationVBox [configurationBottomEventBox]; + w8.Position = 2; + mainHBox.Add (configurationVBox); + + var w9 = (Box.BoxChild)mainHBox [configurationVBox]; + w9.Position = 1; + + backgroundLargeImageEventBox = new EventBox (); + backgroundLargeImageEventBox.Name = "backgroundLargeImageEventBox"; + + backgroundLargeImageVBox = new VBox (); + backgroundLargeImageVBox.Name = "backgroundLargeImageVBox"; + backgroundLargeImageEventBox.Add (backgroundLargeImageVBox); + mainHBox.Add (backgroundLargeImageEventBox); + + var w11 = (Box.BoxChild)mainHBox [backgroundLargeImageEventBox]; + w11.Position = 2; + + Add (mainHBox); + + if (Child != null) { + Child.ShowAll (); + } + + Hide (); + } + + void AddFrameworkSelection() + { targetFrameworkComboBox = ComboBox.NewText (); targetFrameworkComboBox.WidthRequest = 250; targetFrameworkComboBox.Name = "targetFrameworkComboBox"; @@ -180,44 +255,55 @@ namespace MonoDevelop.DotNetCore.Gui w5.BottomAttach = 2; w5.XOptions = (AttachOptions)4; w5.YOptions = (AttachOptions)4; + } - configurationTableEventBox.Add (configurationTable); - configurationVBox.Add (configurationTableEventBox); - - var w7 = (Box.BoxChild)configurationVBox [configurationTableEventBox]; - w7.Position = 1; - w7.Expand = false; - w7.Fill = false; - - configurationBottomEventBox = new EventBox (); - configurationBottomEventBox.Name = "configurationBottomEventBox"; - configurationVBox.Add (configurationBottomEventBox); - - var w8 = (Box.BoxChild)configurationVBox [configurationBottomEventBox]; - w8.Position = 2; - mainHBox.Add (configurationVBox); - - var w9 = (Box.BoxChild)mainHBox [configurationVBox]; - w9.Position = 1; - - backgroundLargeImageEventBox = new EventBox (); - backgroundLargeImageEventBox.Name = "backgroundLargeImageEventBox"; - - backgroundLargeImageVBox = new VBox (); - backgroundLargeImageVBox.Name = "backgroundLargeImageVBox"; - backgroundLargeImageEventBox.Add (backgroundLargeImageVBox); - mainHBox.Add (backgroundLargeImageEventBox); - - var w11 = (Box.BoxChild)mainHBox [backgroundLargeImageEventBox]; - w11.Position = 2; - - Add (mainHBox); - - if (Child != null) { - Child.ShowAll (); - } - - Hide (); + void AddAuthenticationSelection(uint primaryRow) + { + authenticationComboBox = ComboBox.NewText (); + authenticationComboBox.WidthRequest = 250; + authenticationComboBox.Name = "authenticationComboBox"; + configurationTable.Add (authenticationComboBox); + + var authenticationComboBoxCell = (Table.TableChild)configurationTable [authenticationComboBox]; + authenticationComboBoxCell.TopAttach = primaryRow; + authenticationComboBoxCell.BottomAttach = primaryRow + 1; + authenticationComboBoxCell.LeftAttach = 1; + authenticationComboBoxCell.RightAttach = 2; + authenticationComboBoxCell.XOptions = (AttachOptions)4; + authenticationComboBoxCell.YOptions = (AttachOptions)4; + + authenticationInformationLabel = new Label (); + authenticationInformationLabel.Name = "authenticationInformationLabel"; + authenticationInformationLabel.Xpad = 5; + authenticationInformationLabel.Xalign = 0F; + authenticationInformationLabel.LabelProp = GettextCatalog.GetString ("TODO: Make this dynamic."); + authenticationInformationLabel.Justify = (Justification)1; + configurationTable.Add (authenticationInformationLabel); + + var authenticationInformationLabelCell = (Table.TableChild)configurationTable [authenticationInformationLabel]; + authenticationInformationLabelCell.TopAttach = primaryRow + 1; + authenticationInformationLabelCell.BottomAttach = primaryRow + 2; + authenticationInformationLabelCell.LeftAttach = 1; + authenticationInformationLabelCell.RightAttach = 2; + authenticationInformationLabelCell.XOptions = (AttachOptions)4; + authenticationInformationLabelCell.YOptions = (AttachOptions)4; + + authenticationLabel = new Label (); + authenticationLabel.WidthRequest = 132; + authenticationLabel.Name = "authenticationLabel"; + authenticationLabel.Xpad = 5; + authenticationLabel.Xalign = 1F; + authenticationLabel.LabelProp = GettextCatalog.GetString ("Authentication:"); + authenticationLabel.Justify = (Justification)1; + configurationTable.Add (authenticationLabel); + + var authenticationLabelCell = (Table.TableChild)configurationTable [authenticationLabel]; + authenticationLabelCell.TopAttach = primaryRow; + authenticationLabelCell.BottomAttach = primaryRow + 1; + authenticationLabelCell.LeftAttach = 0; + authenticationLabelCell.RightAttach = 1; + authenticationLabelCell.XOptions = (AttachOptions)4; + authenticationLabelCell.YOptions = (AttachOptions)4; } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateParameters.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateParameters.cs new file mode 100644 index 0000000000..d4f82b589e --- /dev/null +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateParameters.cs @@ -0,0 +1,72 @@ +// +// DotNetCoreTemplate.cs +// +// Author: +// iantoal <iantoal@microsoft.com> +// +// Copyright (c) 2020 Microsoft +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. +using System; +using System.Collections.Generic; +using System.Linq; +using MonoDevelop.Ide; +using MonoDevelop.Ide.Templates; + +namespace MonoDevelop.DotNetCore.Templating +{ + public class AuthenticationParameter + { + static readonly string [] supportedParameters = new string [] { "None", "Individual" }; + + public static readonly string ParameterName = "auth"; + + public string Name { get; private set; } + + public string Description { get; private set; } + + public AuthenticationParameter(string name, string description) + { + Name = name; + Description = description; + } + + public static IList<AuthenticationParameter> CreateSupportedParameterList(IReadOnlyDictionary<string, string> parameterChoices) + { + return parameterChoices.Where(choice => supportedParameters.Contains(choice.Key)) + .Select(parameter => new AuthenticationParameter(parameter.Key, parameter.Value)) + .ToList (); + } + } + + public class DotNetCoreProjectTemplateParameters + { + public static IList<AuthenticationParameter> GetAuthenticationParameters (string templateId) + { + if (IdeServices.TemplatingService.GetSolutionTemplate (templateId) is MicrosoftTemplateEngineSolutionTemplate template){ + if (template.IsSupportedParameter (AuthenticationParameter.ParameterName)) { + var supportedAuth = template.GetParameterChoices (AuthenticationParameter.ParameterName); + return AuthenticationParameter.CreateSupportedParameterList (supportedAuth); + } + } + + return new List<AuthenticationParameter> (); + } + } +} diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs index 41e3ce3b1e..6d213a5823 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizard.cs @@ -28,7 +28,6 @@ using System.Collections.Generic; using System.Linq; using MonoDevelop.Core.Assemblies; using MonoDevelop.Ide.Templates; -using MonoDevelop.Projects; namespace MonoDevelop.DotNetCore.Templating { @@ -42,7 +41,7 @@ namespace MonoDevelop.DotNetCore.Templating public override WizardPage GetPage (int pageNumber) { - var page = new DotNetCoreProjectTemplateWizardPage (this, targetFrameworks); + var page = new DotNetCoreProjectTemplateWizardPage (this, targetFrameworks, SupportedAuthentications); targetFrameworks = null; return page; } @@ -53,18 +52,21 @@ namespace MonoDevelop.DotNetCore.Templating internal IList<TargetFramework> TargetFrameworks => targetFrameworks; - /// <summary> - /// When only .NET Core 2.0 is installed there is only one option in the drop down - /// list for the target framework for .NET Core projects so there is no point in displaying - /// the wizard since nothing can be changed. If .NET Core 1.0 is installed then there is at - /// least two options available. If the .NET Standard project template is selected then there - /// are multiple options available. So here a check is made to see if more than one target - /// framework is available. If not then the wizard will not be displayed. - /// </summary> - int GetTotalPages () + internal IList<AuthenticationParameter> SupportedAuthentications { get; private set; } + + /// <summary> + /// When only .NET Core 2.0 is installed there is only one option in the drop down + /// list for the target framework for .NET Core projects so there is no point in displaying + /// the wizard since nothing can be changed. If .NET Core 1.0 is installed then there is at + /// least two options available. If the .NET Standard project template is selected then there + /// are multiple options available. So here a check is made to see if more than one target + /// framework is available. If not then the wizard will not be displayed. + /// </summary> + int GetTotalPages () { + GetSupportedAuthentifications (); GetTargetFrameworks (); - if (targetFrameworks.Count > 1) + if (targetFrameworks.Count > 1 || SupportedAuthentications.Any()) return 1; ConfigureDefaultParameters (); @@ -72,6 +74,12 @@ namespace MonoDevelop.DotNetCore.Templating return 0; } + void GetSupportedAuthentifications () + { + var templateId = Parameters ["TemplateId"]; + SupportedAuthentications = DotNetCoreProjectTemplateParameters.GetAuthenticationParameters (templateId); + } + void GetTargetFrameworks () { if (IsSupportedParameter ("NetStandard")) { diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs index 8d87500de2..50a25d7ccd 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.Templating/DotNetCoreProjectTemplateWizardPage.cs @@ -43,12 +43,15 @@ namespace MonoDevelop.DotNetCore.Templating public DotNetCoreProjectTemplateWizardPage ( DotNetCoreProjectTemplateWizard wizard, - List<TargetFramework> targetFrameworks) + List<TargetFramework> targetFrameworks, + IList<AuthenticationParameter> supportedAuthentications) { this.wizard = wizard; this.targetFrameworks = targetFrameworks; parameters = CreateTargetFrameworksParameters (); + SupportedAuthentications = supportedAuthentications; + if (targetFrameworks.Any ()) SelectedTargetFrameworkIndex = 0; else @@ -115,5 +118,17 @@ namespace MonoDevelop.DotNetCore.Templating if (!string.IsNullOrEmpty (parameter)) wizard.Parameters [parameter] = "true"; } + + public IList<AuthenticationParameter> SupportedAuthentications { get; } + + int selectedAuthenticationIndex; + + public int SelectedAuthenticationIndex { + get { return selectedAuthenticationIndex; } + set { + selectedAuthenticationIndex = value; + wizard.Parameters [AuthenticationParameter.ParameterName] = SupportedAuthentications [selectedAuthenticationIndex].Name; + } + } } } diff --git a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj index 01af0f8ead..c3af883e33 100644 --- a/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj +++ b/main/src/addins/MonoDevelop.DotNetCore/MonoDevelop.DotNetCore.csproj @@ -96,6 +96,7 @@ <Compile Include="MonoDevelop.DotNetCore\DotNetCoreRuntimeSystemInformation.cs" /> <Compile Include="MonoDevelop.DotNetCore.Commands\PackCommandHandler.cs" /> <Compile Include="MonoDevelop.DotNetCore.GlobalTools\DotNetCoreGlobalToolManager.cs" /> + <Compile Include="MonoDevelop.DotNetCore.Templating\DotNetCoreProjectTemplateParameters.cs" /> </ItemGroup> <ItemGroup> <ProjectReference Include="..\..\..\external\mono-addins\Mono.Addins\Mono.Addins.csproj"> diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineSolutionTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineSolutionTemplate.cs index 5b53a60a08..ef9a5e6f89 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineSolutionTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/MicrosoftTemplateEngineSolutionTemplate.cs @@ -33,7 +33,7 @@ using MonoDevelop.Ide.Codons; namespace MonoDevelop.Ide.Templates { - class MicrosoftTemplateEngineSolutionTemplate : SolutionTemplate + public class MicrosoftTemplateEngineSolutionTemplate : SolutionTemplate { internal readonly ITemplateInfo templateInfo; @@ -65,28 +65,6 @@ namespace MonoDevelop.Ide.Templates this.templateInfo = templateInfo; } - string MergeDefaultParameters (string defaultParameters) - { - List<TemplateParameter> priorityParameters = null; - var parameters = new List<string> (); - var cacheParameters = templateInfo.CacheParameters.Where (m => !string.IsNullOrEmpty (m.Value.DefaultValue)); - - if (!cacheParameters.Any ()) - return defaultParameters; - - if (!string.IsNullOrEmpty (defaultParameters)) { - priorityParameters = TemplateParameter.CreateParameters (defaultParameters).ToList (); - defaultParameters += ","; - } - - foreach (var p in cacheParameters) { - if (priorityParameters != null && !priorityParameters.Exists (t => t.Name == p.Key)) - parameters.Add ($"{p.Key}={p.Value.DefaultValue}"); - } - - return defaultParameters += string.Join (",", parameters); - } - internal string FileFormattingExclude { get; set; } internal bool ShouldFormatFile (string fileName) @@ -166,5 +144,15 @@ namespace MonoDevelop.Ide.Templates return textBuilder.ToString (); } + + public IReadOnlyDictionary<string, string> GetParameterChoices (string parameterName) + { + return templateInfo.Parameters.FirstOrDefault (parameter => parameter.Name == parameterName)?.Choices; + } + + public bool IsSupportedParameter(string parameterName) + { + return templateInfo.Parameters.FirstOrDefault (parameter => parameter.Name == parameterName) != null; + } } } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateWizard.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateWizard.cs index 811dc651ec..709c800ad6 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateWizard.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplateWizard.cs @@ -72,6 +72,7 @@ namespace MonoDevelop.Ide.Templates internal void UpdateParameters (SolutionTemplate template) { + Parameters ["TemplateId"] = template.Id; Parameters ["TemplateName"] = template.Name; UpdateSupportedParameters (template.SupportedParameters); UpdateDefaultParameters (template.DefaultParameters); diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs index 046e19e429..71c4101a49 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs @@ -206,6 +206,12 @@ namespace MonoDevelop.Ide.Templates return itemTemplatingProvider.GetTemplates ();
}
+ public SolutionTemplate GetSolutionTemplate (string templateId) + { + var categories = GetProjectTemplateCategories (template => template.Id == templateId); + return GetTemplate (categories, templateId); + }
+
public IEnumerable<ItemTemplate> GetItemTemplates (Predicate<ItemTemplate> match)
{
return GetItemTemplates ().Where (template => match (template));
|