adding/removing/renaming file almost done

This commit is contained in:
kiyan42 2020-02-09 18:56:44 +01:00
parent ef6f338cce
commit a3c4fcc6fe
2 changed files with 39 additions and 17 deletions

View File

@ -49,9 +49,9 @@ local function scratch_buffer()
api.nvim_command('au BufWipeout <buffer> exe "silent bwipeout! "'..border_buf) api.nvim_command('au BufWipeout <buffer> exe "silent bwipeout! "'..border_buf)
end end
local function set_mappings() local function set_mappings(path)
local chars = { local chars = {
'a', 'b', 'c', 'd', 'e', 'f', 'h', 'j', 'l', 'q', 'k', 'g', 'i', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z' 'a', 'b', 'd', 'e', 'f', 'h', 'l', 'j', 'q', 'k', 'g', 'i', 'n', 'o', 'p', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'
} }
for _,v in ipairs(chars) do for _,v in ipairs(chars) do
api.nvim_buf_set_keymap(buf, 'n', v, '', { nowait = true, noremap = true, silent = true }) api.nvim_buf_set_keymap(buf, 'n', v, '', { nowait = true, noremap = true, silent = true })
@ -60,6 +60,12 @@ local function set_mappings()
api.nvim_buf_set_keymap(buf, 'i', '<c-'..v..'>', '', { nowait = true, noremap = true, silent = true }) api.nvim_buf_set_keymap(buf, 'i', '<c-'..v..'>', '', { nowait = true, noremap = true, silent = true })
api.nvim_buf_set_keymap(buf, 'i', '<c-' ..v:upper()..'>', '', { nowait = true, noremap = true, silent = true }) api.nvim_buf_set_keymap(buf, 'i', '<c-' ..v:upper()..'>', '', { nowait = true, noremap = true, silent = true })
end end
-- TODO: launch different functions here
api.nvim_buf_set_keymap(buf, 'i', '<CR>', "<esc>:lua require'lib/file'.add_file(vim.api.nvim_get_current_line())<CR>", { nowait = true, noremap = true, silent = true })
api.nvim_buf_set_keymap(buf, 'i', '<esc>', "<esc>:q!<CR>", { nowait = true, noremap = true, silent = true })
api.nvim_buf_set_keymap(buf, 'i', '<C-c>', "<esc>:q!<CR>", { nowait = true, noremap = true, silent = true })
api.nvim_buf_set_keymap(buf, 'i', '<C-[>', "<esc>:q!<CR>", { nowait = true, noremap = true, silent = true })
end end
local function update_view(...) local function update_view(...)
@ -68,29 +74,45 @@ local function update_view(...)
api.nvim_command('startinsert!') api.nvim_command('startinsert!')
end end
local function wrapper(...) local function wrapper(path, ...)
scratch_buffer() scratch_buffer()
update_view(...) update_view(...)
set_mappings() set_mappings(path)
end
local function edit_add(path)
wrapper(path, { "Create File", path })
end
local function edit_remove(filename, path, isdir)
local name = "File"
if isdir == true then name = "Directory" end
wrapper(path .. filename, { "Remove " .. name .. " " .. filename .. " ?", "y/n: " })
end
local function edit_rename(filename, path, isdir)
local name = "File"
if isdir == true then name = "Directory" end
wrapper(path .. filename, { "Rename " .. name, path .. filename })
end end
local function add_file(path) local function add_file(path)
wrapper({ "Create File", path }) print(path)
api.nvim_command("q!")
end end
local function remove_file(filename, path, isdir) local function remove_file(path, confirm)
local name = "File" print(path)
if isdir == true then name = "Directory" end api.nvim_command("q!")
wrapper({ "Remove " .. name .. " " .. filename .. " ?", "y/n: " })
end end
local function rename_file(filename, path, isdir) local function rename_file(path)
local name = "File"
if isdir == true then name = "Directory" end
wrapper({ "Rename " .. name, path .. filename })
end end
return { return {
edit_add = edit_add;
edit_remove = edit_remove;
edit_rename = edit_rename;
add_file = add_file; add_file = add_file;
remove_file = remove_file; remove_file = remove_file;
rename_file = rename_file; rename_file = rename_file;

View File

@ -196,14 +196,14 @@ local function edit_file(edit_type)
if edit_type == 'add' then if edit_type == 'add' then
if node.dir == true then if node.dir == true then
lib_file.add_file(node.path .. node.name .. '/') lib_file.edit_add(node.path .. node.name .. '/')
else else
lib_file.add_file(node.path) lib_file.edit_add(node.path)
end end
elseif edit_type == 'delete' then elseif edit_type == 'delete' then
lib_file.remove_file(node.name, node.path, node.dir) lib_file.edit_remove(node.name, node.path, node.dir)
elseif edit_type == 'rename' then elseif edit_type == 'rename' then
lib_file.rename_file(node.name, node.path, node.dir) lib_file.edit_rename(node.name, node.path, node.dir)
end end
end end