1
1
using EnvDTE ;
2
+ using EnvDTE80 ;
2
3
using Microsoft . SqlServer . TransactSql . ScriptDom ;
3
4
using Microsoft . VisualStudio . Shell ;
4
5
using SQLScriptsExplorer . Addin . Repository ;
@@ -12,6 +13,15 @@ namespace SQLScriptsExplorer.Addin.Infrastructure
12
13
{
13
14
public static class DocumentManager
14
15
{
16
+ private static DTE2 DTE
17
+ {
18
+ get
19
+ {
20
+ ThreadHelper . ThrowIfNotOnUIThread ( ) ;
21
+ return Package . GetGlobalService ( typeof ( DTE ) ) as DTE2 ;
22
+ }
23
+ }
24
+
15
25
public static void OpenTemplate ( string fileName , string fileFullPath )
16
26
{
17
27
try
@@ -21,9 +31,10 @@ public static void OpenTemplate(string fileName, string fileFullPath)
21
31
if ( File . Exists ( fileFullPath ) )
22
32
{
23
33
string fileContent = File . ReadAllText ( fileFullPath ) ;
34
+ var docName = Path . GetFileNameWithoutExtension ( fileName ) ;
35
+ var docExtension = Path . GetExtension ( fileName ) ;
24
36
25
- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
26
- var fileDocument = dte . ItemOperations . NewFile ( @"General\Text File" , fileName ) . Document ;
37
+ var fileDocument = DTE . ItemOperations . NewFile ( @"General\Text File" , $ "{ docName } _Copy{ docExtension } ") . Document ;
27
38
28
39
TextSelection textSelection = fileDocument . Selection as TextSelection ;
29
40
textSelection . SelectAll ( ) ;
@@ -48,12 +59,9 @@ public static void EditTemplate(string fileName, string fileFullPath)
48
59
{
49
60
try
50
61
{
51
- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
52
-
53
62
if ( File . Exists ( fileFullPath ) )
54
63
{
55
- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
56
- dte . ItemOperations . OpenFile ( fileFullPath ) ;
64
+ DTE . ItemOperations . OpenFile ( fileFullPath ) ;
57
65
}
58
66
else
59
67
{
@@ -66,20 +74,16 @@ public static void EditTemplate(string fileName, string fileFullPath)
66
74
}
67
75
}
68
76
69
- public static void ExecuteTemplate ( string fileName , string fileFullPath , bool confirmScriptExecution )
77
+ public static void ExecuteTemplate ( string fileName , string fileFullPath )
70
78
{
71
79
string CMD_QUERY_EXECUTE = "Query.Execute" ;
72
80
73
81
try
74
82
{
75
- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
76
-
77
- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
78
-
79
83
// Ensure the document we are executing is the document we have opened by checking its name
80
- if ( dte . ActiveDocument != null && dte . ActiveDocument . ProjectItem . Name . Equals ( fileName ) )
84
+ if ( DTE . ActiveDocument != null && DTE . ActiveDocument . ProjectItem . Name . Equals ( fileName ) )
81
85
{
82
- dte . ExecuteCommand ( CMD_QUERY_EXECUTE ) ;
86
+ DTE . ExecuteCommand ( CMD_QUERY_EXECUTE ) ;
83
87
}
84
88
}
85
89
catch ( Exception ex )
@@ -92,13 +96,9 @@ public static void FormatSelection()
92
96
{
93
97
try
94
98
{
95
- ThreadHelper . ThrowIfNotOnUIThread ( ) ;
96
-
97
- DTE dte = Package . GetGlobalService ( typeof ( DTE ) ) as DTE ;
98
-
99
- if ( dte . ActiveDocument != null )
99
+ if ( DTE . ActiveDocument != null )
100
100
{
101
- TextSelection selection = ( TextSelection ) dte . ActiveDocument . Selection ;
101
+ TextSelection selection = ( TextSelection ) DTE . ActiveDocument . Selection ;
102
102
103
103
// Format whole text: selection.SelectAll();
104
104
string selectedText = selection . Text ;
@@ -150,7 +150,15 @@ private static string FormatSelectionUsingSQLServer(string code)
150
150
151
151
private static Tuple < TSqlParser , SqlScriptGenerator > GetSQLParser ( string targetVersion )
152
152
{
153
- if ( targetVersion == "SQL Server 2019" )
153
+ if ( targetVersion == "SQL Server 2025" )
154
+ {
155
+ return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql170Parser ( false ) , new Sql170ScriptGenerator ( ) ) ;
156
+ }
157
+ else if ( targetVersion == "SQL Server 2022" )
158
+ {
159
+ return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql160Parser ( false ) , new Sql160ScriptGenerator ( ) ) ;
160
+ }
161
+ else if ( targetVersion == "SQL Server 2019" )
154
162
{
155
163
return new Tuple < TSqlParser , SqlScriptGenerator > ( new TSql150Parser ( false ) , new Sql150ScriptGenerator ( ) ) ;
156
164
}
0 commit comments