Skip to content

Commit a5fb1d2

Browse files
committed
frontend/jupyter: add cell-type switches to the button menu of a cell
1 parent 358fec8 commit a5fb1d2

File tree

5 files changed

+70
-32
lines changed

5 files changed

+70
-32
lines changed

src/packages/frontend/cspell.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@
4141
"timetravel",
4242
"tolerations",
4343
"undelete",
44-
"undeleting"
44+
"undeleting",
45+
"revealjs"
4546
],
4647
"ignoreWords": [
4748
"antd",
@@ -64,7 +65,9 @@
6465
"vertexai",
6566
"vfill",
6667
"xsmall",
67-
"flyouts"
68+
"flyouts",
69+
"buttonbar",
70+
"noconf"
6871
],
6972
"flagWords": [],
7073
"ignorePaths": ["node_modules/**", "dist/**", "dist-ts/**", "build/**"],

src/packages/frontend/frame-editors/jupyter-editor/editor.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55

66
/*
77
Spec for editing Jupyter notebooks via a frame tree.
8+
9+
cSpell:ignore JSONIPynb
810
*/
911

1012
import { createElement } from "react";
13+
1114
import type { Command } from "@cocalc/frontend/frame-editors/frame-tree/commands";
1215
import { addEditorMenus } from "@cocalc/frontend/frame-editors/frame-tree/commands";
1316
import { FORMAT_SOURCE_ICON } from "@cocalc/frontend/frame-editors/frame-tree/config";
@@ -25,10 +28,10 @@ import { Introspect } from "./introspect/introspect";
2528
import JSONIPynb from "./json-ipynb";
2629
import KernelMenuItem from "./kernel-menu-item";
2730
import { RawIPynb } from "./raw-ipynb";
31+
import { search } from "./search";
2832
import { Slideshow } from "./slideshow-revealjs/slideshow";
2933
import { JupyterSnippets } from "./snippets";
3034
import { TableOfContents } from "./table-of-contents";
31-
import { search } from "./search";
3235

3336
const SNIPPET_ICON_NAME = "magic";
3437

