Skip to content

Commit ce87c53

Browse files
committed
made create and delete workspaces as internal commands as well.
Fixed the same issues that the workspace browser had for the creation and deletion also in the server browser.
1 parent 164c601 commit ce87c53

File tree

3 files changed

+48
-36
lines changed

3 files changed

+48
-36
lines changed

Codemp.sublime-commands

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -64,20 +64,20 @@
6464
// "user": 'lupo'
6565
}
6666
},
67-
{
68-
"caption": "Codemp: Create Workspace",
69-
"command": "codemp_create_workspace",
70-
"args": {
71-
// "id": 'lmaaaao'
72-
}
73-
},
74-
{
75-
"caption": "Codemp: Delete Workspace",
76-
"command": "codemp_delete_workspace",
77-
"args": {
78-
// "id": 'lmaaaao'
79-
}
80-
},
67+
// {
68+
// "caption": "Codemp: Create Workspace",
69+
// "command": "codemp_create_workspace",
70+
// "args": {
71+
// // "id": 'lmaaaao'
72+
// }
73+
// },
74+
// {
75+
// "caption": "Codemp: Delete Workspace",
76+
// "command": "codemp_delete_workspace",
77+
// "args": {
78+
// // "id": 'lmaaaao'
79+
// }
80+
// },
8181
{
8282
"caption": "Codemp: Join Buffer",
8383
"command": "codemp_join_buffer",

plugin/commands/client.py

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ class CodempCreateWorkspaceCommand(sublime_plugin.WindowCommand):
208208
def is_enabled(self):
209209
return session.is_active()
210210

211-
def input(self, args):
212-
if "workspace_id" not in args:
213-
return SimpleTextInput(("workspace_id", "new workspace name"))
211+
# def input(self, args):
212+
# if "workspace_id" not in args:
213+
# return SimpleTextInput(("workspace_id", "new workspace name"))
214214

215215
def run(self, workspace_id: str): # pyright: ignore[reportIncompatibleMethodOverride]
216216
try:
@@ -224,25 +224,26 @@ class CodempDeleteWorkspaceCommand(sublime_plugin.WindowCommand):
224224
def is_enabled(self):
225225
return session.is_active()
226226

227-
def input(self, args):
228-
workspaces = session.get_workspaces(owned=True, invited=False) # noqa: F841
229-
if "workspace_id" not in args:
230-
return SimpleListInput(("workspace_id", workspaces))
227+
# def input(self, args):
228+
# workspaces = session.get_workspaces(owned=True, invited=False) # noqa: F841
229+
# if "workspace_id" not in args:
230+
# return SimpleListInput(("workspace_id", workspaces))
231231

232232
def run(self, workspace_id: str): # pyright: ignore[reportIncompatibleMethodOverride]
233-
try:
234-
vws = workspaces.lookupId(workspace_id)
233+
if workspace_id in workspaces:
235234
if not sublime.ok_cancel_dialog(
236235
"You are currently attached to '{workspace_id}'.\n\
237236
Do you want to detach and delete it?",
238237
ok_title="yes", title="Delete Workspace?",
239-
):
240-
return
238+
): return
241239
self.window.run_command(
242240
"codemp_leave_workspace",
243241
{"workspace_id": workspace_id})
242+
else:
243+
if not sublime.ok_cancel_dialog(
244+
f"Confirm you want to delete the workspace '{workspace_id}'",
245+
ok_title="delete", title="Delete Workspace?",
246+
): return
244247

245-
except KeyError: pass
246-
finally:
247-
session.client.delete_workspace(workspace_id)
248+
session.client.delete_workspace(workspace_id).wait()
248249

plugin/quickpanel/qpbrowser.py

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ def _():
7171
def edit_server(self):
7272
actions = [
7373
qpi("Back", color=qpg.QP_COLOR_CYANISH, letter=qpg.QP_BACK),
74+
qpi("Disconnect", color=qpg.QP_COLOR_REDISH, letter=qpg.QP_BACK),
7475
qpi("New Workspace", color=qpg.QP_COLOR_GREENISH, letter=qpg.QP_ADD),
7576
qpi("Delete Workspace", color=qpg.QP_COLOR_REDISH, letter=qpg.QP_NO)
7677
]
@@ -84,27 +85,37 @@ def edit_server_actions(self, index):
8485
self.run()
8586

8687
if index == 1:
88+
self.window.run_command("codemp_disconnect", {})
89+
90+
if index == 2:
8791
def create_workspace(name):
8892
self.window.run_command(
8993
"codemp_create_workspace", {"workspace_id": name})
90-
self.run()
94+
self.window.run_command(
95+
"codemp_browse_server", {})
96+
9197
self.window.show_input_panel("New Workspace Name", "", create_workspace, None, self.edit_server)
9298

93-
if index == 2:
99+
if index == 3:
94100
def delete_workspace(index):
95101
if index == -1 or index == 0:
96102
self.edit_server()
97-
# we must be careful here. here with index 1 we are selecting the correct
98-
# workspace, because the index zero in the entries is the workspace action submenu.
99-
# which is occupied by the back action.
100-
# if we add extra non workspace entries, then we must shift the index accordingly.
101-
# Do this differently?
103+
return
104+
102105
selected = self.entries[index]
103106
self.window.run_command(
104107
"codemp_delete_workspace",
105108
{"workspace_id": selected.trigger})
109+
self.window.run_command(
110+
"codemp_browse_server", {})
106111

107-
112+
if len(self.entries) < 2:
113+
sublime.message_dialog("You don't have workspaces to delete!")
114+
sublime.set_timeout(self.run, 10)
115+
else:
116+
selentries = self.entries
117+
selentries[0] = qpi("Back", color=qpg.QP_COLOR_CYANISH, letter=qpg.QP_BACK)
118+
show_qp(self.window, selentries, delete_workspace, self.qp_placeholder(), keepopen=False)
108119
show_qp(self.window, self.entries, delete_workspace, self.qp_placeholder())
109120

110121

0 commit comments

Comments
 (0)