From 03c669d2cdff8541f66d8c3fdca38de4f695c6cf Mon Sep 17 00:00:00 2001 From: hasezoey Date: Sat, 30 Mar 2024 12:14:09 +0100 Subject: [PATCH] FileChooser: collates: apply code review to not use "sort_percent" for simple percent sort > I think that in the first two cases we do not need sort_percent, we can "smooth" percent_finished and use it for sorting and for displaying. re #11592 --- frontend/ui/widget/filechooser.lua | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index e6fcaebf3..592f867f5 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -158,7 +158,7 @@ local FileChooser = Menu:extend{ return function(a, b) if a.opened == b.opened then if a.opened then - return a.sort_percent < b.sort_percent + return a.percent_finished < b.percent_finished end return ffiUtil.strcoll(a.text, b.text) end @@ -173,10 +173,8 @@ local FileChooser = Menu:extend{ percent_finished = doc_settings:readSetting("percent_finished") end - percent_finished = percent_finished or 0 -- smooth 2 decimal points (0.00) instead of 16 decimal points - item.sort_percent = util.round_decimal(percent_finished, 2) - item.percent_finished = percent_finished + item.percent_finished = util.round_decimal(percent_finished or 0, 2) end, mandatory_func = function(item) return item.opened and string.format("%d %%", 100 * item.percent_finished) or "–" @@ -190,7 +188,7 @@ local FileChooser = Menu:extend{ return function(a, b) if a.opened == b.opened then if a.opened then - return a.sort_percent < b.sort_percent + return a.percent_finished < b.percent_finished end return ffiUtil.strcoll(a.text, b.text) end @@ -205,10 +203,8 @@ local FileChooser = Menu:extend{ percent_finished = doc_settings:readSetting("percent_finished") end - percent_finished = percent_finished or 0 -- smooth 2 decimal points (0.00) instead of 16 decimal points - item.sort_percent = util.round_decimal(percent_finished, 2) - item.percent_finished = percent_finished + item.percent_finished = util.round_decimal(percent_finished or 0, 2) end, mandatory_func = function(item) return item.opened and string.format("%d %%", 100 * item.percent_finished) or "–"