diff --git a/ui/terminal_tab_widget.py b/ui/terminal_tab_widget.py index e054b4f..dbe63d8 100644 --- a/ui/terminal_tab_widget.py +++ b/ui/terminal_tab_widget.py @@ -231,6 +231,7 @@ class TerminalTabWidget(QWidget): menu = QMenu(self) panel = self._panel_at(idx) a_rename = menu.addAction("重命名") + a_duplicate = menu.addAction("📋 复制标签") a_close = menu.addAction("关闭标签") a_close_others = menu.addAction("关闭其他") if panel and panel._connected: @@ -242,6 +243,8 @@ class TerminalTabWidget(QWidget): chosen = menu.exec_(self.tabs.tabBar().mapToGlobal(pos)) if chosen == a_rename: self._on_tab_double_clicked(idx) + elif chosen == a_duplicate: + self._duplicate_tab(idx) elif chosen == a_close: self._close_tab(idx) elif chosen == a_close_others: @@ -250,6 +253,29 @@ class TerminalTabWidget(QWidget): if panel and panel.conn: panel._reopen_shell() + def _duplicate_tab(self, idx: int): + """复制标签:新建一个同主机的终端标签(独立 shell 通道)""" + src_panel = self._panel_at(idx) + if src_panel is None: + return + host_id = self._host_id_for_panel(src_panel) + # 决定新标签的初始连接 + conn = self.manager.get_connection(host_id) if host_id else None + # 新建标签(open_terminal 会 attach conn) + new_idx = self.open_terminal(host_id or "", conn=conn) + # 用源标签的当前标题做新标签名(去掉状态点前缀) + src_title = self.tabs.tabText(idx) + for prefix in ("⚪ ", "🟢 ", "🔴 ", "🟡 "): + if src_title.startswith(prefix): + src_title = src_title[len(prefix):] + break + # 加 " (副本)" 后缀 + self.tabs.setTabText(new_idx, f"⚪ {src_title} (副本)") + self.tabs.setCurrentIndex(new_idx) + # 如果已连接,给用户一个小提示:每个副本是独立 shell + if conn: + self.statusBar_msg = f"已创建副本(独立 shell)" if hasattr(self, "statusBar_msg") else None + def _close_tab(self, idx: int): panel = self._panel_at(idx) if panel and panel._connected: