diff --git a/data/core/command.lua b/data/core/command.lua index 5164a13a..513e0701 100644 --- a/data/core/command.lua +++ b/data/core/command.lua @@ -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 diff --git a/data/core/commands/files.lua b/data/core/commands/files.lua new file mode 100644 index 00000000..a0106f47 --- /dev/null +++ b/data/core/commands/files.lua @@ -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, +}) diff --git a/data/plugins/treeview.lua b/data/plugins/treeview.lua index bd95cc79..a681f4ab 100644 --- a/data/plugins/treeview.lua +++ b/data/plugins/treeview.lua @@ -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