Replaced dialog for editing Kotlin signature with balloon.
This commit is contained in:
+47
-18
@@ -30,9 +30,11 @@ import com.intellij.openapi.editor.EditorFactory;
|
||||
import com.intellij.openapi.editor.EditorSettings;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.DialogWrapper;
|
||||
import com.intellij.openapi.ui.popup.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.IdeFocusManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.util.Function;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -42,6 +44,9 @@ import org.jetbrains.jet.plugin.JetFileType;
|
||||
import org.jetbrains.jet.plugin.JetIcons;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
@@ -90,11 +95,12 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
else {
|
||||
// TODO check if annotations are editable
|
||||
DialogWrapper dialogWrapper = new EditSignatureDialog(element);
|
||||
dialogWrapper.show();
|
||||
|
||||
new EditSignatureBalloon(element).show(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
private static final String KOTLIN_SIGNATURE_ANNOTATION = JvmStdlibNames.KOTLIN_SIGNATURE.getFqName().getFqName();
|
||||
|
||||
@Nullable
|
||||
@@ -133,13 +139,16 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
public void collectSlowLineMarkers(@NotNull List<PsiElement> elements, @NotNull Collection<LineMarkerInfo> result) {
|
||||
}
|
||||
|
||||
private static class EditSignatureDialog extends DialogWrapper {
|
||||
@SuppressWarnings("SSBasedInspection")
|
||||
private static class EditSignatureBalloon {
|
||||
private final JPanel panel;
|
||||
private final Editor editor;
|
||||
private final PsiMethod method;
|
||||
private final String previousSignature;
|
||||
private final Balloon balloon;
|
||||
|
||||
public EditSignatureDialog(PsiMethod method) {
|
||||
super(method.getProject());
|
||||
public EditSignatureBalloon(PsiMethod method) {
|
||||
panel = new JPanel(new BorderLayout());
|
||||
this.method = method;
|
||||
PsiAnnotation kotlinSignatureAnnotation = findKotlinSignatureAnnotation(this.method);
|
||||
assert kotlinSignatureAnnotation != null;
|
||||
@@ -155,25 +164,45 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
settings.setRightMarginShown(false);
|
||||
settings.setAdditionalPageAtBottom(false);
|
||||
settings.setAdditionalLinesCount(0);
|
||||
init();
|
||||
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
||||
|
||||
JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JButton saveButton = new JButton("Save");
|
||||
toolbar.add(saveButton);
|
||||
panel.add(toolbar, BorderLayout.SOUTH);
|
||||
saveButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
save();
|
||||
balloon.hide();
|
||||
}
|
||||
});
|
||||
|
||||
BalloonBuilder builder = JBPopupFactory.getInstance().createDialogBalloonBuilder(panel, "Kotlin signature");
|
||||
builder.setHideOnClickOutside(true);
|
||||
builder.setHideOnKeyOutside(true);
|
||||
|
||||
balloon = builder.createBalloon();
|
||||
balloon.addListener(new JBPopupAdapter() {
|
||||
@Override
|
||||
public void onClosed(LightweightWindowEvent event) {
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void dispose() {
|
||||
super.dispose();
|
||||
public void show(MouseEvent e) {
|
||||
balloon.show(new RelativePoint(e), Balloon.Position.above);
|
||||
IdeFocusManager.getInstance(editor.getProject()).requestFocus(editor.getContentComponent(), false);
|
||||
}
|
||||
|
||||
private void dispose() {
|
||||
EditorFactory editorFactory = EditorFactory.getInstance();
|
||||
assert editorFactory != null;
|
||||
editorFactory.releaseEditor(editor);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected JComponent createCenterPanel() {
|
||||
return editor.getComponent();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOKAction() {
|
||||
super.doOKAction();
|
||||
private void save() {
|
||||
String newSignature = editor.getDocument().getText();
|
||||
if (previousSignature.equals(newSignature)) return;
|
||||
final Project project = method.getProject();
|
||||
|
||||
Reference in New Issue
Block a user