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

« back to all changes in this revision

Viewing changes to src/addins/MonoDevelop.GtkCore/lib/stetic/libsteticui/Project.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:
1
 
 
2
 
using System;
3
 
using System.Xml;
4
 
using System.IO;
5
 
using System.Collections;
6
 
using System.Collections.Generic;
7
 
using System.Collections.Specialized;
8
 
 
9
 
namespace Stetic
10
 
{
11
 
        public class Project: MarshalByRefObject
12
 
        {
13
 
                Application app;
14
 
                ProjectBackend backend;
15
 
                string fileName;
16
 
                IResourceProvider resourceProvider;
17
 
                Component selection;
18
 
                string tmpProjectFile;
19
 
                bool reloadRequested;
20
 
                List<WidgetInfo> widgets = new List<WidgetInfo> ();
21
 
                List<ActionGroupInfo> groups = new List<ActionGroupInfo> ();
22
 
                bool modified;
23
 
                ImportFileDelegate importFileDelegate;
24
 
                
25
 
                public event WidgetInfoEventHandler WidgetAdded;
26
 
                public event WidgetInfoEventHandler WidgetRemoved;
27
 
                public event ComponentNameEventHandler ComponentNameChanged;
28
 
                public event EventHandler ComponentTypesChanged;
29
 
                
30
 
                public event EventHandler ActionGroupsChanged;
31
 
                public event EventHandler ModifiedChanged;
32
 
                public event EventHandler Changed;
33
 
 
34
 
                
35
 
                // Internal events
36
 
                internal event BackendChangingHandler BackendChanging;
37
 
                internal event BackendChangedHandler BackendChanged;
38
 
                internal event ComponentSignalEventHandler SignalAdded;
39
 
                internal event ComponentSignalEventHandler SignalRemoved;
40
 
                internal event ComponentSignalEventHandler SignalChanged;
41
 
 
42
 
                public event EventHandler ProjectReloading;
43
 
                public event EventHandler ProjectReloaded;
44
 
 
45
 
                internal Project (Application app): this (app, null)
46
 
                {
47
 
                }
48
 
                
49
 
                internal Project (Application app, ProjectBackend backend)
50
 
                {
51
 
                        this.app = app;
52
 
                        if (backend != null) {
53
 
                                this.backend = backend;
54
 
                                backend.SetFrontend (this);
55
 
                        }
56
 
 
57
 
                        app.BackendChanging += OnBackendChanging;
58
 
                        app.BackendChanged += OnBackendChanged;
59
 
                }
60
 
                
61
 
                internal ProjectBackend ProjectBackend {
62
 
                        get {
63
 
                                if (backend == null) {
64
 
                                        backend = app.Backend.CreateProject ();
65
 
                                        backend.SetFrontend (this);
66
 
                                        if (resourceProvider != null)
67
 
                                                backend.ResourceProvider = resourceProvider;
68
 
                                        if (fileName != null)
69
 
                                                backend.Load (fileName);
70
 
                                }
71
 
                                return backend; 
72
 
                        }
73
 
                }
74
 
                
75
 
                internal bool IsBackendLoaded {
76
 
                        get { return backend != null; }
77
 
                }
78
 
                
79
 
                internal Application App {
80
 
                        get { return app; }
81
 
                }
82
 
                
83
 
                public void Dispose ()
84
 
                {
85
 
                        app.BackendChanging -= OnBackendChanging;
86
 
                        app.BackendChanged -= OnBackendChanged;
87
 
                        
88
 
                        if (tmpProjectFile != null && File.Exists (tmpProjectFile)) {
89
 
                                File.Delete (tmpProjectFile);
90
 
                                tmpProjectFile = null;
91
 
                        }
92
 
                        if (backend != null)
93
 
                                backend.Dispose ();
94
 
                        app.DisposeProject (this);
95
 
                        System.Runtime.Remoting.RemotingServices.Disconnect (this);
96
 
                        app.UpdateWidgetLibraries (false, false);
97
 
                }
98
 
 
99
 
                public override object InitializeLifetimeService ()
100
 
                {
101
 
                        // Will be disconnected when calling Dispose
102
 
                        return null;
103
 
                }
104
 
 
105
 
                public string FileName {
106
 
                        get { return fileName; }
107
 
                }
108
 
                
109
 
                public IResourceProvider ResourceProvider { 
110
 
                        get { return resourceProvider; }
111
 
                        set { 
112
 
                                resourceProvider = value;
113
 
                                if (backend != null)
114
 
                                        backend.ResourceProvider = value;
115
 
                        }
116
 
                }
117
 
                
118
 
                public Stetic.ProjectIconFactory IconFactory {
119
 
                        get { return ProjectBackend.IconFactory; }
120
 
                        set { backend.IconFactory = value; }
121
 
                }
122
 
                
123
 
                public ImportFileDelegate ImportFileCallback {
124
 
                        get { return importFileDelegate; }
125
 
                        set { importFileDelegate = value; }
126
 
                }
127
 
                
128
 
                public bool CanGenerateCode {
129
 
                        get { return ProjectBackend.CanGenerateCode; }
130
 
                }
131
 
                
132
 
                public Component Selection {
133
 
                        get { return selection; }
134
 
                }
135
 
                
136
 
                public string ImagesRootPath {
137
 
                        get { return ProjectBackend.ImagesRootPath; }
138
 
                        set { ProjectBackend.ImagesRootPath = value; }
139
 
                }
140
 
                
141
 
                public string TargetGtkVersion {
142
 
                        get { return ProjectBackend.TargetGtkVersion; }
143
 
                        set { ProjectBackend.TargetGtkVersion = value; }
144
 
                }
145
 
                
146
 
                public void Close ()
147
 
                {
148
 
                        if (backend != null)
149
 
                                backend.Close ();
150
 
                }
151
 
                
152
 
                public void Load (string fileName)
153
 
                {
154
 
                        this.fileName = fileName;
155
 
                        if (backend != null)
156
 
                                backend.Load (fileName);
157
 
                        
158
 
                        using (StreamReader sr = new StreamReader (fileName)) {
159
 
                                XmlTextReader reader = new XmlTextReader (sr); 
160
 
                                
161
 
                                reader.MoveToContent ();
162
 
                                if (reader.IsEmptyElement)
163
 
                                        return;
164
 
                                
165
 
                                reader.ReadStartElement ("stetic-interface");
166
 
                                if (reader.IsEmptyElement)
167
 
                                        return;
168
 
                                while (reader.NodeType != XmlNodeType.EndElement) {
169
 
                                        if (reader.NodeType == XmlNodeType.Element) {
170
 
                                                if (reader.LocalName == "widget")
171
 
                                                        ReadWidget (reader);
172
 
                                                else if (reader.LocalName == "action-group")
173
 
                                                        ReadActionGroup (reader);
174
 
                                                else
175
 
                                                        reader.Skip ();
176
 
                                        }
177
 
                                        else {
178
 
                                                reader.Skip ();
179
 
                                        }
180
 
                                        reader.MoveToContent ();
181
 
                                }
182
 
                        }
183
 
                }
184
 
                
185
 
                void ReadWidget (XmlTextReader reader)
186
 
                {
187
 
                        WidgetInfo w = new WidgetInfo (this, reader.GetAttribute ("id"), reader.GetAttribute ("class"));
188
 
                        widgets.Add (w);
189
 
                        if (reader.IsEmptyElement) {
190
 
                                reader.Skip ();
191
 
                                return;
192
 
                        }
193
 
                        reader.ReadStartElement ();
194
 
                        reader.MoveToContent ();
195
 
                        while (reader.NodeType != XmlNodeType.EndElement) {
196
 
                                if (reader.NodeType == XmlNodeType.Element && reader.LocalName == "action-group") {
197
 
                                        w.AddGroup (reader.GetAttribute ("name"));
198
 
                                }
199
 
                                reader.Skip ();
200
 
                                reader.MoveToContent ();
201
 
                        }
202
 
                        reader.ReadEndElement ();
203
 
                }
204
 
                
205
 
                void ReadActionGroup (XmlTextReader reader)
206
 
                {
207
 
                        groups.Add (new ActionGroupInfo (this, reader.GetAttribute ("name")));
208
 
                        reader.Skip ();
209
 
                }
210
 
                
211
 
                public void Save (string fileName)
212
 
                {
213
 
                        this.fileName = fileName;
214
 
                        if (backend != null)
215
 
                                backend.Save (fileName);
216
 
                }
217
 
                
218
 
                public void ImportGlade (string fileName)
219
 
                {
220
 
                        ProjectBackend.ImportGlade (fileName);
221
 
                }
222
 
                
223
 
                public void ExportGlade (string fileName)
224
 
                {
225
 
                        ProjectBackend.ExportGlade (fileName);
226
 
                }
227
 
                
228
 
                public bool Modified {
229
 
                        get {
230
 
                                if (backend != null)
231
 
                                        return backend.Modified; 
232
 
                                else
233
 
                                        return modified;
234
 
                        }
235
 
                        set {
236
 
                                if (backend != null)
237
 
                                        backend.Modified = value;       
238
 
                                else
239
 
                                        modified = true;
240
 
                        }
241
 
                }
242
 
                
243
 
                public IEnumerable<WidgetInfo> Widgets {
244
 
                        get { return widgets; }
245
 
                }
246
 
                
247
 
                public IEnumerable<ActionGroupInfo> ActionGroups {
248
 
                        get { return groups; }
249
 
                }
250
 
                
251
 
                public WidgetInfo GetWidget (string name)
252
 
                {
253
 
                        foreach (WidgetInfo w in widgets)
254
 
                                if (w.Name == name)
255
 
                                        return w;
256
 
                        return null;
257
 
                }
258
 
                
259
 
                public ActionGroupInfo GetActionGroup (string name)
260
 
                {
261
 
                        foreach (ActionGroupInfo w in groups)
262
 
                                if (w.Name == name)
263
 
                                        return w;
264
 
                        return null;
265
 
                }
266
 
                                
267
 
                public WidgetDesigner CreateWidgetDesigner (WidgetInfo widgetInfo, bool autoCommitChanges)
268
 
                {
269
 
                        return new WidgetDesigner (this, widgetInfo.Name, autoCommitChanges);
270
 
                }
271
 
                
272
 
                public ActionGroupDesigner CreateActionGroupDesigner (ActionGroupInfo actionGroup, bool autoCommitChanges)
273
 
                {
274
 
                        return new ActionGroupDesigner (this, null, actionGroup.Name, null, autoCommitChanges);
275
 
                }
276
 
 
277
 
                public WidgetInfo AddNewComponent (ComponentType type, string name)
278
 
                {
279
 
                        object ob = ProjectBackend.AddNewWidget (type.Name, name);
280
 
                        WidgetComponent wc = (WidgetComponent) App.GetComponent (ob, null, null);
281
 
                        WidgetInfo wi = GetWidget (wc.Name);
282
 
                        if (wi == null) {
283
 
                                wi = new WidgetInfo (this, wc);
284
 
                                widgets.Add (wi);
285
 
                        }
286
 
                        return wi;
287
 
                }
288
 
                
289
 
                public WidgetInfo AddNewComponent (XmlElement template)
290
 
                {
291
 
                        object ob = ProjectBackend.AddNewWidgetFromTemplate (template.OuterXml);
292
 
                        WidgetComponent wc = (WidgetComponent) App.GetComponent (ob, null, null);
293
 
                        WidgetInfo wi = GetWidget (wc.Name);
294
 
                        if (wi == null) {
295
 
                                wi = new WidgetInfo (this, wc);
296
 
                                widgets.Add (wi);
297
 
                        }
298
 
                        return wi;
299
 
                }
300
 
                
301
 
                public ComponentType[] GetComponentTypes ()
302
 
                {
303
 
                        ArrayList types = new ArrayList ();
304
 
                        
305
 
                        ArrayList typeNames = ProjectBackend.GetComponentTypes ();
306
 
                        for (int n=0; n<typeNames.Count; n++)
307
 
                                types.Add (app.GetComponentType ((string) typeNames [n]));
308
 
 
309
 
                        // Global action groups
310
 
                        foreach (ActionGroupComponent grp in GetActionGroups ()) {
311
 
                                foreach (ActionComponent ac in grp.GetActions ())
312
 
                                        types.Add (new ComponentType (app, ac));
313
 
                        }
314
 
                        
315
 
                        return (ComponentType[]) types.ToArray (typeof(ComponentType));
316
 
                }
317
 
                
318
 
                // Returns a list of all support widget types (including base classes)
319
 
                public string[] GetWidgetTypes ()
320
 
                {
321
 
                        return ProjectBackend.GetWidgetTypes ();
322
 
                }
323
 
                
324
 
                public void RemoveComponent (WidgetInfo component)
325
 
                {
326
 
                        ProjectBackend.RemoveWidget (component.Name);
327
 
                }
328
 
                
329
 
                public WidgetComponent GetComponent (string name)
330
 
                {
331
 
                        object ob = ProjectBackend.GetTopLevelWrapper (name, false);
332
 
                        if (ob != null)
333
 
                                return (WidgetComponent) App.GetComponent (ob, name, null);
334
 
                        else
335
 
                                return null;
336
 
                }
337
 
                
338
 
                public ActionGroupComponent AddNewActionGroup (string id)
339
 
                {
340
 
                        object ob = ProjectBackend.AddNewActionGroup (id);
341
 
                        ActionGroupComponent ac = (ActionGroupComponent) App.GetComponent (ob, id, null);
342
 
                        
343
 
                        // Don't wait for the group added event to come to update the groups list since
344
 
                        // it may be too late.
345
 
                        ActionGroupInfo gi = GetActionGroup (ac.Name);
346
 
                        if (gi == null) {
347
 
                                gi = new ActionGroupInfo (this, ac.Name);
348
 
                                groups.Add (gi);
349
 
                        }
350
 
                        return ac;
351
 
                }
352
 
                
353
 
                public ActionGroupComponent AddNewActionGroup (XmlElement template)
354
 
                {
355
 
                        object ob = ProjectBackend.AddNewActionGroupFromTemplate (template.OuterXml);
356
 
                        ActionGroupComponent ac = (ActionGroupComponent) App.GetComponent (ob, null, null);
357
 
                        
358
 
                        // Don't wait for the group added event to come to update the groups list since
359
 
                        // it may be too late.
360
 
                        ActionGroupInfo gi = GetActionGroup (ac.Name);
361
 
                        if (gi == null) {
362
 
                                gi = new ActionGroupInfo (this, ac.Name);
363
 
                                groups.Add (gi);
364
 
                        }
365
 
                        return ac;
366
 
                }
367
 
                
368
 
                public void RemoveActionGroup (ActionGroupInfo group)
369
 
                {
370
 
                        ActionGroupComponent ac = (ActionGroupComponent) group.Component;
371
 
                        ProjectBackend.RemoveActionGroup ((Stetic.Wrapper.ActionGroup) ac.Backend);
372
 
                }
373
 
                
374
 
                internal ActionGroupComponent[] GetActionGroups ()
375
 
                {
376
 
                        Wrapper.ActionGroup[] acs = ProjectBackend.GetActionGroups ();
377
 
                        
378
 
                        ArrayList comps = new ArrayList (acs.Length);
379
 
                        for (int n=0; n<acs.Length; n++) {
380
 
                                ActionGroupComponent ag = (ActionGroupComponent) App.GetComponent (acs[n], null, null);
381
 
                                if (ag != null)
382
 
                                        comps.Add (ag);
383
 
                        }
384
 
                                
385
 
                        return (ActionGroupComponent[]) comps.ToArray (typeof(ActionGroupComponent));
386
 
                }
387
 
 
388
 
                public void AddWidgetLibrary (string assemblyPath)
389
 
                {
390
 
                        AddWidgetLibrary (assemblyPath, false);
391
 
                }
392
 
                
393
 
                public void AddWidgetLibrary (string assemblyPath, bool isInternal)
394
 
                {
395
 
                        reloadRequested = false;
396
 
                        ProjectBackend.AddWidgetLibrary (assemblyPath);
397
 
                        app.UpdateWidgetLibraries (false, false);
398
 
                        if (!reloadRequested)
399
 
                                ProjectBackend.Reload ();
400
 
                }
401
 
                
402
 
                public void RemoveWidgetLibrary (string assemblyPath)
403
 
                {
404
 
                        reloadRequested = false;
405
 
                        ProjectBackend.RemoveWidgetLibrary (assemblyPath);
406
 
                        app.UpdateWidgetLibraries (false, false);
407
 
                        if (!reloadRequested)
408
 
                                ProjectBackend.Reload ();
409
 
                }
410
 
                
411
 
                public string[] WidgetLibraries {
412
 
                        get {
413
 
                                return (string[]) ProjectBackend.WidgetLibraries.ToArray (typeof(string));
414
 
                        }
415
 
                }
416
 
                
417
 
                public void SetWidgetLibraries (string[] libraries, string[] internalLibraries)
418
 
                {
419
 
                        reloadRequested = false;
420
 
                        
421
 
                        ArrayList libs = new ArrayList ();
422
 
                        libs.AddRange (libraries);
423
 
                        libs.AddRange (internalLibraries);
424
 
                        ProjectBackend.WidgetLibraries = libs;
425
 
                        
426
 
                        libs = new ArrayList ();
427
 
                        libs.AddRange (internalLibraries);
428
 
                        ProjectBackend.InternalWidgetLibraries = libs;
429
 
                        
430
 
                        app.UpdateWidgetLibraries (false, false);
431
 
                        if (!reloadRequested)
432
 
                                ProjectBackend.Reload ();
433
 
                }
434
 
                
435
 
/*              public bool CanCopySelection {
436
 
                        get { return Selection != null ? Selection.CanCopy : false; }
437
 
                }
438
 
                
439
 
                public bool CanCutSelection {
440
 
                        get { return Selection != null ? Selection.CanCut : false; }
441
 
                }
442
 
                
443
 
                public bool CanPasteToSelection {
444
 
                        get { return Selection != null ? Selection.CanPaste : false; }
445
 
                }
446
 
                
447
 
                public void CopySelection ()
448
 
                {
449
 
                        if (Selection != null)
450
 
                                backend.ClipboardCopySelection ();
451
 
                }
452
 
                
453
 
                public void CutSelection ()
454
 
                {
455
 
                        if (Selection != null)
456
 
                                backend.ClipboardCutSelection ();
457
 
                }
458
 
                
459
 
                public void PasteToSelection ()
460
 
                {
461
 
                        if (Selection != null)
462
 
                                backend.ClipboardPaste ();
463
 
                }
464
 
                
465
 
                public void DeleteSelection ()
466
 
                {
467
 
                        backend.DeleteSelection ();
468
 
                }
469
 
*/
470
 
                
471
 
                public void EditIcons ()
472
 
                {
473
 
                        ProjectBackend.EditIcons ();
474
 
                }
475
 
                
476
 
                internal void NotifyWidgetAdded (object obj, string name, string typeName)
477
 
                {
478
 
                        GuiDispatch.InvokeSync (
479
 
                                delegate {
480
 
                                        Component c = App.GetComponent (obj, name, typeName);
481
 
                                        if (c != null) {
482
 
                                                WidgetInfo wi = GetWidget (c.Name);
483
 
                                                if (wi == null) {
484
 
                                                        wi = new WidgetInfo (this, c);
485
 
                                                        widgets.Add (wi);
486
 
                                                }
487
 
                                                if (WidgetAdded != null)
488
 
                                                        WidgetAdded (this, new WidgetInfoEventArgs (this, wi));
489
 
                                        }
490
 
                                }
491
 
                        );
492
 
                }
493
 
                
494
 
                internal void NotifyWidgetRemoved (string name)
495
 
                {
496
 
                        GuiDispatch.InvokeSync (
497
 
                                delegate {
498
 
                                        WidgetInfo wi = GetWidget (name);
499
 
                                        if (wi != null) {
500
 
                                                widgets.Remove (wi);
501
 
                                                if (WidgetRemoved != null)
502
 
                                                        WidgetRemoved (this, new WidgetInfoEventArgs (this, wi));
503
 
                                        }
504
 
                                }
505
 
                        );
506
 
                }
507
 
                
508
 
                internal void NotifyModifiedChanged ()
509
 
                {
510
 
                        GuiDispatch.InvokeSync (
511
 
                                delegate {
512
 
                                        if (ModifiedChanged != null)
513
 
                                                ModifiedChanged (this, EventArgs.Empty);
514
 
                                }
515
 
                        );
516
 
                }
517
 
                
518
 
                internal void NotifyChanged ()
519
 
                {
520
 
                        GuiDispatch.InvokeSync (
521
 
                                delegate {
522
 
                                        if (Changed != null)
523
 
                                                Changed (this, EventArgs.Empty);
524
 
                                
525
 
                                        // TODO: Optimize
526
 
                                        foreach (ProjectItemInfo it in widgets)
527
 
                                                it.NotifyChanged ();
528
 
                                        foreach (ProjectItemInfo it in groups)
529
 
                                                it.NotifyChanged ();
530
 
                                }
531
 
                        );
532
 
                }
533
 
                
534
 
                internal void NotifyWidgetNameChanged (object obj, string oldName, string newName, bool isRoot)
535
 
                {
536
 
                        WidgetComponent c = obj != null ? (WidgetComponent) App.GetComponent (obj, null, null) : null;
537
 
                        if (c != null)
538
 
                                c.UpdateName (newName);
539
 
                        
540
 
                        if (isRoot) {
541
 
                                WidgetInfo wi = GetWidget (oldName);
542
 
                                if (wi != null)
543
 
                                        wi.NotifyNameChanged (newName);
544
 
                        }
545
 
                        
546
 
                        GuiDispatch.InvokeSync (
547
 
                                delegate {
548
 
                                        if (c != null) {
549
 
                                                if (ComponentNameChanged != null)
550
 
                                                        ComponentNameChanged (this, new ComponentNameEventArgs (this, c, oldName));
551
 
                                        }
552
 
                                }
553
 
                        );
554
 
                }
555
 
                
556
 
                internal void NotifyActionGroupAdded (string group)
557
 
                {
558
 
                        GuiDispatch.InvokeSync (delegate {
559
 
                                ActionGroupInfo gi = GetActionGroup (group);
560
 
                                if (gi == null) {
561
 
                                        gi = new ActionGroupInfo (this, group);
562
 
                                        groups.Add (gi);
563
 
                                }
564
 
                                if (ActionGroupsChanged != null)
565
 
                                        ActionGroupsChanged (this, EventArgs.Empty);
566
 
                        });
567
 
                }
568
 
                
569
 
                internal void NotifyActionGroupRemoved (string group)
570
 
                {
571
 
                        GuiDispatch.InvokeSync (delegate {
572
 
                                ActionGroupInfo gi = GetActionGroup (group);
573
 
                                if (gi != null) {
574
 
                                        groups.Remove (gi);
575
 
                                        if (ActionGroupsChanged != null)
576
 
                                                ActionGroupsChanged (this, EventArgs.Empty);
577
 
                                }
578
 
                        });
579
 
                }
580
 
                
581
 
                internal void NotifySignalAdded (object obj, string name, Signal signal)
582
 
                {
583
 
                        GuiDispatch.InvokeSync (delegate {
584
 
                                if (SignalAdded != null) {
585
 
                                        Component c = App.GetComponent (obj, name, null);
586
 
                                        if (c != null)
587
 
                                                SignalAdded (this, new ComponentSignalEventArgs (this, c, null, signal));
588
 
                                }
589
 
                        });
590
 
                }
591
 
                
592
 
                internal void NotifySignalRemoved (object obj, string name, Signal signal)
593
 
                {
594
 
                        GuiDispatch.InvokeSync (delegate {
595
 
                                if (SignalRemoved != null) {
596
 
                                        Component c = App.GetComponent (obj, name, null);
597
 
                                        if (c != null)
598
 
                                                SignalRemoved (this, new ComponentSignalEventArgs (this, c, null, signal));
599
 
                                }
600
 
                        });
601
 
                }
602
 
                
603
 
                internal void NotifySignalChanged (object obj, string name, Signal oldSignal, Signal signal)
604
 
                {
605
 
                        GuiDispatch.InvokeSync (delegate {
606
 
                                if (SignalChanged != null) {
607
 
                                        Component c = App.GetComponent (obj, name, null);
608
 
                                        if (c != null)
609
 
                                                SignalChanged (this, new ComponentSignalEventArgs (this, c, oldSignal, signal));
610
 
                                }
611
 
                        });
612
 
                }
613
 
                
614
 
                internal void NotifyProjectReloaded ()
615
 
                {
616
 
                        GuiDispatch.InvokeSync (delegate {
617
 
                                if (ProjectReloaded != null)
618
 
                                        ProjectReloaded (this, EventArgs.Empty);
619
 
                        });
620
 
                }
621
 
                
622
 
                internal void NotifyProjectReloading ()
623
 
                {
624
 
                        GuiDispatch.InvokeSync (delegate {
625
 
                                if (ProjectReloading != null)
626
 
                                        ProjectReloading (this, EventArgs.Empty);
627
 
                        });
628
 
                }
629
 
                
630
 
                internal void NotifyComponentTypesChanged ()
631
 
                {
632
 
                        GuiDispatch.InvokeSync (delegate {
633
 
                                if (ComponentTypesChanged != null)
634
 
                                        ComponentTypesChanged (this, EventArgs.Empty);
635
 
                        });
636
 
                }
637
 
                
638
 
                internal string ImportFile (string filePath)
639
 
                {
640
 
                        if (importFileDelegate != null) {
641
 
                                string res = null;
642
 
                                GuiDispatch.InvokeSync (delegate {
643
 
                                        res = importFileDelegate (filePath);
644
 
                                });
645
 
                                return res;
646
 
                        }
647
 
                        else
648
 
                                return filePath;
649
 
                }
650
 
                
651
 
                internal void NotifyUpdateLibraries ()
652
 
                {
653
 
                        app.UpdateWidgetLibraries (false, false);
654
 
                }
655
 
                
656
 
                void OnBackendChanging ()
657
 
                {
658
 
                        selection = null;
659
 
                                
660
 
                        if (BackendChanging != null)
661
 
                                BackendChanging ();
662
 
                }
663
 
                
664
 
                void OnBackendChanged (ApplicationBackend oldBackend)
665
 
                {
666
 
                        if (oldBackend != null) {
667
 
                                tmpProjectFile = Path.GetTempFileName ();
668
 
                                backend.Save (tmpProjectFile);
669
 
                        }
670
 
                        
671
 
                        backend = app.Backend.CreateProject ();
672
 
                        backend.SetFrontend (this);
673
 
 
674
 
                        if (tmpProjectFile != null && File.Exists (tmpProjectFile)) {
675
 
                                backend.Load (tmpProjectFile, fileName);
676
 
                                File.Delete (tmpProjectFile);
677
 
                                tmpProjectFile = null;
678
 
                        } else if (fileName != null) {
679
 
                                backend.Load (fileName);
680
 
                        }
681
 
 
682
 
                        if (resourceProvider != null)
683
 
                                backend.ResourceProvider = resourceProvider;
684
 
 
685
 
                        if (BackendChanged != null)
686
 
                                BackendChanged (oldBackend);
687
 
                                
688
 
                        if (ProjectReloaded != null)
689
 
                                ProjectReloaded (this, EventArgs.Empty);
690
 
                }
691
 
        }
692
 
 
693
 
        public abstract class ProjectItemInfo
694
 
        {
695
 
                string name;
696
 
                protected Project project;
697
 
                
698
 
                public event EventHandler Changed;
699
 
 
700
 
                internal ProjectItemInfo (Project project, string name)
701
 
                {
702
 
                        this.name = name;
703
 
                        this.project = project;
704
 
                }
705
 
                
706
 
                public string Name {
707
 
                        get { return name; }
708
 
                        set { Component.Name = value; name = value; }
709
 
                }
710
 
                
711
 
                internal void NotifyNameChanged (string name)
712
 
                {
713
 
                        this.name = name;
714
 
                        NotifyChanged ();
715
 
                }
716
 
                
717
 
                internal void NotifyChanged ()
718
 
                {
719
 
                        if (Changed != null)
720
 
                                Changed (this, EventArgs.Empty);
721
 
                }
722
 
                
723
 
                public abstract Component Component { get; }
724
 
        }
725
 
                
726
 
        public class WidgetInfo: ProjectItemInfo
727
 
        {
728
 
                string type;
729
 
                List<ActionGroupInfo> groups;
730
 
                
731
 
                internal WidgetInfo (Project project, string name, string type): base (project, name)
732
 
                {
733
 
                        this.type = type;
734
 
                }
735
 
                
736
 
                internal WidgetInfo (Project project, Component c): base (project, c.Name)
737
 
                {
738
 
                        type = c.Type.Name;
739
 
                }
740
 
                
741
 
                public IEnumerable<ActionGroupInfo> ActionGroups {
742
 
                        get {
743
 
                                if (groups != null)
744
 
                                        return groups;
745
 
                                else
746
 
                                        return new ActionGroupInfo [0];
747
 
                        }
748
 
                }
749
 
                
750
 
                public string Type {
751
 
                        get { return type; }
752
 
                }
753
 
                
754
 
                public bool IsWindow {
755
 
                        get { return type == "Gtk.Dialog" || type == "Gtk.Window"; }
756
 
                }
757
 
                
758
 
                public override Component Component {
759
 
                        get { return project.GetComponent (Name); }
760
 
                }
761
 
                
762
 
                internal void AddGroup (string group)
763
 
                {
764
 
                        if (groups == null)
765
 
                                groups = new List<ActionGroupInfo> ();
766
 
                        groups.Add (new ActionGroupInfo (project, group, Name));
767
 
                }
768
 
        }
769
 
        
770
 
        public class ActionGroupInfo: ProjectItemInfo
771
 
        {
772
 
                string widgetName;
773
 
                
774
 
                internal ActionGroupInfo (Project project, string name): base (project, name)
775
 
                {
776
 
                }
777
 
                
778
 
                internal ActionGroupInfo (Project project, string name, string widgetName): base (project, name)
779
 
                {
780
 
                        this.widgetName = widgetName;
781
 
                }
782
 
                
783
 
                public override Component Component {
784
 
                        get {
785
 
                                ActionGroupComponent[] ags;
786
 
                                if (widgetName != null) {
787
 
                                        WidgetComponent c = project.GetComponent (widgetName) as WidgetComponent;
788
 
                                        if (c == null)
789
 
                                                return null;
790
 
                                        ags = c.GetActionGroups ();
791
 
                                }
792
 
                                else {
793
 
                                        ags = project.GetActionGroups ();
794
 
                                }
795
 
                                foreach (ActionGroupComponent ag in ags)
796
 
                                        if (ag.Name == Name)
797
 
                                                return ag;
798
 
                                return null;
799
 
                        }
800
 
                }
801
 
        }
802
 
        
803
 
        public delegate string ImportFileDelegate (string fileName);
804
 
}