diff options
author | Matt Ward <ward.matt@gmail.com> | 2015-02-05 13:00:13 +0300 |
---|---|---|
committer | Matt Ward <ward.matt@gmail.com> | 2015-02-05 21:54:18 +0300 |
commit | 492ac2710907baad7dbc5b718e1d91e6dcdef884 (patch) | |
tree | 4cbaaa2ed8431634f9deea31fa9a620a19c1fea6 /main/src/core/MonoDevelop.Ide | |
parent | e2fa61400f9ed4843ae4c28f187e3dc4faa24119 (diff) |
[Ide] Project templates can now be hidden in the New Project dialog.
A project template can now indicate when it should be displayed in the
New Project dialog. The project template can indicate that it should
only be shown when creating a new solution, or when adding a new
project to an existing solution, or, by default, always be shown. This
is done by adding a new Visibility element to the template's header:
<TemplateConfiguration>
<Visibility>NewProject</Visibility>
If this element is missing then the project template is always shown.
Supported Visibility values are: NewSolution and NewProject.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
8 files changed, 99 insertions, 5 deletions
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs index 27d25915c0..146996cbb0 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Projects/NewProjectController.cs @@ -107,13 +107,13 @@ namespace MonoDevelop.Ide.Projects public NewProjectDialogController ()
{
IsFirstPage = true;
- LoadTemplateCategories ();
GetVersionControlHandler ();
}
public bool Show ()
{
projectConfiguration.CreateSolution = ParentFolder == null;
+ LoadTemplateCategories ();
SetDefaultSettings ();
SelectDefaultTemplate ();
@@ -246,7 +246,16 @@ namespace MonoDevelop.Ide.Projects void LoadTemplateCategories ()
{
- templateCategories = IdeApp.Services.TemplatingService.GetProjectTemplateCategories ().ToList ();
+ Predicate<SolutionTemplate> templateMatch = GetTemplateFilter ();
+ templateCategories = IdeApp.Services.TemplatingService.GetProjectTemplateCategories (templateMatch).ToList ();
+ }
+
+ Predicate<SolutionTemplate> GetTemplateFilter ()
+ {
+ if (IsNewSolution) {
+ return ProjectTemplateCategorizer.MatchNewSolutionTemplates;
+ }
+ return ProjectTemplateCategorizer.MatchNewProjectTemplates;
}
void SelectDefaultTemplate ()
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DefaultSolutionTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DefaultSolutionTemplate.cs index 6d820602cd..85f54bcaeb 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DefaultSolutionTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DefaultSolutionTemplate.cs @@ -24,6 +24,8 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
+using System;
+
namespace MonoDevelop.Ide.Templates
{
internal class DefaultSolutionTemplate : SolutionTemplate
@@ -46,10 +48,22 @@ namespace MonoDevelop.Ide.Templates DefaultParameters = template.DefaultParameters;
ImageId = template.ImageId;
ImageFile = template.ImageFile;
+ Visibility = GetVisibility (template.Visibility);
HasProjects = (template.SolutionDescriptor.EntryDescriptors.Length > 0);
}
+ SolutionTemplateVisibility GetVisibility (string value)
+ {
+ if (!String.IsNullOrEmpty (value)) {
+ SolutionTemplateVisibility visibility;
+ if (Enum.TryParse (value, true, out visibility)) {
+ return visibility;
+ }
+ }
+ return SolutionTemplateVisibility.All;
+ }
+
internal ProjectTemplate Template {
get { return template; }
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs index c9802c6095..d44a08d4f7 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs @@ -173,6 +173,11 @@ namespace MonoDevelop.Ide.Templates get { return imageFile; } } + private string visibility; + public string Visibility { + get { return visibility; } + } + //constructors static ProjectTemplate () { @@ -271,6 +276,10 @@ namespace MonoDevelop.Ide.Templates } } + if (xmlConfiguration ["Visibility"] != null) { + visibility = xmlConfiguration ["Visibility"].InnerText; + } + if (xmlDocument.DocumentElement ["Combine"] == null) { throw new InvalidOperationException ("Combine element not found"); } diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplateCategorizer.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplateCategorizer.cs index 5ca601d2e1..cb0e0ebf53 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplateCategorizer.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplateCategorizer.cs @@ -36,10 +36,15 @@ namespace MonoDevelop.Ide.Templates List<TemplateCategory> categories;
TemplateCategory defaultCategory;
Dictionary<string, TemplateCategory> mappedCategories = new Dictionary<string, TemplateCategory> ();
+ Predicate<SolutionTemplate> templateMatch;
- public ProjectTemplateCategorizer (IEnumerable<TemplateCategory> categories)
+ public static readonly Predicate<SolutionTemplate> MatchNewProjectTemplates = template => template.IsMatch (SolutionTemplateVisibility.NewProject);
+ public static readonly Predicate<SolutionTemplate> MatchNewSolutionTemplates = template => template.IsMatch (SolutionTemplateVisibility.NewSolution);
+
+ public ProjectTemplateCategorizer (IEnumerable<TemplateCategory> categories, Predicate<SolutionTemplate> templateMatch)
{
this.categories = categories.Select (category => category.Clone ()).ToList ();
+ this.templateMatch = templateMatch;
PopulateMappedCategories ();
defaultCategory = GetDefaultCategory ();
}
@@ -86,7 +91,7 @@ namespace MonoDevelop.Ide.Templates public void CategorizeTemplates (IEnumerable<SolutionTemplate> templates)
{
- foreach (SolutionTemplate template in templates) {
+ foreach (SolutionTemplate template in GetFilteredTemplates (templates)) {
TemplateCategory category = GetCategory (template);
if (category != null) {
category.AddTemplate (template);
@@ -97,6 +102,11 @@ namespace MonoDevelop.Ide.Templates RemoveEmptyCategories ();
}
+ IEnumerable<SolutionTemplate> GetFilteredTemplates (IEnumerable<SolutionTemplate> templates)
+ {
+ return templates.Where (template => templateMatch (template));
+ }
+
TemplateCategory GetCategory (SolutionTemplate template)
{
TemplateCategory match = GetCategory (template, categories);
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs index 792a6689a3..36dab1af96 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs @@ -49,6 +49,7 @@ namespace MonoDevelop.Ide.Templates Name = name;
IconId = UseDefaultIconIdIfNullOrEmpty (iconId);
HasProjects = true;
+ Visibility = SolutionTemplateVisibility.All;
}
static string UseDefaultIconIdIfNullOrEmpty (string iconId)
@@ -65,6 +66,7 @@ namespace MonoDevelop.Ide.Templates public string Description { get; set; }
public string Category { get; set; }
public bool HasProjects { get; set; }
+ public SolutionTemplateVisibility Visibility { get; set; }
/// <summary>
/// Allows templates to be grouped together in the New Project dialog.
@@ -203,6 +205,11 @@ namespace MonoDevelop.Ide.Templates return ".proj";
}
}
+
+ internal bool IsMatch (SolutionTemplateVisibility visibility)
+ {
+ return (Visibility == visibility) || (Visibility == SolutionTemplateVisibility.All);
+ }
}
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplateVisibility.cs b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplateVisibility.cs new file mode 100644 index 0000000000..844c318f90 --- /dev/null +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplateVisibility.cs @@ -0,0 +1,38 @@ +//
+// SolutionTemplateVisibility.cs
+//
+// Author:
+// Matt Ward <matt.ward@xamarin.com>
+//
+// Copyright (c) 2015 Xamarin Inc. (http://xamarin.com)
+//
+// 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;
+
+namespace MonoDevelop.Ide.Templates
+{
+ public enum SolutionTemplateVisibility
+ {
+ All,
+ NewSolution,
+ NewProject
+ }
+}
+
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 bc458d8192..4d8b1708c4 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs @@ -24,6 +24,7 @@ // 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 Mono.Addins;
@@ -92,7 +93,12 @@ namespace MonoDevelop.Ide.Templates public IEnumerable<TemplateCategory> GetProjectTemplateCategories ()
{
- var templateCategorizer = new ProjectTemplateCategorizer (projectTemplateCategories);
+ return GetProjectTemplateCategories (solutionTemplate => true);
+ }
+
+ public IEnumerable<TemplateCategory> GetProjectTemplateCategories (Predicate<SolutionTemplate> match)
+ {
+ var templateCategorizer = new ProjectTemplateCategorizer (projectTemplateCategories, match);
foreach (IProjectTemplatingProvider provider in templateProviders) {
templateCategorizer.CategorizeTemplates (provider.GetTemplates ());
}
diff --git a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj index 3a410adf75..b9c21d3a6e 100644 --- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj +++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.csproj @@ -2995,6 +2995,7 @@ <Compile Include="MonoDevelop.Ide.Projects\NewProjectConfiguration.cs" /> <Compile Include="MonoDevelop.Components\EventBoxTooltip.cs" /> <Compile Include="MonoDevelop.Ide.Templates\ProjectTemplateCreateInformation.cs" /> + <Compile Include="MonoDevelop.Ide.Templates\SolutionTemplateVisibility.cs" /> </ItemGroup> <ItemGroup> <None Include="Makefile.am" /> |