mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
selectIn favorites view + send to favorites
This commit is contained in:
@@ -19,7 +19,7 @@
|
||||
<group id="AddToFavorites" popup="true" text="_Add To Favorites"/>
|
||||
<action id="AddNewFavoritesList" class="com.intellij.ide.favoritesTreeView.AddNewFavoritesListAction" text="Add New Favorites List" description="Add New Favorites List" internal="true"/>
|
||||
<action id="RemoveFavoritesList" class="com.intellij.ide.favoritesTreeView.RemoveFavoritesListAction" text="Remove Favorites List" description="REmove Favorites List" internal="true"/>
|
||||
<group id="SendToFavoritesGroup" popup="true" text="_Send Favorites"/>
|
||||
<group id="SendToFavoritesGroup" class="com.intellij.ide.favoritesTreeView.SendToFavoritesGroup" popup="true" text="_Send Favorites"/>
|
||||
<group id="RunContextGroup" popup="false">
|
||||
<action id="CreateRunConfiguration" text="Create Run Configuration" description="Create run configuration from context" class="com.intellij.execution.actions.CreateAction"/>
|
||||
</group>
|
||||
|
||||
@@ -21,6 +21,8 @@ import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.uiDesigner.compiler.Utils;
|
||||
@@ -47,11 +49,16 @@ public class AddToFavoritesAction extends AnAction {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = (Project)dataContext.getData(DataConstants.PROJECT);
|
||||
final AbstractTreeNode[] nodes = createNodes(dataContext);
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(project);
|
||||
if (nodes != null) {
|
||||
final FavoritesTreeViewPanel favoritesTreeViewPanel = favoritesView.getFavoritesTreeViewPanel(myFavoritesList);
|
||||
for (int i = 0; i < nodes.length; i++) {
|
||||
AbstractTreeNode node = nodes[i];
|
||||
FavoritesViewImpl.getInstance(project).getFavoritesTreeViewPanel(myFavoritesList).addToFavorites(node);
|
||||
favoritesTreeViewPanel.addToFavorites(node);
|
||||
}
|
||||
final ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
|
||||
windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW).activate(null);
|
||||
favoritesView.setSelectedContent(favoritesView.getContent(favoritesTreeViewPanel));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,14 +73,10 @@ public class AddToFavoritesAction extends AnAction {
|
||||
}
|
||||
}
|
||||
|
||||
protected boolean isEnabled() {
|
||||
return false; //To change body of implemented methods use File | Settings | File Templates.
|
||||
}
|
||||
|
||||
private AbstractTreeNode[] createNodes(DataContext dataContext) {
|
||||
ArrayList<AbstractTreeNode> result = new ArrayList<AbstractTreeNode>();
|
||||
Project project = (Project)dataContext.getData(DataConstants.PROJECT);
|
||||
final FavoritesTreeViewConfiguration favoritesConfig = FavoritesViewImpl.getInstance(project).getCurrentTreeViewPanel().getFavoritesTreeStructure().getFavoritesConfiguration();
|
||||
final FavoritesTreeViewConfiguration favoritesConfig = FavoritesViewImpl.getInstance(project).getFavoritesTreeViewPanel(myFavoritesList).getFavoritesTreeStructure().getFavoritesConfiguration();
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
|
||||
final String currentViewId = ProjectView.getInstance(project).getCurrentViewId();
|
||||
|
||||
@@ -21,22 +21,29 @@ public class DeleteFromFavoritesAction extends AnAction {
|
||||
return;
|
||||
}
|
||||
if (e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_POPUP) || e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_TOOLBAR)) {
|
||||
FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesViewImpl.getInstance(project).getCurrentTreeViewPanel()
|
||||
final FavoritesTreeViewPanel currentTreeViewPanel = FavoritesViewImpl.getInstance(project).getCurrentTreeViewPanel();
|
||||
FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = currentTreeViewPanel
|
||||
.getSelectedNodeDescriptors();
|
||||
for (int i = 0; i < selectedNodeDescriptors.length; i++) {
|
||||
FavoritesTreeNodeDescriptor selectedNodeDescriptor = selectedNodeDescriptors[i];
|
||||
selectedNodeDescriptor = getFavoritesRoot(selectedNodeDescriptor, project);
|
||||
if (selectedNodeDescriptor != null) {
|
||||
FavoritesViewImpl.getInstance(project).getCurrentTreeViewPanel().removeFromFavorites((AbstractTreeNode)selectedNodeDescriptor.getElement());
|
||||
}
|
||||
removeNodes(selectedNodeDescriptors, project, currentTreeViewPanel.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void removeNodes(final FavoritesTreeNodeDescriptor[] selectedNodeDescriptors, final Project project, String favoritesViewPane) {
|
||||
final FavoritesTreeViewPanel favoritesTreeViewPanel = FavoritesViewImpl.getInstance(project).getFavoritesTreeViewPanel(favoritesViewPane);
|
||||
for (int i = 0; selectedNodeDescriptors != null && i < selectedNodeDescriptors.length; i++) {
|
||||
FavoritesTreeNodeDescriptor selectedNodeDescriptor = selectedNodeDescriptors[i];
|
||||
selectedNodeDescriptor = getFavoritesRoot(selectedNodeDescriptor, project, favoritesViewPane);
|
||||
if (selectedNodeDescriptor != null) {
|
||||
favoritesTreeViewPanel.removeFromFavorites((AbstractTreeNode)selectedNodeDescriptor.getElement());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private FavoritesTreeNodeDescriptor getFavoritesRoot(FavoritesTreeNodeDescriptor node, Project project) {
|
||||
private FavoritesTreeNodeDescriptor getFavoritesRoot(FavoritesTreeNodeDescriptor node, Project project, String favoritesViewPane) {
|
||||
final FavoritesTreeViewPanel favoritesTreeViewPanel = FavoritesViewImpl.getInstance(project).getFavoritesTreeViewPanel(favoritesViewPane);
|
||||
while (node.getParentDescriptor() != null && node.getParentDescriptor() instanceof FavoritesTreeNodeDescriptor) {
|
||||
FavoritesTreeNodeDescriptor favoritesDescriptor = (FavoritesTreeNodeDescriptor)node.getParentDescriptor();
|
||||
if (favoritesDescriptor.getElement() == FavoritesViewImpl.getInstance(project).getCurrentTreeViewPanel().getFavoritesTreeStructure().getRootElement()) {
|
||||
if (favoritesDescriptor.getElement() == favoritesTreeViewPanel.getFavoritesTreeStructure().getRootElement()) {
|
||||
return node;
|
||||
}
|
||||
node = favoritesDescriptor;
|
||||
|
||||
@@ -3,7 +3,7 @@ package com.intellij.ide.favoritesTreeView;
|
||||
import com.intellij.ide.projectView.PresentationData;
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.impl.*;
|
||||
import com.intellij.ide.projectView.impl.nodes.FormNode;
|
||||
import com.intellij.ide.projectView.impl.nodes.*;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.j2ee.module.components.J2EEModuleUrl;
|
||||
@@ -15,11 +15,17 @@ import com.intellij.j2ee.module.view.web.FilterUrl;
|
||||
import com.intellij.j2ee.module.view.web.ListenerUrl;
|
||||
import com.intellij.j2ee.module.view.web.ServletUrl;
|
||||
import com.intellij.j2ee.module.view.web.WebRootFileUrl;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.impl.ModuleUtil;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.*;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jdom.Element;
|
||||
@@ -70,7 +76,7 @@ public class FavoritesTreeStructure extends ProjectAbstractTreeStructureBase imp
|
||||
super(project);
|
||||
myRoot = new AbstractTreeNode(myProject, "Root") {
|
||||
public Collection<AbstractTreeNode> getChildren() {
|
||||
return null;
|
||||
return myFavorites;
|
||||
}
|
||||
|
||||
public void update(final PresentationData presentation) {
|
||||
@@ -129,6 +135,77 @@ public class FavoritesTreeStructure extends ProjectAbstractTreeStructureBase imp
|
||||
myFavorites.remove(element);
|
||||
}
|
||||
|
||||
public boolean contains(final VirtualFile vFile){
|
||||
final ProjectFileIndex projectFileIndex = ProjectRootManager.getInstance(myProject).getFileIndex();
|
||||
final ContentIterator contentIterator = new ContentIterator() {
|
||||
public boolean processFile(VirtualFile fileOrDir) {
|
||||
if (fileOrDir == null ? vFile == null : fileOrDir.equals(vFile)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
for (Iterator<AbstractTreeNode> iterator = myRoot.getChildren().iterator(); iterator.hasNext();) {
|
||||
AbstractTreeNode node = iterator.next();
|
||||
boolean find = false;
|
||||
if (node.getValue() instanceof PsiElement){
|
||||
final VirtualFile virtualFile = BasePsiNode.getVirtualFile(((PsiElement)node.getValue()));
|
||||
if (vFile == null ? virtualFile == null : vFile.equals(virtualFile)){
|
||||
return true;
|
||||
}
|
||||
if (!virtualFile.isDirectory()){
|
||||
continue;
|
||||
}
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(((PsiElement)node.getValue()));
|
||||
if (module != null){
|
||||
find = ModuleRootManager.getInstance(module).getFileIndex().iterateContentUnderDirectory(virtualFile, contentIterator);
|
||||
} else {
|
||||
find = projectFileIndex.iterateContentUnderDirectory(virtualFile, contentIterator);
|
||||
}
|
||||
}
|
||||
if (node.getValue() instanceof Module){
|
||||
find = ModuleRootManager.getInstance(((Module)node.getValue())).getFileIndex().iterateContent(contentIterator);
|
||||
}
|
||||
if (node.getValue() instanceof LibraryGroupElement){
|
||||
find = ModuleRootManager.getInstance(((LibraryGroupElement)node.getValue()).getModule()).getFileIndex().isInContent(vFile) &&
|
||||
projectFileIndex.isInLibraryClasses(vFile);
|
||||
}
|
||||
if (node.getValue() instanceof NamedLibraryElement){
|
||||
NamedLibraryElement namedLibraryElement = (NamedLibraryElement)node.getValue();
|
||||
final VirtualFile[] files = namedLibraryElement.getOrderEntry().getFiles(OrderRootType.CLASSES);
|
||||
if (files != null){
|
||||
find = ArrayUtil.find(files, vFile) > -1;
|
||||
}
|
||||
}
|
||||
if (node.getValue() instanceof Form){
|
||||
Form form = (Form) node.getValue();
|
||||
PsiFile[] forms = form.getClassToBind().getManager().getSearchHelper().findFormsBoundToClass(form.getClassToBind().getQualifiedName());
|
||||
for (int i = 0; i < forms.length; i++) {
|
||||
PsiFile psiFile = forms[i];
|
||||
final VirtualFile virtualFile = psiFile.getVirtualFile();
|
||||
if (virtualFile == null ? vFile == null : virtualFile.equals(vFile)){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (find){
|
||||
return true;
|
||||
}
|
||||
if (node.getValue() instanceof ModuleGroup){
|
||||
ModuleGroup group = (ModuleGroup) node.getValue();
|
||||
final Module[] modules = group.modulesInGroup(myProject, true);
|
||||
for (int i = 0; i < modules.length; i++) {
|
||||
Module module = modules[i];
|
||||
find = ModuleRootManager.getInstance(module).getFileIndex().iterateContent(contentIterator);
|
||||
if (find){
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public void initFavoritesList() {
|
||||
for (Iterator<AbstractUrl> iterator = myAbstractUrls.keySet().iterator(); iterator.hasNext();) {
|
||||
AbstractUrl abstractUrl = iterator.next();
|
||||
|
||||
@@ -26,10 +26,7 @@ import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.AutoScrollToSourceHandler;
|
||||
import com.intellij.ui.PopupHandler;
|
||||
import com.intellij.ui.ScrollPaneFactory;
|
||||
import com.intellij.ui.SimpleTextAttributes;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.util.EditSourceOnDoubleClickHandler;
|
||||
import com.intellij.util.ui.Tree;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
@@ -106,6 +103,7 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider {
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setShowsRootHandles(true);
|
||||
myTree.setLargeModel(true);
|
||||
new TreeSpeedSearch(myTree);
|
||||
myTree.setCellRenderer(new NodeRenderer() {
|
||||
public void customizeCellRenderer(JTree tree,
|
||||
Object value,
|
||||
@@ -143,8 +141,6 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider {
|
||||
JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(myTree);
|
||||
PopupHandler.installPopupHandler(myTree, (ActionGroup)ActionManager.getInstance().getAction(IdeActions.GROUP_FAVORITES_VIEW_POPUP),
|
||||
ActionPlaces.FAVORITES_VIEW_POPUP, ActionManager.getInstance());
|
||||
|
||||
|
||||
/* mySplitter = new Splitter(true);
|
||||
mySplitter.setHonorComponentsMinimumSize(true);
|
||||
mySplitter.setFirstComponent(myCenterPanel);
|
||||
@@ -166,6 +162,9 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider {
|
||||
};
|
||||
}
|
||||
|
||||
public void selectElement(final Object selector, final VirtualFile file){
|
||||
myBuilder.select(selector, file, true, myBuilder);
|
||||
}
|
||||
/*public void selectElement(final AbstractTreeNode element) {
|
||||
myBuilder.updateFromRoot();
|
||||
DefaultMutableTreeNode node = myBuilder.getNodeForElement(element);
|
||||
@@ -253,7 +252,7 @@ public class FavoritesTreeViewPanel extends JPanel implements DataProvider {
|
||||
result.add(element);
|
||||
}
|
||||
}
|
||||
return result.toArray(new PsiElement[result.size()]);
|
||||
return result.isEmpty() ? null : result.toArray(new PsiElement[result.size()]);
|
||||
}
|
||||
if (DataConstantsEx.TARGET_PSI_ELEMENT.equals(dataId)) {
|
||||
return null;
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.SelectInManager;
|
||||
import com.intellij.ide.SelectInTarget;
|
||||
import com.intellij.ide.impl.ContentManagerWatcher;
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
@@ -10,10 +12,7 @@ import com.intellij.openapi.components.ProjectComponent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectManager;
|
||||
import com.intellij.openapi.startup.StartupManager;
|
||||
import com.intellij.openapi.util.IconLoader;
|
||||
import com.intellij.openapi.util.InvalidDataException;
|
||||
import com.intellij.openapi.util.JDOMExternalizable;
|
||||
import com.intellij.openapi.util.WriteExternalException;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowAnchor;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
@@ -28,7 +27,7 @@ import java.util.*;
|
||||
public class FavoritesViewImpl extends ContentManagerImpl implements ProjectComponent, JDOMExternalizable {
|
||||
private Project myProject;
|
||||
private Map<String, Content> myName2FavoritesListSet = new HashMap<String, Content>();
|
||||
private String myCurrentFavoritesList;
|
||||
public String myCurrentFavoritesList;
|
||||
private Map<String, AddToFavoritesAction> myActions = new HashMap<String, AddToFavoritesAction>();
|
||||
public static FavoritesViewImpl getInstance(Project project) {
|
||||
return project.getComponent(FavoritesViewImpl.class);
|
||||
@@ -58,6 +57,12 @@ public class FavoritesViewImpl extends ContentManagerImpl implements ProjectComp
|
||||
}
|
||||
}
|
||||
});
|
||||
SelectInManager selectInManager = SelectInManager.getInstance(myProject);
|
||||
selectInManager.addTarget(createSelectInTarget());
|
||||
}
|
||||
|
||||
private SelectInTarget createSelectInTarget() {
|
||||
return new FavoritesViewSelectInTarget(myProject);
|
||||
}
|
||||
|
||||
public void initComponent() {
|
||||
@@ -133,6 +138,10 @@ public class FavoritesViewImpl extends ContentManagerImpl implements ProjectComp
|
||||
return temp.isEmpty() ? null : temp.toArray(new String[temp.size()]);
|
||||
}
|
||||
|
||||
public String [] getAllAddActionNames(){
|
||||
return myActions.keySet().toArray(new String[myActions.keySet().size()]);
|
||||
}
|
||||
|
||||
public AddToFavoritesAction getAddToFavoritesAction(String name){
|
||||
return myActions.get(name);
|
||||
}
|
||||
@@ -159,7 +168,7 @@ public class FavoritesViewImpl extends ContentManagerImpl implements ProjectComp
|
||||
((DefaultActionGroup)ActionManager.getInstance().getAction(IdeActions.ADD_TO_FAVORITES)).add(addAction);
|
||||
favoritesPanel.getFavoritesTreeStructure().readExternal(el);
|
||||
}
|
||||
myCurrentFavoritesList = element.getAttributeValue("current");
|
||||
DefaultJDOMExternalizer.readExternal(this, element);
|
||||
}
|
||||
|
||||
public void writeExternal(Element element) throws WriteExternalException {
|
||||
@@ -171,8 +180,6 @@ public class FavoritesViewImpl extends ContentManagerImpl implements ProjectComp
|
||||
favoritesTreeViewPanel.getFavoritesTreeStructure().writeExternal(el);
|
||||
element.addContent(el);
|
||||
}
|
||||
if (myCurrentFavoritesList != null) {
|
||||
element.setAttribute("current", myCurrentFavoritesList);
|
||||
}
|
||||
DefaultJDOMExternalizer.writeExternal(this, element);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.impl.SelectInTargetPsiWrapper;
|
||||
import com.intellij.ide.projectView.impl.nodes.BasePsiNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiJavaFile;
|
||||
|
||||
/**
|
||||
* User: anna
|
||||
* Date: Feb 25, 2005
|
||||
*/
|
||||
public class FavoritesViewSelectInTarget extends SelectInTargetPsiWrapper{
|
||||
public FavoritesViewSelectInTarget(final Project project) {
|
||||
super(project);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "Favorites";
|
||||
}
|
||||
|
||||
protected boolean canSelect(final PsiFile file) {
|
||||
return findSuitableFavoritesList(file.getVirtualFile()) != null;
|
||||
}
|
||||
|
||||
protected void select(PsiElement element, boolean requestFocus) {
|
||||
while (true) {
|
||||
if (element instanceof PsiFile) {
|
||||
break;
|
||||
}
|
||||
if (element instanceof PsiClass && element.getParent() instanceof PsiFile) {
|
||||
break;
|
||||
}
|
||||
element = element.getParent();
|
||||
}
|
||||
|
||||
if (element instanceof PsiJavaFile) {
|
||||
final PsiClass[] classes = ((PsiJavaFile)element).getClasses();
|
||||
if (classes.length > 0) {
|
||||
element = classes[0];
|
||||
}
|
||||
}
|
||||
|
||||
final PsiElement _element = element.getOriginalElement();
|
||||
|
||||
selectElement(new Runnable() {
|
||||
public void run() {
|
||||
final VirtualFile virtualFile = BasePsiNode.getVirtualFile(_element);
|
||||
final FavoritesTreeViewPanel suitableFavoritesList = findSuitableFavoritesList(virtualFile);
|
||||
if (suitableFavoritesList != null){
|
||||
suitableFavoritesList.selectElement(_element, virtualFile);
|
||||
final ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject);
|
||||
windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW).activate(null);
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(myProject);
|
||||
favoritesView.setSelectedContent(favoritesView.getContent(suitableFavoritesList));
|
||||
}
|
||||
}
|
||||
}, requestFocus);
|
||||
}
|
||||
|
||||
private void selectElement(final Runnable runnable, final boolean requestFocus) {
|
||||
final ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject);
|
||||
if (requestFocus) {
|
||||
windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW).activate(runnable);
|
||||
}
|
||||
else {
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
private FavoritesTreeViewPanel findSuitableFavoritesList(VirtualFile file){
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(myProject);
|
||||
final String[] allAddActionNames = favoritesView.getAllAddActionNames();
|
||||
for (int i = 0; i < allAddActionNames.length; i++) {
|
||||
String actionName = allAddActionNames[i];
|
||||
final FavoritesTreeViewPanel favoritesTreeViewPanel = favoritesView.getFavoritesTreeViewPanel(actionName);
|
||||
if (favoritesTreeViewPanel.getFavoritesTreeStructure().contains(file)){
|
||||
return favoritesTreeViewPanel;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void select(final Object selector, final VirtualFile virtualFile, final boolean requestFocus) {
|
||||
selectElement(new Runnable() {
|
||||
public void run() {
|
||||
final FavoritesTreeViewPanel suitableFavoritesList = findSuitableFavoritesList(virtualFile);
|
||||
if (suitableFavoritesList != null){
|
||||
suitableFavoritesList.selectElement(selector, virtualFile);
|
||||
final ToolWindowManager windowManager = ToolWindowManager.getInstance(myProject);
|
||||
windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW).activate(null);
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(myProject);
|
||||
favoritesView.setSelectedContent(favoritesView.getContent(suitableFavoritesList));
|
||||
}
|
||||
}
|
||||
}, requestFocus);
|
||||
}
|
||||
|
||||
protected boolean canWorkWithCustomObjects() {
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getToolWindowId() {
|
||||
return ToolWindowId.FAVORITES_VIEW;
|
||||
}
|
||||
|
||||
public String getMinorViewId() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,13 @@ public class SendToFavoritesAction extends AnAction{
|
||||
}
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
Project project = (Project)e.getDataContext().getData(DataConstants.PROJECT);
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = (Project)dataContext.getData(DataConstants.PROJECT);
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(project);
|
||||
final FavoritesTreeViewPanel currentTreeViewPanel = favoritesView.getCurrentTreeViewPanel();
|
||||
final FavoritesTreeNodeDescriptor[] selectedNodeDescriptors = currentTreeViewPanel.getSelectedNodeDescriptors();
|
||||
favoritesView.getAddToFavoritesAction(myName).actionPerformed(e);
|
||||
((DeleteFromFavoritesAction)ActionManager.getInstance().getAction(IdeActions.REMOVE_FROM_FAVORITES)).actionPerformed(e);
|
||||
((DeleteFromFavoritesAction)ActionManager.getInstance().getAction(IdeActions.REMOVE_FROM_FAVORITES)).removeNodes(selectedNodeDescriptors, project, currentTreeViewPanel.getName());
|
||||
}
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
|
||||
@@ -11,10 +11,7 @@ import com.intellij.openapi.project.Project;
|
||||
* Date: Feb 24, 2005
|
||||
*/
|
||||
public class SendToFavoritesGroup extends DefaultActionGroup{
|
||||
public SendToFavoritesGroup() {
|
||||
super("Send To Other Favorites List", true);
|
||||
}
|
||||
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
Project project = (Project)e.getDataContext().getData(DataConstants.PROJECT);
|
||||
final FavoritesViewImpl favoritesView = FavoritesViewImpl.getInstance(project);
|
||||
@@ -23,6 +20,7 @@ public class SendToFavoritesGroup extends DefaultActionGroup{
|
||||
e.getPresentation().setEnabled(e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_POPUP) &&
|
||||
selectedNodeDescriptors != null &&
|
||||
allAddActionNamesButThis != null);
|
||||
removeAll();
|
||||
for (int i = 0; i < allAddActionNamesButThis.length; i++) {
|
||||
String addAction = allAddActionNamesButThis[i];
|
||||
add(new SendToFavoritesAction(addAction));
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
package com.intellij.ide.projectView;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeNodeDescriptor;
|
||||
import com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
@@ -78,7 +79,11 @@ public abstract class BaseProjectTreeBuilder extends AbstractTreeBuilder {
|
||||
if (defaultMutableTreeNode.getUserObject() instanceof AbstractTreeNode) {
|
||||
ProjectViewNode treeNode = (ProjectViewNode)defaultMutableTreeNode.getUserObject();
|
||||
result.add(treeNode);
|
||||
} else if (defaultMutableTreeNode.getUserObject() instanceof FavoritesTreeNodeDescriptor){
|
||||
AbstractTreeNode treeNode = ((FavoritesTreeNodeDescriptor)defaultMutableTreeNode.getUserObject()).getElement();
|
||||
result.add(treeNode);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -720,7 +720,7 @@ public final class ProjectViewImpl extends ProjectView implements JDOMExternaliz
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
return elements.toArray(new PsiElement[elements.size()]);
|
||||
return elements.isEmpty() ? null : elements.toArray(new PsiElement[elements.size()]);
|
||||
}
|
||||
if (DataConstantsEx.TARGET_PSI_ELEMENT.equals(dataId)) {
|
||||
return null;
|
||||
|
||||
Reference in New Issue
Block a user