37
37
using MonoDevelop.Core.Collections;
38
38
using MonoDevelop.Core.StringParsing;
39
39
using MonoDevelop.Core.Instrumentation;
40
using MonoDevelop.Projects.Policies;
41
42
namespace MonoDevelop.Projects
43
public abstract class SolutionItem: IExtendedDataItem, IBuildTarget, ILoadController
44
public abstract class SolutionItem: IExtendedDataItem, IBuildTarget, ILoadController, IPolicyProvider
45
46
SolutionFolder parentFolder;
46
47
Solution parentSolution;
59
60
PropertyBag userProperties;
63
/// Initializes a new instance of the <see cref="MonoDevelop.Projects.SolutionItem"/> class.
61
65
public SolutionItem()
63
67
ProjectExtensionUtil.LoadControl (this);
71
/// Initializes a new instance of this item, using an xml element as template
73
/// <param name='template'>
66
76
public virtual void InitializeFromTemplate (XmlElement template)
81
/// Gets the handler for this solution item
84
/// The solution item handler.
86
/// <exception cref='InvalidOperationException'>
87
/// Is thrown if there isn't a ISolutionItemHandler for this solution item
70
89
protected internal ISolutionItemHandler ItemHandler {
72
91
if (handler == null) {
91
116
return this.handler;
120
/// Gets the author information for this solution item, inherited from the solution and global settings.
122
public AuthorInformation AuthorInformation {
124
if (ParentSolution != null)
125
return ParentSolution.AuthorInformation;
127
return AuthorInformation.Default;
132
/// Gets a service instance of a given type
137
/// <typeparam name='T'>
138
/// Type of the service
141
/// This method looks for an imlpementation of a service of the given type.
94
143
public T GetService<T> () where T: class
96
145
return (T) GetService (typeof(T));
149
/// Gets a service instance of a given type
155
/// Type of the service
158
/// This method looks for an imlpementation of a service of the given type.
159
/// The default implementation this instance if the type is an interface
160
/// implemented by this instance. Otherwise, it looks for a service in
161
/// the project extension chain.
99
163
public virtual object GetService (Type t)
101
165
if (t.IsInstanceOfType (this))
113
180
parentSolution = value;
185
/// Gets a value indicating whether this item is currently being loaded from a file
188
/// While an item is loading, some events such as project file change events may be fired.
189
/// This flag can be used to check if change events are caused by data being loaded.
117
191
public bool Loading {
118
192
get { return loading > 0; }
196
/// Saves the solution item
198
/// <param name='monitor'>
199
/// A progress monitor.
121
201
public abstract void Save (IProgressMonitor monitor);
204
/// Name of the solution item
123
206
public abstract string Name { get; set; }
209
/// Gets or sets the base directory of this solution item
212
/// The base directory.
215
/// The base directory is the directory where files belonging to this project
216
/// are placed. Notice that this directory may be different than the directory
217
/// where the project file is placed.
125
219
public FilePath BaseDirectory {
127
221
if (baseDirectory == null) {
157
254
internal bool HasCustomBaseDirectory {
158
255
get { return baseDirectory != null; }
259
/// Gets the default base directory.
262
/// The base directory is the directory where files belonging to this project
263
/// are placed. Notice that this directory may be different than the directory
264
/// where the project file is placed.
161
266
protected virtual FilePath GetDefaultBaseDirectory ( )
163
268
return ParentSolution.BaseDirectory;
272
/// Gets the identifier of this solution item
275
/// The identifier is unique inside the solution
166
277
public string ItemId {
167
278
get { return ItemHandler.ItemId; }
282
/// Gets extended properties.
285
/// This dictionary can be used by add-ins to store arbitrary information about this solution item.
286
/// Keys and values can be of any type.
287
/// If a value implements IDisposable, the value will be disposed when this solution item is disposed.
288
/// Values in this dictionary won't be serialized, unless they are registered as serializable using
289
/// the /MonoDevelop/ProjectModel/ExtendedProperties extension point.
170
291
public IDictionary ExtendedProperties {
171
292
get { return InternalGetExtendedProperties; }
299
/// Returns a policy container which can be used to query policies specific for this
300
/// solution item. If a policy is not defined for this item, the inherited value will be returned.
174
302
public MonoDevelop.Projects.Policies.PolicyBag Policies {
176
304
//newly created (i.e. not deserialised) SolutionItems may have a null PolicyBag
213
368
internalChildren.ParentFolder = value;
373
/// Gets a value indicating whether this <see cref="MonoDevelop.Projects.SolutionItem"/> has been disposed.
376
/// <c>true</c> if disposed; otherwise, <c>false</c>.
378
internal protected bool Disposed { get; private set; }
381
/// Releases all resource used by the <see cref="MonoDevelop.Projects.SolutionItem"/> object.
384
/// Call <see cref="Dispose"/> when you are finished using the <see cref="MonoDevelop.Projects.SolutionItem"/>. The
385
/// <see cref="Dispose"/> method leaves the <see cref="MonoDevelop.Projects.SolutionItem"/> in an unusable state.
386
/// After calling <see cref="Dispose"/>, you must release all references to the
387
/// <see cref="MonoDevelop.Projects.SolutionItem"/> so the garbage collector can reclaim the memory that the
388
/// <see cref="MonoDevelop.Projects.SolutionItem"/> was occupying.
217
390
public virtual void Dispose ()
219
394
if (extendedProperties != null) {
220
395
foreach (object ob in extendedProperties.Values) {
221
396
IDisposable disp = ob as IDisposable;
222
397
if (disp != null)
400
extendedProperties = null;
402
if (handler != null) {
227
403
handler.Dispose ();
228
if (userProperties != null)
406
if (userProperties != null) {
229
407
((IDisposable)userProperties).Dispose ();
408
userProperties = null;
411
// parentFolder = null;
412
// parentSolution = null;
413
// internalChildren = null;
418
/// Gets solution items referenced by this instance (items on which this item depends)
421
/// The referenced items.
423
/// <param name='configuration'>
424
/// Configuration for which to get the referenced items
232
426
public virtual IEnumerable<SolutionItem> GetReferencedItems (ConfigurationSelector configuration)
234
428
return new SolutionItem [0];
432
/// Runs a build or execution target.
435
/// The result of the operation
437
/// <param name='monitor'>
438
/// A progress monitor
440
/// <param name='target'>
441
/// Name of the target
443
/// <param name='configuration'>
444
/// Configuration to use to run the target
237
446
public BuildResult RunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration)
239
448
return Services.ProjectService.GetExtensionChain (this).RunTarget (monitor, this, target, configuration);
452
/// Cleans the files produced by this solution item
454
/// <param name='monitor'>
455
/// A progress monitor
457
/// <param name='configuration'>
458
/// Configuration to use to clean the project
242
460
public void Clean (IProgressMonitor monitor, ConfigurationSelector configuration)
244
462
RunTarget (monitor, ProjectService.CleanTarget, configuration);
466
/// Builds the solution item
468
/// <param name='monitor'>
469
/// A progress monitor
471
/// <param name='configuration'>
472
/// Configuration to use to build the project
247
474
public BuildResult Build (IProgressMonitor monitor, ConfigurationSelector configuration)
249
476
return Build (monitor, configuration, false);
480
/// Builds the solution item
482
/// <param name='monitor'>
483
/// A progress monitor
485
/// <param name='configuration'>
486
/// Configuration to use to build the project
488
/// <param name='buildReferences'>
489
/// When set to <c>true</c>, the referenced items will be built before building this item
252
491
public BuildResult Build (IProgressMonitor monitor, ConfigurationSelector solutionConfiguration, bool buildReferences)
254
493
ITimeTracker tt = Counters.BuildProjectTimer.BeginTiming ("Building " + Name);
329
577
GetBuildableReferencedItems (visited, referenced, ritem, configuration);
581
/// Executes this solution item
583
/// <param name='monitor'>
584
/// A progress monitor
586
/// <param name='context'>
587
/// An execution context
589
/// <param name='configuration'>
590
/// Configuration to use to execute the item
332
592
public void Execute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
334
594
Services.ProjectService.GetExtensionChain (this).Execute (monitor, this, context, configuration);
598
/// Determines whether this solution item can be executed using the specified context and configuration.
601
/// <c>true</c> if this instance can be executed; otherwise, <c>false</c>.
603
/// <param name='context'>
604
/// An execution context
606
/// <param name='configuration'>
607
/// Configuration to use to execute the item
337
609
public bool CanExecute (ExecutionContext context, ConfigurationSelector configuration)
339
611
return Services.ProjectService.GetExtensionChain (this).CanExecute (this, context, configuration);
615
/// Checks if this solution item has modified files and has to be built
618
/// <c>true</c> if the solution item has to be built
620
/// <param name='configuration'>
621
/// Configuration for which to do the check
342
623
public bool NeedsBuilding (ConfigurationSelector configuration)
344
625
using (Counters.NeedsBuildingTimer.BeginTiming ("NeedsBuilding check for " + Name)) {
636
/// States whether this solution item needs to be built or not
638
/// <param name='value'>
639
/// Whether this solution item needs to be built or not
641
/// <param name='configuration'>
642
/// Configuration for which to set the flag
354
644
public void SetNeedsBuilding (bool value, ConfigurationSelector configuration)
356
646
Services.ProjectService.GetExtensionChain (this).SetNeedsBuilding (this, value, configuration);
650
/// Gets or sets a value indicating whether this <see cref="MonoDevelop.Projects.SolutionItem"/> needs to be reload due to changes in project or solution file
653
/// <c>true</c> if needs reload; otherwise, <c>false</c>.
359
655
public virtual bool NeedsReload {
361
657
if (ParentSolution != null)
376
685
internalChildren.Items.Add (item);
689
/// Unregisters an internal child item.
691
/// <param name='item'>
379
694
protected void UnregisterInternalChild (SolutionItem item)
381
696
if (internalChildren != null)
382
697
internalChildren.Items.Remove (item);
701
/// Gets the string tag model description for this solution item
704
/// The string tag model description
706
/// <param name='conf'>
707
/// Configuration for which to get the string tag model description
385
709
public virtual StringTagModelDescription GetStringTagModelDescription (ConfigurationSelector conf)
387
711
StringTagModelDescription model = new StringTagModelDescription ();
811
/// Called when a load operation for this solution item has started
461
813
protected virtual void OnBeginLoad ()
818
/// Called when a load operation for this solution item has finished
465
820
protected virtual void OnEndLoad ()
825
/// Notifies that this solution item has been modified
827
/// <param name='hint'>
828
/// Hint about which part of the solution item has been modified. This will typically be the property name.
469
830
protected void NotifyModified (string hint)
471
832
OnModified (new SolutionItemModifiedEventArgs (this, hint));
836
/// Raises the modified event.
838
/// <param name='args'>
474
841
protected virtual void OnModified (SolutionItemModifiedEventArgs args)
476
if (Modified != null)
843
if (Modified != null && !Disposed)
477
844
Modified (this, args);
848
/// Raises the name changed event.
480
853
protected virtual void OnNameChanged (SolutionItemRenamedEventArgs e)
482
855
NotifyModified ("Name");
483
if (NameChanged != null)
856
if (NameChanged != null && !Disposed)
484
857
NameChanged (this, e);
861
/// Initializes the item handler.
864
/// This method is called the first time an item handler is requested.
865
/// Subclasses should override this method use SetItemHandler to
866
/// assign a handler to this item.
487
868
protected virtual void InitializeItemHandler ()
873
/// Runs a build or execution target.
876
/// The result of the operation
878
/// <param name='monitor'>
879
/// A progress monitor
881
/// <param name='target'>
882
/// Name of the target
884
/// <param name='configuration'>
885
/// Configuration to use to run the target
888
/// Subclasses can override this method to provide a custom implementation of project operations such as
889
/// build or clean. The default implementation delegates the execution to the more specific OnBuild
890
/// and OnClean methods, or to the item handler for other targets.
491
892
internal protected virtual BuildResult OnRunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration)
493
894
if (target == ProjectService.BuildTarget)
499
900
return ItemHandler.RunTarget (monitor, target, configuration) ?? new BuildResult ();
904
/// Cleans the files produced by this solution item
906
/// <param name='monitor'>
907
/// A progress monitor
909
/// <param name='configuration'>
910
/// Configuration to use to clean the project
502
912
protected abstract void OnClean (IProgressMonitor monitor, ConfigurationSelector configuration);
915
/// Builds the solution item
917
/// <param name='monitor'>
918
/// A progress monitor
920
/// <param name='configuration'>
921
/// Configuration to use to build the project
503
923
protected abstract BuildResult OnBuild (IProgressMonitor monitor, ConfigurationSelector configuration);
926
/// Executes this solution item
928
/// <param name='monitor'>
929
/// A progress monitor
931
/// <param name='context'>
932
/// An execution context
934
/// <param name='configuration'>
935
/// Configuration to use to execute the item
504
937
internal protected abstract void OnExecute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration);
940
/// Checks if this solution item has modified files and has to be built
943
/// <c>true</c> if the solution item has to be built
945
/// <param name='configuration'>
946
/// Configuration for which to do the check
505
948
internal protected abstract bool OnGetNeedsBuilding (ConfigurationSelector configuration);
951
/// States whether this solution item needs to be built or not
953
/// <param name='val'>
954
/// Whether this solution item needs to be built or not
956
/// <param name='configuration'>
957
/// Configuration for which to set the flag
506
959
internal protected abstract void OnSetNeedsBuilding (bool val, ConfigurationSelector configuration);
962
/// Gets the time of the last build
965
/// The last build time.
967
/// <param name='configuration'>
968
/// Configuration for which to get the last build time.
508
970
internal protected virtual DateTime OnGetLastBuildTime (ConfigurationSelector configuration)
510
972
return DateTime.MinValue;
976
/// Determines whether this solution item can be executed using the specified context and configuration.
979
/// <c>true</c> if this instance can be executed; otherwise, <c>false</c>.
981
/// <param name='context'>
982
/// An execution context
984
/// <param name='configuration'>
985
/// Configuration to use to execute the item
513
987
internal protected virtual bool OnGetCanExecute (ExecutionContext context, ConfigurationSelector configuration)
993
/// Occurs when the name of the item changes
518
995
public event SolutionItemRenamedEventHandler NameChanged;
998
/// Occurs when the item is modified.
519
1000
public event SolutionItemModifiedEventHandler Modified;
527
1008
yield return new StringTagDescription ("ProjectName", "Project Name");
528
1009
yield return new StringTagDescription ("ProjectDir", "Project Directory");
1010
yield return new StringTagDescription ("AuthorName", "Project Author Name");
1011
yield return new StringTagDescription ("AuthorEmail", "Project Author Email");
1012
yield return new StringTagDescription ("AuthorCopyright", "Project Author Copyright");
1013
yield return new StringTagDescription ("AuthorCompany", "Project Author Company");
1014
yield return new StringTagDescription ("AuthorTrademark", "Project Trademark");
531
1017
public override object GetTagValue (SolutionItem item, string tag)