Datei: NDOPackage/CodeGenHelper.cs

Last Commit (ed9120d)
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 async Task<DocumentView> ActivateTextDocumentAsync( Project prj, string fileName )
77 ········{
78 ············var documentView = await VS.Documents.OpenAsync( fileName );
79 ············return documentView;
80 ········}
81
82 ····}
83 }
84 l;
85
86 ········//····// we need to ensure that the item is open since we would not
87 ········//····// be able to get a text document otherwise
88 ········//····if (!pri.get_IsOpen(Constants.vsViewKindCode))
89 ········//········pri.Open(Constants.vsViewKindCode);
90 ········//····Document doc = pri.Document;
91 ········//····doc.Activate();
92 ········//····TextDocument txdoc = doc.DTE.ActiveDocument.Object("TextDocument") as TextDocument;
93 ········//····return txdoc;
94 ········//}
95
96 ····}
97 }
98
New Commit (946ad0e)
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 ········public static bool IsCsProject( EnvDTE.Project project )
64 ········{
65 #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
66 ············return project.Kind == ProjectKind.prjKindCSharpProject;
67 #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
68 ········}
69
70 ········public static bool IsVbProject( EnvDTE.Project project )
71 ········{
72 #pragma warning disable VSTHRD010 // Invoke single-threaded types on Main thread
73 ············return project.Kind == ProjectKind.prjKindVBProject;
74 #pragma warning restore VSTHRD010 // Invoke single-threaded types on Main thread
75 ········}
76
77
78 ········public static ProjectItem FindProjectItemByName( EnvDTE.Project prj, string strItemNameWithFileExtension )
79 ········{
80 ············if (prj.ProjectItems.Count < 1)
81 ················throw new Exception( string.Format( "Project Item {0} not found. No project items in project {1}", strItemNameWithFileExtension, prj.Name ) );
82 ············if (strItemNameWithFileExtension == null)
83 ················return prj.ProjectItems.Item( 1 );
84 ············foreach (ProjectItem pri in prj.ProjectItems)
85 ················if (pri.Name == strItemNameWithFileExtension)
86 ····················return pri;
87 ············return null;
88 ········}
89
90 ········public static TextDocument ActivateAndGetTextDocument( EnvDTE.Project prj, string strProjectItem )
91 ········{
92 ············ProjectItem pri = FindProjectItemByName( prj, strProjectItem );
93 ············if (pri == null)
94 ················return null;
95
96 // we need to ensure that the item is open since we would not
97 // be able to get a text document otherwise
98 if ( !pri. get_IsOpen( Constants. vsViewKindCode ) )
99 pri. Open( Constants. vsViewKindCode ) ;
100 Document doc = pri. Document;
101 doc. Activate( ) ;
102 TextDocument txdoc = doc. DTE. ActiveDocument. Object( "TextDocument" ) as TextDocument;
103 return txdoc;
104 }
 
 
105
106 ········public static async Task<DocumentView> ActivateTextDocumentAsync( Project prj, string fileName )
107 ········{
108 ············var documentView = await VS.Documents.OpenAsync( fileName );
109 ············return documentView;
110 ········}
111
112 ····}
113 }
 
114
 
 
 
 
 
 
 
 
 
 
 
 
115