dfhack
dfhack copied to clipboard
Make setting `FilteredList.edit.setText('')` optional in `FilteredList:setChoices`?
I ran into a situation where this line of code was causing me some confusion.
I have a script that has a bunch of tabs that determine the current "view" and "subview". For e.g. Citizens -> Adults, Animals -> Wild. There is a single FilteredList
that displays the units matching the filters determined by view/subview + a filter that the user provides in the FilteredList.edit
.
The FilteredList
has an edit_on_change
callback that stores the value of the filter when it is changed. The purpose of this is to keep track of the current filter as you switch between views and restore them. So in the above screenshot, if I click away to a different tab and then switch back to Citizens -> Adults, I want the filter to be "adil" again.
When I switch views, I call FilteredList:setChoices(newChoices)
. This causes FilteredList.edit.setText('')
to be executed, which causes edit_on_change
to trigger which is causing my filter cache to be updated to ''
for that view/subview as well.
I think it should maybe be possible to call this method without resetting the edit value.
One way I can think to work around this for now would be to set some global variable before I call FilteredList:setChoices(newChoices)
, check the value in my edit_on_change
callback to determine if it should be executed, then set the value back after the call.