@NotNull @Override // com.intellij.codeInsight.actions.RearrangeCodeProcessor.prepareTask() protected FutureTask<Boolean> prepareTask(@NotNull PsiFile file, boolean processChangedTextOnly) { return new FutureTask<>(() -> { try { Collection<TextRange> ranges = getRangesToFormat(file, processChangedTextOnly); Document document = PsiDocumentManager.getInstance(myProject).getDocument(file); if (document != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null) { PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document); Runnable command = prepareRearrangeCommand(file, ranges); CommandProcessor.getInstance().executeCommand(myProject, command, COMMAND_NAME, null); } return true; } catch (FilesTooBigForDiffException e) { handleFileTooBigException(LOGGER, e, file); return false; } }); }
private void setUpActions() { boolean canOptimizeImports = !LanguageImportStatements.INSTANCE.forFile(myFile).isEmpty(); myOptimizeImportsCb.setVisible(canOptimizeImports); if (canOptimizeImports) { myOptimizeImportsCb.setSelected(myLastRunOptions.getLastOptimizeImports()); } boolean canRearrangeCode = Rearranger.EXTENSION.forLanguage(myFile.getLanguage()) != null; myRearrangeCodeCb.setVisible(canRearrangeCode); if (canRearrangeCode) { myRearrangeCodeCb.setSelected(myLastRunOptions.isRearrangeCode(myFile.getLanguage())); } myOptionalLabel.setVisible(canOptimizeImports || canRearrangeCode); }
@NotNull @Override protected FutureTask<Boolean> prepareTask(@NotNull final PsiFile file, final boolean processChangedTextOnly) { return new FutureTask<Boolean>(new Callable<Boolean>() { @Override public Boolean call() throws Exception { try { Collection<TextRange> ranges = getRangesToFormat(file, processChangedTextOnly); Document document = PsiDocumentManager.getInstance(myProject).getDocument(file); if (document != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null) { PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document); PsiDocumentManager.getInstance(myProject).commitDocument(document); Runnable command = prepareRearrangeCommand(file, ranges); try { CommandProcessor.getInstance().executeCommand(myProject, command, COMMAND_NAME, null); } finally { PsiDocumentManager.getInstance(myProject).commitDocument(document); } } return true; } catch (FilesTooBigForDiffException e) { handleFileTooBigException(LOG, e, file); return false; } } }); }
private void updateState() { myCbIncludeSubdirs.setEnabled(myRbDirectory.isSelected()); myCbOptimizeImports.setEnabled( !myRbSelectedText.isSelected() && !(myFile != null && LanguageImportStatements.INSTANCE.forFile(myFile).isEmpty() && myRbFile.isSelected()) ); myCbArrangeEntries.setEnabled(myFile != null && Rearranger.EXTENSION.forLanguage(myFile.getLanguage()) != null ); myCbOnlyVcsChangedRegions.setEnabled(canTargetVcsRegions()); myDoNotAskMeCheckBox.setEnabled(!myRbDirectory.isSelected()); myRbDirectory.setEnabled(!myDoNotAskMeCheckBox.isSelected()); }
@Nonnull @Override protected FutureTask<Boolean> prepareTask(@Nonnull final PsiFile file, final boolean processChangedTextOnly) { return new FutureTask<Boolean>(new Callable<Boolean>() { @Override public Boolean call() throws Exception { try { Collection<TextRange> ranges = getRangesToFormat(file, processChangedTextOnly); Document document = PsiDocumentManager.getInstance(myProject).getDocument(file); if (document != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null) { PsiDocumentManager.getInstance(myProject).doPostponedOperationsAndUnblockDocument(document); PsiDocumentManager.getInstance(myProject).commitDocument(document); Runnable command = prepareRearrangeCommand(file, ranges); try { CommandProcessor.getInstance().executeCommand(myProject, command, COMMAND_NAME, null); } finally { PsiDocumentManager.getInstance(myProject).commitDocument(document); } } return true; } catch (FilesTooBigForDiffException e) { handleFileTooBigException(LOG, e, file); return false; } } }); }
@RequiredDispatchThread @Override public void update(@Nonnull AnActionEvent e) { PsiFile file = e.getDataContext().getData(CommonDataKeys.PSI_FILE); boolean enabled = file != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null; e.getPresentation().setEnabled(enabled); }
@Override public void update(AnActionEvent e) { PsiFile file = CommonDataKeys.PSI_FILE.getData(e.getDataContext()); boolean enabled = file != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null; e.getPresentation().setEnabled(enabled); }
@Override protected JComponent createCenterPanel() { JPanel panel = new JPanel(new GridBagLayout()); panel.setBorder(BorderFactory.createEmptyBorder(4, 8, 8, 0)); GridBagConstraints gbConstraints = new GridBagConstraints(); gbConstraints.gridy = 0; gbConstraints.gridx = 0; gbConstraints.gridwidth = 3; gbConstraints.gridheight = 1; gbConstraints.weightx = 1; gbConstraints.fill = GridBagConstraints.BOTH; gbConstraints.insets = new Insets(0, 0, 0, 0); myRbFile = new JRadioButton(CodeInsightBundle.message("process.scope.file", (myFile != null ? "'" + myFile.getVirtualFile().getPresentableUrl() + "'" : ""))); panel.add(myRbFile, gbConstraints); myRbSelectedText = new JRadioButton(CodeInsightBundle.message("reformat.option.selected.text")); if (myTextSelected != null) { gbConstraints.gridy++; gbConstraints.insets = new Insets(0, 0, 0, 0); panel.add(myRbSelectedText, gbConstraints); } myRbDirectory = new JRadioButton(); myCbIncludeSubdirs = new JCheckBox(CodeInsightBundle.message("reformat.option.include.subdirectories")); if (myDirectory != null) { myRbDirectory.setText(CodeInsightBundle.message("reformat.option.all.files.in.directory", myDirectory.getVirtualFile().getPresentableUrl())); gbConstraints.gridy++; gbConstraints.insets = new Insets(0, 0, 0, 0); panel.add(myRbDirectory, gbConstraints); if (myDirectory.getSubdirectories().length > 0) { gbConstraints.gridy++; gbConstraints.insets = new Insets(0, 20, 0, 0); panel.add(myCbIncludeSubdirs, gbConstraints); } } myCbOptimizeImports = new JCheckBox(CodeInsightBundle.message("reformat.option.optimize.imports")); if (myTextSelected != null && LanguageImportStatements.INSTANCE.hasAnyExtensions()) { gbConstraints.gridy++; gbConstraints.insets = new Insets(0, 0, 0, 0); panel.add(myCbOptimizeImports, gbConstraints); } myCbArrangeEntries = new JCheckBox(CodeInsightBundle.message("reformat.option.rearrange.entries")); if (myFile != null && Rearranger.EXTENSION.forLanguage(myFile.getLanguage()) != null) { gbConstraints.gridy++; gbConstraints.insets = new Insets(0, 0, 0, 0); panel.add(myCbArrangeEntries, gbConstraints); } myCbOnlyVcsChangedRegions = new JCheckBox(CodeInsightBundle.message("reformat.option.vcs.changed.region")); gbConstraints.gridy++; panel.add(myCbOnlyVcsChangedRegions, gbConstraints); ButtonGroup buttonGroup = new ButtonGroup(); buttonGroup.add(myRbFile); buttonGroup.add(myRbSelectedText); buttonGroup.add(myRbDirectory); myRbFile.setEnabled(myFile != null); myRbSelectedText.setEnabled(myTextSelected == Boolean.TRUE); return panel; }
@Override public void update(AnActionEvent e) { PsiFile file = LangDataKeys.PSI_FILE.getData(e.getDataContext()); boolean enabled = file != null && Rearranger.EXTENSION.forLanguage(file.getLanguage()) != null; e.getPresentation().setEnabled(enabled); }