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:
39
core/i18n.py
39
core/i18n.py
@@ -396,6 +396,19 @@ _EN = {
|
||||
"info_database": "Database:",
|
||||
"info_ssl": "SSL:",
|
||||
"info_db_index": "DB Index:",
|
||||
|
||||
# Context menu
|
||||
"ctx_open_terminal": "Open Terminal",
|
||||
"ctx_browse_files": "Browse Files",
|
||||
"ctx_install_key": "Install Key",
|
||||
"ctx_open_powershell": "Open PowerShell",
|
||||
"ctx_open_query": "Open Query Editor",
|
||||
"ctx_open_console": "Open Console",
|
||||
"ctx_connect": "Connect",
|
||||
"ctx_open_browser": "Open in Browser",
|
||||
"ctx_check_status": "Check Status",
|
||||
"ctx_copy_alias": "Copy Alias",
|
||||
"ctx_alias_copied": "Alias copied",
|
||||
}
|
||||
|
||||
_RU = {
|
||||
@@ -769,6 +782,19 @@ _RU = {
|
||||
"info_database": "База данных:",
|
||||
"info_ssl": "SSL:",
|
||||
"info_db_index": "Индекс БД:",
|
||||
|
||||
# Context menu
|
||||
"ctx_open_terminal": "Открыть терминал",
|
||||
"ctx_browse_files": "Обзор файлов",
|
||||
"ctx_install_key": "Установить ключ",
|
||||
"ctx_open_powershell": "Открыть PowerShell",
|
||||
"ctx_open_query": "Открыть SQL-редактор",
|
||||
"ctx_open_console": "Открыть консоль",
|
||||
"ctx_connect": "Подключиться",
|
||||
"ctx_open_browser": "Открыть в браузере",
|
||||
"ctx_check_status": "Проверить статус",
|
||||
"ctx_copy_alias": "Копировать алиас",
|
||||
"ctx_alias_copied": "Алиас скопирован",
|
||||
}
|
||||
|
||||
_ZH = {
|
||||
@@ -1142,6 +1168,19 @@ _ZH = {
|
||||
"info_database": "数据库:",
|
||||
"info_ssl": "SSL:",
|
||||
"info_db_index": "数据库索引:",
|
||||
|
||||
# Context menu
|
||||
"ctx_open_terminal": "打开终端",
|
||||
"ctx_browse_files": "浏览文件",
|
||||
"ctx_install_key": "安装密钥",
|
||||
"ctx_open_powershell": "打开 PowerShell",
|
||||
"ctx_open_query": "打开查询编辑器",
|
||||
"ctx_open_console": "打开控制台",
|
||||
"ctx_connect": "连接",
|
||||
"ctx_open_browser": "在浏览器中打开",
|
||||
"ctx_check_status": "检查状态",
|
||||
"ctx_copy_alias": "复制别名",
|
||||
"ctx_alias_copied": "别名已复制",
|
||||
}
|
||||
|
||||
_TRANSLATIONS = {
|
||||
|
||||
41
gui/app.py
41
gui/app.py
@@ -102,6 +102,9 @@ class App(ctk.CTk):
|
||||
self.sidebar.add_callback = self._add_server
|
||||
self.sidebar.edit_callback = self._edit_server
|
||||
self.sidebar.delete_callback = self._delete_server
|
||||
self.sidebar.open_tab_callback = self._context_open_tab
|
||||
self.sidebar.check_status_callback = self._context_check_status
|
||||
self.sidebar.open_browser_callback = self._context_open_browser
|
||||
|
||||
# Main area
|
||||
self._main_frame = ctk.CTkFrame(self, fg_color="transparent")
|
||||
@@ -248,6 +251,44 @@ class App(ctk.CTk):
|
||||
self.store.remove_server(alias)
|
||||
self._on_server_select(None)
|
||||
|
||||
def _context_open_tab(self, alias: str, tab_key: str):
|
||||
"""Context menu: select server and switch to a specific tab."""
|
||||
self._on_server_select(alias)
|
||||
self.sidebar._select(alias)
|
||||
if tab_key in self._tab_keys:
|
||||
try:
|
||||
self.tabview.set(t(tab_key))
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
def _context_check_status(self, alias: str):
|
||||
"""Context menu: check single server status in background."""
|
||||
import threading
|
||||
|
||||
server = self.store.get_server(alias)
|
||||
if not server:
|
||||
return
|
||||
|
||||
def _check():
|
||||
online = self.checker.check_one(server)
|
||||
self.store.set_status(alias, "online" if online else "offline")
|
||||
self.after(0, self.sidebar.update_statuses)
|
||||
|
||||
threading.Thread(target=_check, daemon=True).start()
|
||||
|
||||
def _context_open_browser(self, alias: str):
|
||||
"""Context menu: open Grafana/Prometheus in browser."""
|
||||
import webbrowser
|
||||
|
||||
server = self.store.get_server(alias)
|
||||
if not server:
|
||||
return
|
||||
use_ssl = server.get("use_ssl", False)
|
||||
scheme = "https" if use_ssl else "http"
|
||||
port = server.get("port", 3000)
|
||||
url = f"{scheme}://{server['ip']}:{port}"
|
||||
webbrowser.open(url)
|
||||
|
||||
def _on_status_update(self):
|
||||
self.sidebar.update_statuses()
|
||||
self.sidebar.update_session_indicators()
|
||||
|
||||
@@ -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)
|
||||
|
||||
BIN
releases/ServerManager-v1.8.26-win-x64.exe
Normal file
BIN
releases/ServerManager-v1.8.26-win-x64.exe
Normal file
Binary file not shown.
@@ -1,6 +1,6 @@
|
||||
"""Version info for ServerManager."""
|
||||
|
||||
__version__ = "1.8.25"
|
||||
__version__ = "1.8.26"
|
||||
__app_name__ = "ServerManager"
|
||||
__author__ = "aibot777"
|
||||
__description__ = "Desktop GUI for managing remote servers"
|
||||
|
||||
Reference in New Issue
Block a user