public static boolean showFacetSettingsDialog(
     @NotNull final Facet facet, @Nullable final String tabNameToSelect) {
   final Project project = facet.getModule().getProject();
   final ProjectStructureConfigurable config = ProjectStructureConfigurable.getInstance(project);
   return ShowSettingsUtil.getInstance()
       .editConfigurable(
           project,
           config,
           new Runnable() {
             @Override
             public void run() {
               final ModuleStructureConfigurable modulesConfig = config.getModulesConfig();
               config
                   .select(facet, true)
                   .doWhenDone(
                       new Runnable() {
                         @Override
                         public void run() {
                           if (tabNameToSelect != null) {
                             FacetEditorImpl facetEditor =
                                 modulesConfig.getFacetConfigurator().getOrCreateEditor(facet);
                             facetEditor.setSelectedTabName(tabNameToSelect);
                           }
                         }
                       });
             }
           });
 }
 @Override
 public void actionPerformed(AnActionEvent e) {
   TaskRepositoriesConfigurable configurable = new TaskRepositoriesConfigurable(getProject(e));
   if (ShowSettingsUtil.getInstance().editConfigurable(getProject(e), configurable)) {
     serversChanged();
   }
 }
 public void actionPerformed(AnActionEvent e) {
   boolean applied =
       ShowSettingsUtil.getInstance()
           .editConfigurable(DependenciesPanel.this, new DependencyConfigurable(myProject));
   if (applied) {
     rebuild();
   }
 }
