Skip to content

Commit 1fc6188

Browse files
committed
Clean up and save static plot metadata
1 parent 8553925 commit 1fc6188

File tree

5 files changed

+41
-49
lines changed

5 files changed

+41
-49
lines changed

src/vs/workbench/contrib/positronPlots/browser/positronPlots.contribution.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { IPositronPlotsService, POSITRON_PLOTS_VIEW_ID } from '../../../services
1818
import { IWorkbenchContributionsRegistry, Extensions as WorkbenchExtensions, IWorkbenchContribution } from '../../../common/contributions.js';
1919
import { Extensions as ViewContainerExtensions, IViewsRegistry } from '../../../common/views.js';
2020
import { MenuRegistry, registerAction2, MenuId, ISubmenuItem } from '../../../../platform/actions/common/actions.js';
21-
import { PlotsActiveEditorCopyAction, PlotsActiveEditorSaveAction, PlotsActiveEditorZoomAction, PlotsClearAction, PlotsCopyAction, PlotsEditorAction, PlotsNextAction, PlotsPopoutAction, PlotsPreviousAction, PlotsRefreshAction, PlotsSaveAction, PlotsSizingPolicyAction, ZoomFiftyAction, ZoomOneHundredAction, ZoomSeventyFiveAction, ZoomToFitAction, ZoomTwoHundredAction } from './positronPlotsActions.js';
21+
import { PlotsActiveEditorCopyAction, PlotsActiveEditorSaveAction, PlotsClearAction, PlotsEditorZoomAction, PlotsCopyAction, PlotsEditorAction, PlotsNextAction, PlotsPopoutAction, PlotsPreviousAction, PlotsRefreshAction, PlotsSaveAction, PlotsSizingPolicyAction, ZoomFiftyAction, ZoomOneHundredAction, ZoomSeventyFiveAction, ZoomToFitAction, ZoomTwoHundredAction } from './positronPlotsActions.js';
2222
import { POSITRON_SESSION_CONTAINER } from '../../positronSession/browser/positronSessionContainer.js';
2323
import { Extensions as ConfigurationExtensions, IConfigurationRegistry } from '../../../../platform/configuration/common/configurationRegistry.js';
2424
import { localize, localize2 } from '../../../../nls.js';
@@ -76,15 +76,14 @@ class PositronPlotsContribution extends Disposable implements IWorkbenchContribu
7676
registerAction2(PlotsActiveEditorCopyAction);
7777
registerAction2(PlotsActiveEditorSaveAction);
7878
registerAction2(PlotsSizingPolicyAction);
79-
registerAction2(PlotsActiveEditorZoomAction); // Keep this to register the SUBMENU_ID
8079
this.registerEditorZoomSubMenu();
8180
}
8281

