-
Notifications
You must be signed in to change notification settings - Fork 28.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add copy actions to interactive session list (#176685)
* Add Copy/Copy All actions to interactive sessions * Remove Copy from F1 * Remove from command palette
- Loading branch information
1 parent
fc12c7e
commit ef1542d
Showing
6 changed files
with
110 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
src/vs/workbench/contrib/interactiveSession/browser/actions/interactiveSessionCopyActions.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import { ServicesAccessor } from 'vs/editor/browser/editorExtensions'; | ||
import { localize } from 'vs/nls'; | ||
import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; | ||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; | ||
import { INTERACTIVE_SESSION_CATEGORY } from 'vs/workbench/contrib/interactiveSession/browser/actions/interactiveSessionActions'; | ||
import { IInteractiveSessionWidgetService } from 'vs/workbench/contrib/interactiveSession/browser/interactiveSessionWidget'; | ||
import { IInteractiveRequestViewModel, IInteractiveResponseViewModel, isRequestVM, isResponseVM } from 'vs/workbench/contrib/interactiveSession/common/interactiveSessionViewModel'; | ||
|
||
export function registerInteractiveSessionCopyActions() { | ||
registerAction2(class CopyAllAction extends Action2 { | ||
constructor() { | ||
super({ | ||
id: 'workbench.action.interactiveSession.copyAll', | ||
title: { | ||
value: localize('interactive.copyAll.label', "Copy All"), | ||
original: 'Copy All' | ||
}, | ||
f1: false, | ||
category: INTERACTIVE_SESSION_CATEGORY, | ||
menu: { | ||
id: MenuId.InteractiveSessionContext | ||
} | ||
}); | ||
} | ||
|
||
run(accessor: ServicesAccessor, ...args: any[]) { | ||
const clipboardService = accessor.get(IClipboardService); | ||
const interactiveWidgetService = accessor.get(IInteractiveSessionWidgetService); | ||
const widget = interactiveWidgetService.lastFocusedWidget; | ||
if (widget) { | ||
const model = widget.getModel(); | ||
const sessionAsText = model?.getItems() | ||
.map(stringifyItem) | ||
.join('\n\n'); | ||
if (sessionAsText) { | ||
clipboardService.writeText(sessionAsText); | ||
} | ||
} | ||
} | ||
}); | ||
|
||
registerAction2(class CopyItemAction extends Action2 { | ||
constructor() { | ||
super({ | ||
id: 'workbench.action.interactiveSession.copyItem', | ||
title: { | ||
value: localize('interactive.copyItem.label', "Copy"), | ||
original: 'Copy' | ||
}, | ||
f1: false, | ||
category: INTERACTIVE_SESSION_CATEGORY, | ||
menu: { | ||
id: MenuId.InteractiveSessionContext | ||
} | ||
}); | ||
} | ||
|
||
run(accessor: ServicesAccessor, ...args: any[]) { | ||
const item = args[0]; | ||
if (!isRequestVM(item) && !isResponseVM(item)) { | ||
return; | ||
} | ||
|
||
const clipboardService = accessor.get(IClipboardService); | ||
const text = stringifyItem(item); | ||
clipboardService.writeText(text); | ||
} | ||
}); | ||
} | ||
|
||
function stringifyItem(item: IInteractiveRequestViewModel | IInteractiveResponseViewModel): string { | ||
return isRequestVM(item) ? | ||
`${item.username}: ${item.message}` : `${item.username}: ${item.response.value}`; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters