<commit_before>local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local MultiInputDialog = require("ui/widget/multiinputdialog")
local ConfirmBox = require("ui/widget/confirmbox")
local CenterContainer = require("ui/widget/container/centercontainer")
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 SetDefaults = InputContainer:new{
    defaults_name = {},
    defaults_value = {},
    results = {},
    defaults_menu = {},
    already_read = 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{
            text = _("Some changes will just work on the next restart. Wrong settings might crash KOReader! Continue?"),
            ok_callback = function()
                self.EditConfirmed = true
                self:init()
            end,
        })
    else
        self:init()
    end
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<commit_msg>Improved SetDefaults dialog message.<commit_after>local InfoMessage = require("ui/widget/infomessage")
local UIManager = require("ui/uimanager")
local InputContainer = require("ui/widget/container/inputcontainer")
local InputDialog = require("ui/widget/inputdialog")
local MultiInputDialog = require("ui/widget/multiinputdialog")
local ConfirmBox = require("ui/widget/confirmbox")
local CenterContainer = require("ui/widget/container/centercontainer")
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 SetDefaults = InputContainer:new{
    defaults_name = {},
    defaults_value = {},
    results = {},
    defaults_menu = {},
    already_read = 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{
            text = _("Some changes will not work until the next restart. Be careful; the wrong settings might crash KOReader!\nAre you sure you want to continue?"),
            ok_callback = function()
                self.EditConfirmed = true
                self:init()
            end,
        })
    else
        self:init()
    end
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
{'fraction_non_alphanumeric': 0.13382974441537532, 'fraction_numerical': 0.00482994566311129, 'mean_word_length': 2.465829846582985, 'pattern_counts': {'":': 2, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5212013', 'n_tokens_mistral': 1535, 'n_tokens_neox': 1512, 'n_words': 402}