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/editor-settings.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 { FormattedMessage } from "react-intl";
7
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
8
import { Panel } from "@cocalc/frontend/antd-bootstrap";
9
import { Icon, Loading } from "@cocalc/frontend/components";
10
import { KEYBOARD_VARIANTS } from "@cocalc/frontend/frame-editors/x11-editor/xpra/keyboards";
11
import { deep_copy } from "@cocalc/util/misc";
12
import { EditorSettingsAutosaveInterval } from "./autosave-interval";
13
import { EditorSettingsCheckboxes } from "./checkboxes";
14
import { EditorSettingsColorScheme } from "./color-schemes";
15
import { EditorSettingsFontSize } from "./font-size";
16
import { EditorSettingsIndentSize } from "./indent-size";
17
import { EditorSettingsKeyboardBindings } from "./keyboard-bindings";
18
import {
19
EditorSettingsKeyboardVariant,
20
EditorSettingsPhysicalKeyboard,
21
} from "./x11-keyboard";
22
import { set_account_table } from "../util";
23
24
export function EditorSettings({}) {
25
const autosave = useTypedRedux("account", "autosave");
26
const font_size = useTypedRedux("account", "font_size");
27
const editor_settings = useTypedRedux("account", "editor_settings");
28
const email_address = useTypedRedux("account", "email_address");
29
const tab_size = editor_settings?.get("tab_size");
30
31
function get_keyboard_variant_options(val?) {
32
if (val == null) {
33
val = editor_settings?.get("physical_keyboard");
34
}
35
const options = deep_copy(KEYBOARD_VARIANTS[val] ?? []);
36
options.unshift({ value: "", display: "No variant" });
37
return options;
38
}
39
40
function on_change(name: string, val: any): void {
41
if (name === "autosave" || name === "font_size") {
42
set_account_table({ [name]: val });
43
} else {
44
set_account_table({ editor_settings: { [name]: val } });
45
}
46
47
if (name === "physical_keyboard") {
48
const options = get_keyboard_variant_options(val);
49
redux
50
.getActions("account")
51
.setState({ keyboard_variant_options: options });
52
for (const opt of options) {
53
if (opt.value === "nodeadkeys") {
54
on_change("keyboard_variant", opt.value);
55
return;
56
}
57
}
58
// otherwise, select default
59
on_change("keyboard_variant", "");
60
}
61
}
62
63
if (editor_settings == null || font_size == null || !autosave || !tab_size) {
64
return <Loading />;
65
}
66
67
return (
68
<Panel
69
header={
70
<>
71
<Icon name="edit" />{" "}
72
<FormattedMessage
73
id="account.editor-settings.title"
74
defaultMessage="Editor Settings"
75
/>
76
</>
77
}
78
>
79
<EditorSettingsFontSize on_change={on_change} font_size={font_size} />
80
<EditorSettingsAutosaveInterval
81
on_change={on_change}
82
autosave={autosave}
83
/>
84
<EditorSettingsIndentSize on_change={on_change} tab_size={tab_size} />
85
<EditorSettingsColorScheme
86
on_change={(value) => on_change("theme", value)}
87
theme={editor_settings.get("theme") ?? ""}
88
editor_settings={editor_settings}
89
font_size={font_size}
90
/>
91
<EditorSettingsKeyboardBindings
92
on_change={(value) => on_change("bindings", value)}
93
bindings={editor_settings.get("bindings") ?? ""}
94
/>
95
<EditorSettingsPhysicalKeyboard
96
on_change={(value) => on_change("physical_keyboard", value)}
97
physical_keyboard={editor_settings.get("physical_keyboard") ?? ""}
98
/>
99
<EditorSettingsKeyboardVariant
100
on_change={(value) => on_change("keyboard_variant", value)}
101
keyboard_variant={editor_settings.get("keyboard_variant") ?? ""}
102
keyboard_variant_options={get_keyboard_variant_options()}
103
/>
104
<EditorSettingsCheckboxes
105
on_change={on_change}
106
editor_settings={editor_settings}
107
email_address={email_address}
108
/>
109
</Panel>
110
);
111
}
112
113