Skip to content

Commit

Permalink
Merge pull request microsoft#92984 from microsoft/roblou/runButton
Browse files Browse the repository at this point in the history
Add run button and progress bar to cells
  • Loading branch information
rebornix authored Mar 20, 2020
2 parents a67cde2 + edaee26 commit a7e8704
Show file tree
Hide file tree
Showing 9 changed files with 147 additions and 89 deletions.
4 changes: 2 additions & 2 deletions src/vs/workbench/api/browser/mainThreadNotebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -250,11 +250,11 @@ export class MainThreadNotebookController implements IMainNotebookController {
return false;
}

executeNotebookActiveCell(uri: URI): void {
async executeNotebookActiveCell(uri: URI): Promise<void> {
let mainthreadNotebook = this._mapping.get(URI.from(uri).toString());

if (mainthreadNotebook && mainthreadNotebook.textModel.activeCell) {
this._proxy.$executeNotebook(this._viewType, uri, mainthreadNotebook.textModel.activeCell.handle);
return this._proxy.$executeNotebook(this._viewType, uri, mainthreadNotebook.textModel.activeCell.handle);
}
}

Expand Down
1 change: 1 addition & 0 deletions src/vs/workbench/contrib/notebook/browser/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const CELL_MARGIN = 32;
export const EDITOR_TOP_PADDING = 8;
export const EDITOR_BOTTOM_PADDING = 8;
export const EDITOR_TOOLBAR_HEIGHT = 22;
export const RUN_BUTTON_WIDTH = 20;

// Context Keys
export const NOTEBOOK_CELL_TYPE_CONTEXT_KEY = 'notebookCellType';
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ import { ContextKeyExpr, IContextKeyService } from 'vs/platform/contextkey/commo
import { InputFocusedContext, InputFocusedContextKey, IsDevelopmentContext } from 'vs/platform/contextkey/common/contextkeys';
import { ServicesAccessor } from 'vs/platform/instantiation/common/instantiation';
import { KeybindingWeight } from 'vs/platform/keybinding/common/keybindingsRegistry';
import { DELETE_CELL_COMMAND_ID, EDIT_CELL_COMMAND_ID, INSERT_CODE_CELL_ABOVE_COMMAND_ID, INSERT_CODE_CELL_BELOW_COMMAND_ID, INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID, INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID, MOVE_CELL_DOWN_COMMAND_ID, MOVE_CELL_UP_COMMAND_ID, SAVE_CELL_COMMAND_ID, COPY_CELL_UP_COMMAND_ID, COPY_CELL_DOWN_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/constants';
import { INotebookEditor, KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED, NOTEBOOK_EDITOR_FOCUSED, ICellViewModel, CellState } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { COPY_CELL_DOWN_COMMAND_ID, COPY_CELL_UP_COMMAND_ID, DELETE_CELL_COMMAND_ID, EDIT_CELL_COMMAND_ID, EXECUTE_CELL_COMMAND_ID, INSERT_CODE_CELL_ABOVE_COMMAND_ID, INSERT_CODE_CELL_BELOW_COMMAND_ID, INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID, INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID, MOVE_CELL_DOWN_COMMAND_ID, MOVE_CELL_UP_COMMAND_ID, SAVE_CELL_COMMAND_ID } from 'vs/workbench/contrib/notebook/browser/constants';
import { CellRenderTemplate, CellState, ICellViewModel, INotebookEditor, KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED, NOTEBOOK_EDITOR_FOCUSED } from 'vs/workbench/contrib/notebook/browser/notebookBrowser';
import { INotebookService } from 'vs/workbench/contrib/notebook/browser/notebookService';
import { CellKind, NOTEBOOK_EDITOR_CURSOR_BOUNDARY } from 'vs/workbench/contrib/notebook/common/notebookCommon';
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';

registerAction2(class extends Action2 {
constructor() {
super({
id: 'workbench.action.executeNotebookCell',
id: EXECUTE_CELL_COMMAND_ID,
title: localize('notebookActions.execute', "Execute Notebook Cell"),
keybinding: {
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, InputFocusedContext),
Expand All @@ -33,11 +33,36 @@ registerAction2(class extends Action2 {
});
}

async run(accessor: ServicesAccessor): Promise<void> {
runActiveCell(accessor);
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) {
context = getActiveCellContext(accessor);
if (!context) {
return;
}
}

runCell(accessor, context);
}
});

export class ExecuteCellAction extends MenuItemAction {
constructor(
@IContextKeyService contextKeyService: IContextKeyService,
@ICommandService commandService: ICommandService
) {
super(
{
id: EXECUTE_CELL_COMMAND_ID,
title: localize('notebookActions.executeCell', "Execute Cell"),
icon: { id: 'codicon/play' }
},
undefined,
{ shouldForwardArgs: true },
contextKeyService,
commandService);
}
}

registerAction2(class extends Action2 {
constructor() {
super({
Expand All @@ -53,7 +78,7 @@ registerAction2(class extends Action2 {

async run(accessor: ServicesAccessor): Promise<void> {
const editorService = accessor.get(IEditorService);
const activeCell = runActiveCell(accessor);
const activeCell = await runActiveCell(accessor);
if (!activeCell) {
return;
}
Expand Down Expand Up @@ -93,7 +118,7 @@ registerAction2(class extends Action2 {

async run(accessor: ServicesAccessor): Promise<void> {
const editorService = accessor.get(IEditorService);
const activeCell = runActiveCell(accessor);
const activeCell = await runActiveCell(accessor);
if (!activeCell) {
return;
}
Expand Down Expand Up @@ -273,7 +298,7 @@ function getActiveNotebookEditor(editorService: IEditorService): INotebookEditor
return activeEditorPane?.isNotebookEditor ? activeEditorPane : undefined;
}

function runActiveCell(accessor: ServicesAccessor): ICellViewModel | undefined {
async function runActiveCell(accessor: ServicesAccessor): Promise<ICellViewModel | undefined> {
const editorService = accessor.get(IEditorService);
const notebookService = accessor.get(INotebookService);

Expand Down Expand Up @@ -303,11 +328,41 @@ function runActiveCell(accessor: ServicesAccessor): ICellViewModel | undefined {
}

const viewType = notebookProviders[0].id;
notebookService.executeNotebookActiveCell(viewType, resource);
await notebookService.executeNotebookActiveCell(viewType, resource);

return activeCell;
}

async function runCell(accessor: ServicesAccessor, context: INotebookCellActionContext): Promise<void> {
const progress = context.cellTemplate!.progressBar!;
progress.infinite().show(500);

const editorService = accessor.get(IEditorService);
const notebookService = accessor.get(INotebookService);

const resource = editorService.activeEditor?.resource;
if (!resource) {
return;
}

const editor = getActiveNotebookEditor(editorService);
if (!editor) {
return;
}

const notebookProviders = notebookService.getContributedNotebookProviders(resource);
if (!notebookProviders.length) {
return;
}

// Need to make active, maybe TODO
editor.focusNotebookCell(context.cell, false);

const viewType = notebookProviders[0].id;
await notebookService.executeNotebookActiveCell(viewType, resource);
progress.hide();
}

async function changeActiveCellToKind(kind: CellKind, accessor: ServicesAccessor): Promise<void> {
const editorService = accessor.get(IEditorService);
const editor = getActiveNotebookEditor(editorService);
Expand Down Expand Up @@ -341,6 +396,7 @@ async function changeActiveCellToKind(kind: CellKind, accessor: ServicesAccessor
}

export interface INotebookCellActionContext {
cellTemplate?: CellRenderTemplate;
cell: ICellViewModel;
notebookEditor: INotebookEditor;
}
Expand Down
24 changes: 23 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebook.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
position: relative;
}

.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row .cell {
display: flex;
}

.monaco-workbench .part.editor > .content .notebook-editor .notebook-content-widgets {
position: absolute;
top: 0;
Expand Down Expand Up @@ -122,11 +126,29 @@
cursor: pointer;
}

.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row .monaco-toolbar {
.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row > .monaco-toolbar {
visibility: hidden;
margin-right: 24px;
}

.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row .cell .run-button-container .monaco-toolbar {
margin-top: 8px;
visibility: hidden;
}

.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row:hover .cell .run-button-container .monaco-toolbar,
.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row.focused .cell .run-button-container .monaco-toolbar {
visibility: visible;
}

.monaco-workbench .part.editor > .content .notebook-editor .cell .cell-editor-container {
position: relative;
}

.monaco-workbench .part.editor > .content .notebook-editor .cell .monaco-progress-container {
top: 0px;
}

.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row.focused .monaco-toolbar,
.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row:hover .monaco-toolbar {
visibility: visible;
Expand Down
5 changes: 4 additions & 1 deletion src/vs/workbench/contrib/notebook/browser/notebookBrowser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Range } from 'vs/editor/common/core/range';
import { ToolBar } from 'vs/base/browser/ui/toolbar/toolbar';
import { DisposableStore } from 'vs/base/common/lifecycle';
import { URI } from 'vs/base/common/uri';
import { ProgressBar } from 'vs/base/browser/ui/progressbar/progressbar';

export const KEYBINDING_CONTEXT_NOTEBOOK_FIND_WIDGET_FOCUSED = new RawContextKey<boolean>('notebookFindWidgetFocused', false);

Expand Down Expand Up @@ -202,12 +203,14 @@ export interface INotebookEditor {
export interface CellRenderTemplate {
container: HTMLElement;
cellContainer: HTMLElement;
menuContainer?: HTMLElement;
editorContainer?: HTMLElement;
toolbar: ToolBar;
focusIndicator?: HTMLElement;
runToolbar?: ToolBar;
editingContainer?: HTMLElement;
outputContainer?: HTMLElement;
editor?: CodeEditorWidget;
progressBar?: ProgressBar;
disposables: DisposableStore;
}

Expand Down
12 changes: 7 additions & 5 deletions src/vs/workbench/contrib/notebook/browser/notebookEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { NotebookViewModel, INotebookEditorViewState, IModelDecorationsChangeAcc
import { IEditorGroupView } from 'vs/workbench/browser/parts/editor/editor';
import { CellViewModel } from 'vs/workbench/contrib/notebook/browser/viewModel/notebookCellViewModel';
import { Range } from 'vs/editor/common/core/range';
import { CELL_MARGIN } from 'vs/workbench/contrib/notebook/browser/constants';
import { CELL_MARGIN, RUN_BUTTON_WIDTH } from 'vs/workbench/contrib/notebook/browser/constants';
import { Color, RGBA } from 'vs/base/common/color';

const $ = DOM.$;
Expand Down Expand Up @@ -732,12 +732,12 @@ registerThemingParticipant((theme, collector) => {
}
const link = theme.getColor(textLinkForeground);
if (link) {
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .cell a { color: ${link}; }`);
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .cell .output a { color: ${link}; }`);
}
const activeLink = theme.getColor(textLinkActiveForeground);
if (activeLink) {
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .cell a:hover,
.monaco-workbench .part.editor > .content .notebook-editor .cell a:active { color: ${activeLink}; }`);
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .cell .output a:hover,
.monaco-workbench .part.editor > .content .notebook-editor .cell .output a:active { color: ${activeLink}; }`);
}
const shortcut = theme.getColor(textPreformatForeground);
if (shortcut) {
Expand Down Expand Up @@ -771,5 +771,7 @@ registerThemingParticipant((theme, collector) => {

// Cell Margin
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .monaco-list-row > div.cell { padding: 8px ${CELL_MARGIN}px 8px ${CELL_MARGIN}px; }`);
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .output { margin: 8px ${CELL_MARGIN}px; }`);
collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .output { margin: 8px ${CELL_MARGIN}px 8px ${CELL_MARGIN + RUN_BUTTON_WIDTH}px }`);

collector.addRule(`.monaco-workbench .part.editor > .content .notebook-editor .cell .cell-editor-container { width: calc(100% - ${RUN_BUTTON_WIDTH}px); }`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface IMainNotebookController {
updateNotebookActiveCell(uri: URI, cellHandle: number): void;
createRawCell(uri: URI, index: number, language: string, type: CellKind): Promise<NotebookCellTextModel | undefined>;
deleteCell(uri: URI, index: number): Promise<boolean>
executeNotebookActiveCell(uri: URI): void;
executeNotebookActiveCell(uri: URI): Promise<void>;
onDidReceiveMessage(uri: URI, message: any): void;
destoryNotebookDocument(notebook: INotebookTextModel): Promise<void>;
save(uri: URI): Promise<boolean>;
Expand Down
Loading

0 comments on commit a7e8704

Please sign in to comment.