Made signature balloon read-only if owning annotations XML file is read-only.
This commit is contained in:
@@ -58,9 +58,11 @@ class EditSignatureBalloon {
|
||||
private final Project project;
|
||||
private final String previousSignature;
|
||||
private final Balloon balloon;
|
||||
private final boolean editable;
|
||||
|
||||
public EditSignatureBalloon(@NotNull PsiMethod method, @NotNull String previousSignature) {
|
||||
public EditSignatureBalloon(@NotNull PsiMethod method, @NotNull String previousSignature, boolean editable) {
|
||||
this.method = method;
|
||||
this.editable = editable;
|
||||
project = method.getProject();
|
||||
this.previousSignature = previousSignature;
|
||||
|
||||
@@ -94,45 +96,47 @@ class EditSignatureBalloon {
|
||||
};
|
||||
panel.add(editor.getComponent(), BorderLayout.CENTER);
|
||||
|
||||
JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JButton saveButton = new JButton("Save") {
|
||||
@Override
|
||||
public boolean isDefaultButton() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
JButton deleteButton = new JButton("Delete");
|
||||
if (editable) {
|
||||
JPanel toolbar = new JPanel(new FlowLayout(FlowLayout.RIGHT));
|
||||
JButton saveButton = new JButton("Save") {
|
||||
@Override
|
||||
public boolean isDefaultButton() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
JButton deleteButton = new JButton("Delete");
|
||||
|
||||
toolbar.add(saveButton);
|
||||
toolbar.add(deleteButton);
|
||||
panel.add(toolbar, BorderLayout.SOUTH);
|
||||
toolbar.add(saveButton);
|
||||
toolbar.add(deleteButton);
|
||||
panel.add(toolbar, BorderLayout.SOUTH);
|
||||
|
||||
ActionListener saveAndHideListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveAndHide();
|
||||
}
|
||||
};
|
||||
ActionListener saveAndHideListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
saveAndHide();
|
||||
}
|
||||
};
|
||||
|
||||
ActionListener cancelActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
balloon.hide();
|
||||
}
|
||||
};
|
||||
ActionListener cancelActionListener = new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
balloon.hide();
|
||||
}
|
||||
};
|
||||
|
||||
saveButton.addActionListener(saveAndHideListener);
|
||||
deleteButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
deleteAndHide();
|
||||
}
|
||||
});
|
||||
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);
|
||||
saveButton.addActionListener(saveAndHideListener);
|
||||
deleteButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
deleteAndHide();
|
||||
}
|
||||
});
|
||||
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;
|
||||
}
|
||||
@@ -141,6 +145,7 @@ class EditSignatureBalloon {
|
||||
EditorFactory editorFactory = EditorFactory.getInstance();
|
||||
assert editorFactory != null;
|
||||
Document document = editorFactory.createDocument(this.previousSignature);
|
||||
document.setReadOnly(!editable);
|
||||
|
||||
Editor editor = editorFactory.createEditor(document, project, JetFileType.INSTANCE, false);
|
||||
EditorSettings settings = editor.getSettings();
|
||||
|
||||
+5
-3
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.jet.plugin.codeInsight;
|
||||
|
||||
import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.ExternalAnnotationsManager;
|
||||
import com.intellij.codeInsight.daemon.DaemonCodeAnalyzer;
|
||||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||
@@ -172,9 +173,10 @@ public class KotlinSignatureInJavaMarkerProvider implements LineMarkerProvider {
|
||||
}
|
||||
}
|
||||
else {
|
||||
// TODO check if annotations are editable
|
||||
|
||||
new EditSignatureBalloon(getAnnotationOwner(element), getKotlinSignature(annotation)).show(point, editor);
|
||||
PsiMethod annotationOwner = getAnnotationOwner(element);
|
||||
boolean editable = ExternalAnnotationsManager.getInstance(element.getProject())
|
||||
.isExternalAnnotationWritable(annotationOwner, KOTLIN_SIGNATURE_ANNOTATION);
|
||||
new EditSignatureBalloon(annotationOwner, getKotlinSignature(annotation), editable).show(point, editor);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user