mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Cleanup (common code; formatting)
This commit is contained in:
+9
-25
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.SelectInManager;
|
||||
@@ -26,10 +25,9 @@ import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
@@ -51,33 +49,19 @@ public class FavoritesViewSelectInTarget extends SelectInTargetPsiWrapper {
|
||||
|
||||
@Override
|
||||
protected void select(Object selector, VirtualFile virtualFile, boolean requestFocus) {
|
||||
select(myProject, selector, null, null, virtualFile, requestFocus);
|
||||
select(myProject, selector, virtualFile, requestFocus);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void select(PsiElement element, boolean requestFocus) {
|
||||
PsiElement toSelect = null;
|
||||
if (element instanceof PsiFile || element instanceof PsiDirectory) {
|
||||
toSelect = element;
|
||||
PsiElement toSelect = findElementToSelect(element, null);
|
||||
if (toSelect != null) {
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(toSelect);
|
||||
select(toSelect, virtualFile, requestFocus);
|
||||
}
|
||||
else {
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile == null) return;
|
||||
final FileViewProvider viewProvider = containingFile.getViewProvider();
|
||||
toSelect = viewProvider.getPsi(viewProvider.getBaseLanguage());
|
||||
}
|
||||
if (toSelect == null) return;
|
||||
PsiElement originalElement = toSelect.getOriginalElement();
|
||||
final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(originalElement);
|
||||
select(originalElement, virtualFile, requestFocus);
|
||||
}
|
||||
|
||||
public static ActionCallback select(@NotNull Project project,
|
||||
final Object toSelect,
|
||||
@Nullable final String viewId,
|
||||
@Nullable final String subviewId,
|
||||
final VirtualFile virtualFile,
|
||||
final boolean requestFocus) {
|
||||
private static ActionCallback select(@NotNull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
|
||||
@@ -127,4 +111,4 @@ public class FavoritesViewSelectInTarget extends SelectInTargetPsiWrapper {
|
||||
protected boolean canWorkWithCustomObjects() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,7 +13,6 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.impl;
|
||||
|
||||
import com.intellij.ide.CompositeSelectInTarget;
|
||||
@@ -27,15 +26,15 @@ import com.intellij.ide.projectView.impl.ProjectViewPane;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.project.DumbService;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilBase;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -65,7 +64,6 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
|
||||
final boolean requestFocus) {
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
|
||||
final ProjectView projectView = ProjectView.getInstance(project);
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
AbstractProjectViewPane pane = projectView.getProjectViewPaneById(ProjectViewPane.ID);
|
||||
@@ -95,7 +93,6 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public Collection<SelectInTarget> getSubTargets(@NotNull SelectInContext context) {
|
||||
@@ -131,27 +128,13 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
|
||||
}
|
||||
if (toSelect != null) break;
|
||||
}
|
||||
if (toSelect == null) {
|
||||
if (element instanceof PsiFile || element instanceof PsiDirectory) {
|
||||
toSelect = element;
|
||||
}
|
||||
else {
|
||||
final PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile == null) return;
|
||||
final FileViewProvider viewProvider = containingFile.getViewProvider();
|
||||
toSelect = viewProvider.getPsi(viewProvider.getBaseLanguage());
|
||||
}
|
||||
|
||||
toSelect = findElementToSelect(element, toSelect);
|
||||
|
||||
if (toSelect != null) {
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(toSelect);
|
||||
select(toSelect, virtualFile, requestFocus);
|
||||
}
|
||||
if (toSelect == null) return;
|
||||
PsiElement originalElement;
|
||||
try {
|
||||
originalElement = toSelect.getOriginalElement();
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
originalElement = toSelect;
|
||||
}
|
||||
final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(originalElement);
|
||||
select(originalElement, virtualFile, requestFocus);
|
||||
}
|
||||
|
||||
private TreeStructureProvider[] getProvidersDumbAware() {
|
||||
@@ -177,4 +160,4 @@ public abstract class ProjectViewSelectInTarget extends SelectInTargetPsiWrapper
|
||||
public final String getSubId() {
|
||||
return mySubId;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -13,20 +13,19 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.intellij.ide.impl;
|
||||
|
||||
import com.intellij.ide.SelectInContext;
|
||||
import com.intellij.ide.SelectInTarget;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
|
||||
public abstract class SelectInTargetPsiWrapper implements SelectInTarget {
|
||||
protected final Project myProject;
|
||||
|
||||
@@ -99,4 +98,35 @@ public abstract class SelectInTargetPsiWrapper implements SelectInTarget {
|
||||
protected abstract boolean canWorkWithCustomObjects();
|
||||
|
||||
protected abstract void select(PsiElement element, boolean requestFocus);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
protected static PsiElement findElementToSelect(PsiElement element, PsiElement candidate) {
|
||||
PsiElement toSelect = candidate;
|
||||
|
||||
if (toSelect == null) {
|
||||
if (element instanceof PsiFile || element instanceof PsiDirectory) {
|
||||
toSelect = element;
|
||||
}
|
||||
else {
|
||||
PsiFile containingFile = element.getContainingFile();
|
||||
if (containingFile != null) {
|
||||
FileViewProvider viewProvider = containingFile.getViewProvider();
|
||||
toSelect = viewProvider.getPsi(viewProvider.getBaseLanguage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (toSelect != null) {
|
||||
PsiElement originalElement = null;
|
||||
try {
|
||||
originalElement = toSelect.getOriginalElement();
|
||||
}
|
||||
catch (IndexNotReadyException ignored) { }
|
||||
if (originalElement != null) {
|
||||
toSelect = originalElement;
|
||||
}
|
||||
}
|
||||
|
||||
return toSelect;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user