use of com.intellij.refactoring.RefactoringSettings in project intellij-community by JetBrains.
the class SafeDeleteDialog method createNorthPanel.
@Override
protected JComponent createNorthPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final GridBagConstraints gbc = new GridBagConstraints();
final String promptKey = isDelete() ? "prompt.delete.elements" : "search.for.usages.and.delete.elements";
final String warningMessage = DeleteUtil.generateWarningMessage(IdeBundle.message(promptKey), myElements);
gbc.insets = JBUI.insets(4, 8);
gbc.weighty = 1;
gbc.weightx = 1;
gbc.gridx = 0;
gbc.gridy = 0;
gbc.gridwidth = 2;
gbc.fill = GridBagConstraints.BOTH;
gbc.anchor = GridBagConstraints.WEST;
panel.add(new JLabel(warningMessage), gbc);
if (isDelete()) {
gbc.gridy++;
gbc.gridx = 0;
gbc.weightx = 0.0;
gbc.gridwidth = 1;
gbc.insets = JBUI.insets(4, 8, 0, 8);
myCbSafeDelete = new JCheckBox(IdeBundle.message("checkbox.safe.delete.with.usage.search"));
panel.add(myCbSafeDelete, gbc);
myCbSafeDelete.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
updateControls(myCbSearchInComments);
updateControls(myCbSearchTextOccurrences);
}
});
}
gbc.gridy++;
gbc.gridx = 0;
gbc.weightx = 0.0;
gbc.gridwidth = 1;
myCbSearchInComments = new StateRestoringCheckBox();
myCbSearchInComments.setText(RefactoringBundle.getSearchInCommentsAndStringsText());
panel.add(myCbSearchInComments, gbc);
if (needSearchForTextOccurrences()) {
gbc.gridx++;
myCbSearchTextOccurrences = new StateRestoringCheckBox();
myCbSearchTextOccurrences.setText(RefactoringBundle.getSearchForTextOccurrencesText());
panel.add(myCbSearchTextOccurrences, gbc);
}
final RefactoringSettings refactoringSettings = RefactoringSettings.getInstance();
if (myCbSafeDelete != null) {
myCbSafeDelete.setSelected(refactoringSettings.SAFE_DELETE_WHEN_DELETE);
}
myCbSearchInComments.setSelected(myDelegate != null ? myDelegate.isToSearchInComments(myElements[0]) : refactoringSettings.SAFE_DELETE_SEARCH_IN_COMMENTS);
if (myCbSearchTextOccurrences != null) {
myCbSearchTextOccurrences.setSelected(myDelegate != null ? myDelegate.isToSearchForTextOccurrences(myElements[0]) : refactoringSettings.SAFE_DELETE_SEARCH_IN_NON_JAVA);
}
updateControls(myCbSearchTextOccurrences);
updateControls(myCbSearchInComments);
return panel;
}
use of com.intellij.refactoring.RefactoringSettings in project intellij-community by JetBrains.
the class SafeDeleteDialog method doOKAction.
@Override
protected void doOKAction() {
if (DumbService.isDumb(myProject)) {
Messages.showMessageDialog(myProject, "Safe delete refactoring is not available while indexing is in progress", "Indexing", null);
return;
}
NonProjectFileWritingAccessProvider.disableChecksDuring(() -> {
if (myCallback != null && isSafeDelete()) {
myCallback.run(this);
} else {
super.doOKAction();
}
});
final RefactoringSettings refactoringSettings = RefactoringSettings.getInstance();
if (myCbSafeDelete != null) {
refactoringSettings.SAFE_DELETE_WHEN_DELETE = myCbSafeDelete.isSelected();
}
if (isSafeDelete()) {
if (myDelegate == null) {
refactoringSettings.SAFE_DELETE_SEARCH_IN_COMMENTS = isSearchInComments();
if (myCbSearchTextOccurrences != null) {
refactoringSettings.SAFE_DELETE_SEARCH_IN_NON_JAVA = isSearchForTextOccurences();
}
} else {
myDelegate.setToSearchInComments(myElements[0], isSearchInComments());
if (myCbSearchTextOccurrences != null) {
myDelegate.setToSearchForTextOccurrences(myElements[0], isSearchForTextOccurences());
}
}
}
}
use of com.intellij.refactoring.RefactoringSettings in project intellij-community by JetBrains.
the class SafeDeleteHandler method invoke.
public static void invoke(final Project project, PsiElement[] elements, @Nullable Module module, boolean checkDelegates, @Nullable final Runnable successRunnable) {
for (PsiElement element : elements) {
if (!SafeDeleteProcessor.validElement(element)) {
return;
}
}
final PsiElement[] temptoDelete = PsiTreeUtil.filterAncestors(elements);
Set<PsiElement> elementsSet = new HashSet<>(Arrays.asList(temptoDelete));
Set<PsiElement> fullElementsSet = new LinkedHashSet<>();
if (checkDelegates) {
for (PsiElement element : temptoDelete) {
boolean found = false;
for (SafeDeleteProcessorDelegate delegate : Extensions.getExtensions(SafeDeleteProcessorDelegate.EP_NAME)) {
if (delegate.handlesElement(element)) {
found = true;
Collection<? extends PsiElement> addElements = delegate instanceof SafeDeleteProcessorDelegateBase ? ((SafeDeleteProcessorDelegateBase) delegate).getElementsToSearch(element, module, elementsSet) : delegate.getElementsToSearch(element, elementsSet);
if (addElements == null)
return;
fullElementsSet.addAll(addElements);
break;
}
}
if (!found) {
fullElementsSet.add(element);
}
}
} else {
ContainerUtil.addAll(fullElementsSet, temptoDelete);
}
if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, fullElementsSet, true))
return;
final PsiElement[] elementsToDelete = PsiUtilCore.toPsiElementArray(fullElementsSet);
if (ApplicationManager.getApplication().isUnitTestMode()) {
RefactoringSettings settings = RefactoringSettings.getInstance();
SafeDeleteProcessor.createInstance(project, null, elementsToDelete, settings.SAFE_DELETE_SEARCH_IN_COMMENTS, settings.SAFE_DELETE_SEARCH_IN_NON_JAVA, true).run();
if (successRunnable != null)
successRunnable.run();
} else {
final SafeDeleteDialog.Callback callback = new SafeDeleteDialog.Callback() {
@Override
public void run(final SafeDeleteDialog dialog) {
SafeDeleteProcessor.createInstance(project, () -> {
if (successRunnable != null) {
successRunnable.run();
}
dialog.close(DialogWrapper.CANCEL_EXIT_CODE);
}, elementsToDelete, dialog.isSearchInComments(), dialog.isSearchForTextOccurences(), true).run();
}
};
SafeDeleteDialog dialog = new SafeDeleteDialog(project, elementsToDelete, callback);
dialog.show();
}
}
Aggregations