Add KeyShortcutHandler to every NAT UI, KeyShortcutSystem
This commit is contained in:
@@ -9,7 +9,7 @@ typedef PrefixMapHandler<T> = (Map<String, ShortcutKey<T>>) -> Void;
|
|||||||
typedef ItemHandler<T> = (T) -> Void;
|
typedef ItemHandler<T> = (T) -> Void;
|
||||||
typedef FinishHandler = () -> Void;
|
typedef FinishHandler = () -> Void;
|
||||||
typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;
|
typedef BadKeyHandler<T> = (String, PrefixMap<T>) -> Void;
|
||||||
typedef BadShortcutHandler<T> = (String,ShortcutKey<T>) -> Void;
|
typedef BadShortcutHandler<T> = (String, ShortcutKey<T>) -> Void;
|
||||||
|
|
||||||
enum ShortcutKey<T> {
|
enum ShortcutKey<T> {
|
||||||
Final(item:T);
|
Final(item:T);
|
||||||
|
@@ -83,4 +83,3 @@
|
|||||||
(method :Void registerItem [description :T item]
|
(method :Void registerItem [description :T item]
|
||||||
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
(whenLet [keyboardShortcut (extractKeyboardShortcuts description)]
|
||||||
(registerShortcut (keyboardShortcut.split "") description item)))
|
(registerShortcut (keyboardShortcut.split "") description item)))
|
||||||
|
|
||||||
|
@@ -11,6 +11,7 @@
|
|||||||
"main": "nat.CLI",
|
"main": "nat.CLI",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"kiss": "",
|
"kiss": "",
|
||||||
|
"kiss-tools": "",
|
||||||
"tink_json": ""
|
"tink_json": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -160,6 +160,8 @@
|
|||||||
(archive.addSystem (new RemarkableAPISystem))
|
(archive.addSystem (new RemarkableAPISystem))
|
||||||
(archive.addSystem (new WikipediaImageSystem))
|
(archive.addSystem (new WikipediaImageSystem))
|
||||||
(archive.addSystem (new ImageAttachmentSystem))
|
(archive.addSystem (new ImageAttachmentSystem))
|
||||||
|
(archive.addSystem (new KeyShortcutSystem this))
|
||||||
|
|
||||||
// Just for testing:
|
// Just for testing:
|
||||||
// (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))
|
// (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@
|
|||||||
(defCommand CreateMediaEntries [medium (Text null) names (VarText null)]
|
(defCommand CreateMediaEntries [medium (Text null) names (VarText null)]
|
||||||
// createEntry returns a list, so these lists must be flattened
|
// createEntry returns a list, so these lists must be flattened
|
||||||
(flatten (for name names
|
(flatten (for name names
|
||||||
(CreateEntry name))))
|
(CreateMediaEntry medium name))))
|
||||||
|
|
||||||
// TODO use Tag and VarTag arg types for AddTags and RemoveTags
|
// TODO use Tag and VarTag arg types for AddTags and RemoveTags
|
||||||
(defCommand AddTags [entries (SelectedEntries 1 null)
|
(defCommand AddTags [entries (SelectedEntries 1 null)
|
||||||
@@ -214,6 +216,14 @@
|
|||||||
(removeTags archive e tagsToRemove))
|
(removeTags archive e tagsToRemove))
|
||||||
entries) // TODO this includes entries that didn't have the tag in the changeset
|
entries) // TODO this includes entries that didn't have the tag in the changeset
|
||||||
|
|
||||||
|
(defCommand AddKeyShortcut [e SelectedEntry description (Text null)]
|
||||||
|
(addComponent archive e KeyShortcut description))
|
||||||
|
|
||||||
|
(defCommand AddNATCommand [e (SelectedEntries null null) command (Text null)]
|
||||||
|
(doFor e e (addComponent archive e NATCommand command)))
|
||||||
|
|
||||||
|
(defCommand AddNATCommands [e (SelectedEntries null null) commands (VarText null)]
|
||||||
|
(doFor e e (addComponent archive e NATCommands commands)))
|
||||||
|
|
||||||
(defCommand AddFiles [entries (SelectedEntries 1 null)
|
(defCommand AddFiles [entries (SelectedEntries 1 null)
|
||||||
// TODO add File and Files as an argument type for commands, ArchiveUI
|
// TODO add File and Files as an argument type for commands, ArchiveUI
|
||||||
|
@@ -1,6 +1,8 @@
|
|||||||
package nat;
|
package nat;
|
||||||
|
|
||||||
|
import nat.Entry;
|
||||||
import nat.ArchiveController;
|
import nat.ArchiveController;
|
||||||
|
import kiss_tools.KeyShortcutHandler;
|
||||||
|
|
||||||
interface ArchiveUI {
|
interface ArchiveUI {
|
||||||
/**
|
/**
|
||||||
@@ -8,6 +10,11 @@ interface ArchiveUI {
|
|||||||
*/
|
*/
|
||||||
var controller(default, default):ArchiveController;
|
var controller(default, default):ArchiveController;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A KeyShortcutHandler that will integrate with the KeyShortcutSystem if provided
|
||||||
|
*/
|
||||||
|
var shortcutHandler(default, null):Null<KeyShortcutHandler<Entry>>;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prompt the user to enter text
|
* Prompt the user to enter text
|
||||||
*/
|
*/
|
||||||
|
@@ -13,6 +13,7 @@
|
|||||||
(controller.tryRunCommand command))))
|
(controller.tryRunCommand command))))
|
||||||
|
|
||||||
(prop &mut :ArchiveController controller)
|
(prop &mut :ArchiveController controller)
|
||||||
|
(prop :KeyShortcutHandler<Entry> shortcutHandler null)
|
||||||
|
|
||||||
(defNew [])
|
(defNew [])
|
||||||
|
|
||||||
|
@@ -0,0 +1,3 @@
|
|||||||
|
package nat.components;
|
||||||
|
|
||||||
|
typedef KeyShortcut = String;
|
@@ -0,0 +1,3 @@
|
|||||||
|
package nat.components;
|
||||||
|
|
||||||
|
typedef NATCommand = String;
|
@@ -0,0 +1,3 @@
|
|||||||
|
package nat.components;
|
||||||
|
|
||||||
|
typedef NATCommands = Array<NATCommand>;
|
@@ -0,0 +1,7 @@
|
|||||||
|
package nat.systems;
|
||||||
|
|
||||||
|
import kiss.Prelude;
|
||||||
|
import kiss.List;
|
||||||
|
|
||||||
|
@:build(kiss.Kiss.build())
|
||||||
|
class KeyShortcutSystem extends System {}
|
@@ -0,0 +1,32 @@
|
|||||||
|
(load "../Lib.kiss")
|
||||||
|
|
||||||
|
(prop :Map<String,Bool> descriptions (new Map))
|
||||||
|
|
||||||
|
(defNew [&prop :ArchiveController controller]
|
||||||
|
[&mut :Bool setup false]
|
||||||
|
(super
|
||||||
|
->[archive e]
|
||||||
|
(hasComponent e KeyShortcut)
|
||||||
|
->[archive e &opt ui]
|
||||||
|
{
|
||||||
|
(when (and ui ui.shortcutHandler)
|
||||||
|
(unless setup
|
||||||
|
(set ui.shortcutHandler.onSelectItem (invokeEntry.bind archive ui))
|
||||||
|
(set ui.shortcutHandler.onBadKey ->[key map] (ui.displayMessage "$key is not mapped to a shortcut in this context: $map"))
|
||||||
|
(set setup true))
|
||||||
|
|
||||||
|
(unless (descriptions.exists (readComponent e KeyShortcut))
|
||||||
|
(ui.shortcutHandler.registerItem (readComponent e KeyShortcut) e)
|
||||||
|
(dictSet descriptions (readComponent e KeyShortcut) true)))
|
||||||
|
0
|
||||||
|
}))
|
||||||
|
|
||||||
|
(method invokeEntry [archive ui :Entry e]
|
||||||
|
// TODO make this doCond
|
||||||
|
(cond
|
||||||
|
((hasComponent e NATCommand)
|
||||||
|
(controller.tryRunCommand (readComponent e NATCommand)) 0)
|
||||||
|
((hasComponent e NATCommands)
|
||||||
|
// TODO chain them together asynchronously (they may be partial)
|
||||||
|
0)
|
||||||
|
(true (ui.displayMessage "tried to invoke ${e.id} but it has no available actions"))) 0)
|
@@ -38,6 +38,7 @@
|
|||||||
<haxelib name="flixel" />
|
<haxelib name="flixel" />
|
||||||
|
|
||||||
<haxelib name="kiss" />
|
<haxelib name="kiss" />
|
||||||
|
<haxelib name="kiss-tools" />
|
||||||
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
<haxeflag name="--macro" value="kiss.Kiss.setup()" />
|
||||||
|
|
||||||
<haxelib name="kiss-flixel" />
|
<haxelib name="kiss-flixel" />
|
||||||
|
@@ -19,6 +19,8 @@ import flixel.addons.plugin.FlxMouseControl;
|
|||||||
import flixel.input.mouse.FlxMouseEventManager;
|
import flixel.input.mouse.FlxMouseEventManager;
|
||||||
using StringTools;
|
using StringTools;
|
||||||
using kiss_flixel.CameraTools;
|
using kiss_flixel.CameraTools;
|
||||||
|
import kiss_tools.KeyShortcutHandler;
|
||||||
|
import kiss_tools.FlxKeyShortcutHandler;
|
||||||
|
|
||||||
@:build(kiss.Kiss.build())
|
@:build(kiss.Kiss.build())
|
||||||
class PlayState extends FlxState implements ArchiveUI {}
|
class PlayState extends FlxState implements ArchiveUI {}
|
||||||
|
@@ -21,6 +21,7 @@
|
|||||||
archive
|
archive
|
||||||
this)))
|
this)))
|
||||||
|
|
||||||
|
(prop :KeyShortcutHandler<Entry> shortcutHandler (new FlxKeyShortcutHandler<Entry>))
|
||||||
|
|
||||||
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
(prop &mut :FlxGroup uiGroup (new FlxGroup))
|
||||||
(add uiGroup)
|
(add uiGroup)
|
||||||
@@ -105,9 +106,13 @@
|
|||||||
(archive.processSystems this)
|
(archive.processSystems this)
|
||||||
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
(FlxG.camera.calculateScrollBounds entryGroup SCROLL_BOUND_MARGIN))
|
||||||
|
|
||||||
|
(defAlias &ident sh (cast shortcutHandler FlxKeyShortcutHandler<Dynamic>))
|
||||||
(method &override :Void update [:Float elapsed]
|
(method &override :Void update [:Float elapsed]
|
||||||
(super.update elapsed)
|
(super.update elapsed)
|
||||||
|
|
||||||
|
(when sh.currentMap
|
||||||
|
(sh.update))
|
||||||
|
|
||||||
(spriteDepthSystem.process archive)
|
(spriteDepthSystem.process archive)
|
||||||
|
|
||||||
(when FlxG.keys.justPressed.ESCAPE
|
(when FlxG.keys.justPressed.ESCAPE
|
||||||
@@ -142,6 +147,11 @@
|
|||||||
|
|
||||||
(FlxG.camera.updateScrollWheelZoom elapsed 1)
|
(FlxG.camera.updateScrollWheelZoom elapsed 1)
|
||||||
|
|
||||||
|
// Don't check keys that can be used in shortcuts outside this block:
|
||||||
|
(unless sh.currentMap
|
||||||
|
(when FlxG.keys.justPressed.SEMICOLON
|
||||||
|
(sh.start)
|
||||||
|
(return))
|
||||||
// +/- keys to change an entry's z
|
// +/- keys to change an entry's z
|
||||||
(doFor e (controller.getSelectedEntries)
|
(doFor e (controller.getSelectedEntries)
|
||||||
(when FlxG.keys.justPressed.MINUS
|
(when FlxG.keys.justPressed.MINUS
|
||||||
@@ -161,7 +171,7 @@
|
|||||||
->{FlxG.keys.pressed.A}
|
->{FlxG.keys.pressed.A}
|
||||||
->{FlxG.keys.pressed.D}
|
->{FlxG.keys.pressed.D}
|
||||||
->{FlxG.keys.pressed.W}
|
->{FlxG.keys.pressed.W}
|
||||||
->{FlxG.keys.pressed.S}))))
|
->{FlxG.keys.pressed.S})))))
|
||||||
|
|
||||||
(method :Void typeCommand []
|
(method :Void typeCommand []
|
||||||
(enterText
|
(enterText
|
||||||
|
Reference in New Issue
Block a user