Skip to content
This repository was archived by the owner on Sep 11, 2024. It is now read-only.

Commit 568da3a

Browse files
committed
Rest
Signed-off-by: Šimon Brandner <[email protected]>
1 parent f33d662 commit 568da3a

File tree

3 files changed

+93
-7
lines changed

3 files changed

+93
-7
lines changed

res/css/views/settings/tabs/user/_KeyboardUserSettingsTab.scss

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,17 @@ limitations under the License.
1818
.mx_KeyboardUserSettingsTab .mx_SettingsTab_section {
1919
.mx_KeyboardShortcut_shortcutRow {
2020
display: flex;
21-
justify-content: space-between;
2221
align-items: center;
22+
23+
.mx_KeyboardShortcut_shortcutRow_displayName {
24+
margin-right: auto;
25+
}
26+
27+
.mx_AccessibleButton {
28+
margin: 0 4px;
29+
}
30+
31+
margin: 4px 0;
2332
}
2433

2534
kbd {
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
Copyright 2022 Šimon Brandner <[email protected]>
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
import React, { useState } from "react";
18+
19+
import { KeyCombo } from "../../../../../KeyBindingsManager";
20+
import BaseDialog from "../../../dialogs/BaseDialog";
21+
import { IDialogProps } from "../../../dialogs/IDialogProps";
22+
import KeyboardShortcut from "../../KeyboardShortcut";
23+
24+
interface IProps extends IDialogProps {
25+
value: KeyCombo;
26+
}
27+
28+
export const ChangeKeyboardShortcutDialog: React.FC<IProps> = ({ onFinished, value }) => {
29+
const [currentValue] = useState(value);
30+
31+
const onDialogFinished = () => {
32+
onFinished();
33+
};
34+
35+
const onKeyDown = (event: KeyboardEvent) => {
36+
37+
};
38+
39+
return <BaseDialog onFinished={onDialogFinished} onKeyDown={onKeyDown}>
40+
<KeyboardShortcut value={currentValue} />
41+
</BaseDialog>;
42+
};
43+
44+
export default ChangeKeyboardShortcutDialog;

src/components/views/settings/tabs/user/KeyboardUserSettingsTab.tsx

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,41 +25,69 @@ import {
2525
import SdkConfig from "../../../../../SdkConfig";
2626
import { _t } from "../../../../../languageHandler";
2727
import {
28-
getKeyboardShortcutDisplayName, getKeyboardShortcutValue,
28+
getKeyboardShortcutDisplayName,
29+
getKeyboardShortcutHideEditUI,
30+
getKeyboardShortcutValue,
2931
} from "../../../../../accessibility/KeyboardShortcutUtils";
3032
import { KeyboardShortcut } from "../../KeyboardShortcut";
33+
import AccessibleButton from "../../../elements/AccessibleButton";
34+
import SettingsStore from "../../../../../settings/SettingsStore";
35+
import { SettingLevel } from "../../../../../settings/SettingLevel";
3136

3237
interface IKeyboardShortcutRowProps {
3338
name: string;
39+
allowCustomization: boolean;
3440
}
3541

3642
// Filter out the labs section if labs aren't enabled.
3743
const visibleCategories = Object.entries(CATEGORIES).filter(([categoryName]) =>
3844
categoryName !== CategoryName.LABS || SdkConfig.get()['showLabsSettings']);
3945

40-
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name }) => {
46+
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name, allowCustomization }) => {
4147
const displayName = getKeyboardShortcutDisplayName(name);
48+
const hideEditUI = getKeyboardShortcutHideEditUI(name);
4249
const value = getKeyboardShortcutValue(name);
4350
if (!displayName || !value) return null;
4451

52+
const onEditClick = (): void => {
53+
54+
};
55+
56+
const onResetClick = (): void => {
57+
SettingsStore.setValue(name, null, SettingLevel.DEVICE, SettingsStore.getDefaultValue(name));
58+
};
59+
4560
return <div className="mx_KeyboardShortcut_shortcutRow">
46-
{ displayName }
61+
<div className="mx_KeyboardShortcut_shortcutRow_displayName">
62+
{ displayName }
63+
</div>
4764
<KeyboardShortcut value={value} />
65+
{ allowCustomization && <React.Fragment>
66+
<AccessibleButton kind="primary_outline" disabled={hideEditUI} onClick={onEditClick}> { _t("Edit") } </AccessibleButton>
67+
<AccessibleButton kind="primary_outline" disabled={hideEditUI} onClick={onResetClick}> { _t("Reset") } </AccessibleButton>
68+
</React.Fragment> }
4869
</div>;
4970
};
5071

5172
interface IKeyboardShortcutSectionProps {
5273
categoryName: CategoryName;
5374
category: ICategory;
75+
allowCustomization: boolean;
5476
}
5577

56-
const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = ({ categoryName, category }) => {
78+
const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = (
79+
{ categoryName, category, allowCustomization },
80+
) => {
5781
if (!category.categoryLabel) return null;
5882

5983
return <div className="mx_SettingsTab_section" key={categoryName}>
6084
<div className="mx_SettingsTab_subheading">{ _t(category.categoryLabel) }</div>
6185
<div> { category.settingNames.map((shortcutName) => {
62-
return <KeyboardShortcutRow key={shortcutName} name={shortcutName} />;
86+
return <KeyboardShortcutRow
87+
key={shortcutName}
88+
name={shortcutName}
89+
allowCustomization={allowCustomization}
90+
/>;
6391
}) } </div>
6492
</div>;
6593
};
@@ -68,7 +96,12 @@ const KeyboardUserSettingsTab: React.FC = () => {
6896
return <div className="mx_SettingsTab mx_KeyboardUserSettingsTab">
6997
<div className="mx_SettingsTab_heading">{ _t("Keyboard") }</div>
7098
{ visibleCategories.map(([categoryName, category]: [CategoryName, ICategory]) => {
71-
return <KeyboardShortcutSection key={categoryName} categoryName={categoryName} category={category} />;
99+
return <KeyboardShortcutSection
100+
key={categoryName}
101+
categoryName={categoryName}
102+
category={category}
103+
allowCustomization={SettingsStore.getValue("feature_customizable_keybindings")}
104+
/>;
72105
}) }
73106
</div>;
74107
};

0 commit comments

Comments
 (0)