| 160 | } |
| 161 | |
| 162 | void StackView::onStackTreeContextMenuRequest(QPoint pos) |
| 163 | { |
| 164 | QMenu menu(m_stackTree); |
| 165 | auto model = m_stackTree->model(); |
| 166 | |
| 167 | auto copyStackAct = menu.addAction(i18n("Copy Stack Trace")); |
| 168 | connect(copyStackAct, &QAction::triggered, m_stackTree, [model] { |
| 169 | QString text; |
| 170 | for (int i = 0; i < model->rowCount(); ++i) { |
| 171 | QString no = model->index(i, StackFrameModel::Column::Number).data().toString(); |
| 172 | QString func = model->index(i, StackFrameModel::Column::Func).data().toString(); |
| 173 | QString path = model->index(i, StackFrameModel::Column::Path).data().toString(); |
| 174 | text.append(QStringLiteral("#%1 %2 %3\n").arg(no, func, path)); |
| 175 | } |
| 176 | qApp->clipboard()->setText(text); |
| 177 | }); |
| 178 | |
| 179 | auto index = m_stackTree->currentIndex(); |
| 180 | if (index.isValid()) { |
| 181 | auto frame = index.data(StackFrameModel::StackFrameRole).value<dap::StackFrame>(); |
| 182 | if (frame.source) { |
| 183 | auto url = frame.source->path; |
| 184 | int line = frame.line - 1; |
| 185 | if (url.isValid()) { |
| 186 | auto a = menu.addAction(i18n("Open Location")); |
| 187 | connect(a, &QAction::triggered, m_stackTree, [this, url, line] { |
| 188 | Utils::goToDocumentLocation(m_mainWindow, url, KTextEditor::Range({line, 0}, 0), {.focus = true, .record = false}); |
| 189 | }); |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | auto copyLocAct = menu.addAction(i18n("Copy Location")); |
| 194 | QString location = QStringLiteral("%1:%2").arg(Utils::formatUrl(frame.source->path)).arg(frame.line); |
| 195 | connect(copyLocAct, &QAction::triggered, m_stackTree, [location] { |
| 196 | qApp->clipboard()->setText(location); |
| 197 | }); |
| 198 | } |
| 199 | |
| 200 | menu.exec(m_stackTree->viewport()->mapToGlobal(pos)); |
| 201 | } |
nothing calls this directly
no test coverage detected