Merge branch 'master' into dev
This commit is contained in:
commit
e260290bd3
|
@ -1,5 +1,6 @@
|
||||||
local core = require "core"
|
local core = require "core"
|
||||||
local command = require "core.command"
|
local command = require "core.command"
|
||||||
|
local common = require "core.common"
|
||||||
|
|
||||||
command.add("core.nagview", {
|
command.add("core.nagview", {
|
||||||
["dialog:previous-entry"] = function()
|
["dialog:previous-entry"] = function()
|
||||||
|
@ -15,13 +16,13 @@ command.add("core.nagview", {
|
||||||
["dialog:select-yes"] = function()
|
["dialog:select-yes"] = function()
|
||||||
local v = core.active_view
|
local v = core.active_view
|
||||||
if v ~= core.nag_view then return end
|
if v ~= core.nag_view then return end
|
||||||
v:change_hovered(findindex(v.options, "default_yes"))
|
v:change_hovered(common.find_index(v.options, "default_yes"))
|
||||||
command.perform "dialog:select"
|
command.perform "dialog:select"
|
||||||
end,
|
end,
|
||||||
["dialog:select-no"] = function()
|
["dialog:select-no"] = function()
|
||||||
local v = core.active_view
|
local v = core.active_view
|
||||||
if v ~= core.nag_view then return end
|
if v ~= core.nag_view then return end
|
||||||
v:change_hovered(findindex(v.options, "default_no"))
|
v:change_hovered(common.find_index(v.options, "default_no"))
|
||||||
command.perform "dialog:select"
|
command.perform "dialog:select"
|
||||||
end,
|
end,
|
||||||
["dialog:select"] = function()
|
["dialog:select"] = function()
|
||||||
|
|
|
@ -1,37 +1,11 @@
|
||||||
local core = require "core"
|
local core = require "core"
|
||||||
local command = require "core.command"
|
local command = require "core.command"
|
||||||
|
local common = require "core.common"
|
||||||
local function mkdirp(path)
|
|
||||||
local segments = {}
|
|
||||||
local pos = 1
|
|
||||||
while true do
|
|
||||||
local s, e = string.find(path, "[/\\]+", pos)
|
|
||||||
if not s then break end
|
|
||||||
table.insert(segments, string.sub(str, pos, s - 1))
|
|
||||||
pos = e + 1
|
|
||||||
end
|
|
||||||
table.insert(segments, string.sub(str, pos))
|
|
||||||
if segments[#segments] == '' then
|
|
||||||
table.remove(segments)
|
|
||||||
end
|
|
||||||
|
|
||||||
for i = 1, #segments do
|
|
||||||
local p = table.concat(segments, PATHSEP, 1, i)
|
|
||||||
local stat = system.get_file_info(p)
|
|
||||||
if stat and stat.type == "file" then
|
|
||||||
return nil, "path exists", p
|
|
||||||
end
|
|
||||||
local success, err = system.mkdir(p)
|
|
||||||
if not success then
|
|
||||||
return nil, err, p
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
command.add(nil, {
|
command.add(nil, {
|
||||||
["files:create-directory"] = function()
|
["files:create-directory"] = function()
|
||||||
core.command_view:enter("New directory name", function(text)
|
core.command_view:enter("New directory name", function(text)
|
||||||
local success, err, path = mkdirp(text)
|
local success, err, path = common.mkdirp(text)
|
||||||
if not success then
|
if not success then
|
||||||
core.error("cannot create directory %q: %s", path, err)
|
core.error("cannot create directory %q: %s", path, err)
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,6 +22,13 @@ function common.round(n)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function common.find_index(tbl, prop)
|
||||||
|
for i, o in ipairs(tbl) do
|
||||||
|
if o[prop] then return i end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
function common.lerp(a, b, t)
|
function common.lerp(a, b, t)
|
||||||
if type(a) ~= "table" then
|
if type(a) ~= "table" then
|
||||||
return a + (b - a) * t
|
return a + (b - a) * t
|
||||||
|
@ -291,4 +298,26 @@ function common.relative_path(ref_dir, dir)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function common.mkdirp(path)
|
||||||
|
local stat = system.get_file_info(path)
|
||||||
|
if stat and stat.type then
|
||||||
|
return false, "path exists", path
|
||||||
|
end
|
||||||
|
local subdirs = {}
|
||||||
|
while path and path ~= "" do
|
||||||
|
local success_mkdir = system.mkdir(path)
|
||||||
|
if success_mkdir then break end
|
||||||
|
local updir, basedir = path:match("(.*)[/\\](.+)$")
|
||||||
|
table.insert(subdirs, 1, basedir or path)
|
||||||
|
path = updir
|
||||||
|
end
|
||||||
|
for _, dirname in ipairs(subdirs) do
|
||||||
|
path = path and path .. PATHSEP .. dirname or dirname
|
||||||
|
if not system.mkdir(path) then
|
||||||
|
return false, "cannot create directory", path
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
return common
|
return common
|
||||||
|
|
|
@ -270,25 +270,12 @@ end
|
||||||
-- create a directory using mkdir but may need to create the parent
|
-- create a directory using mkdir but may need to create the parent
|
||||||
-- directories as well.
|
-- directories as well.
|
||||||
local function create_user_directory()
|
local function create_user_directory()
|
||||||
local dirname_create = USERDIR
|
local success, err = common.mkdirp(USERDIR)
|
||||||
local basedir
|
if not success then
|
||||||
local subdirs = {}
|
error("cannot create directory \"" .. USERDIR .. "\": " .. err)
|
||||||
while dirname_create and dirname_create ~= "" do
|
|
||||||
local success_mkdir = system.mkdir(dirname_create)
|
|
||||||
if success_mkdir then break end
|
|
||||||
dirname_create, basedir = dirname_create:match("(.*)[/\\](.+)$")
|
|
||||||
if basedir then
|
|
||||||
subdirs[#subdirs + 1] = basedir
|
|
||||||
end
|
|
||||||
end
|
|
||||||
for _, dirname in ipairs(subdirs) do
|
|
||||||
dirname_create = dirname_create .. '/' .. dirname
|
|
||||||
if not system.mkdir(dirname_create) then
|
|
||||||
error("cannot create directory: \"" .. dirname_create .. "\"")
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
for _, modname in ipairs {'plugins', 'colors', 'fonts'} do
|
for _, modname in ipairs {'plugins', 'colors', 'fonts'} do
|
||||||
local subdirname = dirname_create .. '/' .. modname
|
local subdirname = USERDIR .. PATHSEP .. modname
|
||||||
if not system.mkdir(subdirname) then
|
if not system.mkdir(subdirname) then
|
||||||
error("cannot create directory: \"" .. subdirname .. "\"")
|
error("cannot create directory: \"" .. subdirname .. "\"")
|
||||||
end
|
end
|
||||||
|
|
|
@ -170,12 +170,6 @@ function NagView:draw()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function findindex(tbl, prop)
|
|
||||||
for i, o in ipairs(tbl) do
|
|
||||||
if o[prop] then return i end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function NagView:get_message_height()
|
function NagView:get_message_height()
|
||||||
local h = 0
|
local h = 0
|
||||||
for str in string.gmatch(self.message, "(.-)\n") do
|
for str in string.gmatch(self.message, "(.-)\n") do
|
||||||
|
@ -196,7 +190,7 @@ function NagView:next()
|
||||||
-- self.target_height is the nagview height needed to display the message and
|
-- self.target_height is the nagview height needed to display the message and
|
||||||
-- the buttons, excluding the top and bottom padding space.
|
-- the buttons, excluding the top and bottom padding space.
|
||||||
self.target_height = math.max(message_height, self:get_buttons_height())
|
self.target_height = math.max(message_height, self:get_buttons_height())
|
||||||
self:change_hovered(findindex(self.options, "default_yes"))
|
self:change_hovered(common.find_index(self.options, "default_yes"))
|
||||||
end
|
end
|
||||||
self.force_focus = self.message ~= nil
|
self.force_focus = self.message ~= nil
|
||||||
core.set_active_view(self.message ~= nil and self or core.last_active_view)
|
core.set_active_view(self.message ~= nil and self or core.last_active_view)
|
||||||
|
|
Loading…
Reference in New Issue