@@ -25,10 +25,7 @@ import { Signal } from '@lumino/signaling';
2525import { IDragEvent } from '@lumino/dragdrop' ;
2626import { MimeData } from '@lumino/coreutils' ;
2727
28- import {
29- CodeSnippetService ,
30- ICodeSnippet
31- } from './CodeSnippetService' ;
28+ import { CodeSnippetService , ICodeSnippet } from './CodeSnippetService' ;
3229// import { CodeSnippetWidgetModel } from './CodeSnippetWidgetModel';
3330import { CodeSnippetDisplay } from './CodeSnippetDisplay' ;
3431import { CodeSnippetInputDialog } from './CodeSnippetInputDialog' ;
@@ -86,67 +83,6 @@ export class CodeSnippetWidget extends ReactWidget {
8683 this . node . setAttribute ( 'data-lm-dragscroll' , 'true' ) ;
8784 }
8885
89- // Request code snippets from contents service
90- // async fetchData(): Promise<ICodeSnippet[]> {
91- // // const fileModels: Contents.IModel[] = [];
92- // // const paths: string[] = [];
93-
94- // const codeSnippets = this.codeSnippetManager.snippets;
95- // return codeSnippets;
96-
97- // // Clear the current snippets
98- // this._codeSnippetWidgetModel.clearSnippets();
99-
100- // await this.codeSnippetManager
101- // .getData('snippets', 'directory')
102- // .then(model => {
103- // fileModels.push(...model.content);
104- // });
105-
106- // fileModels.forEach(fileModel => paths.push(fileModel.path));
107-
108- // let newSnippet: ICodeSnippet = {
109- // name: '',
110- // description: '',
111- // language: '',
112- // code: [],
113- // id: -1
114- // };
115-
116- // const codeSnippetList: ICodeSnippet[] = [];
117- // for (let i = 0; i < paths.length; i++) {
118- // await this.codeSnippetManager.getData(paths[i], 'file').then(model => {
119- // const codeSnippet: ICodeSnippet = JSON.parse(model.content);
120-
121- // // append a new snippet created from scratch to the end
122- // if (codeSnippet.id === -1) {
123- // codeSnippet.id = paths.length - 1;
124- // newSnippet = codeSnippet;
125- // }
126-
127- // codeSnippetList.push(codeSnippet);
128- // });
129- // }
130-
131- // // new list of snippets
132- // this._codeSnippetWidgetModel.snippets = codeSnippetList;
133-
134- // // sort codeSnippetList by ID
135- // this._codeSnippetWidgetModel.sortSnippets();
136-
137- // // update the content of the new snippet
138- // if (newSnippet.name !== '') {
139- // this.codeSnippetManager.save('snippets/' + newSnippet.name + '.json', {
140- // type: 'file',
141- // format: 'text',
142- // content: JSON.stringify(newSnippet)
143- // });
144- // }
145-
146- // this._codeSnippets = this._codeSnippetWidgetModel.snippets;
147- // return this._codeSnippetWidgetModel.snippets;
148- // }
149-
15086 updateCodeSnippetWidget ( ) : void {
15187 console . log ( 'updating code snippets' ) ;
15288 const newSnippets = this . codeSnippetManager . snippets ;
@@ -158,7 +94,7 @@ export class CodeSnippetWidget extends ReactWidget {
15894 }
15995
16096 onAfterShow ( msg : Message ) : void {
161- console . log ( " onAfterShow" ) ;
97+ console . log ( ' onAfterShow' ) ;
16298 this . updateCodeSnippetWidget ( ) ;
16399 }
164100
@@ -344,8 +280,7 @@ export class CodeSnippetWidget extends ReactWidget {
344280 let idx ;
345281 if ( snippet !== undefined ) {
346282 idx = parseInt ( snippet . id ) ;
347- }
348- else {
283+ } else {
349284 idx = this . codeSnippetManager . snippets . length ;
350285 }
351286
@@ -366,11 +301,6 @@ export class CodeSnippetWidget extends ReactWidget {
366301 event . dropAction = 'move' ;
367302 if ( event . mimeData . hasData ( 'snippet/id' ) ) {
368303 const srcIdx = event . mimeData . getData ( 'snippet/id' ) as number ;
369- // if (idx === -1) {
370- // this.fetchData().then(codeSnippets => {
371- // idx = codeSnippets.length;
372- // });
373- // }
374304 this . moveCodeSnippet ( srcIdx , idx ) ;
375305 }
376306 } else {
@@ -381,8 +311,8 @@ export class CodeSnippetWidget extends ReactWidget {
381311
382312 // Reorder snippet just to make sure id's are in order.
383313 this . codeSnippetManager . orderSnippets ( ) . then ( ( res : boolean ) => {
384- if ( ! res ) {
385- console . log ( " Error in ordering snippets" ) ;
314+ if ( ! res ) {
315+ console . log ( ' Error in ordering snippets' ) ;
386316 return ;
387317 }
388318 } ) ;
@@ -391,12 +321,14 @@ export class CodeSnippetWidget extends ReactWidget {
391321 // move code snippet within code snippet explorer
392322 private moveCodeSnippet ( srcIdx : number , targetIdx : number ) : void {
393323 console . log ( 'move snippet' ) ;
394- this . codeSnippetManager . moveSnippet ( srcIdx , targetIdx ) . then ( ( res : boolean ) => {
395- if ( ! res ) {
396- console . log ( "Error in moving snippet" ) ;
397- return ;
398- }
399- } ) ;
324+ this . codeSnippetManager
325+ . moveSnippet ( srcIdx , targetIdx )
326+ . then ( ( res : boolean ) => {
327+ if ( ! res ) {
328+ console . log ( 'Error in moving snippet' ) ;
329+ return ;
330+ }
331+ } ) ;
400332 const newSnippets = this . codeSnippetManager . snippets ;
401333 console . log ( newSnippets ) ;
402334 this . renderCodeSnippetsSignal . emit ( newSnippets ) ;
0 commit comments