@@ -25,8 +25,6 @@ local Screen = Device.screen
2525
2626local logger = require (" logger" )
2727
28- local menu_patched = false
29-
3028local FolderCover = {
3129 name = " .cover" ,
3230 exts = { " .jpg" , " .jpeg" , " .png" , " .webp" , " .gif" },
@@ -82,12 +80,20 @@ local orig_FileChooser_getListItem = FileChooser.getListItem
8280local cached_list = {}
8381
8482function FileChooser :getListItem (dirpath , f , fullpath , attributes , collate )
85- local key = toKey (dirpath , f , fullpath , attributes , collate )
86- cached_list [key ] = cached_list [key ]
87- or orig_FileChooser_getListItem (self , dirpath , f , fullpath , attributes , collate )
83+ local key = toKey (dirpath , f , fullpath , attributes , collate , self .show_filter .status )
84+ cached_list [key ] = cached_list [key ] or orig_FileChooser_getListItem (self , dirpath , f , fullpath , attributes , collate )
8885 return cached_list [key ]
8986end
9087
88+ -- local orig_FileChooser_genItemTableFromPath = FileChooser.genItemTableFromPath
89+
90+ -- function FileChooser:genItemTableFromPath(path)
91+ -- local start = os.clock()
92+ -- local item_table = orig_FileChooser_genItemTableFromPath(self, path)
93+ -- logger.info("!!!!!!! GEN", path, (os.clock() - start) * 1000)
94+ -- return item_table
95+ -- end
96+
9197local function capitalize (sentence )
9298 local words = {}
9399 for word in sentence :gmatch (" %S+" ) do
@@ -119,12 +125,12 @@ local function patchCoverBrowser(plugin)
119125 local BookInfoManager = userpatch .getUpValue (MosaicMenuItem .update , " BookInfoManager" )
120126 local original_update = MosaicMenuItem .update
121127
122- -- settings
128+ -- setting
123129 function BooleanSetting (text , name , default )
124130 self = { text = text }
125131 self .get = function ()
126132 local setting = BookInfoManager :getSetting (name )
127- if default then return not setting end
133+ if default then return not setting end -- false is stored as nil, so we need or own logic for boolean default
128134 return setting
129135 end
130136 self .toggle = function () return BookInfoManager :toggleSetting (name ) end
@@ -136,11 +142,10 @@ local function patchCoverBrowser(plugin)
136142 name_centered = BooleanSetting (_ (" Folder name centered" ), " folder_name_centered" , true ),
137143 }
138144
145+ -- cover item
139146 function MosaicMenuItem :update (...)
140147 original_update (self , ... )
141- if self ._foldercover_processed or self .menu .no_refresh_covers or not self .do_cover_image then
142- return
143- end
148+ if self ._foldercover_processed or self .menu .no_refresh_covers or not self .do_cover_image then return end
144149
145150 if self .entry .is_file or self .entry .file or not self .mandatory then return end -- it's a file
146151 local dir_path = self .entry and self .entry .path
@@ -180,11 +185,7 @@ local function patchCoverBrowser(plugin)
180185 and not bookinfo .ignore_cover
181186 and not BookInfoManager .isCachedCoverInvalid (bookinfo , self .menu .cover_specs )
182187 then
183- self :_setFolderCover {
184- data = bookinfo .cover_bb ,
185- w = bookinfo .cover_w ,
186- h = bookinfo .cover_h ,
187- }
188+ self :_setFolderCover { data = bookinfo .cover_bb , w = bookinfo .cover_w , h = bookinfo .cover_h }
188189 break
189190 end
190191 end
@@ -204,8 +205,7 @@ local function patchCoverBrowser(plugin)
204205 img_options .width = target .w
205206 img_options .height = target .h
206207 else
207- local _ , _ , scale_factor = BookInfoManager .getCachedCoverSize (img .w , img .h , target .w , target .h )
208- img_options .scale_factor = scale_factor
208+ img_options .scale_factor = math.min (target .w / img .w , target .h / img .h )
209209 end
210210
211211 local image = ImageWidget :new (img_options )
@@ -216,55 +216,62 @@ local function patchCoverBrowser(plugin)
216216 local size = nbitems :getSize ()
217217 local nb_size = math.max (size .w , size .h )
218218
219- local widget = VerticalGroup :new {
220- VerticalSpan :new { width = math.max (0 , math.ceil ((self .height - (top_h + dimen .h )) * 0.5 )) },
221- LineWidget :new {
222- background = Folder .edge .color ,
223- dimen = { w = math.floor (dimen .w * (Folder .edge .width ^ 2 )), h = Folder .edge .thick },
224- },
225- VerticalSpan :new { width = Folder .edge .margin },
226- LineWidget :new {
227- background = Folder .edge .color ,
228- dimen = { w = math.floor (dimen .w * Folder .edge .width ), h = Folder .edge .thick },
229- },
230- VerticalSpan :new { width = Folder .edge .margin },
231- OverlapGroup :new {
232- dimen = { w = self .width , h = self .height - top_h },
233- FrameContainer :new {
234- padding = 0 ,
235- bordersize = Folder .face .border_size ,
236- image ,
237- overlap_align = " center" ,
219+ local widget = CenterContainer :new {
220+ dimen = { w = self .width , h = self .height },
221+ VerticalGroup :new {
222+ VerticalSpan :new { width = math.max (0 , math.ceil ((self .height - (top_h + dimen .h )) * 0.5 )) },
223+ LineWidget :new {
224+ background = Folder .edge .color ,
225+ dimen = { w = math.floor (dimen .w * (Folder .edge .width ^ 2 )), h = Folder .edge .thick },
238226 },
239- (settings .name_centered .get () and CenterContainer or TopContainer ):new {
240- dimen = dimen ,
227+ VerticalSpan :new { width = Folder .edge .margin },
228+ LineWidget :new {
229+ background = Folder .edge .color ,
230+ dimen = { w = math.floor (dimen .w * Folder .edge .width ), h = Folder .edge .thick },
231+ },
232+ VerticalSpan :new { width = Folder .edge .margin },
233+ OverlapGroup :new {
234+ dimen = { w = self .width , h = self .height - top_h },
241235 FrameContainer :new {
242236 padding = 0 ,
243237 bordersize = Folder .face .border_size ,
244- AlphaContainer :new { alpha = Folder .face .alpha , directory },
238+ image ,
239+ overlap_align = " center" ,
245240 },
246- overlap_align = " center" ,
247- },
248- BottomContainer :new {
249- dimen = dimen ,
250- RightContainer :new {
251- dimen = {
252- w = dimen .w - Folder .face .nb_items_margin ,
253- h = nb_size + Folder .face .nb_items_margin * 2 + math.ceil (nb_size * 0.125 ),
254- },
241+ (settings .name_centered .get () and CenterContainer or TopContainer ):new {
242+ dimen = dimen ,
255243 FrameContainer :new {
256244 padding = 0 ,
257- padding_bottom = math.ceil (nb_size * 0.125 ),
258- radius = math.ceil (nb_size * 0.5 ),
259- background = Blitbuffer .COLOR_WHITE ,
260- CenterContainer :new { dimen = { w = nb_size , h = nb_size }, nbitems },
245+ bordersize = Folder .face .border_size ,
246+ AlphaContainer :new { alpha = Folder .face .alpha , directory },
247+ },
248+ overlap_align = " center" ,
249+ },
250+ BottomContainer :new {
251+ dimen = dimen ,
252+ RightContainer :new {
253+ dimen = {
254+ w = dimen .w - Folder .face .nb_items_margin ,
255+ h = nb_size + Folder .face .nb_items_margin * 2 + math.ceil (nb_size * 0.125 ),
256+ },
257+ FrameContainer :new {
258+ padding = 0 ,
259+ padding_bottom = math.ceil (nb_size * 0.125 ),
260+ radius = math.ceil (nb_size * 0.5 ),
261+ background = Blitbuffer .COLOR_WHITE ,
262+ CenterContainer :new { dimen = { w = nb_size , h = nb_size }, nbitems },
263+ },
261264 },
265+ overlap_align = " center" ,
262266 },
263- overlap_align = " center" ,
264267 },
265268 },
266269 }
267- if self ._underline_container [1 ] then self ._underline_container [1 ]:free (true ) end
270+ if self ._underline_container [1 ] then
271+ local previous_widget = self ._underline_container [1 ]
272+ previous_widget :free ()
273+ end
274+
268275 self ._underline_container [1 ] = widget
269276 end
270277
@@ -312,20 +319,28 @@ local function patchCoverBrowser(plugin)
312319
313320 function plugin :addToMainMenu (menu_items )
314321 orig_CoverBrowser_addToMainMenu (self , menu_items )
315- if menu_items .filebrowser_settings == nil or menu_patched then return end
316- menu_patched = true
322+ if menu_items .filebrowser_settings == nil then return end
317323
318324 local item = getMenuItem (menu_items .filebrowser_settings , _ (" Mosaic and detailed list settings" ))
319325 if item then
320- for _ , setting in pairs (settings ) do
321- table.insert (item .sub_item_table , {
322- text = setting .text ,
323- checked_func = function () return setting .get () end ,
324- callback = function ()
325- setting .toggle ()
326- self .ui .file_chooser :updateItems ()
327- end ,
328- })
326+ item .sub_item_table [# item .sub_item_table ].separator = true
327+ for i , setting in pairs (settings ) do
328+ if
329+ not getMenuItem ( -- already exists ?
330+ menu_items .filebrowser_settings ,
331+ _ (" Mosaic and detailed list settings" ),
332+ setting .text
333+ )
334+ then
335+ table.insert (item .sub_item_table , {
336+ text = setting .text ,
337+ checked_func = function () return setting .get () end ,
338+ callback = function ()
339+ setting .toggle ()
340+ self .ui .file_chooser :updateItems ()
341+ end ,
342+ })
343+ end
329344 end
330345 end
331346 end
0 commit comments