Search in sources :

Example 16 with Consumer

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;
}
Also used : DataContext(com.intellij.openapi.actionSystem.DataContext) CodeStyleSchemesConfigurable(com.intellij.application.options.CodeStyleSchemesConfigurable) HyperlinkEvent(javax.swing.event.HyperlinkEvent) Consumer(com.intellij.util.Consumer) HyperlinkListener(javax.swing.event.HyperlinkListener) HyperlinkLabel(com.intellij.ui.HyperlinkLabel) Settings(com.intellij.openapi.options.ex.Settings) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with Consumer

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();
    }
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) UiActivityMonitor(com.intellij.ide.UiActivityMonitor) Arrays(java.util.Arrays) StatusBarProgress(com.intellij.openapi.progress.util.StatusBarProgress) VirtualFile(com.intellij.openapi.vfs.VirtualFile) TreeNode(javax.swing.tree.TreeNode) AbstractTreeBuilder(com.intellij.ide.util.treeView.AbstractTreeBuilder) FocusRequestor(com.intellij.openapi.wm.FocusRequestor) ArrayList(java.util.ArrayList) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) Progressive(com.intellij.openapi.progress.Progressive) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) FavoritesTreeNodeDescriptor(com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor) TreePath(javax.swing.tree.TreePath) UiActivity(com.intellij.ide.UiActivity) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) List(java.util.List) IdeFocusManager(com.intellij.openapi.wm.IdeFocusManager) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) AbstractTreeStructure(com.intellij.ide.util.treeView.AbstractTreeStructure) Registry(com.intellij.openapi.util.registry.Registry) PsiDirectory(com.intellij.psi.PsiDirectory) ObjectUtils(com.intellij.util.ObjectUtils) AbstractTreeUpdater(com.intellij.ide.util.treeView.AbstractTreeUpdater) NotNull(org.jetbrains.annotations.NotNull) Comparator(java.util.Comparator) Consumer(com.intellij.util.Consumer) NodeDescriptor(com.intellij.ide.util.treeView.NodeDescriptor) javax.swing(javax.swing) Consumer(com.intellij.util.Consumer) AbstractTreeNode(com.intellij.ide.util.treeView.AbstractTreeNode)

Example 18 with Consumer

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();
}
Also used : com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) GutterMark(com.intellij.codeInsight.daemon.GutterMark) HighlightSeverity(com.intellij.lang.annotation.HighlightSeverity) Document(com.intellij.openapi.editor.Document) THashSet(gnu.trove.THashSet) DocumentEvent(com.intellij.openapi.editor.event.DocumentEvent) MarkupModelEx(com.intellij.openapi.editor.ex.MarkupModelEx) DocumentMarkupModel(com.intellij.openapi.editor.impl.DocumentMarkupModel) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) Project(com.intellij.openapi.project.Project) PsiFile(com.intellij.psi.PsiFile) DocumentEx(com.intellij.openapi.editor.ex.DocumentEx) PsiDocumentManager(com.intellij.psi.PsiDocumentManager) RangeMarker(com.intellij.openapi.editor.RangeMarker) RedBlackTree(com.intellij.openapi.editor.impl.RedBlackTree) com.intellij.openapi.editor.markup(com.intellij.openapi.editor.markup) EditorColorsScheme(com.intellij.openapi.editor.colors.EditorColorsScheme) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) NotNull(org.jetbrains.annotations.NotNull) Consumer(com.intellij.util.Consumer) RangeMarkerTree(com.intellij.openapi.editor.impl.RangeMarkerTree) RangeMarker(com.intellij.openapi.editor.RangeMarker) GutterMark(com.intellij.codeInsight.daemon.GutterMark) RangeHighlighterEx(com.intellij.openapi.editor.ex.RangeHighlighterEx) List(java.util.List)

