defaults(refactor): remove global hack in filemanagersetdefaults

also added screensaver folder setting dialog for kobo
pull/2045/head
Qingping Hou 8 years ago
parent f5b0f0dcd7
commit 60587e08c6

@ -157,7 +157,6 @@ function FileManager:init()
callback = function()
renameFile(file)
self:refreshPath()
fileManager.rename_dialog:onClose()
UIManager:close(fileManager.rename_dialog)
end,
},
@ -165,13 +164,10 @@ function FileManager:init()
text = _("Cancel"),
enabled = true,
callback = function()
fileManager.rename_dialog:onClose()
UIManager:close(fileManager.rename_dialog)
end,
},
}},
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
fileManager.rename_dialog:onShowKeyboard()
UIManager:show(fileManager.rename_dialog)

@ -83,7 +83,6 @@ end
function FileSearcher:close()
if self.search_value then
self.search_dialog:onClose()
UIManager:close(self.search_dialog)
if string.len(self.search_value) > 0 then
self:readDir() -- TODO this probably doesn't need to be repeated once it's been done
@ -131,8 +130,6 @@ function FileSearcher:showSearch()
},
},
},
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.search_dialog:onShowKeyboard()
UIManager:show(self.search_dialog)

@ -2,10 +2,11 @@ local CenterContainer = require("ui/widget/container/centercontainer")
local InputContainer = require("ui/widget/container/inputcontainer")
local ConfirmBox = require("ui/widget/confirmbox")
local UIManager = require("ui/uimanager")
local Device = require("device")
local GestureRange = require("ui/gesturerange")
local InputDialog = require("ui/widget/inputdialog")
local Geom = require("ui/geometry")
local Screen = require("device").screen
local Device = require("device")
local Screen = Device.screen
local DEBUG = require("dbg")
local _ = require("gettext")
local FileSearcher = require("apps/filemanager/filemanagerfilesearcher")
@ -14,7 +15,7 @@ local SetDefaults = require("apps/filemanager/filemanagersetdefaults")
local FileManagerMenu = InputContainer:extend{
tab_item_table = nil,
registered_widgets = {},
registered_widgets = nil,
}
function FileManagerMenu:init()
@ -93,8 +94,12 @@ function FileManagerMenu:setUpdateItemTable()
})
table.insert(self.tab_item_table.setting, {
text = _("Start with last opened file"),
checked_func = function() return G_reader_settings:readSetting("open_last") end,
enabled_func = function() return G_reader_settings:readSetting("lastfile") ~= nil end,
checked_func = function() return
G_reader_settings:readSetting("open_last")
end,
enabled_func = function() return
G_reader_settings:readSetting("lastfile") ~= nil
end,
callback = function()
local open_last = G_reader_settings:readSetting("open_last") or false
G_reader_settings:saveSetting("open_last", not open_last)
@ -112,6 +117,43 @@ function FileManagerMenu:setUpdateItemTable()
end
-- tools tab
if Device.isKobo() then
table.insert(self.tab_item_table.tools, {
text = _("Screen server folder"),
callback = function()
local ss_folder_path_input
local function save_folder_path()
G_reader_settings:saveSetting(
"screensaver_folder", ss_folder_path_input:getInputText())
UIManager:close(ss_folder_path_input)
end
local curr_path = G_reader_settings:readSetting("screensaver_folder")
ss_folder_path_input = InputDialog:new{
title = _("Screen saver folder"),
input = curr_path,
input_hint = "/mnt/onboard/screensaver",
input_type = "text",
buttons = {
{
{
text = _("Cancel"),
callback = function()
UIManager:close(ss_folder_path_input)
end,
},
{
text = _("Save"),
callback = save_folder_path,
},
}
},
enter_callback = save_folder_path,
}
ss_folder_path_input:onShowKeyboard()
UIManager:show(ss_folder_path_input)
end,
})
end
table.insert(self.tab_item_table.tools, {
text = _("Advanced settings"),
callback = function()

@ -125,7 +125,7 @@ function Search:getCalibre()
self.use_own_metadata_file = false
if self.metafile_1 then
pcall(lfs.mkdir("temp"))
if io.open(koreaderfile,"r") then
if io.open(koreaderfile, "r") then
if lfs.attributes(koreaderfile).modification > lfs.attributes(self.metafile_1).modification then
if self.metafile_2 then
if lfs.attributes(koreaderfile).modification > lfs.attributes(self.metafile_2).modification then
@ -443,7 +443,9 @@ function Search:find(option)
end
g.close()
if lfs.attributes(koreaderfile).modification < lfs.attributes(self.metafile_1).modification then
lfs.touch(koreaderfile, lfs.attributes(self.metafile_1).modification + 1, lfs.attributes(self.metafile_1).modification + 1)
lfs.touch(koreaderfile,
lfs.attributes(self.metafile_1).modification + 1,
lfs.attributes(self.metafile_1).modification + 1)
end
if self.metafile_2 then
if lfs.attributes(koreaderfile).modification < lfs.attributes(self.metafile_2).modification then

@ -10,41 +10,23 @@ local Screen = require("device").screen
local Menu = require("ui/widget/menu")
local Font = require("ui/font")
local util = require("ffi/util")
local DEBUG = require("dbg")
local _ = require("gettext")
local dump = require("dump")
local defaults_path = DataStorage:getDataDir() .. "/defaults.lua"
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
local SetDefaults = InputContainer:new{
defaults_name = {},
defaults_value = {},
results = {},
defaults_menu = {},
already_read = false,
initialized = false,
changed = {}
}
local function settype(b,t)
if t == "boolean" then
if b == "false" then return false else return true end
else
return b
end
end
local function getTableValues(t,dtap)
local dummy = "{"
for n,v in pairs(t) do
if dtap:sub(1,4) == "DTAP" or dtap:sub(1,11) == "DDOUBLE_TAP" then
dummy = dummy .. tostring(n) .. " = " .. tostring(v) .. ", "
elseif tonumber(v) then
dummy = dummy .. tostring(v) .. ", "
else
dummy = dummy .. "\"" .. tostring(v) .. "\", "
end
end
dummy = dummy:sub(1,string.len(dummy) - 2) .. "}"
return dummy
end
function SetDefaults:ConfirmEdit()
if not SetDefaults.EditConfirmed then
UIManager:show(ConfirmBox:new{
@ -62,21 +44,20 @@ end
function SetDefaults:init()
self.results = {}
if not self.already_read then
local i = 0
for n,v in util.orderedPairs(_G) do
if (not string.find(tostring(v), "<")) and (not string.find(tostring(v), ": ")) and string.sub(n,1,1) ~= "_" and string.upper(n) == n and n ~= "LIBRARY_PATH" then
i = i + 1
self.defaults_name[i] = n
self.defaults_value[i] = v
end
if string.find(tostring(v), "table: ") and string.upper(n) == n and n ~= "ARGV" and n ~= "_G" then
i = i + 1
self.defaults_name[i] = n
self.defaults_value[i] = getTableValues(v,n)
end
if not self.initialized then
local defaults = {}
local load_defaults = loadfile(defaults_path)
setfenv(load_defaults, defaults)
load_defaults()
local i = 1
for n, v in util.orderedPairs(defaults) do
self.defaults_name[i] = n
self.defaults_value[i] = v
i = i + 1
end
self.already_read = true
self.initialized = true
end
local menu_container = CenterContainer:new{
@ -102,176 +83,163 @@ function SetDefaults:init()
UIManager:close(menu_container)
end
for i=1,#self.defaults_name do
local cancel_button = {
text = _("Cancel"),
enabled = true,
callback = function()
self:close()
UIManager:show(menu_container)
end,
}
for i=1, #self.defaults_name do
self.changed[i] = false
local settings_type = type(_G[self.defaults_name[i]])
if settings_type == "boolean" then
local setting_name = self.defaults_name[i]
local setting_type = type(_G[setting_name])
if setting_type == "boolean" then
local editBoolean = function()
self.set_dialog = InputDialog:new{
title = setting_name,
input = tostring(self.defaults_value[i]),
buttons = {
{
cancel_button,
{
text = "true",
enabled = true,
callback = function()
self.defaults_value[i] = true
_G[setting_name] = true
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
end
},
{
text = "false",
enabled = true,
callback = function()
self.defaults_value[i] = false
_G[setting_name] = false
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self.defaults_menu:swithItemTable("Defaults", self.results, i)
self:close()
UIManager:show(menu_container)
end
},
},
},
input_type = setting_type,
width = Screen:getWidth() * 0.95,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
table.insert(self.results, {
text = self:build_setting(i),
callback = function()
self.set_dialog = InputDialog:new{
title = self.defaults_name[i] .. ":",
input = tostring(self.defaults_value[i]),
buttons = {
callback = editBoolean
})
elseif setting_type == "table" then
local editTable = function()
local fields = {}
for k, v in util.orderedPairs(_G[setting_name]) do
table.insert(fields, {
text = tostring(k) .. " = " .. tostring(v),
hint = "",
})
end
self.set_dialog = MultiInputDialog:new{
title = setting_name,
fields = fields,
buttons = {
{
cancel_button,
{
{
text = _("Cancel"),
enabled = true,
callback = function()
self:close()
UIManager:show(menu_container)
text = _("OK"),
enabled = true,
callback = function()
local new_table = {}
for _, field in ipairs(MultiInputDialog:getFields()) do
new_table[field:match("^[^= ]+")] = field:match("[^= ]+$")
end
},
{
text = "true",
enabled = true,
callback = function()
self.defaults_value[i] = true
_G[self.defaults_name[i]] = true
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
_G[setting_name] = new_table
self.defaults_value[i] = _G[setting_name]
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
end,
},
},
},
input_type = "number",
width = Screen:getWidth() * 0.95,
height = Screen:getHeight() * 0.2,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
table.insert(self.results, {
text = self:build_setting(i),
callback = editTable
})
else
local editNumStr = function()
self.set_dialog = InputDialog:new{
title = setting_name,
input = tostring(self.defaults_value[i]),
buttons = {
{
cancel_button,
{
text = _("OK"),
enabled = true,
callback = function()
local new_value = self.set_dialog:getInputText()
if setting_type == "boolean" then
if new_value == "true" then
new_value = true
else
new_value = false
end
end
},
{
text = "false",
enabled = true,
callback = function()
self.defaults_value[i] = false
_G[self.defaults_name[i]] = false
if _G[setting_name] ~= new_value then
_G[setting_name] = new_value
self.defaults_value[i] = new_value
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self.defaults_menu:swithItemTable("Defaults", self.results, i)
self:close()
UIManager:show(menu_container)
end
},
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
end,
},
},
input_type = settings_type,
width = Screen:getWidth() * 0.95,
height = Screen:getHeight() * 0.2,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
})
else
if type(_G[self.defaults_name[i]]) == "table" then
table.insert(self.results, {
text = self:build_setting(i),
callback = function()
local fields = {}
for m, n in util.orderedPairs(_G[self.defaults_name[i]]) do
table.insert(fields, {
text = tostring(m) .. " = " .. tostring(n),
hint = "",
})
end
self.set_dialog = MultiInputDialog:new{
title = self.defaults_name[i] .. ":",
fields = fields,
buttons = {
{
{
text = _("Cancel"),
enabled = true,
callback = function()
self:close()
UIManager:show(menu_container)
end,
},
{
text = _("OK"),
enabled = true,
callback = function()
local fields = {}
for _, field in ipairs(MultiInputDialog:getFields()) do
fields[field:match("^[^= ]+")] = field:match("[^= ]+$")
end
_G[self.defaults_name[i]] = fields
self.defaults_value[i] = "{"
DEBUG(_G[self.defaults_name[i]])
for k,v in util.orderedPairs(_G[self.defaults_name[i]]) do
if tonumber(k) then
self.defaults_value[i] = self.defaults_value[i] .. v .. ", "
else
self.defaults_value[i] = self.defaults_value[i] .. k .. " = " .. v .. ", "
end
end
self.defaults_value[i] = self.defaults_value[i]:sub(1,self.defaults_value[i]:len()-2) .. "}"
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
end,
},
},
},
input_type = "number",
width = Screen:getWidth() * 0.95,
height = Screen:getHeight() * 0.2,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
})
else
table.insert(self.results, {
text = self:build_setting(i),
callback = function()
self.set_dialog = InputDialog:new{
title = self.defaults_name[i] .. ":",
input = tostring(self.defaults_value[i]),
buttons = {
{
{
text = _("Cancel"),
enabled = true,
callback = function()
self:close()
UIManager:show(menu_container)
end,
},
{
text = _("OK"),
enabled = true,
callback = function()
if type(_G[self.defaults_name[i]]) == "table" then
self.defaults_value[i] = self.set_dialog:getInputText()
elseif _G[self.defaults_name[i]] ~= settype(self.set_dialog:getInputText(),settings_type) then
_G[self.defaults_name[i]] = settype(self.set_dialog:getInputText(),settings_type)
self.defaults_value[i] = _G[self.defaults_name[i]]
end
settings_changed = true
self.changed[i] = true
self.results[i].text = self:build_setting(i)
self:close()
self.defaults_menu:swithItemTable("Defaults", self.results, i)
UIManager:show(menu_container)
end,
},
},
},
input_type = settings_type,
width = Screen:getWidth() * 0.95,
height = Screen:getHeight() * 0.2,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
})
},
input_type = setting_type,
width = Screen:getWidth() * 0.95,
}
self.set_dialog:onShowKeyboard()
UIManager:show(self.set_dialog)
end
table.insert(self.results, {
text = self:build_setting(i),
callback = editNumStr
})
end
end
self.defaults_menu:swithItemTable("Defaults", self.results)
@ -279,13 +247,12 @@ function SetDefaults:init()
end
function SetDefaults:close()
self.set_dialog:onClose()
UIManager:close(self.set_dialog)
end
function SetDefaults:ConfirmSave()
UIManager:show(ConfirmBox:new{
text = _("Are you sure you want to save the settings to \"defaults.persistent.lua\"?"),
text = _('Are you sure you want to save the settings to "defaults.persistent.lua"?'),
ok_callback = function()
self:SaveSettings()
end,
@ -293,73 +260,64 @@ function SetDefaults:ConfirmSave()
end
function SetDefaults:build_setting(j)
local ret = self.defaults_name[j] .. " = "
if type(_G[self.defaults_name[j]]) == "boolean" or type(_G[self.defaults_name[j]]) == "table" then
ret = ret .. tostring(self.defaults_value[j])
local setting_name = self.defaults_name[j]
local ret = setting_name .. " = "
if type(_G[setting_name]) == "boolean" then
return ret .. tostring(self.defaults_value[j])
elseif type(_G[setting_name]) == "table" then
return ret .. "{...}"
elseif tonumber(self.defaults_value[j]) then
ret = ret .. tostring(tonumber(self.defaults_value[j]))
return ret .. tostring(tonumber(self.defaults_value[j]))
else
ret = ret .. "\"" .. tostring(self.defaults_value[j]) .. "\""
return ret .. "\"" .. tostring(self.defaults_value[j]) .. "\""
end
return ret
end
function SetDefaults:SaveSettings()
local function fileread(filename,array)
local file = io.open(filename)
local line = file:read()
local counter = 0
while line do
counter = counter + 1
local i = string.find(line,"[-][-]") -- remove comments from file
if (i or 0)>1 then line = string.sub(line,1,i-1) end
array[counter] = line:gsub("^%s*(.-)%s*$", "%1") -- trim
line = file:read()
end
file:close()
end
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
local file
if io.open(persistent_filename,"r") == nil then
file = io.open(persistent_filename, "w")
file:write("-- For configuration changes that persists between (nightly) releases\n")
self.results = {}
local persisted_defaults = {}
local file = io.open(persistent_filename, "r")
if file ~= nil then
file:close()
local load_defaults = loadfile(persistent_filename)
setfenv(load_defaults, persisted_defaults)
load_defaults()
end
local dpl = {}
fileread(persistent_filename, dpl)
local dl = {}
fileread("defaults.lua",dl)
self.results = {}
local done = {}
for j=1,#SetDefaults.defaults_name do
if not self.changed[j] then done[j] = true end
local checked = {}
for j=1, #self.defaults_name do
if not self.changed[j] then checked[j] = true end
end
-- handle case "found in persistent", replace it
for i = 1,#dpl do
for j=1,#SetDefaults.defaults_name do
if not done[j] and string.find(dpl[i],SetDefaults.defaults_name[j] .. " ") == 1 then
dpl[i] = self:build_setting(j)
done[j] = true
-- handle case "found in persistent" and changed, replace it
for k, v in pairs(persisted_defaults) do
for j=1, #self.defaults_name do
if not checked[j]
and k == self.defaults_name[j] then
persisted_defaults[k] = self.defaults_value[j]
checked[j] = true
end
end
end
-- handle case "not in persistent and different in non-persistent", add to persistent
for j=1,#SetDefaults.defaults_name do
if not done[j] then
dpl[#dpl+1] = self:build_setting(j)
-- handle case "not in persistent and different in non-persistent", add to
-- persistent
for j=1, #self.defaults_name do
if not checked[j] then
persisted_defaults[self.defaults_name[j]] = self.defaults_value[j]
end
end
file = io.open(persistent_filename, "w")
if file then
for i = 1,#dpl do
file:write(dpl[i] .. "\n")
file:write("-- For configuration changes that persists between updates\n")
for k, v in pairs(persisted_defaults) do
local line = {}
table.insert(line, k)
table.insert(line, " = ")
table.insert(line, dump(v))
table.insert(line, "\n")
file:write(table.concat(line))
end
file:close()
UIManager:show(InfoMessage:new{
@ -368,4 +326,5 @@ function SetDefaults:SaveSettings()
end
settings_changed = false
end
return SetDefaults

@ -116,8 +116,6 @@ function ReaderFrontLight:onShowFlDialog()
},
},
input_type = "number",
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.fl_dialog:onShowKeyboard()
UIManager:show(self.fl_dialog)

@ -1,7 +1,6 @@
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Event = require("ui/event")
local _ = require("gettext")
@ -58,15 +57,12 @@ function ReaderGoto:onShowGotoDialog()
},
input_type = "number",
enter_callback = function() self:gotoPage() end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.goto_dialog:onShowKeyboard()
UIManager:show(self.goto_dialog)
end
function ReaderGoto:close()
self.goto_dialog:onClose()
UIManager:close(self.goto_dialog)
end

@ -426,8 +426,6 @@ function ReaderUI:unlockDocumentWithPassword(document, try_again)
},
},
text_type = "password",
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.password_dialog:onShowKeyboard()
UIManager:show(self.password_dialog)

@ -4,6 +4,7 @@ simple serialization function, won't do uservalues, functions, loops
local isUbuntuTouch = os.getenv("UBUNTU_APPLICATION_ISOLATION") ~= nil
local insert = table.insert
local indent_prefix = " "
local function _serialize(what, outt, indent, max_lv, history)
if not max_lv then
@ -19,7 +20,7 @@ local function _serialize(what, outt, indent, max_lv, history)
for up, item in ipairs(history) do
if item == what then
insert(outt, "nil --[[ LOOP:\n")
insert(outt, string.rep("\t", indent - up))
insert(outt, string.rep(indent_prefix, indent - up))
insert(outt, "^------- ]]")
return
end
@ -32,7 +33,7 @@ local function _serialize(what, outt, indent, max_lv, history)
insert(outt, ",")
end
insert(outt, "\n")
insert(outt, string.rep("\t", indent+1))
insert(outt, string.rep(indent_prefix, indent+1))
insert(outt, "[")
_serialize(k, outt, indent+1, max_lv, new_history)
insert(outt, "] = ")
@ -41,7 +42,7 @@ local function _serialize(what, outt, indent, max_lv, history)
end
if didrun then
insert(outt, "\n")
insert(outt, string.rep("\t", indent))
insert(outt, string.rep(indent_prefix, indent))
end
insert(outt, "}")
elseif type(what) == "string" then

@ -545,15 +545,12 @@ function BookStatusWidget:onSwitchFocus(inputbox)
enter_callback = function()
self:closeInputDialog()
end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.note_dialog:onShowKeyboard()
UIManager:show(self.note_dialog)
end
function BookStatusWidget:closeInputDialog()
self.note_dialog:onClose()
UIManager:close(self.note_dialog)
end

@ -1,6 +1,5 @@
local WidgetContainer = require("ui/widget/container/widgetcontainer")
local UIManager = require("ui/uimanager")
local Screen = require("device").screen
local Geom = require("ui/geometry")
local Event = require("ui/event")
local _ = require("gettext")
@ -128,15 +127,12 @@ function InputContainer:onInput(input)
input.callback(self.input_dialog:getInputText())
self:closeInputDialog()
end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog)
end
function InputContainer:closeInputDialog()
self.input_dialog:onClose()
UIManager:close(self.input_dialog)
end

@ -424,8 +424,6 @@ function DictQuickLookup:lookupInputWord(hint)
self:closeInputDialog()
self:inputLookup()
end,
width = Screen:getWidth() * 0.8,
height = Screen:getHeight() * 0.2,
}
self.input_dialog:onShowKeyboard()
UIManager:show(self.input_dialog)
@ -440,7 +438,6 @@ function DictQuickLookup:inputLookup()
end
function DictQuickLookup:closeInputDialog()
self.input_dialog:onClose()
UIManager:close(self.input_dialog)
end

@ -1,3 +1,40 @@
--[[--
Widget for taking user input.
Example:
local _ = require("gettext")
local UIManager = require("ui/uimanager")
local sample_input
local saveHandler = function()
print('Got user input:', sample_input:getInputText())
end
sample_input = InputDialog:new{
title = _("Dialog title"),
input = "default value",
input_hint = "hint text",
input_type = "text",
buttons = {
{
{
text = _("Cancel"),
callback = function()
UIManager:close(sample_input)
end,
},
{
text = _("Save"),
callback = saveHandler,
},
}
},
enter_callback = saveHandler,
}
sample_input:onShowKeyboard()
UIManager:show(sample_input)
]]
local InputContainer = require("ui/widget/container/inputcontainer")
local FrameContainer = require("ui/widget/container/framecontainer")
local CenterContainer = require("ui/widget/container/centercontainer")
@ -38,6 +75,7 @@ local InputDialog = InputContainer:new{
}
function InputDialog:init()
self.width = self.width or Screen:getWidth() * 0.8
local title_width = RenderText:sizeUtf8Text(0, self.width,
self.title_face, self.title, true).x
if title_width > self.width then
@ -78,7 +116,6 @@ function InputDialog:init()
show_parent = self,
}
self.title_bar = LineWidget:new{
--background = Blitbuffer.gray(0.5),
dimen = Geom:new{
w = self.button_table:getSize().w + self.button_padding,
h = Screen:scaleBySize(2),
@ -138,6 +175,7 @@ function InputDialog:onShow()
end
function InputDialog:onCloseWidget()
self:onClose()
UIManager:setDirty(nil, function()
return "partial", self.dialog_frame.dimen
end)

@ -40,7 +40,7 @@ function MultiInputDialog:init()
scroll = false,
parent = self,
}
table.insert(VerticalGroupData,CenterContainer:new{
table.insert(VerticalGroupData, CenterContainer:new{
dimen = Geom:new{
w = self.title_bar:getSize().w,
h = input_field[k]:getSize().h,

@ -0,0 +1,90 @@
describe("defaults module", function()
local Defaults, DataStorage
setup(function()
require("commonrequire")
Defaults = require("apps/filemanager/filemanagersetdefaults")
DataStorage = require("datastorage")
end)
it("should load all defaults from defaults.lua", function()
Defaults:init()
assert.is_same(#Defaults.defaults_name, 78)
assert.is_same(Defaults.defaults_name[29], 'DHINTCOUNT')
end)
it("should save changes to defaults.persistent.lua", function()
local persistent_filename = DataStorage:getDataDir() .. "/defaults.persistent.lua"
os.remove(persistent_filename)
-- not in persistent but checked in defaults
Defaults.changed[14] = true
Defaults.changed[19] = true
Defaults.changed[29] = true
Defaults.changed[64] = true
Defaults.changed[78] = true
Defaults:SaveSettings()
assert.is_same(#Defaults.defaults_name, 78)
assert.is_same(Defaults.defaults_name[29], 'DHINTCOUNT')
assert.is_same(Defaults.defaults_name[78], 'SEARCH_TITLE')
assert.is_same(Defaults.defaults_name[64], 'DTAP_ZONE_MENU')
assert.is_same(Defaults.defaults_name[19], 'DCREREADER_VIEW_MODE')
assert.is_same(Defaults.defaults_name[14],
'DCREREADER_CONFIG_MARGIN_SIZES_LARGE')
local fd = io.open(persistent_filename, "r")
assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
[1] = 20,
[2] = 20,
[3] = 20,
[4] = 20
}
DCREREADER_VIEW_MODE = "page"
DHINTCOUNT = 1
DTAP_ZONE_MENU = {
["y"] = 0,
["x"] = 0.125,
["h"] = 0.25,
["w"] = 0.75
}
]],
fd:read("*a"))
fd:close()
-- in persistent
Defaults:init()
Defaults.changed[29] = true
Defaults.defaults_value[29] = 2
Defaults.changed[64] = true
Defaults.defaults_value[64] = {
y = 10,
x = 10.125,
h = 20.25,
w = 20.75
}
Defaults:SaveSettings()
fd = io.open(persistent_filename)
assert.Equals(
[[-- For configuration changes that persists between updates
SEARCH_TITLE = true
DHINTCOUNT = 2
DTAP_ZONE_MENU = {
["y"] = 10,
["x"] = 10.125,
["h"] = 20.25,
["w"] = 20.75
}
DCREREADER_CONFIG_MARGIN_SIZES_LARGE = {
[1] = 20,
[2] = 20,
[3] = 20,
[4] = 20
}
DCREREADER_VIEW_MODE = "page"
]],
fd:read("*a"))
fd:close()
os.remove(persistent_filename)
end)
end)
Loading…
Cancel
Save