8382
private registerEditorZoomSubMenu(): void {
8483
// Register the main submenu for the editor action bar
8584
const zoomSubmenu: ISubmenuItem = {
8685
title: localize2('positronPlots.zoomSubMenuTitle', 'Set the plot zoom'),
87-
submenu: PlotsActiveEditorZoomAction.SUBMENU_ID,
86+
submenu: PlotsEditorZoomAction.SUBMENU_ID,
8887
when: PLOT_IS_ACTIVE_EDITOR,
8988
group: 'navigation',
9089
order: 3,

src/vs/workbench/contrib/positronPlots/browser/positronPlotsActions.ts

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import { IPositronPlotClient, IPositronPlotsService, isZoomablePlotClient, ZoomL
2020
import { PlotClientInstance } from '../../../services/languageRuntime/common/languageRuntimePlotClient.js';
2121
import { ThemeIcon } from '../../../../base/common/themables.js';
2222
import { Uri } from 'vscode';
23+
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
2324

2425
export enum PlotActionTarget {
2526
VIEW = 'view',
@@ -627,29 +628,10 @@ export class PlotsSizingPolicyAction extends AbstractPlotsAction {
627628
}
628629
}
629630

630-
export class PlotsActiveEditorZoomAction extends Action2 {
631-
static readonly ID = 'workbench.action.positronPlots.zoomActiveEditor';
631+
export abstract class PlotsEditorZoomAction extends Action2 {
632632
static readonly SUBMENU_ID = MenuId.for('positronPlots.zoomSubmenu');
633+
static readonly ZOOM_LEVEL_CONTEXT_KEY = 'positronPlotsEditorZoomLevel';
633634

634-
constructor() {
635-
super({
636-
id: PlotsActiveEditorZoomAction.ID,
637-
title: localize2('positronPlots.zoomSubMenuTitle', 'Zoom'), // Title for the action if shown in lists like Keyboard Shortcuts
638-
category, // POSITRON_PLOTS_ACTION_CATEGORY
639-
f1: false, // Not in command palette by default
640-
// The 'menu' and 'icon' properties are removed.
641-
// This action itself is not directly placed in a menu to act as a submenu trigger.
642-
// An ISubmenuItem will be registered in positronPlots.contribution.ts for that.
643-
});
644-
}
645-
646-
async run(accessor: ServicesAccessor): Promise<void> {
647-
// This is a no-op. The action primarily serves to define SUBMENU_ID.
648-
// The actual zoom functionality is handled by individual zoom actions.
649-
}
650-
}
651-
652-
abstract class PlotsEditorZoomAction extends Action2 {
653635
abstract zoomLevel: ZoomLevel;
654636

655637
constructor(descriptor: IAction2Options) {
@@ -682,9 +664,12 @@ export class ZoomToFitAction extends PlotsEditorZoomAction {
682664
category,
683665
f1: false, // Not in command palette by default
684666
precondition: PLOT_IS_ACTIVE_EDITOR,
667+
toggled: {
668+
condition: ContextKeyExpr.equals('positronPlotsEditorZoomLevel', ZoomLevel.Fit.toString()),
669+
},
685670
menu: [
686671
{
687-
id: PlotsActiveEditorZoomAction.SUBMENU_ID,
672+
id: PlotsEditorZoomAction.SUBMENU_ID,
688673
when: PLOT_IS_ACTIVE_EDITOR,
689674
group: 'navigation',
690675
order: 1,
@@ -705,9 +690,12 @@ export class ZoomFiftyAction extends PlotsEditorZoomAction {
705690
category,
706691
f1: false, // Not in command palette by default
707692
precondition: PLOT_IS_ACTIVE_EDITOR,
693+
toggled: {
694+
condition: ContextKeyExpr.equals('positronPlotsEditorZoomLevel', ZoomLevel.Fifty.toString()),
695+
},
708696
menu: [
709697
{
710-
id: PlotsActiveEditorZoomAction.SUBMENU_ID,
698+
id: PlotsEditorZoomAction.SUBMENU_ID,
711699
when: PLOT_IS_ACTIVE_EDITOR,
712700
group: 'navigation',
713701
order: 2,
@@ -728,9 +716,12 @@ export class ZoomSeventyFiveAction extends PlotsEditorZoomAction {
728716
category,
729717
f1: false, // Not in command palette by default
730718
precondition: PLOT_IS_ACTIVE_EDITOR,
719+
toggled: {
720+
condition: ContextKeyExpr.equals('positronPlotsEditorZoomLevel', ZoomLevel.SeventyFive.toString()),
721+
},
731722
menu: [
732723
{
733-
id: PlotsActiveEditorZoomAction.SUBMENU_ID,
724+
id: PlotsEditorZoomAction.SUBMENU_ID,
734725
when: PLOT_IS_ACTIVE_EDITOR,
735726
group: 'navigation',
736727
order: 3,
@@ -751,9 +742,12 @@ export class ZoomOneHundredAction extends PlotsEditorZoomAction {
751742
category,
752743
f1: false, // Not in command palette by default
753744
precondition: PLOT_IS_ACTIVE_EDITOR,
745+
toggled: {
746+
condition: ContextKeyExpr.equals('positronPlotsEditorZoomLevel', ZoomLevel.OneHundred.toString()),
747+
},
754748
menu: [
755749
{
756-
id: PlotsActiveEditorZoomAction.SUBMENU_ID,
750+
id: PlotsEditorZoomAction.SUBMENU_ID,
757751
when: PLOT_IS_ACTIVE_EDITOR,
758752
group: 'navigation',
759753
order: 4,
@@ -774,9 +768,12 @@ export class ZoomTwoHundredAction extends PlotsEditorZoomAction {
774768
category,
775769
f1: false, // Not in command palette by default
776770
precondition: PLOT_IS_ACTIVE_EDITOR,
771+
toggled: {
772+
condition: ContextKeyExpr.equals('positronPlotsEditorZoomLevel', ZoomLevel.TwoHundred.toString()),
773+
},
777774
menu: [
778775
{
779-
id: PlotsActiveEditorZoomAction.SUBMENU_ID,
776+
id: PlotsEditorZoomAction.SUBMENU_ID,
780777
when: PLOT_IS_ACTIVE_EDITOR,
781778
group: 'navigation',
782779
order: 5,

src/vs/workbench/contrib/positronPlots/browser/positronPlotsService.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { ILanguageRuntimeMessageOutput, LanguageRuntimeSessionMode, RuntimeOutpu
1010
import { ILanguageRuntimeSession, IRuntimeClientInstance, IRuntimeSessionService, RuntimeClientType } from '../../../services/runtimeSession/common/runtimeSessionService.js';
1111
import { HTMLFileSystemProvider } from '../../../../platform/files/browser/htmlFileSystemProvider.js';
1212
import { IFileService } from '../../../../platform/files/common/files.js';
13-
import { createSuggestedFileNameForPlot, DarkFilter, HistoryPolicy, IPositronPlotClient, IPositronPlotsService, isZoomablePlotClient, PlotRenderFormat, PlotRenderSettings, POSITRON_PLOTS_VIEW_ID, ZoomLevel } from '../../../services/positronPlots/common/positronPlots.js';
13+
import { createSuggestedFileNameForPlot, DarkFilter, HistoryPolicy, IPositronPlotClient, IPositronPlotsService, PlotRenderFormat, PlotRenderSettings, POSITRON_PLOTS_VIEW_ID, ZoomLevel } from '../../../services/positronPlots/common/positronPlots.js';
1414
import { Emitter, Event } from '../../../../base/common/event.js';
1515
import { StaticPlotClient } from '../../../services/positronPlots/common/staticPlotClient.js';
1616
import { IStorageService, StorageTarget, StorageScope } from '../../../../platform/storage/common/storage.js';
@@ -564,18 +564,6 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
564564
}
565565
}
566566

567-
setEditorPlotZoom(plotId: string, zoomLevel: ZoomLevel): void {
568-
const plot = this._editorPlots.get(plotId);
569-
570-
if (isZoomablePlotClient(plot)) {
571-
plot.zoomLevel = zoomLevel;
572-
this.storePlotMetadata(plot.metadata);
573-
} else {
574-
// plot not found, show an error
575-
this._notificationService.error(localize('positronPlots.zoom.invalidPlotId', 'Plot not found: {0}', plotId));
576-
}
577-
}
578-
579567
getEditorPlotZoom(plotId: string): ZoomLevel | undefined {
580568
const plot = this._editorPlots.get(plotId);
581569
if (plot instanceof PlotClientInstance) {
@@ -934,6 +922,10 @@ export class PositronPlotsService extends Disposable implements IPositronPlotsSe
934922
this.generateStorageKey(metadata.session_id, metadata.id, metadata.location),
935923
StorageScope.WORKSPACE);
936924
}));
925+
this._register(plot.onDidChangeZoomLevel((zoomLevel) => {
926+
// Store the zoom level in the plot metadata
927+
this.storePlotMetadata(plot.metadata);
928+
}));
937929
this._editorPlots.set(metadata.id, plot);
938930
}
939931

src/vs/workbench/contrib/positronPlotsEditor/browser/positronPlotsEditor.tsx

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Emitter, Event } from '../../../../base/common/event.js';
1414
import { IAccessibilityService } from '../../../../platform/accessibility/common/accessibility.js';
1515
import { ICommandService } from '../../../../platform/commands/common/commands.js';
1616
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
17-
import { IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
17+
import { IContextKey, IContextKeyService } from '../../../../platform/contextkey/common/contextkey.js';
1818
import { IContextMenuService } from '../../../../platform/contextview/browser/contextView.js';
1919
import { EditorActivation, IEditorOptions } from '../../../../platform/editor/common/editor.js';
2020
import { IHoverService } from '../../../../platform/hover/browser/hover.js';
@@ -30,7 +30,7 @@ import { EditorPlotsContainer } from './editorPlotsContainer.js';
3030
import { PositronPlotsEditorInput } from './positronPlotsEditorInput.js';
3131
import { IEditorGroup } from '../../../services/editor/common/editorGroupsService.js';
3232
import { ILanguageRuntimeService } from '../../../services/languageRuntime/common/languageRuntimeService.js';
33-
import { createSuggestedFileNameForPlot, IPositronPlotClient, IPositronPlotsService } from '../../../services/positronPlots/common/positronPlots.js';
33+
import { createSuggestedFileNameForPlot, IPositronPlotClient, IPositronPlotsService, isZoomablePlotClient, ZoomLevel } from '../../../services/positronPlots/common/positronPlots.js';
3434
import { IPreferencesService } from '../../../services/preferences/common/preferences.js';
3535
import { ILayoutService } from '../../../../platform/layout/browser/layoutService.js';
3636

@@ -62,6 +62,7 @@ export class PositronPlotsEditor extends EditorPane implements IPositronPlotsEdi
6262

6363
private readonly _onFocusedEmitter = this._register(new Emitter<void>());
6464
private _plotClient: IPositronPlotClient | undefined;
65+
_zoomContextKey: IContextKey<string>;
6566

6667
get identifier(): string | undefined {
6768
return this._identifier;
@@ -124,6 +125,7 @@ export class PositronPlotsEditor extends EditorPane implements IPositronPlotsEdi
124125

125126
this._container = DOM.$('.positron-plots-editor-container');
126127
this._container.onclick = () => this.takeFocus();
128+
this._zoomContextKey = this._contextKeyService.createKey('positronPlotsEditorZoomLevel', '');
127129
}
128130

129131
private renderContainer(plotClient: IPositronPlotClient): void {
@@ -181,6 +183,13 @@ export class PositronPlotsEditor extends EditorPane implements IPositronPlotsEdi
181183

182184
input.setName(this._plotClient.metadata.suggested_file_name ?? createSuggestedFileNameForPlot(this.storageService));
183185

186+
if (isZoomablePlotClient(this._plotClient)) {
187+
this._register(this._plotClient.onDidChangeZoomLevel((zoomLevel: ZoomLevel) => {
188+
this._zoomContextKey.set(zoomLevel.toString());
189+
}));
190+
this._zoomContextKey.set(this._plotClient.metadata.zoom_level?.toString() ?? '');
191+
}
192+
184193
this.renderContainer(this._plotClient);
185194
this.onSizeChanged((event: ISize) => {
186195
this._height = event.height;

src/vs/workbench/services/positronPlots/common/positronPlots.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,6 @@ export interface IPositronPlotsService {
335335
*/
336336
setPlotsRenderSettings(settings: PlotRenderSettings): void;
337337

338-
/**
339-
* Sets the plot zoom level for the given editor plot ID.
340-
*/
341-
setEditorPlotZoom(plotId: string, zoom: number): void;
342-
343338
/**
344339
* Placeholder for service initialization.
345340
*/

0 commit comments

Comments
 (0)