Example 19 with Consumer

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);
            }
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ShowFilePathAction(com.intellij.ide.actions.ShowFilePathAction) UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) DragSession(com.intellij.ui.docking.DragSession) VirtualFile(com.intellij.openapi.vfs.VirtualFile) UniqueVFilePathBuilder(com.intellij.openapi.fileEditor.UniqueVFilePathBuilder) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) com.intellij.ui.tabs(com.intellij.ui.tabs) InplaceButton(com.intellij.ui.InplaceButton) Border(javax.swing.border.Border) JBUI(com.intellij.util.ui.JBUI) Map(java.util.Map) Disposer(com.intellij.openapi.util.Disposer) MouseAdapter(java.awt.event.MouseAdapter) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) AsyncResult(com.intellij.openapi.util.AsyncResult) Extensions(com.intellij.openapi.extensions.Extensions) ColorUtil(com.intellij.ui.ColorUtil) UISettingsListener(com.intellij.ide.ui.UISettingsListener) ActionCallback(com.intellij.openapi.util.ActionCallback) ToolWindowManagerEx(com.intellij.openapi.wm.ex.ToolWindowManagerEx) ToolWindowManagerAdapter(com.intellij.openapi.wm.ex.ToolWindowManagerAdapter) DockContainer(com.intellij.ui.docking.DockContainer) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) com.intellij.openapi.wm(com.intellij.openapi.wm) GeneralSettings(com.intellij.ide.GeneralSettings) Registry(com.intellij.openapi.util.registry.Registry) NotNull(org.jetbrains.annotations.NotNull) DockableContent(com.intellij.ui.docking.DockableContent) Consumer(com.intellij.util.Consumer) InputEvent(java.awt.event.InputEvent) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx) DataFlavor(java.awt.datatransfer.DataFlavor) Transferable(java.awt.datatransfer.Transferable) NonNls(org.jetbrains.annotations.NonNls) FileDropHandler(com.intellij.openapi.fileEditor.impl.text.FileDropHandler) IdeEventQueue(com.intellij.ide.IdeEventQueue) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) CloseAction(com.intellij.ide.actions.CloseAction) IdeDocumentHistory(com.intellij.openapi.fileEditor.ex.IdeDocumentHistory) UISettings(com.intellij.ide.ui.UISettings) Disposable(com.intellij.openapi.Disposable) SystemInfo(com.intellij.openapi.util.SystemInfo) MouseEvent(java.awt.event.MouseEvent) java.awt(java.awt) com.intellij.openapi.actionSystem(com.intellij.openapi.actionSystem) CommandProcessor(com.intellij.openapi.command.CommandProcessor) ShadowAction(com.intellij.openapi.ui.ShadowAction) DockManager(com.intellij.ui.docking.DockManager) JBTabsImpl(com.intellij.ui.tabs.impl.JBTabsImpl) Queryable(com.intellij.openapi.ui.Queryable) TimedDeadzone(com.intellij.util.ui.TimedDeadzone) FocusEvent(java.awt.event.FocusEvent) CustomActionsSchema(com.intellij.ide.ui.customization.CustomActionsSchema) BitUtil(com.intellij.util.BitUtil) VfsUtil(com.intellij.openapi.vfs.VfsUtil) JBEditorTabs(com.intellij.ui.tabs.impl.JBEditorTabs) javax.swing(javax.swing) FileEditorManagerEx(com.intellij.openapi.fileEditor.ex.FileEditorManagerEx)

Example 20 with Consumer

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;
    }
}
Also used : InvalidDiffRequestException(com.intellij.diff.InvalidDiffRequestException) MergeResult(com.intellij.diff.merge.MergeResult) Document(com.intellij.openapi.editor.Document) ApplyFilePatch(com.intellij.openapi.diff.impl.patch.apply.ApplyFilePatch) Ref(com.intellij.openapi.util.Ref) MergeRequest(com.intellij.diff.merge.MergeRequest) Consumer(com.intellij.util.Consumer) GenericPatchApplier(com.intellij.openapi.diff.impl.patch.apply.GenericPatchApplier) MergeTool(com.intellij.diff.merge.MergeTool) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Consumer (com.intellij.util.Consumer)59 NotNull (org.jetbrains.annotations.NotNull)41 Project (com.intellij.openapi.project.Project)37 Nullable (org.jetbrains.annotations.Nullable)33 VirtualFile (com.intellij.openapi.vfs.VirtualFile)26 List (java.util.List)22 ApplicationManager (com.intellij.openapi.application.ApplicationManager)17 StringUtil (com.intellij.openapi.util.text.StringUtil)17 javax.swing (javax.swing)16 ContainerUtil (com.intellij.util.containers.ContainerUtil)15 Logger (com.intellij.openapi.diagnostic.Logger)14 Module (com.intellij.openapi.module.Module)12 java.awt (java.awt)12 Pair (com.intellij.openapi.util.Pair)11 java.util (java.util)11 File (java.io.File)10 Collection (java.util.Collection)10 PsiElement (com.intellij.psi.PsiElement)9 PsiFile (com.intellij.psi.PsiFile)9 DataContext (com.intellij.openapi.actionSystem.DataContext)8