Skip to content

Commit

Permalink
Add "insert cell" submenu
Browse files Browse the repository at this point in the history
  • Loading branch information
roblourens committed Aug 12, 2020
1 parent fe4d4f7 commit 2c5cae3
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/vs/platform/actions/common/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ export class MenuId {
static readonly CommentTitle = new MenuId('CommentTitle');
static readonly CommentActions = new MenuId('CommentActions');
static readonly NotebookCellTitle = new MenuId('NotebookCellTitle');
static readonly NotebookCellInsert = new MenuId('NotebookCellInsert');
static readonly NotebookCellBetween = new MenuId('NotebookCellBetween');
static readonly BulkEditTitle = new MenuId('BulkEditTitle');
static readonly BulkEditContext = new MenuId('BulkEditContext');
Expand Down
49 changes: 39 additions & 10 deletions src/vs/workbench/contrib/notebook/browser/contrib/coreActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ const enum CellToolbarOrder {
DeleteCell
}

const enum CellOverflowToolbarGroups {
Copy = '1_copy',
Insert = '2_insert',
Edit = '3_edit',
Collapse = '4_collapse',
}

export interface INotebookActionContext {
readonly cellTemplate?: BaseCellRenderTemplate;
readonly cell?: ICellViewModel;
Expand Down Expand Up @@ -373,6 +380,12 @@ registerAction2(class extends NotebookAction {
}
});

MenuRegistry.appendMenuItem(MenuId.NotebookCellTitle, {
submenu: MenuId.NotebookCellInsert,
title: localize('notebookMenu.insertCell', "Insert Cell"),
group: CellOverflowToolbarGroups.Insert
});

MenuRegistry.appendMenuItem(MenuId.EditorTitle, {
command: {
id: EXECUTE_NOTEBOOK_COMMAND_ID,
Expand Down Expand Up @@ -409,7 +422,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_TYPE.isEqualTo('markdown')),
group: '2_edit',
group: CellOverflowToolbarGroups.Edit,
}
});
}
Expand All @@ -433,7 +446,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE, NOTEBOOK_CELL_TYPE.isEqualTo('code')),
group: '2_edit',
group: CellOverflowToolbarGroups.Edit,
}
});
}
Expand Down Expand Up @@ -526,6 +539,10 @@ registerAction2(class extends InsertCellCommand {
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, InputFocusedContext.toNegated()),
weight: KeybindingWeight.WorkbenchContrib
},
menu: {
id: MenuId.NotebookCellInsert,
order: 0
}
},
CellKind.Code,
'above');
Expand All @@ -543,6 +560,10 @@ registerAction2(class extends InsertCellCommand {
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, InputFocusedContext.toNegated()),
weight: KeybindingWeight.WorkbenchContrib
},
menu: {
id: MenuId.NotebookCellInsert,
order: 1
}
},
CellKind.Code,
'below');
Expand All @@ -565,6 +586,10 @@ registerAction2(class extends InsertCellCommand {
{
id: INSERT_MARKDOWN_CELL_ABOVE_COMMAND_ID,
title: localize('notebookActions.insertMarkdownCellAbove', "Insert Markdown Cell Above"),
menu: {
id: MenuId.NotebookCellInsert,
order: 2
}
},
CellKind.Markdown,
'above');
Expand All @@ -577,6 +602,10 @@ registerAction2(class extends InsertCellCommand {
{
id: INSERT_MARKDOWN_CELL_BELOW_COMMAND_ID,
title: localize('notebookActions.insertMarkdownCellBelow', "Insert Markdown Cell Below"),
menu: {
id: MenuId.NotebookCellInsert,
order: 3
}
},
CellKind.Markdown,
'below');
Expand Down Expand Up @@ -766,7 +795,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: NOTEBOOK_EDITOR_FOCUSED,
group: '1_copy',
group: CellOverflowToolbarGroups.Copy,
}
});
}
Expand All @@ -788,7 +817,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE),
group: '1_copy',
group: CellOverflowToolbarGroups.Copy,
}
});
}
Expand Down Expand Up @@ -817,7 +846,7 @@ registerAction2(class extends NotebookAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE),
group: '1_copy',
group: CellOverflowToolbarGroups.Copy,
}
});
}
Expand Down Expand Up @@ -1375,7 +1404,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_EDITOR_FOCUSED, NOTEBOOK_EDITOR_EDITABLE, NOTEBOOK_CELL_EDITABLE),
group: '2_edit',
group: CellOverflowToolbarGroups.Edit,
}
});
}
Expand Down Expand Up @@ -1419,7 +1448,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED.toNegated()),
group: '3_collapse',
group: CellOverflowToolbarGroups.Collapse,
}
});
}
Expand All @@ -1442,7 +1471,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_INPUT_COLLAPSED),
group: '3_collapse',
group: CellOverflowToolbarGroups.Collapse,
}
});
}
Expand All @@ -1465,7 +1494,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_OUTPUT_COLLAPSED.toNegated(), NOTEBOOK_CELL_HAS_OUTPUTS),
group: '3_collapse',
group: CellOverflowToolbarGroups.Collapse,
}
});
}
Expand All @@ -1488,7 +1517,7 @@ registerAction2(class extends NotebookCellAction {
menu: {
id: MenuId.NotebookCellTitle,
when: ContextKeyExpr.and(NOTEBOOK_CELL_LIST_FOCUSED, NOTEBOOK_CELL_OUTPUT_COLLAPSED),
group: '3_collapse',
group: CellOverflowToolbarGroups.Collapse,
}
});
}
Expand Down

0 comments on commit 2c5cae3

Please sign in to comment.