Skip to content

Commit

Permalink
Remove plot in editor tab flag (#6148)
Browse files Browse the repository at this point in the history
timtmok authored Jan 30, 2025
1 parent f4b7966 commit 9ea950e
Showing 3 changed files with 7 additions and 39 deletions.
Original file line number Diff line number Diff line change
@@ -7,15 +7,15 @@
import './actionBars.css';

// React.
import React, { PropsWithChildren, useEffect } from 'react';
import React, { PropsWithChildren } from 'react';

// Other dependencies.
import { localize } from '../../../../../nls.js';
import { ICommandService } from '../../../../../platform/commands/common/commands.js';
import { IKeybindingService } from '../../../../../platform/keybinding/common/keybinding.js';
import { IContextKeyService } from '../../../../../platform/contextkey/common/contextkey.js';
import { IContextMenuService } from '../../../../../platform/contextview/browser/contextView.js';
import { IConfigurationChangeEvent, IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
import { IConfigurationService } from '../../../../../platform/configuration/common/configuration.js';
import { PositronActionBar } from '../../../../../platform/positronActionBar/browser/positronActionBar.js';
import { IWorkbenchLayoutService } from '../../../../services/layout/browser/layoutService.js';
import { ActionBarRegion } from '../../../../../platform/positronActionBar/browser/components/actionBarRegion.js';
@@ -32,7 +32,6 @@ import { INotificationService } from '../../../../../platform/notification/commo
import { PlotActionTarget, PlotsClearAction, PlotsCopyAction, PlotsNextAction, PlotsPopoutAction, PlotsPreviousAction, PlotsSaveAction } from '../positronPlotsActions.js';
import { IHoverService } from '../../../../../platform/hover/browser/hover.js';
import { HtmlPlotClient } from '../htmlPlotClient.js';
import { POSITRON_EDITOR_PLOTS, positronPlotsEditorEnabled } from '../../../positronPlotsEditor/browser/positronPlotsEditor.contribution.js';
import { IAccessibilityService } from '../../../../../platform/accessibility/common/accessibility.js';
import { OpenInEditorMenuButton } from './openInEditorMenuButton.js';

@@ -66,7 +65,6 @@ export interface ActionBarsProps {
export const ActionBars = (props: PropsWithChildren<ActionBarsProps>) => {
// Hooks.
const positronPlotsContext = usePositronPlotsContext();
const [useEditorPlots, setUseEditorPlots] = React.useState<boolean>(positronPlotsEditorEnabled(props.configurationService));

// Do we have any plots?
const noPlots = positronPlotsContext.positronPlotInstances.length === 0;
@@ -94,19 +92,10 @@ export const ActionBars = (props: PropsWithChildren<ActionBarsProps>) => {
const enablePopoutPlot = hasPlots &&
selectedPlot instanceof HtmlPlotClient;

const enableEditorPlot = hasPlots && useEditorPlots
const enableEditorPlot = hasPlots
&& (selectedPlot instanceof PlotClientInstance
|| selectedPlot instanceof StaticPlotClient);

useEffect(() => {
const disposable = props.configurationService.onDidChangeConfiguration((event: IConfigurationChangeEvent) => {
if (event.affectedKeys.has(POSITRON_EDITOR_PLOTS)) {
setUseEditorPlots(positronPlotsEditorEnabled(props.configurationService));
}
});
return () => disposable.dispose();
}, [props.configurationService]);

// Clear all the plots from the service.
const clearAllPlotsHandler = () => {
if (hasPlots) {
Original file line number Diff line number Diff line change
@@ -455,11 +455,11 @@ export class PlotsActiveEditorCopyAction extends Action2 {
category,
f1: false, // do not show in the command palette
icon: Codicon.copy,
precondition: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${POSITRON_EDITOR_PLOTS}`, true), PLOT_IS_ACTIVE_EDITOR),
precondition: PLOT_IS_ACTIVE_EDITOR,
menu: [
{
id: MenuId.EditorTitle,
when: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${POSITRON_EDITOR_PLOTS}`, true), PLOT_IS_ACTIVE_EDITOR),
when: PLOT_IS_ACTIVE_EDITOR,
group: 'navigation',
order: 2,
}
@@ -492,11 +492,11 @@ export class PlotsActiveEditorSaveAction extends Action2 {
category,
f1: false, // do not show in the command palette
icon: Codicon.positronSave,
precondition: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${POSITRON_EDITOR_PLOTS}`, true), PLOT_IS_ACTIVE_EDITOR),
precondition: PLOT_IS_ACTIVE_EDITOR,
menu: [
{
id: MenuId.EditorTitle,
when: ContextKeyExpr.and(ContextKeyExpr.equals(`config.${POSITRON_EDITOR_PLOTS}`, true), PLOT_IS_ACTIVE_EDITOR),
when: PLOT_IS_ACTIVE_EDITOR,
group: 'navigation',
order: 1,
}
Original file line number Diff line number Diff line change
@@ -6,14 +6,11 @@
import { Disposable } from '../../../../base/common/lifecycle.js';
import { Schemas } from '../../../../base/common/network.js';
import { localize } from '../../../../nls.js';
import { IConfigurationService } from '../../../../platform/configuration/common/configuration.js';
import { IConfigurationRegistry, Extensions as ConfigurationExtensions, ConfigurationScope } from '../../../../platform/configuration/common/configurationRegistry.js';
import { ContextKeyExpr } from '../../../../platform/contextkey/common/contextkey.js';
import { SyncDescriptor } from '../../../../platform/instantiation/common/descriptors.js';
import { IInstantiationService } from '../../../../platform/instantiation/common/instantiation.js';
import { Registry } from '../../../../platform/registry/common/platform.js';
import { EditorPaneDescriptor, IEditorPaneRegistry } from '../../../browser/editor.js';
import { applicationConfigurationNodeBase } from '../../../common/configuration.js';
import { registerWorkbenchContribution2, WorkbenchPhase } from '../../../common/contributions.js';
import { EditorExtensions } from '../../../common/editor.js';
import { PositronPlotsEditor } from './positronPlotsEditor.js';
@@ -79,22 +76,4 @@ registerWorkbenchContribution2(
WorkbenchPhase.AfterRestored
);

const configurationRegistry = Registry.as<IConfigurationRegistry>(ConfigurationExtensions.Configuration);
configurationRegistry.registerConfiguration({
...applicationConfigurationNodeBase,
properties: {
[POSITRON_EDITOR_PLOTS]: {
scope: ConfigurationScope.APPLICATION,
type: 'boolean',
default: false,
tags: ['experimental'],
description: localize('workbench.positronPlotsEditor.description', 'When enabled, plots can be opened in an editor tab.')
}
}
});

export function positronPlotsEditorEnabled(configurationService: IConfigurationService) {
return Boolean(configurationService.getValue(POSITRON_EDITOR_PLOTS));
}

export const PLOT_IS_ACTIVE_EDITOR = ContextKeyExpr.equals('activeEditor', PositronPlotsEditorInput.EditorID);

0 comments on commit 9ea950e

Please sign in to comment.