6 changed files with 255 additions and 19 deletions
@ -0,0 +1,144 @@
@@ -0,0 +1,144 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Diagnostics; |
||||
using System.Linq; |
||||
|
||||
using ICSharpCode.Core; |
||||
using ICSharpCode.SharpDevelop.Debugging; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public abstract class ProjectBehavior |
||||
{ |
||||
ProjectBehavior next; |
||||
protected IProject Project { get; private set; } |
||||
|
||||
public ProjectBehavior(IProject project, ProjectBehavior next = null) |
||||
{ |
||||
if (project == null) |
||||
throw new ArgumentNullException("project"); |
||||
this.Project = project; |
||||
this.next = next; |
||||
} |
||||
|
||||
internal void SetProject(IProject project) |
||||
{ |
||||
if (project == null) |
||||
throw new ArgumentNullException("project"); |
||||
this.Project = project; |
||||
} |
||||
|
||||
internal void SetNext(ProjectBehavior next) |
||||
{ |
||||
if (next == null) |
||||
throw new ArgumentNullException("next"); |
||||
this.next = next; |
||||
} |
||||
|
||||
public virtual bool IsStartable { |
||||
get { |
||||
if (this.next != null) |
||||
return next.IsStartable; |
||||
return false; |
||||
} |
||||
} |
||||
|
||||
public virtual void Start(bool withDebugging) |
||||
{ |
||||
if (this.next != null) |
||||
next.Start(withDebugging); |
||||
} |
||||
|
||||
public virtual ProcessStartInfo CreateStartInfo() |
||||
{ |
||||
if (this.next != null) |
||||
return next.CreateStartInfo(); |
||||
return null; |
||||
} |
||||
|
||||
public virtual ItemType GetDefaultItemType(string fileName) |
||||
{ |
||||
if (this.next != null) |
||||
return next.GetDefaultItemType(fileName); |
||||
return default(ItemType); |
||||
} |
||||
|
||||
public virtual ProjectItem CreateProjectItem(IProjectItemBackendStore item) |
||||
{ |
||||
if (this.next != null) |
||||
return next.CreateProjectItem(item); |
||||
return null; |
||||
} |
||||
|
||||
public virtual ICollection<ItemType> AvailableFileItemTypes { |
||||
get { |
||||
if (this.next != null) |
||||
return next.AvailableFileItemTypes; |
||||
return null; |
||||
} |
||||
} |
||||
|
||||
public virtual void ProjectCreationComplete() |
||||
{ |
||||
if (this.next != null) |
||||
next.ProjectCreationComplete(); |
||||
} |
||||
} |
||||
|
||||
sealed class DefaultProjectBehavior : ProjectBehavior |
||||
{ |
||||
public DefaultProjectBehavior(IProject project) |
||||
: base(project) |
||||
{ |
||||
} |
||||
|
||||
public override bool IsStartable { |
||||
get { return false; } |
||||
} |
||||
|
||||
public override void Start(bool withDebugging) |
||||
{ |
||||
ProcessStartInfo psi; |
||||
try { |
||||
if (!(Project is AbstractProject)) |
||||
return; |
||||
psi = ((AbstractProject)Project).CreateStartInfo(); |
||||
} catch (ProjectStartException ex) { |
||||
MessageService.ShowError(ex.Message); |
||||
return; |
||||
} |
||||
if (withDebugging) { |
||||
DebuggerService.CurrentDebugger.Start(psi); |
||||
} else { |
||||
DebuggerService.CurrentDebugger.StartWithoutDebugging(psi); |
||||
} |
||||
} |
||||
|
||||
public override ProcessStartInfo CreateStartInfo() |
||||
{ |
||||
throw new NotSupportedException(); |
||||
} |
||||
|
||||
public override ItemType GetDefaultItemType(string fileName) |
||||
{ |
||||
return ItemType.None; |
||||
} |
||||
|
||||
public override ProjectItem CreateProjectItem(IProjectItemBackendStore item) |
||||
{ |
||||
return new UnknownProjectItem(Project, item); |
||||
} |
||||
|
||||
public override ICollection<ItemType> AvailableFileItemTypes { |
||||
get { return ItemType.DefaultFileItems; } |
||||
} |
||||
|
||||
public override void ProjectCreationComplete() |
||||
{ |
||||
|
||||
} |
||||
} |
||||
} |
@ -0,0 +1,32 @@
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public static class ProjectBehaviorService |
||||
{ |
||||
const string AddInPath = "/SharpDevelop/Workbench/ProjectBehaviors"; |
||||
|
||||
public static ProjectBehavior LoadBehaviorsForProject(IProject project, ProjectBehavior defaultBehavior) |
||||
{ |
||||
List<ProjectBehavior> behaviors = AddInTree.BuildItems<ProjectBehavior>(AddInPath, project, false); |
||||
ProjectBehavior first = null, current = null; |
||||
foreach (var behavior in behaviors) { |
||||
behavior.SetProject(project); |
||||
if (first == null) |
||||
first = behavior; |
||||
else |
||||
current.SetNext(behavior); |
||||
current = behavior; |
||||
} |
||||
if (current == null) |
||||
return defaultBehavior; |
||||
current.SetNext(defaultBehavior); |
||||
return first; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,47 @@
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
|
||||
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
|
||||
|
||||
using System; |
||||
using System.Collections.Generic; |
||||
using System.Linq; |
||||
using ICSharpCode.Core; |
||||
|
||||
namespace ICSharpCode.SharpDevelop.Project |
||||
{ |
||||
public class ProjectBehaviorSupportedConditionEvaluator : IConditionEvaluator |
||||
{ |
||||
public bool IsValid(object owner, Condition condition) |
||||
{ |
||||
Guid conditionGuid; |
||||
if (!Guid.TryParse(condition.Properties["guid"], out conditionGuid)) |
||||
return true; |
||||
|
||||
string guidString; |
||||
if (owner is IProject) |
||||
guidString = FindGuidInProject((IProject)owner); |
||||
else if (ProjectService.CurrentProject != null) |
||||
guidString = FindGuidInProject(ProjectService.CurrentProject); |
||||
else |
||||
return false; |
||||
|
||||
Guid result; |
||||
foreach (string guid in guidString.Split(new[] { ';' }, StringSplitOptions.RemoveEmptyEntries)) { |
||||
if (Guid.TryParse(guid, out result) && conditionGuid == result) |
||||
return true; |
||||
} |
||||
|
||||
return false; |
||||
} |
||||
|
||||
string FindGuidInProject(IProject project) |
||||
{ |
||||
if (project is MSBuildBasedProject) { |
||||
string guid = ((MSBuildBasedProject)project).GetEvaluatedProperty("ProjectTypeGuids"); |
||||
if (!string.IsNullOrEmpty(guid)) |
||||
return guid; |
||||
} |
||||
|
||||
return project.TypeGuid; |
||||
} |
||||
} |
||||
} |
Loading…
Reference in new issue