@@ -27,6 +27,30 @@ export function activate(context: vscode.ExtensionContext) {
27
27
28
28
//context.subscriptions.push(disposable);
29
29
context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.createFromList' , createFromList ) ) ;
30
+ context . subscriptions . push ( vscode . commands . registerCommand ( 'extension.createTemplate' , createTemplate ) ) ;
31
+ }
32
+
33
+ let templateDirectory = vscode . extensions . getExtension ( 'jchannon.csharpextensions' ) . extensionPath + '/templates/' ;
34
+
35
+ function createNewTemplateFile ( newTemplateFile ) {
36
+ if ( ! fs . exists ( newTemplateFile ) ) {
37
+ fs . writeFileSync ( newTemplateFile , `\${Description: Template Description Here}
38
+ //use \${namespace} to set namespace
39
+ //use \${name} to set name
40
+ //use \${cursor} to set where the cursor will go when the file is first opened
41
+ //rename this file to the name of your template
42
+ ` ) ;
43
+ }
44
+
45
+ }
46
+
47
+ function createTemplate ( ) {
48
+ vscode . window . showInputBox ( { ignoreFocusOut : true , prompt : 'Please enter template name' , value : "templateName.tmpl" } ) . then ( result => {
49
+ createNewTemplateFile ( path . join ( templateDirectory , result ) ) ;
50
+ var uri = vscode . Uri . parse ( templateDirectory ) ;
51
+ vscode . commands . executeCommand ( 'vscode.openFolder' , uri , true ) ;
52
+ } ) ;
53
+
30
54
}
31
55
32
56
function createFromList ( args ) {
@@ -74,11 +98,11 @@ function openTemplateAndSaveNewFile(type: string, namespace: string, filename: s
74
98
75
99
let templatefileName = type + '.tmpl' ;
76
100
77
- vscode . workspace . openTextDocument ( vscode . extensions . getExtension ( 'jchannon.csharpextensions' ) . extensionPath + '/templates/' + templatefileName )
101
+ vscode . workspace . openTextDocument ( path . join ( templateDirectory , templatefileName ) )
78
102
. then ( ( doc : vscode . TextDocument ) => {
79
103
let text = doc . getText ( ) ;
80
104
text = text . replace ( '${namespace}' , namespace ) ;
81
- text = text . replace ( '${classname }' , filename ) ;
105
+ text = text . replace ( '${name }' , filename ) ;
82
106
text = text . replace ( new RegExp ( / \$ \{ D e s c r i p t i o n : ( .* ) \n / i) , '' ) ;
83
107
let cursorPosition = findCursorInTemlpate ( text ) ;
84
108
text = text . replace ( '${cursor}' , '' ) ;
0 commit comments