src/packages/frontend/i18n/common.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1280,6 +1280,20 @@ export const jupyter = {
12801280
defaultMessage: "None",
12811281
description: "Jupyter Notebook cell toolbar 'None' hides the toolbar",
12821282
},
1283+
change_cell_to_code: {
1284+
id: "jupyter.commands.change_cell_to_code.label",
1285+
defaultMessage: "Change Cell to Code",
1286+
},
1287+
change_cell_to_markdown: {
1288+
id: "jupyter.commands.change_cell_to_markdown.label",
1289+
defaultMessage: "Change Cell to Markdown",
1290+
description: "Cell in a Jupyter Notebook",
1291+
},
1292+
change_cell_to_raw: {
1293+
id: "jupyter.commands.change_cell_to_raw.label",
1294+
defaultMessage: "Change Cell to Raw",
1295+
description: "Cell in a Jupyter Notebook",
1296+
},
12831297
restart_kernel_noconf_menu: {
12841298
id: "jupyter.commands.restart_kernel_noconf.menu",
12851299
defaultMessage: "Restart kernel",

src/packages/frontend/jupyter/cell-buttonbar-menu.tsx

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { useIntl } from "react-intl";
1010

1111
import { alert_message } from "@cocalc/frontend/alerts";
1212
import { Icon } from "@cocalc/frontend/components";
13-
import { labels } from "@cocalc/frontend/i18n";
13+
import { jupyter, labels } from "@cocalc/frontend/i18n";
1414
import {
1515
CODE_BAR_BTN_STYLE,
1616
COPY_CELL_ICON,
@@ -56,6 +56,19 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
5656
if (actions == null) return null;
5757

5858
const items: MenuProps["items"] = [
59+
{
60+
key: "undo",
61+
label: intl.formatMessage(labels.undo),
62+
icon: <Icon name="undo" />,
63+
onClick: () => actions.undo(),
64+
},
65+
{
66+
key: "redo",
67+
label: intl.formatMessage(labels.redo),
68+
icon: <Icon name="redo" />,
69+
onClick: () => actions.redo(),
70+
},
71+
{ key: "divider3", type: "divider" },
5972
{
6073
key: "copy",
6174
label: intl.formatMessage({
@@ -74,18 +87,31 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
7487
icon: <Icon name="paste" />,
7588
onClick: pasteFromClipboard,
7689
},
77-
{ key: "divider3", type: "divider" },
78-
{
79-
key: "undo",
80-
label: intl.formatMessage(labels.undo),
81-
icon: <Icon name="undo" />,
82-
onClick: () => actions.undo(),
83-
},
90+
{ key: "divider5", type: "divider" },
8491
{
85-
key: "redo",
86-
label: intl.formatMessage(labels.redo),
87-
icon: <Icon name="redo" />,
88-
onClick: () => actions.redo(),
92+
key: "cell-type",
93+
label: intl.formatMessage(jupyter.commands.cell_type_menu),
94+
icon: <Icon name="code-outlined" />,
95+
children: [
96+
{
97+
key: "cell-type-code",
98+
label: intl.formatMessage(jupyter.commands.change_cell_to_code),
99+
icon: <Icon name="code-outlined" />,
100+
onClick: () => frameActions.current?.set_selected_cell_type("code"),
101+
},
102+
{
103+
key: "cell-type-markdown",
104+
label: intl.formatMessage(jupyter.commands.change_cell_to_markdown),
105+
icon: <Icon name="markdown" />,
106+
onClick: () =>
107+
frameActions.current?.set_selected_cell_type("markdown"),
108+
},
109+
{
110+
key: "cell-type-raw",
111+
label: intl.formatMessage(jupyter.commands.change_cell_to_raw),
112+
onClick: () => frameActions.current?.set_selected_cell_type("raw"),
113+
},
114+
],
89115
},
90116
{ key: "divider4", type: "divider" },
91117
{
@@ -163,7 +189,8 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
163189
icon: <Icon name={DELETE_CELL_ICON} />,
164190
onClick: () => frameActions.current?.delete_selected_cells(),
165191
},
166-
{ key: "divider5", type: "divider" },
192+
193+
{ key: "divider6", type: "divider" },
167194
{
168195
key: "split-cell",
169196
label: intl.formatMessage({
@@ -207,7 +234,7 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
207234
),
208235
onClick: () => frameActions.current?.merge_cell_below(),
209236
},
210-
{ key: "divider6", type: "divider" },
237+
{ key: "divider7", type: "divider" },
211238
{
212239
key: "move-cell-up",
213240
label: intl.formatMessage({
@@ -228,12 +255,13 @@ export function CodeBarDropdownMenu({ actions, frameActions, id, cell }) {
228255
icon: <Icon name="arrow-down" />,
229256
onClick: () => move_cell(1),
230257
},
231-
].map(({ key, label, icon, onClick }) => {
258+
].map(({ key, label, icon, onClick, children }) => {
232259
return {
233260
key,
234261
label,
235262
onClick,
236263
icon: <span style={{ width: "24px" }}>{icon}</span>,
264+
children,
237265
};
238266
});
239267

src/packages/frontend/jupyter/commands.ts

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,7 @@ export function commands(actions: AllActions): {
175175

176176
"change cell to code": {
177177
i: "code-outlined",
178-
m: defineMessage({
179-
id: "jupyter.commands.change_cell_to_code.label",
180-
defaultMessage: "Change Cell to Code",
181-
}),
178+
m: jupyter.commands.change_cell_to_code,
182179
k: [{ which: 89, mode: "escape" }],
183180
f: () => actions.frame_actions?.set_selected_cell_type("code"),
184181
},
@@ -239,21 +236,14 @@ export function commands(actions: AllActions): {
239236
},
240237

241238
"change cell to markdown": {
242-
m: defineMessage({
243-
id: "jupyter.commands.change_cell_to_markdown.label",
244-
defaultMessage: "Change Cell to Markdown",
245-
description: "Cell in a Jupyter Notebook",
246-
}),
239+
m: jupyter.commands.change_cell_to_markdown,
240+
i: "markdown",
247241
k: [{ which: 77, mode: "escape" }],
248242
f: () => actions.frame_actions?.set_selected_cell_type("markdown"),
249243
},
250244

251245
"change cell to raw": {
252-
m: defineMessage({
253-
id: "jupyter.commands.change_cell_to_row.label",
254-
defaultMessage: "Change Cell to Raw",
255-
description: "Cell in a Jupyter Notebook",
256-
}),
246+
m: jupyter.commands.change_cell_to_raw,
257247
k: [{ which: 82, mode: "escape" }],
258248
f: () => actions.frame_actions?.set_selected_cell_type("raw"),
259249
},

0 commit comments

Comments
 (0)