Datei: NDOPackage/CodeGenHelper.cs

Last 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
New 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