com.intellij.ui.EditorNotificationPanel Java Examples

The following examples show how to use com.intellij.ui.EditorNotificationPanel. 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: PluginAdvertiserEditorNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (file.getFileType() != PlainTextFileType.INSTANCE && !(file.getFileType() instanceof AbstractFileType)) return null;

  final String extension = file.getExtension();
  if (extension == null) {
    return null;
  }

  if (myEnabledExtensions.contains(extension) || isIgnoredFile(file)) return null;

  UnknownExtension fileFeatureForChecking = new UnknownExtension(FileTypeFactory.FILE_TYPE_FACTORY_EP.getName(), file.getName());

  List<PluginDescriptor> allPlugins = PluginsAdvertiserHolder.getLoadedPluginDescriptors();

  Set<PluginDescriptor> byFeature = PluginsAdvertiser.findByFeature(allPlugins, fileFeatureForChecking);
  if (!byFeature.isEmpty()) {
    return createPanel(file, byFeature);

  }
  return null;
}
 
Example #2
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {

  // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
  if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;

  if (file.getFileType() != DartFileType.INSTANCE) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null || psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
  if (flutterSdk == null) {
    return createNoFlutterSdkPanel(project);
  }
  else if (!flutterSdk.getVersion().isMinRecommendedSupported()) {
    return createOutOfDateFlutterSdkPanel(flutterSdk);
  }

  return null;
}
 
Example #3
Source File: IncompatibleDartPluginNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!FlutterUtils.isFlutteryFile(file)) return null;

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

  if (psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (module == null) return null;

  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final Version minimumVersion = DartPlugin.getInstance().getMinimumVersion();
  final Version dartVersion = DartPlugin.getInstance().getVersion();
  if (dartVersion.minor == 0 && dartVersion.bugfix == 0) {
    return null; // Running from sources.
  }
  return dartVersion.compareTo(minimumVersion) < 0 ? createUpdateDartPanel(myProject, module, dartVersion.toCompactString(),
                                                                           getPrintableRequiredDartVersion()) : null;
}
 
Example #4
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 #5
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 #6
Source File: FileChangedNotificationProvider.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredReadAction
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor) {
  if (!myProject.isDisposed() && !GeneralSettings.getInstance().isSyncOnFrameActivation()) {
    VirtualFileSystem fs = file.getFileSystem();
    if (fs instanceof LocalFileSystem) {
      FileAttributes attributes = ((LocalFileSystem)fs).getAttributes(file);
      if (attributes == null || file.getTimeStamp() != attributes.lastModified || file.getLength() != attributes.length) {
        LogUtil.debug(LOG, "%s: (%s,%s) -> %s", file, file.getTimeStamp(), file.getLength(), attributes);
        return createPanel(file);
      }
    }
  }

  return null;
}
 
Example #7
Source File: SetupUnitySDKProvider.java    From consulo-unity3d with Apache License 2.0 6 votes vote down vote up
@Override
@RequiredReadAction
public EditorNotificationPanel createNotificationPanel(@Nonnull VirtualFile file, @Nonnull FileEditor fileEditor)
{
	final PsiFile psiFile = PsiManager.getInstance(myProject).findFile(file);
	if(psiFile == null)
	{
		return null;
	}

	Unity3dRootModuleExtension rootModuleExtension = Unity3dModuleExtensionUtil.getRootModuleExtension(myProject);
	if(rootModuleExtension == null)
	{
		return null;
	}
	if(rootModuleExtension.getSdk() == null)
	{
		return createPanel(rootModuleExtension.getInheritableSdk().isNull() ? null : rootModuleExtension.getInheritableSdk().getName(), rootModuleExtension.getModule());
	}
	return null;
}
 
