~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/AddIns/Misc/PackageManagement/Project/Src/EnvDTE/ProjectItem.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using System.ComponentModel;
 
6
using System.IO;
 
7
using ICSharpCode.Core;
 
8
using SD = ICSharpCode.SharpDevelop.Project;
 
9
using ICSharpCode.SharpDevelop.Project;
 
10
 
 
11
namespace ICSharpCode.PackageManagement.EnvDTE
 
12
{
 
13
        public class ProjectItem
 
14
        {
 
15
                SD.FileProjectItem projectItem;
 
16
                
 
17
                public const string CopyToOutputDirectoryPropertyName = "CopyToOutputDirectory";
 
18
                public const string CustomToolPropertyName = "CustomTool";
 
19
                public const string FullPathPropertyName = "FullPath";
 
20
                
 
21
                public ProjectItem(Project project, FileProjectItem projectItem)
 
22
                {
 
23
                        this.projectItem = projectItem;
 
24
                        this.ContainingProject = project;
 
25
                        this.ProjectItems = new DirectoryProjectItems(this);
 
26
                        CreateProperties();
 
27
                }
 
28
                
 
29
                void CreateProperties()
 
30
                {
 
31
                        var propertyFactory = new ProjectItemPropertyFactory(this);
 
32
                        Properties = new Properties(propertyFactory);
 
33
                }
 
34
                
 
35
                public string Name {
 
36
                        get { return Path.GetFileName(projectItem.Include); }
 
37
                }
 
38
                
 
39
                public Properties Properties { get; private set; }
 
40
                public Project ContainingProject  { get; private set; }
 
41
                public ProjectItems ProjectItems { get; private set; }
 
42
                
 
43
                internal object GetProperty(string name)
 
44
                {
 
45
                        if (name == CopyToOutputDirectoryPropertyName) {
 
46
                                return GetCopyToOutputDirectory();
 
47
                        } else if (name == CustomToolPropertyName) {
 
48
                                return projectItem.CustomTool;
 
49
                        } else if (name == FullPathPropertyName) {
 
50
                                return projectItem.FileName;
 
51
                        }
 
52
                        return String.Empty;
 
53
                }
 
54
                
 
55
                UInt32 GetCopyToOutputDirectory()
 
56
                {
 
57
                        return (UInt32)projectItem.CopyToOutputDirectory;
 
58
                }
 
59
                
 
60
                internal void SetProperty(string name, object value)
 
61
                {
 
62
                        if (name == CopyToOutputDirectoryPropertyName) {
 
63
                                SetCopyToOutputDirectory(value);
 
64
                        } else if (name == CustomToolPropertyName) {
 
65
                                projectItem.CustomTool = value as string;
 
66
                        }
 
67
                }
 
68
                
 
69
                void SetCopyToOutputDirectory(object value)
 
70
                {
 
71
                        CopyToOutputDirectory copyToOutputDirectory = ConvertToCopyToOutputDirectory(value);
 
72
                        projectItem.CopyToOutputDirectory = copyToOutputDirectory;
 
73
                }
 
74
                
 
75
                CopyToOutputDirectory ConvertToCopyToOutputDirectory(object value)
 
76
                {
 
77
                        string valueAsString = value.ToString();
 
78
                        return (CopyToOutputDirectory)Enum.Parse(typeof(CopyToOutputDirectory), valueAsString);
 
79
                }
 
80
                
 
81
                internal bool IsMatchByName(string name)
 
82
                {
 
83
                        return String.Equals(this.Name, name, StringComparison.InvariantCultureIgnoreCase);
 
84
                }
 
85
                
 
86
                internal virtual bool IsChildItem(SD.ProjectItem msbuildProjectItem)
 
87
                {
 
88
                        string directory = Path.GetDirectoryName(msbuildProjectItem.Include);
 
89
                        return IsMatchByName(directory);
 
90
                }
 
91
                
 
92
                internal ProjectItemRelationship GetRelationship(SD.ProjectItem msbuildProjectItem)
 
93
                {
 
94
                        return new ProjectItemRelationship(this, msbuildProjectItem);
 
95
                }
 
96
        }
 
97
}