Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: experimental/visual_studio_plugin/third_party/Microsoft.VisualStudio.Project/NodeProperties.cs

Issue 10928195: First round of dead file removal (Closed) Base URL: https://github.com/samclegg/nativeclient-sdk.git@master
Patch Set: Created 8 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 /// Copyright (c) Microsoft Corporation. All rights reserved.
2
3 using System;
4 using System.ComponentModel;
5 using System.Diagnostics;
6 using System.Diagnostics.CodeAnalysis;
7 using System.Globalization;
8 using System.IO;
9 using System.Runtime.InteropServices;
10 using Microsoft.VisualStudio;
11 using Microsoft.VisualStudio.OLE.Interop;
12 using Microsoft.VisualStudio.Shell;
13 using Microsoft.VisualStudio.Shell.Interop;
14 using IOleServiceProvider = Microsoft.VisualStudio.OLE.Interop.IServiceProvider;
15
16 namespace Microsoft.VisualStudio.Project
17 {
18
19 /// <summary>
20 /// All public properties on Nodeproperties or derived classes are assum ed to be used by Automation by default.
21 /// Set this attribute to false on Properties that should not be visible for Automation.
22 /// </summary>
23 [AttributeUsage(AttributeTargets.Property, AllowMultiple = false, Inheri ted = true)]
24 public sealed class AutomationBrowsableAttribute : System.Attribute
25 {
26 public AutomationBrowsableAttribute(bool browsable)
27 {
28 this.browsable = browsable;
29 }
30
31 public bool Browsable
32 {
33 get
34 {
35 return this.browsable;
36 }
37 }
38
39 private bool browsable;
40 }
41
42 /// <summary>
43 /// To create your own localizable node properties, subclass this and ad d public properties
44 /// decorated with your own localized display name, category and descrip tion attributes.
45 /// </summary>
46 [CLSCompliant(false), ComVisible(true)]
47 public class NodeProperties : LocalizableProperties,
48 ISpecifyPropertyPages,
49 IVsGetCfgProvider,
50 IVsSpecifyProjectDesignerPages,
51 EnvDTE80.IInternalExtenderProvider,
52 IVsBrowseObject
53 {
54 #region fields
55 private HierarchyNode node;
56 #endregion
57
58 #region properties
59 [Browsable(false)]
60 [AutomationBrowsable(false)]
61 public HierarchyNode Node
62 {
63 get { return this.node; }
64 }
65
66 /// <summary>
67 /// Used by Property Pages Frame to set it's title bar. The Capt ion of the Hierarchy Node is returned.
68 /// </summary>
69 [Browsable(false)]
70 [AutomationBrowsable(false)]
71 public virtual string Name
72 {
73 get { return this.node.Caption; }
74 }
75
76 #endregion
77
78 #region ctors
79 public NodeProperties(HierarchyNode node)
80 {
81 if(node == null)
82 {
83 throw new ArgumentNullException("node");
84 }
85 this.node = node;
86 }
87 #endregion
88
89 #region ISpecifyPropertyPages methods
90 public virtual void GetPages(CAUUID[] pages)
91 {
92 this.GetCommonPropertyPages(pages);
93 }
94 #endregion
95
96 #region IVsSpecifyProjectDesignerPages
97 /// <summary>
98 /// Implementation of the IVsSpecifyProjectDesignerPages. It wil l retun the pages that are configuration independent.
99 /// </summary>
100 /// <param name="pages">The pages to return.</param>
101 /// <returns></returns>
102 public virtual int GetProjectDesignerPages(CAUUID[] pages)
103 {
104 this.GetCommonPropertyPages(pages);
105 return VSConstants.S_OK;
106 }
107 #endregion
108
109 #region IVsGetCfgProvider methods
110 public virtual int GetCfgProvider(out IVsCfgProvider p)
111 {
112 p = null;
113 return VSConstants.E_NOTIMPL;
114 }
115 #endregion
116
117 #region IVsBrowseObject methods
118 /// <summary>
119 /// Maps back to the hierarchy or project item object correspond ing to the browse object.
120 /// </summary>
121 /// <param name="hier">Reference to the hierarchy object.</param >
122 /// <param name="itemid">Reference to the project item.</param>
123 /// <returns>If the method succeeds, it returns S_OK. If it fail s, it returns an error code. </returns>
124 public virtual int GetProjectItem(out IVsHierarchy hier, out uin t itemid)
125 {
126 if(this.node == null)
127 {
128 throw new InvalidOperationException();
129 }
130 hier = HierarchyNode.GetOuterHierarchy(this.node.Project Mgr);
131 itemid = this.node.ID;
132 return VSConstants.S_OK;
133 }
134 #endregion
135
136 #region overridden methods
137 /// <summary>
138 /// Get the Caption of the Hierarchy Node instance. If Caption i s null or empty we delegate to base
139 /// </summary>
140 /// <returns>Caption of Hierarchy node instance</returns>
141 public override string GetComponentName()
142 {
143 string caption = this.Node.Caption;
144 if(string.IsNullOrEmpty(caption))
145 {
146 return base.GetComponentName();
147 }
148 else
149 {
150 return caption;
151 }
152 }
153 #endregion
154
155 #region helper methods
156 protected string GetProperty(string name, string def)
157 {
158 string a = this.Node.ItemNode.GetMetadata(name);
159 return (a == null) ? def : a;
160 }
161
162 protected void SetProperty(string name, string value)
163 {
164 this.Node.ItemNode.SetMetadata(name, value);
165 }
166
167 /// <summary>
168 /// Retrieves the common property pages. The NodeProperties is t he BrowseObject and that will be called to support
169 /// configuration independent properties.
170 /// </summary>
171 /// <param name="pages">The pages to return.</param>
172 private void GetCommonPropertyPages(CAUUID[] pages)
173 {
174 // We do not check whether the supportsProjectDesigner i s set to false on the ProjectNode.
175 // We rely that the caller knows what to call on us.
176 if(pages == null)
177 {
178 throw new ArgumentNullException("pages");
179 }
180
181 if(pages.Length == 0)
182 {
183 throw new ArgumentException(SR.GetString(SR.Inva lidParameter, CultureInfo.CurrentUICulture), "pages");
184 }
185
186 // Only the project should show the property page the re st should show the project properties.
187 if(this.node != null && (this.node is ProjectNode))
188 {
189 // Retrieve the list of guids from hierarchy pro perties.
190 // Because a flavor could modify that list we mu st make sure we are calling the outer most implementation of IVsHierarchy
191 string guidsList = String.Empty;
192 IVsHierarchy hierarchy = HierarchyNode.GetOuterH ierarchy(this.Node.ProjectMgr);
193 object variant = null;
194 ErrorHandler.ThrowOnFailure(hierarchy.GetPropert y(VSConstants.VSITEMID_ROOT, (int)__VSHPROPID2.VSHPROPID_PropertyPagesCLSIDList, out variant));
195 guidsList = (string)variant;
196
197 Guid[] guids = Utilities.GuidsArrayFromSemicolon DelimitedStringOfGuids(guidsList);
198 if(guids == null || guids.Length == 0)
199 {
200 pages[0] = new CAUUID();
201 pages[0].cElems = 0;
202 }
203 else
204 {
205 pages[0] = PackageUtilities.CreateCAUUID FromGuidArray(guids);
206 }
207 }
208 else
209 {
210 pages[0] = new CAUUID();
211 pages[0].cElems = 0;
212 }
213 }
214 #endregion
215
216 #region IInternalExtenderProvider Members
217
218 bool EnvDTE80.IInternalExtenderProvider.CanExtend(string extende rCATID, string extenderName, object extendeeObject)
219 {
220 EnvDTE80.IInternalExtenderProvider outerHierarchy = Hier archyNode.GetOuterHierarchy(this.Node) as EnvDTE80.IInternalExtenderProvider;
221
222
223 if(outerHierarchy != null)
224 {
225 return outerHierarchy.CanExtend(extenderCATID, e xtenderName, extendeeObject);
226 }
227 return false;
228 }
229
230 object EnvDTE80.IInternalExtenderProvider.GetExtender(string ext enderCATID, string extenderName, object extendeeObject, EnvDTE.IExtenderSite ext enderSite, int cookie)
231 {
232 EnvDTE80.IInternalExtenderProvider outerHierarchy = Hier archyNode.GetOuterHierarchy(this.Node) as EnvDTE80.IInternalExtenderProvider;
233
234 if(outerHierarchy != null)
235 {
236 return outerHierarchy.GetExtender(extenderCATID, extenderName, extendeeObject, extenderSite, cookie);
237 }
238
239 return null;
240 }
241
242 object EnvDTE80.IInternalExtenderProvider.GetExtenderNames(strin g extenderCATID, object extendeeObject)
243 {
244 EnvDTE80.IInternalExtenderProvider outerHierarchy = Hier archyNode.GetOuterHierarchy(this.Node) as EnvDTE80.IInternalExtenderProvider;
245
246 if(outerHierarchy != null)
247 {
248 return outerHierarchy.GetExtenderNames(extenderC ATID, extendeeObject);
249 }
250
251 return null;
252 }
253
254 #endregion
255
256 #region ExtenderSupport
257 [Browsable(false)]
258 [SuppressMessage("Microsoft.Naming", "CA1709:IdentifiersShouldBe CasedCorrectly", MessageId = "CATID")]
259 public virtual string ExtenderCATID
260 {
261 get
262 {
263 Guid catid = this.Node.ProjectMgr.GetCATIDForTyp e(this.GetType());
264 if(Guid.Empty.CompareTo(catid) == 0)
265 {
266 return null;
267 }
268 return catid.ToString("B");
269 }
270 }
271
272 [Browsable(false)]
273 public object ExtenderNames()
274 {
275 EnvDTE.ObjectExtenders extenderService = (EnvDTE.ObjectE xtenders)this.Node.GetService(typeof(EnvDTE.ObjectExtenders));
276 Debug.Assert(extenderService != null, "Could not get the ObjectExtenders object from the services exposed by this property object");
277 if(extenderService == null)
278 {
279 throw new InvalidOperationException();
280 }
281 return extenderService.GetExtenderNames(this.ExtenderCAT ID, this);
282 }
283
284 public object Extender(string extenderName)
285 {
286 EnvDTE.ObjectExtenders extenderService = (EnvDTE.ObjectE xtenders)this.Node.GetService(typeof(EnvDTE.ObjectExtenders));
287 Debug.Assert(extenderService != null, "Could not get the ObjectExtenders object from the services exposed by this property object");
288 if(extenderService == null)
289 {
290 throw new InvalidOperationException();
291 }
292 return extenderService.GetExtender(this.ExtenderCATID, e xtenderName, this);
293 }
294
295 #endregion
296 }
297
298 [CLSCompliant(false), ComVisible(true)]
299 public class FileNodeProperties : NodeProperties
300 {
301 #region properties
302 [SRCategoryAttribute(SR.Advanced)]
303 [LocDisplayName(SR.BuildAction)]
304 [SRDescriptionAttribute(SR.BuildActionDescription)]
305 public virtual BuildAction BuildAction
306 {
307 get
308 {
309 string value = this.Node.ItemNode.ItemName;
310 if(value == null || value.Length == 0)
311 {
312 return BuildAction.None;
313 }
314 return (BuildAction)Enum.Parse(typeof(BuildActio n), value);
315 }
316 set
317 {
318 this.Node.ItemNode.ItemName = value.ToString();
319 }
320 }
321
322 [SRCategoryAttribute(SR.Misc)]
323 [LocDisplayName(SR.FileName)]
324 [SRDescriptionAttribute(SR.FileNameDescription)]
325 public string FileName
326 {
327 get
328 {
329 return this.Node.Caption;
330 }
331 set
332 {
333 this.Node.SetEditLabel(value);
334 }
335 }
336
337 [SRCategoryAttribute(SR.Misc)]
338 [LocDisplayName(SR.FullPath)]
339 [SRDescriptionAttribute(SR.FullPathDescription)]
340 public string FullPath
341 {
342 get
343 {
344 return this.Node.Url;
345 }
346 }
347
348 #region non-browsable properties - used for automation only
349 [Browsable(false)]
350 public string Extension
351 {
352 get
353 {
354 return Path.GetExtension(this.Node.Caption);
355 }
356 }
357 #endregion
358
359 #endregion
360
361 #region ctors
362 public FileNodeProperties(HierarchyNode node)
363 : base(node)
364 {
365 }
366 #endregion
367
368 #region overridden methods
369 public override string GetClassName()
370 {
371 return SR.GetString(SR.FileProperties, CultureInfo.Curre ntUICulture);
372 }
373 #endregion
374 }
375
376 [CLSCompliant(false), ComVisible(true)]
377 public class DependentFileNodeProperties : NodeProperties
378 {
379 #region properties
380 [SRCategoryAttribute(SR.Advanced)]
381 [LocDisplayName(SR.BuildAction)]
382 [SRDescriptionAttribute(SR.BuildActionDescription)]
383 public virtual BuildAction BuildAction
384 {
385 get
386 {
387 string value = this.Node.ItemNode.ItemName;
388 if(value == null || value.Length == 0)
389 {
390 return BuildAction.None;
391 }
392 return (BuildAction)Enum.Parse(typeof(BuildActio n), value);
393 }
394 set
395 {
396 this.Node.ItemNode.ItemName = value.ToString();
397 }
398 }
399
400 [SRCategoryAttribute(SR.Misc)]
401 [LocDisplayName(SR.FileName)]
402 [SRDescriptionAttribute(SR.FileNameDescription)]
403 public virtual string FileName
404 {
405 get
406 {
407 return this.Node.Caption;
408 }
409 }
410
411 [SRCategoryAttribute(SR.Misc)]
412 [LocDisplayName(SR.FullPath)]
413 [SRDescriptionAttribute(SR.FullPathDescription)]
414 public string FullPath
415 {
416 get
417 {
418 return this.Node.Url;
419 }
420 }
421 #endregion
422
423 #region ctors
424 public DependentFileNodeProperties(HierarchyNode node)
425 : base(node)
426 {
427 }
428
429 #endregion
430
431 #region overridden methods
432 public override string GetClassName()
433 {
434 return SR.GetString(SR.FileProperties, CultureInfo.Curre ntUICulture);
435 }
436 #endregion
437 }
438
439 [CLSCompliant(false), ComVisible(true)]
440 public class SingleFileGeneratorNodeProperties : FileNodeProperties
441 {
442 #region fields
443 private EventHandler<HierarchyNodeEventArgs> onCustomToolChanged ;
444 private EventHandler<HierarchyNodeEventArgs> onCustomToolNameSpa ceChanged;
445 private string _customTool = "";
446 private string _customToolNamespace = "";
447 #endregion
448
449 #region custom tool events
450 internal event EventHandler<HierarchyNodeEventArgs> OnCustomTool Changed
451 {
452 add { onCustomToolChanged += value; }
453 remove { onCustomToolChanged -= value; }
454 }
455
456 internal event EventHandler<HierarchyNodeEventArgs> OnCustomTool NameSpaceChanged
457 {
458 add { onCustomToolNameSpaceChanged += value; }
459 remove { onCustomToolNameSpaceChanged -= value; }
460 }
461
462 #endregion
463
464 #region properties
465 [SRCategoryAttribute(SR.Advanced)]
466 [LocDisplayName(SR.CustomTool)]
467 [SRDescriptionAttribute(SR.CustomToolDescription)]
468 public virtual string CustomTool
469 {
470 get
471 {
472 _customTool = this.Node.ItemNode.GetMetadata(Pro jectFileConstants.Generator);
473 return _customTool;
474 }
475 set
476 {
477 _customTool = value;
478 if(!string.IsNullOrEmpty(_customTool))
479 {
480 this.Node.ItemNode.SetMetadata(ProjectFi leConstants.Generator, _customTool);
481 HierarchyNodeEventArgs args = new Hierar chyNodeEventArgs(this.Node);
482 if(onCustomToolChanged != null)
483 {
484 onCustomToolChanged(this.Node, a rgs);
485 }
486 }
487 }
488 }
489
490 [SRCategoryAttribute(VisualStudio.Project.SR.Advanced)]
491 [LocDisplayName(SR.CustomToolNamespace)]
492 [SRDescriptionAttribute(SR.CustomToolNamespaceDescription)]
493 public virtual string CustomToolNamespace
494 {
495 get
496 {
497 _customToolNamespace = this.Node.ItemNode.GetMet adata(ProjectFileConstants.CustomToolNamespace);
498 return _customToolNamespace;
499 }
500 set
501 {
502 _customToolNamespace = value;
503 if(!string.IsNullOrEmpty(_customToolNamespace))
504 {
505 this.Node.ItemNode.SetMetadata(ProjectFi leConstants.CustomToolNamespace, _customToolNamespace);
506 HierarchyNodeEventArgs args = new Hierar chyNodeEventArgs(this.Node);
507 if(onCustomToolNameSpaceChanged != null)
508 {
509 onCustomToolNameSpaceChanged(thi s.Node, args);
510 }
511 }
512 }
513 }
514 #endregion
515
516 #region ctors
517 public SingleFileGeneratorNodeProperties(HierarchyNode node)
518 : base(node)
519 {
520 }
521 #endregion
522 }
523
524 [CLSCompliant(false), ComVisible(true)]
525 public class ProjectNodeProperties : NodeProperties
526 {
527 #region properties
528 [SRCategoryAttribute(SR.Misc)]
529 [LocDisplayName(SR.ProjectFolder)]
530 [SRDescriptionAttribute(SR.ProjectFolderDescription)]
531 [AutomationBrowsable(false)]
532 public string ProjectFolder
533 {
534 get
535 {
536 return this.Node.ProjectMgr.ProjectFolder;
537 }
538 }
539
540 [SRCategoryAttribute(SR.Misc)]
541 [LocDisplayName(SR.ProjectFile)]
542 [SRDescriptionAttribute(SR.ProjectFileDescription)]
543 [AutomationBrowsable(false)]
544 public string ProjectFile
545 {
546 get
547 {
548 return this.Node.ProjectMgr.ProjectFile;
549 }
550 set
551 {
552 this.Node.ProjectMgr.ProjectFile = value;
553 }
554 }
555
556 #region non-browsable properties - used for automation only
557 [Browsable(false)]
558 public string FileName
559 {
560 get
561 {
562 return this.Node.ProjectMgr.ProjectFile;
563 }
564 set
565 {
566 this.Node.ProjectMgr.ProjectFile = value;
567 }
568 }
569
570
571 [Browsable(false)]
572 public string FullPath
573 {
574 get
575 {
576 string fullPath = this.Node.ProjectMgr.ProjectFo lder;
577 if(!fullPath.EndsWith(Path.DirectorySeparatorCha r.ToString(), StringComparison.Ordinal))
578 {
579 return fullPath + Path.DirectorySeparato rChar;
580 }
581 else
582 {
583 return fullPath;
584 }
585 }
586 }
587 #endregion
588
589 #endregion
590
591 #region ctors
592 public ProjectNodeProperties(ProjectNode node)
593 : base(node)
594 {
595 }
596 #endregion
597
598 #region overridden methods
599 public override string GetClassName()
600 {
601 return SR.GetString(SR.ProjectProperties, CultureInfo.Cu rrentUICulture);
602 }
603
604 /// <summary>
605 /// ICustomTypeDescriptor.GetEditor
606 /// To enable the "Property Pages" button on the properties brow ser
607 /// the browse object (project properties) need to be unmanaged
608 /// or it needs to provide an editor of type ComponentEditor.
609 /// </summary>
610 /// <param name="editorBaseType">Type of the editor</param>
611 /// <returns>Editor</returns>
612 public override object GetEditor(Type editorBaseType)
613 {
614 // Override the scenario where we are asked for a Compon entEditor
615 // as this is how the Properties Browser calls us
616 if(editorBaseType == typeof(ComponentEditor))
617 {
618 IOleServiceProvider sp;
619 ErrorHandler.ThrowOnFailure(this.Node.GetSite(ou t sp));
620 return new PropertiesEditorLauncher(new ServiceP rovider(sp));
621 }
622
623 return base.GetEditor(editorBaseType);
624 }
625
626 public override int GetCfgProvider(out IVsCfgProvider p)
627 {
628 if(this.Node != null && this.Node.ProjectMgr != null)
629 {
630 return this.Node.ProjectMgr.GetCfgProvider(out p );
631 }
632
633 return base.GetCfgProvider(out p);
634 }
635 #endregion
636 }
637
638 [CLSCompliant(false), ComVisible(true)]
639 public class FolderNodeProperties : NodeProperties
640 {
641 #region properties
642 [SRCategoryAttribute(SR.Misc)]
643 [LocDisplayName(SR.FolderName)]
644 [SRDescriptionAttribute(SR.FolderNameDescription)]
645 [AutomationBrowsable(false)]
646 public string FolderName
647 {
648 get
649 {
650 return this.Node.Caption;
651 }
652 set
653 {
654 this.Node.SetEditLabel(value);
655 this.Node.ReDraw(UIHierarchyElement.Caption);
656 }
657 }
658
659 #region properties - used for automation only
660 [Browsable(false)]
661 [AutomationBrowsable(true)]
662 public string FileName
663 {
664 get
665 {
666 return this.Node.Caption;
667 }
668 set
669 {
670 this.Node.SetEditLabel(value);
671 }
672 }
673
674 [Browsable(false)]
675 [AutomationBrowsable(true)]
676 public string FullPath
677 {
678 get
679 {
680 string fullPath = this.Node.GetMkDocument();
681 if(!fullPath.EndsWith(Path.DirectorySeparatorCha r.ToString(), StringComparison.Ordinal))
682 {
683 return fullPath + Path.DirectorySeparato rChar;
684 }
685 else
686 {
687 return fullPath;
688 }
689 }
690 }
691 #endregion
692
693 #endregion
694
695 #region ctors
696 public FolderNodeProperties(HierarchyNode node)
697 : base(node)
698 {
699 }
700 #endregion
701
702 #region overridden methods
703 public override string GetClassName()
704 {
705 return SR.GetString(SR.FolderProperties, CultureInfo.Cur rentUICulture);
706 }
707 #endregion
708 }
709
710 [CLSCompliant(false), ComVisible(true)]
711 public class ReferenceNodeProperties : NodeProperties
712 {
713 #region properties
714 [SRCategoryAttribute(SR.Misc)]
715 [LocDisplayName(SR.RefName)]
716 [SRDescriptionAttribute(SR.RefNameDescription)]
717 [Browsable(true)]
718 [AutomationBrowsable(true)]
719 public override string Name
720 {
721 get
722 {
723 return this.Node.Caption;
724 }
725 }
726
727 [SRCategoryAttribute(SR.Misc)]
728 [LocDisplayName(SR.CopyToLocal)]
729 [SRDescriptionAttribute(SR.CopyToLocalDescription)]
730 public bool CopyToLocal
731 {
732 get
733 {
734 string copyLocal = this.GetProperty(ProjectFileC onstants.Private, "False");
735 if(copyLocal == null || copyLocal.Length == 0)
736 return true;
737 return bool.Parse(copyLocal);
738 }
739 set
740 {
741 this.SetProperty(ProjectFileConstants.Private, v alue.ToString());
742 }
743 }
744
745 [SRCategoryAttribute(SR.Misc)]
746 [LocDisplayName(SR.FullPath)]
747 [SRDescriptionAttribute(SR.FullPathDescription)]
748 public virtual string FullPath
749 {
750 get
751 {
752 return this.Node.Url;
753 }
754 }
755 #endregion
756
757 #region ctors
758 public ReferenceNodeProperties(HierarchyNode node)
759 : base(node)
760 {
761 }
762 #endregion
763
764 #region overridden methods
765 public override string GetClassName()
766 {
767 return SR.GetString(SR.ReferenceProperties, CultureInfo. CurrentUICulture);
768 }
769 #endregion
770 }
771
772 [ComVisible(true)]
773 public class ProjectReferencesProperties : ReferenceNodeProperties
774 {
775 #region ctors
776 public ProjectReferencesProperties(ProjectReferenceNode node)
777 : base(node)
778 {
779 }
780 #endregion
781
782 #region overriden methods
783 public override string FullPath
784 {
785 get
786 {
787 return ((ProjectReferenceNode)Node).ReferencedPr ojectOutputPath;
788 }
789 }
790 #endregion
791 }
792 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698