@@ -37,6 +37,11 @@ export type SavedConnectionInformation = {
37
37
// A loaded connection contains connection information.
38
38
export type LoadedConnection = SavedConnection & SavedConnectionInformation ;
39
39
40
+ export enum NewConnectionType {
41
+ NEW_CONNECTION = 'NEW_CONNECTION' ,
42
+ SAVED_CONNECTION = 'SAVED_CONNECTION'
43
+ }
44
+
40
45
export default class ConnectionController {
41
46
// This is a map of connection ids to their configurations.
42
47
// These connections can be saved on the session (runtime),
@@ -586,13 +591,13 @@ export default class ConnectionController {
586
591
const connectionNameToRemove :
587
592
| string
588
593
| undefined = await vscode . window . showQuickPick (
589
- connectionIds . map (
590
- ( id , index ) => `${ index + 1 } : ${ this . _connections [ id ] . name } `
591
- ) ,
592
- {
593
- placeHolder : 'Choose a connection to remove...'
594
- }
595
- ) ;
594
+ connectionIds . map (
595
+ ( id , index ) => `${ index + 1 } : ${ this . _connections [ id ] . name } `
596
+ ) ,
597
+ {
598
+ placeHolder : 'Choose a connection to remove...'
599
+ }
600
+ ) ;
596
601
597
602
if ( ! connectionNameToRemove ) {
598
603
return Promise . resolve ( false ) ;
@@ -777,4 +782,63 @@ export default class ConnectionController {
777
782
public setDisconnecting ( disconnecting : boolean ) : void {
778
783
this . _disconnecting = disconnecting ;
779
784
}
785
+
786
+ public getСonnectionQuickPicks ( ) : any [ ] {
787
+ if ( ! this . _connections ) {
788
+ return [
789
+ {
790
+ label : 'Add new connection' ,
791
+ data : {
792
+ type : NewConnectionType . NEW_CONNECTION
793
+ }
794
+ }
795
+ ] ;
796
+ }
797
+
798
+ return [
799
+ {
800
+ label : 'Add new connection' ,
801
+ data : {
802
+ type : NewConnectionType . NEW_CONNECTION
803
+ }
804
+ } ,
805
+ ...Object . values ( this . _connections )
806
+ . sort ( ( connectionA : any , connectionB : any ) =>
807
+ ( connectionA . name || '' ) . localeCompare ( connectionB . name || '' )
808
+ )
809
+ . map ( ( item : any ) => ( {
810
+ label : item . name ,
811
+ data : {
812
+ type : NewConnectionType . SAVED_CONNECTION ,
813
+ connectionId : item . id
814
+ }
815
+ } ) )
816
+ ] ;
817
+ }
818
+
819
+ public changeActiveConnection ( ) : Promise < boolean > {
820
+ return new Promise ( async ( resolve ) => {
821
+ const selectedQuickPickItem = await vscode . window . showQuickPick (
822
+ this . getСonnectionQuickPicks ( ) ,
823
+ {
824
+ placeHolder : 'Select new connection...'
825
+ }
826
+ ) ;
827
+
828
+ if ( ! selectedQuickPickItem ) {
829
+ return resolve ( true ) ;
830
+ }
831
+
832
+ if (
833
+ selectedQuickPickItem . data . type === NewConnectionType . NEW_CONNECTION
834
+ ) {
835
+ return this . connectWithURI ( ) ;
836
+ }
837
+
838
+ // Get the saved connection by id and return as the current connection.
839
+ return this . connectWithConnectionId (
840
+ selectedQuickPickItem . data . connectionId
841
+ ) ;
842
+ } ) ;
843
+ }
780
844
}
0 commit comments