use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class MacheteAnnotator method processMacheteGeneratedEntry.
@UIThreadUnsafe
private void processMacheteGeneratedEntry(MacheteGeneratedEntry macheteEntry, AnnotationHolder holder) {
MacheteGeneratedBranch branch = macheteEntry.getBranch();
PsiFile file = macheteEntry.getContainingFile();
val branchNames = MacheteFileUtils.getBranchNamesForPsiFile(file);
if (branchNames.isEmpty()) {
if (!cantGetBranchesMessageWasShown) {
UiThreadExecutionCompat.invokeLaterIfNeeded(NON_MODAL, () -> showCantGetBranchesMessage(file));
}
return;
}
cantGetBranchesMessageWasShown = false;
val processedBranchName = branch.getText();
if (!branchNames.contains(processedBranchName)) {
holder.newAnnotation(HighlightSeverity.ERROR, format(getString("string.GitMachete.MacheteAnnotator.cannot-find-local-branch-in-repo"), processedBranchName)).range(branch).create();
}
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class MacheteCompletionContributor method fillCompletionVariants.
@Override
@UIThreadUnsafe
public void fillCompletionVariants(CompletionParameters parameters, CompletionResultSet result) {
PsiFile file = parameters.getOriginalFile();
val branchNames = MacheteFileUtils.getBranchNamesForPsiFile(file);
if (branchNames.isEmpty()) {
return;
}
/**
* {@link CompletionResultSet#stopHere} marks the result set as stopped.
* Completion service calls contributors as long as everyone gets called or result set get marked as stopped.
* The following call allows to avoid other contributor invocations (performance).
*
* See {@link com.intellij.codeInsight.completion.CompletionService#getVariantsFromContributors}
*/
result.stopHere();
String prefix = getCompletionPrefix(parameters);
val matcher = new PlainPrefixMatcher(prefix, /* prefixMatchesOnly */
true);
val completionResultSet = result.caseInsensitive().withPrefixMatcher(matcher);
for (String branchName : branchNames) {
ProgressManager.checkCanceled();
completionResultSet.addElement(LookupElementBuilder.create(branchName));
}
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class MacheteFileUtils method getBranchNamesForPsiFile.
@UIThreadUnsafe
public static List<String> getBranchNamesForPsiFile(PsiFile psiFile) {
val project = psiFile.getProject();
val gitRepository = List.ofAll(GitRepositoryManager.getInstance(project).getRepositories()).find(repository -> GitVfsUtils.getMacheteFile(repository).map(macheteFile -> macheteFile.equals(psiFile.getVirtualFile())).getOrElse(false));
if (gitRepository.isEmpty()) {
return List.empty();
}
return List.ofAll(gitRepository.get().getInfo().getLocalBranchesWithHashes().keySet()).map(localBranch -> localBranch.getName());
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class GitMacheteRepository method discoverLayoutAndCreateSnapshot.
@Override
@UIThreadUnsafe
public IGitMacheteRepositorySnapshot discoverLayoutAndCreateSnapshot() throws GitMacheteException {
LOG.startTimer().debug("Entering");
try {
val aux = new DiscoverGitMacheteRepositoryAux(gitCoreRepository, statusHookExecutor, preRebaseHookExecutor);
val result = aux.discoverLayoutAndCreateSnapshot(NUMBER_OF_MOST_RECENTLY_CHECKED_OUT_BRANCHES_FOR_DISCOVER);
LOG.withTimeElapsed().info("Finished");
return result;
} catch (GitCoreException e) {
throw new GitMacheteException(e);
}
}
use of com.virtuslab.qual.guieffect.UIThreadUnsafe in project git-machete-intellij-plugin by VirtusLab.
the class GitCommandUpdatingCurrentBranchBackgroundable method handleResult.
@UIThreadUnsafe
private void handleResult(GitCommandResult result, GitLocalChangesWouldBeOverwrittenDetector localChangesDetector, GitUntrackedFilesOverwrittenByOperationDetector untrackedFilesDetector, GitRevisionNumber currentRev, Label beforeLabel, @Nullable GitUpdatedRanges updatedRanges) {
VirtualFile root = gitRepository.getRoot();
if (result.success()) {
VfsUtil.markDirtyAndRefresh(/* async */
false, /* recursive */
true, /* reloadChildren */
false, root);
gitRepository.update();
if (updatedRanges != null && AbstractCommonUpdateAction.showsCustomNotification(java.util.Collections.singletonList(GitVcs.getInstance(project)))) {
val ranges = updatedRanges.calcCurrentPositions();
GitUpdateInfoAsLog.NotificationData notificationData = new GitUpdateInfoAsLog(project, ranges).calculateDataAndCreateLogTab();
Notification notification;
if (notificationData != null) {
String title = getTitleForUpdateNotification(notificationData.getUpdatedFilesCount(), notificationData.getReceivedCommitsCount());
String content = getBodyForUpdateNotification(notificationData.getFilteredCommitsCount());
notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification(title, content, INFORMATION, /* listener */
null);
notification.addAction(NotificationAction.createSimple(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.message.view-commits"), notificationData.getViewCommitAction()));
} else {
// When the pull results with no commits, there is no git update info (as log).
// Based on that we know that all files are up-to-date.
notification = VcsNotifier.STANDARD_NOTIFICATION.createNotification(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.title.all-files-are-up-to-date"), /* content */
"", INFORMATION, /* listener */
null);
}
VcsNotifier.getInstance(project).notify(notification);
} else {
showUpdates(currentRev, beforeLabel);
}
} else if (localChangesDetector.wasMessageDetected()) {
localChangesWouldBeOverwrittenHelper_showErrorNotification(project, gitRepository.getRoot(), getOperationName(), localChangesDetector.getRelativeFilePaths());
} else if (untrackedFilesDetector.wasMessageDetected()) {
GitUntrackedFilesHelper.notifyUntrackedFilesOverwrittenBy(project, root, untrackedFilesDetector.getRelativeFilePaths(), getOperationName(), /* description */
null);
} else {
IntelliJNotificationCompat.notifyError(project, format(getString("action.GitMachete.GitCommandUpdatingCurrentBranchBackgroundable.notification.title.update-fail"), getOperationName()), result.getErrorOutputAsJoinedString());
gitRepository.update();
}
}
Aggregations