mirror of
https://github.com/hexedtech/codemp-nvim.git
synced 2024-11-22 15:34:53 +01:00
fix(neotree): open and add actions
This commit is contained in:
parent
cb2069196e
commit
2fd15290b9
1 changed files with 45 additions and 35 deletions
|
@ -8,13 +8,22 @@ local client_manager = require("codemp.client")
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local function toggle(node)
|
||||||
|
if node:is_expanded() then
|
||||||
|
node:collapse()
|
||||||
|
else
|
||||||
|
node:expand()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
M.refresh = require("neo-tree.utils").wrap(manager.refresh, "codemp")
|
M.refresh = require("neo-tree.utils").wrap(manager.refresh, "codemp")
|
||||||
|
|
||||||
M.open = function(state, path, extra)
|
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 == "title" then return end
|
if selected.type == "title" then return end
|
||||||
if selected.type == "root" then selected:toggle() end
|
if selected.type == "entry" then return end
|
||||||
|
if selected.type == "root" then toggle(selected) end
|
||||||
if selected.type == "button" then
|
if selected.type == "button" then
|
||||||
if selected.name == "[connect]" and session.client == nil then
|
if selected.name == "[connect]" and session.client == nil then
|
||||||
client_manager.connect()
|
client_manager.connect()
|
||||||
|
@ -22,15 +31,6 @@ M.open = function(state, path, extra)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if selected.type == "workspace" then
|
if selected.type == "workspace" then
|
||||||
if selected:is_expanded() then
|
|
||||||
vim.ui.input({ prompt = "disconnect from workspace?" }, function (input)
|
|
||||||
if input == nil then return end
|
|
||||||
if input ~= "y" then return end
|
|
||||||
ws_manager.leave()
|
|
||||||
selected:collapse()
|
|
||||||
manager.refresh("codemp")
|
|
||||||
end)
|
|
||||||
else
|
|
||||||
if session.workspace ~= nil and session.workspace.name ~= selected.name then
|
if session.workspace ~= nil and session.workspace.name ~= selected.name then
|
||||||
error("must leave current workspace first")
|
error("must leave current workspace first")
|
||||||
end
|
end
|
||||||
|
@ -39,7 +39,6 @@ M.open = function(state, path, extra)
|
||||||
end
|
end
|
||||||
selected:expand()
|
selected:expand()
|
||||||
manager.refresh("codemp")
|
manager.refresh("codemp")
|
||||||
end
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
if selected.type == "buffer" then
|
if selected.type == "buffer" then
|
||||||
|
@ -74,7 +73,14 @@ end
|
||||||
|
|
||||||
M.delete = function(state, path, extra)
|
M.delete = function(state, path, extra)
|
||||||
local selected = state.tree:get_node()
|
local selected = state.tree:get_node()
|
||||||
if selected.type == "buffer" then
|
if selected.type == "root" and vim.startswith(selected.name, "#") then
|
||||||
|
vim.ui.input({ prompt = "disconnect from workspace?" }, function (input)
|
||||||
|
if input == nil then return end
|
||||||
|
if input ~= "y" then return end
|
||||||
|
ws_manager.leave()
|
||||||
|
manager.refresh("codemp")
|
||||||
|
end)
|
||||||
|
elseif selected.type == "buffer" then
|
||||||
if session.workspace == nil then error("join a workspace first") end
|
if session.workspace == nil then error("join a workspace first") end
|
||||||
session.workspace:delete_buffer(selected.name):await()
|
session.workspace:delete_buffer(selected.name):await()
|
||||||
print("deleted buffer " .. selected.name)
|
print("deleted buffer " .. selected.name)
|
||||||
|
@ -89,23 +95,27 @@ M.delete = function(state, path, extra)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
M.add = function(_state)
|
M.add = function(state, path, extra)
|
||||||
if session.client == nil then
|
local selected = state.tree:get_node()
|
||||||
vim.ui.input({ prompt = "server address" }, function(input)
|
if selected.type == "root" then
|
||||||
|
if vim.startswith(selected.name, "#") then
|
||||||
|
vim.ui.input({ prompt = "buffer path" }, function(input)
|
||||||
if input == nil or input == "" then return end
|
if input == nil or input == "" then return end
|
||||||
client_manager.connect(input)
|
session.workspace:create_buffer(input):await()
|
||||||
|
manager.refresh("codemp")
|
||||||
end)
|
end)
|
||||||
elseif session.workspace == nil then
|
elseif selected.name == "workspaces" then
|
||||||
vim.ui.input({ prompt = "workspace name" }, function(input)
|
vim.ui.input({ prompt = "workspace name" }, function(input)
|
||||||
if input == nil or input == "" then return end
|
if input == nil or input == "" then return end
|
||||||
session.client:create_workspace(input):await()
|
session.client:create_workspace(input):await()
|
||||||
manager.refresh("codemp")
|
manager.refresh("codemp")
|
||||||
end)
|
end)
|
||||||
else
|
end
|
||||||
vim.ui.input({ prompt = "buffer path" }, function(input)
|
elseif selected.type == "workspace" then
|
||||||
|
vim.ui.input({ prompt = "user name" }, function(input)
|
||||||
if input == nil or input == "" then return end
|
if input == nil or input == "" then return end
|
||||||
session.workspace:create_buffer(input):await()
|
session.client:invite_to_workspace(selected.name, input):await()
|
||||||
manager.refresh("codemp")
|
print("invited user " .. input .. " to workspace " .. selected.name)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
manager.refresh("codemp")
|
manager.refresh("codemp")
|
||||||
|
|
Loading…
Reference in a new issue