-
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
Change open in editor tab to menu button #5733
base: main
Are you sure you want to change the base?
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 |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* 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; | ||
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 right') | ||
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 wonder if we could use similar verbiage to the File Explorer and hook into this preference: Or maybe the user will want "to the Side" for plots to be different than the File Explorer? Here's the context menu when right-clicking on a file in the File Explorer: |
||
}, | ||
]; | ||
|
||
/** | ||
* 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={localize('positron-editor-plot-popout', "Open in editor tab")} | ||
actions={() => actions} | ||
dropdownIndicator='enabled-split' /> | ||
); | ||
}; |
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.
I think we may have lost the ariaLabels on the
Open plot in [location]
elements