mirror of
https://github.com/hexedtech/codemp-sublime.git
synced 2025-03-26 03:31:32 +01:00
Make create buffer and delete buffer, be internal commands. Dealing with the input handlers sheningans is too much.
Also improves the logic in the qpbrowser for the creation and deletion of buffers. and simplify the logic in the internal commands.
This commit is contained in:
parent
8dc6a96bde
commit
0a25a5f7c1
5 changed files with 53 additions and 77 deletions
Codemp.sublime-commands
plugin
|
@ -94,22 +94,22 @@
|
|||
// 'buffer_id': 'test'
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "Codemp: Create Buffer",
|
||||
"command": "codemp_create_buffer",
|
||||
"args": {
|
||||
// 'workspace_id': 'asd'
|
||||
// 'buffer_id': 'test'
|
||||
}
|
||||
},
|
||||
{
|
||||
"caption": "Codemp: Delete Buffer",
|
||||
"command": "codemp_delete_buffer",
|
||||
"args": {
|
||||
// 'workspace_id': 'asd'
|
||||
// 'buffer_id': 'test'
|
||||
}
|
||||
},
|
||||
// {
|
||||
// "caption": "Codemp: Create Buffer",
|
||||
// "command": "codemp_create_buffer",
|
||||
// "args": {
|
||||
// // 'workspace_id': 'asd'
|
||||
// // 'buffer_id': 'test'
|
||||
// }
|
||||
// },
|
||||
// {
|
||||
// "caption": "Codemp: Delete Buffer",
|
||||
// "command": "codemp_delete_buffer",
|
||||
// "args": {
|
||||
// // 'workspace_id': 'asd'
|
||||
// // 'buffer_id': 'test'
|
||||
// }
|
||||
// },
|
||||
{
|
||||
"caption": "Codemp: Sync",
|
||||
"command": "codemp_sync_buffer",
|
||||
|
|
|
@ -116,28 +116,10 @@ class CodempCreateBufferCommand(sublime_plugin.WindowCommand):
|
|||
def is_enabled(self):
|
||||
return len(workspaces.lookup()) > 0
|
||||
|
||||
def input_description(self) -> str:
|
||||
return "Create Buffer: "
|
||||
|
||||
def input(self, args):
|
||||
missingargs = [arg for arg in ["workspace_id", "buffer_id"] if arg not in args]
|
||||
for arg in missingargs:
|
||||
if arg == "workspace_id":
|
||||
return SimpleListInput([
|
||||
("workspace_id", session.client.active_workspaces()),
|
||||
("buffer_id", "new buffer name")
|
||||
])
|
||||
if arg == "buffer_id":
|
||||
return SimpleTextInput(
|
||||
("buffer_id", "new buffer name"),
|
||||
)
|
||||
|
||||
def run(self, workspace_id, buffer_id):# pyright: ignore[reportIncompatibleMethodOverride]
|
||||
try: vws = workspaces.lookupId(workspace_id)
|
||||
except KeyError:
|
||||
sublime.error_message(
|
||||
f"You are not attached to the workspace '{workspace_id}'"
|
||||
)
|
||||
sublime.error_message(f"You are not attached to the workspace '{workspace_id}'")
|
||||
logging.warning(f"You are not attached to the workspace '{workspace_id}'")
|
||||
return
|
||||
|
||||
|
@ -151,53 +133,30 @@ class CodempDeleteBufferCommand(sublime_plugin.WindowCommand):
|
|||
def is_enabled(self):
|
||||
return len(workspaces.lookup()) > 0
|
||||
|
||||
def input_description(self) -> str:
|
||||
return "Delete buffer: "
|
||||
|
||||
def input(self, args):
|
||||
# FIXME: THIS DOES NOT WORK SORRY
|
||||
if "workspace_id" not in args:
|
||||
return SimpleListInput(
|
||||
("workspace_id", session.get_workspaces(owned=True, invited=False)),
|
||||
)
|
||||
|
||||
if "buffer_id" not in args:
|
||||
try: ws = workspaces.lookupId(args["workspace_id"])
|
||||
except KeyError:
|
||||
sublime.error_message("Workspace does not exists or is not attached.")
|
||||
return sublime_plugin.BackInputHandler()
|
||||
|
||||
bflist = ws.handle.fetch_buffers().wait()
|
||||
return SimpleListInput(
|
||||
("buffer_id", bflist),
|
||||
)
|
||||
|
||||
def run(self, workspace_id, buffer_id):# pyright: ignore[reportIncompatibleMethodOverride]
|
||||
|
||||
try: vws = workspaces.lookupId(workspace_id)
|
||||
except KeyError:
|
||||
sublime.error_message(
|
||||
f"You are not attached to the workspace '{workspace_id}'"
|
||||
)
|
||||
sublime.error_message(f"You are not attached to the workspace '{workspace_id}'")
|
||||
logging.warning(f"You are not attached to the workspace '{workspace_id}'")
|
||||
return
|
||||
|
||||
if not sublime.ok_cancel_dialog(
|
||||
f"Confirm you want to delete the buffer '{buffer_id}'",
|
||||
ok_title="delete", title="Delete Buffer?",
|
||||
): return
|
||||
if buffer_id in buffers:
|
||||
|
||||
try:
|
||||
buffers.lookupId(buffer_id)
|
||||
if not sublime.ok_cancel_dialog(
|
||||
"You are currently attached to '{buffer_id}'.\n\
|
||||
Do you want to detach and delete it?",
|
||||
ok_title="yes", title="Delete Buffer?",
|
||||
):
|
||||
return
|
||||
self.window.run_command(
|
||||
"codemp_leave_buffer",
|
||||
{ "workspace_id": workspace_id, "buffer_id": buffer_id })
|
||||
except KeyError: pass
|
||||
finally:
|
||||
vws.handle.delete_buffer(buffer_id).wait()
|
||||
): return
|
||||
|
||||
self.window.run_command(
|
||||
"codemp_leave_buffer", {"buffer_id": buffer_id })
|
||||
|
||||
else:
|
||||
if not sublime.ok_cancel_dialog(
|
||||
f"Confirm you want to delete the buffer '{buffer_id}'",
|
||||
ok_title="delete", title="Delete Buffer?",
|
||||
): return
|
||||
|
||||
vws.handle.delete_buffer(buffer_id).wait()
|
||||
|
||||
|
|
|
@ -175,7 +175,6 @@ class BufferRegistry():
|
|||
del self._buffers[bf]
|
||||
|
||||
|
||||
|
||||
buffers = BufferRegistry()
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import sublime_plugin
|
||||
|
||||
|
||||
# Input handlers
|
||||
############################################################
|
||||
class SimpleTextInput(sublime_plugin.TextInputHandler):
|
||||
|
|
|
@ -108,6 +108,7 @@ class QPServerBrowser():
|
|||
def create_workspace(name):
|
||||
self.window.run_command(
|
||||
"codemp_create_workspace", {"workspace_id": name})
|
||||
self.run()
|
||||
self.window.show_input_panel("New Workspace Name", "", create_workspace, None, self.edit_server)
|
||||
|
||||
if index == 2:
|
||||
|
@ -201,21 +202,37 @@ class QPWorkspaceBrowser():
|
|||
"workspace_id": self.workspace_id,
|
||||
"buffer_id": name
|
||||
})
|
||||
self.window.show_input_panel("New Buffer Name", "", create_buffer, None, self.edit_workspace)
|
||||
|
||||
self.window.run_command(
|
||||
"codemp_browse_workspace", {"workspace_id": self.workspace_id})
|
||||
|
||||
panel = self.window.show_input_panel("New Buffer Name", "", create_buffer, None, self.edit_workspace)
|
||||
panel.settings().set("password", False)
|
||||
elif index == 4:
|
||||
def delete_buffer(index):
|
||||
if index == -1 or index == 0:
|
||||
self.edit_workspace()
|
||||
|
||||
# same warning as the server browser. Check your indexed 3 times
|
||||
selected = self.entries[index]
|
||||
selected = self.entries[index+1]
|
||||
self.window.run_command(
|
||||
"codemp_delete_buffer",
|
||||
{
|
||||
"workspace_id": self.workspace_id,
|
||||
"buffer_id": selected.trigger
|
||||
})
|
||||
show_qp(self.window, self.entries, delete_buffer, self.qp_placeholder())
|
||||
|
||||
def _():
|
||||
buffers = workspaces.lookupId(self.workspace_id).handle.fetch_buffers()
|
||||
QPWorkspaceBrowser(self.window, self.workspace_id, buffers.wait()).run()
|
||||
sublime.set_timeout(_)
|
||||
|
||||
if len(self.entries) < 2:
|
||||
sublime.message_dialog("The workspace is empty!")
|
||||
sublime.set_timeout(self.run, 10)
|
||||
else:
|
||||
show_qp(self.window, self.entries[1:], delete_buffer, self.qp_placeholder())
|
||||
|
||||
elif index == 5:
|
||||
sublime.message_dialog("renaming is not yet implemented.")
|
||||
self.edit_workspace()
|
Loading…
Add table
Reference in a new issue