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 <matt.ward@xamarin.com>2017-07-28 19:56:31 +0300
committerMatt Ward <matt.ward@xamarin.com>2017-07-28 19:56:31 +0300
commit5baeaa1d3138d30c5f4d4f3e2f629115c51498dd (patch)
tree17ff0eed6a2472dd889205fc3dd54f7bf626dc59 /main/src/core/MonoDevelop.Ide
parent84e557b3b63087a5b936a6ebf74b0a3e16d6966c (diff)
[Ide] Fix duplicate recent project template for grouped templates
Creating a CocoaApp project that targeted Mavericks and then creating another CocoaApp project that targeted a later Mac OS would then result in two CocoaApp projects for C# shown in the recent project templates list in the New Project dialog when they are logically the same template just part of a group of templates.
Diffstat (limited to 'main/src/core/MonoDevelop.Ide')
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs13
-rw-r--r--main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs25
2 files changed, 34 insertions, 4 deletions
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 f5f888f330..4514c77390 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/SolutionTemplate.cs
@@ -255,6 +255,19 @@ namespace MonoDevelop.Ide.Templates
^ (Name != null ? Name.GetHashCode () : 0)
^ (Category != null ? Category.GetHashCode () : 0);
}
+
+ /// <summary>
+ /// Returns all other templates in the group. Does not include this template.
+ /// </summary>
+ internal IEnumerable<SolutionTemplate> GetGroupedTemplates ()
+ {
+ if (Parent != null)
+ return Parent.groupedTemplates
+ .Where (template => template != this)
+ .Concat (Parent);
+
+ return groupedTemplates;
+ }
}
}
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 181735c339..5edc53bf20 100644
--- a/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs
+++ b/main/src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/TemplatingService.cs
@@ -109,7 +109,7 @@ namespace MonoDevelop.Ide.Templates
return templateCategorizer.GetCategorizedTemplates ();
}
- internal SolutionTemplate GetTemplate (IEnumerable<TemplateCategory> categories, string templateId)
+ internal static SolutionTemplate GetTemplate (IEnumerable<TemplateCategory> categories, string templateId)
{
return GetTemplate (
categories,
@@ -118,7 +118,7 @@ namespace MonoDevelop.Ide.Templates
category => true);
}
- internal SolutionTemplate GetTemplate (
+ internal static SolutionTemplate GetTemplate (
IEnumerable<TemplateCategory> categories,
Func<SolutionTemplate, bool> isTemplateMatch,
Func<TemplateCategory, bool> isTopLevelCategoryMatch,
@@ -230,6 +230,8 @@ namespace MonoDevelop.Ide.Templates
public void AddTemplate (SolutionTemplate template)
{
try {
+ if (template.HasGroupId)
+ RemoveTemplateFromSameGroup (template);
var recentItem = CreateRecentItem (template);
recentTemplates.AddWithLimit (recentItem, templateGroup, ItemLimit);
} catch (Exception e) {
@@ -237,6 +239,21 @@ namespace MonoDevelop.Ide.Templates
}
}
+ /// <summary>
+ /// Removes any recent templates from the same group if it has the same language.
+ /// Different languages for the same group can exist separately in the recent project
+ /// templates list.
+ /// </summary>
+ void RemoveTemplateFromSameGroup (SolutionTemplate template)
+ {
+ foreach (var groupTemplate in template.GetGroupedTemplates ()) {
+ if (groupTemplate.Language == template.Language) {
+ var recentItem = CreateRecentItem (groupTemplate);
+ recentTemplates.RemoveItem (recentItem);
+ }
+ }
+ }
+
RecentItem CreateRecentItem (SolutionTemplate template)
{
var mime = "application/vnd.monodevelop.template";
@@ -256,7 +273,7 @@ namespace MonoDevelop.Ide.Templates
SolutionTemplate recentTemplate = null;
if (parts.Length > 1)
- recentTemplate = IdeApp.Services.TemplatingService.GetTemplate (
+ recentTemplate = TemplatingService.GetTemplate (
categories,
(template) => template.Id == templateId,
(category) => parts.Length > 1 ? category.Id == parts[0] : true,
@@ -266,7 +283,7 @@ namespace MonoDevelop.Ide.Templates
// fallback to global template lookup if no category matched
// in this case the category is not guaranteed if a template is listed in more than one category
if (recentTemplate == null)
- recentTemplate = IdeApp.Services.TemplatingService.GetTemplate (categories, templateId);
+ recentTemplate = TemplatingService.GetTemplate (categories, templateId);
return recentTemplate;
}