@ -1,29 +1,34 @@
'use strict' ;
import { QuickPickOptions , window } from 'vscode' ;
import { Commands } from '../commands' ;
import { GitRemote , RemoteProvider OpenType } from '../gitService' ;
import { GitRemote , RemoteOpenType } from '../gitService' ;
import { CommandQuickPickItem , getQuickPickIgnoreFocusOut } from './quickPicks' ;
import * as path from 'path' ;
function getNameFromRemoteOpenType ( type : RemoteOpenType ) {
switch ( type ) {
case 'branch' : return 'Branch' ;
case 'commit' : return 'Commit' ;
case 'file' : return 'File' ;
case 'working-file' : return 'Working File' ;
default : return '' ;
}
}
export class OpenRemoteCommandQuickPickItem extends CommandQuickPickItem {
private type : RemoteProviderOpenType ;
private remote : GitRemote ;
private type : RemoteOpenType ;
constructor ( remote : GitRemote , type : RemoteProviderOpenType , . . . args : string [ ] ) ;
constructor ( remote : GitRemote , type : RemoteProviderOpenType , branchOrShaOrFileName : string , fileSha? : string , name? : string ) {
if ( ! name ) {
name = ` ${ type [ 0 ] . toUpperCase ( ) } ${ type . substring ( 1 ) } ` ;
}
constructor ( remote : GitRemote , type : RemoteOpenType , . . . args : string [ ] ) {
super ( {
label : ` $ (link-external) Open ${ name } in ${ remote . provider . name } ` ,
label : ` $ (link-external) Open ${ getNameFromRemoteOpenType ( type ) } in ${ remote . provider . name } ` ,
description : ` \ u00a0 \ u2014 \ u00a0 \ u00a0 $ (repo) ${ remote . provider . path } `
} , undefined , undefined ) ;
this . type = type ;
this . remote = remote ;
this . args = [ branchOrShaOrFileName , fileSha ] ;
this . type = type ;
this . args = args ;
}
async execute ( ) : Promise < { } > {
@ -35,37 +40,37 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
constructor ( remotes : GitRemote [ ] , type : 'branch' , branch : string , goBackCommand? : CommandQuickPickItem ) ;
constructor ( remotes : GitRemote [ ] , type : 'commit' , sha : string , goBackCommand? : CommandQuickPickItem ) ;
constructor ( remotes : GitRemote [ ] , type : 'file' , fileName : string , sha? : string , name ? : string , goBackCommand? : CommandQuickPickItem ) ;
constructor ( remotes : GitRemote [ ] , type : RemoteProvider OpenType , branchOrShaOrFileName : string , shaOrGoBackCommand? : string | CommandQuickPickItem , name ? : string , goBackCommand? : CommandQuickPickItem ) {
let fileSha : string ;
if ( typeof shaOrGoBackCommand === 'string' ) {
fileSha = shaOrGoBackCommand ;
constructor ( remotes : GitRemote [ ] , type : 'file' | 'working-file' , fileName : string , branch? : string , sha ? : string , goBackCommand? : CommandQuickPickItem ) ;
constructor ( remotes : GitRemote [ ] , type : RemoteOpenType , branchOrShaOrFileName : string , goBackCommandOrFileBranch? : CommandQuickPickItem | string , fileSha ? : string , goBackCommand? : CommandQuickPickItem ) {
let fileBranch : string ;
if ( typeof goBackCommandOrFileBranch === 'string' ) {
fileBranch = goBackCommandOrFileBranch ;
}
else if ( ! goBackCommand ) {
goBackCommand = shaOrGoBackCommand ;
goBackCommand = goBackCommandOrFileBranch ;
}
const name = getNameFromRemoteOpenType ( type ) ;
let description : string ;
let placeHolder : string ;
switch ( type ) {
case 'branch' :
name = name || 'Branch' ;
description = ` $ (git-branch) ${ branchOrShaOrFileName } ` ;
placeHolder = ` open ${ branchOrShaOrFileName } ${ name . toLowerCase ( ) } in \ u2026 ` ;
break ;
case 'commit' :
const shortSha = branchOrShaOrFileName . substring ( 0 , 8 ) ;
name = name || 'Commit' ;
description = ` $ (git-commit) ${ shortSha } ` ;
placeHolder = ` open ${ name . toLowerCase ( ) } ${ shortSha } in \ u2026 ` ;
break ;
case 'file' :
case 'working-file' :
const fileName = path . basename ( branchOrShaOrFileName ) ;
const shortFileSha = ( fileSha && fileSha . substring ( 0 , 8 ) ) || '' ;
const shaSuffix = shortFileSha ? ` \ u00a0 \ u2022 \ u00a0 ${ shortFileSha } ` : '' ;
name = name || 'File' ;
description = ` $ (file-text) ${ fileName } ${ shortFileSha ? ` in \ u00a0 $ (git-commit) ${ shortFileSha } ` : '' } ` ;
placeHolder = ` open ${ branchOrShaOrFileName } ${ shaSuffix } in \ u2026 ` ;
break ;
@ -76,7 +81,7 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
super ( {
label : ` $ (link-external) Open ${ name } in ${ remote . provider . name } ` ,
description : ` \ u00a0 \ u2014 \ u00a0 \ u00a0 $ (repo) ${ remote . provider . path } \ u00a0 \ u2022 \ u00a0 ${ description } `
} , Commands . OpenInRemote , [ undefined , remotes , type , [ branchOrShaOrFileName , fileSha ] , name , goBackCommand ] ) ;
} , Commands . OpenInRemote , [ undefined , remotes , type , [ branchOrShaOrFileName , fileBranch , fileSha ] , goBackCommand ] ) ;
return ;
}
@ -88,15 +93,15 @@ export class OpenRemotesCommandQuickPickItem extends CommandQuickPickItem {
super ( {
label : ` $ (link-external) Open ${ name } in ${ provider } \ u2026 ` ,
description : ` \ u00a0 \ u2014 \ u00a0 \ u00a0 ${ description } `
} , Commands . OpenInRemote , [ undefined , remotes , type , [ branchOrShaOrFileName , fileSha ] , name , goBackCommand ] ) ;
} , Commands . OpenInRemote , [ undefined , remotes , type , [ branchOrShaOrFileName , fileBranch , fileSha ] , goBackCommand ] ) ;
}
}
export class RemotesQuickPick {
static async show ( remotes : GitRemote [ ] , placeHolder : string , type : RemoteProvider OpenType , args : string [ ] , name : string , goBackCommand? : CommandQuickPickItem ) : Promise < OpenRemoteCommandQuickPickItem | CommandQuickPickItem | undefined > {
static async show ( remotes : GitRemote [ ] , placeHolder : string , type : RemoteOpenType , args : string [ ] , goBackCommand? : CommandQuickPickItem ) : Promise < OpenRemoteCommandQuickPickItem | CommandQuickPickItem | undefined > {
const items = remotes . map ( _ = > new OpenRemoteCommandQuickPickItem ( _ , type , . . . args , name )) as ( OpenRemoteCommandQuickPickItem | CommandQuickPickItem ) [ ] ;
const items = remotes . map ( _ = > new OpenRemoteCommandQuickPickItem ( _ , type , . . . args ) ) as ( OpenRemoteCommandQuickPickItem | CommandQuickPickItem ) [ ] ;
if ( goBackCommand ) {
items . splice ( 0 , 0 , goBackCommand ) ;