mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-12-23 13:54:54 +01:00
feat(neotree): improved tree view
This commit is contained in:
parent
1732f94add
commit
5c3f7dc85e
4 changed files with 39 additions and 20 deletions
|
@ -1,6 +1,5 @@
|
|||
local renderer = require("neo-tree.ui.renderer")
|
||||
local codemp = require("codemp.session")
|
||||
local cc = require("neo-tree.sources.common.commands")
|
||||
local buf_manager = require("codemp.buffers")
|
||||
|
||||
local M = {}
|
||||
|
@ -87,28 +86,43 @@ end
|
|||
|
||||
M.update_state = function(state)
|
||||
---@type Item[]
|
||||
local root = {}
|
||||
local root = {
|
||||
{
|
||||
id = "codemp",
|
||||
name = "codemp",
|
||||
type = "title",
|
||||
extra = {},
|
||||
}
|
||||
}
|
||||
|
||||
if codemp.workspace ~= nil then
|
||||
root = {
|
||||
new_root(codemp.client.username .. "@" .. codemp.workspace.name),
|
||||
spacer(),
|
||||
new_root("users"),
|
||||
spacer(),
|
||||
}
|
||||
table.insert(root, spacer())
|
||||
local ws_section = new_root("session #" .. codemp.workspace.name)
|
||||
for i, path in ipairs(codemp.workspace:filetree()) do
|
||||
table.insert(root[1].children, new_item(codemp.workspace.name, path))
|
||||
table.insert(ws_section.children, new_item(codemp.workspace.name, path))
|
||||
end
|
||||
|
||||
local usr_section = new_root("users")
|
||||
for user, buffer in pairs(buf_manager.users) do
|
||||
table.insert(root[3].children, new_user(codemp.workspace.name, user))
|
||||
table.insert(usr_section.children, new_user(codemp.workspace.name, user))
|
||||
end
|
||||
elseif codemp.client ~= nil then
|
||||
root = { new_root(codemp.client.username .. "@codemp") }
|
||||
if #buf_manager.users > 0 then
|
||||
table.insert(ws_section.children, spacer())
|
||||
table.insert(ws_section.children, usr_section)
|
||||
end
|
||||
table.insert(root, ws_section)
|
||||
end
|
||||
|
||||
if codemp.client ~= nil then
|
||||
table.insert(root, spacer())
|
||||
local ws_section = new_root("workspaces")
|
||||
for _, ws in ipairs(codemp.available) do
|
||||
table.insert(root[1].children, new_workspace(ws.name, ws.owned))
|
||||
table.insert(ws_section.children, new_workspace(ws.name, ws.owned))
|
||||
end
|
||||
table.insert(root, ws_section)
|
||||
else
|
||||
root = { new_root("codemp") }
|
||||
table.insert(root, spacer())
|
||||
table.insert(root, new_root("[connect]"))
|
||||
end
|
||||
|
||||
renderer.show_nodes(root, state)
|
||||
|
|
|
@ -14,9 +14,7 @@ M.open = function(state, path, extra)
|
|||
local selected = state.tree:get_node()
|
||||
if selected.type == "spacer" then return end
|
||||
if selected.type == "root" then
|
||||
if session.client ~= nil then
|
||||
print(" +-+ connected to codemp as " .. session.client.username)
|
||||
else
|
||||
if selected.name == "[connect]" and session.client ~= nil then
|
||||
client_manager.connect()
|
||||
end
|
||||
return
|
||||
|
|
|
@ -30,7 +30,7 @@ M.icon = function(config, node, state)
|
|||
icon = "= "
|
||||
highlight = highlights.DIRECTORY_ICON
|
||||
elseif node.type == "root" then
|
||||
icon = "]| "
|
||||
icon = "> "
|
||||
highlight = highlights.DIRECTORY_ICON
|
||||
elseif node.type == "workspace" then
|
||||
icon = "= "
|
||||
|
@ -48,13 +48,17 @@ end
|
|||
|
||||
M.name = function(config, node, state)
|
||||
local highlight = config.highlight or highlights.FILE_NAME
|
||||
if node.type == "root" then
|
||||
local text = node.name
|
||||
if node.type == "tutle" then
|
||||
text = ":: " .. node.name .. " ::"
|
||||
highlight = highlights.PREVIEW
|
||||
elseif node.type == "root" then
|
||||
highlight = highlights.FLOAT_TITLE
|
||||
elseif node.type == "workspace" then
|
||||
highlight = highlights.SYMBOLIC_LINK_TARGET
|
||||
end
|
||||
return {
|
||||
text = node.name,
|
||||
text = text,
|
||||
highlight = highlight,
|
||||
}
|
||||
end
|
||||
|
|
|
@ -15,6 +15,9 @@ end
|
|||
|
||||
M.default_config = {
|
||||
renderers = {
|
||||
title = {
|
||||
{ "name" },
|
||||
},
|
||||
spacer = {
|
||||
{ "indent" },
|
||||
},
|
||||
|
|
Loading…
Reference in a new issue