use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class LongLineInspection method createOptionsPanel.
@Nullable
@Override
public JComponent createOptionsPanel() {
final HyperlinkLabel codeStyleHyperlink = new HyperlinkLabel("Edit Code Style settings");
codeStyleHyperlink.addHyperlinkListener(new HyperlinkListener() {
@Override
public void hyperlinkUpdate(HyperlinkEvent e) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone(new Consumer<DataContext>() {
@Override
public void consume(DataContext context) {
if (context != null) {
final Settings settings = Settings.KEY.getData(context);
if (settings != null) {
settings.select(settings.find(CodeStyleSchemesConfigurable.class));
} else {
ShowSettingsUtil.getInstance().showSettingsDialog(CommonDataKeys.PROJECT.getData(context), CodeStyleSchemesConfigurable.class);
}
}
}
});
}
});
final JPanel panel = new JPanel();
panel.setLayout(new BorderLayout());
panel.add(codeStyleHyperlink, BorderLayout.NORTH);
return panel;
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class BaseProjectTreeBuilder method _select.
private void _select(final Object element, final VirtualFile file, final boolean requestFocus, final Condition<AbstractTreeNode> nonStopCondition, final ActionCallback result, @NotNull final ProgressIndicator indicator, @Nullable final Ref<Object> virtualSelectTarget, final FocusRequestor focusRequestor, final boolean isSecondAttempt) {
final AbstractTreeNode alreadySelected = alreadySelectedNode(element);
final Runnable onDone = () -> {
if (requestFocus && virtualSelectTarget == null && getUi().isReady()) {
focusRequestor.requestFocus(getTree(), true);
}
result.setDone();
};
final Condition<AbstractTreeNode> condition = abstractTreeNode -> !result.isProcessed() && nonStopCondition.value(abstractTreeNode);
if (alreadySelected == null) {
expandPathTo(file, (AbstractTreeNode) getTreeStructure().getRootElement(), element, condition, indicator, virtualSelectTarget).doWhenDone(new Consumer<AbstractTreeNode>() {
@Override
public void consume(AbstractTreeNode node) {
if (virtualSelectTarget == null) {
select(node, onDone);
} else {
onDone.run();
}
}
}).doWhenRejected(() -> {
if (isSecondAttempt) {
result.setRejected();
} else {
_select(file, file, requestFocus, nonStopCondition, result, indicator, virtualSelectTarget, focusRequestor, true);
}
});
} else if (virtualSelectTarget == null) {
scrollTo(alreadySelected, onDone);
} else {
onDone.run();
}
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class UpdateHighlightersUtil method createOrReuseHighlighterFor.
private static void createOrReuseHighlighterFor(@NotNull final HighlightInfo info, // if null global scheme will be used
@Nullable final EditorColorsScheme colorsScheme, @NotNull final Document document, final int group, @NotNull final PsiFile psiFile, @NotNull MarkupModelEx markup, @Nullable HighlightersRecycler infosToRemove, @NotNull final Map<TextRange, RangeMarker> ranges2markersCache, @NotNull SeverityRegistrar severityRegistrar) {
int infoStartOffset = info.startOffset;
int infoEndOffset = info.endOffset;
final int docLength = document.getTextLength();
if (infoEndOffset > docLength) {
infoEndOffset = docLength;
infoStartOffset = Math.min(infoStartOffset, infoEndOffset);
}
if (infoEndOffset == infoStartOffset && !info.isAfterEndOfLine()) {
// empty highlighter beyond file boundaries
if (infoEndOffset == docLength)
return;
//show something in case of empty highlightinfo
infoEndOffset++;
}
info.setGroup(group);
int layer = getLayer(info, severityRegistrar);
RangeHighlighterEx highlighter = infosToRemove == null ? null : (RangeHighlighterEx) infosToRemove.pickupHighlighterFromGarbageBin(info.startOffset, info.endOffset, layer);
final TextRange finalInfoRange = new TextRange(infoStartOffset, infoEndOffset);
final TextAttributes infoAttributes = info.getTextAttributes(psiFile, colorsScheme);
Consumer<RangeHighlighterEx> changeAttributes = finalHighlighter -> {
if (infoAttributes != null) {
finalHighlighter.setTextAttributes(infoAttributes);
}
info.setHighlighter(finalHighlighter);
finalHighlighter.setAfterEndOfLine(info.isAfterEndOfLine());
Color color = info.getErrorStripeMarkColor(psiFile, colorsScheme);
finalHighlighter.setErrorStripeMarkColor(color);
if (info != finalHighlighter.getErrorStripeTooltip()) {
finalHighlighter.setErrorStripeTooltip(info);
}
GutterMark renderer = info.getGutterIconRenderer();
finalHighlighter.setGutterIconRenderer((GutterIconRenderer) renderer);
ranges2markersCache.put(finalInfoRange, info.getHighlighter());
if (info.quickFixActionRanges != null) {
List<Pair<HighlightInfo.IntentionActionDescriptor, RangeMarker>> list = new ArrayList<>(info.quickFixActionRanges.size());
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
TextRange textRange = pair.second;
RangeMarker marker = getOrCreate(document, ranges2markersCache, textRange);
list.add(Pair.create(pair.first, marker));
}
info.quickFixActionMarkers = ContainerUtil.createLockFreeCopyOnWriteList(list);
}
ProperTextRange fixRange = info.getFixTextRange();
if (finalInfoRange.equals(fixRange)) {
info.fixMarker = null;
} else {
info.fixMarker = getOrCreate(document, ranges2markersCache, fixRange);
}
};
if (highlighter == null) {
highlighter = markup.addRangeHighlighterAndChangeAttributes(infoStartOffset, infoEndOffset, layer, null, HighlighterTargetArea.EXACT_RANGE, false, changeAttributes);
} else {
markup.changeAttributesInBatch(highlighter, changeAttributes);
}
boolean attributesSet = Comparing.equal(infoAttributes, highlighter.getTextAttributes());
assert attributesSet : "Info: " + infoAttributes + "; colorsScheme: " + (colorsScheme == null ? "[global]" : colorsScheme.getName()) + "; highlighter:" + highlighter.getTextAttributes();
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class EditorTabbedContainer method close.
@Override
public void close() {
TabInfo selected = myTabs.getTargetInfo();
if (selected == null)
return;
final VirtualFile file = (VirtualFile) selected.getObject();
final FileEditorManagerEx mgr = FileEditorManagerEx.getInstanceEx(myProject);
AsyncResult<EditorWindow> window = mgr.getActiveWindow();
window.doWhenDone((Consumer<EditorWindow>) wnd -> {
if (wnd != null) {
if (wnd.findFileComposite(file) != null) {
mgr.closeFile(file, wnd);
}
}
});
}
use of com.intellij.util.Consumer in project intellij-community by JetBrains.
the class ApplyPatchAction method applyOnly.
@NotNull
public static ApplyPatchStatus applyOnly(@Nullable final Project project, @NotNull final ApplyFilePatchBase patch, @Nullable final ApplyPatchContext context, @NotNull final VirtualFile file, @Nullable final CommitContext commitContext, boolean reverse, @Nullable String leftPanelTitle, @Nullable String rightPanelTitle) {
final ApplyFilePatch.Result result = tryApplyPatch(project, patch, context, file, commitContext);
final ApplyPatchStatus status = result.getStatus();
if (ApplyPatchStatus.ALREADY_APPLIED.equals(status) || ApplyPatchStatus.SUCCESS.equals(status)) {
return status;
}
final ApplyPatchForBaseRevisionTexts mergeData = result.getMergeData();
if (mergeData == null)
return status;
final Document document = FileDocumentManager.getInstance().getDocument(file);
if (document == null)
return ApplyPatchStatus.FAILURE;
String baseContent = toString(mergeData.getBase());
String localContent = toString(mergeData.getLocal());
String patchedContent = mergeData.getPatched();
if (localContent == null)
return ApplyPatchStatus.FAILURE;
final Ref<ApplyPatchStatus> applyPatchStatusReference = new Ref<>();
Consumer<MergeResult> callback = new Consumer<MergeResult>() {
@Override
public void consume(MergeResult result) {
FileDocumentManager.getInstance().saveDocument(document);
applyPatchStatusReference.setIfNull(result != MergeResult.CANCEL ? ApplyPatchStatus.SUCCESS : ApplyPatchStatus.FAILURE);
}
};
try {
MergeRequest request;
if (baseContent != null) {
if (reverse) {
if (leftPanelTitle == null)
leftPanelTitle = VcsBundle.message("patch.apply.conflict.patched.version");
if (rightPanelTitle == null)
rightPanelTitle = VcsBundle.message("patch.apply.conflict.local.version");
List<String> contents = ContainerUtil.list(patchedContent, baseContent, localContent);
List<String> titles = ContainerUtil.list(leftPanelTitle, null, rightPanelTitle);
request = PatchDiffRequestFactory.createMergeRequest(project, document, file, contents, null, titles, callback);
} else {
request = PatchDiffRequestFactory.createMergeRequest(project, document, file, baseContent, localContent, patchedContent, callback);
}
} else {
TextFilePatch textPatch = (TextFilePatch) patch.getPatch();
final GenericPatchApplier applier = new GenericPatchApplier(localContent, textPatch.getHunks());
applier.execute();
final AppliedTextPatch appliedTextPatch = AppliedTextPatch.create(applier.getAppliedInfo());
request = PatchDiffRequestFactory.createBadMergeRequest(project, document, file, localContent, appliedTextPatch, callback);
}
request.putUserData(DiffUserDataKeysEx.MERGE_ACTION_CAPTIONS, new Function<MergeResult, String>() {
@Override
public String fun(MergeResult result) {
return result.equals(MergeResult.CANCEL) ? "Abort..." : null;
}
});
request.putUserData(DiffUserDataKeysEx.MERGE_CANCEL_HANDLER, new Condition<MergeTool.MergeViewer>() {
@Override
public boolean value(MergeTool.MergeViewer viewer) {
int result = Messages.showYesNoCancelDialog(viewer.getComponent().getRootPane(), XmlStringUtil.wrapInHtml("Would you like to <u>A</u>bort&Rollback applying patch action or <u>S</u>kip this file?"), "Close Merge", "_Abort", "_Skip", "Cancel", Messages.getQuestionIcon());
if (result == Messages.YES) {
applyPatchStatusReference.set(ApplyPatchStatus.ABORT);
} else if (result == Messages.NO) {
applyPatchStatusReference.set(ApplyPatchStatus.SKIP);
}
return result != Messages.CANCEL;
}
});
DiffManager.getInstance().showMerge(project, request);
return applyPatchStatusReference.get();
} catch (InvalidDiffRequestException e) {
LOG.warn(e);
return ApplyPatchStatus.FAILURE;
}
}
Aggregations