Skip to content
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

Remove plot in editor tab flag #6148

Merged
merged 1 commit into from
Jan 30, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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';

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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,
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);