Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Ward <ward.matt@gmail.com>2015-02-05 13:00:13 +0300
committerMatt Ward <ward.matt@gmail.com>2015-02-05 21:54:18 +0300
commit492ac2710907baad7dbc5b718e1d91e6dcdef884 (patch)
tree4cbaaa2ed8431634f9deea31fa9a620a19c1fea6 /main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates
parente2fa61400f9ed4843ae4c28f187e3dc4faa24119 (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/MonoDevelop.Ide.Templates')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DefaultSolutionTemplate.cs14
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplate.cs9
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/ProjectTemplateCategorizer.cs14
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs7
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplateVisibility.cs38
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs8
6 files changed, 87 insertions, 3 deletions
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 ());
}