More versatile selection commands
This commit is contained in:
@@ -166,28 +166,7 @@
|
|||||||
(+ "Available commands:\n"
|
(+ "Available commands:\n"
|
||||||
(commandNames.join "\n"))) [])
|
(commandNames.join "\n"))) [])
|
||||||
|
|
||||||
(method selectionCommand [entries]
|
(load "SelectionCommands.kiss")
|
||||||
(let [lastSelectedEntries _selectedEntries]
|
|
||||||
(set _selectedEntries entries)
|
|
||||||
(ui.onSelectionChanged entries lastSelectedEntries)) [])
|
|
||||||
|
|
||||||
(defCommand SelectEntry [e OneEntry]
|
|
||||||
(selectionCommand [e]))
|
|
||||||
|
|
||||||
(defCommand ToggleEntrySelection [e OneEntry]
|
|
||||||
(let [newSelection (_selectedEntries.copy)]
|
|
||||||
(unless (newSelection.remove e)
|
|
||||||
(newSelection.push e))
|
|
||||||
(selectionCommand newSelection)))
|
|
||||||
|
|
||||||
(defCommand SelectEntries [entries (Entries null null)]
|
|
||||||
(selectionCommand entries) [])
|
|
||||||
|
|
||||||
(defCommand SelectAllEntries []
|
|
||||||
(selectionCommand (for =>id e archive.entries e)))
|
|
||||||
|
|
||||||
(defCommand SelectLastChangeSet []
|
|
||||||
(selectionCommand lastChangeSet))
|
|
||||||
|
|
||||||
(defCommand PrintSelectedEntries [entries (SelectedEntries null null)]
|
(defCommand PrintSelectedEntries [entries (SelectedEntries null null)]
|
||||||
(doFor e entries (ui.displayMessage (archive.fullString e))) [])
|
(doFor e entries (ui.displayMessage (archive.fullString e))) [])
|
||||||
@@ -220,11 +199,6 @@
|
|||||||
(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 SelectByTags [tagsBoolExp (Text null)]
|
|
||||||
(SelectEntries (filter archive.entries ->e (tagsMatch archive e tagsBoolExp))))
|
|
||||||
|
|
||||||
(defCommand SelectByComponents [componentsBoolExp (Text null)]
|
|
||||||
(SelectEntries (filter archive.entries ->e (componentsMatch e componentsBoolExp))))
|
|
||||||
|
|
||||||
(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
|
||||||
@@ -254,7 +228,4 @@
|
|||||||
(withWritableComponents archive e [scaleComponent Scale]
|
(withWritableComponents archive e [scaleComponent Scale]
|
||||||
(set scaleComponent scale))
|
(set scaleComponent scale))
|
||||||
(addComponent archive e Scale scale)))
|
(addComponent archive e Scale scale)))
|
||||||
entries)
|
entries))
|
||||||
|
|
||||||
(defCommand SelectByName [name (Text null)]
|
|
||||||
(SelectEntries (nameSystem.getEntries name)) []))
|
|
||||||
|
|||||||
71
projects/nat-archive-tool/src/nat/SelectionCommands.kiss
Normal file
71
projects/nat-archive-tool/src/nat/SelectionCommands.kiss
Normal file
@@ -0,0 +1,71 @@
|
|||||||
|
// Every command that can select entries has variants that can toggleSelect,
|
||||||
|
// addSelect or deSelect instead of setting the selection directly
|
||||||
|
|
||||||
|
// TODO The three varations of selection are all O(n) when they would't need to be if _selectedEntries was a Map
|
||||||
|
// TODO these commands could avoid calling onSelectionChanged if they don't actually modify the selection
|
||||||
|
|
||||||
|
(method selectionCommand [:Array<Entry> entries]
|
||||||
|
(let [lastSelectedEntries _selectedEntries]
|
||||||
|
(set _selectedEntries entries)
|
||||||
|
(ui.onSelectionChanged entries lastSelectedEntries)) [])
|
||||||
|
|
||||||
|
(method addSelectionCommand [:Array<Entry> entries]
|
||||||
|
(let [lastSelectedEntries (_selectedEntries.copy)]
|
||||||
|
(doFor e entries
|
||||||
|
(unless (_selectedEntries.contains e)
|
||||||
|
(_selectedEntries.push e)))
|
||||||
|
(ui.onSelectionChanged _selectedEntries lastSelectedEntries)) [])
|
||||||
|
|
||||||
|
(method deSelectionCommand [:Array<Entry> entries]
|
||||||
|
(let [lastSelectedEntries (_selectedEntries.copy)]
|
||||||
|
(doFor e entries
|
||||||
|
(_selectedEntries.remove e))
|
||||||
|
(ui.onSelectionChanged _selectedEntries lastSelectedEntries)) [])
|
||||||
|
|
||||||
|
(method toggleSelectionCommand [:Array<Entry> entries]
|
||||||
|
(let [lastSelectedEntries (_selectedEntries.copy)]
|
||||||
|
(doFor e entries
|
||||||
|
(unless (_selectedEntries.remove e)
|
||||||
|
(_selectedEntries.push e)))
|
||||||
|
(ui.onSelectionChanged _selectedEntries lastSelectedEntries)) [])
|
||||||
|
|
||||||
|
// Define all 4 variants of the command that selects according to the behavior in body
|
||||||
|
(defMacro defSelectCommand [name args &body body]
|
||||||
|
(let [nameStr (symbolNameValue name)
|
||||||
|
addName (symbol "Add$nameStr")
|
||||||
|
deSelectName (symbol "De$nameStr")
|
||||||
|
toggleName (symbol "Toggle$nameStr")]
|
||||||
|
`{
|
||||||
|
(defCommand ,name ,args
|
||||||
|
(selectionCommand {,@body}))
|
||||||
|
|
||||||
|
(defCommand ,addName ,args
|
||||||
|
(addSelectionCommand {,@body}))
|
||||||
|
|
||||||
|
(defCommand ,deSelectName ,args
|
||||||
|
(deSelectionCommand {,@body}))
|
||||||
|
|
||||||
|
(defCommand ,toggleName ,args
|
||||||
|
(toggleSelectionCommand {,@body}))
|
||||||
|
}))
|
||||||
|
|
||||||
|
(defSelectCommand SelectEntry [e OneEntry]
|
||||||
|
[e])
|
||||||
|
|
||||||
|
(defSelectCommand SelectEntries [entries (Entries null null)]
|
||||||
|
entries)
|
||||||
|
|
||||||
|
(defSelectCommand SelectAllEntries []
|
||||||
|
(for =>id e archive.entries e))
|
||||||
|
|
||||||
|
(defSelectCommand SelectLastChangeSet []
|
||||||
|
lastChangeSet)
|
||||||
|
|
||||||
|
(defSelectCommand SelectByTags [tagsBoolExp (Text null)]
|
||||||
|
(filter archive.entries ->e (tagsMatch archive e tagsBoolExp)))
|
||||||
|
|
||||||
|
(defSelectCommand SelectByComponents [componentsBoolExp (Text null)]
|
||||||
|
(filter archive.entries ->e (componentsMatch e componentsBoolExp)))
|
||||||
|
|
||||||
|
(defSelectCommand SelectByName [name (Text null)]
|
||||||
|
(nameSystem.getEntries name))
|
||||||
@@ -25,7 +25,7 @@
|
|||||||
(set mousePressedCallback
|
(set mousePressedCallback
|
||||||
->[self _x _y]
|
->[self _x _y]
|
||||||
{
|
{
|
||||||
(controller.ToggleEntrySelection e)
|
(controller.ToggleSelectEntry e)
|
||||||
})
|
})
|
||||||
(set mouseStopDragCallback
|
(set mouseStopDragCallback
|
||||||
->[self _dx _dy]
|
->[self _dx _dy]
|
||||||
|
|||||||
Reference in New Issue
Block a user