CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/editor-settings/checkboxes.tsx
Views: 687
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
import { defineMessage, useIntl } from "react-intl";
7
import { Checkbox } from "@cocalc/frontend/antd-bootstrap";
8
import { Rendered } from "@cocalc/frontend/app-framework";
9
import { IntlMessage, isIntlMessage } from "@cocalc/frontend/i18n";
10
import { capitalize, keys } from "@cocalc/util/misc";
11
12
const EDITOR_SETTINGS_CHECKBOXES = {
13
extra_button_bar: defineMessage({
14
id: "account.editor-setting.checkbox.extra_button_bar",
15
defaultMessage:
16
"customizable button bar below menu bar with shortcuts to menu items",
17
}),
18
line_wrapping: defineMessage({
19
id: "account.editor-setting.checkbox.line_wrapping",
20
defaultMessage: "wrap long lines",
21
}),
22
line_numbers: defineMessage({
23
id: "account.editor-setting.checkbox.line_numbers",
24
defaultMessage: "show line numbers",
25
}),
26
jupyter_line_numbers: defineMessage({
27
id: "account.editor-setting.checkbox.jupyter_line_numbers",
28
defaultMessage: "show line numbers in Jupyter Notebooks",
29
}),
30
code_folding: defineMessage({
31
id: "account.editor-setting.checkbox.code_folding",
32
defaultMessage: "fold code using control+Q",
33
}),
34
smart_indent: defineMessage({
35
id: "account.editor-setting.checkbox.smart_indent",
36
defaultMessage: "context sensitive indentation",
37
}),
38
electric_chars: defineMessage({
39
id: "account.editor-setting.checkbox.electric_chars",
40
defaultMessage: "sometimes reindent current line",
41
}),
42
match_brackets: defineMessage({
43
id: "account.editor-setting.checkbox.match_brackets",
44
defaultMessage: "highlight matching brackets near cursor",
45
}),
46
auto_close_brackets: defineMessage({
47
id: "account.editor-setting.checkbox.auto_close_brackets",
48
defaultMessage: "automatically close brackets",
49
}),
50
match_xml_tags: defineMessage({
51
id: "account.editor-setting.checkbox.match_xml_tags",
52
defaultMessage: "automatically match XML tags",
53
}),
54
auto_close_xml_tags: defineMessage({
55
id: "account.editor-setting.checkbox.auto_close_xml_tags",
56
defaultMessage: "automatically close XML tags",
57
}),
58
auto_close_latex: defineMessage({
59
id: "account.editor-setting.checkbox.auto_close_latex",
60
defaultMessage: "automatically close LaTeX environments",
61
}),
62
strip_trailing_whitespace: defineMessage({
63
id: "account.editor-setting.checkbox.strip_trailing_whitespace",
64
defaultMessage: "remove whenever file is saved",
65
}),
66
show_trailing_whitespace: defineMessage({
67
id: "account.editor-setting.checkbox.show_trailing_whitespace",
68
defaultMessage: "show spaces at ends of lines",
69
}),
70
spaces_instead_of_tabs: defineMessage({
71
id: "account.editor-setting.checkbox.spaces_instead_of_tabs",
72
defaultMessage: "send spaces when the tab key is pressed",
73
}),
74
build_on_save: defineMessage({
75
id: "account.editor-setting.checkbox.build_on_save",
76
defaultMessage: "build LaTex/Rmd files whenever it is saved to disk",
77
}),
78
show_exec_warning: defineMessage({
79
id: "account.editor-setting.checkbox.show_exec_warning",
80
defaultMessage: "warn that certain files are not directly executable",
81
}),
82
ask_jupyter_kernel: defineMessage({
83
id: "account.editor-setting.checkbox.ask_jupyter_kernel",
84
defaultMessage: "ask which kernel to use for a new Jupyter Notebook",
85
}),
86
show_my_other_cursors: "when editing the same file in multiple browsers",
87
disable_jupyter_virtualization: defineMessage({
88
id: "account.editor-setting.checkbox.disable_jupyter_virtualization",
89
defaultMessage:
90
"render entire Jupyter Notebook instead of just visible part (slower and not recommended)",
91
}),
92
} as const;
93
94
interface Props {
95
editor_settings;
96
email_address?: string;
97
on_change: Function;
98
}
99
100
export function EditorSettingsCheckboxes(props: Props) {
101
const intl = useIntl();
102
103
function label_checkbox(
104
name: string,
105
desc: IntlMessage | Rendered,
106
): Rendered {
107
return (
108
<span>
109
{capitalize(
110
name
111
.replace(/_/g, " ")
112
.replace(/-/g, " ")
113
.replace("xml", "XML")
114
.replace("latex", "LaTeX"),
115
) + ": "}
116
{isIntlMessage(desc) ? intl.formatMessage(desc) : desc}
117
</span>
118
);
119
}
120
121
function render_checkbox(
122
name: string,
123
desc: IntlMessage | Rendered,
124
): Rendered {
125
if (
126
props.email_address?.indexOf("minervaproject.com") != -1 &&
127
name === "jupyter_classic"
128
) {
129
// Special case -- minerva doesn't get the jupyter classic option, to avoid student confusion.
130
return;
131
}
132
return (
133
<Checkbox
134
checked={!!props.editor_settings.get(name)}
135
key={name}
136
onChange={(e) => props.on_change(name, e.target.checked)}
137
>
138
{label_checkbox(name, desc)}
139
</Checkbox>
140
);
141
}
142
143
return (
144
<span>
145
{keys(EDITOR_SETTINGS_CHECKBOXES).map((name) =>
146
render_checkbox(name, EDITOR_SETTINGS_CHECKBOXES[name]),
147
)}
148
</span>
149
);
150
}
151
152