diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index 66875e5d2..15a296bce 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -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, + }, }, }