mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 07:24:52 +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 renderer = require("neo-tree.ui.renderer")
|
||||||
local codemp = require("codemp.session")
|
local codemp = require("codemp.session")
|
||||||
local cc = require("neo-tree.sources.common.commands")
|
|
||||||
local buf_manager = require("codemp.buffers")
|
local buf_manager = require("codemp.buffers")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
@ -87,28 +86,43 @@ end
|
||||||
|
|
||||||
M.update_state = function(state)
|
M.update_state = function(state)
|
||||||
---@type Item[]
|
---@type Item[]
|
||||||
local root = {}
|
local root = {
|
||||||
|
{
|
||||||
|
id = "codemp",
|
||||||
|
name = "codemp",
|
||||||
|
type = "title",
|
||||||
|
extra = {},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if codemp.workspace ~= nil then
|
if codemp.workspace ~= nil then
|
||||||
root = {
|
table.insert(root, spacer())
|
||||||
new_root(codemp.client.username .. "@" .. codemp.workspace.name),
|
local ws_section = new_root("session #" .. codemp.workspace.name)
|
||||||
spacer(),
|
|
||||||
new_root("users"),
|
|
||||||
spacer(),
|
|
||||||
}
|
|
||||||
for i, path in ipairs(codemp.workspace:filetree()) do
|
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
|
end
|
||||||
|
|
||||||
|
local usr_section = new_root("users")
|
||||||
for user, buffer in pairs(buf_manager.users) do
|
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
|
end
|
||||||
elseif codemp.client ~= nil then
|
if #buf_manager.users > 0 then
|
||||||
root = { new_root(codemp.client.username .. "@codemp") }
|
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
|
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
|
end
|
||||||
|
table.insert(root, ws_section)
|
||||||
else
|
else
|
||||||
root = { new_root("codemp") }
|
table.insert(root, spacer())
|
||||||
|
table.insert(root, new_root("[connect]"))
|
||||||
end
|
end
|
||||||
|
|
||||||
renderer.show_nodes(root, state)
|
renderer.show_nodes(root, state)
|
||||||
|
|
|
@ -14,9 +14,7 @@ M.open = function(state, path, extra)
|
||||||
local selected = state.tree:get_node()
|
local selected = state.tree:get_node()
|
||||||
if selected.type == "spacer" then return end
|
if selected.type == "spacer" then return end
|
||||||
if selected.type == "root" then
|
if selected.type == "root" then
|
||||||
if session.client ~= nil then
|
if selected.name == "[connect]" and session.client ~= nil then
|
||||||
print(" +-+ connected to codemp as " .. session.client.username)
|
|
||||||
else
|
|
||||||
client_manager.connect()
|
client_manager.connect()
|
||||||
end
|
end
|
||||||
return
|
return
|
||||||
|
|
|
@ -30,7 +30,7 @@ M.icon = function(config, node, state)
|
||||||
icon = "= "
|
icon = "= "
|
||||||
highlight = highlights.DIRECTORY_ICON
|
highlight = highlights.DIRECTORY_ICON
|
||||||
elseif node.type == "root" then
|
elseif node.type == "root" then
|
||||||
icon = "]| "
|
icon = "> "
|
||||||
highlight = highlights.DIRECTORY_ICON
|
highlight = highlights.DIRECTORY_ICON
|
||||||
elseif node.type == "workspace" then
|
elseif node.type == "workspace" then
|
||||||
icon = "= "
|
icon = "= "
|
||||||
|
@ -48,13 +48,17 @@ end
|
||||||
|
|
||||||
M.name = function(config, node, state)
|
M.name = function(config, node, state)
|
||||||
local highlight = config.highlight or highlights.FILE_NAME
|
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
|
highlight = highlights.FLOAT_TITLE
|
||||||
elseif node.type == "workspace" then
|
elseif node.type == "workspace" then
|
||||||
highlight = highlights.SYMBOLIC_LINK_TARGET
|
highlight = highlights.SYMBOLIC_LINK_TARGET
|
||||||
end
|
end
|
||||||
return {
|
return {
|
||||||
text = node.name,
|
text = text,
|
||||||
highlight = highlight,
|
highlight = highlight,
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,6 +15,9 @@ end
|
||||||
|
|
||||||
M.default_config = {
|
M.default_config = {
|
||||||
renderers = {
|
renderers = {
|
||||||
|
title = {
|
||||||
|
{ "name" },
|
||||||
|
},
|
||||||
spacer = {
|
spacer = {
|
||||||
{ "indent" },
|
{ "indent" },
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in a new issue