@@ -73,16 +73,24 @@ export function CodeSnippetInputDialog(
7373
7474 const body : InputHandler = new InputHandler ( tags ) ;
7575
76- return showInputDialog ( tags , idx , codeSnippetWidget , code , body ) ;
76+ return showInputDialog (
77+ codeSnippetWidget ,
78+ tags ,
79+ idx ,
80+ codeSnippetManager ,
81+ code ,
82+ body
83+ ) ;
7784}
7885
7986/**
8087 * This function creates the actual input form and processes the inputs given.
8188 */
8289export function showInputDialog (
90+ codeSnippetWidget : CodeSnippetWidget ,
8391 tags : string [ ] ,
8492 idx : number ,
85- codeSnippetWidget : CodeSnippetWidget ,
93+ codeSnippetManager : CodeSnippetService ,
8694 code : string [ ] ,
8795 body : InputHandler
8896) : Promise < Contents . IModel | null > {
@@ -101,7 +109,14 @@ export function showInputDialog(
101109 console . log ( idx ) ;
102110
103111 if ( validateForm ( result ) === false ) {
104- showInputDialog ( tags , idx , codeSnippetWidget , code , body ) ;
112+ showInputDialog (
113+ codeSnippetWidget ,
114+ tags ,
115+ idx ,
116+ codeSnippetManager ,
117+ code ,
118+ body
119+ ) ;
105120 } else {
106121 // if (idx === -1) {
107122 // idx = codeSnippetWidget.codeSnippetWidgetModel.snippets.length;
@@ -116,21 +131,26 @@ export function showInputDialog(
116131 id : idx ,
117132 tags : tags
118133 } ;
119- for ( const snippet of snippets ) {
134+
135+ for ( const snippet of codeSnippetManager . snippets ) {
120136 if ( snippet . name === newSnippet . name ) {
121- const result = saveOverWriteFile (
122- codeSnippetManager ,
123- snippet ,
124- newSnippet
137+ saveOverWriteFile ( codeSnippetManager , snippet , newSnippet ) . then (
138+ ( res : boolean ) => {
139+ if ( res ) {
140+ codeSnippetWidget . renderCodeSnippetsSignal . emit (
141+ codeSnippetManager . snippets
142+ ) ;
143+ }
144+ }
125145 ) ;
126- console . log ( 'uh reached here' ) ;
127- result
128- . then ( newSnippets => {
129- codeSnippetWidget . renderCodeSnippetsSignal . emit ( newSnippets ) ;
130- } )
131- . catch ( _ => {
132- console . log ( 'cancelling overwrite!' ) ;
133- } ) ;
146+ // console.log('uh reached here');
147+ // result
148+ // .then(newSnippets => {
149+ // codeSnippetWidget.renderCodeSnippetsSignal.emit(newSnippets);
150+ // })
151+ // .catch(_ => {
152+ // console.log('cancelling overwrite!');
153+ // });
134154 return ;
135155 }
136156 }
@@ -183,33 +203,33 @@ function createNewSnippet(
183203/**
184204 * Rename a file, warning for overwriting another.
185205 */
186- async function saveOverWriteFile (
206+ export async function saveOverWriteFile (
187207 codeSnippetManager : CodeSnippetService ,
188208 oldSnippet : ICodeSnippet ,
189209 newSnippet : ICodeSnippet
190- ) : Promise < ICodeSnippet [ ] | null > {
210+ ) : Promise < boolean > {
191211 const newName = newSnippet . name ;
192212
193- return await shouldOverwrite ( newName ) . then ( value => {
194- if ( value ) {
213+ await shouldOverwrite ( newName ) . then ( res => {
214+ if ( res ) {
195215 newSnippet . id = oldSnippet . id ;
196216
197217 codeSnippetManager . deleteSnippet ( oldSnippet . id ) . then ( ( res : boolean ) => {
198218 if ( ! res ) {
199219 console . log ( 'Error in overwriting a snippet (delete)' ) ;
200- return ;
220+ return false ;
201221 }
202222 } ) ;
203223 codeSnippetManager . addSnippet ( newSnippet ) . then ( ( res : boolean ) => {
204224 if ( ! res ) {
205225 console . log ( 'Error in overwriting a snippet (add)' ) ;
206- return ;
226+ return false ;
207227 }
208228 } ) ;
209- return codeSnippetManager . snippets ;
229+ return true ;
210230 }
211- return null ;
212231 } ) ;
232+ return false ;
213233}
214234
215235/**
0 commit comments