2022-01-17 12:53:10 +01:00
|
|
|
/*
|
|
|
|
|
Copyright 2020 The Matrix.org Foundation C.I.C.
|
2022-01-24 12:33:27 +01:00
|
|
|
Copyright 2021 - 2022 Šimon Brandner <simon.bra.ag@gmail.com>
|
2022-01-17 12:53:10 +01:00
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
|
limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import React from "react";
|
|
|
|
|
|
2023-02-13 11:39:16 +00:00
|
|
|
import { ICategory, CATEGORIES, CategoryName, KeyBindingAction } from "../../../../../accessibility/KeyboardShortcuts";
|
2022-01-26 17:50:47 +01:00
|
|
|
import SdkConfig from "../../../../../SdkConfig";
|
2022-01-24 12:33:27 +01:00
|
|
|
import { _t } from "../../../../../languageHandler";
|
2022-03-14 14:25:51 +01:00
|
|
|
import {
|
|
|
|
|
getKeyboardShortcutDisplayName,
|
|
|
|
|
getKeyboardShortcutValue,
|
|
|
|
|
} from "../../../../../accessibility/KeyboardShortcutUtils";
|
|
|
|
|
import { KeyboardShortcut } from "../../KeyboardShortcut";
|
2022-01-24 12:33:27 +01:00
|
|
|
|
|
|
|
|
interface IKeyboardShortcutRowProps {
|
2023-02-13 11:39:16 +00:00
|
|
|
name: KeyBindingAction;
|
2022-01-24 12:33:27 +01:00
|
|
|
}
|
|
|
|
|
|
2022-01-26 17:50:47 +01:00
|
|
|
// Filter out the labs section if labs aren't enabled.
|
2023-05-16 14:25:43 +01:00
|
|
|
const visibleCategories = (Object.entries(CATEGORIES) as [CategoryName, ICategory][]).filter(
|
2022-03-18 10:12:36 -06:00
|
|
|
([categoryName]) => categoryName !== CategoryName.LABS || SdkConfig.get("show_labs_settings"),
|
|
|
|
|
);
|
2022-01-26 17:50:47 +01:00
|
|
|
|
2022-01-24 12:33:27 +01:00
|
|
|
const KeyboardShortcutRow: React.FC<IKeyboardShortcutRowProps> = ({ name }) => {
|
2022-02-28 17:05:52 +01:00
|
|
|
const displayName = getKeyboardShortcutDisplayName(name);
|
2022-03-14 14:25:51 +01:00
|
|
|
const value = getKeyboardShortcutValue(name);
|
|
|
|
|
if (!displayName || !value) return null;
|
2022-02-28 17:05:52 +01:00
|
|
|
|
2022-01-24 12:33:27 +01:00
|
|
|
return (
|
2023-04-20 18:13:30 +01:00
|
|
|
<li className="mx_KeyboardShortcut_shortcutRow">
|
2022-02-28 17:05:52 +01:00
|
|
|
{displayName}
|
2022-03-14 14:25:51 +01:00
|
|
|
<KeyboardShortcut value={value} />
|
2023-04-20 18:13:30 +01:00
|
|
|
</li>
|
2022-01-24 12:33:27 +01:00
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
interface IKeyboardShortcutSectionProps {
|
|
|
|
|
categoryName: CategoryName;
|
|
|
|
|
category: ICategory;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const KeyboardShortcutSection: React.FC<IKeyboardShortcutSectionProps> = ({ categoryName, category }) => {
|
2022-02-28 17:05:52 +01:00
|
|
|
if (!category.categoryLabel) return null;
|
|
|
|
|
|
2022-01-24 12:33:27 +01:00
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab_section" key={categoryName}>
|
|
|
|
|
<div className="mx_SettingsTab_subheading">{_t(category.categoryLabel)}</div>
|
2023-04-20 18:13:30 +01:00
|
|
|
<ul>
|
2022-12-12 12:24:14 +01:00
|
|
|
{" "}
|
2022-01-24 12:33:27 +01:00
|
|
|
{category.settingNames.map((shortcutName) => {
|
|
|
|
|
return <KeyboardShortcutRow key={shortcutName} name={shortcutName} />;
|
|
|
|
|
})}{" "}
|
2023-04-20 18:13:30 +01:00
|
|
|
</ul>
|
2022-01-17 12:53:10 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const KeyboardUserSettingsTab: React.FC = () => {
|
|
|
|
|
return (
|
|
|
|
|
<div className="mx_SettingsTab mx_KeyboardUserSettingsTab">
|
|
|
|
|
<div className="mx_SettingsTab_heading">{_t("Keyboard")}</div>
|
2023-05-16 14:25:43 +01:00
|
|
|
{visibleCategories.map(([categoryName, category]) => {
|
2022-01-24 12:33:27 +01:00
|
|
|
return <KeyboardShortcutSection key={categoryName} categoryName={categoryName} category={category} />;
|
|
|
|
|
})}
|
2022-01-17 12:53:10 +01:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default KeyboardUserSettingsTab;
|