-
Notifications
You must be signed in to change notification settings - Fork 36.5k
Support toolbar in notebook outline pane entries #207498
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
Merged
Merged
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d50860b
relocate toggle action, fix toggle verbage, more generic section args
Yoyokrazy b96cde9
support toolbar in outline pane entries
Yoyokrazy 609dcd4
Merge branch 'main' into milively/outline-toolbar
Yoyokrazy 48bc2ce
unused imports slipped in with the merge
Yoyokrazy 8a8f3a3
css class name fix
Yoyokrazy 5f89e54
folding action support + css fix
Yoyokrazy 31d3b93
better typeguard fn
Yoyokrazy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
147 changes: 147 additions & 0 deletions
147
src/vs/workbench/contrib/notebook/browser/controller/sectionActions.ts
This file contains hidden or 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,147 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { localize, localize2 } from 'vs/nls'; | ||
| import { Action2, MenuId, registerAction2 } from 'vs/platform/actions/common/actions'; | ||
| import { ContextKeyExpr } from 'vs/platform/contextkey/common/contextkey'; | ||
| import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation'; | ||
| import { NotebookOutlineContext } from 'vs/workbench/contrib/notebook/browser/contrib/outline/notebookOutline'; | ||
| import { FoldingController } from 'vs/workbench/contrib/notebook/browser/controller/foldingController'; | ||
| import { CellFoldingState, INotebookEditor } from 'vs/workbench/contrib/notebook/browser/notebookBrowser'; | ||
| import * as icons from 'vs/workbench/contrib/notebook/browser/notebookIcons'; | ||
| import { OutlineEntry } from 'vs/workbench/contrib/notebook/browser/viewModel/OutlineEntry'; | ||
| import { MarkupCellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/markupCellViewModel'; | ||
|
|
||
| export type NotebookSectionArgs = { | ||
| notebookEditor: INotebookEditor | undefined; | ||
| outlineEntry: OutlineEntry; | ||
| }; | ||
|
|
||
| export class NotebookRunSingleCellInSection extends Action2 { | ||
| constructor() { | ||
| super({ | ||
| id: 'notebook.section.runSingleCell', | ||
| title: { | ||
| ...localize2('runCell', "Run Cell"), | ||
| mnemonicTitle: localize({ key: 'mirunCell', comment: ['&& denotes a mnemonic'] }, "&&Run Cell"), | ||
| }, | ||
| shortTitle: localize('runCell', "Run Cell"), | ||
| icon: icons.executeIcon, | ||
| menu: [ | ||
| { | ||
| id: MenuId.NotebookOutlineActionMenu, | ||
| group: 'inline', | ||
| order: 1, | ||
| when: ContextKeyExpr.and( | ||
| NotebookOutlineContext.CellKind.isEqualTo('code'), | ||
| NotebookOutlineContext.OutlineElementTarget.isEqualTo('outline'), | ||
| NotebookOutlineContext.CellHasChildren.toNegated(), | ||
| NotebookOutlineContext.CellHasHeader.toNegated(), | ||
| ) | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| override async run(_accessor: ServicesAccessor, context: NotebookSectionArgs): Promise<void> { | ||
| context.notebookEditor?.executeNotebookCells([context.outlineEntry.cell]); | ||
| } | ||
| } | ||
|
|
||
| export class NotebookRunCellsInSection extends Action2 { | ||
| constructor() { | ||
| super({ | ||
| id: 'notebook.section.runCells', | ||
| title: { | ||
| ...localize2('runCellsInSection', "Run Cells In Section"), | ||
| mnemonicTitle: localize({ key: 'mirunCellsInSection', comment: ['&& denotes a mnemonic'] }, "&&Run Cells In Section"), | ||
| }, | ||
| shortTitle: localize('runCellsInSection', "Run Cells In Section"), | ||
| // icon: icons.executeBelowIcon, // TODO @Yoyokrazy replace this with new icon later | ||
| menu: [ | ||
| { | ||
| id: MenuId.NotebookStickyScrollContext, | ||
| group: 'notebookExecution', | ||
| order: 1 | ||
| }, | ||
| { | ||
| id: MenuId.NotebookOutlineActionMenu, | ||
| group: 'inline', | ||
| order: 1, | ||
| when: ContextKeyExpr.and( | ||
| NotebookOutlineContext.CellKind.isEqualTo('markdown'), | ||
| NotebookOutlineContext.OutlineElementTarget.isEqualTo('outline'), | ||
| NotebookOutlineContext.CellHasChildren, | ||
| NotebookOutlineContext.CellHasHeader, | ||
| ) | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| override async run(_accessor: ServicesAccessor, context: NotebookSectionArgs): Promise<void> { | ||
| const cell = context.outlineEntry.cell; | ||
|
|
||
| const idx = context.notebookEditor?.getViewModel()?.getCellIndex(cell); | ||
| if (idx === undefined) { | ||
| return; | ||
| } | ||
| const length = context.notebookEditor?.getViewModel()?.getFoldedLength(idx); | ||
| if (length === undefined) { | ||
| return; | ||
| } | ||
|
|
||
| const cells = context.notebookEditor?.getCellsInRange({ start: idx, end: idx + length + 1 }); | ||
| context.notebookEditor?.executeNotebookCells(cells); | ||
| } | ||
| } | ||
|
|
||
| export class NotebookToggleFoldingSection extends Action2 { | ||
| constructor() { | ||
| super({ | ||
| id: 'notebook.section.foldSection', | ||
| title: { | ||
| ...localize2('foldSection', "Fold Section"), | ||
| mnemonicTitle: localize({ key: 'mifoldSection', comment: ['&& denotes a mnemonic'] }, "&&Fold Section"), | ||
| }, | ||
| shortTitle: localize('foldSection', "Fold Section"), | ||
| menu: [ | ||
| { | ||
| id: MenuId.NotebookOutlineActionMenu, | ||
| group: 'notebookFolding', | ||
| order: 2, | ||
| when: ContextKeyExpr.and( | ||
| NotebookOutlineContext.CellKind.isEqualTo('markdown'), | ||
| NotebookOutlineContext.OutlineElementTarget.isEqualTo('outline'), | ||
| NotebookOutlineContext.CellHasChildren, | ||
| NotebookOutlineContext.CellHasHeader, | ||
| ) | ||
| } | ||
| ] | ||
| }); | ||
| } | ||
|
|
||
| override async run(_accessor: ServicesAccessor, context: NotebookSectionArgs): Promise<void> { | ||
| if (context.notebookEditor) { | ||
| this.toggleFoldRange(context.outlineEntry, context.notebookEditor); | ||
| } | ||
| } | ||
|
|
||
| private toggleFoldRange(entry: OutlineEntry, notebookEditor: INotebookEditor) { | ||
| const foldingController = notebookEditor.getContribution<FoldingController>(FoldingController.id); | ||
| const currentState = (entry.cell as MarkupCellViewModel).foldingState; | ||
|
|
||
| const index = entry.index; | ||
| const headerLevel = entry.level; | ||
| const newFoldingState = (currentState === CellFoldingState.Collapsed) ? CellFoldingState.Expanded : CellFoldingState.Collapsed; | ||
|
|
||
| foldingController.setFoldingStateUp(index, newFoldingState, headerLevel); | ||
| } | ||
|
|
||
| } | ||
|
|
||
| registerAction2(NotebookRunSingleCellInSection); | ||
| registerAction2(NotebookRunCellsInSection); | ||
| registerAction2(NotebookToggleFoldingSection); | ||
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.