From b3bfb4a83469f605043c12107a99e1bb299dab40 Mon Sep 17 00:00:00 2001 From: LKM Date: Thu, 24 Dec 2020 11:29:27 +0800 Subject: [PATCH] feat: support copying seleted logs --- src/ui/widgets/windows/w_MainWindow.cpp | 54 ++++++++++--------- src/ui/widgets/windows/w_MainWindow.hpp | 1 + src/ui/widgets/windows/w_MainWindow_extra.cpp | 1 + translations/en_US.ts | 28 +++++----- 4 files changed, 46 insertions(+), 38 deletions(-) diff --git a/src/ui/widgets/windows/w_MainWindow.cpp b/src/ui/widgets/windows/w_MainWindow.cpp index 403cbfd7..cb181972 100644 --- a/src/ui/widgets/windows/w_MainWindow.cpp +++ b/src/ui/widgets/windows/w_MainWindow.cpp @@ -192,6 +192,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma // // Actions for right click the log text browser // + logRCM_Menu->addAction(action_RCM_CopySelected); logRCM_Menu->addAction(action_RCM_CopyRecentLogs); logRCM_Menu->addSeparator(); logRCM_Menu->addAction(action_RCM_SwitchCoreLog); @@ -200,6 +201,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma connect(action_RCM_SwitchCoreLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(vCoreLogDocument); }); connect(action_RCM_SwitchQv2rayLog, &QAction::triggered, [this] { masterLogBrowser->setDocument(qvLogDocument); }); connect(action_RCM_CopyRecentLogs, &QAction::triggered, this, &MainWindow::Action_CopyRecentLogs); + connect(action_RCM_CopySelected, &QAction::triggered, masterLogBrowser, &QTextBrowser::copy); // speedChartWidget->setContextMenuPolicy(Qt::CustomContextMenu); connect(speedChartWidget, &QWidget::customContextMenuRequested, [this](const QPoint &) { graphWidgetMenu->popup(QCursor::pos()); }); @@ -282,13 +284,13 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), QvStateObject("Ma // Find and start if there is an auto-connection const auto connectionStarted = StartAutoConnectionEntry(); - if (!connectionStarted && !ConnectionManager->GetConnections().isEmpty()) + if (!connectionStarted && !ConnectionManager->GetConnections().isEmpty()) { // Select the first connection. const auto groups = ConnectionManager->AllGroups(); if (!groups.isEmpty()) { - const auto connections = ConnectionManager->GetConnections(groups.first()); + const auto connections = ConnectionManager->GetConnections(groups.first()); if (!connections.empty()) { const auto index = modelHelper->GetConnectionPairIndex({ connections.first(), groups.first() }); @@ -526,32 +528,32 @@ void MainWindow::on_connectionTreeView_customContextMenuRequested(const QPoint & void MainWindow::Action_DeleteConnections() { QList connlist; - QList groupsList; + QList groupsList; for (const auto &item : connectionTreeView->selectionModel()->selectedIndexes()) { - const auto widget = GetIndexWidget(item); - if (!widget) - continue; - - const auto identifier = widget->Identifier(); - if (widget->IsConnection()) + const auto widget = GetIndexWidget(item); + if (!widget) + continue; + + const auto identifier = widget->Identifier(); + if (widget->IsConnection()) { - // Simply add the connection id - connlist.append(identifier); - continue; + // Simply add the connection id + connlist.append(identifier); + continue; } - for (const auto &conns : ConnectionManager->GetConnections(identifier.groupId)) - { - connlist.append(ConnectionGroupPair{ conns, identifier.groupId }); - } + for (const auto &conns : ConnectionManager->GetConnections(identifier.groupId)) + { + connlist.append(ConnectionGroupPair{ conns, identifier.groupId }); + } - const auto message = tr("Do you want to remove this group as well?") + NEWLINE + tr("Group: ") + GetDisplayName(identifier.groupId); - if (QvMessageBoxAsk(this, tr("Removing Connection"), message) == Yes) - { - groupsList << identifier.groupId; - } + const auto message = tr("Do you want to remove this group as well?") + NEWLINE + tr("Group: ") + GetDisplayName(identifier.groupId); + if (QvMessageBoxAsk(this, tr("Removing Connection"), message) == Yes) + { + groupsList << identifier.groupId; + } } const auto strRemoveConnTitle = tr("Removing Connection(s)", "", connlist.count()); @@ -565,11 +567,11 @@ void MainWindow::Action_DeleteConnections() { ConnectionManager->RemoveConnectionFromGroup(conn.connectionId, conn.groupId); } - - for (const auto &group : groupsList) - { - ConnectionManager->DeleteGroup(group); - } + + for (const auto &group : groupsList) + { + ConnectionManager->DeleteGroup(group); + } } void MainWindow::on_importConfigButton_clicked() diff --git a/src/ui/widgets/windows/w_MainWindow.hpp b/src/ui/widgets/windows/w_MainWindow.hpp index 12578064..2c7e7f14 100644 --- a/src/ui/widgets/windows/w_MainWindow.hpp +++ b/src/ui/widgets/windows/w_MainWindow.hpp @@ -151,6 +151,7 @@ class MainWindow DECL_ACTION(logRCM_Menu, action_RCM_SwitchCoreLog); DECL_ACTION(logRCM_Menu, action_RCM_SwitchQv2rayLog); DECL_ACTION(logRCM_Menu, action_RCM_CopyRecentLogs); + DECL_ACTION(logRCM_Menu, action_RCM_CopySelected); #undef DECL_ACTION QTextDocument *vCoreLogDocument = new QTextDocument(this); diff --git a/src/ui/widgets/windows/w_MainWindow_extra.cpp b/src/ui/widgets/windows/w_MainWindow_extra.cpp index e641c7f5..6f9dc273 100644 --- a/src/ui/widgets/windows/w_MainWindow_extra.cpp +++ b/src/ui/widgets/windows/w_MainWindow_extra.cpp @@ -233,4 +233,5 @@ void MainWindow::UpdateActionTranslations() // action_RCM_CopyGraph->setText(tr("Copy graph as image.")); action_RCM_CopyRecentLogs->setText(tr("Copy latest logs.")); + action_RCM_CopySelected->setText(tr("Copy selected.")); } diff --git a/translations/en_US.ts b/translations/en_US.ts index 08fb9a8e..d88632c7 100644 --- a/translations/en_US.ts +++ b/translations/en_US.ts @@ -1068,18 +1068,22 @@ This entry is ignored by V2Ray core when using DoH servers. Copy latest logs. - - Do you want to remove this group as well? - - - - Group: - - - - Removing Connection - - + + Do you want to remove this group as well? + + + + Group: + + + + Removing Connection + + + + Copy selected. + + OutboundEditor