From 0aa19d72a09a5ad56a8d42a104470ab04c624b64 Mon Sep 17 00:00:00 2001 From: poire-z Date: Sat, 3 Dec 2016 14:19:35 +0100 Subject: [PATCH] FileManager: show files with sidecar dir in bold (#2391) docsettings : added hasSidecarDir() and made getSidecarDir() more robust widget/menu : allow items to specify themselves to be displayed in bold --- frontend/docsettings.lua | 16 +++++++++++++++- frontend/ui/widget/filechooser.lua | 7 +++++++ frontend/ui/widget/menu.lua | 2 +- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/frontend/docsettings.lua b/frontend/docsettings.lua index 8ecfeb486..6a0419ccf 100644 --- a/frontend/docsettings.lua +++ b/frontend/docsettings.lua @@ -17,7 +17,21 @@ end -- Sidecar directory is the file without _last_ suffix. function DocSettings:getSidecarDir(doc_path) - return doc_path:match("(.*)%.")..".sdr" + local file_without_suffix = doc_path:match("(.*)%.") + if file_without_suffix then + return file_without_suffix..".sdr" + end + -- We shouldn't be called with anything but files with registered + -- extensions, but in case we are, return something useful + return doc_path..".sdr" +end + +function DocSettings:hasSidecarDir(doc_path) + -- We may be called with items from FileManager, which may not be a document + if lfs.attributes(doc_path, "mode") == "directory" then + return false + end + return lfs.attributes(self:getSidecarDir(doc_path), "mode") == "directory" end function DocSettings:getHistoryPath(fullpath) diff --git a/frontend/ui/widget/filechooser.lua b/frontend/ui/widget/filechooser.lua index c5ae74794..41a8efe97 100644 --- a/frontend/ui/widget/filechooser.lua +++ b/frontend/ui/widget/filechooser.lua @@ -3,6 +3,7 @@ local UIManager = require("ui/uimanager") local Menu = require("ui/widget/menu") local Screen = require("device").screen local Device = require("device") +local DocSettings = require("docsettings") local util = require("ffi/util") local _ = require("gettext") local ffi = require("ffi") @@ -128,9 +129,15 @@ function FileChooser:genItemTableFromPath(path) else sstr = string.format("%d B", file_size) end + -- show files with a .sdr in bold + local bold = nil + if DocSettings:hasSidecarDir(full_path) then + bold = true + end table.insert(item_table, { text = file.name, mandatory = sstr, + bold = bold, path = full_path }) end diff --git a/frontend/ui/widget/menu.lua b/frontend/ui/widget/menu.lua index 3362d8032..176d18a85 100644 --- a/frontend/ui/widget/menu.lua +++ b/frontend/ui/widget/menu.lua @@ -648,7 +648,7 @@ function Menu:updateItems(select_number) state_size = self.state_size or {}, text = self.item_table[i].text, mandatory = self.item_table[i].mandatory, - bold = self.item_table.current == i, + bold = self.item_table.current == i or self.item_table[i].bold == true, face = self.cface, dimen = self.item_dimen:new(), shortcut = item_shortcut,