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.application.Result;
|
||||||
import com.intellij.openapi.command.WriteCommandAction;
|
import com.intellij.openapi.command.WriteCommandAction;
|
||||||
import com.intellij.openapi.editor.*;
|
import com.intellij.openapi.editor.*;
|
||||||
|
import com.intellij.openapi.editor.ex.EditorEx;
|
||||||
import com.intellij.openapi.project.Project;
|
import com.intellij.openapi.project.Project;
|
||||||
import com.intellij.openapi.ui.popup.*;
|
import com.intellij.openapi.ui.popup.*;
|
||||||
|
import com.intellij.openapi.util.SystemInfo;
|
||||||
import com.intellij.openapi.wm.IdeFocusManager;
|
import com.intellij.openapi.wm.IdeFocusManager;
|
||||||
import com.intellij.psi.JavaPsiFacade;
|
import com.intellij.psi.JavaPsiFacade;
|
||||||
import com.intellij.psi.PsiDocumentManager;
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
@@ -37,9 +39,7 @@ import org.jetbrains.jet.plugin.JetFileType;
|
|||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
import java.awt.event.ActionEvent;
|
import java.awt.event.*;
|
||||||
import java.awt.event.ActionListener;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Evgeny Gerashchenko
|
* @author Evgeny Gerashchenko
|
||||||
@@ -81,15 +81,36 @@ class EditSignatureBalloon {
|
|||||||
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
||||||
|
|
||||||
JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
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);
|
toolbar.add(saveButton);
|
||||||
panel.add(toolbar, BorderLayout.SOUTH);
|
panel.add(toolbar, BorderLayout.SOUTH);
|
||||||
saveButton.addActionListener(new ActionListener() {
|
|
||||||
|
ActionListener saveAndHideListener = new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
saveAndHide();
|
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;
|
return panel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,6 +128,10 @@ class EditSignatureBalloon {
|
|||||||
settings.setAdditionalPageAtBottom(false);
|
settings.setAdditionalPageAtBottom(false);
|
||||||
settings.setAdditionalLinesCount(0);
|
settings.setAdditionalLinesCount(0);
|
||||||
|
|
||||||
|
if (editor instanceof EditorEx) {
|
||||||
|
((EditorEx)editor).setEmbeddedIntoDialogWrapper(true);
|
||||||
|
}
|
||||||
|
|
||||||
return editor;
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,20 +163,23 @@ class EditSignatureBalloon {
|
|||||||
|
|
||||||
private void saveAndHide() {
|
private void saveAndHide() {
|
||||||
String newSignature = editor.getDocument().getText();
|
String newSignature = editor.getDocument().getText();
|
||||||
if (previousSignature.equals(newSignature)) return;
|
if (!previousSignature.equals(newSignature)) {
|
||||||
final Project project = method.getProject();
|
final Project project = method.getProject();
|
||||||
final PsiNameValuePair[] nameValuePairs = JavaPsiFacade.getElementFactory(project).createAnnotationFromText(
|
final PsiNameValuePair[] nameValuePairs = JavaPsiFacade.getElementFactory(project).createAnnotationFromText(
|
||||||
"@" + KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION + "(value=\"" + newSignature + "\")", null).getParameterList().getAttributes();
|
"@" + KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION + "(value=\"" + newSignature + "\")", null)
|
||||||
|
.getParameterList().getAttributes();
|
||||||
|
|
||||||
new WriteCommandAction(project){
|
new WriteCommandAction(project) {
|
||||||
@Override
|
@Override
|
||||||
protected void run(final Result result) throws Throwable {
|
protected void run(final Result result) throws Throwable {
|
||||||
ExternalAnnotationsManager
|
ExternalAnnotationsManager
|
||||||
.getInstance(project).deannotate(method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION);
|
.getInstance(project).deannotate(method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION);
|
||||||
ExternalAnnotationsManager.getInstance(project).annotateExternally(
|
ExternalAnnotationsManager.getInstance(project).annotateExternally(
|
||||||
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(), nameValuePairs);
|
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(),
|
||||||
}
|
nameValuePairs);
|
||||||
}.execute();
|
}
|
||||||
|
}.execute();
|
||||||
|
}
|
||||||
|
|
||||||
balloon.hide();
|
balloon.hide();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user