@@ -14,12 +14,13 @@ import TelemetryController from './telemetry/telemetryController';
1414import { StatusView } from './views' ;
1515import { createLogger } from './logging' ;
1616import { StorageController } from './storage' ;
17- import DatabaseTreeItem from './explorer/databaseTreeItem' ;
1817import ConnectionTreeItem from './explorer/connectionTreeItem' ;
18+ import DatabaseTreeItem from './explorer/databaseTreeItem' ;
1919import SchemaTreeItem from './explorer/schemaTreeItem' ;
20+ import DocumentListTreeItem from './explorer/documentListTreeItem' ;
2021import DocumentTreeItem from './explorer/documentTreeItem' ;
2122import WebviewController from './views/webviewController' ;
22- import DocumentListTreeItem from './explorer/documentListTreeItem ' ;
23+ import FieldTreeItem from './explorer/fieldTreeItem ' ;
2324
2425const log = createLogger ( 'commands' ) ;
2526
@@ -200,19 +201,15 @@ export default class MDBExtensionController implements vscode.Disposable {
200201 ) ;
201202 this . registerCommand (
202203 'mdb.copyConnectionString' ,
203- ( element : ConnectionTreeItem ) => {
204- // TODO: Password obfuscation.
204+ async ( element : ConnectionTreeItem ) : Promise < boolean > => {
205205 const connectionString = this . _connectionController . getConnectionStringFromConnectionId (
206206 element . connectionId
207207 ) ;
208208
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.' ) ;
212211
213- return resolve ( true ) ;
214- } , reject ) ;
215- } ) ;
212+ return true ;
216213 }
217214 ) ;
218215 this . registerCommand (
@@ -232,7 +229,7 @@ export default class MDBExtensionController implements vscode.Disposable {
232229 vscode . window . showErrorMessage (
233230 'Please wait for the connection to finish loading before adding a database.'
234231 ) ;
235- return Promise . resolve ( false ) ;
232+ return false ;
236233 }
237234
238235 if (
@@ -242,72 +239,63 @@ export default class MDBExtensionController implements vscode.Disposable {
242239 vscode . window . showErrorMessage (
243240 'Please connect to this connection before adding a database.'
244241 ) ;
245- return Promise . resolve ( false ) ;
242+ return false ;
246243 }
247244
248245 if ( this . _connectionController . isDisconnecting ( ) ) {
249246 vscode . window . showErrorMessage (
250247 'Unable to add database: currently disconnecting.'
251248 ) ;
252- return Promise . resolve ( false ) ;
249+ return false ;
253250 }
254251
255252 if ( this . _connectionController . isConnecting ( ) ) {
256253 vscode . window . showErrorMessage (
257254 'Unable to add database: currently connecting.'
258255 ) ;
259- return Promise . resolve ( false ) ;
256+ return false ;
260257 }
261258
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 ;
278273 }
279274 ) ;
280275 this . registerCommand (
281276 '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 ;
289281 }
290282 ) ;
291283 this . registerCommand (
292284 '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 ;
311299 }
312300 ) ;
313301 this . registerCommand (
@@ -324,58 +312,48 @@ export default class MDBExtensionController implements vscode.Disposable {
324312 vscode . window . showErrorMessage (
325313 'Unable to add collection: currently disconnecting.'
326314 ) ;
327- return Promise . resolve ( false ) ;
315+ return false ;
328316 }
329317
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 ;
346330 }
347331 ) ;
348332 this . registerCommand (
349333 '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 ;
357339 }
358340 ) ;
359341 this . registerCommand (
360342 '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 ;
379357 }
380358 ) ;
381359 this . registerCommand (
@@ -417,6 +395,17 @@ export default class MDBExtensionController implements vscode.Disposable {
417395 return this . _explorerController . refresh ( ) ;
418396 }
419397 ) ;
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+ ) ;
420409 }
421410
422411 dispose ( ) : void {
0 commit comments