mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
copy reference
This commit is contained in:
@@ -241,10 +241,9 @@
|
||||
<action id="$Cut" class="com.intellij.ide.actions.CutAction" text="Cu_t" icon="/actions/menu-cut.png" description="Cut to clipboard"/>
|
||||
<action id="$Copy" class="com.intellij.ide.actions.CopyAction" text="_Copy" icon="/actions/menu-copy.png" description="Copy to clipboard"/>
|
||||
<action id="CopyPaths" class="com.intellij.ide.actions.CopyPathsAction" text="C_opy Paths" description="Copy paths corresponding to selected files or directories to clipboard"/>
|
||||
<action id="CopyReference" class="com.intellij.ide.actions.CopyReferenceAction" text="Copy _Reference" description="Copy Java class/method/field reference"/>
|
||||
<action id="$Paste" class="com.intellij.ide.actions.PasteAction" text="_Paste" icon="/actions/menu-paste.png" description="Paste from clipboard"/>
|
||||
<action id="PasteMultiple" class="com.intellij.openapi.editor.actions.MultiplePasteAction" text="Past_e..." description="Paste from recent clipboards"/>
|
||||
<action id="CopyReference" class="com.intellij.ide.actions.CopyReferenceAction" text="Copy _Reference" description="Copy Java class/method/field reference"/>
|
||||
<action id="PasteReference" class="com.intellij.ide.actions.PasteReferenceAction" text="Paste Re_ference" description="Paste reference to copied Java class/method/field"/>
|
||||
<reference ref="EditorToggleColumnMode"/>
|
||||
</group>
|
||||
<separator/>
|
||||
|
||||
@@ -109,8 +109,7 @@ public class CodeInsightSettings implements NamedJDOMExternalizable, Cloneable,
|
||||
public boolean OPTIMIZE_IMPORTS_ON_THE_FLY = false;
|
||||
public boolean ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = false;
|
||||
|
||||
public CodeInsightSettings(EditorActionManager editorActionManager) {
|
||||
EditorActionManager actionManager = editorActionManager;
|
||||
public CodeInsightSettings(EditorActionManager actionManager) {
|
||||
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_ENTER, new EnterHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER)));
|
||||
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END, new EndHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_MOVE_LINE_END)));
|
||||
actionManager.setActionHandler(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET, new SelectWordHandler(actionManager.getActionHandler(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET)));
|
||||
|
||||
@@ -2,7 +2,6 @@ package com.intellij.codeInsight.editorActions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.folding.CodeFoldingManager;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.openapi.actionSystem.DataConstants;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
@@ -11,6 +10,7 @@ import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
|
||||
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
|
||||
import com.intellij.openapi.editor.ex.EditorEx;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.ide.CopyPasteManager;
|
||||
@@ -18,7 +18,6 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.openapi.util.text.LineTokenizer;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.codeStyle.CodeStyleSettings;
|
||||
@@ -26,6 +25,8 @@ import com.intellij.psi.codeStyle.CodeStyleSettingsManager;
|
||||
import com.intellij.psi.codeStyle.Indent;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.text.CharArrayUtil;
|
||||
import com.intellij.ide.PasteProvider;
|
||||
import com.intellij.ide.actions.CopyReferenceAction;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
@@ -39,6 +40,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.editorActions.PasteHandler");
|
||||
|
||||
private EditorActionHandler myOriginalHandler;
|
||||
private final PasteProvider myPasteReferenceProvider = new CopyReferenceAction.MyPasteProvider();
|
||||
|
||||
public PasteHandler(EditorActionHandler originalAction) {
|
||||
myOriginalHandler = originalAction;
|
||||
@@ -53,8 +55,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
final Project project = (Project)DataManager.getInstance().getDataContext(editor.getComponent()).getData(
|
||||
DataConstants.PROJECT);
|
||||
final Project project = editor.getProject();
|
||||
if (project == null || editor.isColumnMode()) {
|
||||
if (myOriginalHandler != null) {
|
||||
myOriginalHandler.execute(editor, dataContext);
|
||||
@@ -83,7 +84,12 @@ public class PasteHandler extends EditorActionHandler {
|
||||
|
||||
document.startGuardedBlockChecking();
|
||||
try {
|
||||
doPaste(editor, project, file, fileType, document);
|
||||
if (myPasteReferenceProvider.isPasteEnabled(dataContext)) {
|
||||
myPasteReferenceProvider.performPaste(dataContext);
|
||||
}
|
||||
else {
|
||||
doPaste(editor, project, file, fileType, document);
|
||||
}
|
||||
}
|
||||
catch (ReadOnlyFragmentModificationException e) {
|
||||
EditorActionManager.getInstance().getReadonlyFragmentModificationHandler().handle(e);
|
||||
@@ -252,7 +258,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private String escapeIfStringLiteral(final Project project,
|
||||
private static String escapeIfStringLiteral(final Project project,
|
||||
final PsiFile file,
|
||||
final Editor editor,
|
||||
String text) {
|
||||
@@ -262,8 +268,8 @@ public class PasteHandler extends EditorActionHandler {
|
||||
int caretOffset = editor.getCaretModel().getOffset();
|
||||
PsiElement elementAtCaret = file.findElementAt(caretOffset);
|
||||
if (elementAtCaret instanceof PsiJavaToken &&
|
||||
(((PsiJavaToken)elementAtCaret)).getTokenType() == JavaTokenType.STRING_LITERAL &&
|
||||
caretOffset > elementAtCaret.getTextOffset()) {
|
||||
((PsiJavaToken)elementAtCaret).getTokenType() == JavaTokenType.STRING_LITERAL &&
|
||||
caretOffset > elementAtCaret.getTextOffset()) {
|
||||
StringBuffer buffer = new StringBuffer(text.length());
|
||||
CodeStyleSettings codeStyleSettings = CodeStyleSettingsManager.getSettings(project);
|
||||
String breaker = codeStyleSettings.BINARY_OPERATION_SIGN_ON_NEXT_LINE ? "\\n\"\n+ \"" : "\\n\" +\n\"";
|
||||
@@ -278,7 +284,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
return text;
|
||||
}
|
||||
|
||||
private PsiJavaCodeReferenceElement[] findReferencesToRestore(PsiFile file,
|
||||
private static PsiJavaCodeReferenceElement[] findReferencesToRestore(PsiFile file,
|
||||
RangeMarker bounds,
|
||||
TextBlockTransferable.ReferenceData[] referenceData) {
|
||||
PsiManager manager = file.getManager();
|
||||
@@ -318,7 +324,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
return refs;
|
||||
}
|
||||
|
||||
private void restoreReferences(TextBlockTransferable.ReferenceData[] referenceData,
|
||||
private static void restoreReferences(TextBlockTransferable.ReferenceData[] referenceData,
|
||||
PsiJavaCodeReferenceElement[] refs) {
|
||||
for (int i = 0; i < refs.length; i++) {
|
||||
PsiJavaCodeReferenceElement reference = refs[i];
|
||||
@@ -341,7 +347,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void indentBlock(Project project, Editor editor, int startOffset, int endOffset, int originalCaretCol) {
|
||||
private static void indentBlock(Project project, Editor editor, int startOffset, int endOffset, int originalCaretCol) {
|
||||
Document document = editor.getDocument();
|
||||
CharSequence chars = document.getCharsSequence();
|
||||
|
||||
@@ -375,7 +381,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void indentEachLine(Project project, Editor editor, int startOffset, int endOffset) {
|
||||
private static void indentEachLine(Project project, Editor editor, int startOffset, int endOffset) {
|
||||
Document document = editor.getDocument();
|
||||
CharSequence chars = document.getCharsSequence();
|
||||
endOffset = CharArrayUtil.shiftBackward(chars, endOffset - 1, "\n\r") + 1;
|
||||
@@ -406,7 +412,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void reformatBlock(Project project, Editor editor, int startOffset, int endOffset) {
|
||||
private static void reformatBlock(Project project, Editor editor, int startOffset, int endOffset) {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
|
||||
|
||||
@@ -418,12 +424,12 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void adjustBlockIndent(Project project, Document document, PsiFile file, int startOffset, int endOffset) {
|
||||
private static void adjustBlockIndent(Project project, Document document, PsiFile file, int startOffset, int endOffset) {
|
||||
final FileType fileType = file.getFileType();
|
||||
indentJavaBlock(project, document, startOffset, endOffset, file, fileType);
|
||||
}
|
||||
|
||||
private void indentPlainTextBlock(Document document, int startOffset, int endOffset, int originalCaretColumn) {
|
||||
private static void indentPlainTextBlock(Document document, int startOffset, int endOffset, int originalCaretColumn) {
|
||||
CharSequence chars = document.getCharsSequence();
|
||||
int spaceEnd = CharArrayUtil.shiftForward(chars, startOffset, " \t");
|
||||
if (spaceEnd > endOffset) return;
|
||||
@@ -444,7 +450,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private void indentJavaBlock(Project project, Document document,
|
||||
private static void indentJavaBlock(Project project, Document document,
|
||||
int startOffset,
|
||||
int endOffset,
|
||||
PsiFile file,
|
||||
@@ -573,7 +579,6 @@ public class PasteHandler extends EditorActionHandler {
|
||||
PsiJavaCodeReferenceElement ref = refs[i];
|
||||
if (ref != null) {
|
||||
LOG.assertTrue(ref.isValid());
|
||||
TextBlockTransferable.ReferenceData data = referenceData[i];
|
||||
Object refObject = refObjects[i];
|
||||
boolean found = false;
|
||||
for (int j = 0; j < selectedObjects.length; j++) {
|
||||
@@ -590,7 +595,7 @@ public class PasteHandler extends EditorActionHandler {
|
||||
}
|
||||
}
|
||||
|
||||
private String getFQName(Object element) {
|
||||
private static String getFQName(Object element) {
|
||||
return element instanceof PsiClass ? ((PsiClass)element).getQualifiedName() : (String)element;
|
||||
}
|
||||
}
|
||||
@@ -3,26 +3,43 @@
|
||||
*/
|
||||
package com.intellij.ide.actions;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.ide.CopyPasteManagerEx;
|
||||
import com.intellij.ide.PasteProvider;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataConstants;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.EditorModificationUtil;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
import com.intellij.openapi.editor.colors.EditorColors;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.markup.TextAttributes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.wm.ex.StatusBarEx;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.WindowManager;
|
||||
import com.intellij.openapi.wm.ex.StatusBarEx;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.codeStyle.CodeStyleManager;
|
||||
import com.intellij.psi.impl.source.codeStyle.CodeStyleManagerEx;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import com.intellij.ide.util.PropertiesComponent;
|
||||
import com.intellij.codeInsight.highlighting.HighlightManager;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.IOException;
|
||||
|
||||
public class CopyReferenceAction extends AnAction {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.actions.CopyReferenceAction");
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
Editor editor = (Editor)dataContext.getData(DataConstants.EDITOR);
|
||||
@@ -37,21 +54,196 @@ public class CopyReferenceAction extends AnAction {
|
||||
PsiFile file = PsiDocumentManager.getInstance(project).getPsiFile(editor.getDocument());
|
||||
PsiElement element = file.findElementAt(editor.getCaretModel().getOffset());
|
||||
|
||||
PsiMember member = PsiTreeUtil.getParentOfType(element, PsiMember.class);
|
||||
String fqn;
|
||||
fqn = elementToFqn(member);
|
||||
PropertiesComponent.getInstance(project).setValue("REFERENCE_FQN",fqn);
|
||||
if (!(element instanceof PsiIdentifier)) return;
|
||||
final PsiElement parent = element.getParent();
|
||||
PsiMember member = null;
|
||||
if (parent instanceof PsiReferenceExpression) {
|
||||
PsiElement resolved = ((PsiReferenceExpression)parent).resolve();
|
||||
if (resolved instanceof PsiMember) {
|
||||
member = (PsiMember)resolved;
|
||||
}
|
||||
}
|
||||
else if (parent instanceof PsiMember) {
|
||||
member = (PsiMember)parent;
|
||||
}
|
||||
else {
|
||||
//todo show error
|
||||
return;
|
||||
}
|
||||
|
||||
if (member != null) {
|
||||
doCopy(member, project);
|
||||
|
||||
HighlightManager highlightManager = HighlightManager.getInstance(project);
|
||||
EditorColorsManager manager = EditorColorsManager.getInstance();
|
||||
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
|
||||
highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{element}, attributes, true, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static void doCopy(final PsiElement element, final Project project) {
|
||||
String fqn = elementToFqn(element);
|
||||
|
||||
CopyPasteManagerEx.getInstance().setContents(new MyTransferable(fqn));
|
||||
|
||||
final StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(project);
|
||||
statusBar.setInfo("Reference to '"+fqn+"' has been copied.");
|
||||
}
|
||||
|
||||
HighlightManager highlightManager = HighlightManager.getInstance(project);
|
||||
EditorColorsManager manager = EditorColorsManager.getInstance();
|
||||
TextAttributes attributes = manager.getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
|
||||
PsiIdentifier nameIdentifier = member instanceof PsiClass ? ((PsiClass)member).getNameIdentifier() :
|
||||
member instanceof PsiVariable ? ((PsiVariable)member).getNameIdentifier() :
|
||||
((PsiMethod)member).getNameIdentifier();
|
||||
highlightManager.addOccurrenceHighlights(editor, new PsiElement[]{nameIdentifier}, attributes, true, null);
|
||||
private static void insert(final String fqn, final PsiNamedElement element, final Editor editor) {
|
||||
final PsiFile file = PsiDocumentManager.getInstance(editor.getProject()).getPsiFile(editor.getDocument());
|
||||
if (!CodeInsightUtil.prepareFileForWrite(file)) return;
|
||||
|
||||
final Project project = editor.getProject();
|
||||
CommandProcessor.getInstance().executeCommand(project, new Runnable() {
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
doInsert(fqn, element, editor, project);
|
||||
|
||||
}
|
||||
catch (IncorrectOperationException e1) {
|
||||
LOG.error(e1);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}, "Pasting reference", null);
|
||||
|
||||
final StatusBarEx statusBar = (StatusBarEx)WindowManager.getInstance().getStatusBar(project);
|
||||
statusBar.setInfo("Reference to '"+fqn+"' has been pasted.");
|
||||
}
|
||||
|
||||
private static void doInsert(String fqn,
|
||||
PsiNamedElement element,
|
||||
final Editor editor,
|
||||
final Project project) throws IncorrectOperationException {
|
||||
final PsiDocumentManager documentManager = PsiDocumentManager.getInstance(project);
|
||||
Document document = editor.getDocument();
|
||||
final PsiFile file = documentManager.getPsiFile(document);
|
||||
|
||||
final int offset = editor.getCaretModel().getOffset();
|
||||
fqn = fqn.replace('#', '.');
|
||||
String toInsert = element.getName();
|
||||
String suffix = "";
|
||||
if (element instanceof PsiClass) {
|
||||
suffix = " ";
|
||||
}
|
||||
else if (element instanceof PsiMethod) {
|
||||
suffix = "()";
|
||||
}
|
||||
final PsiElementFactory factory = PsiManager.getInstance(project).getElementFactory();
|
||||
final PsiExpression expression = factory.createExpressionFromText(toInsert+suffix, file.findElementAt(offset));
|
||||
final PsiReferenceExpression referenceExpression=expression instanceof PsiMethodCallExpression ?
|
||||
((PsiMethodCallExpression)expression).getMethodExpression() : expression instanceof PsiReferenceExpression ?
|
||||
(PsiReferenceExpression)expression : null;
|
||||
if (referenceExpression == null || referenceExpression.advancedResolve(true).getElement() != element) {
|
||||
toInsert = fqn;
|
||||
}
|
||||
|
||||
document.insertString(offset, toInsert+suffix);
|
||||
documentManager.commitDocument(document);
|
||||
int endOffset = offset + toInsert.length() + suffix.length();
|
||||
RangeMarker rangeMarker = document.createRangeMarker(endOffset, endOffset);
|
||||
PsiElement elementAt = file.findElementAt(offset);
|
||||
|
||||
shortenReference(elementAt);
|
||||
CodeStyleManager.getInstance(project).adjustLineIndent(file, offset);
|
||||
|
||||
int caretOffset = rangeMarker.getEndOffset();
|
||||
if (element instanceof PsiMethod) {
|
||||
caretOffset --;
|
||||
}
|
||||
editor.getCaretModel().moveToOffset(caretOffset);
|
||||
}
|
||||
|
||||
private static void shortenReference(PsiElement element) throws IncorrectOperationException {
|
||||
if (element == null) return;
|
||||
while (element.getParent() instanceof PsiJavaCodeReferenceElement) {
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
final CodeStyleManagerEx codeStyleManagerEx = (CodeStyleManagerEx)CodeStyleManager.getInstance(element.getManager().getProject());
|
||||
codeStyleManagerEx.shortenClassReferences(element, CodeStyleManagerEx.UNCOMPLETE_CODE);
|
||||
}
|
||||
|
||||
public static class MyPasteProvider implements PasteProvider {
|
||||
public void performPaste(DataContext dataContext) {
|
||||
final Project project = (Project)dataContext.getData(DataConstants.PROJECT);
|
||||
final Editor editor = (Editor)dataContext.getData(DataConstants.EDITOR);
|
||||
if (project == null || editor == null) return;
|
||||
|
||||
final String fqn = getCopiedFqn();
|
||||
PsiMember member = CopyReferenceAction.fqnToMember(project, fqn);
|
||||
insert(fqn, (PsiNamedElement)member, editor);
|
||||
|
||||
if (editor.getSelectionModel().hasSelection()) {
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
public void run() {
|
||||
EditorModificationUtil.deleteSelectedText(editor);
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isPastePossible(DataContext dataContext) {
|
||||
return isPasteEnabled(dataContext);
|
||||
}
|
||||
|
||||
public boolean isPasteEnabled(DataContext dataContext) {
|
||||
final Project project = (Project)dataContext.getData(DataConstants.PROJECT);
|
||||
final Editor editor = (Editor)dataContext.getData(DataConstants.EDITOR);
|
||||
if (project == null || editor == null) return false;
|
||||
return getCopiedFqn() != null;
|
||||
}
|
||||
}
|
||||
|
||||
private static String getCopiedFqn() {
|
||||
final Transferable contents = CopyPasteManagerEx.getInstance().getContents();
|
||||
if (contents == null) return null;
|
||||
try {
|
||||
final String fqn = (String)contents.getTransferData(OUR_DATA_FLAVOR);
|
||||
return fqn;
|
||||
}
|
||||
catch (UnsupportedFlavorException e) {
|
||||
}
|
||||
catch (IOException e) {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static final DataFlavor OUR_DATA_FLAVOR;
|
||||
static {
|
||||
try {
|
||||
OUR_DATA_FLAVOR = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" + MyTransferable.class.getName());
|
||||
}
|
||||
catch (ClassNotFoundException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyTransferable implements Transferable {
|
||||
private final String fqn;
|
||||
|
||||
public MyTransferable(String fqn) {
|
||||
this.fqn = fqn;
|
||||
}
|
||||
|
||||
public DataFlavor[] getTransferDataFlavors() {
|
||||
return new DataFlavor[]{OUR_DATA_FLAVOR};
|
||||
}
|
||||
|
||||
public boolean isDataFlavorSupported(DataFlavor flavor) {
|
||||
return OUR_DATA_FLAVOR.equals(flavor);
|
||||
}
|
||||
|
||||
public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
|
||||
if (!isDataFlavorSupported(flavor)) return null;
|
||||
return fqn;
|
||||
}
|
||||
}
|
||||
|
||||
public static String elementToFqn(final PsiElement element) {
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package com.intellij.ide.util.gotoByName;
|
||||
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.ide.actions.CopyReferenceAction;
|
||||
import com.intellij.ide.actions.PasteReferenceAction;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsManager;
|
||||
import com.intellij.openapi.editor.colors.EditorColorsScheme;
|
||||
import com.intellij.openapi.keymap.KeymapManager;
|
||||
@@ -29,6 +26,7 @@ import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
import javax.swing.text.DefaultEditorKit;
|
||||
import java.awt.*;
|
||||
import java.awt.event.*;
|
||||
import java.util.*;
|
||||
@@ -74,7 +72,6 @@ public abstract class ChooseByNameBase{
|
||||
private static final String NOT_FOUND_CARD = "nfound";
|
||||
private static final String CHECK_BOX_CARD = "chkbox";
|
||||
static final int REBUILD_DELAY = 100;
|
||||
private Editor myEditor;
|
||||
|
||||
private static class IgnoreCaseComparator implements Comparator<String> {
|
||||
public int compare(String a, String b) {
|
||||
@@ -216,18 +213,18 @@ public abstract class ChooseByNameBase{
|
||||
myTextField = new MyTextField();
|
||||
myTextField.setText(myInitialText);
|
||||
|
||||
myEditor = (Editor)DataManager.getInstance().getDataContext(myPreviouslyFocusedComponent).getData(DataConstants.EDITOR);
|
||||
if (myEditor != null) {
|
||||
myTextField.setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.EMPTY_SET);
|
||||
/* TODO[max, cdr]: to discuss.
|
||||
final JPanel p = new JPanel(new BorderLayout());
|
||||
final JLabel label = new JLabel("<html><body><center>Press <b>TAB</b> to paste the reference into editor.</center></body></html>");
|
||||
label.setHorizontalAlignment(SwingConstants.CENTER);
|
||||
p.add(label, BorderLayout.CENTER);
|
||||
myTextFieldPanel.add(p);
|
||||
*/
|
||||
}
|
||||
|
||||
final ActionMap actionMap = new ActionMap();
|
||||
actionMap.setParent(myTextField.getActionMap());
|
||||
actionMap.put(DefaultEditorKit.copyAction, new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
final Object chosenElement = getChosenElement();
|
||||
if (chosenElement instanceof PsiElement) {
|
||||
CopyReferenceAction.doCopy((PsiElement)chosenElement, myProject);
|
||||
}
|
||||
}
|
||||
});
|
||||
myTextField.setActionMap(actionMap);
|
||||
|
||||
myTextFieldPanel.add(myTextField);
|
||||
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
|
||||
Font editorFont = new Font(scheme.getEditorFontName(), Font.PLAIN, scheme.getEditorFontSize());
|
||||
@@ -266,9 +263,6 @@ public abstract class ChooseByNameBase{
|
||||
}
|
||||
final int keyCode = e.getKeyCode();
|
||||
switch (keyCode) {
|
||||
case KeyEvent.VK_TAB:
|
||||
insertElement();
|
||||
break;
|
||||
case KeyEvent.VK_DOWN:
|
||||
ListScrollingUtilEx.moveDown(myList, e.getModifiersEx());
|
||||
break;
|
||||
@@ -347,16 +341,6 @@ public abstract class ChooseByNameBase{
|
||||
}
|
||||
}
|
||||
|
||||
private void insertElement() {
|
||||
final Object chosenElement = getChosenElement();
|
||||
if (!(chosenElement instanceof PsiElement)) return;
|
||||
if (myEditor == null) return;
|
||||
final PsiElement element = (PsiElement)chosenElement;
|
||||
final String fqn = CopyReferenceAction.elementToFqn(element);
|
||||
PasteReferenceAction.doInsert(fqn, element, myEditor);
|
||||
close(false);
|
||||
}
|
||||
|
||||
private synchronized void ensureNamesLoaded(boolean checkboxState) {
|
||||
int index = checkboxState ? 1 : 0;
|
||||
if (myNames[index] != null) return;
|
||||
@@ -403,7 +387,7 @@ public abstract class ChooseByNameBase{
|
||||
(10, (paneHeight - (y + preferredTextFieldPanelSize.height)) / (preferredTextFieldPanelSize.height / 2) - 1);
|
||||
|
||||
// I'm registering KeyListener to close popup only by KeyTyped event.
|
||||
// If react on KeyPressed then sometime KeyTyped goes into underlying myEditor.
|
||||
// If react on KeyPressed then sometime KeyTyped goes into underlying editor.
|
||||
// It causes typing of Enter into it.
|
||||
myTextFieldPanel.registerKeyboardAction(new AbstractAction() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package com.intellij.openapi.editor.impl;
|
||||
|
||||
import com.intellij.Patches;
|
||||
import com.intellij.codeInsight.hint.DocumentFragmentTooltipRenderer;
|
||||
import com.intellij.codeInsight.hint.HintManager;
|
||||
import com.intellij.codeInsight.hint.TooltipController;
|
||||
import com.intellij.codeInsight.hint.TooltipGroup;
|
||||
import com.intellij.codeInsight.hint.DocumentFragmentTooltipRenderer;
|
||||
import com.intellij.ide.*;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.DataConstants;
|
||||
@@ -59,6 +59,7 @@ import java.text.AttributedString;
|
||||
import java.text.CharacterIterator;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Map;
|
||||
import java.util.TooManyListenersException;
|
||||
|
||||
public class EditorImpl implements EditorEx {
|
||||
@@ -88,8 +89,8 @@ public class EditorImpl implements EditorEx {
|
||||
private final CaretCursor myCaretCursor;
|
||||
private final ScrollingTimer myScrollingTimer = new ScrollingTimer();
|
||||
|
||||
private final Object MOUSE_DRAGGED_GROUP = Key.create("MouseDraggedGroup");
|
||||
private final THashMap<Object, Object> myUserDataMap = new THashMap<Object, Object>();
|
||||
private final Key<Object> MOUSE_DRAGGED_GROUP = Key.create("MouseDraggedGroup");
|
||||
private final Map<Object, Object> myUserDataMap = new THashMap<Object, Object>();
|
||||
|
||||
private final DocumentListener myEditorDocumentAdapter;
|
||||
|
||||
@@ -909,7 +910,7 @@ public class EditorImpl implements EditorEx {
|
||||
myScrollPane.getViewport().setViewSize(myPreferredSize);
|
||||
int lineNum = Math.max(1, getDocument().getLineCount());
|
||||
|
||||
myGutterComponent.setLineNumberAreaWidth(getFontMetrics(Font.PLAIN).stringWidth(Integer.toString((lineNum + 2))) + 6);
|
||||
myGutterComponent.setLineNumberAreaWidth(getFontMetrics(Font.PLAIN).stringWidth(Integer.toString(lineNum + 2)) + 6);
|
||||
final JViewport rowHeader = myScrollPane.getRowHeader();
|
||||
if (rowHeader != null) {
|
||||
rowHeader.setViewSize(myGutterComponent.getPreferredSize());
|
||||
|
||||
+1
-2
@@ -1,6 +1,5 @@
|
||||
package com.intellij.dupLocator.util;
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
|
||||
/**
|
||||
@@ -31,7 +31,7 @@
|
||||
*/
|
||||
package com.intellij.psi.impl.smartPointers;
|
||||
|
||||
import com.intellij.dupLocator.util.PsiAnchor;
|
||||
import com.intellij.psi.PsiAnchor;
|
||||
import com.intellij.psi.*;
|
||||
|
||||
public class LazyPointerImpl implements SmartPointerEx {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package com.intellij.refactoring.typeCook.deductive.builder;
|
||||
|
||||
import com.intellij.dupLocator.util.PsiAnchor;
|
||||
import com.intellij.psi.PsiAnchor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.psi.*;
|
||||
|
||||
Reference in New Issue
Block a user