~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.DesignerSupport/MonoDevelop.DesignerSupport.Projects/ProjectFileDescriptor.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
55
55
                        get { return file.FilePath; }
56
56
                }
57
57
                
 
58
                [DisplayName ("Type")]
 
59
                [Description ("Type of the file.")]
 
60
                public string FileType {
 
61
                        get {
 
62
                                string type = MonoDevelop.Core.Gui.Services.PlatformService.GetMimeTypeForUri (file.Name);
 
63
                                return MonoDevelop.Core.Gui.Services.PlatformService.GetMimeTypeDescription (type); 
 
64
                        }
 
65
                }
 
66
                
58
67
                [Category ("Build")]
59
68
                [DisplayName ("Build action")]
60
69
                [Description ("Action to perform when building this file.")]
61
 
                public BuildAction BuildAction {
 
70
                [TypeConverter (typeof (BuildActionStringsConverter))]
 
71
                public string BuildAction {
62
72
                        get { return file.BuildAction; }
63
73
                        set { file.BuildAction = value; }
64
74
                }
71
81
                        set { file.ResourceId = value; }
72
82
                }
73
83
                
 
84
                [Category ("Build")]
 
85
                [DisplayName ("Copy to output directory")]
 
86
                [Description ("Whether to copy the file to the project's output directory when the project is built.")]
 
87
                public FileCopyMode CopyToOutputDirectory {
 
88
                        get { return file.CopyToOutputDirectory; }
 
89
                        set { file.CopyToOutputDirectory = value; }
 
90
                }
 
91
                
74
92
                protected override bool IsReadOnly (string propertyName)
75
93
                {
76
 
                        if (propertyName == "ResourceId" && file.BuildAction != BuildAction.EmbedAsResource)
 
94
                        if (propertyName == "ResourceId" && file.BuildAction != MonoDevelop.Projects.BuildAction.EmbeddedResource)
77
95
                                return true;
78
96
                        return false;
79
97
                }
 
98
                
 
99
                [MonoDevelop.DesignerSupport.PropertyGrid.PropertyEditors.StandardValuesSeparator ("--")]
 
100
                class BuildActionStringsConverter : StandardStringsConverter
 
101
                {
 
102
                        public override System.Collections.ICollection GetStandardStrings (ITypeDescriptorContext context)
 
103
                        {
 
104
                                ProjectFileDescriptor descriptor = context != null?
 
105
                                        context.Instance as ProjectFileDescriptor : null;
 
106
                                
 
107
                                if (descriptor != null && descriptor.file != null && descriptor.file.Project != null) {
 
108
                                        return descriptor.file.Project.GetBuildActions ();
 
109
                                } else {
 
110
                                        return new string[] {"Content", "None", "Compile"};
 
111
                                }
 
112
                        }
 
113
                        
 
114
                        public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
 
115
                        {
 
116
                                return sourceType == typeof (string);
 
117
                        }
 
118
                        
 
119
                        public override object ConvertFrom (ITypeDescriptorContext context,
 
120
                                                            System.Globalization.CultureInfo culture, object value)
 
121
                        {
 
122
                                if (!IsValid (context, value))
 
123
                                        throw new FormatException ("Invalid build target name");
 
124
                                
 
125
                                return value;
 
126
                        }
 
127
                        
 
128
                        //these must encode into XML element names
 
129
                        public override bool IsValid (ITypeDescriptorContext context, object value)
 
130
                        {
 
131
                                if (!(value is string))
 
132
                                        return false;
 
133
                                
 
134
                                string str = (string) value;
 
135
                                if (string.IsNullOrEmpty (str) || !char.IsLetter (str[0]))
 
136
                                        return false;
 
137
                                
 
138
                                for (int i = 1; i < str.Length; i++) {
 
139
                                        char c = str[i];
 
140
                                        if (char.IsLetterOrDigit (c) || c == '_')
 
141
                                                continue;
 
142
                                        else
 
143
                                                return false;
 
144
                                }
 
145
                                
 
146
                                return true;
 
147
                        }
 
148
                        
 
149
                        public override bool GetStandardValuesExclusive (ITypeDescriptorContext context)
 
150
                        {
 
151
                                //only make the list exclusive if we managed to get a list from the parent project
 
152
                                ProjectFileDescriptor descriptor = context != null?
 
153
                                        context.Instance as ProjectFileDescriptor : null;
 
154
                                
 
155
                                return (descriptor != null && descriptor.file != null && descriptor.file.Project != null);
 
156
                        }
 
157
                }
 
158
                
 
159
                abstract class StandardStringsConverter : TypeConverter
 
160
                {
 
161
                        public override bool GetStandardValuesSupported (ITypeDescriptorContext context)
 
162
                        {
 
163
                                return true;
 
164
                        }
 
165
                
 
166
                        public override bool CanConvertFrom (ITypeDescriptorContext context, Type sourceType)
 
167
                        {
 
168
                                return sourceType == typeof (string) || base.CanConvertFrom (context, sourceType);
 
169
                        }
 
170
                
 
171
                        public override bool CanConvertTo (ITypeDescriptorContext context, Type destinationType)
 
172
                        {
 
173
                                return destinationType == typeof (string) || base.CanConvertTo (context, destinationType);
 
174
                        }
 
175
                
 
176
                        public override object ConvertFrom (ITypeDescriptorContext context, 
 
177
                                                            System.Globalization.CultureInfo culture, object value)
 
178
                        {
 
179
                                if (value != null && value is string)
 
180
                                        return value;
 
181
                                else
 
182
                                        return base.ConvertFrom (context, culture, value);
 
183
                        }
 
184
                
 
185
                        public override object ConvertTo (ITypeDescriptorContext context, System.Globalization.CultureInfo culture,
 
186
                                                          object value, Type destinationType)
 
187
                        {
 
188
                                if (value != null && (destinationType == typeof (string)))
 
189
                                        return value;
 
190
                                else
 
191
                                        return base.ConvertTo (context, culture, value, destinationType);
 
192
                        }
 
193
                
 
194
                        public override StandardValuesCollection GetStandardValues (ITypeDescriptorContext context)
 
195
                        {
 
196
                                return new StandardValuesCollection (GetStandardStrings (context));
 
197
                        }
 
198
                
 
199
                        public abstract System.Collections.ICollection GetStandardStrings (ITypeDescriptorContext context);
 
200
                }
80
201
        }
81
202
}