Java Code Examples for com.intellij.ui.EditorNotificationPanel#createActionLabel()

The following examples show how to use com.intellij.ui.EditorNotificationPanel#createActionLabel() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ForcedSoftWrapsNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull final VirtualFile file, @Nonnull final FileEditor fileEditor) {
  if (!(fileEditor instanceof TextEditor)) return null;
  final Editor editor = ((TextEditor)fileEditor).getEditor();
  if (!Boolean.TRUE.equals(editor.getUserData(DesktopEditorImpl.FORCED_SOFT_WRAPS)) ||
      !Boolean.TRUE.equals(editor.getUserData(DesktopEditorImpl.SOFT_WRAPS_EXIST)) ||
      PropertiesComponent.getInstance().isTrueValue(DISABLED_NOTIFICATION_KEY)) {
    return null;
  }

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(EditorBundle.message("forced.soft.wrap.message"));
  panel.createActionLabel(EditorBundle.message("forced.soft.wrap.hide.message"), () -> {
    editor.putUserData(DesktopEditorImpl.FORCED_SOFT_WRAPS, null);
    EditorNotifications.getInstance(myProject).updateNotifications(file);
  });
  panel.createActionLabel(EditorBundle.message("forced.soft.wrap.dont.show.again.message"), () -> {
    PropertiesComponent.getInstance().setValue(DISABLED_NOTIFICATION_KEY, "true");
    EditorNotifications.getInstance(myProject).updateAllNotifications();
  });
  return panel;
}
 
Example 2
Source File: IgnoredEditingNotificationProvider.java    From idea-gitignore with MIT License 6 votes vote down vote up
/**
 * Creates notification panel for given file and checks if is allowed to show the notification.
 *
 * @param file       current file
 * @param fileEditor current file editor
 * @return created notification panel
 */
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file,
                                                       @NotNull FileEditor fileEditor, @NotNull Project project) {
    if (!settings.isNotifyIgnoredEditing() || Properties.isDismissedIgnoredEditingNotification(project, file)
            || !changeListManager.isIgnoredFile(file) && !manager.isFileIgnored(file)) {
        return null;
    }

    final EditorNotificationPanel panel = new EditorNotificationPanel();

    panel.setText(IgnoreBundle.message("daemon.ignoredEditing"));
    panel.createActionLabel(IgnoreBundle.message("daemon.ok"), () -> {
        Properties.setDismissedIgnoredEditingNotification(project, file);
        notifications.updateAllNotifications();
    });

    try { // ignore if older SDK does not support panel icon
        panel.icon(Icons.IGNORE);
    } catch (NoSuchMethodError ignored) {
    }

    return panel;
}
 
Example 3
Source File: Unity3dAssetEditorNotificationProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor)
{
	if(file.getFileType() != Unity3dYMLAssetFileType.INSTANCE || !ArrayUtil.contains(file.getExtension(), Unity3dAssetFileTypeDetector.ourAssetExtensions))
	{
		return null;
	}
	final String uuid = Unity3dAssetUtil.getGUID(myProject, file);
	if(uuid == null)
	{
		return null;
	}
	MultiMap<VirtualFile, Unity3dYMLAsset> map = Unity3dYMLAsset.findAssetAsAttach(myProject, file);
	if(map.isEmpty())
	{
		return null;
	}

	PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
	if(psiFile == null)
	{
		return null;
	}

	final EditorNotificationPanel panel = new EditorNotificationPanel();
	panel.text("Used asset...");
	panel.createActionLabel("Find usages...", () -> FindManager.getInstance(myProject).findUsages(psiFile));
	return panel;
}
 
Example 4
Source File: FileChangedNotificationProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
private EditorNotificationPanel createPanel(@Nonnull final VirtualFile file) {
  EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(IdeBundle.message("file.changed.externally.message"));
  panel.createActionLabel(IdeBundle.message("file.changed.externally.reload"), () -> {
    if (!myProject.isDisposed()) {
      file.refresh(false, false);
      EditorNotifications.getInstance(myProject).updateNotifications(file);
    }
  });
  return panel;
}
 
Example 5
Source File: BackgroundTaskEditorNotificationProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull final VirtualFile file, @Nonnull FileEditor fileEditor) {
  List<BackgroundTaskByVfsChangeProvider> providers = BackgroundTaskByVfsChangeProviders.getProviders(myProject, file);
  if (providers.isEmpty()) {
    return null;
  }

  EditorNotificationPanel panel = new EditorNotificationPanel(Gray._220);

  List<BackgroundTaskByVfsChangeTask> tasks = BackgroundTaskByVfsChangeManager.getInstance(myProject).findTasks(file);
  if (!tasks.isEmpty()) {
    panel.text("Task(s): " + StringUtil.join(tasks, it -> it.getName() + (!it.isEnabled() ? " (disabled)" : ""), ", "));

    panel.createActionLabel("Force Run", () -> {
      BackgroundTaskByVfsChangeManager.getInstance(myProject).runTasks(file);
    });
  }
  else {
    panel.text("Background task(s) on file change is available");
  }

  panel.createActionLabel("Manage", () -> {
    BackgroundTaskByVfsChangeManager.getInstance(myProject).openManageDialog(file);
  });
  return panel;
}
 
Example 6
Source File: DiffNotifications.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static JPanel createNotification(@Nonnull String text, @Nullable final Color background, boolean showHideAction) {
  final EditorNotificationPanel panel = new EditorNotificationPanel(background);
  panel.text(text);
  if (showHideAction) {
    HyperlinkLabel link = panel.createActionLabel("Hide", () -> panel.setVisible(false));
    link.setToolTipText("Hide this notification");
  }
  return panel;
}
 
Example 7
Source File: PluginAdvertiserEditorNotificationProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
private EditorNotificationPanel createPanel(VirtualFile virtualFile, Set<PluginDescriptor> plugins) {
  String extension = virtualFile.getExtension();

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(IdeBundle.message("plugin.advestiser.notification.text", plugins.size()));
  final PluginDescriptor disabledPlugin = getDisabledPlugin(plugins.stream().map(x -> x.getPluginId().getIdString()).collect(Collectors.toSet()));
  if (disabledPlugin != null) {
    panel.createActionLabel("Enable " + disabledPlugin.getName() + " plugin", () -> {
      myEnabledExtensions.add(extension);
      consulo.container.plugin.PluginManager.enablePlugin(disabledPlugin.getPluginId().getIdString());
      myNotifications.updateAllNotifications();
      PluginManagerMain.notifyPluginsWereUpdated("Plugin was successfully enabled", null);
    });
  }
  else {
    panel.createActionLabel(IdeBundle.message("plugin.advestiser.notification.install.link", plugins.size()), () -> {
      final PluginsAdvertiserDialog advertiserDialog = new PluginsAdvertiserDialog(null, new ArrayList<>(plugins));
      advertiserDialog.show();
      if (advertiserDialog.isUserInstalledPlugins()) {
        myEnabledExtensions.add(extension);
        myNotifications.updateAllNotifications();
      }
    });
  }

  panel.createActionLabel("Ignore by file name", () -> {
    myUnknownFeaturesCollector.ignoreFeature(new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP, virtualFile.getName()));
    myNotifications.updateAllNotifications();
  });

  panel.createActionLabel("Ignore by extension", () -> {
    myUnknownFeaturesCollector.ignoreFeature(new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP, "*." + virtualFile.getExtension()));
    myNotifications.updateAllNotifications();
  });

  return panel;
}
 
Example 8
Source File: AddUnversionedFilesNotificationProvider.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Creates notification panel.
 *
 * @param project current project
 * @return notification panel
 */
private EditorNotificationPanel createPanel(@NotNull final Project project) {
    final EditorNotificationPanel panel = new EditorNotificationPanel();
    final IgnoreFileType fileType = GitFileType.INSTANCE;
    panel.setText(IgnoreBundle.message("daemon.addUnversionedFiles"));
    panel.createActionLabel(IgnoreBundle.message("daemon.addUnversionedFiles.create"), () -> {
        final VirtualFile projectDir = Utils.guessProjectDir(project);
        if (projectDir == null) {
            return;
        }
        final VirtualFile virtualFile = projectDir.findChild(GitLanguage.INSTANCE.getFilename());
        final PsiFile file = virtualFile != null ? PsiManager.getInstance(project).findFile(virtualFile) : null;
        if (file != null) {
            final String content = StringUtil.join(unignoredFiles, Constants.NEWLINE);

            try {
                new AppendFileCommandAction(project, file, content, true, false)
                        .execute();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
            handledMap.put(virtualFile, true);
            notifications.updateAllNotifications();
        }
    });
    panel.createActionLabel(IgnoreBundle.message("daemon.cancel"), () -> {
        Properties.setAddUnversionedFiles(project);
        notifications.updateAllNotifications();
    });

    try { // ignore if older SDK does not support panel icon
        Icon icon = fileType.getIcon();
        if (icon != null) {
            panel.icon(icon);
        }
    } catch (NoSuchMethodError ignored) {
    }

    return panel;
}
 
Example 9
Source File: FileIsNotAttachedProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile virtualFile, @Nonnull FileEditor fileEditor)
{
	if(virtualFile.getFileType() != CSharpFileType.INSTANCE)
	{
		return null;
	}

	Unity3dRootModuleExtension rootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(myProject);
	if(rootModuleExtension == null)
	{
		return null;
	}

	if(ProjectFileIndex.getInstance(myProject).isInLibraryClasses(virtualFile) || virtualFile instanceof MsilFileRepresentationVirtualFile)
	{
		return null;
	}

	Module module = ModuleUtilCore.findModuleForFile(virtualFile, myProject);

	if(module == null || module.equals(rootModuleExtension.getModule()))
	{
		EditorNotificationPanel panel = new EditorNotificationPanel();
		panel.text("File is not attached to project. Some features are unavailable (code analysis, debugging, etc)");
		panel.createActionLabel("Re-import Unity Project", () ->
		{
			Unity3dProjectImportUtil.syncProjectStep1(myProject, rootModuleExtension.getSdk(), null, true);
		});
		return panel;
	}
	return null;
}
 
Example 10
Source File: SetupUnitySDKProvider.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
@Nonnull
private static EditorNotificationPanel createPanel(@Nullable String name, @Nonnull final Module rootModule)
{
	EditorNotificationPanel panel = new EditorNotificationPanel();
	if(StringUtil.isEmpty(name))
	{
		panel.setText(Unity3dBundle.message("unity.sdk.is.not.defiled"));
	}
	else
	{
		panel.setText(Unity3dBundle.message("unity.0.sdk.is.not.defined", name));
	}
	panel.createActionLabel("Open Settings", () -> ProjectSettingsService.getInstance(rootModule.getProject()).openModuleSettings(rootModule));
	return panel;
}
 
Example 11
Source File: IncompatibleDartPluginNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static EditorNotificationPanel createUpdateDartPanel(@NotNull Project project,
                                                             @Nullable Module module,
                                                             @NotNull String currentVersion,
                                                             @NotNull String minimumVersion) {
  if (module == null) return null;

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(FlutterBundle.message("flutter.incompatible.dart.plugin.warning", minimumVersion, currentVersion));
  panel.createActionLabel(FlutterBundle.message("dart.plugin.update.action.label"),
                          () -> ShowSettingsUtil.getInstance().showSettingsDialog(project, PluginManagerConfigurable.class));

  return panel;
}
 
Example 12
Source File: ConvertToSourceDependencyEditorNotificationsProvider.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
  @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project
) {
  if(!BspUtil.isBspProject(project)){
    return null;
  }
  JarMappings mappings = JarMappings.getInstance(project);
  Optional<PantsTargetAddress> targetName =
    JarMappings.getParentJar(file)
      .flatMap(mappings::findTargetForJar)
      .flatMap(PantsTargetAddress::tryParse);
  if (targetName.isPresent()) {
    EditorNotificationPanel panel = new EditorNotificationPanel();
    panel.createActionLabel(PantsBundle.message("pants.bsp.editor.convert.button"), () -> {
      try {
        OpenBspAmendWindowAction.bspAmendWithDialog(project, Collections.singleton(targetName.get().toAddressString()));
      } catch (Throwable e) {
        logger.error(e);
      }
    });
    return panel.text(PantsBundle.message(
      "pants.bsp.file.editor.amend.notification.title",
      targetName.get().toAddressString()
    ));
  }
  else {
    return null;
  }
}
 
Example 13
Source File: AddTsConfigNotificationProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
private EditorNotificationPanel createNotificationPanel(
    Project project, VirtualFile file, Label tsConfig) {
  EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText("Do you want to add the tsconfig.json for this file to the project view?");
  panel.createActionLabel(
      "Add tsconfig.json to project view",
      () -> {
        ProjectViewEdit edit =
            ProjectViewEdit.editLocalProjectView(
                project,
                builder -> {
                  ListSection<Label> rules = builder.getLast(TsConfigRulesSection.KEY);
                  builder.replace(
                      rules, ListSection.update(TsConfigRulesSection.KEY, rules).add(tsConfig));
                  return true;
                });
        if (edit != null) {
          edit.apply();
        }
        EditorNotifications.getInstance(project).updateNotifications(file);
      });
  panel.createActionLabel(
      "Hide notification",
      () -> {
        // suppressed for this file until the editor is restarted
        suppressedFiles.add(VfsUtil.virtualToIoFile(file));
        EditorNotifications.getInstance(project).updateNotifications(file);
      });
  return panel;
}
 
Example 14
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private EditorNotificationPanel createOutOfDateFlutterSdkPanel(@NotNull FlutterSdk sdk) {
  final FlutterUIConfig settings = FlutterUIConfig.getInstance();
  if (settings.shouldIgnoreOutOfDateFlutterSdks()) return null;

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.icon(FlutterIcons.Flutter);
  panel.setText(FlutterBundle.message("flutter.old.sdk.warning"));
  panel.createActionLabel("Dismiss", () -> {
    settings.setIgnoreOutOfDateFlutterSdks();
    panel.setVisible(false);
  });

  return panel;
}
 
Example 15
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 16
Source File: IncompatibleDartPluginNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
private static EditorNotificationPanel createUpdateDartPanel(@NotNull Project project,
                                                             @Nullable Module module,
                                                             @NotNull String currentVersion,
                                                             @NotNull String minimumVersion) {
  if (module == null) return null;

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(FlutterBundle.message("flutter.incompatible.dart.plugin.warning", minimumVersion, currentVersion));
  panel.createActionLabel(FlutterBundle.message("dart.plugin.update.action.label"),
                          () -> ShowSettingsUtil.getInstance().showSettingsDialog(project, PluginManagerConfigurable.class));

  return panel;
}
 
Example 17
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private EditorNotificationPanel createOutOfDateFlutterSdkPanel(@NotNull FlutterSdk sdk) {
  final FlutterUIConfig settings = FlutterUIConfig.getInstance();
  if (settings.shouldIgnoreOutOfDateFlutterSdks()) return null;

  final EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.icon(FlutterIcons.Flutter);
  panel.setText(FlutterBundle.message("flutter.old.sdk.warning"));
  panel.createActionLabel("Dismiss", () -> {
    settings.setIgnoreOutOfDateFlutterSdks();
    panel.setVisible(false);
  });

  return panel;
}
 
Example 18
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@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;
}
 
