mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 13:00:58 +00:00
Allow share providers to return text (#184203)
This commit is contained in:
parent
fa84a900fa
commit
5504c4b854
|
@ -31,7 +31,8 @@ export class MainThreadShare implements MainThreadShareShape {
|
|||
selector,
|
||||
priority,
|
||||
provideShare: async (item: IShareableItem) => {
|
||||
return URI.revive(await this.proxy.$provideShare(handle, item, new CancellationTokenSource().token));
|
||||
const result = await this.proxy.$provideShare(handle, item, new CancellationTokenSource().token);
|
||||
return typeof result === 'string' ? result : URI.revive(result);
|
||||
}
|
||||
};
|
||||
this.providers.set(handle, provider);
|
||||
|
|
|
@ -2032,7 +2032,7 @@ export interface ExtHostQuickDiffShape {
|
|||
}
|
||||
|
||||
export interface ExtHostShareShape {
|
||||
$provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | undefined>;
|
||||
$provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | string | undefined>;
|
||||
}
|
||||
|
||||
export interface ExtHostTaskShape {
|
||||
|
|
|
@ -23,7 +23,7 @@ export class ExtHostShare implements ExtHostShareShape {
|
|||
this.proxy = mainContext.getProxy(MainContext.MainThreadShare);
|
||||
}
|
||||
|
||||
async $provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | undefined> {
|
||||
async $provideShare(handle: number, shareableItem: IShareableItemDto, token: CancellationToken): Promise<UriComponents | string | undefined> {
|
||||
const provider = this.providers.get(handle);
|
||||
const result = await provider?.provideShare({ selection: Range.to(shareableItem.selection), resourceUri: URI.revive(shareableItem.resourceUri) }, token);
|
||||
return result ?? undefined;
|
||||
|
|
|
@ -86,28 +86,29 @@ class ShareWorkbenchContribution {
|
|||
const progressService = accessor.get(IProgressService);
|
||||
const selection = accessor.get(ICodeEditorService).getActiveCodeEditor()?.getSelection() ?? undefined;
|
||||
|
||||
const uri = await progressService.withProgress({
|
||||
const result = await progressService.withProgress({
|
||||
location: ProgressLocation.Window,
|
||||
detail: localize('generating link', 'Generating link...')
|
||||
}, async () => shareService.provideShare({ resourceUri, selection }, new CancellationTokenSource().token));
|
||||
|
||||
if (uri) {
|
||||
const uriText = uri.toString();
|
||||
if (result) {
|
||||
const uriText = result.toString();
|
||||
const isResultText = typeof result === 'string';
|
||||
await clipboardService.writeText(uriText);
|
||||
|
||||
dialogService.prompt(
|
||||
{
|
||||
type: Severity.Info,
|
||||
message: localize('shareSuccess', 'Copied link to clipboard!'),
|
||||
message: isResultText ? localize('shareTextSuccess', 'Copied text to clipboard!') : localize('shareSuccess', 'Copied link to clipboard!'),
|
||||
custom: {
|
||||
icon: Codicon.check,
|
||||
markdownDetails: [{
|
||||
markdown: new MarkdownString(`<div aria-label='${uriText}'>${uriText}</div>`, { supportHtml: true }),
|
||||
classes: ['share-dialog-input']
|
||||
classes: [isResultText ? 'share-dialog-input-text' : 'share-dialog-input-link']
|
||||
}]
|
||||
},
|
||||
cancelButton: localize('close', 'Close'),
|
||||
buttons: [{ label: localize('open link', 'Open Link'), run: () => { urlService.open(uri, { openExternal: true }); } }]
|
||||
buttons: isResultText ? [] : [{ label: localize('open link', 'Open Link'), run: () => { urlService.open(result, { openExternal: true }); } }]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -3,16 +3,19 @@
|
|||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
div.share-dialog-input {
|
||||
div.share-dialog-input-text,
|
||||
div.share-dialog-input-link {
|
||||
border: 1px solid var(--vscode-input-border, transparent);
|
||||
border-radius: 2px;
|
||||
color: var(--vscode-input-foreground);
|
||||
background-color: var(--vscode-input-background);
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
padding: 2px;
|
||||
user-select: all;
|
||||
line-height: 24px;
|
||||
}
|
||||
|
||||
div.share-dialog-input-link {
|
||||
overflow: hidden;
|
||||
white-space: nowrap;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
|
|
@ -48,7 +48,7 @@ export class ShareService implements IShareService {
|
|||
return [];
|
||||
}
|
||||
|
||||
async provideShare(item: IShareableItem, token: CancellationToken): Promise<URI | undefined> {
|
||||
async provideShare(item: IShareableItem, token: CancellationToken): Promise<URI | string | undefined> {
|
||||
const language = this.codeEditorService.getActiveCodeEditor()?.getModel()?.getLanguageId() ?? '';
|
||||
const providers = [...this._providers.values()]
|
||||
.filter((p) => score(p.selector, item.resourceUri, language, true, undefined, undefined) > 0)
|
||||
|
|
|
@ -22,7 +22,7 @@ export interface IShareProvider {
|
|||
readonly priority: number;
|
||||
readonly selector: LanguageSelector;
|
||||
prepareShare?(item: IShareableItem, token: CancellationToken): Thenable<boolean | undefined>;
|
||||
provideShare(item: IShareableItem, token: CancellationToken): Thenable<URI | undefined>;
|
||||
provideShare(item: IShareableItem, token: CancellationToken): Thenable<URI | string | undefined>;
|
||||
}
|
||||
|
||||
export const IShareService = createDecorator<IShareService>('shareService');
|
||||
|
@ -31,5 +31,5 @@ export interface IShareService {
|
|||
|
||||
registerShareProvider(provider: IShareProvider): IDisposable;
|
||||
getShareActions(): ISubmenuItem[];
|
||||
provideShare(item: IShareableItem, token: CancellationToken): Thenable<URI | undefined>;
|
||||
provideShare(item: IShareableItem, token: CancellationToken): Thenable<URI | string | undefined>;
|
||||
}
|
||||
|
|
|
@ -47,9 +47,10 @@ declare module 'vscode' {
|
|||
*
|
||||
* @param item Data about an item which can be shared.
|
||||
* @param token A cancellation token.
|
||||
* @returns An {@link Uri} which will be copied to the user's clipboard and presented in a confirmation dialog.
|
||||
* @returns A {@link Uri} representing an external link or sharing text. The provider result
|
||||
* will be copied to the user's clipboard and presented in a confirmation dialog.
|
||||
*/
|
||||
provideShare(item: ShareableItem, token: CancellationToken): ProviderResult<Uri>;
|
||||
provideShare(item: ShareableItem, token: CancellationToken): ProviderResult<Uri | string>;
|
||||
}
|
||||
|
||||
export namespace window {
|
||||
|
|
Loading…
Reference in a new issue