@@ -14,12 +14,13 @@ import TelemetryController from './telemetry/telemetryController';
14
14
import { StatusView } from './views' ;
15
15
import { createLogger } from './logging' ;
16
16
import { StorageController } from './storage' ;
17
- import DatabaseTreeItem from './explorer/databaseTreeItem' ;
18
17
import ConnectionTreeItem from './explorer/connectionTreeItem' ;
18
+ import DatabaseTreeItem from './explorer/databaseTreeItem' ;
19
19
import SchemaTreeItem from './explorer/schemaTreeItem' ;
20
+ import DocumentListTreeItem from './explorer/documentListTreeItem' ;
20
21
import DocumentTreeItem from './explorer/documentTreeItem' ;
21
22
import WebviewController from './views/webviewController' ;
22
- import DocumentListTreeItem from './explorer/documentListTreeItem ' ;
23
+ import FieldTreeItem from './explorer/fieldTreeItem ' ;
23
24
24
25
const log = createLogger ( 'commands' ) ;
25
26
@@ -200,19 +201,15 @@ export default class MDBExtensionController implements vscode.Disposable {
200
201
) ;
201
202
this . registerCommand (
202
203
'mdb.copyConnectionString' ,
203
- ( element : ConnectionTreeItem ) => {
204
- // TODO: Password obfuscation.
204
+ async ( element : ConnectionTreeItem ) : Promise < boolean > => {
205
205
const connectionString = this . _connectionController . getConnectionStringFromConnectionId (
206
206
element . connectionId
207
207
) ;
208
208
209
- return new Promise ( ( resolve , reject ) => {
210
- vscode . env . clipboard . writeText ( connectionString ) . then ( ( ) => {
211
- vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
209
+ await vscode . env . clipboard . writeText ( connectionString ) ;
210
+ vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
212
211
213
- return resolve ( true ) ;
214
- } , reject ) ;
215
- } ) ;
212
+ return true ;
216
213
}
217
214
) ;
218
215
this . registerCommand (
@@ -232,7 +229,7 @@ export default class MDBExtensionController implements vscode.Disposable {
232
229
vscode . window . showErrorMessage (
233
230
'Please wait for the connection to finish loading before adding a database.'
234
231
) ;
235
- return Promise . resolve ( false ) ;
232
+ return false ;
236
233
}
237
234
238
235
if (
@@ -242,72 +239,63 @@ export default class MDBExtensionController implements vscode.Disposable {
242
239
vscode . window . showErrorMessage (
243
240
'Please connect to this connection before adding a database.'
244
241
) ;
245
- return Promise . resolve ( false ) ;
242
+ return false ;
246
243
}
247
244
248
245
if ( this . _connectionController . isDisconnecting ( ) ) {
249
246
vscode . window . showErrorMessage (
250
247
'Unable to add database: currently disconnecting.'
251
248
) ;
252
- return Promise . resolve ( false ) ;
249
+ return false ;
253
250
}
254
251
255
252
if ( this . _connectionController . isConnecting ( ) ) {
256
253
vscode . window . showErrorMessage (
257
254
'Unable to add database: currently connecting.'
258
255
) ;
259
- return Promise . resolve ( false ) ;
256
+ return false ;
260
257
}
261
258
262
- return new Promise ( ( resolve , reject ) => {
263
- element
264
- . onAddDatabaseClicked ( this . _context )
265
- . then ( ( successfullyAddedDatabase ) => {
266
- if ( successfullyAddedDatabase ) {
267
- vscode . window . showInformationMessage (
268
- 'Database and collection successfully created.'
269
- ) ;
270
-
271
- // When we successfully added a database & collection, we need
272
- // to update the explorer view.
273
- this . _explorerController . refresh ( ) ;
274
- }
275
- resolve ( successfullyAddedDatabase ) ;
276
- } , reject ) ;
277
- } ) ;
259
+ const successfullyAddedDatabase = await element . onAddDatabaseClicked (
260
+ this . _context
261
+ ) ;
262
+
263
+ if ( successfullyAddedDatabase ) {
264
+ vscode . window . showInformationMessage (
265
+ 'Database and collection successfully created.'
266
+ ) ;
267
+
268
+ // When we successfully added a database & collection, we need
269
+ // to update the explorer view.
270
+ this . _explorerController . refresh ( ) ;
271
+ }
272
+ return successfullyAddedDatabase ;
278
273
}
279
274
) ;
280
275
this . registerCommand (
281
276
'mdb.copyDatabaseName' ,
282
- ( element : DatabaseTreeItem ) => {
283
- return new Promise ( ( resolve , reject ) => {
284
- vscode . env . clipboard . writeText ( element . databaseName ) . then ( ( ) => {
285
- vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
286
- return resolve ( true ) ;
287
- } , reject ) ;
288
- } ) ;
277
+ async ( element : DatabaseTreeItem ) => {
278
+ await vscode . env . clipboard . writeText ( element . databaseName ) ;
279
+ vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
280
+ return true ;
289
281
}
290
282
) ;
291
283
this . registerCommand (
292
284
'mdb.dropDatabase' ,
293
- ( element : DatabaseTreeItem ) : Promise < boolean > => {
294
- return new Promise ( ( resolve , reject ) => {
295
- element
296
- . onDropDatabaseClicked ( )
297
- . then ( ( successfullyDroppedDatabase ) => {
298
- if ( successfullyDroppedDatabase ) {
299
- vscode . window . showInformationMessage (
300
- 'Database successfully dropped.'
301
- ) ;
302
-
303
- // When we successfully drop a database, we need
304
- // to update the explorer view.
305
- this . _explorerController . refresh ( ) ;
306
- }
307
-
308
- resolve ( successfullyDroppedDatabase ) ;
309
- } , reject ) ;
310
- } ) ;
285
+ async ( element : DatabaseTreeItem ) : Promise < boolean > => {
286
+ const successfullyDroppedDatabase = await element . onDropDatabaseClicked ( ) ;
287
+
288
+ if ( successfullyDroppedDatabase ) {
289
+ vscode . window . showInformationMessage (
290
+ 'Database successfully dropped.'
291
+ ) ;
292
+
293
+ // When we successfully drop a database, we need
294
+ // to update the explorer view.
295
+ this . _explorerController . refresh ( ) ;
296
+ }
297
+
298
+ return successfullyDroppedDatabase ;
311
299
}
312
300
) ;
313
301
this . registerCommand (
@@ -324,58 +312,48 @@ export default class MDBExtensionController implements vscode.Disposable {
324
312
vscode . window . showErrorMessage (
325
313
'Unable to add collection: currently disconnecting.'
326
314
) ;
327
- return Promise . resolve ( false ) ;
315
+ return false ;
328
316
}
329
317
330
- return new Promise ( ( resolve , reject ) => {
331
- element
332
- . onAddCollectionClicked ( this . _context )
333
- . then ( ( successfullyAddedCollection ) => {
334
- if ( successfullyAddedCollection ) {
335
- vscode . window . showInformationMessage (
336
- 'Collection successfully created.'
337
- ) ;
338
-
339
- // When we successfully added a collection, we need
340
- // to update the explorer view.
341
- this . _explorerController . refresh ( ) ;
342
- }
343
- resolve ( true ) ;
344
- } , reject ) ;
345
- } ) ;
318
+ const successfullyAddedCollection = await element
319
+ . onAddCollectionClicked ( this . _context ) ;
320
+ if ( successfullyAddedCollection ) {
321
+ vscode . window . showInformationMessage (
322
+ 'Collection successfully created.'
323
+ ) ;
324
+
325
+ // When we successfully added a collection, we need
326
+ // to update the explorer view.
327
+ this . _explorerController . refresh ( ) ;
328
+ }
329
+ return true ;
346
330
}
347
331
) ;
348
332
this . registerCommand (
349
333
'mdb.copyCollectionName' ,
350
- ( element : CollectionTreeItem ) : Promise < boolean > => {
351
- return new Promise ( ( resolve , reject ) => {
352
- vscode . env . clipboard . writeText ( element . collectionName ) . then ( ( ) => {
353
- vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
354
- return resolve ( true ) ;
355
- } , reject ) ;
356
- } ) ;
334
+ async ( element : CollectionTreeItem ) : Promise < boolean > => {
335
+ await vscode . env . clipboard . writeText ( element . collectionName ) ;
336
+ vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
337
+
338
+ return true ;
357
339
}
358
340
) ;
359
341
this . registerCommand (
360
342
'mdb.dropCollection' ,
361
- ( element : CollectionTreeItem ) : Promise < boolean > => {
362
- return new Promise ( ( resolve , reject ) => {
363
- element
364
- . onDropCollectionClicked ( )
365
- . then ( ( successfullyDroppedCollection ) => {
366
- if ( successfullyDroppedCollection ) {
367
- vscode . window . showInformationMessage (
368
- 'Collection successfully dropped.'
369
- ) ;
370
-
371
- // When we successfully drop a collection, we need
372
- // to update the explorer view.
373
- this . _explorerController . refresh ( ) ;
374
- }
375
-
376
- resolve ( successfullyDroppedCollection ) ;
377
- } , reject ) ;
378
- } ) ;
343
+ async ( element : CollectionTreeItem ) : Promise < boolean > => {
344
+ const successfullyDroppedCollection = await element . onDropCollectionClicked ( ) ;
345
+
346
+ if ( successfullyDroppedCollection ) {
347
+ vscode . window . showInformationMessage (
348
+ 'Collection successfully dropped.'
349
+ ) ;
350
+
351
+ // When we successfully drop a collection, we need
352
+ // to update the explorer view.
353
+ this . _explorerController . refresh ( ) ;
354
+ }
355
+
356
+ return successfullyDroppedCollection ;
379
357
}
380
358
) ;
381
359
this . registerCommand (
@@ -417,6 +395,17 @@ export default class MDBExtensionController implements vscode.Disposable {
417
395
return this . _explorerController . refresh ( ) ;
418
396
}
419
397
) ;
398
+ this . registerCommand (
399
+ 'mdb.copySchemaFieldName' ,
400
+ async ( fieldTreeItem : FieldTreeItem ) : Promise < boolean > => {
401
+ await vscode . env . clipboard . writeText (
402
+ fieldTreeItem . getFieldName ( )
403
+ ) ;
404
+ vscode . window . showInformationMessage ( 'Copied to clipboard.' ) ;
405
+
406
+ return true ;
407
+ }
408
+ ) ;
420
409
}
421
410
422
411
dispose ( ) : void {
0 commit comments