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