提交 425fb1ca 编写于 作者: R Rob Lourens

Notebook action cleanup, add more to f1

上级 a4f436bd
...@@ -32,7 +32,6 @@ const COPY_CELL_UP_COMMAND_ID = 'workbench.notebook.cell.copyUp'; ...@@ -32,7 +32,6 @@ const COPY_CELL_UP_COMMAND_ID = 'workbench.notebook.cell.copyUp';
const COPY_CELL_DOWN_COMMAND_ID = 'workbench.notebook.cell.copyDown'; const COPY_CELL_DOWN_COMMAND_ID = 'workbench.notebook.cell.copyDown';
const EXECUTE_CELL_COMMAND_ID = 'workbench.notebook.cell.execute'; const EXECUTE_CELL_COMMAND_ID = 'workbench.notebook.cell.execute';
const EXECUTE_ACTIVE_CELL_COMMAND_ID = 'workbench.notebook.cell.executeActive';
const CANCEL_CELL_COMMAND_ID = 'workbench.notebook.cell.cancelExecution'; const CANCEL_CELL_COMMAND_ID = 'workbench.notebook.cell.cancelExecution';
const EXECUTE_NOTEBOOK_COMMAND_ID = 'workbench.notebook.executeNotebook'; const EXECUTE_NOTEBOOK_COMMAND_ID = 'workbench.notebook.executeNotebook';
const CANCEL_NOTEBOOK_COMMAND_ID = 'workbench.notebook.cancelExecution'; const CANCEL_NOTEBOOK_COMMAND_ID = 'workbench.notebook.cancelExecution';
...@@ -70,7 +69,7 @@ registerAction2(class extends Action2 { ...@@ -70,7 +69,7 @@ registerAction2(class extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -85,13 +84,15 @@ registerAction2(class extends Action2 { ...@@ -85,13 +84,15 @@ registerAction2(class extends Action2 {
constructor() { constructor() {
super({ super({
id: CANCEL_CELL_COMMAND_ID, id: CANCEL_CELL_COMMAND_ID,
title: localize('notebookActions.cancel', "Stop Execution"), title: localize('notebookActions.cancel', "Stop Cell Execution"),
icon: { id: 'codicon/primitive-square' } category: NOTEBOOK_ACTIONS_CATEGORY,
icon: { id: 'codicon/primitive-square' },
f1: true
}); });
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -212,7 +213,9 @@ registerAction2(class extends Action2 { ...@@ -212,7 +213,9 @@ registerAction2(class extends Action2 {
constructor() { constructor() {
super({ super({
id: EXECUTE_NOTEBOOK_COMMAND_ID, id: EXECUTE_NOTEBOOK_COMMAND_ID,
title: localize('notebookActions.executeNotebook', "Execute Notebook") title: localize('notebookActions.executeNotebook', "Execute Notebook"),
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
...@@ -231,7 +234,9 @@ registerAction2(class extends Action2 { ...@@ -231,7 +234,9 @@ registerAction2(class extends Action2 {
constructor() { constructor() {
super({ super({
id: CANCEL_NOTEBOOK_COMMAND_ID, id: CANCEL_NOTEBOOK_COMMAND_ID,
title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution") title: localize('notebookActions.cancelNotebook', "Cancel Notebook Execution"),
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
...@@ -246,29 +251,6 @@ registerAction2(class extends Action2 { ...@@ -246,29 +251,6 @@ registerAction2(class extends Action2 {
} }
}); });
registerAction2(class extends Action2 {
constructor() {
super({
id: EXECUTE_ACTIVE_CELL_COMMAND_ID,
title: localize('notebookActions.executeNotebookCell', "Execute Notebook Active Cell")
});
}
async run(accessor: ServicesAccessor): Promise<void> {
let editorService = accessor.get(IEditorService);
let editor = getActiveNotebookEditor(editorService);
if (!editor) {
return;
}
let activeCell = editor.getActiveCell();
if (activeCell) {
return editor.executeNotebookCell(activeCell);
}
}
});
registerAction2(class extends Action2 { registerAction2(class extends Action2 {
constructor() { constructor() {
super({ super({
...@@ -368,7 +350,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, { ...@@ -368,7 +350,7 @@ MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
MenuRegistry.appendMenuItem(MenuId.EditorTitle, { MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: { command: {
id: EXECUTE_ACTIVE_CELL_COMMAND_ID, id: EXECUTE_CELL_COMMAND_ID,
title: localize('notebookActions.menu.execute', "Execute Notebook Cell"), title: localize('notebookActions.menu.execute', "Execute Notebook Cell"),
icon: { id: 'codicon/run' } icon: { id: 'codicon/run' }
}, },
...@@ -386,7 +368,9 @@ registerAction2(class extends Action2 { ...@@ -386,7 +368,9 @@ registerAction2(class extends Action2 {
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)), when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
primary: KeyCode.KEY_Y, primary: KeyCode.KEY_Y,
weight: KeybindingWeight.WorkbenchContrib weight: KeybindingWeight.WorkbenchContrib
} },
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
...@@ -404,7 +388,9 @@ registerAction2(class extends Action2 { ...@@ -404,7 +388,9 @@ registerAction2(class extends Action2 {
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)), when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, ContextKeyExpr.not(InputFocusedContextKey)),
primary: KeyCode.KEY_M, primary: KeyCode.KEY_M,
weight: KeybindingWeight.WorkbenchContrib weight: KeybindingWeight.WorkbenchContrib
} },
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
...@@ -481,6 +467,10 @@ export interface INotebookCellActionContext { ...@@ -481,6 +467,10 @@ export interface INotebookCellActionContext {
notebookEditor: INotebookEditor; notebookEditor: INotebookEditor;
} }
function isCellActionContext(context: any): context is INotebookCellActionContext {
return context && !!context.cell && !!context.notebookEditor;
}
function getActiveCellContext(accessor: ServicesAccessor): INotebookCellActionContext | undefined { function getActiveCellContext(accessor: ServicesAccessor): INotebookCellActionContext | undefined {
const editorService = accessor.get(IEditorService); const editorService = accessor.get(IEditorService);
...@@ -510,7 +500,7 @@ abstract class InsertCellCommand extends Action2 { ...@@ -510,7 +500,7 @@ abstract class InsertCellCommand extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -641,7 +631,7 @@ registerAction2(class extends Action2 { ...@@ -641,7 +631,7 @@ registerAction2(class extends Action2 {
} }
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -671,7 +661,7 @@ registerAction2(class extends Action2 { ...@@ -671,7 +661,7 @@ registerAction2(class extends Action2 {
} }
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -709,7 +699,7 @@ registerAction2(class extends Action2 { ...@@ -709,7 +699,7 @@ registerAction2(class extends Action2 {
} }
run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -755,7 +745,7 @@ registerAction2(class extends Action2 { ...@@ -755,7 +745,7 @@ registerAction2(class extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -789,7 +779,7 @@ registerAction2(class extends Action2 { ...@@ -789,7 +779,7 @@ registerAction2(class extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -805,12 +795,14 @@ registerAction2(class extends Action2 { ...@@ -805,12 +795,14 @@ registerAction2(class extends Action2 {
super( super(
{ {
id: COPY_CELL_UP_COMMAND_ID, id: COPY_CELL_UP_COMMAND_ID,
title: localize('notebookActions.copyCellUp', "Copy Cell Up") title: localize('notebookActions.copyCellUp', "Copy Cell Up"),
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -826,12 +818,14 @@ registerAction2(class extends Action2 { ...@@ -826,12 +818,14 @@ registerAction2(class extends Action2 {
super( super(
{ {
id: COPY_CELL_DOWN_COMMAND_ID, id: COPY_CELL_DOWN_COMMAND_ID,
title: localize('notebookActions.copyCellDown', "Copy Cell Down") title: localize('notebookActions.copyCellDown', "Copy Cell Down"),
category: NOTEBOOK_ACTIONS_CATEGORY,
f1: true
}); });
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext) {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -856,7 +850,7 @@ registerAction2(class extends Action2 { ...@@ -856,7 +850,7 @@ registerAction2(class extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
...@@ -895,7 +889,7 @@ registerAction2(class extends Action2 { ...@@ -895,7 +889,7 @@ registerAction2(class extends Action2 {
} }
async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> { async run(accessor: ServicesAccessor, context?: INotebookCellActionContext): Promise<void> {
if (!context) { if (!isCellActionContext(context)) {
context = getActiveCellContext(accessor); context = getActiveCellContext(accessor);
if (!context) { if (!context) {
return; return;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册