2
0
mirror of https://github.com/koreader/koreader synced 2024-11-18 03:25:46 +00:00
koreader/frontend/ui/elements/file_ext_assoc.lua
Martín Fernández 2263931b99
Pocketbook misc fixes (#6633)
After the awesome work made by @ezdiy:

- Remove empty dir from release zip
- Remove misc files (txt, md, html, gif) to prevent displaying them in PB library
- Do not asociate executable files (sh and py for the moment), just openable files
- Rename the font sample from html to template (to prevent wiping it during clean)
2020-09-12 10:47:35 +02:00

78 lines
1.9 KiB
Lua

local Device = require("device")
local _ = require("gettext")
local function getSupportedExtensions()
local t = require("document/documentregistry"):getExtensions()
t["sh"] = nil
t["py"] = nil
return t
end
local ExtAssoc = {
assoc = G_reader_settings:readSetting("file_ext_assoc") or {},
}
function ExtAssoc:commit()
G_reader_settings:saveSetting("file_ext_assoc", self.assoc):flush()
-- Translate the boolean map back to map of providers the OS backend can inquire further
local t = {}
for k, v in pairs(getSupportedExtensions()) do
if self.assoc[k] then t[k] = v end
end
Device:associateFileExtensions(t)
end
function ExtAssoc:setAll(state)
for k, dummy in pairs(getSupportedExtensions()) do
self:setOne(k, state)
end
self:commit()
end
function ExtAssoc:setOne(ext, state)
self.assoc[ext] = state and true or nil
end
function ExtAssoc:getSettingsMenuTable()
local ret = {
{
keep_menu_open = true,
text = _("Enable all"),
callback = function(menu)
self:setAll(true)
menu:updateItems()
end,
},
{
keep_menu_open = true,
text = _("Disable all"),
callback = function(menu)
self:setAll(false)
menu:updateItems()
end,
separator = true,
},
}
local exts = getSupportedExtensions()
local keys = {}
for k, dummy in pairs(exts) do
table.insert(keys, k)
end
table.sort(keys)
for dummy, k in ipairs(keys) do
table.insert(ret, {
keep_menu_open = true,
text = k,
checked_func = function() return self.assoc[k] end,
callback = function()
self:setOne(k, not self.assoc[k])
self:commit()
end
})
end
return ret
end
return ExtAssoc