Example #8
Source File: SdkConfigurationNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull final VirtualFile file, @NotNull final FileEditor fileEditor) {

  // If this is a Bazel configured Flutter project, exit immediately, neither of the notifications should be shown for this project type.
  if (FlutterModuleUtils.isFlutterBazelProject(project)) return null;

  if (file.getFileType() != DartFileType.INSTANCE) return null;

  final PsiFile psiFile = PsiManager.getInstance(project).findFile(file);
  if (psiFile == null || psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final FlutterSdk flutterSdk = FlutterSdk.getFlutterSdk(project);
  if (flutterSdk == null) {
    return createNoFlutterSdkPanel(project);
  }
  else if (!flutterSdk.getVersion().isMinRecommendedSupported()) {
    return createOutOfDateFlutterSdkPanel(flutterSdk);
  }

  return null;
}
 
Example #9
Source File: IncompatibleDartPluginNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!FlutterUtils.isFlutteryFile(file)) return null;

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

  if (psiFile.getLanguage() != DartLanguage.INSTANCE) return null;

  final Module module = ModuleUtilCore.findModuleForPsiElement(psiFile);
  if (module == null) return null;

  if (!FlutterModuleUtils.isFlutterModule(module)) return null;

  final Version minimumVersion = DartPlugin.getInstance().getMinimumVersion();
  final Version dartVersion = DartPlugin.getInstance().getVersion();
  if (dartVersion.minor == 0 && dartVersion.bugfix == 0) {
    return null; // Running from sources.
  }
  return dartVersion.compareTo(minimumVersion) < 0 ? createUpdateDartPanel(myProject, module, dartVersion.toCompactString(),
                                                                           getPrintableRequiredDartVersion()) : null;
}
 
Example #10
Source File: FlutterSampleNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
  @NotNull VirtualFile file, @NotNull FileEditor fileEditor, @NotNull Project project) {
  if (!(fileEditor instanceof TextEditor)) {
    return null;
  }

  final FlutterSdk sdk = FlutterSdk.getFlutterSdk(project);
  if (sdk == null) {
    return null;
  }

  final String flutterPackagePath = sdk.getHomePath() + "/packages/flutter/lib/src/";
  final String filePath = file.getPath();

  // Only show for files in the flutter sdk.
  if (!filePath.startsWith(flutterPackagePath)) {
    return null;
  }

  final TextEditor textEditor = (TextEditor)fileEditor;
  final Editor editor = textEditor.getEditor();
  final Document document = editor.getDocument();

  final PsiFile psiFile = PsiDocumentManager.getInstance(project).getPsiFile(document);
  if (psiFile == null || !psiFile.isValid()) {
    return null;
  }

  // Run the code to query the document in a read action.
  final List<FlutterSample> samples = ApplicationManager.getApplication().
    runReadAction((Computable<List<FlutterSample>>)() -> {
      //noinspection CodeBlock2Expr
      return getSamplesFromDoc(flutterPackagePath, document, filePath);
    });

  return samples.isEmpty() ? null : new FlutterSampleActionsPanel(samples);
}
 
Example #11
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 #12
Source File: MissingGitignoreNotificationProvider.java    From idea-gitignore with MIT License 5 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 VirtualFile file, @NotNull FileEditor fileEditor,
                                                       @NotNull Project project) {
    // Break if feature is disabled in the Settings
    if (!settings.isMissingGitignore()) {
        return null;
    }
    // Break if user canceled previously this notification
    if (Properties.isIgnoreMissingGitignore(project)) {
        return null;
    }
    // Break if there is no Git directory in the project
    String vcsDirectory = GitLanguage.INSTANCE.getVcsDirectory();
    if (vcsDirectory == null) {
        return null;
    }

    final VirtualFile moduleRoot = Utils.getModuleRootForFile(file, project);
    if (moduleRoot == null) {
        return null;
    }

    final VirtualFile gitDirectory = moduleRoot.findChild(vcsDirectory);
    if (gitDirectory == null || !gitDirectory.isDirectory()) {
        return null;
    }
    // Break if there is Gitignore file already
    final VirtualFile gitignoreFile = moduleRoot.findChild(GitLanguage.INSTANCE.getFilename());
    if (gitignoreFile != null) {
        return null;
    }

    return createPanel(project, moduleRoot);
}
 
