onSelectionChanged UI event
This commit is contained in:
@@ -3,16 +3,16 @@
|
||||
(method :Void _collectAndValidateArg [:CommandArg arg :Dynamic->Void continuation]
|
||||
(case arg.type
|
||||
(SelectedEntry
|
||||
(if (= 1 selectedEntries.length)
|
||||
(continuation (first selectedEntries))
|
||||
(ui.reportError "The requested command expects 1 entry to be selected. You have selected: $selectedEntries.length")))
|
||||
(if (= 1 _selectedEntries.length)
|
||||
(continuation (first _selectedEntries))
|
||||
(ui.reportError "The requested command expects 1 entry to be selected. You have selected: $_selectedEntries.length")))
|
||||
((SelectedEntries min max)
|
||||
(unless min (set min 0))
|
||||
// TODO might want to optimize this O(n) count operation by pre-calculating it
|
||||
(unless max (set max (count archive.entries)))
|
||||
(if !(<= min selectedEntries.length max)
|
||||
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $selectedEntries.length")
|
||||
(continuation selectedEntries)))
|
||||
(if !(<= min _selectedEntries.length max)
|
||||
(ui.reportError "The requested command expects between $min and $max entries to be selected. You have selected: $_selectedEntries.length")
|
||||
(continuation _selectedEntries)))
|
||||
((Text maxLength)
|
||||
(unless maxLength (set maxLength Math.POSITIVE_INFINITY))
|
||||
(ui.enterText
|
||||
@@ -113,14 +113,12 @@
|
||||
(set lastCollector (_composeArgCollector collectedArgs arg lastCollector)))
|
||||
(lastCollector)))
|
||||
|
||||
|
||||
(defMacro defCommand [name args &body body]
|
||||
(let [argPairs
|
||||
(groups (expList args) 2)
|
||||
methodArgs
|
||||
(for [name type] argPairs
|
||||
// TODO write an exprCase macro that simplifies this terrible mess,
|
||||
// and maybe adds back precise pattern matching instead of relying
|
||||
// on partial string matching
|
||||
(exprCase type
|
||||
((exprOr SelectedEntry OneEntry) `:nat.Entry ,name)
|
||||
((exprOr (SelectedEntries _ _) (Entries _ _)) `:Array<nat.Entry> ,name)
|
||||
@@ -139,10 +137,12 @@
|
||||
|
||||
(var :Array<String> commandNames [])
|
||||
|
||||
(method isSelected [:Entry e]
|
||||
!(= -1 (_selectedEntries.indexOf e)))
|
||||
|
||||
(defNew [&prop :Archive archive
|
||||
&prop :ArchiveUI ui]
|
||||
[&mut :Array<Entry> selectedEntries []
|
||||
[&mut :Array<Entry> _selectedEntries []
|
||||
&mut :ChangeSet lastChangeSet []
|
||||
:Map<String,Command> commands (new Map)
|
||||
:NameSystem nameSystem (new NameSystem)]
|
||||
@@ -163,21 +163,28 @@
|
||||
(+ "Available commands:\n"
|
||||
(commandNames.join "\n"))) [])
|
||||
|
||||
(method selectionCommand [entries]
|
||||
(let [lastSelectedEntries _selectedEntries]
|
||||
(set _selectedEntries entries)
|
||||
(ui.onSelectionChanged entries lastSelectedEntries)) [])
|
||||
|
||||
(defCommand SelectEntry [e OneEntry]
|
||||
(set selectedEntries [e]) [])
|
||||
(selectionCommand [e]))
|
||||
|
||||
(defCommand ToggleEntrySelection [e OneEntry]
|
||||
(unless (selectedEntries.remove e)
|
||||
(selectedEntries.push e)) [])
|
||||
(let [newSelection (_selectedEntries.copy)]
|
||||
(unless (newSelection.remove e)
|
||||
(newSelection.push e))
|
||||
(selectionCommand newSelection)))
|
||||
|
||||
(defCommand SelectEntries [entries (Entries null null)]
|
||||
(set selectedEntries entries) [])
|
||||
(selectionCommand entries) [])
|
||||
|
||||
(defCommand SelectAllEntries []
|
||||
(set selectedEntries (for =>id e archive.entries e)) [])
|
||||
(selectionCommand (for =>id e archive.entries e)))
|
||||
|
||||
(defCommand SelectLastChangeSet []
|
||||
(set selectedEntries lastChangeSet) [])
|
||||
(selectionCommand lastChangeSet))
|
||||
|
||||
(defCommand PrintSelectedEntries [entries (SelectedEntries null null)]
|
||||
(doFor e entries (ui.displayMessage (archive.fullString e))) [])
|
||||
|
@@ -42,4 +42,9 @@ interface ArchiveUI {
|
||||
* Tell the user that something is wrong
|
||||
*/
|
||||
function reportError(error:String):Void;
|
||||
|
||||
/**
|
||||
* Update UI to show that the set of selected entries has changed
|
||||
*/
|
||||
function onSelectionChanged(selectedEntries:Array<Entry>, lastSelectedEntries:Array<Entry>):Void;
|
||||
}
|
||||
|
@@ -90,3 +90,7 @@
|
||||
|
||||
(method :Void reportError [error]
|
||||
(print error))
|
||||
|
||||
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> _]
|
||||
(print "Selected:")
|
||||
(controller.PrintSelectedEntries selectedEntries))
|
||||
|
@@ -22,12 +22,10 @@
|
||||
(enableMouseDrag)
|
||||
}))
|
||||
|
||||
// TODO add onEntrySelected(), onEntryDeselected() callback to ArchiveUI and use these to change color if SelectByName or SelectByTags are used on an Entry that has a sprite in the entryspritesystem's dictionary
|
||||
(set mousePressedCallback
|
||||
->[self _x _y]
|
||||
{
|
||||
(controller.ToggleEntrySelection e)
|
||||
(updateColor)
|
||||
})
|
||||
(set mouseStopDragCallback
|
||||
->[self _dx _dy]
|
||||
@@ -35,7 +33,7 @@
|
||||
(dictSet positions positionKey (object x (cast this.x Float) y (cast this.y Float) z 0.0)))))
|
||||
|
||||
(method updateColor []
|
||||
(if !(= -1 (controller.selectedEntries.indexOf e))
|
||||
(if (controller.isSelected e)
|
||||
{
|
||||
(set color FlxColor.BLUE)
|
||||
}
|
||||
|
@@ -208,3 +208,8 @@
|
||||
(let [text (new FlxText 0 0 0 (error.replace "\n" "|"))]
|
||||
(text.setFormat null 8 FlxColor.RED)
|
||||
(showUI text)))
|
||||
|
||||
(method :Void onSelectionChanged [:Array<Entry> selectedEntries :Array<Entry> lastSelectedEntries]
|
||||
(doFor e (selectedEntries.concat lastSelectedEntries)
|
||||
(whenLet [sprite (dictGet spriteSystem.sprites e.id)]
|
||||
(sprite.updateColor))))
|
Reference in New Issue
Block a user