MCPcopy Create free account
hub / github.com/KDE/kdevelop / applySelected

Method applySelected

plugins/git/diffviewsctrl.cpp:347–390  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

345}
346
347void 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
392void DiffViewsCtrl::gotoSrcLine()
393{

Callers

nothing calls this directly

Calls 15

setBaseDiffMethod · 0.80
subDiffHunkMethod · 0.80
subDiffMethod · 0.80
registerJobMethod · 0.80
runControllerMethod · 0.80
isValidMethod · 0.45
setDiffMethod · 0.45
textMethod · 0.45
toUrlMethod · 0.45
pathMethod · 0.45
isEmptyMethod · 0.45
lineMethod · 0.45

Tested by

no test coverage detected