Merge pull request #1183 from flylai/dev-log-copy-selected

feat: support copying selected logs
This commit is contained in:
flylai 2020-12-24 15:07:29 +08:00 committed by GitHub
commit 88a2b51da3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 46 additions and 38 deletions

View File

@ -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<ConnectionGroupPair> connlist;
QList<GroupId> groupsList;
QList<GroupId> 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()

View File

@ -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);

View File

@ -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."));
}

View File

@ -1068,18 +1068,22 @@ This entry is ignored by V2Ray core when using DoH servers.</source>
<source>Copy latest logs.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you want to remove this group as well?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Group: </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Removing Connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Do you want to remove this group as well?</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Group: </source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Removing Connection</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Copy selected.</source>
<translation type="unfinished"></translation>
</message>
</context>
<context>
<name>OutboundEditor</name>