From d949d278cba5844092856c5a3bee1a90e168c5e2 Mon Sep 17 00:00:00 2001 From: shenmo Date: Fri, 30 Oct 2026 20:26:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(chat):=20=E4=BC=9A=E8=AF=9D=E9=87=8D?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E4=B8=8E=E5=88=A0=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 侧栏右键菜单:重命名、删除 - 删除后自动选中相邻会话,流式输出中先取消请求 --- src/chat/chatwindow.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/chat/chatwindow.cpp b/src/chat/chatwindow.cpp index 1133b38..761c7cc 100644 --- a/src/chat/chatwindow.cpp +++ b/src/chat/chatwindow.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -444,6 +445,43 @@ void ChatWindow::setupUi() m_sendButton->setEnabled(false); connect(m_sidebar, &QListWidget::currentRowChanged, this, &ChatWindow::selectConversation); + + m_sidebar->setContextMenuPolicy(Qt::CustomContextMenu); + connect(m_sidebar, &QListWidget::customContextMenuRequested, this, + [this](const QPoint &pos) { + const QModelIndex index = m_sidebar->indexAt(pos); + if (!index.isValid() || index.row() >= m_conversations.size()) { + return; + } + const int row = index.row(); + QMenu menu(this); + QAction *rename = menu.addAction(tr("重命名对话")); + QAction *remove = menu.addAction(tr("删除对话")); + QAction *chosen = menu.exec(m_sidebar->viewport()->mapToGlobal(pos)); + if (chosen == rename) { + bool ok = false; + const QString title = QInputDialog::getText( + nullptr, tr("重命名对话"), tr("名称"), QLineEdit::Normal, + m_conversations.at(row).title, &ok); + if (ok && !title.trimmed().isEmpty()) { + m_conversations[row].title = title.trimmed(); + save(); + updateSidebar(); + renderConversation(); + } + } else if (chosen == remove) { + if (m_client->busy()) { + m_client->cancel(); + m_streamingIndex = -1; + } + m_conversations.removeAt(row); + m_current = m_conversations.isEmpty() ? -1 + : qBound(0, row, m_conversations.size() - 1); + save(); + updateSidebar(); + renderConversation(); + } + }); connect(static_cast(m_sidebar), &ChatSidebar::droppedAt, this, &ChatWindow::handleDropOnConversation); connect(static_cast(m_view), &ChatView::dropped, this,