Example 19
Source File: ExternalFileProjectManagementHelper.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(VirtualFile vf, FileEditor fileEditor) {
  if (!enabled.getValue()) {
    return null;
  }
  if (!BlazeUserSettings.getInstance().getShowAddFileToProjectNotification()
      || suppressedFiles.contains(new File(vf.getPath()))) {
    return null;
  }
  File file = new File(vf.getPath());
  if (!supportedFileType(file)) {
    return null;
  }
  LocationContext context = AddSourceToProjectHelper.getContext(project, vf);
  if (context == null) {
    return null;
  }
  boolean inProjectDirectories = AddSourceToProjectHelper.sourceInProjectDirectories(context);
  boolean alreadyBuilt = AddSourceToProjectHelper.sourceCoveredByProjectViewTargets(context);
  if (alreadyBuilt && inProjectDirectories) {
    return null;
  }

  boolean addTargets = !alreadyBuilt && !AddSourceToProjectHelper.autoDeriveTargets(project);
  ListenableFuture<List<TargetInfo>> targetsFuture =
      addTargets
          ? AddSourceToProjectHelper.getTargetsBuildingSource(context)
          : Futures.immediateFuture(ImmutableList.of());
  if (targetsFuture == null) {
    return null;
  }

  EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setVisible(false); // starts off not visible until we get the query results
  panel.setText("Do you want to add this file to your project sources?");
  panel.createActionLabel(
      "Add file to project",
      () -> {
        AddSourceToProjectHelper.addSourceToProject(
            project, context.workspacePath, inProjectDirectories, targetsFuture);
        EditorNotifications.getInstance(project).updateNotifications(vf);
      });
  panel.createActionLabel(
      "Hide notification",
      () -> {
        // suppressed for this file until the editor is restarted
        suppressedFiles.add(file);
        EditorNotifications.getInstance(project).updateNotifications(vf);
      });
  panel.createActionLabel(
      "Don't show again",
      () -> {
        // disables the notification permanently, and focuses the relevant setting, so users know
        // how to turn it back on
        BlazeUserSettings.getInstance().setShowAddFileToProjectNotification(false);
        ShowSettingsUtilImpl.showSettingsDialog(
            project,
            BlazeUserSettingsCompositeConfigurable.ID,
            BlazeUserSettingsConfigurable.SHOW_ADD_FILE_TO_PROJECT.label());
      });

  targetsFuture.addListener(
      () -> {
        try {
          List<TargetInfo> targets = targetsFuture.get();
          if (!targets.isEmpty() || !inProjectDirectories) {
            panel.setVisible(true);
          }
        } catch (InterruptedException | ExecutionException e) {
          // ignore
        }
      },
      MoreExecutors.directExecutor());

  return panel;
}
 
Example 20
Source File: AdditionalLanguagesHelper.java    From intellij with Apache License 2.0 4 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(VirtualFile file, FileEditor fileEditor) {
  String ext = file.getExtension();
  if (ext == null) {
    return null;
  }
  LanguageClass language = LanguageClass.fromExtension(ext);
  if (language == null || notifiedLanguages.contains(language)) {
    return null;
  }
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null) {
    return null;
  }
  WorkspaceLanguageSettings settings = projectData.getWorkspaceLanguageSettings();
  if (settings.isLanguageActive(language)) {
    return null;
  }
  if (!LanguageSupport.supportedLanguagesForWorkspaceType(settings.getWorkspaceType())
      .contains(language)) {
    return null;
  }

  String langName = language.getName();
  String message =
      String.format(
          "Do you want to enable %s plugin %s support?",
          Blaze.buildSystemName(project), langName);

  EditorNotificationPanel panel = new EditorNotificationPanel();
  panel.setText(message);
  panel.createActionLabel(
      String.format("Enable %s support", langName),
      () -> {
        enableLanguageSupport(project, ImmutableList.of(language));
        suppressNotifications(language);
      });
  panel.createActionLabel("Don't show again", () -> suppressNotifications(language));
  return panel;
}