Added handling for Ctrl+Enter and Esc in EditSignatureBalloon.
This commit is contained in:
@@ -23,8 +23,10 @@ import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.*;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -37,9 +39,7 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.*;
|
||||
|
||||
/**
|
||||
* @author Evgeny Gerashchenko
|
||||
@@ -81,15 +81,36 @@ class EditSignatureBalloon {
|
||||
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
||||
|
||||
JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JButton saveButton = new JButton("Save");
|
||||
JButton saveButton = new JButton("Save") {
|
||||
@Override
|
||||
public boolean isDefaultButton() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
toolbar.add(saveButton);
|
||||
panel.add(toolbar, BorderLayout.SOUTH);
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
|
||||
ActionListener saveAndHideListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveAndHide();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
ActionListener cancelActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
balloon.hide();
|
||||
}
|
||||
};
|
||||
|
||||
saveButton.addActionListener(saveAndHideListener);
|
||||
panel.registerKeyboardAction(saveAndHideListener, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,
|
||||
SystemInfo.isMac ? InputEvent.META_DOWN_MASK : InputEvent.CTRL_DOWN_MASK),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
panel.registerKeyboardAction(cancelActionListener, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
|
||||
JComponent.WHEN_IN_FOCUSED_WINDOW);
|
||||
|
||||
return panel;
|
||||
}
|
||||
|
||||
@@ -107,6 +128,10 @@ class EditSignatureBalloon {
|
||||
settings.setAdditionalPageAtBottom(false);
|
||||
settings.setAdditionalLinesCount(0);
|
||||
|
||||
if (editor instanceof EditorEx) {
|
||||
((EditorEx)editor).setEmbeddedIntoDialogWrapper(true);
|
||||
}
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
@@ -138,20 +163,23 @@ class EditSignatureBalloon {
|
||||
|
||||
private void saveAndHide() {
|
||||
String newSignature = editor.getDocument().getText();
|
||||
if (previousSignature.equals(newSignature)) return;
|
||||
final Project project = method.getProject();
|
||||
final PsiNameValuePair[] nameValuePairs = JavaPsiFacade.getElementFactory(project).createAnnotationFromText(
|
||||
"@" + KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION + "(value=\"" + newSignature + "\")", null).getParameterList().getAttributes();
|
||||
if (!previousSignature.equals(newSignature)) {
|
||||
final Project project = method.getProject();
|
||||
final PsiNameValuePair[] nameValuePairs = JavaPsiFacade.getElementFactory(project).createAnnotationFromText(
|
||||
"@" + KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION + "(value=\"" + newSignature + "\")", null)
|
||||
.getParameterList().getAttributes();
|
||||
|
||||
new WriteCommandAction(project){
|
||||
@Override
|
||||
protected void run(final Result result) throws Throwable {
|
||||
ExternalAnnotationsManager
|
||||
.getInstance(project).deannotate(method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION);
|
||||
ExternalAnnotationsManager.getInstance(project).annotateExternally(
|
||||
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(), nameValuePairs);
|
||||
}
|
||||
}.execute();
|
||||
new WriteCommandAction(project) {
|
||||
@Override
|
||||
protected void run(final Result result) throws Throwable {
|
||||
ExternalAnnotationsManager
|
||||
.getInstance(project).deannotate(method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION);
|
||||
ExternalAnnotationsManager.getInstance(project).annotateExternally(
|
||||
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(),
|
||||
nameValuePairs);
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
balloon.hide();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user