Add command to create a directory in a new category "files"

Use the alt + (left click) is tree view to create a directory and
shift + (middle click) to remove a project directory.
This commit is contained in:
Francesco Abbate 2020-12-28 16:18:03 +01:00
parent ddd56ec615
commit 63331ac50c
3 changed files with 32 additions and 2 deletions

View File

@ -59,7 +59,7 @@ end
function command.add_defaults() function command.add_defaults()
local reg = { "core", "root", "command", "doc", "findreplace" } local reg = { "core", "root", "command", "doc", "findreplace", "files" }
for _, name in ipairs(reg) do for _, name in ipairs(reg) do
require("core.commands." .. name) require("core.commands." .. name)
end end

View File

@ -0,0 +1,13 @@
local core = require "core"
local command = require "core.command"
command.add(nil, {
["files:create-directory"] = function()
core.command_view:enter("New directory name", function(text)
local success, err = system.mkdir(text)
if not success then
core.error("cannot create directory %q: %s", text, err)
end
end)
end,
})

View File

@ -137,12 +137,29 @@ function TreeView:on_mouse_moved(px, py)
end end
local function create_directory_in(item)
local path = item.abs_filename
local basename = path:match("[^\\/]+$")
core.command_view:enter("Create directory in " .. basename, function(text)
local dirname = path .. PATHSEP .. text
local success, err = system.mkdir(dirname)
if not success then
core.error("cannot create directory %q: %s", dirname, err)
end
item.expanded = true
core.request_project_scan()
end)
end
function TreeView:on_mouse_pressed(button, x, y) function TreeView:on_mouse_pressed(button, x, y)
if not self.hovered_item then if not self.hovered_item then
return return
elseif self.hovered_item.type == "dir" then elseif self.hovered_item.type == "dir" then
if button == "middle" and self.hovered_item.depth == 0 then if keymap.modkeys["shift"] and button == "middle" and self.hovered_item.depth == 0 then
core.remove_project_directory(self.hovered_item.abs_filename) core.remove_project_directory(self.hovered_item.abs_filename)
elseif keymap.modkeys["alt"] and button == "left" then
create_directory_in(self.hovered_item)
else else
self.hovered_item.expanded = not self.hovered_item.expanded self.hovered_item.expanded = not self.hovered_item.expanded
end end