From a3c4fcc6fe12b7e456200450b69cc80d36bb5640 Mon Sep 17 00:00:00 2001 From: kiyan42 Date: Sun, 9 Feb 2020 18:56:44 +0100 Subject: [PATCH] adding/removing/renaming file almost done --- lua/lib/file.lua | 48 +++++++++++++++++++++++++++++++++++------------- lua/tree.lua | 8 ++++---- 2 files changed, 39 insertions(+), 17 deletions(-) diff --git a/lua/lib/file.lua b/lua/lib/file.lua index d77512e2..55781149 100644 --- a/lua/lib/file.lua +++ b/lua/lib/file.lua @@ -49,9 +49,9 @@ local function scratch_buffer() api.nvim_command('au BufWipeout exe "silent bwipeout! "'..border_buf) end -local function set_mappings() +local function set_mappings(path) 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 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', '', '', { nowait = true, noremap = true, silent = true }) api.nvim_buf_set_keymap(buf, 'i', '', '', { nowait = true, noremap = true, silent = true }) end + + -- TODO: launch different functions here + api.nvim_buf_set_keymap(buf, 'i', '', ":lua require'lib/file'.add_file(vim.api.nvim_get_current_line())", { nowait = true, noremap = true, silent = true }) + api.nvim_buf_set_keymap(buf, 'i', '', ":q!", { nowait = true, noremap = true, silent = true }) + api.nvim_buf_set_keymap(buf, 'i', '', ":q!", { nowait = true, noremap = true, silent = true }) + api.nvim_buf_set_keymap(buf, 'i', '', ":q!", { nowait = true, noremap = true, silent = true }) end local function update_view(...) @@ -68,29 +74,45 @@ local function update_view(...) api.nvim_command('startinsert!') end -local function wrapper(...) +local function wrapper(path, ...) scratch_buffer() 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 local function add_file(path) - wrapper({ "Create File", path }) + print(path) + api.nvim_command("q!") end -local function remove_file(filename, path, isdir) - local name = "File" - if isdir == true then name = "Directory" end - wrapper({ "Remove " .. name .. " " .. filename .. " ?", "y/n: " }) +local function remove_file(path, confirm) + print(path) + api.nvim_command("q!") end -local function rename_file(filename, path, isdir) - local name = "File" - if isdir == true then name = "Directory" end - wrapper({ "Rename " .. name, path .. filename }) +local function rename_file(path) end return { + edit_add = edit_add; + edit_remove = edit_remove; + edit_rename = edit_rename; add_file = add_file; remove_file = remove_file; rename_file = rename_file; diff --git a/lua/tree.lua b/lua/tree.lua index ea892cdb..4c701d70 100644 --- a/lua/tree.lua +++ b/lua/tree.lua @@ -196,14 +196,14 @@ local function edit_file(edit_type) if edit_type == 'add' then if node.dir == true then - lib_file.add_file(node.path .. node.name .. '/') + lib_file.edit_add(node.path .. node.name .. '/') else - lib_file.add_file(node.path) + lib_file.edit_add(node.path) end 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 - lib_file.rename_file(node.name, node.path, node.dir) + lib_file.edit_rename(node.name, node.path, node.dir) end end