~ubuntu-branches/ubuntu/saucy/monodevelop/saucy-proposed

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Core/MonoDevelop.Projects/Workspace.cs

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2010-09-10 16:54:48 UTC
  • mfrom: (19.1.1 experimental)
  • Revision ID: james.westby@ubuntu.com-20100910165448-0rybfk25zd4o9431
Tags: 2.4+dfsg-2
* debian/patches/inject_Mono.Debugger.Soft_source.patch,
  debian/patches/use_system_Mono.Debugger.Soft.patch,
  debian/control:
  + Build against system Soft Debugger, since we now have a new
    enough Mono to match MonoDevelop's required API

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//
 
2
// Workspace.cs
 
3
//
 
4
// Author:
 
5
//   Lluis Sanchez Gual
 
6
//
 
7
// Copyright (C) 2006 Novell, Inc (http://www.novell.com)
 
8
//
 
9
// Permission is hereby granted, free of charge, to any person obtaining
 
10
// a copy of this software and associated documentation files (the
 
11
// "Software"), to deal in the Software without restriction, including
 
12
// without limitation the rights to use, copy, modify, merge, publish,
 
13
// distribute, sublicense, and/or sell copies of the Software, and to
 
14
// permit persons to whom the Software is furnished to do so, subject to
 
15
// the following conditions:
 
16
// 
 
17
// The above copyright notice and this permission notice shall be
 
18
// included in all copies or substantial portions of the Software.
 
19
// 
 
20
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 
21
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
 
22
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 
23
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
 
24
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
 
25
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 
26
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
27
//
 
28
 
 
29
 
 
30
using System;
 
31
using System.IO;
 
32
using System.Collections.Generic;
 
33
using System.Collections.ObjectModel;
 
34
using MonoDevelop.Core;
 
35
using MonoDevelop.Core.Serialization;
 
36
 
 
37
namespace MonoDevelop.Projects
 
