@@ -25,41 +25,80 @@ import {
25
25
import SdkConfig from "../../../../../SdkConfig" ;
26
26
import { _t } from "../../../../../languageHandler" ;
27
27
import {
28
- getKeyboardShortcutDisplayName , getKeyboardShortcutValue ,
28
+ getKeyboardShortcutDisplayName ,
29
+ getKeyboardShortcutHideEditUI ,
30
+ getKeyboardShortcutValue ,
29
31
} from "../../../../../accessibility/KeyboardShortcutUtils" ;
30
32
import { KeyboardShortcut } from "../../KeyboardShortcut" ;
33
+ import AccessibleButton from "../../../elements/AccessibleButton" ;
34
+ import SettingsStore from "../../../../../settings/SettingsStore" ;
35
+ import { SettingLevel } from "../../../../../settings/SettingLevel" ;
36
+ import Modal from "../../../../../Modal" ;
37
+ import {
38
+ ChangeKeyboardShortcutDialog ,
39
+ IProps as IChangeKeyboardShortcutDialogProps ,
40
+ } from "./ChangeKeyboardShortcutDialog" ;
31
41
32
42
interface IKeyboardShortcutRowProps {
33
43
name : string ;
44
+ allowCustomization : boolean ;
34
45
}
35
46
36
47
// Filter out the labs section if labs aren't enabled.
37
48
const visibleCategories = Object . entries ( CATEGORIES ) . filter ( ( [ categoryName ] ) =>
38
49
categoryName !== CategoryName . LABS || SdkConfig . get ( ) [ 'showLabsSettings' ] ) ;
39
50
40
- const KeyboardShortcutRow : React . FC < IKeyboardShortcutRowProps > = ( { name } ) => {
51
+ const KeyboardShortcutRow : React . FC < IKeyboardShortcutRowProps > = ( { name, allowCustomization } ) => {
41
52
const displayName = getKeyboardShortcutDisplayName ( name ) ;
53
+ const hideEditUI = getKeyboardShortcutHideEditUI ( name ) ;
42
54
const value = getKeyboardShortcutValue ( name ) ;
43
55
if ( ! displayName || ! value ) return null ;
44
56
57
+ const onEditClick = async ( ) : Promise < void > => {
58
+ const { finished } = Modal . createDialog ( ChangeKeyboardShortcutDialog , {
59
+ value,
60
+ } as IChangeKeyboardShortcutDialogProps ) ;
61
+ const [ newValue ] = await finished ;
62
+ if ( ! newValue ) return ;
63
+
64
+ //SettingsStore.setValue(name, null, SettingLevel.DEVICE, newValue);
65
+ } ;
66
+
67
+ const onResetClick = ( ) : void => {
68
+ SettingsStore . setValue ( name , null , SettingLevel . DEVICE , SettingsStore . getDefaultValue ( name ) ) ;
69
+ } ;
70
+
45
71
return < div className = "mx_KeyboardShortcut_shortcutRow" >
46
- { displayName }
72
+ < div className = "mx_KeyboardShortcut_shortcutRow_displayName" >
73
+ { displayName }
74
+ </ div >
47
75
< KeyboardShortcut value = { value } />
76
+ { allowCustomization && < React . Fragment >
77
+ < AccessibleButton kind = "primary_outline" disabled = { hideEditUI } onClick = { onEditClick } > { _t ( "Edit" ) } </ AccessibleButton >
78
+ < AccessibleButton kind = "primary_outline" disabled = { hideEditUI } onClick = { onResetClick } > { _t ( "Reset" ) } </ AccessibleButton >
79
+ </ React . Fragment > }
48
80
</ div > ;
49
81
} ;
50
82
51
83
interface IKeyboardShortcutSectionProps {
52
84
categoryName : CategoryName ;
53
85
category : ICategory ;
86
+ allowCustomization : boolean ;
54
87
}
55
88
56
- const KeyboardShortcutSection : React . FC < IKeyboardShortcutSectionProps > = ( { categoryName, category } ) => {
89
+ const KeyboardShortcutSection : React . FC < IKeyboardShortcutSectionProps > = (
90
+ { categoryName, category, allowCustomization } ,
91
+ ) => {
57
92
if ( ! category . categoryLabel ) return null ;
58
93
59
94
return < div className = "mx_SettingsTab_section" key = { categoryName } >
60
95
< div className = "mx_SettingsTab_subheading" > { _t ( category . categoryLabel ) } </ div >
61
96
< div > { category . settingNames . map ( ( shortcutName ) => {
62
- return < KeyboardShortcutRow key = { shortcutName } name = { shortcutName } /> ;
97
+ return < KeyboardShortcutRow
98
+ key = { shortcutName }
99
+ name = { shortcutName }
100
+ allowCustomization = { allowCustomization }
101
+ /> ;
63
102
} ) } </ div >
64
103
</ div > ;
65
104
} ;
@@ -68,7 +107,12 @@ const KeyboardUserSettingsTab: React.FC = () => {
68
107
return < div className = "mx_SettingsTab mx_KeyboardUserSettingsTab" >
69
108
< div className = "mx_SettingsTab_heading" > { _t ( "Keyboard" ) } </ div >
70
109
{ visibleCategories . map ( ( [ categoryName , category ] : [ CategoryName , ICategory ] ) => {
71
- return < KeyboardShortcutSection key = { categoryName } categoryName = { categoryName } category = { category } /> ;
110
+ return < KeyboardShortcutSection
111
+ key = { categoryName }
112
+ categoryName = { categoryName }
113
+ category = { category }
114
+ allowCustomization = { SettingsStore . getValue ( "feature_customizable_keybindings" ) }
115
+ /> ;
72
116
} ) }
73
117
</ div > ;
74
118
} ;
0 commit comments