| 506 | } |
| 507 | |
| 508 | void MainWindow::navigateToCode(const QUrl &url, int lineNumber, int columnNumber) |
| 509 | { |
| 510 | // Show Qt resources in our qrc browser |
| 511 | if (url.scheme() == QLatin1String("qrc")) { |
| 512 | if (selectTool(QStringLiteral("GammaRay::ResourceBrowser"))) { |
| 513 | QMetaObject::invokeMethod(ui->toolStack->currentWidget(), "selectResource", |
| 514 | Q_ARG(QString, url.toString()), |
| 515 | Q_ARG(int, lineNumber), Q_ARG(int, columnNumber)); |
| 516 | } |
| 517 | } else { |
| 518 | QSettings settings; |
| 519 | settings.beginGroup(QStringLiteral("CodeNavigation")); |
| 520 | const auto ideIdx = settings.value(QStringLiteral("IDE"), IDE_SETTING_DEFAULT).toInt(); |
| 521 | |
| 522 | QString command; |
| 523 | if (ideIdx >= 0 && ideIdx < ideSettingsSize) { |
| 524 | command += ideSettings[ideIdx].app; |
| 525 | command += ' '; |
| 526 | command += ideSettings[ideIdx].args; |
| 527 | } else if (ideIdx == IDE_SETTING_CUSTOM) { |
| 528 | command = settings.value(QStringLiteral("CustomCommand")).toString(); |
| 529 | } else { |
| 530 | QDesktopServices::openUrl(QUrl(url)); |
| 531 | } |
| 532 | |
| 533 | const QString filePath = url.isLocalFile() ? url.toLocalFile() : url.toString(); |
| 534 | command.replace(QStringLiteral("%f"), filePath); |
| 535 | command.replace(QStringLiteral("%l"), QString::number(std::max(1, lineNumber + 1))); |
| 536 | command.replace(QStringLiteral("%c"), QString::number(std::max(1, columnNumber + 1))); |
| 537 | |
| 538 | if (!command.isEmpty()) { |
| 539 | std::cout << "Detaching: " << qPrintable(command) << std::endl; |
| 540 | // TODO refactor this to avoid the command splitting altogether, so we don't fail with e.g. spaces in paths |
| 541 | auto s = command.split(QLatin1Char(' ')); |
| 542 | const QString program = s.takeFirst(); |
| 543 | QProcess::startDetached(program, s); |
| 544 | } |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | void MainWindow::closeEvent(QCloseEvent *e) |
| 549 | { |
no test coverage detected