Compare commits

...

1 Commits

Author SHA1 Message Date
Francesco Abbate 63331ac50c 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.
2020-12-28 16:18:03 +01:00
3 changed files with 32 additions and 2 deletions

View File

@ -59,7 +59,7 @@ end
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
require("core.commands." .. name)
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
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)
if not self.hovered_item then
return
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)
elseif keymap.modkeys["alt"] and button == "left" then
create_directory_in(self.hovered_item)
else
self.hovered_item.expanded = not self.hovered_item.expanded
end