ui changes
This commit is contained in:
+109
-158
@@ -27,94 +27,57 @@ end
|
|||||||
function M.manager(project_root)
|
function M.manager(project_root)
|
||||||
local templates = require("Polydev.templates")
|
local templates = require("Polydev.templates")
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
local width, height = math.floor(ui.width * 0.8), math.floor(ui.height * 0.9)
|
local width, height = math.floor(ui.width * 0.40), math.floor(ui.height * 0.4)
|
||||||
local row, col = math.floor((ui.height - height) / 2), math.floor((ui.width - width) / 2)
|
local row, col = math.floor((ui.height - height) / 3), math.floor((ui.width - width) / 2)
|
||||||
local content_row = row + 2
|
local content_row = row + 2
|
||||||
local content_height = height - 3
|
local content_height = height - 3
|
||||||
|
|
||||||
local tabs = { "Projects", "Recents" }
|
|
||||||
local selected = 1
|
|
||||||
local selected_tab = tabs[selected]
|
|
||||||
|
|
||||||
local cwd = vim.fn.getcwd()
|
local cwd = vim.fn.getcwd()
|
||||||
local current_view = {}
|
local current_view = {}
|
||||||
|
|
||||||
local tab_buf = vim.api.nvim_create_buf(false, true)
|
local content_buf = vim.api.nvim_create_buf(false, true)
|
||||||
local tab_win = vim.api.nvim_open_win(tab_buf, false, {
|
local content_win = vim.api.nvim_open_win(content_buf, true, {
|
||||||
relative = "editor",
|
relative = "editor",
|
||||||
width = width,
|
width = width,
|
||||||
height = 1,
|
height = content_height,
|
||||||
row = row,
|
row = content_row,
|
||||||
col = col,
|
col = col,
|
||||||
style = "minimal",
|
style = "minimal",
|
||||||
border = "rounded",
|
border = "rounded",
|
||||||
})
|
})
|
||||||
|
|
||||||
local content_bufs = {
|
|
||||||
Projects = vim.api.nvim_create_buf(false, true),
|
|
||||||
Recents = vim.api.nvim_create_buf(false, true),
|
|
||||||
}
|
|
||||||
|
|
||||||
local content_wins = {
|
|
||||||
Projects = vim.api.nvim_open_win(content_bufs.Projects, true, {
|
|
||||||
relative = "editor",
|
|
||||||
width = width,
|
|
||||||
height = content_height,
|
|
||||||
row = content_row,
|
|
||||||
col = col,
|
|
||||||
style = "minimal",
|
|
||||||
border = "rounded",
|
|
||||||
}),
|
|
||||||
Recents = nil,
|
|
||||||
}
|
|
||||||
|
|
||||||
local function close_all_windows()
|
local function close_all_windows()
|
||||||
for _, win in pairs(content_wins) do
|
if vim.api.nvim_win_is_valid(content_win) then
|
||||||
if win and vim.api.nvim_win_is_valid(win) then
|
pcall(vim.api.nvim_win_close, content_win, true)
|
||||||
pcall(vim.api.nvim_win_close, win, true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
pcall(vim.api.nvim_win_close, tab_win, true)
|
|
||||||
end
|
|
||||||
|
|
||||||
|
|
||||||
local function update_tab_bar()
|
|
||||||
local line = {}
|
|
||||||
for i, tab in ipairs(tabs) do
|
|
||||||
local label = (i == selected and "[ " .. tab .. " ]") or (" " .. tab .. " ")
|
|
||||||
table.insert(line, label)
|
|
||||||
end
|
|
||||||
vim.api.nvim_buf_set_lines(tab_buf, 0, -1, false, { table.concat(line, " ") })
|
|
||||||
end
|
end
|
||||||
|
|
||||||
local function update_screen()
|
local function update_screen()
|
||||||
if selected_tab == "Projects" then
|
local entries = get_entries(cwd)
|
||||||
local entries = get_entries(cwd)
|
local root = vim.fn.expand(project_root)
|
||||||
local root = vim.fn.expand(project_root)
|
if not cwd:find(root, 1, true) then
|
||||||
if not cwd:find(root, 1, true) then
|
cwd = root
|
||||||
cwd = root
|
entries = get_entries(cwd)
|
||||||
entries = get_entries(cwd)
|
|
||||||
end
|
|
||||||
if cwd ~= root then
|
|
||||||
table.insert(entries, 1, {
|
|
||||||
name = "../",
|
|
||||||
type = "directory",
|
|
||||||
full_path = vim.fn.fnamemodify(cwd, ":h"),
|
|
||||||
is_up = true,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
current_view = vim.deepcopy(entries)
|
|
||||||
|
|
||||||
local lines = {}
|
|
||||||
for i, item in ipairs(current_view) do
|
|
||||||
table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
|
|
||||||
end
|
|
||||||
vim.api.nvim_buf_set_lines(content_bufs.Projects, 0, -1, false, lines)
|
|
||||||
end
|
end
|
||||||
|
if cwd ~= root then
|
||||||
|
table.insert(entries, 1, {
|
||||||
|
name = "../",
|
||||||
|
type = "directory",
|
||||||
|
full_path = vim.fn.fnamemodify(cwd, ":h"),
|
||||||
|
is_up = true,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
current_view = vim.deepcopy(entries)
|
||||||
|
|
||||||
|
local lines = {}
|
||||||
|
for i, item in ipairs(current_view) do
|
||||||
|
table.insert(lines, string.format("%-2d | %-27s | %-6s", i, item.name, item.type))
|
||||||
|
end
|
||||||
|
vim.api.nvim_buf_set_lines(content_buf, 0, -1, false, lines)
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get_selected_entry()
|
local function get_selected_entry()
|
||||||
local win = content_wins[selected_tab]
|
local win = content_win
|
||||||
if not win or not vim.api.nvim_win_is_valid(win) then return end
|
if not win or not vim.api.nvim_win_is_valid(win) then return end
|
||||||
local row = vim.api.nvim_win_get_cursor(win)[1]
|
local row = vim.api.nvim_win_get_cursor(win)[1]
|
||||||
return current_view[row], row
|
return current_view[row], row
|
||||||
@@ -135,110 +98,98 @@ function M.manager(project_root)
|
|||||||
return l, n
|
return l, n
|
||||||
end
|
end
|
||||||
|
|
||||||
update_tab_bar()
|
|
||||||
update_screen()
|
update_screen()
|
||||||
|
|
||||||
-- Shared mappings
|
local buf = content_buf
|
||||||
for _, buf in pairs(content_bufs) do
|
vim.keymap.set("n", "<ESC>", function()
|
||||||
vim.keymap.set("n", "<ESC>", function()
|
if vim.api.nvim_win_is_valid(content_win) then
|
||||||
for _, win in pairs(content_wins) do
|
pcall(vim.api.nvim_win_close, content_win, true)
|
||||||
if win and vim.api.nvim_win_is_valid(win) then
|
end
|
||||||
pcall(vim.api.nvim_win_close, win, true)
|
end, { buffer = buf })
|
||||||
end
|
vim.keymap.set("n", "a", function ()
|
||||||
|
vim.ui.input({ prompt = "New folder name: " }, function(input)
|
||||||
|
if input then
|
||||||
|
vim.fn.mkdir(cwd .. "/" .. input, "p")
|
||||||
|
update_screen()
|
||||||
end
|
end
|
||||||
pcall(vim.api.nvim_win_close, tab_win, true)
|
end)
|
||||||
end, { buffer = buf })
|
end, { buffer = buf })
|
||||||
vim.keymap.set("n", "a", function ()
|
vim.keymap.set("n", "R", function ()
|
||||||
vim.ui.input({ prompt = "New folder name: " }, function(input)
|
local entry = get_selected_entry()
|
||||||
|
if entry ~= nil and not entry.is_up then
|
||||||
|
vim.ui.input({ prompt = "Rename: ", default = entry.name }, function(input)
|
||||||
if input then
|
if input then
|
||||||
vim.fn.mkdir(cwd .. "/" .. input, "p")
|
local new_path = cwd .. "/" .. input
|
||||||
|
vim.fn.rename(entry.full_path, new_path)
|
||||||
update_screen()
|
update_screen()
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
end, { buffer = buf })
|
end
|
||||||
vim.keymap.set("n", "R", function ()
|
end, { buffer = buf })
|
||||||
local entry = get_selected_entry()
|
vim.keymap.set("n", "D", function()
|
||||||
if entry ~= nil and not entry.is_up then
|
local entry = get_selected_entry()
|
||||||
vim.ui.input({ prompt = "Rename: ", default = entry.name }, function(input)
|
if entry ~= nil and not entry.is_up then
|
||||||
if input then
|
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
|
||||||
local new_path = cwd .. "/" .. input
|
if input == "y" or input == "Y" then
|
||||||
vim.fn.rename(entry.full_path, new_path)
|
vim.fn.delete(entry.full_path, "rf")
|
||||||
update_screen()
|
update_screen()
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end, { buffer = buf })
|
|
||||||
vim.keymap.set("n", "D", function()
|
|
||||||
local entry = get_selected_entry()
|
|
||||||
if entry ~= nil and not entry.is_up then
|
|
||||||
vim.ui.input({ prompt = "Deletion of " .. entry.name .. ": (y/N) Defaults to N: " }, function(input)
|
|
||||||
if input == "y" or input == "Y" then
|
|
||||||
vim.fn.delete(entry.full_path, "rf")
|
|
||||||
update_screen()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
end, { buffer = buf })
|
|
||||||
vim.keymap.set("n", "%", function()
|
|
||||||
local lang, name = get_inputs("file")
|
|
||||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
|
||||||
if templates.files[lang].run then
|
|
||||||
if name ~= nil and name ~= "" then
|
|
||||||
close_all_windows()
|
|
||||||
templates.files[lang].run(name)
|
|
||||||
end
|
end
|
||||||
else
|
end)
|
||||||
print("Error: No File creation method for " .. lang)
|
end
|
||||||
|
end, { buffer = buf })
|
||||||
|
vim.keymap.set("n", "%", function()
|
||||||
|
local lang, name = get_inputs("file")
|
||||||
|
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||||
|
if templates.files[lang].run then
|
||||||
|
if name ~= nil and name ~= "" then
|
||||||
|
close_all_windows()
|
||||||
|
templates.files[lang].run(name)
|
||||||
end
|
end
|
||||||
end, { buffer = buf })
|
else
|
||||||
vim.keymap.set("n", "x", function()
|
print("Error: No File creation method for " .. lang)
|
||||||
local lang, name = get_inputs("aux file")
|
end
|
||||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
end, { buffer = buf })
|
||||||
if templates.extras.run then
|
vim.keymap.set("n", "x", function()
|
||||||
if name ~= nil and name ~= "" then
|
local lang, name = get_inputs("aux file")
|
||||||
close_all_windows()
|
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||||
templates.extras.run(lang, name)
|
if templates.extras.run then
|
||||||
end
|
if name ~= nil and name ~= "" then
|
||||||
else
|
close_all_windows()
|
||||||
print("Error: No File creation method for " .. lang)
|
templates.extras.run(lang, name)
|
||||||
end
|
end
|
||||||
end, { buffer = buf })
|
else
|
||||||
vim.keymap.set("n", "d", function ()
|
print("Error: No File creation method for " .. lang)
|
||||||
local lang, name = get_inputs("project")
|
end
|
||||||
local opts = {}
|
end, { buffer = buf })
|
||||||
opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get(lang), opts or {})
|
vim.keymap.set("n", "d", function ()
|
||||||
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
local lang, name = get_inputs("project")
|
||||||
if templates.projects[lang].run then
|
local opts = {}
|
||||||
if name ~= nil and name ~= "" then
|
opts = vim.tbl_deep_extend("force", {}, require("Polydev.configs").get(lang), opts or {})
|
||||||
close_all_windows()
|
if lang == nil or lang == "" then return print("Error: Lang cannot be nil") end
|
||||||
templates.projects[lang].run(name, opts.project_root)
|
if templates.projects[lang].run then
|
||||||
end
|
if name ~= nil and name ~= "" then
|
||||||
else
|
close_all_windows()
|
||||||
print("Error: No project creation method for " .. lang)
|
templates.projects[lang].run(name, opts.project_root)
|
||||||
end
|
end
|
||||||
end, { buffer = buf })
|
else
|
||||||
vim.keymap.set("n", "<CR>", function()
|
print("Error: No project creation method for " .. lang)
|
||||||
local entry = get_selected_entry()
|
end
|
||||||
if not entry then return end
|
end, { buffer = buf })
|
||||||
|
vim.keymap.set("n", "<CR>", function()
|
||||||
|
local entry = get_selected_entry()
|
||||||
|
if not entry then return end
|
||||||
|
|
||||||
if entry.type == "file" then
|
if entry.type == "file" then
|
||||||
for _, win in pairs(content_wins) do
|
close_all_windows()
|
||||||
if win and vim.api.nvim_win_is_valid(win) then
|
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||||
pcall(vim.api.nvim_win_close, win, true)
|
elseif entry.type == "directory" then
|
||||||
end
|
cwd = entry.full_path
|
||||||
end
|
vim.cmd("cd " .. cwd)
|
||||||
pcall(vim.api.nvim_win_close, tab_win, true)
|
update_screen()
|
||||||
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
else
|
||||||
|
print("Error")
|
||||||
elseif entry.type == "directory" then
|
end
|
||||||
cwd = entry.full_path
|
end, { buffer = buf })
|
||||||
vim.cmd("cd " .. cwd)
|
|
||||||
update_screen()
|
|
||||||
else
|
|
||||||
print("Error")
|
|
||||||
end
|
|
||||||
end, { buffer = buf })
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|||||||
Reference in New Issue
Block a user