KeyShortcutHandler allow force register item

This commit is contained in:
2022-10-08 22:33:14 +00:00
parent 9446ad09a8
commit 18a81742fa
2 changed files with 8 additions and 8 deletions

View File

@@ -94,7 +94,7 @@
(when xKey (when xKey
(when (= keyHandler.cancelKey xKey) (when (= keyHandler.cancelKey xKey)
(set keyHandler.cancelKey null)) (set keyHandler.cancelKey null))
(xHandler.registerItem "{${xKey}}" closeAction)))) (xHandler.registerItem "{${xKey}}" closeAction true))))
// TODO show which shortcuts' prefixes are partially highlighted? // TODO show which shortcuts' prefixes are partially highlighted?
) )
@@ -148,7 +148,7 @@
(dictSet _actions ftext ->:Void _ (scrollLeft)) (dictSet _actions ftext ->:Void _ (scrollLeft))
(set leftText ftext)) (set leftText ftext))
(when leftKey (when leftKey
(xHandler.registerItem "{${leftKey}}" scrollLeft)) (xHandler.registerItem "{${leftKey}}" scrollLeft true))
(let [ftext (new FlxText width height 0 "->" textSize)] (let [ftext (new FlxText width height 0 "->" textSize)]
(set ftext.cameras [controlCamera]) (set ftext.cameras [controlCamera])
(-= ftext.x ftext.width) (-= ftext.x ftext.width)
@@ -159,7 +159,7 @@
(dictSet _actions ftext ->:Void _ (scrollRight)) (dictSet _actions ftext ->:Void _ (scrollRight))
(set rightText ftext)) (set rightText ftext))
(when rightKey (when rightKey
(xHandler.registerItem "{${rightKey}}" scrollRight)) (xHandler.registerItem "{${rightKey}}" scrollRight true))
(refreshColumnTexts) (refreshColumnTexts)
(set hasScrollArrows true)) (set hasScrollArrows true))

View File

@@ -71,11 +71,11 @@
(otherwise (otherwise
shortcuts))) shortcuts)))
(method :Void registerShortcut [keys description item &opt :PrefixMap<T> prefixMap] (method :Void registerShortcut [keys description item &opt :Bool force :PrefixMap<T> prefixMap]
(unless prefixMap (set prefixMap rootMap)) (unless prefixMap (set prefixMap rootMap))
(let [firstKey (keys.shift)] (let [firstKey (keys.shift)]
(cond (cond
((or (prefixMap.exists firstKey) (= firstKey cancelKey)) ((and !force (or (prefixMap.exists firstKey) (= firstKey cancelKey)))
(let [existingKey (if (= firstKey cancelKey) (Cancel cancelKey) (dictGet prefixMap firstKey)) (let [existingKey (if (= firstKey cancelKey) (Cancel cancelKey) (dictGet prefixMap firstKey))
conflictMessage "Keyboard shortcut for $description conflicts with $existingKey"] conflictMessage "Keyboard shortcut for $description conflicts with $existingKey"]
(if keys (if keys
@@ -94,12 +94,12 @@
(if keys (if keys
(let [innerPrefixMap (new Map)] (let [innerPrefixMap (new Map)]
(dictSet prefixMap firstKey (Prefix innerPrefixMap)) (dictSet prefixMap firstKey (Prefix innerPrefixMap))
(registerShortcut keys description item innerPrefixMap)) (registerShortcut keys description item force innerPrefixMap))
(dictSet prefixMap firstKey (Final item))))))) (dictSet prefixMap firstKey (Final item)))))))
(method :Void registerItem [description :T item] (method :Void registerItem [description :T item &opt :Bool force]
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)] (whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
(registerShortcut keyboardShortcut description item))) (registerShortcut keyboardShortcut description item force)))
(method :Map<String,String> prefixMapToStrings [:PrefixMap<T> map] (method :Map<String,String> prefixMapToStrings [:PrefixMap<T> map]
(for =>key mapping map (for =>key mapping map