2020
2121
2222import * as vscode from 'vscode' ;
23- import { JournalController , Input , InlineTemplate , InlineString , HeaderTemplate } from '../model' ;
23+ import { IConfiguration , ILogger , Input , InlineTemplate , InlineString , HeaderTemplate } from '../model' ;
2424import { isNullOrUndefined } from '../util' ;
2525
2626
2727
2828
2929export class Inject {
3030
31- constructor ( public ctrl : JournalController ) {
32-
31+ constructor ( private config : IConfiguration , private logger : ILogger ) {
3332 }
3433
3534 /**
@@ -43,27 +42,27 @@ export class Inject {
4342 * @memberof Inject
4443 */
4544 public async injectInput ( doc : vscode . TextDocument , input : Input ) : Promise < vscode . TextDocument > {
46- this . ctrl . logger . trace ( "Entering injectInput() in inject.ts with Input:" , JSON . stringify ( input ) ) ;
45+ this . logger . trace ( "Entering injectInput() in inject.ts with Input:" , JSON . stringify ( input ) ) ;
4746
4847 if ( ! input . hasMemo ( ) || ! input . hasFlags ( ) ) {
4948 return doc ;
5049 }
5150
5251 try {
5352 if ( input . flags . match ( "memo" ) ) {
54- const tplInfo = await this . ctrl . config . getMemoInlineTemplate ( ) ;
53+ const tplInfo = await this . config . getMemoInlineTemplate ( ) ;
5554 const val = await this . buildInlineString ( doc , tplInfo , [ "${input}" , input . text ] ) ;
5655 return this . injectInlineString ( val ) ;
5756 } else if ( input . flags . match ( / t a s k | t o d o / ) ) {
58- const tplInfo = await this . ctrl . config . getTaskInlineTemplate ( ) ;
57+ const tplInfo = await this . config . getTaskInlineTemplate ( ) ;
5958 const val = await this . buildInlineString ( doc , tplInfo , [ "${input}" , input . text ] ) ;
6059 return this . injectInlineString ( val ) ;
6160 } else {
6261 throw new Error ( "Failed to handle input" ) ;
6362 }
6463 } catch ( error ) {
6564 if ( error instanceof Error ) {
66- this . ctrl . logger . error ( error . message ) ;
65+ this . logger . error ( error . message ) ;
6766 }
6867 throw error ;
6968 }
@@ -85,7 +84,7 @@ export class Inject {
8584 * Updates: Fix for #55, always make sure there is a linebreak between the header and the injected text to stay markdown compliant
8685 */
8786 public async buildInlineString ( doc : vscode . TextDocument , tpl : InlineTemplate , ...values : string [ ] [ ] ) : Promise < InlineString > {
88- this . ctrl . logger . trace ( "Entering buildInlineString() in inject.ts with InlineTemplate: " , JSON . stringify ( tpl ) , " and values " , JSON . stringify ( values ) ) ;
87+ this . logger . trace ( "Entering buildInlineString() in inject.ts with InlineTemplate: " , JSON . stringify ( tpl ) , " and values " , JSON . stringify ( values ) ) ;
8988
9089 let content : string = tpl . value ! ;
9190 values . forEach ( ( val : string [ ] ) => {
@@ -149,10 +148,10 @@ export class Inject {
149148 *
150149 */
151150 public async injectInlineString ( content : InlineString , ...other : InlineString [ ] ) : Promise < vscode . TextDocument > {
152- this . ctrl . logger . trace ( "Entering injectInlineString() in inject.ts with string: " , content . value . trim ( ) ) ;
151+ this . logger . trace ( "Entering injectInlineString() in inject.ts with string: " , content . value . trim ( ) ) ;
153152
154153 if ( isNullOrUndefined ( content ) ) {
155- this . ctrl . logger . error ( "Content is null" ) ;
154+ this . logger . error ( "Content is null" ) ;
156155 throw new Error ( "Invalid call, no reference to document due to null content." ) ;
157156 }
158157
@@ -167,13 +166,13 @@ export class Inject {
167166 }
168167
169168 if ( isNullOrUndefined ( edit ) || edit . size === 0 ) {
170- this . ctrl . logger . trace ( "No changes have been made to the document: " , content . document . fileName ) ;
169+ this . logger . trace ( "No changes have been made to the document: " , content . document . fileName ) ;
171170 return content . document ;
172171 }
173172
174173 const applied = await vscode . workspace . applyEdit ( edit ) ;
175174 if ( ! applied ) {
176- this . ctrl . logger . error ( "Failed inject inline string '" , content . value , "'" ) ;
175+ this . logger . error ( "Failed inject inline string '" , content . value , "'" ) ;
177176 throw new Error ( "Failed to applied edit" ) ;
178177 }
179178 return content . document ;
@@ -235,8 +234,8 @@ export class Inject {
235234 * @memberof Inject
236235 */
237236 public async formatNote ( input : Input ) : Promise < string > {
238- this . ctrl . logger . trace ( "Entering formatNote() in inject.ts with input: " , JSON . stringify ( input ) ) ;
239- const headerTemplate : HeaderTemplate = await this . ctrl . config . getNotesTemplate ( input . scope ) ;
237+ this . logger . trace ( "Entering formatNote() in inject.ts with input: " , JSON . stringify ( input ) ) ;
238+ const headerTemplate : HeaderTemplate = await this . config . getNotesTemplate ( input . scope ) ;
240239 headerTemplate . value = headerTemplate . value ! . replace ( '${input}' , input . text ) ;
241240 headerTemplate . value = headerTemplate . value ! . replace ( '${tags}' , input . tags . join ( " " ) + '\n' ) ;
242241
0 commit comments