FileChooser: add new sorting method (#11369)

"percent - unopened - finished last"
(ie. 90% > 50% > 0% > unopened > 100%)
reviewable/pr11463/r1^2
hasezoey 2 months ago committed by GitHub
parent 5d4747c593
commit 76980098ec
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -206,6 +206,42 @@ local FileChooser = Menu:extend{
return item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
end,
},
percent_natural = {
-- sort 90% > 50% > 0% > unopened > 100%
text = _("percent - unopened - finished last"),
menu_order = 90,
can_collate_mixed = false,
init_sort_func = function(cache)
local natsort
natsort, cache = sort.natsort_cmp(cache)
local sortfunc = function(a, b)
if a.percent_finished == b.percent_finished then
return natsort(a.text, b.text)
elseif a.percent_finished == 1 then
return false
elseif b.percent_finished == 1 then
return true
else
return a.percent_finished > b.percent_finished
end
end
return sortfunc, cache
end,
item_func = function(item)
local percent_finished
item.opened = DocSettings:hasSidecarFile(item.path)
if item.opened then
local doc_settings = DocSettings:open(item.path)
percent_finished = doc_settings:readSetting("percent_finished")
end
-- smooth 2 decimal points (0.00) instead of 16 decimal numbers
item.percent_finished = math.floor((percent_finished or -1) * 100) / 100
end,
mandatory_func = function(item)
return item.opened and string.format("%d %%", 100 * item.percent_finished) or ""
end,
},
},
}

Loading…
Cancel
Save