~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to samples/ComponentInspector/ComponentInspector.Core/Src/ObjectBrowser/TreeNodes/ComTypeLibTreeNode.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
// <file>
 
2
//     <copyright see="prj:///doc/copyright.txt"/>
 
3
//     <license see="prj:///doc/license.txt"/>
 
4
//     <owner name="Oakland Software Incorporated" email="general@oaklandsoftware.com"/>
 
5
//     <version>$Revision$</version>
 
6
// </file>
 
7
 
 
8
using System;
 
9
using System.Collections;
 
10
using System.Windows.Forms;
 
11
 
 
12
using NoGoop.Controls;
 
13
using NoGoop.Obj;
 
14
using NoGoop.ObjBrowser.Panels;
 
15
 
 
16
namespace NoGoop.ObjBrowser.TreeNodes
 
17
{
 
18
        internal class ComTypeLibTreeNode : BrowserTreeNode, IConvertableTreeNode, IFavoriteTreeNode
 
19
        {
 
20
                protected TypeLibrary           _typeLib;
 
21
                public int HelpContext {
 
22
                        get {
 
23
                                return _typeLib.HelpContext;
 
24
                        }
 
25
                }
 
26
                
 
27
                public String HelpFile {
 
28
                        get {
 
29
                                return _typeLib.HelpFile;
 
30
                        }
 
31
                }
 
32
                
 
33
                public HelpNavigator HelpNavigator {
 
34
                        get {
 
35
                                return HelpNavigator.Topic;
 
36
                        }
 
37
                }
 
38
                
 
39
                internal TypeLibrary TypeLib {
 
40
                        get {
 
41
                                return _typeLib;
 
42
                        }
 
43
                }
 
44
                
 
45
                internal ComTypeLibTreeNode(TypeLibrary typeLib)
 
46
                {
 
47
                        _typeLib = typeLib;
 
48
                        _typeLib.TreeNode = this;
 
49
                        SetPresInfo(_typeLib.PresInfo);
 
50
                        PostConstructor();
 
51
                }
 
52
                
 
53
                public override String GetSearchNameString()
 
54
                {
 
55
                        return _typeLib.GetSearchNameString();
 
56
                }
 
57
                
 
58
                public override int GetImageIndex()
 
59
                {
 
60
                        return _typeLib.GetImageIndex();
 
61
                }
 
62
                
 
63
                public override ICollection GetSearchChildren()
 
64
                {
 
65
                        return _typeLib.GetSearchChildren();
 
66
                }
 
67
                
 
68
                public override bool HasSearchChildren(ISearcher searcher)
 
69
                {
 
70
                        return _typeLib.HasSearchChildren(searcher);
 
71
                }
 
72
                
 
73
                // Gets the objects to iterate over to make the child nodes
 
74
                protected override ICollection GetChildren()
 
75
                {
 
76
                        return _typeLib.Members;
 
77
                }
 
78
                
 
79
                // Allocates the correct type of node
 
80
                protected override BrowserTreeNode AllocateChildNode(Object obj)
 
81
                {
 
82
                        return new ComTypeTreeNode((BasicInfo)obj);
 
83
                }
 
84
                
 
85
                // Determines is this node has children
 
86
                protected override bool HasChildren()
 
87
                {
 
88
                        // Lets assume there are children without asking,
 
89
                        // because asking causes the type library to actually
 
90
                        // be opened, and we don't want to take the performance
 
91
                        // hit of doing that
 
92
                        return true;
 
93
                }
 
94
                
 
95
                public override bool HasConvert()            
 
96
                { 
 
97
                        return !_typeLib.Converted;
 
98
                }
 
99
                
 
100
                public override bool HasRegister()
 
101
                { 
 
102
                        return !_typeLib.Registered;
 
103
                }
 
104
                
 
105
                public override bool HasUnregister()
 
106
                { 
 
107
                        return _typeLib.Registered;
 
108
                }
 
109
                
 
110
                public override bool HasClose()
 
111
                { 
 
112
                        // We allow only unregistered typelibs to be closed.
 
113
                        return !_typeLib.Registered;
 
114
                }
 
115
                
 
116
                public override bool HasRemoveFavorite()
 
117
                { 
 
118
                        // Unregistered type libs in the favs section will
 
119
                        // have the close option
 
120
                        return Parent == ComSupport.FavoriteTypeLibNode && _typeLib.Registered;
 
121
                }
 
122
                
 
123
                public override void RemoveLogicalNode()
 
124
                {
 
125
                        try {
 
126
                                _typeLib.Close();
 
127
                                base.RemoveLogicalNode();
 
128
                        } catch (Exception ex) {
 
129
                                ErrorDialog.Show(ex,
 
130
                                                                "Error closing " + GetName(),
 
131
                                                                MessageBoxIcon.Error);
 
132
                        }
 
133
                }
 
134
                
 
135
                public override void Select()
 
136
                {
 
137
                        // We should check for this, because its quick to do and
 
138
                        // if one of these exists, they we will get all of the
 
139
                        // right information in the detail text.
 
140
                        _typeLib.CheckForPrimaryInteropAssy();
 
141
                        base.Select();
 
142
                }
 
143
                
 
144
                public override bool ExpandNode()
 
145
                {
 
146
                        // Do the conversion automatically
 
147
                        if (ComponentInspectorProperties.AutoConvertTypeLibs) {
 
148
                                // Returns false if failed, then expansion should not
 
149
                                // be cancelled
 
150
                                if (!DoConvertInternal())
 
151
                                        return base.ExpandNode();
 
152
                        }
 
153
                        // Returns true if this is made a favorite for the
 
154
                        // first time, and the expansion should be cancelled
 
155
                        if (MakeFavorite(true))
 
156
                                return true;
 
157
                        return base.ExpandNode();
 
158
                }
 
159
                
 
160
                public void DoConvert()
 
161
                {
 
162
                        DoConvertInternal();
 
163
                }
 
164
                
 
165
                // Returns false if failed
 
166
                protected bool DoConvertInternal()
 
167
                {
 
168
                        try {
 
169
                                // This will convert it if necessary
 
170
                                _typeLib.TranslateTypeLib();
 
171
                                // Conversion will have caused detail panel information
 
172
                                // to change
 
173
                                DetailPanel.Clear();
 
174
                                GetDetailText();
 
175
                                return true;
 
176
                        } catch (Exception ex) {
 
177
                                ErrorDialog.Show(ex,
 
178
                                                                "Error converting " + GetName(),
 
179
                                                                MessageBoxIcon.Error);
 
180
                                return false;
 
181
                        }
 
182
                }
 
183
                
 
184
                public void DoRegister()
 
185
                {
 
186
                        try {
 
187
                                _typeLib.Register();
 
188
                                MakeFavorite(false);
 
189
                                // No need to invalidate sinces its considered
 
190
                                // a favorite for now
 
191
                        } catch (Exception ex) {
 
192
                                ErrorDialog.Show(ex,
 
193
                                                                "Error registering " + GetName(),
 
194
                                                                MessageBoxIcon.Error);
 
195
                        }
 
196
                }
 
197
                
 
198
                public void DoUnregister()
 
199
                {
 
200
                        try {
 
201
                                _typeLib.Unregister();
 
202
                                ComSupport.RegisteredTypeLibNode.InvalidateNode();
 
203
                        } catch (Exception ex) {
 
204
                                ErrorDialog.Show(ex,
 
205
                                                                "Error Unregistering " + GetName(),
 
206
                                                                MessageBoxIcon.Error);
 
207
                        }
 
208
                }
 
209
                
 
210
                public void DoRemoveFavorite()
 
211
                {
 
212
                        try {
 
213
                                // Call superclass to not close the typelib
 
214
                                base.RemoveLogicalNode();
 
215
                                _typeLib.ForgetMe();
 
216
                                // This goes back into the registered tree now
 
217
                                ComSupport.RegisteredTypeLibNode.InvalidateNode();
 
218
                        } catch (Exception ex) {
 
219
                                ErrorDialog.Show(ex,
 
220
                                                                "Error Removing Favorite " + GetName(),
 
221
                                                                MessageBoxIcon.Error);
 
222
                        }
 
223
                }
 
224
                
 
225
                // Return true if this is being made a favorite, which
 
226
                // should cause the expansion of the original node to be cancelled
 
227
                protected bool MakeFavorite(bool doExpand)
 
228
                {
 
229
                        if (_typeLib.Registered && !HasRemoveFavorite()) {
 
230
                                // This may already be a favorite, since it got
 
231
                                // moved there when it was translated (if it was just
 
232
                                // translated)
 
233
                                BrowserTreeNode foundNode = ComSupport.FindTypeLib(_typeLib.Key, ComSupport.FavoriteTypeLibNode);
 
234
                                if (foundNode == null) {
 
235
                                        // Not in the favorites, put it there
 
236
                                        foundNode = new ComTypeLibTreeNode(_typeLib);
 
237
                                        ComSupport.FavoriteTypeLibNode.AddLogicalNode(foundNode);
 
238
                                }
 
239
                                _typeLib.RememberMe();
 
240
                                if (doExpand) {
 
241
                                        foundNode.Expand();
 
242
                                        foundNode.PointToNode();
 
243
                                        // Cancel expansion of original node
 
244
                                        return true;
 
245
                                }
 
246
                        }
 
247
                        return false;
 
248
                }
 
249
                
 
250
                public override String GetName()
 
251
                {
 
252
                        return _typeLib.GetName(BasicInfo.PREFER_DESCRIPTION);
 
253
                }
 
254
                
 
255
                public override void GetDetailText()
 
256
                {
 
257
                        base.GetDetailText();
 
258
                        if (_typeLib != null)
 
259
                                _typeLib.GetDetailText(TypeLibrary.SHOW_ASSY);
 
260
                }
 
261
        }
 
262
}