use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class CreateFormAction method invokeDialog.
@NotNull
protected PsiElement[] invokeDialog(Project project, PsiDirectory directory) {
final MyInputValidator validator = new JavaNameValidator(project, directory);
final DialogWrapper dialog = new MyDialog(project, validator);
dialog.show();
return validator.getCreatedElements();
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class DarculaTitlePane method createHelpButton.
private JButton createHelpButton() {
Ref<WindowButton> button = Ref.create();
button.set(new WindowButton("Help", AllIcons.Windows.HelpButton, AllIcons.Windows.HelpButton, new AbstractAction("Help") {
@Override
public void actionPerformed(ActionEvent e) {
final DialogWrapper dialog = DialogWrapper.findInstance(button.get());
if (dialog != null) {
try {
final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction");
getHelpAction.setAccessible(true);
final Object helpAction = getHelpAction.invoke(dialog);
if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) {
((Action) helpAction).actionPerformed(e);
}
} catch (Exception ex) {
}
}
}
}, BUTTON_HOVER_BG) {
{
setFont(new Font("Segoe UI Regular", Font.PLAIN, JBUI.scale(15)));
}
@Override
public void paint(Graphics g) {
if (isHelpAvailable()) {
super.paint(g);
} else {
g.setColor(getBackground());
g.fillRect(0, 0, getWidth(), getHeight());
}
}
private boolean isHelpAvailable() {
final DialogWrapper dialog = DialogWrapper.findInstance(this);
if (dialog != null) {
try {
final Method getHelpAction = DialogWrapper.class.getDeclaredMethod("getHelpAction");
getHelpAction.setAccessible(true);
final Object helpAction = getHelpAction.invoke(dialog);
if (helpAction instanceof Action && ((Action) helpAction).isEnabled()) {
return true;
}
} catch (Exception e) {
e.printStackTrace();
}
}
return false;
}
});
return button.get();
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class PsiDocumentManagerImplTest method testCommitDocumentInModalDialog.
public void testCommitDocumentInModalDialog() throws IOException {
VirtualFile vFile = getVirtualFile(createTempFile("a.txt", "abc"));
PsiFile psiFile = findFile(vFile);
final Document document = getDocument(psiFile);
final DialogWrapper dialog = new DialogWrapper(getProject()) {
@Nullable
@Override
protected JComponent createCenterPanel() {
return null;
}
};
disposeOnTearDown(() -> dialog.close(DialogWrapper.OK_EXIT_CODE));
ApplicationManager.getApplication().runWriteAction(() -> {
// commit thread is paused
document.setText("xx");
LaterInvocator.enterModal(dialog);
});
assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
// may or may not be committed until exit modal dialog
waitTenSecondsForCommit(document);
LaterInvocator.leaveModal(dialog);
assertEquals(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
// must commit
waitTenSecondsForCommit(document);
assertTrue(getPsiDocumentManager().isCommitted(document));
// check that inside modal dialog commit is possible
ApplicationManager.getApplication().runWriteAction(() -> {
// commit thread is paused
LaterInvocator.enterModal(dialog);
document.setText("yyy");
});
assertNotSame(ModalityState.NON_MODAL, ApplicationManager.getApplication().getCurrentModalityState());
// must commit
waitTenSecondsForCommit(document);
assertTrue(getPsiDocumentManager().isCommitted(document));
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class NavBarListener method focusLost.
@Override
public void focusLost(final FocusEvent e) {
if (myPanel.getProject().isDisposed()) {
myPanel.setContextComponent(null);
myPanel.hideHint();
return;
}
final DialogWrapper dialog = DialogWrapper.findInstance(e.getOppositeComponent());
shouldFocusEditor = dialog != null;
if (dialog != null) {
Disposer.register(dialog.getDisposable(), new Disposable() {
@Override
public void dispose() {
if (dialog.getExitCode() == DialogWrapper.CANCEL_EXIT_CODE) {
shouldFocusEditor = false;
}
}
});
}
// required invokeLater since in current call sequence KeyboardFocusManager is not initialized yet
// but future focused component
//noinspection SSBasedInspection
SwingUtilities.invokeLater(() -> processFocusLost(e));
}
use of com.intellij.openapi.ui.DialogWrapper in project intellij-community by JetBrains.
the class JavaChangeSignatureHandler method invoke.
private static void invoke(final PsiMethod method, final Project project, @Nullable final Editor editor) {
PsiMethod newMethod = SuperMethodWarningUtil.checkSuperMethod(method, RefactoringBundle.message("to.refactor"));
if (newMethod == null)
return;
if (!newMethod.equals(method)) {
ChangeSignatureUtil.invokeChangeSignatureOn(newMethod, project);
return;
}
if (!CommonRefactoringUtil.checkReadOnlyStatus(project, method))
return;
final PsiClass containingClass = method.getContainingClass();
final PsiReferenceExpression refExpr = editor != null ? JavaTargetElementEvaluator.findReferenceExpression(editor) : null;
final boolean allowDelegation = containingClass != null && (!containingClass.isInterface() || PsiUtil.isLanguageLevel8OrHigher(containingClass));
InplaceChangeSignature inplaceChangeSignature = editor != null ? InplaceChangeSignature.getCurrentRefactoring(editor) : null;
ChangeInfo initialChange = inplaceChangeSignature != null ? inplaceChangeSignature.getStableChange() : null;
boolean isInplace = Registry.is("inplace.change.signature") && editor != null && editor.getSettings().isVariableInplaceRenameEnabled() && (initialChange == null || initialChange.getMethod() != method) && refExpr == null;
PsiIdentifier nameIdentifier = method.getNameIdentifier();
LOG.assertTrue(nameIdentifier != null);
if (isInplace) {
CommandProcessor.getInstance().executeCommand(project, () -> new InplaceChangeSignature(project, editor, nameIdentifier), REFACTORING_NAME, null);
} else {
JavaMethodDescriptor methodDescriptor = new JavaMethodDescriptor(method);
if (initialChange != null) {
JavaChangeInfo currentInfo = (JavaChangeInfo) inplaceChangeSignature.getCurrentInfo();
if (currentInfo != null) {
methodDescriptor = new JavaMethodDescriptor(method) {
@Override
public String getName() {
return currentInfo.getNewName();
}
@Override
public List<ParameterInfoImpl> getParameters() {
return Arrays.asList((ParameterInfoImpl[]) currentInfo.getNewParameters());
}
@Override
public String getVisibility() {
return currentInfo.getNewVisibility();
}
@Override
public int getParametersCount() {
return currentInfo.getNewParameters().length;
}
@Nullable
@Override
public String getReturnTypeText() {
return currentInfo.getNewReturnType().getTypeText();
}
};
}
inplaceChangeSignature.cancel();
}
final DialogWrapper dialog = new JavaChangeSignatureDialog(project, methodDescriptor, allowDelegation, refExpr == null ? method : refExpr);
dialog.show();
}
}
Aggregations