mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-10-01 19:02:13 +07:00
IDEA-206431: add SelectInContext.selectIn method
This commit is contained in:
+1
-5
@@ -50,10 +50,6 @@ public class FavoritesAutoscrollFromSourceHandler extends AutoScrollFromSourceHa
|
||||
protected void selectElementFromEditor(@NotNull FileEditor editor) {
|
||||
VirtualFile file = FileEditorManagerEx.getInstanceEx(myProject).getFile(editor);
|
||||
PsiFile psiFile = file == null ? null : PsiManager.getInstance(myProject).findFile(file);
|
||||
if (psiFile == null) return;
|
||||
FileEditorSelectInContext context = new FileEditorSelectInContext(editor, psiFile);
|
||||
if (mySelectInTarget.canSelect(context)) {
|
||||
mySelectInTarget.selectIn(context, false);
|
||||
}
|
||||
if (psiFile != null) new FileEditorSelectInContext(editor, psiFile).selectIn(mySelectInTarget, false);
|
||||
}
|
||||
}
|
||||
@@ -48,7 +48,9 @@ public class ProjectViewSelectInGroupTarget implements CompositeSelectInTarget,
|
||||
}
|
||||
}
|
||||
targetsToCheck.addAll(targets);
|
||||
targetsToCheck.stream().filter(t -> t.canSelect(context)).findFirst().ifPresent(target -> target.selectIn(context, requestFocus));
|
||||
for (SelectInTarget target : targetsToCheck) {
|
||||
if (context.selectIn(target, requestFocus)) break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1978,8 +1978,8 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
|
||||
|
||||
void selectInCurrentTarget() {
|
||||
SelectInTarget target = getCurrentSelectInTarget();
|
||||
if (target != null && getPsiFile() != null && target.canSelect(this)) {
|
||||
target.selectIn(this, false);
|
||||
if (target != null && getPsiFile() != null) {
|
||||
selectIn(target, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -38,4 +38,15 @@ public interface SelectInContext {
|
||||
|
||||
@Nullable
|
||||
FileEditorProvider getFileEditorProvider();
|
||||
|
||||
/**
|
||||
* @param target an object that supports a context selection
|
||||
* @param requestFocus specifies whether a focus request is needed or not
|
||||
* @return {@code true} if a selection request is approved and executed by the given target
|
||||
*/
|
||||
default boolean selectIn(@NotNull SelectInTarget target, boolean requestFocus) {
|
||||
if (!target.canSelect(this)) return false;
|
||||
target.selectIn(this, requestFocus);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -167,10 +167,7 @@ public class OpenFileDescriptor implements Navigatable, Comparable<OpenFileDescr
|
||||
private boolean navigateInProjectView(boolean requestFocus) {
|
||||
SelectInContext context = new FileSelectInContext(myProject, myFile, null);
|
||||
for (SelectInTarget target : SelectInManager.getInstance(myProject).getTargets()) {
|
||||
if (target.canSelect(context)) {
|
||||
target.selectIn(context, requestFocus);
|
||||
return true;
|
||||
}
|
||||
if (context.selectIn(target, requestFocus)) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user