|
|
@ -68,23 +68,58 @@ export class OpenRemoteResourceCommandQuickPickItem extends CommandQuickPickItem |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class SetADefaultRemoteCommandQuickPickItem extends CommandQuickPickItem { |
|
|
|
constructor(private readonly remotes: GitRemote<RemoteProvider>[]) { |
|
|
|
super({ label: 'Set a Default Remote...' }); |
|
|
|
} |
|
|
|
|
|
|
|
async execute(): Promise<GitRemote<RemoteProvider> | undefined> { |
|
|
|
return RemoteProviderPicker.setADefaultRemote(this.remotes); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export class SetRemoteAsDefaultCommandQuickPickItem extends CommandQuickPickItem { |
|
|
|
constructor(private readonly remote: GitRemote<RemoteProvider>) { |
|
|
|
super({ |
|
|
|
label: remote.provider.name, |
|
|
|
detail: `$(repo) ${remote.provider.path}`, |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
async execute(): Promise<GitRemote<RemoteProvider>> { |
|
|
|
void (await this.remote.setAsDefault(true)); |
|
|
|
return this.remote; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export namespace RemoteProviderPicker { |
|
|
|
export async function show( |
|
|
|
title: string, |
|
|
|
placeHolder: string, |
|
|
|
resource: RemoteResource, |
|
|
|
remotes: GitRemote<RemoteProvider>[], |
|
|
|
clipboard?: boolean, |
|
|
|
): Promise<CopyOrOpenRemoteCommandQuickPickItem | undefined> { |
|
|
|
const items = remotes.map(r => new CopyOrOpenRemoteCommandQuickPickItem(r, resource, clipboard)); |
|
|
|
options?: { clipboard?: boolean; setDefault?: boolean }, |
|
|
|
): Promise<CopyOrOpenRemoteCommandQuickPickItem | SetADefaultRemoteCommandQuickPickItem | undefined> { |
|
|
|
const { clipboard, setDefault } = { clipboard: false, setDefault: true, ...options }; |
|
|
|
|
|
|
|
const items: (CopyOrOpenRemoteCommandQuickPickItem | SetADefaultRemoteCommandQuickPickItem)[] = remotes.map( |
|
|
|
r => new CopyOrOpenRemoteCommandQuickPickItem(r, resource, clipboard), |
|
|
|
); |
|
|
|
if (setDefault) { |
|
|
|
items.push(new SetADefaultRemoteCommandQuickPickItem(remotes)); |
|
|
|
} |
|
|
|
|
|
|
|
const quickpick = window.createQuickPick<CopyOrOpenRemoteCommandQuickPickItem>(); |
|
|
|
const quickpick = window.createQuickPick< |
|
|
|
CopyOrOpenRemoteCommandQuickPickItem | SetADefaultRemoteCommandQuickPickItem |
|
|
|
>(); |
|
|
|
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut(); |
|
|
|
|
|
|
|
const disposables: Disposable[] = []; |
|
|
|
|
|
|
|
try { |
|
|
|
const pick = await new Promise<CopyOrOpenRemoteCommandQuickPickItem | undefined>(resolve => { |
|
|
|
const pick = await new Promise< |
|
|
|
CopyOrOpenRemoteCommandQuickPickItem | SetADefaultRemoteCommandQuickPickItem | undefined |
|
|
|
>(resolve => { |
|
|
|
disposables.push( |
|
|
|
quickpick.onDidHide(() => resolve()), |
|
|
|
quickpick.onDidAccept(() => { |
|
|
@ -109,4 +144,41 @@ export namespace RemoteProviderPicker { |
|
|
|
disposables.forEach(d => d.dispose()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
export async function setADefaultRemote( |
|
|
|
remotes: GitRemote<RemoteProvider>[], |
|
|
|
): Promise<GitRemote<RemoteProvider> | undefined> { |
|
|
|
const items = remotes.map(r => new SetRemoteAsDefaultCommandQuickPickItem(r)); |
|
|
|
|
|
|
|
const quickpick = window.createQuickPick<SetRemoteAsDefaultCommandQuickPickItem>(); |
|
|
|
quickpick.ignoreFocusOut = getQuickPickIgnoreFocusOut(); |
|
|
|
|
|
|
|
const disposables: Disposable[] = []; |
|
|
|
|
|
|
|
try { |
|
|
|
const pick = await new Promise<SetRemoteAsDefaultCommandQuickPickItem | undefined>(resolve => { |
|
|
|
disposables.push( |
|
|
|
quickpick.onDidHide(() => resolve()), |
|
|
|
quickpick.onDidAccept(() => { |
|
|
|
if (quickpick.activeItems.length !== 0) { |
|
|
|
resolve(quickpick.activeItems[0]); |
|
|
|
} |
|
|
|
}), |
|
|
|
); |
|
|
|
|
|
|
|
quickpick.title = 'Set a Default Remote'; |
|
|
|
quickpick.placeholder = 'Choose which remote to set as the default'; |
|
|
|
quickpick.matchOnDetail = true; |
|
|
|
quickpick.items = items; |
|
|
|
|
|
|
|
quickpick.show(); |
|
|
|
}); |
|
|
|
if (pick == null) return undefined; |
|
|
|
|
|
|
|
return await pick.execute(); |
|
|
|
} finally { |
|
|
|
quickpick.dispose(); |
|
|
|
disposables.forEach(d => d.dispose()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |