Search in sources :

Example 46 with EditorNotificationPanel

use of com.intellij.ui.EditorNotificationPanel in project intellij-community by JetBrains.

the class SrcFileAnnotator method hideCoverageData.

public void hideCoverageData() {
    Editor editor = myEditor;
    PsiFile file = myFile;
    Document document = myDocument;
    if (editor == null || editor.isDisposed() || file == null || document == null)
        return;
    final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
    final List<RangeHighlighter> highlighters = editor.getUserData(COVERAGE_HIGHLIGHTERS);
    if (highlighters != null) {
        for (final RangeHighlighter highlighter : highlighters) {
            ApplicationManager.getApplication().invokeLater(() -> highlighter.dispose());
        }
        editor.putUserData(COVERAGE_HIGHLIGHTERS, null);
    }
    final Map<FileEditor, EditorNotificationPanel> map = file.getCopyableUserData(NOTIFICATION_PANELS);
    if (map != null) {
        final VirtualFile vFile = getVirtualFile(file);
        boolean freeAll = !fileEditorManager.isFileOpen(vFile);
        file.putCopyableUserData(NOTIFICATION_PANELS, null);
        for (FileEditor fileEditor : map.keySet()) {
            if (!freeAll && !isCurrentEditor(fileEditor)) {
                continue;
            }
            fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor));
        }
    }
    final DocumentListener documentListener = editor.getUserData(COVERAGE_DOCUMENT_LISTENER);
    if (documentListener != null) {
        document.removeDocumentListener(documentListener);
        editor.putUserData(COVERAGE_DOCUMENT_LISTENER, null);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) DocumentListener(com.intellij.openapi.editor.event.DocumentListener) FileEditor(com.intellij.openapi.fileEditor.FileEditor) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiFile(com.intellij.psi.PsiFile) TextEditor(com.intellij.openapi.fileEditor.TextEditor) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Editor(com.intellij.openapi.editor.Editor) Document(com.intellij.openapi.editor.Document)

Example 47 with EditorNotificationPanel

use of com.intellij.ui.EditorNotificationPanel in project intellij-community by JetBrains.

the class SdkSetupNotificationProvider method createPanel.

@NotNull
private static EditorNotificationPanel createPanel(@NotNull String message, @NotNull Runnable fix) {
    EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.setText(message);
    panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), fix);
    return panel;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) NotNull(org.jetbrains.annotations.NotNull)

Example 48 with EditorNotificationPanel

use of com.intellij.ui.EditorNotificationPanel in project intellij-community by JetBrains.

the class AttachSourcesNotificationProvider method createNotificationPanel.

@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull FileEditor fileEditor) {
    if (file.getFileType() != JavaClassFileType.INSTANCE)
        return null;
    final EditorNotificationPanel panel = new EditorNotificationPanel();
    String text = ProjectBundle.message("class.file.decompiled.text");
    String classInfo = getClassFileInfo(file);
    if (classInfo != null)
        text += ", " + classInfo;
    panel.setText(text);
    final VirtualFile sourceFile = JavaEditorFileSwapper.findSourceFile(myProject, file);
    if (sourceFile == null) {
        final List<LibraryOrderEntry> libraries = findLibraryEntriesForFile(file);
        if (libraries != null) {
            List<AttachSourcesProvider.AttachSourcesAction> actions = new ArrayList<>();
            PsiFile clsFile = PsiManager.getInstance(myProject).findFile(file);
            boolean hasNonLightAction = false;
            for (AttachSourcesProvider each : Extensions.getExtensions(EXTENSION_POINT_NAME)) {
                for (AttachSourcesProvider.AttachSourcesAction action : each.getActions(libraries, clsFile)) {
                    if (hasNonLightAction) {
                        if (action instanceof AttachSourcesProvider.LightAttachSourcesAction) {
                            // Don't add LightAttachSourcesAction if non light action exists.
                            continue;
                        }
                    } else {
                        if (!(action instanceof AttachSourcesProvider.LightAttachSourcesAction)) {
                            // All previous actions is LightAttachSourcesAction and should be removed.
                            actions.clear();
                            hasNonLightAction = true;
                        }
                    }
                    actions.add(action);
                }
            }
            Collections.sort(actions, (o1, o2) -> o1.getName().compareToIgnoreCase(o2.getName()));
            AttachSourcesProvider.AttachSourcesAction defaultAction;
            if (findSourceFileInSameJar(file) != null) {
                defaultAction = new AttachJarAsSourcesAction(file);
            } else {
                defaultAction = new ChooseAndAttachSourcesAction(myProject, panel);
            }
            actions.add(defaultAction);
            for (final AttachSourcesProvider.AttachSourcesAction action : actions) {
                panel.createActionLabel(GuiUtils.getTextWithoutMnemonicEscaping(action.getName()), () -> {
                    List<LibraryOrderEntry> entries = findLibraryEntriesForFile(file);
                    if (!Comparing.equal(libraries, entries)) {
                        Messages.showErrorDialog(myProject, "Can't find library for " + file.getName(), "Error");
                        return;
                    }
                    panel.setText(action.getBusyText());
                    action.perform(entries);
                });
            }
        }
    } else {
        panel.createActionLabel(ProjectBundle.message("class.file.open.source.action"), () -> {
            OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, sourceFile);
            FileEditorManager.getInstance(myProject).openTextEditor(descriptor, true);
        });
    }
    return panel;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ArrayList(java.util.ArrayList) AttachSourcesProvider(com.intellij.codeInsight.AttachSourcesProvider) EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) PsiFile(com.intellij.psi.PsiFile) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor)

Example 49 with EditorNotificationPanel

use of com.intellij.ui.EditorNotificationPanel in project intellij-elixir by KronicDeth.

the class SetupSDKNotificationProvider method createPanel.

@NotNull
private static EditorNotificationPanel createPanel(@NotNull final Project project, @NotNull final PsiFile file) {
    EditorNotificationPanel panel = new EditorNotificationPanel();
    // project.sdk.not.defined -> "Project SDK is not defined"
    // project.sdk.setup -> "Setup SDK"
    panel.setText(ProjectBundle.message("project.sdk.not.defined"));
    panel.createActionLabel(ProjectBundle.message("project.sdk.setup"), new Runnable() {

        @Override
        public void run() {
            if (ElixirSystemUtil.isSmallIde()) {
                ShowSettingsUtil.getInstance().showSettingsDialog(project, ElixirExternalToolsConfigurable.ELIXIR_RELATED_TOOLS);
                return;
            }
            Sdk projectSdk = ProjectSettingsService.getInstance(project).chooseAndSetSdk();
            if (projectSdk == null)
                return;
            ApplicationManager.getApplication().runWriteAction(new Runnable() {

                @Override
                public void run() {
                    Module module = ModuleUtilCore.findModuleForPsiElement(file);
                    if (module != null) {
                        ModuleRootModificationUtil.setSdkInherited(module);
                    }
                }
            });
        }
    });
    return panel;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 50 with EditorNotificationPanel

use of com.intellij.ui.EditorNotificationPanel in project flutter-intellij by flutter.

the class SdkConfigurationNotificationProvider method createNoFlutterSdkPanel.

@SuppressWarnings("SameReturnValue")
private static EditorNotificationPanel createNoFlutterSdkPanel(Project project) {
    final EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.icon(FlutterIcons.Flutter);
    panel.setText(FlutterBundle.message("flutter.no.sdk.warning"));
    panel.createActionLabel("Dismiss", () -> panel.setVisible(false));
    panel.createActionLabel("Open Flutter settings", () -> FlutterUtils.openFlutterSettings(project));
    return panel;
}
Also used : EditorNotificationPanel(com.intellij.ui.EditorNotificationPanel)

Aggregations

EditorNotificationPanel (com.intellij.ui.EditorNotificationPanel)56 Nullable (org.jetbrains.annotations.Nullable)20 NotNull (org.jetbrains.annotations.NotNull)13 FileEditor (com.intellij.openapi.fileEditor.FileEditor)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)7 PsiFile (com.intellij.psi.PsiFile)7 Editor (com.intellij.openapi.editor.Editor)6 TextEditor (com.intellij.openapi.fileEditor.TextEditor)5 Project (com.intellij.openapi.project.Project)4 Module (com.intellij.openapi.module.Module)3 PluginManagerConfigurable (com.intellij.ide.plugins.PluginManagerConfigurable)2 Document (com.intellij.openapi.editor.Document)2 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 Ref (com.intellij.openapi.util.Ref)2 PerlLocalSettings (com.perl5.lang.perl.idea.configuration.settings.PerlLocalSettings)2 File (java.io.File)2 List (java.util.List)2 AndroidModuleModel (com.android.tools.idea.gradle.project.model.AndroidModuleModel)1 ModelWizardDialog (com.android.tools.idea.wizard.model.ModelWizardDialog)1