Skip to content

Commit

Permalink
Merge pull request #4063 from myk002/myk_tasks_crash
Browse files Browse the repository at this point in the history
[sort] handle case where jobs are manually removed from the tasks screen
  • Loading branch information
myk002 authored Nov 27, 2023
2 parents 18c4ce0 + b63e99e commit b6a49fb
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 6 deletions.
1 change: 1 addition & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ Template for new versions:
- `sort`: search and sort for the "choose unit to elevate to the barony" screen. units are sorted by the number of item preferences they have and the units are annotated with the items that they have preferences for

## Fixes
- `sort`: fix potential crash when removing jobs directly from the Tasks info screen

## Misc Improvements
- wherever units are listed in DFHack tools, properties like "agitated" or (-trained-) are now shown
Expand Down
40 changes: 34 additions & 6 deletions plugins/lua/sort/info.lua
Original file line number Diff line number Diff line change
Expand Up @@ -436,20 +436,48 @@ function InfoOverlay:updateFrames()
return true
end

function InfoOverlay:do_refresh()
self.refresh_search = nil
if self:get_key() == 'JOBS' then
local data = self.state.JOBS
-- if any jobs have been canceled, fix up our data vectors
if data and data.saved_visible and data.saved_original then
local to_remove = {}
for _,elem in ipairs(data.saved_visible) do
if not utils.linear_index(tasks.cri_job, elem) then
table.insert(to_remove, elem)
end
end
for _,elem in ipairs(to_remove) do
table.remove(data.saved_visible, utils.linear_index(data.saved_visible, elem))
data.saved_visible_size = data.saved_visible_size - 1
table.remove(data.saved_original, utils.linear_index(data.saved_original, elem))
data.saved_original_size = data.saved_original_size - 1
end
end
end
self:do_search(self.subviews.search.text, true)
end

function InfoOverlay:onRenderBody(dc)
if self.refresh_search then
self:do_refresh()
end
InfoOverlay.super.onRenderBody(self, dc)
if self:updateFrames() then
self:updateLayout()
end
if self.refresh_search then
self.refresh_search = nil
self:do_search(self.subviews.search.text)
end
end

function InfoOverlay:onInput(keys)
if keys._MOUSE_L and self:get_key() == 'WORK_DETAILS' then
self.refresh_search = true
if self.refresh_search then
self:do_refresh()
end
if keys._MOUSE_L then
local key = self:get_key()
if key == 'WORK_DETAILS' or key == 'JOBS' then
self.refresh_search = true
end
end
return InfoOverlay.super.onInput(self, keys)
end
Expand Down

0 comments on commit b6a49fb

Please sign in to comment.