Datei: NDOPackage/CodeGenHelper.cs

Last Commit (4a7e8ab)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
 
24 using System.IO;
25 using System.Windows.Forms;
26 using EnvDTE;
27 using EnvDTE80;
28 using Microsoft.VisualStudio.CommandBars;
 
 
29
30 namespace NETDataObjects. NDOVSPackage
31 {
32
33 ····internal class CodeGenHelper
34 ····{
35
36 ········public static bool IsCsProject(Project project)
37 ········{
38 return project. Kind == ProjectKind. prjKindCSharpProject || project. Kind == ProjectKind. prjKindNewCSharpProject; // prjKindNewCSharpProject can be removed after VS 17. 8
 
39 ········}
40
41 ········public static bool IsVbProject(Project project)
42 ········{
43 return project. Kind == ProjectKind. prjKindVBProject;
 
44 ········}
45
46
47 public static ProjectItem FindProjectItemByName( Project prj, string strItemNameWithFileExtension)
48 ········{
49 if ( prj. ProjectItems. Count < 1)
50 throw new Exception( string. Format( "Project Item { 0} not found. No project items in project { 1} ", strItemNameWithFileExtension, prj. Name) ) ;
51 ············if (strItemNameWithFileExtension == null)
52 ················return prj.ProjectItems.Item(1);
53 ············foreach (ProjectItem pri in prj.ProjectItems)
54 ················if (pri.Name == strItemNameWithFileExtension)
55 ····················return pri;
56 ············return null;
57 ········}
58
59 public static TextDocument ActivateAndGetTextDocument( Project prj, string strProjectItem)
60 ········{
61 ProjectItem pri = FindProjectItemByName( prj, strProjectItem) ;
62 if ( pri == null)
63 return null;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
64
65 // we need to ensure that the item is open since we would not
66 // be able to get a text document otherwise
67 if ( !pri. get_IsOpen( Constants. vsViewKindCode) )
68 pri. Open( Constants. vsViewKindCode) ;
69 Document doc = pri. Document;
70 doc. Activate( ) ;
71 TextDocument txdoc = doc. DTE. ActiveDocument. Object( "TextDocument") as TextDocument;
72 return txdoc;
73 }
74
75 ····}
76 }
77
New Commit (3030986)
1 //
2 // Copyright (c) 2002-2019 Mirko Matytschak
3 // (www.netdataobjects.de)
4 //
5 // Author: Mirko Matytschak
6 //
7 // Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
8 // documentation files (the "Software"), to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
10 // Software, and to permit persons to whom the Software is furnished to do so, subject to the following
11 // conditions:
12
13 // The above copyright notice and this permission notice shall be included in all copies or substantial portions
14 // of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
17 // TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
19 // CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20 // DEALINGS IN THE SOFTWARE.
21
22
23 using System;
24 using System.Threading.Tasks;
25 using System.IO;
26 using System.Windows.Forms;
 
 
27 using Microsoft.VisualStudio.CommandBars;
28 using Community.VisualStudio.Toolkit;
29 using Microsoft.VisualStudio.Shell.Interop;
30
31 namespace NDOVsPackage
32 {
33
34 ····internal class CodeGenHelper
35 ····{
36
37 ········public static bool IsCsProject(Project project)
38 ········{
39 project. GetItemInfo( out IVsHierarchy hierarchy, out _, out _) ;
40 ············return hierarchy.IsCapabilityMatch("CSharp") || hierarchy.IsCapabilityMatch("VB");
41 ········}
42
43 ········public static bool IsVbProject(Project project)
44 ········{
45 project. GetItemInfo( out IVsHierarchy hierarchy, out _, out _) ;
46 ············return hierarchy.IsCapabilityMatch("VB");
47 ········}
48
49
50 public static bool IsCsOrVbProject( Project project)
51 ········{
52 project. GetItemInfo( out IVsHierarchy hierarchy, out _, out _) ;
53 return hierarchy. IsCapabilityMatch( "CSharp") || hierarchy. IsCapabilityMatch( "VB") ;
 
 
 
 
 
 
54 ········}
55
56 public static bool IsCsOrVbProject( EnvDTE. Project project )
57 ········{
58 #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
59 return project. Kind == ProjectKind. prjKindVBProject || project. Kind == ProjectKind. prjKindCSharpProject;
60 #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
61 ········}
62
63
64 ········//public static ProjectItem FindProjectItemByName(Project prj, string strItemNameWithFileExtension)
65 ········//{
66 ········//····if (prj.ProjectItems.Count < 1)
67 ········//········throw new Exception(string.Format("Project Item {0} not found. No project items in project {1}", strItemNameWithFileExtension, prj.Name));
68 ········//····if (strItemNameWithFileExtension == null)
69 ········//········return prj.ProjectItems.Item(1);
70 ········//····foreach (ProjectItem pri in prj.ProjectItems)
71 ········//········if (pri.Name == strItemNameWithFileExtension)
72 ········//············return pri;
73 ········//····return null;
74 ········//}
75
76 ········//public static TextDocument ActivateAndGetTextDocument(Project prj, string strProjectItem)
77 ········//{
78 ········//····ProjectItem pri = FindProjectItemByName(prj, strProjectItem);
79 ········//····if (pri == null)
80 ········//········return null;
81
82 // // we need to ensure that the item is open since we would not
83 // // be able to get a text document otherwise
84 // if ( !pri. get_IsOpen( Constants. vsViewKindCode) )
85 // pri. Open( Constants. vsViewKindCode) ;
86 // Document doc = pri. Document;
87 // doc. Activate( ) ;
88 // TextDocument txdoc = doc. DTE. ActiveDocument. Object( "TextDocument") as TextDocument;
89 // return txdoc;
90 //}
91
92 ····}
93 }
94