@@ -64,7 +64,6 @@ export class FSCore {
6464
6565 updating = false ;
6666 renaming = '' ;
67- isRenamedItemNew = false ;
6867
6968 setLabelProvider ( labelProvider : FSLabelProviderContribution ) {
7069 this . _labelProvider = labelProvider ;
@@ -253,7 +252,7 @@ export class FSCore {
253252 }
254253
255254 public get isNew ( ) : boolean {
256- return FSNode . isDocument ( this . node ) && this . node . isNew ;
255+ return FSNode . isDocument ( this . node ) && ! ! this . node . isNew ;
257256 }
258257
259258 public get isItem ( ) : boolean {
@@ -998,12 +997,17 @@ export class FSCore {
998997 }
999998
1000999 public async acceptName ( node : FSNode , name : string ) : Promise < boolean > {
1001- return this . isRenamedItemNew
1000+ return FSNode . isItem ( node ) && node . isNew
10021001 ? this . tryCreate ( node , name )
10031002 : this . tryRename ( node , name ) ;
10041003 }
10051004
10061005 public async cancelName ( node : FSNode ) : Promise < void > {
1006+ if ( FSNode . isItem ( node ) && node . isNew ) {
1007+ this . updating = true ;
1008+ this . removeNode ( node ) ;
1009+ this . updating = false ;
1010+ }
10071011 this . setRename ( ) ;
10081012 }
10091013
@@ -1046,15 +1050,17 @@ export class FSCore {
10461050 // (node as any)['id'] = this.itemID(parent.connectionNode.connection, collection),
10471051 node . link = FS_RESOURCE_SCHEME + ':' + collection . name ,
10481052 node . uri = uri ;
1049- this . isRenamedItemNew = false ;
10501053 this . setRename ( ) ;
1054+ node . isNew = false ;
10511055 return true ;
10521056 }
10531057 } catch ( e ) {
1058+ this . removeNode ( node ) ;
10541059 this . setRename ( ) ;
10551060 }
10561061 return false ;
10571062 } else {
1063+ this . removeNode ( node ) ;
10581064 this . setRename ( ) ;
10591065 throw createError ( FSError . unknown ) ;
10601066 }
@@ -1339,33 +1345,13 @@ export class FSCore {
13391345 }
13401346 const collection = this . node as FSCollectionNode ;
13411347 const validator = ( input : string ) => input !== '' && ! this . fileExists ( input ) ;
1342- // const dialog = new SingleTextInputDialog({
1343- // initialValue: this.newName(validator),
1344- // title: 'New ' + (isCollection ? 'collection' : 'document'),
1345- // confirmButtonLabel: 'Create',
1346- // validate: validator,
1347- // });
1348- // let name = await dialog.open();
1349- // if (name) {
1350- // this.nextName(name);
1351- // name = collection.uri + '/' + name;
1352- // if (isCollection) {
1353- // const result = await FSApi.newCollection(collection.connectionNode.connection, name);
1354- // if (result) {
1355- // this.addCollection(collection, result);
1356- // }
1357- // } else {
1358- // this.createDocument(collection, name);
1359- // }
1360- // }
1361- // return false;
13621348 const initialName = this . newName ( validator ) ;
1349+ const name = collection . uri + TRAILING_SYMBOL + initialName ;
13631350 this . nextName ( initialName ) ;
1364- this . isRenamedItemNew = true ;
13651351 let item : FSItemNode ;
13661352 if ( isCollection ) {
13671353 item = await this . addCollection ( collection , {
1368- name : collection . uri + TRAILING_SYMBOL + initialName ,
1354+ name,
13691355 owner : 'admin' ,
13701356 group : 'dba' ,
13711357 acl : [ ] ,
@@ -1374,9 +1360,32 @@ export class FSCore {
13741360 collections : [ ]
13751361 } ) ;
13761362 } else {
1377- item = await this . createDocument ( collection , name ) ;
1363+ item = this . addDocument ( collection , {
1364+ content : '' ,
1365+ name,
1366+ created : new Date ( ) ,
1367+ lastModified : new Date ( ) ,
1368+ binaryDoc : false ,
1369+ acl : [ ] ,
1370+ size : 0 ,
1371+ mediaType : lookup ( name ) || 'text/plain' ,
1372+ group : 'dba' ,
1373+ owner : collection . connectionNode . connection . username ,
1374+ } , true ) ;
13781375 }
1376+ item . isNew = true ;
13791377 this . setRename ( item ) ;
1378+ if ( FSNode . isDocument ( item ) ) {
1379+ const safeAccept = this . acceptName ;
1380+ this . acceptName = async ( n , name ) => {
1381+ await this . setRename ( false ) ;
1382+ await this . removeNode ( item ) ;
1383+ const documentNode = this . addDocument ( collection , { ...( item as FSDocumentNode ) . document , name } , true ) ;
1384+ const doc = this . openDocument ( documentNode ) ;
1385+ this . acceptName = safeAccept ;
1386+ return ! ! doc ;
1387+ }
1388+ }
13801389 return true ;
13811390 }
13821391
@@ -1458,17 +1467,13 @@ export class FSCore {
14581467 return node ? node . id === this . renaming : this . renaming !== '' ;
14591468 }
14601469
1461- public async setRename ( node ?: FSNode ) {
1470+ public async setRename ( node ?: FSNode | false , focus = true ) {
14621471 this . updating = true ;
1463- const renamingNode = this . getNode ( this . renaming ) ;
14641472 this . renaming = node ? node . id : '' ;
1465- if ( ! node ) {
1466- if ( this . isRenamedItemNew && renamingNode ) {
1467- this . removeNode ( renamingNode ) ;
1468- }
1473+ if ( focus == true || node !== false ) {
14691474 const serversWidget = await this . widgetManager . getWidget ( FS_CONNECTIONS_WIDGET_FACTORY_ID ) ;
14701475 if ( serversWidget ) {
1471- serversWidget . activate ( ) ;
1476+ // serversWidget.activate();
14721477 }
14731478 }
14741479 this . updating = false ;
@@ -1479,7 +1484,6 @@ export class FSCore {
14791484 if ( FSNode . isItem ( this . node ) ) {
14801485 // const collection = this.node.parent as FSCollectionNode;
14811486 // const validator = (input: string) => input === (this.node && this.node.nodeName) || input !== '' && !this.fileExists(input, collection);
1482- this . isRenamedItemNew = false ;
14831487 this . setRename ( this . node ) ;
14841488 }
14851489 }
0 commit comments