| 345 | } |
| 346 | |
| 347 | void DiffViewsCtrl::applySelected(DiffViewsCtrl::ApplyAction act) |
| 348 | { |
| 349 | auto vData = activeView(); |
| 350 | if (! vData.isValid() ) |
| 351 | return; |
| 352 | |
| 353 | if (vData.area != RepoStatusModel::None) { |
| 354 | // Setup arguments to subDiff & apply based on the required action |
| 355 | auto [direction, params] = [act]() -> std::pair<VcsDiff::DiffDirection, GitPlugin::ApplyParams> { |
| 356 | switch (act) { |
| 357 | case Stage: |
| 358 | return { VcsDiff::Normal, GitPlugin::Index }; |
| 359 | case Unstage: |
| 360 | return { VcsDiff::Reverse, GitPlugin::Index }; |
| 361 | case Revert: |
| 362 | return { VcsDiff::Reverse, GitPlugin::WorkTree }; |
| 363 | } |
| 364 | Q_UNREACHABLE(); |
| 365 | }(); |
| 366 | |
| 367 | // Construct the selected diff (either from the selected lines |
| 368 | // or the hunk containing the current cursor position) |
| 369 | VcsDiff fullDiff, selectedDiff; |
| 370 | fullDiff.setDiff(vData.ktDoc->text()); |
| 371 | fullDiff.setBaseDiff(vData.project->path().toUrl()); |
| 372 | auto range = vData.actView->selectionRange(); |
| 373 | if (range.isEmpty()) { |
| 374 | selectedDiff = fullDiff.subDiffHunk(vData.actView->cursorPosition().line(), direction); |
| 375 | } else { |
| 376 | int startLine = range.start().line(); |
| 377 | int endLine = range.end().line(); |
| 378 | selectedDiff = fullDiff.subDiff(startLine, endLine, direction); |
| 379 | } |
| 380 | |
| 381 | // Run the apply job |
| 382 | VcsJob* indexJob = vData.vcs->apply(selectedDiff, params); |
| 383 | connect(indexJob, &VcsJob::resultsReady, this, [=] { |
| 384 | if (indexJob->status() == VcsJob::JobSucceeded) { |
| 385 | updateUrlDiffs(vData.url); |
| 386 | } |
| 387 | }); |
| 388 | ICore::self()->runController()->registerJob(indexJob); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | void DiffViewsCtrl::gotoSrcLine() |
| 393 | { |
nothing calls this directly
no test coverage detected