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/editor-settings.tsx
Views: 687
/*1* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.2* License: MS-RSL – see LICENSE.md for details3*/45import { FormattedMessage } from "react-intl";6import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";7import { Panel } from "@cocalc/frontend/antd-bootstrap";8import { Icon, Loading } from "@cocalc/frontend/components";9import { KEYBOARD_VARIANTS } from "@cocalc/frontend/frame-editors/x11-editor/xpra/keyboards";10import { deep_copy } from "@cocalc/util/misc";11import { EditorSettingsAutosaveInterval } from "./autosave-interval";12import { EditorSettingsCheckboxes } from "./checkboxes";13import { EditorSettingsColorScheme } from "./color-schemes";14import { EditorSettingsFontSize } from "./font-size";15import { EditorSettingsIndentSize } from "./indent-size";16import { EditorSettingsKeyboardBindings } from "./keyboard-bindings";17import {18EditorSettingsKeyboardVariant,19EditorSettingsPhysicalKeyboard,20} from "./x11-keyboard";21import { set_account_table } from "../util";2223export function EditorSettings({}) {24const autosave = useTypedRedux("account", "autosave");25const font_size = useTypedRedux("account", "font_size");26const editor_settings = useTypedRedux("account", "editor_settings");27const email_address = useTypedRedux("account", "email_address");28const tab_size = editor_settings?.get("tab_size");2930function get_keyboard_variant_options(val?) {31if (val == null) {32val = editor_settings?.get("physical_keyboard");33}34const options = deep_copy(KEYBOARD_VARIANTS[val] ?? []);35options.unshift({ value: "", display: "No variant" });36return options;37}3839function on_change(name: string, val: any): void {40if (name === "autosave" || name === "font_size") {41set_account_table({ [name]: val });42} else {43set_account_table({ editor_settings: { [name]: val } });44}4546if (name === "physical_keyboard") {47const options = get_keyboard_variant_options(val);48redux49.getActions("account")50.setState({ keyboard_variant_options: options });51for (const opt of options) {52if (opt.value === "nodeadkeys") {53on_change("keyboard_variant", opt.value);54return;55}56}57// otherwise, select default58on_change("keyboard_variant", "");59}60}6162if (editor_settings == null || font_size == null || !autosave || !tab_size) {63return <Loading />;64}6566return (67<Panel68header={69<>70<Icon name="edit" />{" "}71<FormattedMessage72id="account.editor-settings.title"73defaultMessage="Editor Settings"74/>75</>76}77>78<EditorSettingsFontSize on_change={on_change} font_size={font_size} />79<EditorSettingsAutosaveInterval80on_change={on_change}81autosave={autosave}82/>83<EditorSettingsIndentSize on_change={on_change} tab_size={tab_size} />84<EditorSettingsColorScheme85on_change={(value) => on_change("theme", value)}86theme={editor_settings.get("theme") ?? ""}87editor_settings={editor_settings}88font_size={font_size}89/>90<EditorSettingsKeyboardBindings91on_change={(value) => on_change("bindings", value)}92bindings={editor_settings.get("bindings") ?? ""}93/>94<EditorSettingsPhysicalKeyboard95on_change={(value) => on_change("physical_keyboard", value)}96physical_keyboard={editor_settings.get("physical_keyboard") ?? ""}97/>98<EditorSettingsKeyboardVariant99on_change={(value) => on_change("keyboard_variant", value)}100keyboard_variant={editor_settings.get("keyboard_variant") ?? ""}101keyboard_variant_options={get_keyboard_variant_options()}102/>103<EditorSettingsCheckboxes104on_change={on_change}105editor_settings={editor_settings}106email_address={email_address}107/>108</Panel>109);110}111112113