Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash when deleting a flightlog entry #5768

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions data/modules/FlightLog/FlightLogEntries.lua
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ function FlightLogEntry.Base:GetEntry()
return self.entry
end

---@return boolean true if this has a Delete() method
function FlightLogEntry.Base:SupportsDelete()
---@return boolean true if this can be removed from the flightlog method
function FlightLogEntry.Base:CanBeRemoved()
return false
end

Expand Down Expand Up @@ -303,17 +303,10 @@ function FlightLogEntry.Custom:GetDataPairs( earliest_first )
end

---@return boolean true if this has a Delete() method
function FlightLogEntry.Custom:SupportsDelete()
function FlightLogEntry.Custom:CanBeRemoved()
return true
end

---Delete this entry
---@return nil
function FlightLogEntry.Custom:Delete()
FlightLogEntry.TotalDefaultElements = FlightLogEntry.TotalDefaultElements - 1
utils.remove_elem( FlightLogData, self )
end

---@class FlightLogEntry.Station : FlightLogEntry.Base
---@field systemp SystemPath The system the player is in when the log was written
---@field time deptime The game time the log was made, on departure from teh system, relative to the epoch
Expand Down
4 changes: 2 additions & 2 deletions data/pigui/modules/info-view/06-flightlog.lua
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@ local function renderLog( formatter )
ui.nextColumn()
end

if entry:SupportsDelete() then
if entry:CanBeRemoved() then
if ui.iconButton(icons.trashcan, buttonSpaceSize, l.REMOVE .. "##custom" .. counter) then
entry:Delete()
FlightLog:RemoveEntry( entry )
-- if we were already in edit mode, reset it, or else it carries over to next iteration
entering_text = false
end
Expand Down