Example #13
Source File: SrcFileAnnotator.java    From consulo with Apache License 2.0 5 votes vote down vote up
public void hideCoverageData() {
  if (myEditor == null) return;
  final FileEditorManager fileEditorManager = FileEditorManager.getInstance(myProject);
  final List<RangeHighlighter> highlighters = myEditor.getUserData(COVERAGE_HIGHLIGHTERS);
  if (highlighters != null) {
    for (final RangeHighlighter highlighter : highlighters) {
      ApplicationManager.getApplication().invokeLater(new Runnable() {
        @Override
        public void run() {
          highlighter.dispose();
        }
      });
    }
    myEditor.putUserData(COVERAGE_HIGHLIGHTERS, null);
  }
  
  final Map<FileEditor, EditorNotificationPanel> map = myFile.getCopyableUserData(NOTIFICATION_PANELS);
  if (map != null) {
    final VirtualFile vFile = myFile.getVirtualFile();
    LOG.assertTrue(vFile != null);
    boolean freeAll = !fileEditorManager.isFileOpen(vFile);
    myFile.putCopyableUserData(NOTIFICATION_PANELS, null);
    for (FileEditor fileEditor : map.keySet()) {
      if (!freeAll && !isCurrentEditor(fileEditor)) {
        continue;
      }
      fileEditorManager.removeTopComponent(fileEditor, map.get(fileEditor));
    }
  }

  final DocumentListener documentListener = myEditor.getUserData(COVERAGE_DOCUMENT_LISTENER);
  if (documentListener != null) {
    myDocument.removeDocumentListener(documentListener);
    myEditor.putUserData(COVERAGE_DOCUMENT_LISTENER, null);
  }
}
 
Example #14
Source File: NativeEditorNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private EditorNotificationPanel createPanelForAction(VirtualFile file, VirtualFile root, String actionName) {
  if (actionName == null) {
    return null;
  }
  final NativeEditorActionsPanel panel = new NativeEditorActionsPanel(file, root, actionName);
  return panel.isValidForFile() ? panel : null;
}
 
Example #15
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 #16
Source File: NativeEditorNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!file.isInLocalFileSystem() || !showNotification) {
    return null;
  }
  return createPanelForFile(file, findRootDir(file, myProject.getBaseDir()));
}
 
Example #17
Source File: FlutterPubspecNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file,
                                                       @NotNull FileEditor fileEditor,
                                                       @NotNull Project project) {
  if (!file.isInLocalFileSystem()) {
    return null;
  }

  // If the user has opted out of using pub in a project with both bazel rules and pub rules,
  // then we will default to bazel instead of pub.
  if (WorkspaceCache.getInstance(project).isBazel()) {
    return null;
  }

  // We only show this notification inside pubspec files.
  if (!PubRoot.isPubspec(file)) {
    return null;
  }

  // Check that this pubspec file declares flutter
  if (!FlutterUtils.declaresFlutter(file)) {
    return null;
  }

  if (FlutterSdk.getFlutterSdk(project) == null) {
    return null;
  }

  return new FlutterPubspecActionsPanel(project, file);
}
 
Example #18
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 #19
Source File: NativeEditorNotificationProvider.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor) {
  if (!file.isInLocalFileSystem() || !showNotification) {
    return null;
  }
  return createPanelForFile(file, findRootDir(file, myProject.getBaseDir()));
}
 
Example #20
Source File: MissingGitignoreNotificationProvider.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Creates notification panel.
 *
 * @param project    current project
 * @param moduleRoot module root
 * @return notification panel
 */
private EditorNotificationPanel createPanel(@NotNull final Project project, @NotNull VirtualFile moduleRoot) {
    final EditorNotificationPanel panel = new EditorNotificationPanel();
    final IgnoreFileType fileType = GitFileType.INSTANCE;
    panel.setText(IgnoreBundle.message("daemon.missingGitignore"));
    panel.createActionLabel(IgnoreBundle.message("daemon.missingGitignore.create"), () -> {
        PsiDirectory directory = PsiManager.getInstance(project).findDirectory(moduleRoot);
        if (directory != null) {
            try {
                PsiFile file = new CreateFileCommandAction(project, directory, fileType).execute();
                FileEditorManager.getInstance(project).openFile(file.getVirtualFile(), true);
                new GeneratorDialog(project, file).show();
            } catch (Throwable throwable) {
                throwable.printStackTrace();
            }
        }
    });
    panel.createActionLabel(IgnoreBundle.message("daemon.cancel"), () -> {
        Properties.setIgnoreMissingGitignore(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 #21
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 #22
Source File: MergePanel2.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void tryInitView() {
  if (!hasAllEditors()) return;
  if (myMergeList != null) return;
  myMergeList = MergeList.create(myData);
  myMergeList.addListener(myDividersRepainter);
  myStatusUpdater = StatusUpdater.install(myMergeList, myPanel);
  Editor left = getEditor(0);
  Editor base = getEditor(1);
  Editor right = getEditor(2);

  setupHighlighterSettings(left, base, right);

  myMergeList.setMarkups(left, base, right);
  EditingSides[] sides = {getFirstEditingSide(), getSecondEditingSide()};
  EditingSides[] sidesWithApplied = {getFirstEditingSide(true), getSecondEditingSide(true)};
  myScrollSupport.install(sides);
  for (int i = 0; i < myDividers.length; i++) {
    myDividers[i].listenEditors(sidesWithApplied[i]);
  }
  if (myScrollToFirstDiff) {
    myPanel.requestScrollEditors();
  }
  if (myMergeList.getErrorMessage() != null) {
    myPanel.insertTopComponent(new EditorNotificationPanel() {
      {
        myLabel.setText(myMergeList.getErrorMessage());
      }
    });
  }
}
 
Example #23
Source File: AddTsConfigNotificationProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(
    VirtualFile file, FileEditor fileEditor, Project project) {
  if (!addTsConfigNotification.getValue()) {
    return null;
  }
  if (suppressedFiles.contains(VfsUtil.virtualToIoFile(file))) {
    return null;
  }
  if (!TypeScriptPrefetchFileSource.getTypeScriptExtensions().contains(file.getExtension())) {
    return null;
  }
  BlazeProjectData projectData =
      BlazeProjectDataManager.getInstance(project).getBlazeProjectData();
  if (projectData == null
      || !projectData.getWorkspaceLanguageSettings().isLanguageActive(LanguageClass.TYPESCRIPT)) {
    return null;
  }
  Label tsConfig = getTsConfigLabelForFile(project, file);
  if (tsConfig == null) {
    return null;
  }
  ProjectViewSet projectView = ProjectViewManager.getInstance(project).getProjectViewSet();
  if (projectView == null) {
    return null;
  }
  Set<Label> declaredTsConfigs =
      projectView.getSections(TsConfigRulesSection.KEY).stream()
          .map(ListSection::items)
          .flatMap(Collection::stream)
          .collect(toSet());
  projectView.getScalarValue(TsConfigRuleSection.KEY).ifPresent(declaredTsConfigs::add);
  if (declaredTsConfigs.contains(tsConfig)) {
    return null;
  }
  return createNotificationPanel(project, file, tsConfig);
}
 
Example #24
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 #25
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 #26
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 #27
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 #28
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 #29
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 #30
Source File: AddUnversionedFilesNotificationProvider.java    From idea-gitignore with MIT License 5 votes vote down vote up
/**
 * Creates notification panel for given file and checks if is allowed to show the notification.
 * Only {@link GitLanguage} is currently supported.
 *
 * @param file       current file
 * @param fileEditor current file editor
 * @return created notification panel
 */
@Nullable
@Override
public EditorNotificationPanel createNotificationPanel(@NotNull VirtualFile file, @NotNull FileEditor fileEditor,
                                                       @NotNull Project project) {
    // Break if feature is disabled in the Settings
    if (!settings.isAddUnversionedFiles()) {
        return null;
    }
    // Break if user canceled previously this notification
    if (Properties.isAddUnversionedFiles(project)) {
        return null;
    }

    if (handledMap.get(file) != null) {
        return null;
    }

    final IgnoreLanguage language = IgnoreBundle.obtainLanguage(file);
    if (language == null || !language.isVCS() || !(language instanceof GitLanguage)) {
        return null;
    }

    unignoredFiles.clear();
    unignoredFiles.addAll(ExternalExec.getUnignoredFiles(GitLanguage.INSTANCE, project, file));
    if (unignoredFiles.isEmpty()) {
        return null;
    }

    return createPanel(project);
}