-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change open in editor tab to menu button (#5733)
- Loading branch information
Showing
6 changed files
with
146 additions
and
24 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
87 changes: 87 additions & 0 deletions
87
src/vs/workbench/contrib/positronPlots/browser/components/openInEditorMenuButton.tsx
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,87 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (C) 2024 Posit Software, PBC. All rights reserved. | ||
* Licensed under the Elastic License 2.0. See LICENSE.txt for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import React, { useState, useCallback, useEffect } from 'react'; | ||
|
||
import { IAction } from '../../../../../base/common/actions.js'; | ||
import { localize } from '../../../../../nls.js'; | ||
import { ICommandService } from '../../../../../platform/commands/common/commands.js'; | ||
import { ActionBarMenuButton } from '../../../../../platform/positronActionBar/browser/components/actionBarMenuButton.js'; | ||
import { AUX_WINDOW_GROUP_TYPE, ACTIVE_GROUP_TYPE, SIDE_GROUP_TYPE, AUX_WINDOW_GROUP, ACTIVE_GROUP, SIDE_GROUP } from '../../../../services/editor/common/editorService.js'; | ||
import { PlotsEditorAction } from '../positronPlotsActions.js'; | ||
|
||
interface OpenInEditorMenuButtonProps { | ||
tooltip: string; | ||
ariaLabel: string; | ||
defaultGroup: number; | ||
commandService: ICommandService; | ||
} | ||
|
||
interface OpenInEditorCommand { | ||
editorTarget: AUX_WINDOW_GROUP_TYPE | ACTIVE_GROUP_TYPE | SIDE_GROUP_TYPE; | ||
label: string; | ||
} | ||
|
||
// create an array of action ids with labels | ||
const openInEditorCommands: Array<OpenInEditorCommand> = [ | ||
{ | ||
'editorTarget': AUX_WINDOW_GROUP, | ||
'label': localize('positron-editor-new-window', 'Open in new window') | ||
}, | ||
{ | ||
'editorTarget': ACTIVE_GROUP, | ||
'label': localize('positron-editor-new-tab', 'Open in editor tab') | ||
}, | ||
{ | ||
'editorTarget': SIDE_GROUP, | ||
'label': localize('positron-editor-new-tab-right', 'Open in editor tab to the Side') | ||
}, | ||
]; | ||
|
||
/** | ||
* OpenInEditorMenuButton component. | ||
* | ||
* Creates a menu button that allows the user to open a plot in a new editor tab. Choosing a menu | ||
* action will update the default action. The default action is preserved by the plots service when | ||
* opening the editor tab succeeds. | ||
* | ||
* @param props An OpenInEditorMenuButtonProps that contains the component properties. | ||
* @returns | ||
*/ | ||
export const OpenInEditorMenuButton = (props: OpenInEditorMenuButtonProps) => { | ||
const [defaultAction, setDefaultEditorAction] = useState<number>(props.defaultGroup); | ||
const [actions, setActions] = useState<readonly IAction[]>([]); | ||
|
||
const openEditorPlotHandler = useCallback((groupType: number) => { | ||
// props.plotsService.openEditor(groupType); | ||
props.commandService.executeCommand(PlotsEditorAction.ID, groupType); | ||
setDefaultEditorAction(groupType); | ||
}, [props.commandService]); | ||
|
||
useEffect(() => { | ||
const actions = openInEditorCommands.map((command) => { | ||
return { | ||
id: PlotsEditorAction.ID, | ||
label: command.label, | ||
tooltip: '', | ||
class: undefined, | ||
checked: defaultAction === command.editorTarget, | ||
enabled: true, | ||
run: () => openEditorPlotHandler(command.editorTarget) | ||
}; | ||
}); | ||
setActions(actions); | ||
}, [defaultAction]); | ||
|
||
|
||
return ( | ||
<ActionBarMenuButton | ||
iconId='go-to-file' | ||
tooltip={props.tooltip} | ||
ariaLabel={props.ariaLabel} | ||
actions={() => actions} | ||
dropdownIndicator='enabled-split' /> | ||
); | ||
}; |
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