triage: make it possible to copy selected results

This commit is contained in:
Daniel Marjamäki 2021-12-22 18:58:11 +01:00
parent 5491670792
commit 4d5ad5e42e
2 changed files with 22 additions and 0 deletions

View File

@ -32,6 +32,10 @@ MainWindow::MainWindow(QWidget *parent) :
workFolder.mkdir(WORK_FOLDER); workFolder.mkdir(WORK_FOLDER);
} }
ui->results->setContextMenuPolicy(Qt::CustomContextMenu);
connect(ui->results, &QListWidget::customContextMenuRequested,
this, &MainWindow::resultsContextMenu);
mFSmodel.setRootPath(WORK_FOLDER); mFSmodel.setRootPath(WORK_FOLDER);
mFSmodel.setReadOnly(true); mFSmodel.setReadOnly(true);
mFSmodel.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot); mFSmodel.setFilter(QDir::Dirs | QDir::Files | QDir::NoDotAndDotDot);
@ -342,3 +346,20 @@ void MainWindow::searchResultsDoubleClick()
const int line = filename.midRef(idx + 1).toInt(); const int line = filename.midRef(idx + 1).toInt();
showSrcFile(WORK_FOLDER + QString{"/"} + filename.left(idx), "", line); showSrcFile(WORK_FOLDER + QString{"/"} + filename.left(idx), "", line);
} }
void MainWindow::resultsContextMenu(const QPoint& pos)
{
if (ui->results->selectedItems().isEmpty())
return;
QMenu submenu;
submenu.addAction("Copy");
QAction* menuItem = submenu.exec(ui->results->mapToGlobal(pos));
if (menuItem && menuItem->text().contains("Copy"))
{
QString text;
for (const auto *res: ui->results->selectedItems())
text += res->text() + "\n";
QApplication::clipboard()->setText(text);
}
}

View File

@ -30,6 +30,7 @@ public slots:
void findInFilesClicked(); void findInFilesClicked();
void directorytreeDoubleClick(); void directorytreeDoubleClick();
void searchResultsDoubleClick(); void searchResultsDoubleClick();
void resultsContextMenu(const QPoint& pos);
private: private:
Ui::MainWindow *ui; Ui::MainWindow *ui;