Add KeyShortcutHandler to every NAT UI, KeyShortcutSystem
This commit is contained in:
@@ -160,6 +160,8 @@
|
||||
(archive.addSystem (new RemarkableAPISystem))
|
||||
(archive.addSystem (new WikipediaImageSystem))
|
||||
(archive.addSystem (new ImageAttachmentSystem))
|
||||
(archive.addSystem (new KeyShortcutSystem this))
|
||||
|
||||
// Just for testing:
|
||||
// (archive.addSystem (new AttachmentSystem ["jpg" "jpeg" "png"] ->[archive e files] ~files))
|
||||
|
||||
@@ -199,7 +201,7 @@
|
||||
(defCommand CreateMediaEntries [medium (Text null) names (VarText null)]
|
||||
// createEntry returns a list, so these lists must be flattened
|
||||
(flatten (for name names
|
||||
(CreateEntry name))))
|
||||
(CreateMediaEntry medium name))))
|
||||
|
||||
// TODO use Tag and VarTag arg types for AddTags and RemoveTags
|
||||
(defCommand AddTags [entries (SelectedEntries 1 null)
|
||||
@@ -214,7 +216,15 @@
|
||||
(removeTags archive e tagsToRemove))
|
||||
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)
|
||||
// TODO add File and Files as an argument type for commands, ArchiveUI
|
||||
// TODO make tkinter file browser externs and use tkinter as the file picking mechanism for CLI
|
||||
|
@@ -1,6 +1,8 @@
|
||||
package nat;
|
||||
|
||||
import nat.Entry;
|
||||
import nat.ArchiveController;
|
||||
import kiss_tools.KeyShortcutHandler;
|
||||
|
||||
interface ArchiveUI {
|
||||
/**
|
||||
@@ -8,6 +10,11 @@ interface ArchiveUI {
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@@ -13,6 +13,7 @@
|
||||
(controller.tryRunCommand command))))
|
||||
|
||||
(prop &mut :ArchiveController controller)
|
||||
(prop :KeyShortcutHandler<Entry> shortcutHandler null)
|
||||
|
||||
(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)
|
Reference in New Issue
Block a user