-
Notifications
You must be signed in to change notification settings - Fork 92
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic copy plot to clipboard #2640
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,6 +31,7 @@ import { IWorkbenchLayoutService } from 'vs/workbench/services/layout/browser/la | |
import { URI } from 'vs/base/common/uri'; | ||
import { IWorkspaceContextService } from 'vs/platform/workspace/common/workspace'; | ||
import { IKeybindingService } from 'vs/platform/keybinding/common/keybinding'; | ||
import { IClipboardService } from 'vs/platform/clipboard/common/clipboardService'; | ||
|
||
/** The maximum number of recent executions to store. */ | ||
const MaxRecentExecutions = 10; | ||
|
@@ -107,7 +108,8 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe | |
@IFileDialogService private readonly _fileDialogService: IFileDialogService, | ||
@IWorkspaceContextService private readonly _workspaceContextService: IWorkspaceContextService, | ||
@IWorkbenchLayoutService private readonly _layoutService: IWorkbenchLayoutService, | ||
@IKeybindingService private readonly _keybindingService: IKeybindingService) { | ||
@IKeybindingService private readonly _keybindingService: IKeybindingService, | ||
@IClipboardService private _clipboardService: IClipboardService) { | ||
super(); | ||
|
||
// Register for language runtime service startups | ||
|
@@ -745,6 +747,25 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe | |
}); | ||
} | ||
|
||
async copyPlotToClipboard(): Promise<void> { | ||
const plot = this._plots.find(plot => plot.id === this.selectedPlotId); | ||
if (plot instanceof StaticPlotClient) { | ||
try { | ||
await this._clipboardService.writeImage(plot.uri); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
} else if (plot instanceof PlotClientInstance) { | ||
if (plot.lastRender?.uri) { | ||
try { | ||
await this._clipboardService.writeImage(plot.lastRender.uri); | ||
} catch (error) { | ||
throw new Error(error.message); | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should show a little toast notification, or gleam the icon or something, so there's visual feedback that the copy happened. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good idea. It now returns whether the copy occurred and will toast a notification. |
||
} | ||
|
||
/** | ||
* Generates a storage key for a plot. | ||
* | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is where I think that permission will be required. I haven't been able to test the web version so this will likely fail silently due to permissions.