ui changes
This commit is contained in:
+13
-62
@@ -27,36 +27,16 @@ end
|
||||
function M.manager(project_root)
|
||||
local templates = require("Polydev.templates")
|
||||
local ui = vim.api.nvim_list_uis()[1]
|
||||
local width, height = math.floor(ui.width * 0.8), math.floor(ui.height * 0.9)
|
||||
local row, col = math.floor((ui.height - height) / 2), math.floor((ui.width - width) / 2)
|
||||
local width, height = math.floor(ui.width * 0.40), math.floor(ui.height * 0.4)
|
||||
local row, col = math.floor((ui.height - height) / 3), math.floor((ui.width - width) / 2)
|
||||
local content_row = row + 2
|
||||
local content_height = height - 3
|
||||
|
||||
local tabs = { "Projects", "Recents" }
|
||||
local selected = 1
|
||||
local selected_tab = tabs[selected]
|
||||
|
||||
local cwd = vim.fn.getcwd()
|
||||
local current_view = {}
|
||||
|
||||
local tab_buf = vim.api.nvim_create_buf(false, true)
|
||||
local tab_win = vim.api.nvim_open_win(tab_buf, false, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = 1,
|
||||
row = row,
|
||||
col = col,
|
||||
style = "minimal",
|
||||
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, {
|
||||
local content_buf = vim.api.nvim_create_buf(false, true)
|
||||
local content_win = vim.api.nvim_open_win(content_buf, true, {
|
||||
relative = "editor",
|
||||
width = width,
|
||||
height = content_height,
|
||||
@@ -64,31 +44,15 @@ function M.manager(project_root)
|
||||
col = col,
|
||||
style = "minimal",
|
||||
border = "rounded",
|
||||
}),
|
||||
Recents = nil,
|
||||
}
|
||||
})
|
||||
|
||||
local function close_all_windows()
|
||||
for _, win in pairs(content_wins) do
|
||||
if win and vim.api.nvim_win_is_valid(win) then
|
||||
pcall(vim.api.nvim_win_close, win, true)
|
||||
if vim.api.nvim_win_is_valid(content_win) then
|
||||
pcall(vim.api.nvim_win_close, content_win, true)
|
||||
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
|
||||
|
||||
local function update_screen()
|
||||
if selected_tab == "Projects" then
|
||||
local entries = get_entries(cwd)
|
||||
local root = vim.fn.expand(project_root)
|
||||
if not cwd:find(root, 1, true) then
|
||||
@@ -109,12 +73,11 @@ function M.manager(project_root)
|
||||
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
|
||||
vim.api.nvim_buf_set_lines(content_buf, 0, -1, false, lines)
|
||||
end
|
||||
|
||||
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
|
||||
local row = vim.api.nvim_win_get_cursor(win)[1]
|
||||
return current_view[row], row
|
||||
@@ -135,18 +98,13 @@ function M.manager(project_root)
|
||||
return l, n
|
||||
end
|
||||
|
||||
update_tab_bar()
|
||||
update_screen()
|
||||
|
||||
-- Shared mappings
|
||||
for _, buf in pairs(content_bufs) do
|
||||
local buf = content_buf
|
||||
vim.keymap.set("n", "<ESC>", function()
|
||||
for _, win in pairs(content_wins) do
|
||||
if win and vim.api.nvim_win_is_valid(win) then
|
||||
pcall(vim.api.nvim_win_close, win, true)
|
||||
if vim.api.nvim_win_is_valid(content_win) then
|
||||
pcall(vim.api.nvim_win_close, content_win, true)
|
||||
end
|
||||
end
|
||||
pcall(vim.api.nvim_win_close, tab_win, true)
|
||||
end, { buffer = buf })
|
||||
vim.keymap.set("n", "a", function ()
|
||||
vim.ui.input({ prompt = "New folder name: " }, function(input)
|
||||
@@ -222,14 +180,8 @@ function M.manager(project_root)
|
||||
if not entry then return end
|
||||
|
||||
if entry.type == "file" then
|
||||
for _, win in pairs(content_wins) do
|
||||
if win and vim.api.nvim_win_is_valid(win) then
|
||||
pcall(vim.api.nvim_win_close, win, true)
|
||||
end
|
||||
end
|
||||
pcall(vim.api.nvim_win_close, tab_win, true)
|
||||
close_all_windows()
|
||||
vim.cmd("edit " .. vim.fn.fnameescape(entry.full_path))
|
||||
|
||||
elseif entry.type == "directory" then
|
||||
cwd = entry.full_path
|
||||
vim.cmd("cd " .. cwd)
|
||||
@@ -238,7 +190,6 @@ function M.manager(project_root)
|
||||
print("Error")
|
||||
end
|
||||
end, { buffer = buf })
|
||||
end
|
||||
end
|
||||
|
||||
return M
|
||||
|
||||
Reference in New Issue
Block a user