38
{
 
39
        public class Workspace: WorkspaceItem, ICustomDataItem
 
40
        {
 
41
                WorkspaceItemCollection items;
 
42
                
 
43
                public override void Dispose ()
 
44
                {
 
45
                        base.Dispose ();
 
46
                        foreach (WorkspaceItem it in Items)
 
47
                                it.Dispose ();
 
48
                }
 
49
                
 
50
                public override ReadOnlyCollection<string> GetConfigurations ()
 
51
                {
 
52
                        List<string> configs = new List<string> ();
 
53
                        foreach (WorkspaceItem it in Items) {
 
54
                                foreach (string conf in it.GetConfigurations ()) {
 
55
                                        if (!configs.Contains (conf))
 
56
                                                configs.Add (conf);
 
57
                                }
 
58
                        }
 
59
                        return configs.AsReadOnly ();
 
60
                }
 
61
                
 
62
                public WorkspaceItemCollection Items {
 
63
                        get {
 
64
                                if (items == null)
 
65
                                        items = new WorkspaceItemCollection (this);
 
66
                                return items; 
 
67
                        }
 
68
                }
 
69
                
 
70
                public override ReadOnlyCollection<T> GetAllItems<T> ()
 
71
                {
 
72
                        List<T> list = new List<T> ();
 
73
                        GetAllItems<T> (list, this);
 
74
                        return list.AsReadOnly ();
 
75
                }
 
76
                
 
77
                void GetAllItems<T> (List<T> list, WorkspaceItem item) where T: WorkspaceItem
 
78
                {
 
79
                        if (item is T)
 
80
                                list.Add ((T) item);
 
81
                        
 
82
                        if (item is Workspace) {
 
83
                                foreach (WorkspaceItem citem in ((Workspace)item).Items)
 
84
                                        GetAllItems<T> (list, citem);
 
85
                        }
 
86
                }
 
87
                
 
88
                public override SolutionEntityItem FindSolutionItem (string fileName)
 
89
                {
 
90
                        foreach (WorkspaceItem it in Items) {
 
91
                                SolutionEntityItem si = it.FindSolutionItem (fileName);
 
92
                                if (si != null)
 
93
                                        return si;
 
94
                        }
 
95
                        return null;
 
96
                }
 
97
 
 
98
 
 
99
                public override Project GetProjectContainingFile (FilePath fileName)
 
100
                {
 
101
                        foreach (WorkspaceItem it in Items) {
 
102
                                Project p = it.GetProjectContainingFile (fileName);
 
103
                                if (p != null)
 
104
                                        return p;
 
105
                        }
 
106
                        return null;
 
107
                }
 
108
 
 
109
                public override bool ContainsItem (IWorkspaceObject obj)
 
110
                {
 
111
                        if (base.ContainsItem (obj))
 
112
                                return true;
 
113
                        
 
114
                        foreach (WorkspaceItem it in Items) {
 
115
                                if (it.ContainsItem (obj))
 
116
                                        return true;
 
117
                        }
 
118
                        return false;
 
119
                }
 
120
                
 
121
                
 
122
                public override ReadOnlyCollection<T> GetAllSolutionItems<T> ()
 
123
                {
 
124
                        List<T> list = new List<T> ();
 
125
                        foreach (WorkspaceItem it in Items) {
 
126
                                list.AddRange (it.GetAllSolutionItems<T> ());
 
127
                        }
 
128
                        return list.AsReadOnly ();
 
129
                }
 
130
 
 
131
                public override void ConvertToFormat (FileFormat format, bool convertChildren)
 
132
                {
 
133
                        base.ConvertToFormat (format, convertChildren);
 
134
                        if (convertChildren) {
 
135
                                foreach (WorkspaceItem it in Items)
 
136
                                        it.ConvertToFormat (format, true);
 
137
                        }
 
138
                }
 
139
 
 
140
                
 
141
                internal protected override BuildResult OnRunTarget (IProgressMonitor monitor, string target, ConfigurationSelector configuration)
 
142
                {
 
143
                        BuildResult result = null;
 
144
                        monitor.BeginTask (null, Items.Count);
 
145
                        try {
 
146
                                foreach (WorkspaceItem it in Items) {
 
147
                                        BuildResult res = it.RunTarget (monitor, target, configuration);
 
148
                                        if (res != null) {
 
149
                                                if (result == null) {
 
150
                                                        result = new BuildResult ();
 
151
                                                        result.BuildCount = 0;
 
152
                                                }
 
153
                                                result.Append (res);
 
154
                                        }
 
155
                                        monitor.Step (1);
 
156
                                }
 
157
                        } finally {
 
158
                                monitor.EndTask ();
 
159
                        }
 
160
                        return result;
 
161
                }
 
162
                
 
163
                protected internal override void OnExecute (IProgressMonitor monitor, ExecutionContext context, ConfigurationSelector configuration)
 
164
                {
 
165
                        throw new NotImplementedException ();
 
166
                }
 
167
                
 
168
                protected internal override bool OnGetNeedsBuilding (ConfigurationSelector configuration)
 
169
                {
 
170
                        foreach (WorkspaceItem it in Items) {
 
171
                                if (it.NeedsBuilding (configuration))
 
172
                                        return true;
 
173
                        }
 
174
                        return false;
 
175
                }
 
176
                
 
177
                protected internal override void OnSetNeedsBuilding (bool val, ConfigurationSelector configuration)
 
178
                {
 
179
                        foreach (WorkspaceItem it in Items)
 
180
                                it.SetNeedsBuilding (val, configuration);
 
181
                }
 
182
                
 
183
                public WorkspaceItem ReloadItem (IProgressMonitor monitor, WorkspaceItem item)
 
184
                {
 
185
                        if (Items.IndexOf (item) == -1)
 
186
                                throw new InvalidOperationException ("Item '" + item.Name + "' does not belong to workspace '" + Name + "'");
 
187
 
 
188
                        // Load the new item
 
189
                        
 
190
                        WorkspaceItem newItem;
 
191
                        try {
 
192
                                newItem = Services.ProjectService.ReadWorkspaceItem (monitor, item.FileName);
 
193
                        } catch (Exception ex) {
 
194
                                UnknownWorkspaceItem e = new UnknownWorkspaceItem ();
 
195
                                e.LoadError = ex.Message;
 
196
                                e.FileName = item.FileName;
 
197
                                newItem = e;
 
198
                        }
 
199
                        
 
200
                        // Replace in the file list
 
201
                        Items.Replace (item, newItem);
 
202
                        
 
203
                        NotifyModified ();
 
204
                        NotifyItemRemoved (new WorkspaceItemChangeEventArgs (item, true));
 
205
                        NotifyItemAdded (new WorkspaceItemChangeEventArgs (newItem, true));
 
206
                        
 
207
                        item.Dispose ();
 
208
                        return newItem;
 
209
                }
 
210
 
 
211
                public override List<FilePath> GetItemFiles (bool includeReferencedFiles)
 
212
                {
 
213
                        List<FilePath> list = base.GetItemFiles (includeReferencedFiles);
 
214
                        if (includeReferencedFiles) {
 
215
                                foreach (WorkspaceItem it in Items)
 
216
                                        list.AddRange (it.GetItemFiles (true));
 
217
                        }
 
218
                        return list;
 
219
                }
 
220
 
 
221
                
 
222
                internal void NotifyItemAdded (WorkspaceItemChangeEventArgs args)
 
223
                {
 
224
                        OnItemAdded (args);
 
225
                        OnConfigurationsChanged ();
 
226
                }
 
227
                
 
228
                internal void NotifyItemRemoved (WorkspaceItemChangeEventArgs args)
 
229
                {
 
230
                        OnItemRemoved (args);
 
231
                        OnConfigurationsChanged ();
 
232
                }
 
233
                
 
234
                protected virtual void OnItemAdded (WorkspaceItemChangeEventArgs args)
 
235
                {
 
236
                        if (ItemAdded != null)
 
237
                                ItemAdded (this, args);
 
238
                        OnDescendantItemAdded (args);
 
239
                }
 
240
                
 
241
                protected virtual void OnItemRemoved (WorkspaceItemChangeEventArgs args)
 
242
                {
 
243
                        if (ItemRemoved != null)
 
244
                                ItemRemoved (this, args);
 
245
                        OnDescendantItemRemoved (args);
 
246
                }
 
247
                
 
248
                protected virtual void OnDescendantItemAdded (WorkspaceItemChangeEventArgs args)
 
249
                {
 
250
                        if (DescendantItemAdded != null)
 
251
                                DescendantItemAdded (this, args);
 
252
                        if (ParentWorkspace != null)
 
253
                                ParentWorkspace.OnDescendantItemAdded (args);
 
254
                }
 
255
                
 
256
                protected virtual void OnDescendantItemRemoved (WorkspaceItemChangeEventArgs args)
 
257
                {
 
258
                        if (DescendantItemRemoved != null)
 
259
                                DescendantItemRemoved (this, args);
 
260
                        if (ParentWorkspace != null)
 
261
                                ParentWorkspace.OnDescendantItemRemoved (args);
 
262
                }
 
263
 
 
264
                DataCollection ICustomDataItem.Serialize (ITypeSerializer handler)
 
265
                {
 
266
                        DataCollection data = handler.Serialize (this);
 
267
                        DataItem items = new DataItem ();
 
268
                        items.Name = "Items";
 
269
                        items.UniqueNames = false;
 
270
                        string baseDir = Path.GetDirectoryName (handler.SerializationContext.BaseFile);
 
271
                        foreach (WorkspaceItem it in Items) {
 
272
                                DataValue item = new DataValue ("Item", FileService.AbsoluteToRelativePath (baseDir, it.FileName));
 
273
                                items.ItemData.Add (item);
 
274
                        }
 
275
                        data.Add (items);
 
276
                        return data;
 
277
                }
 
278
 
 
279
                void ICustomDataItem.Deserialize (ITypeSerializer handler, DataCollection data)
 
280
                {
 
281
                        DataItem items = (DataItem) data.Extract ("Items");
 
282
                        handler.Deserialize (this, data);
 
283
                        IProgressMonitor monitor = handler.SerializationContext.ProgressMonitor;
 
284
                        if (monitor == null)
 
285
                                monitor = new MonoDevelop.Core.ProgressMonitoring.NullProgressMonitor ();
 
286
                        if (items != null) {
 
287
                                string baseDir = Path.GetDirectoryName (handler.SerializationContext.BaseFile);
 
288
                                monitor.BeginTask (null, items.ItemData.Count);
 
289
                                try {
 
290
                                        foreach (DataValue item in items.ItemData) {
 
291
                                                string file = Path.Combine (baseDir, item.Value);
 
292
                                                WorkspaceItem it = Services.ProjectService.ReadWorkspaceItem (monitor, file);
 
293
                                                if (it != null)
 
294
                                                        Items.Add (it);
 
295
                                                monitor.Step (1);
 
296
                                        }
 
297
                                } finally {
 
298
                                        monitor.EndTask ();
 
299
                                }
 
300
                        }
 
301
                }
 
302
                
 
303
                public event EventHandler<WorkspaceItemChangeEventArgs> ItemAdded;
 
304
                public event EventHandler<WorkspaceItemChangeEventArgs> ItemRemoved;
 
305
                public event EventHandler<WorkspaceItemChangeEventArgs> DescendantItemAdded;   // Fired if added in child workspaces
 
306
                public event EventHandler<WorkspaceItemChangeEventArgs> DescendantItemRemoved; // Fired if added in child workspaces
 
307
        }
 
308
}