v1.8.26: right-click context menu on sidebar servers

Type-adaptive menu: SSH (terminal/files/keys), SQL (query editor),
Redis (console), Grafana/Prometheus (open browser), WinRM (PowerShell),
RDP/VNC (connect). Universal: check status, copy alias, edit, delete.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
chrome-storm-c442
2026-02-24 10:00:00 -05:00
parent 1b3fb30680
commit 4e9012e2ab
5 changed files with 173 additions and 3 deletions

View File

@@ -1,7 +1,8 @@
"""
Sidebar — server list with search, add/edit/delete buttons.
Sidebar — server list with search, add/edit/delete buttons, context menu.
"""
import tkinter as tk
import customtkinter as ctk
from core.i18n import t
from gui.widgets.status_badge import StatusBadge
@@ -35,6 +36,22 @@ TYPE_LABELS = {
}
# Context menu: type → list of (i18n_key, tab_key_or_None)
_CONTEXT_ACTIONS = {
"ssh": [("ctx_open_terminal", "terminal"), ("ctx_browse_files", "files"), ("ctx_install_key", "keys")],
"telnet": [("ctx_open_terminal", "terminal")],
"winrm": [("ctx_open_powershell", "powershell")],
"mariadb": [("ctx_open_query", "query")],
"mssql": [("ctx_open_query", "query")],
"postgresql": [("ctx_open_query", "query")],
"redis": [("ctx_open_console", "console")],
"grafana": [("ctx_open_browser", None)],
"prometheus": [("ctx_open_browser", None)],
"rdp": [("ctx_connect", "launch")],
"vnc": [("ctx_connect", "launch")],
}
class Sidebar(ctk.CTkFrame):
def __init__(self, master, store, on_select=None, session_pool=None):
super().__init__(master, width=250, corner_radius=0)
@@ -79,10 +96,13 @@ class Sidebar(ctk.CTkFrame):
self.del_btn = ctk.CTkButton(btn_frame, text=t("delete"), width=70, height=30, fg_color="#ef4444", hover_color="#dc2626", command=self._on_delete)
self.del_btn.pack(side="right", padx=(3, 0))
# Callbacks for add/edit/delete — set by app.py
# Callbacks — set by app.py
self.add_callback = None
self.edit_callback = None
self.delete_callback = None
self.open_tab_callback = None # (alias, tab_key) → select server + switch tab
self.check_status_callback = None # (alias) → check single server
self.open_browser_callback = None # (alias) → open server URL in browser
# Subscribe to store changes
self.store.subscribe(self._refresh_list)
@@ -162,6 +182,7 @@ class Sidebar(ctk.CTkFrame):
# Click handlers
for widget in [frame, info, name_label, detail_label, badge, type_badge, session_ind]:
widget.bind("<Button-1>", lambda e, a=alias: self._select(a))
widget.bind("<Button-3>", lambda e, a=alias: self._show_context_menu(e, a))
self._server_frames[alias] = frame
@@ -222,3 +243,72 @@ class Sidebar(ctk.CTkFrame):
def _on_delete(self):
if self.delete_callback and self._selected_alias:
self.delete_callback(self._selected_alias)
def _show_context_menu(self, event, alias: str):
"""Show right-click context menu for a server item."""
self._select(alias)
server = self.store.get_server(alias)
if not server:
return
stype = server.get("type", "ssh")
menu = tk.Menu(self, tearoff=0, bg="#2d2d44", fg="#d3d7cf",
activebackground="#44447a", activeforeground="#ffffff",
font=("Segoe UI", 10))
# Type-specific actions
actions = _CONTEXT_ACTIONS.get(stype, [])
for label_key, tab_key in actions:
if tab_key:
menu.add_command(
label=t(label_key),
command=lambda a=alias, tk=tab_key: (
self.open_tab_callback(a, tk) if self.open_tab_callback else None
),
)
else:
menu.add_command(
label=t(label_key),
command=lambda a=alias: (
self.open_browser_callback(a) if self.open_browser_callback else None
),
)
if actions:
menu.add_separator()
# Universal actions
menu.add_command(
label=t("ctx_check_status"),
command=lambda: (
self.check_status_callback(alias) if self.check_status_callback else None
),
)
menu.add_command(
label=t("ctx_copy_alias"),
command=lambda: self._copy_alias(alias),
)
menu.add_separator()
# Management
menu.add_command(
label=t("edit"),
command=lambda: self.edit_callback(alias) if self.edit_callback else None,
)
menu.add_command(
label=t("delete"),
command=lambda: self.delete_callback(alias) if self.delete_callback else None,
foreground="#ef4444",
)
try:
menu.tk_popup(event.x_root, event.y_root)
finally:
menu.grab_release()
def _copy_alias(self, alias: str):
"""Copy server alias to clipboard."""
self.clipboard_clear()
self.clipboard_append(alias)