Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/account/editor-settings/editor-settings.tsx
6040 views
1
/*
2
* This file is part of CoCalc: Copyright © 2020 Sagemath, Inc.
3
* License: MS-RSL – see LICENSE.md for details
4
*/
5
6
// cSpell:ignore nodeadkeys
7
8
import { FormattedMessage } from "react-intl";
9
10
import { Panel } from "@cocalc/frontend/antd-bootstrap";
11
import { redux, useTypedRedux } from "@cocalc/frontend/app-framework";
12
import { Icon, Loading } from "@cocalc/frontend/components";
13
import { KEYBOARD_VARIANTS } from "@cocalc/frontend/frame-editors/x11-editor/xpra/keyboards";
14
import { deep_copy } from "@cocalc/util/misc";
15
import { set_account_table } from "../util";
16
import { EditorSettingsAutosaveInterval } from "./autosave-interval";
17
import { EditorSettingsCheckboxes } from "./checkboxes";
18
import { EditorSettingsColorScheme } from "./color-schemes";
19
import { EditorSettingsFontSize } from "./font-size";
20
import { EditorSettingsIndentSize } from "./indent-size";
21
import { EditorSettingsKeyboardBindings } from "./keyboard-bindings";
22
import {
23
EditorSettingsKeyboardVariant,
24
EditorSettingsPhysicalKeyboard,
25
} from "./x11-keyboard";
26
27
export function EditorSettings({}) {
28
const autosave = useTypedRedux("account", "autosave");
29
const font_size = useTypedRedux("account", "font_size");
30
const editor_settings = useTypedRedux("account", "editor_settings");
31
const other_settings = useTypedRedux("account", "other_settings");
32
const email_address = useTypedRedux("account", "email_address");
33
const tab_size = editor_settings?.get("tab_size");
34
35
function get_keyboard_variant_options(val?) {
36
if (val == null) {
37
val = editor_settings?.get("physical_keyboard");
38
}
39
const options = deep_copy(KEYBOARD_VARIANTS[val] ?? []);
40
options.unshift({ value: "", display: "No variant" });
41
return options;
42
}
43
44
function on_change(name: string, val: any): void {
45
if (name === "autosave" || name === "font_size") {
46
set_account_table({ [name]: val });
47
} else {
48
set_account_table({ editor_settings: { [name]: val } });
49
}
50
51
if (name === "physical_keyboard") {
52
const options = get_keyboard_variant_options(val);
53
redux
54
.getActions("account")
55
.setState({ keyboard_variant_options: options });
56
for (const opt of options) {
57
if (opt.value === "nodeadkeys") {
58
on_change("keyboard_variant", opt.value);
59
return;
60
}
61
}
62
// otherwise, select default
63
on_change("keyboard_variant", "");
64
}
65
}
66
67
function on_change_other_settings(name: string, value: any): void {
68
redux.getActions("account").set_other_settings(name, value);
69
}
70
71
if (editor_settings == null || font_size == null || !autosave || !tab_size) {
72
return <Loading />;
73
}
74
75
return (
76
<>
77
<Panel
78
size="small"
79
header={
80
<>
81
<Icon name="font" />{" "}
82
<FormattedMessage
83
id="account.editor-settings.basic.title"
84
defaultMessage="Basic Settings"
85
/>
86
</>
87
}
88
>
89
<EditorSettingsFontSize on_change={on_change} font_size={font_size} />
90
<EditorSettingsAutosaveInterval
91
on_change={on_change}
92
autosave={autosave}
93
/>
94
<EditorSettingsIndentSize on_change={on_change} tab_size={tab_size} />
95
</Panel>
96
<EditorSettingsColorScheme
97
style={{ marginTop: "10px" }}
98
size={"small"}
99
on_change={(value) => on_change("theme", value)}
100
theme={editor_settings.get("theme") ?? ""}
101
editor_settings={editor_settings}
102
font_size={font_size}
103
/>
104
<Panel
105
size="small"
106
header={
107
<>
108
<Icon name="keyboard" />{" "}
109
<FormattedMessage
110
id="account.editor-settings.keyboard.title"
111
defaultMessage="Keyboard"
112
/>
113
</>
114
}
115
>
116
<EditorSettingsKeyboardBindings
117
on_change={(value) => on_change("bindings", value)}
118
bindings={editor_settings.get("bindings") ?? ""}
119
/>
120
<EditorSettingsPhysicalKeyboard
121
on_change={(value) => on_change("physical_keyboard", value)}
122
physical_keyboard={editor_settings.get("physical_keyboard") ?? ""}
123
/>
124
<EditorSettingsKeyboardVariant
125
on_change={(value) => on_change("keyboard_variant", value)}
126
keyboard_variant={editor_settings.get("keyboard_variant") ?? ""}
127
keyboard_variant_options={get_keyboard_variant_options()}
128
/>
129
</Panel>
130
<EditorSettingsCheckboxes
131
on_change={on_change}
132
on_change_other_settings={on_change_other_settings}
133
editor_settings={editor_settings}
134
other_settings={other_settings}
135
email_address={email_address}
136
/>
137
</>
138
);
139
}
140
141