@@ -29,10 +29,14 @@ import { Message } from '@lumino/messaging';
2929
3030import React from 'react' ;
3131
32- import { CodeSnippetContentsService } from './CodeSnippetContentsService' ;
32+ import {
33+ CodeSnippetContentsService ,
34+ ICodeSnippet
35+ } from './CodeSnippetContentsService' ;
3336import { CodeSnippetWidget } from './CodeSnippetWidget' ;
3437import { SUPPORTED_LANGUAGES } from './CodeSnippetLanguages' ;
3538import { CodeSnippetEditorTags } from './CodeSnippetEditorTags' ;
39+ import { saveOverWriteFile } from './CodeSnippetInputDialog' ;
3640
3741/**
3842 * CSS style classes
@@ -366,7 +370,7 @@ export class CodeSnippetEditor extends ReactWidget {
366370 message += 'Name must be filled out\n' ;
367371 status = false ;
368372 }
369- if ( name . match ( / [ ^ a - z 0 - 9 _ ] + / ) ) {
373+ if ( name . match ( / [ ^ a - z A - Z 0 - 9 _ ] + / ) ) {
370374 message += 'Wrong format of the name\n' ;
371375 status = false ;
372376 }
@@ -410,6 +414,8 @@ export class CodeSnippetEditor extends ReactWidget {
410414 const newPath =
411415 'snippets/' + this . _codeSnippetEditorMetaData . name + '.json' ;
412416
417+ //const oldPath = 'snippets/' + this.oldCodeSnippetName + '.json';
418+
413419 if ( ! this . _codeSnippetEditorMetaData . fromScratch ) {
414420 const oldPath = 'snippets/' + this . oldCodeSnippetName + '.json' ;
415421
@@ -418,14 +424,15 @@ export class CodeSnippetEditor extends ReactWidget {
418424 try {
419425 await this . contentsService . rename ( oldPath , newPath ) ;
420426 } catch ( error ) {
427+ console . log ( 'tffff' ) ;
421428 await showDialog ( {
422429 title : 'Duplicate Name of Code Snippet' ,
423430 body : < p > { `"${ newPath } " already exists.` } </ p > ,
424431 buttons : [ Dialog . okButton ( { label : 'Dismiss' } ) ]
425432 } ) ;
426433 return false ;
427434 }
428-
435+ console . log ( 'huhhh' ) ;
429436 // set new name as an old name
430437 this . oldCodeSnippetName = this . _codeSnippetEditorMetaData . name ;
431438 }
@@ -435,17 +442,48 @@ export class CodeSnippetEditor extends ReactWidget {
435442 . getData ( newPath , 'file' )
436443 . then ( async ( value : Contents . IModel ) => {
437444 if ( value . name ) {
438- await showDialog ( {
439- title : 'Duplicate Name of Code Snippet' ,
440- body : < p > { `"${ newPath } " already exists.` } </ p > ,
441- buttons : [ Dialog . okButton ( { label : 'Dismiss' } ) ]
442- } ) ;
445+ console . log (
446+ this . codeSnippetWidget . codeSnippetWidgetModel . snippets [ 37 ]
447+ ) ;
448+ const oldSnippet : ICodeSnippet = JSON . parse ( value . content ) ;
449+ const newSnippet : ICodeSnippet = {
450+ name : this . _codeSnippetEditorMetaData . name ,
451+ description : this . _codeSnippetEditorMetaData . description ,
452+ language : this . _codeSnippetEditorMetaData . language ,
453+ code : this . _codeSnippetEditorMetaData . code ,
454+ id : this . _codeSnippetEditorMetaData . id ,
455+ tags : this . _codeSnippetEditorMetaData . selectedTags
456+ } ;
457+ console . log ( oldSnippet . id ) ;
458+ // await showDialog({
459+ // title: 'Duplicate Name of Code Snippet',
460+ // body: <p> {`"${newPath}" already exists.`} </p>,
461+ // buttons: [Dialog.okButton({ label: 'Dismiss' })]
462+ // });
463+ const result = saveOverWriteFile (
464+ this . codeSnippetWidget . codeSnippetWidgetModel ,
465+ oldSnippet ,
466+ newSnippet
467+ ) ;
468+ result
469+ . then ( newSnippets => {
470+ this . codeSnippetWidget . renderCodeSnippetsSignal . emit (
471+ newSnippets
472+ ) ;
473+ } )
474+ . catch ( _ => {
475+ console . log ( 'cancelling overwrite!' ) ;
476+ return false ;
477+ } ) ;
443478 }
479+ return true ;
444480 } )
445481 . catch ( ( ) => {
446482 nameCheck = true ;
483+ console . log ( 'hi' ) ;
447484 } ) ;
448485 if ( ! nameCheck ) {
486+ console . log ( 'gdi' ) ;
449487 return false ;
450488 }
451489 }
@@ -585,7 +623,7 @@ export class CodeSnippetEditor extends ReactWidget {
585623 > </ input >
586624 < p className = { CODE_SNIPPET_EDITOR_INPUTNAME_VALIDITY } >
587625 {
588- 'Name of the code snippet MUST be lowercased, alphanumeric or composed of underscore(_)'
626+ 'Name of the code snippet MUST be alphanumeric or composed of underscore(_)'
589627 }
590628 </ p >
591629 < label className = { CODE_SNIPPET_EDITOR_LABEL } >
0 commit comments