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";
|
|
|
|
|
|
2022-01-24 12:33:27 +01:00
|
|
|
import {
|
|
|
|
|
ICategory,
|
|
|
|
|
CATEGORIES,
|
|
|
|
|
CategoryName,
|
|
|
|
|
} 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 {
|
|
|
|
|
name: string;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-26 17:50:47 +01:00
|
|
|
// Filter out the labs section if labs aren't enabled.
|
|
|
|
|
const visibleCategories = Object.entries(CATEGORIES).filter(([categoryName]) =>
|
2022-03-18 10:12:36 -06:00
|
|
|
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 <div className="mx_KeyboardShortcut_shortcutRow">
|
2022-02-28 17:05:52 +01:00
|
|
|
{ displayName }
|
2022-03-14 14:25:51 +01:00
|
|
|
<KeyboardShortcut value={value} />
|
2022-01-24 12:33:27 +01:00
|
|
|
</div>;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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>
|
|
|
|
|
<div> { category.settingNames.map((shortcutName) => {
|
|
|
|
|
return <KeyboardShortcutRow key={shortcutName} name={shortcutName} />;
|
|
|
|
|
}) } </div>
|
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>
|
2022-01-26 17:50:47 +01:00
|
|
|
{ visibleCategories.map(([categoryName, category]: [CategoryName, ICategory]) => {
|
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;
|