Extracted methods from EditSignatureBalloon.
This commit is contained in:
@@ -30,6 +30,7 @@ import com.intellij.psi.JavaPsiFacade;
|
|||||||
import com.intellij.psi.PsiMethod;
|
import com.intellij.psi.PsiMethod;
|
||||||
import com.intellij.psi.PsiNameValuePair;
|
import com.intellij.psi.PsiNameValuePair;
|
||||||
import com.intellij.ui.awt.RelativePoint;
|
import com.intellij.ui.awt.RelativePoint;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.jetbrains.jet.plugin.JetFileType;
|
import org.jetbrains.jet.plugin.JetFileType;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
@@ -49,22 +50,31 @@ class EditSignatureBalloon {
|
|||||||
private final String previousSignature;
|
private final String previousSignature;
|
||||||
private final Balloon balloon;
|
private final Balloon balloon;
|
||||||
|
|
||||||
public EditSignatureBalloon(PsiMethod method, String previousSignature) {
|
public EditSignatureBalloon(@NotNull PsiMethod method, @NotNull String previousSignature) {
|
||||||
this.method = method;
|
this.method = method;
|
||||||
this.previousSignature = previousSignature;
|
this.previousSignature = previousSignature;
|
||||||
|
|
||||||
EditorFactory editorFactory = EditorFactory.getInstance();
|
editor = createEditor();
|
||||||
assert editorFactory != null;
|
JPanel panel = createBalloonPanel();
|
||||||
Document document = editorFactory.createDocument(previousSignature);
|
balloon = createBalloon(panel);
|
||||||
editor = editorFactory.createEditor(document, method.getProject(), JetFileType.INSTANCE, false);
|
}
|
||||||
EditorSettings settings = editor.getSettings();
|
|
||||||
settings.setVirtualSpace(false);
|
|
||||||
settings.setLineMarkerAreaShown(false);
|
|
||||||
settings.setFoldingOutlineShown(false);
|
|
||||||
settings.setRightMarginShown(false);
|
|
||||||
settings.setAdditionalPageAtBottom(false);
|
|
||||||
settings.setAdditionalLinesCount(0);
|
|
||||||
|
|
||||||
|
private Balloon createBalloon(JPanel panel) {
|
||||||
|
BalloonBuilder builder = JBPopupFactory.getInstance().createDialogBalloonBuilder(panel, "Kotlin signature");
|
||||||
|
builder.setHideOnClickOutside(true);
|
||||||
|
builder.setHideOnKeyOutside(true);
|
||||||
|
|
||||||
|
Balloon balloon = builder.createBalloon();
|
||||||
|
balloon.addListener(new JBPopupAdapter() {
|
||||||
|
@Override
|
||||||
|
public void onClosed(LightweightWindowEvent event) {
|
||||||
|
dispose();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return balloon;
|
||||||
|
}
|
||||||
|
|
||||||
|
private JPanel createBalloonPanel() {
|
||||||
JPanel panel = new JPanel(new BorderLayout());
|
JPanel panel = new JPanel(new BorderLayout());
|
||||||
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
||||||
|
|
||||||
@@ -75,22 +85,27 @@ class EditSignatureBalloon {
|
|||||||
saveButton.addActionListener(new ActionListener() {
|
saveButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
save();
|
saveAndHide();
|
||||||
balloon.hide();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
return panel;
|
||||||
|
}
|
||||||
|
|
||||||
BalloonBuilder builder = JBPopupFactory.getInstance().createDialogBalloonBuilder(panel, "Kotlin signature");
|
private Editor createEditor() {
|
||||||
builder.setHideOnClickOutside(true);
|
EditorFactory editorFactory = EditorFactory.getInstance();
|
||||||
builder.setHideOnKeyOutside(true);
|
assert editorFactory != null;
|
||||||
|
Document document = editorFactory.createDocument(this.previousSignature);
|
||||||
|
|
||||||
balloon = builder.createBalloon();
|
Editor editor = editorFactory.createEditor(document, this.method.getProject(), JetFileType.INSTANCE, false);
|
||||||
balloon.addListener(new JBPopupAdapter() {
|
EditorSettings settings = editor.getSettings();
|
||||||
@Override
|
settings.setVirtualSpace(false);
|
||||||
public void onClosed(LightweightWindowEvent event) {
|
settings.setLineMarkerAreaShown(false);
|
||||||
dispose();
|
settings.setFoldingOutlineShown(false);
|
||||||
}
|
settings.setRightMarginShown(false);
|
||||||
});
|
settings.setAdditionalPageAtBottom(false);
|
||||||
|
settings.setAdditionalLinesCount(0);
|
||||||
|
|
||||||
|
return editor;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void show(MouseEvent e) {
|
public void show(MouseEvent e) {
|
||||||
@@ -104,7 +119,7 @@ class EditSignatureBalloon {
|
|||||||
editorFactory.releaseEditor(editor);
|
editorFactory.releaseEditor(editor);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void save() {
|
private void saveAndHide() {
|
||||||
String newSignature = editor.getDocument().getText();
|
String newSignature = editor.getDocument().getText();
|
||||||
if (previousSignature.equals(newSignature)) return;
|
if (previousSignature.equals(newSignature)) return;
|
||||||
final Project project = method.getProject();
|
final Project project = method.getProject();
|
||||||
@@ -120,5 +135,7 @@ class EditSignatureBalloon {
|
|||||||
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(), nameValuePairs);
|
method, KotlinSignatureInJavaMarkerProvider.KOTLIN_SIGNATURE_ANNOTATION, method.getContainingFile(), nameValuePairs);
|
||||||
}
|
}
|
||||||
}.execute();
|
}.execute();
|
||||||
|
|
||||||
|
balloon.hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user