Skip to content
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
1 change: 1 addition & 0 deletions news/1 Enhancements/7800.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add command palette commands for native editor (run all cells, run selected cell, add new cell). And remove interactive window commands from contexts where they don't apply.
59 changes: 55 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@
},
{
"command": "python.datascience.notebookeditor.removeallcells",
"title": "%python.command.python.datascience.removeallcells.title%",
"title": "%python.command.python.datascience.notebookeditor.removeallcells.title%",
"category": "Python"
},
{
Expand All @@ -524,6 +524,21 @@
"title": "%python.command.python.datascience.restartkernel.title%",
"category": "Python"
},
{
"command": "python.datascience.notebookeditor.runallcells",
"title": "%python.command.python.datascience.notebookeditor.runallcells.title%",
"category": "Python"
},
{
"command": "python.datascience.notebookeditor.runselectedcell",
"title": "%python.command.python.datascience.notebookeditor.runselectedcell.title%",
"category": "Python"
},
{
"command": "python.datascience.notebookeditor.addcellbelow",
"title": "%python.command.python.datascience.notebookeditor.addcellbelow.title%",
"category": "Python"
},
{
"command": "python.datascience.expandallcells",
"title": "%python.command.python.datascience.expandallcells.title%",
Expand Down Expand Up @@ -778,7 +793,25 @@
"command": "python.datascience.runallcells",
"title": "%python.command.python.datascience.runallcells.title%",
"category": "Python",
"when": "python.datascience.featureenabled"
"when": "python.datascience.hascodecells && python.datascience.featureenabled"
},
{
"command": "python.datascience.scrolltocell",
"title": "%python.command.python.datascience.scrolltocell.title%",
"category": "Python",
"when": "false"
},
{
"command": "python.datascience.debugcell",
"title": "%python.command.python.datascience.debugcell.title%",
"category": "Python",
"when": "python.datascience.hascodecells && python.datascience.featureenabled"
},
{
"command": "python.datascience.runcell",
"title": "%python.command.python.datascience.runcell.title%",
"category": "Python",
"when": "python.datascience.hascodecells && python.datascience.featureenabled"
},
{
"command": "python.datascience.runFileInteractive",
Expand Down Expand Up @@ -858,7 +891,7 @@
},
{
"command": "python.datascience.notebookeditor.removeallcells",
"title": "%python.command.python.datascience.removeallcells.title%",
"title": "%python.command.python.datascience.notebookeditor.removeallcells.title%",
"category": "Python",
"when": "python.datascience.havenativecells && python.datascience.featureenabled"
},
Expand All @@ -874,6 +907,24 @@
"category": "Python",
"when": "python.datascience.havenative && python.datascience.featureenabled"
},
{
"command": "python.datascience.notebookeditor.runallcells",
"title": "%python.command.python.datascience.notebookeditor.runallcells.title%",
"category": "Python",
"when": "python.datascience.havenative && python.datascience.featureenabled"
},
{
"command": "python.datascience.notebookeditor.runselectedcell",
Copy link

@rchiodo rchiodo Oct 7, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runselectedcell [](start = 66, length = 15)

Does this need a check to see if there is a selected cell? #Resolved

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it doesn't really do anything without that. I'll add it into the send info and have a context for it.


In reply to: 332283220 [](ancestors = 332283220)

"title": "%python.command.python.datascience.notebookeditor.runselectedcell.title%",
"category": "Python",
"when": "python.datascience.havenative && python.datascience.featureenabled && python.datascience.havecellselected"
},
{
"command": "python.datascience.notebookeditor.addcellbelow",
"title": "%python.command.python.datascience.notebookeditor.addcellbelow.title%",
"category": "Python",
"when": "python.datascience.havenative && python.datascience.featureenabled"
},
{
"command": "python.datascience.expandallcells",
"title": "%python.command.python.datascience.expandallcells.title%",
Expand Down Expand Up @@ -906,7 +957,7 @@
"command": "python.datascience.addcellbelow",
"title": "%python.command.python.datascience.addcellbelow.title%",
"category": "Python",
"when": "python.datascience.featureenabled"
"when": "python.datascience.hascodecells && python.datascience.featureenabled"
},
{
"command": "python.datascience.createnewnotebook",
Expand Down
4 changes: 4 additions & 0 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
"python.command.python.datascience.runFileInteractive.title": "Run Current File in Python Interactive Window",
"python.command.python.datascience.debugFileInteractive.title": "Debug Current File in Python Interactive Window",
"python.command.python.datascience.runallcells.title": "Run All Cells",
"python.command.python.datascience.notebookeditor.runallcells.title": "Run All Notebook Cells",
"python.command.python.datascience.runallcellsabove.title": "Run Above",
"python.command.python.datascience.runcellandallbelow.title": "Run Below",
"python.command.python.datascience.runallcellsabove.palette.title": "Run Cells Above Current Cell",
Expand Down Expand Up @@ -60,6 +61,9 @@
"python.command.python.datascience.undocells.title": "Undo Last Python Interactive Action",
"python.command.python.datascience.redocells.title": "Redo Last Python Interactive Action",
"python.command.python.datascience.removeallcells.title": "Delete All Python Interactive Cells",
"python.command.python.datascience.notebookeditor.removeallcells.title": "Delete All Notebook Editor Cells",
"python.command.python.datascience.notebookeditor.runselectedcell.title": "Run Selected Notebook Cell",
"python.command.python.datascience.notebookeditor.addcellbelow.title": "Add Empty Cell to Notebook File",
"python.command.python.datascience.interruptkernel.title": "Interrupt IPython Kernel",
"python.command.python.datascience.restartkernel.title": "Restart IPython Kernel",
"python.command.python.datascience.expandallcells.title": "Expand All Python Interactive Cells",
Expand Down
3 changes: 3 additions & 0 deletions src/client/common/application/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ interface ICommandNameWithoutArgumentTypeMapping {
[DSCommands.NotebookEditorRemoveAllCells]: [];
[DSCommands.NotebookEditorInterruptKernel]: [];
[DSCommands.NotebookEditorRestartKernel]: [];
[DSCommands.NotebookEditorRunAllCells]: [];
[DSCommands.NotebookEditorRunSelectedCell]: [];
[DSCommands.NotebookEditorAddCellBelow]: [];
[DSCommands.ExpandAllCells]: [];
[DSCommands.CollapseAllCells]: [];
[DSCommands.ExportOutputAsNotebook]: [];
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export namespace Commands {
export const NotebookEditorRemoveAllCells = 'python.datascience.notebookeditor.removeallcells';
export const NotebookEditorInterruptKernel = 'python.datascience.notebookeditor.interruptkernel';
export const NotebookEditorRestartKernel = 'python.datascience.notebookeditor.restartkernel';
export const NotebookEditorRunAllCells = 'python.datascience.notebookeditor.runallcells';
export const NotebookEditorRunSelectedCell = 'python.datascience.notebookeditor.runselectedcell';
export const NotebookEditorAddCellBelow = 'python.datascience.notebookeditor.addcellbelow';
export const ExpandAllCells = 'python.datascience.expandallcells';
export const CollapseAllCells = 'python.datascience.collapseallcells';
export const ExportOutputAsNotebook = 'python.datascience.exportoutputasnotebook';
Expand Down Expand Up @@ -71,6 +74,7 @@ export namespace EditorContexts {
export const HaveNativeCells = 'python.datascience.havenativecells';
export const HaveNativeRedoableCells = 'python.datascience.havenativeredoablecells';
export const HaveNative = 'python.datascience.havenative';
export const HaveCellSelected = 'python.datascience.havecellselected';
}

export namespace RegExpValues {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export namespace InteractiveWindowMessages {
export const SaveAll = 'save_all';
export const NativeCommand = 'native_command';
export const VariablesComplete = 'variables_complete';

export const NotebookRunAllCells = 'notebook_run_all_cells';
export const NotebookRunSelectedCell = 'notebook_run_selected_cell';
export const NotebookAddCellBelow = 'notebook_add_cell_below';
}

export enum NativeCommandType {
Expand Down Expand Up @@ -318,4 +320,7 @@ export class IInteractiveWindowMapping {
public [InteractiveWindowMessages.SaveAll]: ISaveAll;
public [InteractiveWindowMessages.NativeCommand]: INativeCommand;
public [InteractiveWindowMessages.VariablesComplete]: never | undefined;
public [InteractiveWindowMessages.NotebookRunAllCells]: never | undefined;
public [InteractiveWindowMessages.NotebookRunSelectedCell]: never | undefined;
public [InteractiveWindowMessages.NotebookAddCellBelow]: never | undefined;
}
15 changes: 15 additions & 0 deletions src/client/datascience/interactive-ipynb/nativeEditor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,18 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
return this.ipynbProvider.getNotebookOptions();
}

public runAllCells() {
this.postMessage(InteractiveWindowMessages.NotebookRunAllCells).ignoreErrors();
}

public runSelectedCell() {
this.postMessage(InteractiveWindowMessages.NotebookRunSelectedCell).ignoreErrors();
}

public addCellBelow() {
this.postMessage(InteractiveWindowMessages.NotebookAddCellBelow).ignoreErrors();
}

protected async reopen(cells: ICell[]): Promise<void> {
try {
super.reload();
Expand Down Expand Up @@ -317,10 +329,13 @@ export class NativeEditor extends InteractiveBase implements INotebookEditor {
interactiveContext.set(!this.isDisposed).catch();
const interactiveCellsContext = new ContextKey(EditorContexts.HaveNativeCells, this.commandManager);
const redoableContext = new ContextKey(EditorContexts.HaveNativeRedoableCells, this.commandManager);
const hasCellSelectedContext = new ContextKey(EditorContexts.HaveCellSelected, this.commandManager);
if (info) {
interactiveCellsContext.set(info.cellCount > 0).catch();
redoableContext.set(info.redoCount > 0).catch();
hasCellSelectedContext.set(info.selectedCell ? true : false).catch();
} else {
hasCellSelectedContext.set(false).catch();
interactiveCellsContext.set(false).catch();
redoableContext.set(false).catch();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,30 @@ export class NativeEditorCommandListener implements IDataScienceCommandListener
this.disposableRegistry.push(commandManager.registerCommand(Commands.NotebookEditorInterruptKernel, () => this.interruptKernel()));
this.disposableRegistry.push(commandManager.registerCommand(Commands.NotebookEditorRestartKernel, () => this.restartKernel()));
this.disposableRegistry.push(commandManager.registerCommand(Commands.OpenNotebook, (file?: Uri, _cmdSource: CommandSource = CommandSource.commandPalette) => this.openNotebook(file)));
this.disposableRegistry.push(commandManager.registerCommand(Commands.NotebookEditorRunAllCells, () => this.runAllCells()));
this.disposableRegistry.push(commandManager.registerCommand(Commands.NotebookEditorRunSelectedCell, () => this.runSelectedCell()));
this.disposableRegistry.push(commandManager.registerCommand(Commands.NotebookEditorAddCellBelow, () => this.addCellBelow()));
}

private runAllCells() {
const activeEditor = this.provider.activeEditor;
if (activeEditor) {
activeEditor.runAllCells();
}
}

private runSelectedCell() {
const activeEditor = this.provider.activeEditor;
if (activeEditor) {
activeEditor.runSelectedCell();
}
}

private addCellBelow() {
const activeEditor = this.provider.activeEditor;
if (activeEditor) {
activeEditor.addCellBelow();
}
}

private undoCells() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,15 @@ export class InteractiveWindow extends InteractiveBase implements IInteractiveWi
interactiveContext.set(!this.isDisposed).catch();
const interactiveCellsContext = new ContextKey(EditorContexts.HaveInteractiveCells, this.commandManager);
const redoableContext = new ContextKey(EditorContexts.HaveRedoableCells, this.commandManager);
const hasCellSelectedContext = new ContextKey(EditorContexts.HaveCellSelected, this.commandManager);
if (info) {
interactiveCellsContext.set(info.cellCount > 0).catch();
redoableContext.set(info.redoCount > 0).catch();
hasCellSelectedContext.set(info.selectedCell ? true : false).catch();
} else {
interactiveCellsContext.set(false).catch();
redoableContext.set(false).catch();
hasCellSelectedContext.set(false).catch();
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/client/datascience/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ export interface INotebookEditor extends IInteractiveBase {
readonly visible: boolean;
readonly active: boolean;
load(contents: string, file: Uri): Promise<void>;
runAllCells(): void;
runSelectedCell(): void;
addCellBelow(): void;
}

export const IInteractiveWindowListener = Symbol('IInteractiveWindowListener');
Expand Down Expand Up @@ -347,6 +350,7 @@ export interface IInteractiveWindowInfo {
undoCount: number;
redoCount: number;
visibleCells: ICell[];
selectedCell: string | undefined;
}

export interface IMessageCell extends nbformat.IBaseCell {
Expand Down
3 changes: 2 additions & 1 deletion src/datascience-ui/interactive-common/mainStateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,8 @@ export class MainStateController implements IMessageHandler {
visibleCells: this.getNonEditCellVMs().map(cvm => cvm.cell),
cellCount: this.getNonEditCellVMs().length,
undoCount: this.pendingState.undoStack.length,
redoCount: this.pendingState.redoStack.length
redoCount: this.pendingState.redoStack.length,
selectedCell: this.pendingState.selectedCellId
};
this.sendMessage(InteractiveWindowMessages.SendInfo, info);
}
Expand Down
24 changes: 24 additions & 0 deletions src/datascience-ui/native-editor/nativeEditorStateController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,18 @@ export class NativeEditorStateController extends MainStateController {
this.waitingForLoadRender = true;
break;

case InteractiveWindowMessages.NotebookRunAllCells:
this.runAll();
break;

case InteractiveWindowMessages.NotebookRunSelectedCell:
this.runSelectedCell();
break;

case InteractiveWindowMessages.NotebookAddCellBelow:
this.addNewCell();
break;

default:
break;
}
Expand Down Expand Up @@ -76,6 +88,18 @@ export class NativeEditorStateController extends MainStateController {
return index > 0 && cells.find((cvm, i) => i >= index && cvm.cell.data.cell_type === 'code');
}

public runSelectedCell = () => {
const selectedCellId = this.getState().selectedCellId;

if (selectedCellId) {
const cells = this.getState().cellVMs;
const selectedCell = cells.find(cvm => cvm.cell.id === selectedCellId);
if (selectedCell) {
this.submitInput(concatMultilineString(selectedCell.cell.data.source), selectedCell);
}
}
}

public runAll = () => {
// Run all code cells (markdown don't need to be run)
this.suspendUpdates();
Expand Down