@@ -27,6 +27,30 @@ export function activate(context: vscode.ExtensionContext) {
2727
2828 //context.subscriptions.push(disposable);
2929 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+
3054}
3155
3256function createFromList ( args ) {
@@ -74,11 +98,11 @@ function openTemplateAndSaveNewFile(type: string, namespace: string, filename: s
7498
7599 let templatefileName = type + '.tmpl' ;
76100
77- vscode . workspace . openTextDocument ( vscode . extensions . getExtension ( 'jchannon.csharpextensions' ) . extensionPath + '/templates/' + templatefileName )
101+ vscode . workspace . openTextDocument ( path . join ( templateDirectory , templatefileName ) )
78102 . then ( ( doc : vscode . TextDocument ) => {
79103 let text = doc . getText ( ) ;
80104 text = text . replace ( '${namespace}' , namespace ) ;
81- text = text . replace ( '${classname }' , filename ) ;
105+ text = text . replace ( '${name }' , filename ) ;
82106 text = text . replace ( new RegExp ( / \$ \{ D e s c r i p t i o n : ( .* ) \n / i) , '' ) ;
83107 let cursorPosition = findCursorInTemlpate ( text ) ;
84108 text = text . replace ( '${cursor}' , '' ) ;
0 commit comments