Merge branch 'master' into dev

This commit is contained in:
jgmdev 2021-06-08 00:52:07 -04:00
commit 1b37232cfa
5 changed files with 73 additions and 45 deletions

View File

@ -1,13 +1,7 @@
local core = require "core"
local command = require "core.command"
local CommandView = require "core.commandview"
local function has_commandview()
return core.active_view:is(CommandView)
end
command.add(has_commandview, {
command.add("core.commandview", {
["command:submit"] = function()
core.active_view:submit()
end,

View File

@ -0,0 +1,34 @@
local core = require "core"
local command = require "core.command"
command.add("core.nagview", {
["dialog:previous-entry"] = function()
local v = core.active_view
local hover = v.hovered_item or 1
v:change_hovered(hover == 1 and #v.options or hover - 1)
end,
["dialog:next-entry"] = function()
local v = core.active_view
local hover = v.hovered_item or 1
v:change_hovered(hover == #v.options and 1 or hover + 1)
end,
["dialog:select-yes"] = function()
local v = core.active_view
if v ~= core.nag_view then return end
v:change_hovered(findindex(v.options, "default_yes"))
command.perform "dialog:select"
end,
["dialog:select-no"] = function()
local v = core.active_view
if v ~= core.nag_view then return end
v:change_hovered(findindex(v.options, "default_no"))
command.perform "dialog:select"
end,
["dialog:select"] = function()
local v = core.active_view
if v.hovered_item then
v.on_selected(v.options[v.hovered_item])
v:next()
end
end
})

View File

@ -1,12 +1,39 @@
local core = require "core"
local command = require "core.command"
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, {
["files:create-directory"] = function()
core.command_view:enter("New directory name", function(text)
local success, err = system.mkdir(text)
local success, err, path = mkdirp(text)
if not success then
core.error("cannot create directory %q: %s", text, err)
core.error("cannot create directory %q: %s", path, err)
end
end)
end,

View File

@ -212,36 +212,4 @@ function NagView:show(title, message, options, on_select)
if #self.queue > 0 and not self.title then self:next() end
end
command.add(NagView, {
["dialog:previous-entry"] = function()
local v = core.active_view
local hover = v.hovered_item or 1
v:change_hovered(hover == 1 and #v.options or hover - 1)
end,
["dialog:next-entry"] = function()
local v = core.active_view
local hover = v.hovered_item or 1
v:change_hovered(hover == #v.options and 1 or hover + 1)
end,
["dialog:select-yes"] = function()
local v = core.active_view
if v ~= core.nag_view then return end
v:change_hovered(findindex(v.options, "default_yes"))
command.perform "dialog:select"
end,
["dialog:select-no"] = function()
local v = core.active_view
if v ~= core.nag_view then return end
v:change_hovered(findindex(v.options, "default_no"))
command.perform "dialog:select"
end,
["dialog:select"] = function()
local v = core.active_view
if v.hovered_item then
v.on_selected(v.options[v.hovered_item])
v:next()
end
end,
})
return NagView
return NagView

View File

@ -64,14 +64,19 @@ end
function ContextMenu:show(x, y)
self.items = nil
local items_list = { width = 0, height = 0 }
for _, items in ipairs(self.itemset) do
if items.predicate(x, y) then
self.items = items.items
break
items_list.width = math.max(items_list.width, items.items.width)
items_list.height = items_list.height + items.items.height
for _, subitems in ipairs(items.items) do
table.insert(items_list, subitems)
end
end
end
if self.items then
if #items_list > 0 then
self.items = items_list
local w, h = self.items.width, self.items.height
-- by default the box is opened on the right and below