示例#4
0
  private void openConfigurationDialog() {
    final CompilerConfigurationImpl configuration =
        (CompilerConfigurationImpl) CompilerConfiguration.getInstance(myProject);
    final Collection<BackendCompiler> compilers = configuration.getRegisteredJavaCompilers();
    final BackendCompiler defaultCompiler = configuration.getDefaultCompiler();
    final JavaCompilersTab compilersTab =
        new JavaCompilersTab(myProject, compilers, defaultCompiler);

    ShowSettingsUtil.getInstance().editConfigurable(myProject, compilersTab);
  }
 public static boolean showArtifactSettings(
     @NotNull Project project, @Nullable final Artifact artifact) {
   final ProjectStructureConfigurable configurable =
       ProjectStructureConfigurable.getInstance(project);
   return ShowSettingsUtil.getInstance()
       .editConfigurable(
           project,
           configurable,
           new Runnable() {
             @Override
             public void run() {
               configurable.select(artifact, true);
             }
           });
 }
  public static void editAssociations(Project project, final PsiFile file) {
    final FileAssociationsConfigurable instance = new FileAssociationsConfigurable(project);

    ShowSettingsUtil.getInstance()
        .editConfigurable(
            project,
            instance,
            new Runnable() {
              public void run() {
                final AssociationsEditor editor = instance.getEditor();
                if (file != null) {
                  editor.select(file);
                }
              }
            });
  }
 public static boolean showDialog(
     Project project,
     @Nullable final String moduleToSelect,
     @Nullable final String editorNameToSelect) {
   final ProjectStructureConfigurable config = ProjectStructureConfigurable.getInstance(project);
   return ShowSettingsUtil.getInstance()
       .editConfigurable(
           project,
           config,
           new Runnable() {
             @Override
             public void run() {
               config.select(moduleToSelect, editorNameToSelect, true);
             }
           });
 }
 private void editColorsAndFonts() {
   final String toConfigure = getSelectedType().getSeverity(null).myName;
   doOKAction();
   myOptionsList.clearSelection();
   final DataContext dataContext = DataManager.getInstance().getDataContext(myPanel);
   final OptionsEditor optionsEditor = OptionsEditor.KEY.getData(dataContext);
   if (optionsEditor != null) {
     final ColorAndFontOptions colorAndFontOptions =
         optionsEditor.findConfigurable(ColorAndFontOptions.class);
     assert colorAndFontOptions != null;
     final SearchableConfigurable javaPage =
         colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
     LOG.assertTrue(javaPage != null);
     optionsEditor
         .clearSearchAndSelect(javaPage)
         .doWhenDone(
             new Runnable() {
               @Override
               public void run() {
                 final Runnable runnable = javaPage.enableSearch(toConfigure);
                 if (runnable != null) {
                   SwingUtilities.invokeLater(runnable);
                 }
               }
             });
   } else {
     ColorAndFontOptions colorAndFontOptions = new ColorAndFontOptions();
     final Configurable[] configurables = colorAndFontOptions.buildConfigurables();
     try {
       final SearchableConfigurable javaPage =
           colorAndFontOptions.findSubConfigurable(InspectionColorSettingsPage.class);
       LOG.assertTrue(javaPage != null);
       ShowSettingsUtil.getInstance()
           .editConfigurable(CommonDataKeys.PROJECT.getData(dataContext), javaPage);
     } finally {
       for (Configurable configurable : configurables) {
         configurable.disposeUIResources();
       }
       colorAndFontOptions.disposeUIResources();
     }
   }
 }
 public void showNoSdkNotification(@NotNull final Project project) {
   final String text =
       "<html>No Python interpreter configured for the project<br><a href=\"\">Configure interpreter</a></html>";
   final BalloonBuilder balloonBuilder =
       JBPopupFactory.getInstance()
           .createHtmlTextBalloonBuilder(
               text,
               null,
               MessageType.WARNING.getPopupBackground(),
               event -> {
                 if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
                   ApplicationManager.getApplication()
                       .invokeLater(
                           () ->
                               ShowSettingsUtil.getInstance()
                                   .showSettingsDialog(project, "Project Interpreter"));
                 }
               });
   balloonBuilder.setHideOnLinkClick(true);
   final Balloon balloon = balloonBuilder.createBalloon();
   StudyUtils.showCheckPopUp(project, balloon);
 }
 @Override
 protected void hyperlinkActivated(
     @NotNull Notification notification, @NotNull HyperlinkEvent event) {
   if (event.getDescription().equals("configure") && !myProject.isDisposed()) {
     ShowSettingsUtil.getInstance()
         .showSettingsDialog(myProject, ActionsBundle.message("group.VcsGroup.text"));
     Collection<VcsRootError> errorsAfterPossibleFix = getInstance(myProject).scan();
     if (errorsAfterPossibleFix.isEmpty() && !notification.isExpired()) {
       notification.expire();
     }
   } else if (event.getDescription().equals("ignore")) {
     mySettings.addIgnoredUnregisteredRoots(
         ContainerUtil.map(myImportantUnregisteredRoots, PATH_FROM_ROOT_ERROR));
     notification.expire();
   } else if (event.getDescription().equals("add")) {
     List<VcsDirectoryMapping> mappings = myVcsManager.getDirectoryMappings();
     for (VcsRootError root : myImportantUnregisteredRoots) {
       mappings = VcsUtil.addMapping(mappings, root.getMapping(), root.getVcsKey().getName());
     }
     myVcsManager.setDirectoryMappings(mappings);
   }
 }
 public void actionPerformed(AnActionEvent e) {
   Project project = PlatformDataKeys.PROJECT.getData(e.getDataContext());
   if (project != null) {
     ShowSettingsUtil.getInstance().editConfigurable(project, new CompilerConfigurable(project));
   }
 }
    @Override
    public void hyperlinkUpdate(HyperlinkEvent e) {
      if (e.getEventType() != HyperlinkEvent.EventType.ACTIVATED) return;

      ShowSettingsUtil.getInstance().showSettingsDialog(myProject, MavenSettings.DISPLAY_NAME);
    }
  @Override
  public void actionPerformed(AnActionEvent e) {
    DataContext dataContext = e.getDataContext();
    final Editor editor = CommonDataKeys.EDITOR.getData(dataContext);
    PsiFile file = CommonDataKeys.PSI_FILE.getData(dataContext);

    final Project project = file.getProject();
    PsiDocumentManager.getInstance(project).commitAllDocuments();

    final TextRange selection =
        new TextRange(
            editor.getSelectionModel().getSelectionStart(),
            editor.getSelectionModel().getSelectionEnd());
    PsiElement current = file.findElementAt(selection.getStartOffset());
    int startOffset = selection.getStartOffset();
    while (current instanceof PsiWhiteSpace) {
      current = current.getNextSibling();
      if (current == null) break;
      startOffset = current.getTextRange().getStartOffset();
    }

    if (startOffset >= selection.getEndOffset()) startOffset = selection.getStartOffset();

    final PsiElement[] psiElements =
        PsiTreeUtil.collectElements(
            file,
            new PsiElementFilter() {
              @Override
              public boolean isAccepted(PsiElement element) {
                return selection.contains(element.getTextRange())
                    && element.getReferences().length > 0;
              }
            });

    final Document document =
        EditorFactory.getInstance()
            .createDocument(
                editor.getDocument().getText().substring(startOffset, selection.getEndOffset()));
    final boolean isXml = file.getLanguage().is(StdLanguages.XML);
    final int offsetDelta = startOffset;
    new WriteCommandAction.Simple(project, (String) null) {
      @Override
      protected void run() throws Throwable {
        Map<RangeMarker, String> rangeToText = new HashMap<RangeMarker, String>();

        for (PsiElement element : psiElements) {
          for (PsiReference reference : element.getReferences()) {
            if (!(reference instanceof PsiQualifiedReference)
                || ((PsiQualifiedReference) reference).getQualifier() == null) {
              String canonicalText = reference.getCanonicalText();
              LOG.assertTrue(canonicalText != null, reference.getClass());
              TextRange referenceRange = reference.getRangeInElement();
              final TextRange elementTextRange = element.getTextRange();
              LOG.assertTrue(elementTextRange != null, elementTextRange);
              final TextRange range =
                  elementTextRange.cutOut(referenceRange).shiftRight(-offsetDelta);
              final String oldText = document.getText(range);
              // workaround for Java references: canonicalText contains generics, and we need to cut
              // them off because otherwise
              // they will be duplicated
              int pos = canonicalText.indexOf('<');
              if (pos > 0 && !oldText.contains("<")) {
                canonicalText = canonicalText.substring(0, pos);
              }
              if (isXml) { // strip namespace prefixes
                pos = canonicalText.lastIndexOf(':');
                if (pos >= 0 && pos < canonicalText.length() - 1 && !oldText.contains(":")) {
                  canonicalText = canonicalText.substring(pos + 1);
                }
              }
              if (!canonicalText.equals(oldText)) {
                rangeToText.put(document.createRangeMarker(range), canonicalText);
              }
            }
          }
        }

        for (Map.Entry<RangeMarker, String> entry : rangeToText.entrySet()) {
          document.replaceString(
              entry.getKey().getStartOffset(), entry.getKey().getEndOffset(), entry.getValue());
        }
      }
    }.execute();

    final TemplateImpl template =
        new TemplateImpl(
            TemplateListPanel.ABBREVIATION, document.getText(), TemplateSettings.USER_GROUP_NAME);
    template.setToReformat(true);

    PsiFile copy;
    AccessToken token = WriteAction.start();
    try {
      copy = TemplateManagerImpl.insertDummyIdentifier(editor, file);
    } finally {
      token.finish();
    }
    Set<TemplateContextType> applicable =
        TemplateManagerImpl.getApplicableContextTypes(copy, startOffset);

    for (TemplateContextType contextType : TemplateManagerImpl.getAllContextTypes()) {
      template.getTemplateContext().setEnabled(contextType, applicable.contains(contextType));
    }

    final LiveTemplatesConfigurable configurable = new LiveTemplatesConfigurable();
    ShowSettingsUtil.getInstance()
        .editConfigurable(
            project, configurable, () -> configurable.getTemplateListPanel().addTemplate(template));
  }
 @Override
 public void actionPerformed(AnActionEvent e) {
   SonarLintProjectConfigurable configurable = new SonarLintProjectConfigurable(e.getProject());
   ShowSettingsUtil.getInstance().editConfigurable(e.getProject(), configurable);
 }