mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-03-22 15:19:59 +07:00
Delete old favorites view UI
GitOrigin-RevId: 63b52a28cad1a9148b8438dab1e821ddb66923c8
This commit is contained in:
committed by
intellij-monorepo-bot
parent
e3a8f05b24
commit
f7c20d0682
@@ -167,8 +167,6 @@
|
||||
<separator/>
|
||||
<reference id="Images.SetBackgroundImage"/>
|
||||
<separator/>
|
||||
<reference id="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference id="VersionControlsGroup"/>
|
||||
<separator/>
|
||||
<reference id="Images.EditExternally"/>
|
||||
@@ -199,8 +197,6 @@
|
||||
<reference id="FindUsages"/>
|
||||
<reference id="RefactoringMenu"/>
|
||||
<separator/>
|
||||
<reference id="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference id="$Delete"/>
|
||||
<separator/>
|
||||
<reference id="VersionControlsGroup"/>
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesView;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesListNode;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.projectView.impl.AbstractUrl;
|
||||
import com.intellij.ide.projectView.impl.nodes.PackageElement;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.testFramework.TestSourceBasedTestCase;
|
||||
import com.intellij.util.TreeItem;
|
||||
import org.jdom.Element;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class FavoriteViewTest extends TestSourceBasedTestCase {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
String root = PathManagerEx.getTestDataPath() + "/ide/favoritesView/" + getTestName(true);
|
||||
PsiTestUtil.removeAllRoots(myModule, IdeaTestUtil.getMockJdk17());
|
||||
createTestProjectStructure(root);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String getTestPath() {
|
||||
return "ide" + File.separator + "favoritesView";
|
||||
}
|
||||
|
||||
public void testClass() {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiClass aClass = psiManager.findClass("com.a", GlobalSearchScope.allScope(myProject));
|
||||
checkAddAndRestored(aClass);
|
||||
}
|
||||
|
||||
public void testDirectory() {
|
||||
final JavaPsiFacade psiManager = getJavaFacade();
|
||||
final PsiDirectory psiDirectory = psiManager.findClass("dir.a", GlobalSearchScope.allScope(myProject)).getContainingFile().getContainingDirectory();
|
||||
checkAddAndRestored(psiDirectory);
|
||||
}
|
||||
|
||||
public void testPackage() {
|
||||
final PsiManager psiManager = PsiManager.getInstance(myProject);
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(psiManager.getProject()).findPackage("pack");
|
||||
PackageElement packageElement = new PackageElement(myModule, aPackage, false);
|
||||
checkAddAndRestored(packageElement);
|
||||
}
|
||||
|
||||
private void checkAddAndRestored(Object nodeToAdd) {
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(getProject());
|
||||
favoritesManager.createNewList("xxx");
|
||||
List<String> names = favoritesManager.getAvailableFavoritesListNames();
|
||||
assertEquals(1, names.size());
|
||||
String name = names.get(0);
|
||||
assertEquals("xxx", name);
|
||||
assertTrue(favoritesManager.getFavoritesListRootUrls(name).isEmpty());
|
||||
assertTrue(favoritesManager.addRoots(name, getModule(), nodeToAdd));
|
||||
|
||||
assertFalse(favoritesManager.getFavoritesListRootUrls(name).isEmpty());
|
||||
Element favorite = favoritesManager.getState();
|
||||
|
||||
final Collection<AbstractTreeNode<?>> nodes = FavoritesListNode.getFavoritesRoots(myProject, "xxx", null);
|
||||
AbstractTreeNode<?> targetNode = null;
|
||||
final AbstractUrl url = FavoritesManager.createUrlByElement(nodeToAdd, myProject);
|
||||
for (AbstractTreeNode<?> node : nodes) {
|
||||
final AbstractUrl nodeUrl = FavoritesManager.createUrlByElement(node.getValue(), myProject);
|
||||
if (Comparing.equal(nodeUrl, url)) {
|
||||
targetNode = node;
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertNotNull(targetNode);
|
||||
targetNode.setParent(new FavoritesListNode(myProject, "xxx"));
|
||||
assertTrue(favoritesManager.removeRoot(name, Collections.singletonList(targetNode)));
|
||||
assertTrue(favoritesManager.getFavoritesListRootUrls(name).isEmpty());
|
||||
|
||||
favoritesManager.loadState(favorite);
|
||||
Collection<TreeItem<Pair<AbstractUrl,String>>> urls = favoritesManager.getFavoritesListRootUrls(name);
|
||||
assertEquals(1, urls.size());
|
||||
|
||||
AbstractUrl abstractUrl = urls.iterator().next().getData().getFirst();
|
||||
Object[] path = abstractUrl.createPath(getProject());
|
||||
assertTrue(path.length != 0);
|
||||
Object value = path[path.length - 1];
|
||||
assertEquals(nodeToAdd, value);
|
||||
}
|
||||
}
|
||||
@@ -207,12 +207,6 @@ public interface IdeActions {
|
||||
String GROUP_TESTTREE_POPUP = "TestTreePopupMenu";
|
||||
String GROUP_TESTSTATISTICS_POPUP = "TestStatisticsTablePopupMenu";
|
||||
|
||||
String GROUP_FAVORITES_VIEW_POPUP = "FavoritesViewPopupMenu";
|
||||
String ADD_TO_FAVORITES = "AddToFavorites";
|
||||
String ADD_NEW_FAVORITES_LIST = "AddNewFavoritesList";
|
||||
String REMOVE_FAVORITES_LIST = "RemoveFavoritesList";
|
||||
String REMOVE_ALL_FAVORITES_LISTS_BUT_THIS = "RemoveAllFavoritesListsButThis";
|
||||
|
||||
String GROUP_SCOPE_VIEW_POPUP = "ScopeViewPopupMenu";
|
||||
|
||||
String GROUP_J2EE_VIEW_POPUP = "J2EEViewPopupMenu";
|
||||
|
||||
@@ -1,21 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
public class Concept {
|
||||
private String myTagName;
|
||||
private String myDescription;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.projectView.impl.GroupByTypeComparator;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
|
||||
final class FavoriteComparator extends GroupByTypeComparator {
|
||||
FavoriteComparator() {
|
||||
super(null, FavoritesViewTreeBuilder.ID);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int compare(NodeDescriptor d1, NodeDescriptor d2) {
|
||||
if (d1 instanceof FavoriteTreeNodeDescriptor && d2 instanceof FavoriteTreeNodeDescriptor) {
|
||||
d1 = ((FavoriteTreeNodeDescriptor)d1).getElement();
|
||||
d2 = ((FavoriteTreeNodeDescriptor)d2).getElement();
|
||||
}
|
||||
return super.compare(d1, d2);
|
||||
}
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.FileEditorSelectInContext;
|
||||
import com.intellij.openapi.fileEditor.FileEditor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.ui.AutoScrollFromSourceHandler;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesAutoscrollFromSourceHandler extends AutoScrollFromSourceHandler {
|
||||
private final FavoritesViewSelectInTarget mySelectInTarget = new FavoritesViewSelectInTarget(myProject);
|
||||
|
||||
public FavoritesAutoscrollFromSourceHandler(@NotNull Project project, @NotNull FavoritesViewTreeBuilder builder) {
|
||||
super(project, Objects.requireNonNull(builder.getTree()), builder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAutoScrollEnabled() {
|
||||
return FavoritesManager.getInstance(myProject).getViewSettings().isAutoScrollFromSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollEnabled(boolean enabled) {
|
||||
FavoritesManager.getInstance(myProject).getViewSettings().setAutoScrollFromSource(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void selectElementFromEditor(@NotNull FileEditor editor) {
|
||||
VirtualFile file = editor.getFile();
|
||||
PsiFile psiFile = file == null ? null : PsiManager.getInstance(myProject).findFile(file);
|
||||
if (psiFile != null) new FileEditorSelectInContext(editor, psiFile).selectIn(mySelectInTarget, false);
|
||||
}
|
||||
}
|
||||
@@ -201,8 +201,7 @@ public final class FavoritesManager implements PersistentStateComponent<Element>
|
||||
}
|
||||
|
||||
public synchronized boolean addRoots(@NotNull String name, Module moduleContext, @NotNull Object elements) {
|
||||
Collection<AbstractTreeNode<?>> nodes = AddToFavoritesAction.createNodes(myProject, moduleContext, elements, true, getViewSettings());
|
||||
return !nodes.isEmpty() && addRoots(name, nodes);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,249 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.dnd.*;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeBuilder;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.SmartPsiElementPointer;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.awt.RelativeRectangle;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.awt.datatransfer.Transferable;
|
||||
import java.awt.datatransfer.UnsupportedFlavorException;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public final class FavoritesPanel {
|
||||
private final Project myProject;
|
||||
private final FavoritesTreeViewPanel myViewPanel;
|
||||
private final DnDAwareTree myTree;
|
||||
private final Image myFavoritesImage = IconUtil.toImage(AllIcons.Toolwindows.ToolWindowFavorites);
|
||||
|
||||
public FavoritesPanel(@NotNull Project project) {
|
||||
myProject = project;
|
||||
myViewPanel = new FavoritesTreeViewPanel(myProject);
|
||||
myTree = myViewPanel.getTree();
|
||||
AbstractTreeBuilder treeBuilder = myViewPanel.getBuilder();
|
||||
if (treeBuilder != null) {
|
||||
Disposer.register(myProject, treeBuilder);
|
||||
}
|
||||
setupDnD();
|
||||
}
|
||||
|
||||
public FavoritesTreeViewPanel getPanel() {
|
||||
return myViewPanel;
|
||||
}
|
||||
|
||||
private void setupDnD() {
|
||||
DnDSupport.createBuilder(myTree)
|
||||
.setBeanProvider(info -> {
|
||||
final TreePath path = myTree.getPathForLocation(info.getPoint().x, info.getPoint().y);
|
||||
if (path != null && path.getPathCount() == 3) {
|
||||
Object o = path.getLastPathComponent();
|
||||
if (o instanceof DefaultMutableTreeNode) {
|
||||
o = ((DefaultMutableTreeNode)o).getUserObject();
|
||||
if (o instanceof FavoriteTreeNodeDescriptor) {
|
||||
FavoriteTreeNodeDescriptor root = ((FavoriteTreeNodeDescriptor)o).getFavoritesRoot();
|
||||
if (root != null && root != o) {
|
||||
o = root.getElement();
|
||||
if (o instanceof FavoritesListNode && ((FavoritesListNode)o).getProvider() == null) {
|
||||
return new DnDDragStartBean(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (path != null && path.getPathCount() == 2) {
|
||||
Object o = path.getLastPathComponent();
|
||||
if (o instanceof DefaultMutableTreeNode) {
|
||||
o = ((DefaultMutableTreeNode)o).getUserObject();
|
||||
if (o instanceof FavoriteTreeNodeDescriptor) {
|
||||
FavoriteTreeNodeDescriptor root = ((FavoriteTreeNodeDescriptor)o).getFavoritesRoot();
|
||||
if (root == o) {
|
||||
return new DnDDragStartBean(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return new DnDDragStartBean("") {
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return true;
|
||||
}
|
||||
};
|
||||
})
|
||||
// todo process drag-and-drop here for tasks
|
||||
.setTargetChecker(new DnDTargetChecker() {
|
||||
@Override
|
||||
public boolean update(DnDEvent event) {
|
||||
final Object obj = event.getAttachedObject();
|
||||
if ("".equals(obj)) {
|
||||
event.setDropPossible(false);
|
||||
return false;
|
||||
}
|
||||
int pathCount = 0;
|
||||
if (obj instanceof TreePath) {
|
||||
pathCount = ((TreePath)obj).getPathCount();
|
||||
if (pathCount < 2) {
|
||||
event.setDropPossible(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
|
||||
if ((obj instanceof TreePath && pathCount == 3 && myViewPanel.myTree.getPath(node).isDescendant((TreePath)obj)) ||
|
||||
(node != null && node.getProvider() != null)) {
|
||||
event.setDropPossible(false);
|
||||
return false;
|
||||
}
|
||||
highlight(node, event);
|
||||
if (obj instanceof TreePath && pathCount == 2 && node != null && node.getProvider() == null) {
|
||||
event.setDropPossible(true);
|
||||
return true;
|
||||
}
|
||||
if (node != null) {
|
||||
event.setDropPossible(true);
|
||||
return true;
|
||||
}
|
||||
event.setDropPossible(false);
|
||||
return false;
|
||||
}
|
||||
})
|
||||
.setDropHandler(new DnDDropHandler() {
|
||||
@Override
|
||||
public void drop(DnDEvent event) {
|
||||
final FavoritesListNode node = myViewPanel.findFavoritesListNode(event.getPoint());
|
||||
final FavoritesManager mgr = FavoritesManager.getInstance(myProject);
|
||||
|
||||
if (node == null) return;
|
||||
|
||||
final String listTo = node.getValue();
|
||||
final Object obj = event.getAttachedObject();
|
||||
|
||||
if (obj instanceof TreePath) {
|
||||
final TreePath path = (TreePath)obj;
|
||||
final String listFrom = FavoritesTreeViewPanel.getListNodeFromPath(path).getValue();
|
||||
if (listTo.equals(listFrom)) return;
|
||||
if (path.getPathCount() == 3) {
|
||||
AbstractTreeNode<?> abstractTreeNode = ((FavoriteTreeNodeDescriptor)((DefaultMutableTreeNode)path.getLastPathComponent()).getUserObject()).getElement();
|
||||
Object element = abstractTreeNode.getValue();
|
||||
mgr.removeRoot(listFrom, Collections.singletonList(abstractTreeNode));
|
||||
if (element instanceof SmartPsiElementPointer) {
|
||||
element = ((SmartPsiElementPointer<?>)element).getElement();
|
||||
}
|
||||
mgr.addRoots(listTo, null, element);
|
||||
}
|
||||
if (path.getPathCount() == 2) {//favorites lists manual sorting
|
||||
Rectangle bounds = myTree.getPathBounds(myTree.getPath(node));
|
||||
if (bounds != null) {
|
||||
mgr.setOrder(listFrom, listTo, event.getPoint().y < bounds.y + bounds.height / 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (obj instanceof Transferable && ((Transferable)obj).isDataFlavorSupported(DnDEventImpl.ourDataFlavor)) {
|
||||
List<PsiElement> elements = Collections.emptyList();
|
||||
try {
|
||||
Object data = ((Transferable)obj).getTransferData(DnDEventImpl.ourDataFlavor);
|
||||
if (data instanceof Object[]) elements = JBIterable.of((Object[])data).filter(PsiElement.class).toList();
|
||||
}
|
||||
catch (IOException | UnsupportedFlavorException ignored) {}
|
||||
if (!elements.isEmpty()) {
|
||||
myViewPanel.dropPsiElements(mgr, node, elements.toArray(PsiElement.EMPTY_ARRAY));
|
||||
}
|
||||
}
|
||||
else if (obj instanceof TransferableWrapper) {
|
||||
myViewPanel.dropPsiElements(mgr, node, ((TransferableWrapper)obj).getPsiElements());
|
||||
}
|
||||
else if (obj instanceof DnDNativeTarget.EventInfo) {
|
||||
myViewPanel.dropPsiElements(mgr, node,
|
||||
getPsiFiles(FileCopyPasteUtil.getFileList(((DnDNativeTarget.EventInfo)obj).getTransferable())));
|
||||
}
|
||||
}
|
||||
})
|
||||
.setImageProvider(
|
||||
info -> new DnDImage(myFavoritesImage, new Point(-myFavoritesImage.getWidth(null) / 2, -myFavoritesImage.getHeight(null) / 2)))
|
||||
.enableAsNativeTarget()
|
||||
.setDisposableParent(myProject)
|
||||
.install();
|
||||
}
|
||||
|
||||
private void highlight(FavoritesListNode node, DnDEvent event) {
|
||||
int pathCount = 0;
|
||||
Object object = event.getAttachedObject();
|
||||
if (object instanceof TreePath) {
|
||||
pathCount = ((TreePath)object).getPathCount();
|
||||
}
|
||||
if (node != null) {
|
||||
TreePath pathToList = myTree.getPath(node);
|
||||
while (pathToList != null) {
|
||||
final Object pathObj = pathToList.getLastPathComponent();
|
||||
if (pathObj instanceof DefaultMutableTreeNode) {
|
||||
final Object userObject = ((DefaultMutableTreeNode)pathObj).getUserObject();
|
||||
if (userObject instanceof FavoriteTreeNodeDescriptor) {
|
||||
if (((FavoriteTreeNodeDescriptor)userObject).getElement() == node) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
pathToList = pathToList.getParentPath();
|
||||
}
|
||||
if (pathToList != null) {
|
||||
Rectangle bounds = myTree.getPathBounds(pathToList);
|
||||
if (bounds != null) {
|
||||
if (pathCount == 2) {
|
||||
FavoritesListNode pathToReorder = FavoritesTreeViewPanel.getListNodeFromPath((TreePath)object);
|
||||
FavoritesListNode anchorPath = FavoritesTreeViewPanel.getListNodeFromPath(pathToList);
|
||||
boolean below = event.getPoint().y >= bounds.y + bounds.height / 2;
|
||||
if (pathToReorder == null || anchorPath == null || !FavoritesManager.getInstance(myProject).canReorder(pathToReorder.getValue(), anchorPath.getValue(), !below)) {
|
||||
event.hideHighlighter();
|
||||
return;
|
||||
}
|
||||
if (below) {
|
||||
bounds.y+=bounds.height - 2;
|
||||
}
|
||||
bounds.height = 2;
|
||||
}
|
||||
event.setHighlighting(new RelativeRectangle(myTree, bounds), DnDEvent.DropTargetHighlightingType.RECTANGLE);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
event.hideHighlighter();
|
||||
}
|
||||
}
|
||||
|
||||
private PsiFileSystemItem @Nullable [] getPsiFiles(@Nullable List<? extends File> fileList) {
|
||||
if (fileList == null) {
|
||||
return null;
|
||||
}
|
||||
List<PsiFileSystemItem> sourceFiles = new ArrayList<>();
|
||||
for (File file : fileList) {
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file);
|
||||
PsiFileSystemItem psiFile = PsiUtilCore.findFileSystemItem(myProject, vFile);
|
||||
if (psiFile != null) {
|
||||
sourceFiles.add(psiFile);
|
||||
}
|
||||
}
|
||||
return sourceFiles.toArray(new PsiFileSystemItem[0]);
|
||||
}
|
||||
}
|
||||
@@ -1,161 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.projectView.SettingsProvider;
|
||||
import com.intellij.ide.projectView.TreeStructureProvider;
|
||||
import com.intellij.ide.projectView.ViewSettings;
|
||||
import com.intellij.ide.projectView.impl.ProjectTreeStructure;
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiDirectoryNode;
|
||||
import com.intellij.ide.projectView.impl.nodes.PsiFileNode;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.impl.PsiManagerImpl;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.ArrayUtilRt;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder.ID;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public final class FavoritesTreeStructure extends ProjectTreeStructure {
|
||||
private static final Logger LOGGER = Logger.getInstance(FavoritesTreeStructure.class);
|
||||
private final TreeStructureProvider myNonProjectProvider;
|
||||
public FavoritesTreeStructure(@NotNull Project project) {
|
||||
super(project, ID);
|
||||
myNonProjectProvider = new MyProvider(project);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTreeNode<?> createRoot(@NotNull final Project project, @NotNull ViewSettings settings) {
|
||||
return new FavoritesRootNode(project);
|
||||
}
|
||||
|
||||
public void rootsChanged() {
|
||||
((FavoritesRootNode)getRootElement()).rootsChanged();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object @NotNull [] getChildElements(@NotNull Object element) {
|
||||
if (!(element instanceof AbstractTreeNode)) {
|
||||
return ArrayUtilRt.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
AbstractTreeNode<?> favTreeElement = (AbstractTreeNode<?>)element;
|
||||
try {
|
||||
if (!(element instanceof FavoritesListNode)) {
|
||||
Object[] elements = super.getChildElements(favTreeElement);
|
||||
if (elements.length > 0) return elements;
|
||||
|
||||
ViewSettings settings = favTreeElement instanceof SettingsProvider ? ((SettingsProvider)favTreeElement).getSettings() : ViewSettings.DEFAULT;
|
||||
return ArrayUtil.toObjectArray(myNonProjectProvider.modify(favTreeElement, new ArrayList<>(), settings));
|
||||
}
|
||||
|
||||
List<AbstractTreeNode<?>> result = new ArrayList<>();
|
||||
FavoritesListNode listNode = (FavoritesListNode)element;
|
||||
if (listNode.getProvider() != null) {
|
||||
return ArrayUtil.toObjectArray(listNode.getChildren());
|
||||
}
|
||||
Collection<AbstractTreeNode<?>> roots = FavoritesListNode.getFavoritesRoots(myProject, listNode.getName(), listNode);
|
||||
for (AbstractTreeNode<?> abstractTreeNode : roots) {
|
||||
final Object value = abstractTreeNode.getValue();
|
||||
|
||||
if (value == null) continue;
|
||||
if (value instanceof PsiElement && !((PsiElement)value).isValid()) continue;
|
||||
if (value instanceof SmartPsiElementPointer && ((SmartPsiElementPointer<?>)value).getElement() == null) continue;
|
||||
|
||||
boolean invalid = false;
|
||||
for (FavoriteNodeProvider nodeProvider : FavoriteNodeProvider.EP_NAME.getExtensions(myProject)) {
|
||||
if (nodeProvider.isInvalidElement(value)) {
|
||||
invalid = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (invalid) continue;
|
||||
|
||||
result.add(abstractTreeNode);
|
||||
}
|
||||
return ArrayUtil.toObjectArray(result);
|
||||
}
|
||||
catch (ProcessCanceledException e) {
|
||||
throw e;
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOGGER.error(e);
|
||||
}
|
||||
|
||||
return ArrayUtilRt.EMPTY_OBJECT_ARRAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getParentElement(@NotNull Object element) {
|
||||
AbstractTreeNode<?> parent = null;
|
||||
if (element == getRootElement()) {
|
||||
return null;
|
||||
}
|
||||
if (element instanceof AbstractTreeNode) {
|
||||
parent = ((AbstractTreeNode<?>)element).getParent();
|
||||
}
|
||||
if (parent == null) {
|
||||
return getRootElement();
|
||||
}
|
||||
return parent;
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public NodeDescriptor<?> createDescriptor(@NotNull Object element, NodeDescriptor parentDescriptor) {
|
||||
return new FavoriteTreeNodeDescriptor(myProject, parentDescriptor, (AbstractTreeNode<?>)element);
|
||||
}
|
||||
|
||||
private static class MyProvider implements TreeStructureProvider {
|
||||
private final Project myProject;
|
||||
|
||||
MyProvider(Project project) {
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Collection<AbstractTreeNode<?>> modify(@NotNull AbstractTreeNode<?> parent,
|
||||
@NotNull Collection<AbstractTreeNode<?>> children,
|
||||
ViewSettings settings) {
|
||||
if (parent instanceof PsiDirectoryNode && children.isEmpty()) {
|
||||
VirtualFile virtualFile = ((PsiDirectoryNode)parent).getVirtualFile();
|
||||
if (virtualFile == null) return children;
|
||||
VirtualFile[] virtualFiles = virtualFile.getChildren();
|
||||
List<AbstractTreeNode<?>> result = new ArrayList<>();
|
||||
PsiManagerImpl psiManager = (PsiManagerImpl)PsiManager.getInstance(myProject);
|
||||
for (VirtualFile file : virtualFiles) {
|
||||
AbstractTreeNode<?> child;
|
||||
if (file.isDirectory()) {
|
||||
PsiDirectory directory = psiManager.findDirectory(file);
|
||||
if (directory == null) continue;
|
||||
child = new PsiDirectoryNode(myProject, directory, settings);
|
||||
}
|
||||
else {
|
||||
PsiFile psiFile = psiManager.findFile(file);
|
||||
if (psiFile == null) continue;
|
||||
child = new PsiFileNode(myProject, psiFile, settings);
|
||||
}
|
||||
child.setParent(parent);
|
||||
result.add(child);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return children;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,23 +14,6 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public final class FavoritesTreeUtil {
|
||||
public static FavoriteTreeNodeDescriptor @NotNull [] getSelectedNodeDescriptors(final DnDAwareTree tree) {
|
||||
TreePath[] path = tree.getSelectionPaths();
|
||||
if (path == null) {
|
||||
return FavoriteTreeNodeDescriptor.EMPTY_ARRAY;
|
||||
}
|
||||
ArrayList<FavoriteTreeNodeDescriptor> result = new ArrayList<>();
|
||||
for (TreePath treePath : path) {
|
||||
DefaultMutableTreeNode lastPathNode = (DefaultMutableTreeNode)treePath.getLastPathComponent();
|
||||
Object userObject = lastPathNode.getUserObject();
|
||||
if (!(userObject instanceof FavoriteTreeNodeDescriptor)) {
|
||||
continue;
|
||||
}
|
||||
FavoriteTreeNodeDescriptor treeNodeDescriptor = (FavoriteTreeNodeDescriptor)userObject;
|
||||
result.add(treeNodeDescriptor);
|
||||
}
|
||||
return result.toArray(FavoriteTreeNodeDescriptor.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
public static List<AbstractTreeNode<?>> getLogicalPathToSelected(final Tree tree) {
|
||||
final List<AbstractTreeNode<?>> result = new ArrayList<>();
|
||||
@@ -54,28 +37,4 @@ public final class FavoritesTreeUtil {
|
||||
}
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static FavoritesListNode extractParentList(FavoriteTreeNodeDescriptor descriptor) {
|
||||
AbstractTreeNode current = descriptor.getElement();
|
||||
while (current != null) {
|
||||
if (current instanceof FavoritesListNode) {
|
||||
return (FavoritesListNode)current;
|
||||
}
|
||||
current = current.getParent();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
static FavoritesListProvider getProvider(@NotNull FavoritesManager manager, @NotNull FavoriteTreeNodeDescriptor descriptor) {
|
||||
AbstractTreeNode treeNode = descriptor.getElement();
|
||||
while (treeNode != null && (!(treeNode instanceof FavoritesListNode))) {
|
||||
treeNode = treeNode.getParent();
|
||||
}
|
||||
if (treeNode != null) {
|
||||
final String name = ((FavoritesListNode)treeNode).getValue();
|
||||
return manager.getListProvider(name);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,661 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.CopyPasteDelegator;
|
||||
import com.intellij.ide.IdeView;
|
||||
import com.intellij.ide.NavigatableInterceptor;
|
||||
import com.intellij.ide.bookmarks.Bookmark;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.favoritesTreeView.actions.*;
|
||||
import com.intellij.ide.projectView.impl.ModuleGroup;
|
||||
import com.intellij.ide.projectView.impl.ProjectViewTree;
|
||||
import com.intellij.ide.projectView.impl.nodes.LibraryGroupElement;
|
||||
import com.intellij.ide.projectView.impl.nodes.NamedLibraryElement;
|
||||
import com.intellij.ide.projectView.impl.nodes.ProjectViewDirectoryHelper;
|
||||
import com.intellij.ide.ui.customization.CustomizationUtil;
|
||||
import com.intellij.ide.util.DirectoryChooserUtil;
|
||||
import com.intellij.ide.util.EditorHelper;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.NodeRenderer;
|
||||
import com.intellij.internal.statistic.BookmarkCounterCollector;
|
||||
import com.intellij.navigation.ItemPresentation;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.fileEditor.OpenFileDescriptor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindowManager;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.ui.*;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import com.intellij.ui.awt.RelativeRectangle;
|
||||
import com.intellij.ui.docking.DockContainer;
|
||||
import com.intellij.ui.docking.DockManager;
|
||||
import com.intellij.ui.docking.DockableContent;
|
||||
import com.intellij.ui.treeStructure.actions.CollapseAllAction;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.containers.JBIterable;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import kotlin.Unit;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
import javax.swing.tree.TreePath;
|
||||
import java.awt.*;
|
||||
import java.util.List;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public final class FavoritesTreeViewPanel extends JPanel implements DataProvider, DockContainer {
|
||||
private final FavoritesTreeStructure myFavoritesTreeStructure;
|
||||
private final FavoritesViewTreeBuilder myBuilder;
|
||||
private final CopyPasteDelegator myCopyPasteDelegator;
|
||||
|
||||
public static final DataKey<FavoriteTreeNodeDescriptor[]> CONTEXT_FAVORITES_ROOTS_DATA_KEY = DataKey.create("FavoritesRoot");
|
||||
public static final DataKey<DnDAwareTree> FAVORITES_TREE_KEY = DataKey.create("Favorites.Tree");
|
||||
public static final DataKey<FavoritesViewTreeBuilder> FAVORITES_TREE_BUILDER_KEY = DataKey.create("Favorites.Tree.Builder");
|
||||
|
||||
public static final DataKey<String> FAVORITES_LIST_NAME_DATA_KEY = DataKey.create("FavoritesListName");
|
||||
private final Project myProject;
|
||||
final DnDAwareTree myTree;
|
||||
|
||||
private final AutoScrollToSourceHandler myAutoScrollToSourceHandler;
|
||||
|
||||
private final IdeView myIdeView = new MyIdeView();
|
||||
|
||||
public FavoritesTreeViewPanel(@NotNull Project project) {
|
||||
super(new BorderLayout());
|
||||
|
||||
myProject = project;
|
||||
|
||||
myFavoritesTreeStructure = new FavoritesTreeStructure(project);
|
||||
DefaultMutableTreeNode root = new DefaultMutableTreeNode();
|
||||
root.setUserObject(myFavoritesTreeStructure.getRootElement());
|
||||
DefaultTreeModel treeModel = new DefaultTreeModel(root);
|
||||
myTree = new DnDAwareTree(treeModel) {
|
||||
@Override
|
||||
public boolean isFileColorsEnabled() {
|
||||
return ProjectViewTree.isFileColorsEnabledFor(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Color getFileColorFor(Object object) {
|
||||
return ProjectViewTree.getColorForElement(getPsiElement(object));
|
||||
}
|
||||
};
|
||||
myBuilder = new FavoritesViewTreeBuilder(myProject, myTree, treeModel, myFavoritesTreeStructure);
|
||||
DockManager.getInstance(project).register(this, project);
|
||||
|
||||
TreeUtil.installActions(myTree);
|
||||
myTree.setRootVisible(false);
|
||||
myTree.setShowsRootHandles(true);
|
||||
myTree.setLargeModel(true);
|
||||
new TreeSpeedSearch(myTree);
|
||||
ToolTipManager.sharedInstance().registerComponent(myTree);
|
||||
FavoriteComparator favoritesComparator = new FavoriteComparator();
|
||||
FavoritesManager favoriteManager = FavoritesManager.getInstance(myProject);
|
||||
myBuilder.setNodeDescriptorComparator((o1, o2) -> {
|
||||
if (o1 instanceof FavoriteTreeNodeDescriptor && o2 instanceof FavoriteTreeNodeDescriptor) {
|
||||
final FavoritesListNode listNode1 = FavoritesTreeUtil.extractParentList((FavoriteTreeNodeDescriptor)o1);
|
||||
final FavoritesListNode listNode2 = FavoritesTreeUtil.extractParentList((FavoriteTreeNodeDescriptor)o2);
|
||||
if (listNode1.equals(listNode2)) {
|
||||
final Comparator<FavoriteTreeNodeDescriptor> comparator = favoriteManager.getCustomComparator(listNode1.getName());
|
||||
if (comparator != null) {
|
||||
return comparator.compare((FavoriteTreeNodeDescriptor)o1, (FavoriteTreeNodeDescriptor)o2);
|
||||
}
|
||||
else {
|
||||
return favoritesComparator.compare(o1, o2);
|
||||
}
|
||||
}
|
||||
}
|
||||
return o1.getIndex() - o2.getIndex();
|
||||
});
|
||||
myTree.setCellRenderer(new NodeRenderer() {
|
||||
@Override
|
||||
public void customizeCellRenderer(@NotNull JTree tree,
|
||||
Object value,
|
||||
boolean selected,
|
||||
boolean expanded,
|
||||
boolean leaf,
|
||||
int row,
|
||||
boolean hasFocus) {
|
||||
super.customizeCellRenderer(tree, value, selected, expanded, leaf, row, hasFocus);
|
||||
|
||||
if (!(value instanceof DefaultMutableTreeNode)) {
|
||||
return;
|
||||
}
|
||||
|
||||
final DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
|
||||
//only favorites roots to explain
|
||||
final Object userObject = node.getUserObject();
|
||||
if (userObject instanceof FavoriteTreeNodeDescriptor) {
|
||||
final FavoriteTreeNodeDescriptor favoritesTreeNodeDescriptor = (FavoriteTreeNodeDescriptor)userObject;
|
||||
AbstractTreeNode<?> treeNode = favoritesTreeNodeDescriptor.getElement();
|
||||
FavoritesListProvider provider = FavoritesTreeUtil.getProvider(favoriteManager, favoritesTreeNodeDescriptor);
|
||||
if (provider != null) {
|
||||
Object o = myBuilder.getUi().getElementFor(value);
|
||||
if (o instanceof AbstractTreeNode) {
|
||||
o = ((AbstractTreeNode<?>)o).getValue();
|
||||
}
|
||||
provider.customizeRenderer(this, tree, o, selected, expanded, leaf, row, hasFocus);
|
||||
return;
|
||||
}
|
||||
final ItemPresentation presentation = treeNode.getPresentation();
|
||||
String locationString = presentation.getLocationString();
|
||||
if (locationString == null &&
|
||||
node.getParent() != null &&
|
||||
node.getParent().getParent() != null &&
|
||||
node.getParent().getParent().getParent() == null) {
|
||||
final String location = favoritesTreeNodeDescriptor.getLocation();
|
||||
if (location != null && location.length() > 0) {
|
||||
append(" (" + location + ")", SimpleTextAttributes.GRAY_ATTRIBUTES);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
CustomizationUtil.installPopupHandler(myTree, IdeActions.GROUP_FAVORITES_VIEW_POPUP, ActionPlaces.FAVORITES_VIEW_POPUP);
|
||||
|
||||
EditSourceOnDoubleClickHandler.install(myTree);
|
||||
EditSourceOnEnterKeyHandler.install(myTree);
|
||||
myCopyPasteDelegator = new CopyPasteDelegator(myProject, this);
|
||||
|
||||
AnActionButton addActionButton = AnActionButton.fromAction(ActionManager.getInstance().getAction("AddNewFavoritesList"));
|
||||
addActionButton.getTemplatePresentation().setIcon(CommonActionsPanel.Buttons.ADD.getIcon());
|
||||
addActionButton.setShortcut(CommonActionsPanel.getCommonShortcut(CommonActionsPanel.Buttons.ADD));
|
||||
|
||||
AnActionButton editActionButton = AnActionButton.fromAction(ActionManager.getInstance().getAction("EditFavorites"));
|
||||
editActionButton.setShortcut(CommonShortcuts.CTRL_ENTER);
|
||||
|
||||
AnActionButton deleteActionButton = new DeleteFromFavoritesAction();
|
||||
deleteActionButton.setShortcut(CustomShortcutSet.fromString("DELETE", "BACK_SPACE"));
|
||||
|
||||
//final AnAction exportToTextFileAction = CommonActionsManager.getInstance().createExportToTextFileAction(createTextExporter());
|
||||
//AnActionButton exportActionButton = AnActionButton.fromAction(exportToTextFileAction);
|
||||
//exportActionButton.setShortcut(exportToTextFileAction.getShortcutSet());
|
||||
|
||||
ToolbarDecorator decorator = ToolbarDecorator.createDecorator(myTree)
|
||||
.initPosition()
|
||||
.disableAddAction().disableRemoveAction().disableDownAction().disableUpAction()
|
||||
.addExtraAction(addActionButton)
|
||||
.addExtraAction(editActionButton)
|
||||
.addExtraAction(deleteActionButton);
|
||||
//.addExtraAction(exportActionButton);
|
||||
|
||||
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_NEW_ELEMENT);
|
||||
action.registerCustomShortcutSet(action.getShortcutSet(), myTree);
|
||||
JPanel panel = decorator.createPanel();
|
||||
|
||||
panel.setBorder(JBUI.Borders.empty());
|
||||
add(panel, BorderLayout.CENTER);
|
||||
setBorder(JBUI.Borders.empty());
|
||||
myAutoScrollToSourceHandler = new AutoScrollToSourceHandler() {
|
||||
@Override
|
||||
protected boolean isAutoScrollMode() {
|
||||
return favoriteManager.getViewSettings().isAutoScrollToSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setAutoScrollMode(boolean state) {
|
||||
favoriteManager.getViewSettings().setAutoScrollToSource(state);
|
||||
}
|
||||
};
|
||||
myAutoScrollToSourceHandler.install(myTree);
|
||||
favoriteManager.addFavoritesListener(new FavoritesListener() {
|
||||
@Override
|
||||
public void rootsChanged() {
|
||||
doUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listAdded(@NotNull String listName) {
|
||||
doUpdate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listRemoved(@NotNull String listName) {
|
||||
doUpdate();
|
||||
}
|
||||
}, project);
|
||||
FavoriteNodeProvider.EP_NAME.getPoint(myProject).addChangeListener(this::doUpdate, myProject);
|
||||
}
|
||||
|
||||
private void doUpdate() {
|
||||
myBuilder.updateFromRoot();
|
||||
myTree.repaint();
|
||||
}
|
||||
|
||||
public void selectElement(final Object selector, final VirtualFile file, final boolean requestFocus) {
|
||||
myBuilder.selectAsync(selector, file, requestFocus);
|
||||
}
|
||||
|
||||
public DnDAwareTree getTree() {
|
||||
return myTree;
|
||||
}
|
||||
|
||||
private PsiElement @NotNull [] getSelectedPsiElements() {
|
||||
List<PsiElement> elements = JBIterable.of(getSelectedNodeElements()).filterMap(this::getPsiElement).toList();
|
||||
return PsiUtilCore.toPsiElementArray(elements);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private PsiElement getPsiElement(@Nullable Object element) {
|
||||
if (element instanceof FavoriteTreeNodeDescriptor) {
|
||||
element = ((FavoriteTreeNodeDescriptor)element).getElement().getValue();
|
||||
}
|
||||
if (element instanceof Bookmark) {
|
||||
element = ((Bookmark)element).getFile();
|
||||
}
|
||||
if (element instanceof PsiElement) {
|
||||
return (PsiElement)element;
|
||||
}
|
||||
else if (element instanceof SmartPsiElementPointer) {
|
||||
return ((SmartPsiElementPointer<?>)element).getElement();
|
||||
}
|
||||
else if (element != null) {
|
||||
for (FavoriteNodeProvider provider : FavoriteNodeProvider.EP_NAME.getExtensions(myProject)) {
|
||||
PsiElement psiElement = provider.getPsiElement(element);
|
||||
if (psiElement != null) {
|
||||
return psiElement;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object getData(@NotNull String dataId) {
|
||||
if (CommonDataKeys.PROJECT.is(dataId)) {
|
||||
return myProject;
|
||||
}
|
||||
if (CommonDataKeys.NAVIGATABLE.is(dataId)) {
|
||||
final FavoriteTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
|
||||
return selectedNodeDescriptors.length == 1 ? new NavigatableInterceptor(selectedNodeDescriptors[0].getElement(), this::logNavigation) : null;
|
||||
}
|
||||
FavoritesManager favoriteManager = FavoritesManager.getInstance(myProject);
|
||||
if (CommonDataKeys.NAVIGATABLE_ARRAY.is(dataId)) {
|
||||
List<String> listNames = getSelectedElements(String.class);
|
||||
final List<Navigatable> selectedElements = new SmartList<>();
|
||||
for (String listname : listNames) {
|
||||
selectedElements.addAll(ContainerUtil.map(favoriteManager.getVirtualFiles(listname, false), file -> new OpenFileDescriptor(myProject, file)));
|
||||
}
|
||||
selectedElements.addAll(getSelectedElements(Navigatable.class));
|
||||
return selectedElements.isEmpty() ? null : NavigatableInterceptor.wrap(selectedElements.toArray(Navigatable.EMPTY_NAVIGATABLE_ARRAY), this::logNavigation);
|
||||
}
|
||||
|
||||
if (PlatformDataKeys.CUT_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator.getCutProvider();
|
||||
}
|
||||
if (PlatformDataKeys.COPY_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator.getCopyProvider();
|
||||
}
|
||||
if (PlatformDataKeys.PASTE_PROVIDER.is(dataId)) {
|
||||
return myCopyPasteDelegator.getPasteProvider();
|
||||
}
|
||||
if (PlatformCoreDataKeys.HELP_ID.is(dataId)) {
|
||||
return "reference.toolWindows.favorites";
|
||||
}
|
||||
if (LangDataKeys.NO_NEW_ACTION.is(dataId)) {
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
if (CommonDataKeys.PSI_ELEMENT.is(dataId)) {
|
||||
PsiElement[] elements = getSelectedPsiElements();
|
||||
if (elements.length != 1) {
|
||||
return null;
|
||||
}
|
||||
return elements[0] != null && elements[0].isValid() ? elements[0] : null;
|
||||
}
|
||||
if (LangDataKeys.PSI_ELEMENT_ARRAY.is(dataId)) {
|
||||
final PsiElement[] elements = getSelectedPsiElements();
|
||||
ArrayList<PsiElement> result = new ArrayList<>();
|
||||
for (PsiElement element : elements) {
|
||||
if (element.isValid()) {
|
||||
result.add(element);
|
||||
}
|
||||
}
|
||||
return result.isEmpty() ? null : PsiUtilCore.toPsiElementArray(result);
|
||||
}
|
||||
|
||||
if (LangDataKeys.IDE_VIEW.is(dataId)) {
|
||||
return myIdeView;
|
||||
}
|
||||
|
||||
if (LangDataKeys.TARGET_PSI_ELEMENT.is(dataId)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (LangDataKeys.MODULE_CONTEXT.is(dataId)) {
|
||||
Module[] selected = getSelectedModules();
|
||||
return selected != null && selected.length == 1 ? selected[0] : null;
|
||||
}
|
||||
if (LangDataKeys.MODULE_CONTEXT_ARRAY.is(dataId)) {
|
||||
return getSelectedModules();
|
||||
}
|
||||
if (ModuleGroup.ARRAY_DATA_KEY.is(dataId)) {
|
||||
final List<ModuleGroup> selectedElements = getSelectedElements(ModuleGroup.class);
|
||||
return selectedElements.isEmpty() ? null : selectedElements.toArray(new ModuleGroup[0]);
|
||||
}
|
||||
if (LibraryGroupElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
final List<LibraryGroupElement> selectedElements = getSelectedElements(LibraryGroupElement.class);
|
||||
return selectedElements.isEmpty() ? null : selectedElements.toArray(new LibraryGroupElement[0]);
|
||||
}
|
||||
if (NamedLibraryElement.ARRAY_DATA_KEY.is(dataId)) {
|
||||
final List<NamedLibraryElement> selectedElements = getSelectedElements(NamedLibraryElement.class);
|
||||
return selectedElements.isEmpty() ? null : selectedElements.toArray(new NamedLibraryElement[0]);
|
||||
}
|
||||
if (CONTEXT_FAVORITES_ROOTS_DATA_KEY.is(dataId)) {
|
||||
List<FavoriteTreeNodeDescriptor> result = new ArrayList<>();
|
||||
FavoriteTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
|
||||
for (FavoriteTreeNodeDescriptor selectedNodeDescriptor : selectedNodeDescriptors) {
|
||||
if (FavoritesTreeUtil.getProvider(favoriteManager, selectedNodeDescriptor) != null) {
|
||||
continue;
|
||||
}
|
||||
FavoriteTreeNodeDescriptor root = selectedNodeDescriptor.getFavoritesRoot();
|
||||
if (root != null && root.getElement() instanceof FavoritesListNode) {
|
||||
result.add(selectedNodeDescriptor);
|
||||
}
|
||||
}
|
||||
return result.toArray(FavoriteTreeNodeDescriptor.EMPTY_ARRAY);
|
||||
}
|
||||
if (FAVORITES_TREE_KEY.is(dataId)) {
|
||||
return myTree;
|
||||
}
|
||||
if (FAVORITES_TREE_BUILDER_KEY.is(dataId)) {
|
||||
return myBuilder;
|
||||
}
|
||||
if (FAVORITES_LIST_NAME_DATA_KEY.is(dataId)) {
|
||||
final FavoriteTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
|
||||
Set<String> selectedNames = new HashSet<>();
|
||||
for (FavoriteTreeNodeDescriptor descriptor : descriptors) {
|
||||
FavoritesListNode node = FavoritesTreeUtil.extractParentList(descriptor);
|
||||
if (node != null) {
|
||||
selectedNames.add(node.getValue());
|
||||
}
|
||||
}
|
||||
|
||||
if (selectedNames.size() == 1) {
|
||||
return selectedNames.iterator().next();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
FavoriteTreeNodeDescriptor[] descriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
|
||||
if (descriptors.length > 0) {
|
||||
List<AbstractTreeNode<?>> nodes = new ArrayList<>();
|
||||
for (FavoriteTreeNodeDescriptor descriptor : descriptors) {
|
||||
nodes.add(descriptor.getElement());
|
||||
}
|
||||
return myFavoritesTreeStructure.getDataFromProviders(nodes, dataId);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Unit logNavigation(Navigatable navigatable, Boolean focusEditor) {
|
||||
BookmarkCounterCollector.favoritesNavigate.log(myProject, navigatable.getClass());
|
||||
return Unit.INSTANCE;
|
||||
}
|
||||
|
||||
private <T> List<T> getSelectedElements(Class<T> klass) {
|
||||
final Object[] elements = getSelectedNodeElements();
|
||||
ArrayList<T> result = new ArrayList<>();
|
||||
for (Object element : elements) {
|
||||
if (element == null) continue;
|
||||
if (klass.isAssignableFrom(element.getClass())) {
|
||||
result.add((T)element);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private Module[] getSelectedModules() {
|
||||
final Object[] elements = getSelectedNodeElements();
|
||||
ArrayList<Module> result = new ArrayList<>();
|
||||
for (Object element : elements) {
|
||||
if (element instanceof Module) {
|
||||
result.add((Module)element);
|
||||
}
|
||||
else if (element instanceof ModuleGroup) {
|
||||
result.addAll(((ModuleGroup)element).modulesInGroup(myProject, true));
|
||||
}
|
||||
}
|
||||
|
||||
return result.isEmpty() ? null : result.toArray(Module.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
private Object @NotNull [] getSelectedNodeElements() {
|
||||
FavoriteTreeNodeDescriptor[] selectedNodeDescriptors = FavoritesTreeUtil.getSelectedNodeDescriptors(myTree);
|
||||
List<Object> result = new ArrayList<>();
|
||||
for (FavoriteTreeNodeDescriptor selectedNodeDescriptor : selectedNodeDescriptors) {
|
||||
if (selectedNodeDescriptor != null) {
|
||||
Object value = selectedNodeDescriptor.getElement().getValue();
|
||||
if (value instanceof SmartPsiElementPointer) {
|
||||
value = ((SmartPsiElementPointer<?>)value).getElement();
|
||||
}
|
||||
result.add(value);
|
||||
}
|
||||
}
|
||||
return ArrayUtil.toObjectArray(result);
|
||||
}
|
||||
|
||||
public void setupToolWindow(@NotNull ToolWindowEx window) {
|
||||
final CollapseAllAction collapseAction = new CollapseAllAction(myTree);
|
||||
collapseAction.getTemplatePresentation().setIcon(AllIcons.Actions.Collapseall);
|
||||
window.setTitleActions(collapseAction);
|
||||
|
||||
final DefaultActionGroup group = new DefaultActionGroup();
|
||||
final ProjectViewDirectoryHelper helper = ProjectViewDirectoryHelper.getInstance(myProject);
|
||||
|
||||
if (helper.supportsFlattenPackages()) {
|
||||
group.add(new FavoritesFlattenPackagesAction(myProject, myBuilder));
|
||||
}
|
||||
if (helper.supportsHideEmptyMiddlePackages()) {
|
||||
group.add(new FavoritesCompactEmptyMiddlePackagesAction(myProject, myBuilder));
|
||||
}
|
||||
if (helper.supportsFlattenPackages()) {
|
||||
group.addAction(new FavoritesAbbreviatePackageNamesAction(myProject, myBuilder));
|
||||
}
|
||||
//todo move this logic to ProjectViewDirectoryHelper.supportsShowMembers
|
||||
if (!PlatformUtils.isCidr() && !PlatformUtils.isRider()) {
|
||||
group.add(new FavoritesShowMembersAction(myProject, myBuilder));
|
||||
}
|
||||
|
||||
final FavoritesAutoscrollFromSourceHandler handler = new FavoritesAutoscrollFromSourceHandler(myProject, myBuilder);
|
||||
handler.install();
|
||||
group.add(handler.createToggleAction());
|
||||
|
||||
group.add(new FavoritesAutoScrollToSourceAction(myProject, myAutoScrollToSourceHandler, myBuilder));
|
||||
window.setAdditionalGearActions(group);
|
||||
}
|
||||
|
||||
public static String getQualifiedName(final VirtualFile file) {
|
||||
return file.getPresentableUrl();
|
||||
}
|
||||
|
||||
public FavoritesViewTreeBuilder getBuilder() {
|
||||
return myBuilder;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
FavoritesListNode findFavoritesListNode(Point point) {
|
||||
final TreePath path = myTree.getClosestPathForLocation(point.x, point.y);
|
||||
final FavoritesListNode node = getListNodeFromPath(path);
|
||||
return node == null ? (FavoritesListNode)((FavoritesRootNode)myFavoritesTreeStructure.getRootElement()).getChildren().iterator().next()
|
||||
: node;
|
||||
}
|
||||
|
||||
static FavoritesListNode getListNodeFromPath(TreePath path) {
|
||||
if (path != null && path.getPathCount() > 1) {
|
||||
final Object o = path.getPath()[1];
|
||||
if (o instanceof DefaultMutableTreeNode) {
|
||||
final Object obj = ((DefaultMutableTreeNode)o).getUserObject();
|
||||
if (obj instanceof FavoriteTreeNodeDescriptor) {
|
||||
final AbstractTreeNode node = ((FavoriteTreeNodeDescriptor)obj).getElement();
|
||||
if (node instanceof FavoritesListNode) {
|
||||
return (FavoritesListNode)node;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
void dropPsiElements(FavoritesManager mgr, FavoritesListNode node, PsiElement[] elements) {
|
||||
if (elements != null && elements.length > 0) {
|
||||
final ArrayList<AbstractTreeNode<?>> nodes = new ArrayList<>();
|
||||
for (PsiElement element : elements) {
|
||||
if (element instanceof SmartPsiElementPointer) {
|
||||
element = ((SmartPsiElementPointer<?>)element).getElement();
|
||||
}
|
||||
final Collection<AbstractTreeNode<?>> tmp = AddToFavoritesAction
|
||||
.createNodes(myProject, null, element, true, FavoritesManager.getInstance(myProject).getViewSettings());
|
||||
nodes.addAll(tmp);
|
||||
mgr.addRoots(node.getValue(), nodes);
|
||||
}
|
||||
myBuilder.select(nodes.toArray(), null);
|
||||
}
|
||||
}
|
||||
|
||||
private final class MyIdeView implements IdeView {
|
||||
@Override
|
||||
public void selectElement(final PsiElement element) {
|
||||
if (element != null) {
|
||||
selectPsiElement(element, false);
|
||||
boolean requestFocus = true;
|
||||
final boolean isDirectory = element instanceof PsiDirectory;
|
||||
if (!isDirectory) {
|
||||
Editor editor = EditorHelper.openInEditor(element);
|
||||
if (editor != null) {
|
||||
ToolWindowManager.getInstance(myProject).activateEditorComponent();
|
||||
requestFocus = false;
|
||||
}
|
||||
}
|
||||
if (requestFocus) {
|
||||
selectPsiElement(element, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void selectPsiElement(PsiElement element, boolean requestFocus) {
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(element);
|
||||
FavoritesTreeViewPanel.this.selectElement(element, virtualFile, requestFocus);
|
||||
}
|
||||
|
||||
private PsiDirectory @Nullable [] getSelectedDirectories() {
|
||||
if (myBuilder == null) return null;
|
||||
final Object[] selectedNodeElements = getSelectedNodeElements();
|
||||
if (selectedNodeElements.length != 1) return null;
|
||||
for (FavoriteNodeProvider nodeProvider : FavoriteNodeProvider.EP_NAME.getExtensions(myProject)) {
|
||||
final PsiElement psiElement = nodeProvider.getPsiElement(selectedNodeElements[0]);
|
||||
if (psiElement instanceof PsiDirectory) {
|
||||
return new PsiDirectory[]{(PsiDirectory)psiElement};
|
||||
}
|
||||
else if (psiElement instanceof PsiDirectoryContainer) {
|
||||
final String moduleName = nodeProvider.getElementModuleName(selectedNodeElements[0]);
|
||||
GlobalSearchScope searchScope = GlobalSearchScope.projectScope(myProject);
|
||||
if (moduleName != null) {
|
||||
final Module module = ModuleManager.getInstance(myProject).findModuleByName(moduleName);
|
||||
if (module != null) {
|
||||
searchScope = GlobalSearchScope.moduleScope(module);
|
||||
}
|
||||
}
|
||||
return ((PsiDirectoryContainer)psiElement).getDirectories(searchScope);
|
||||
}
|
||||
else if (psiElement != null) {
|
||||
PsiFile file = psiElement.getContainingFile();
|
||||
if (file != null) {
|
||||
PsiDirectory parent = file.getParent();
|
||||
if (parent != null) {
|
||||
return new PsiDirectory[]{parent};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return selectedNodeElements[0] instanceof PsiDirectory ? new PsiDirectory[]{(PsiDirectory)selectedNodeElements[0]} : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory @NotNull [] getDirectories() {
|
||||
final PsiDirectory[] directories = getSelectedDirectories();
|
||||
return directories == null ? PsiDirectory.EMPTY_ARRAY : directories;
|
||||
}
|
||||
|
||||
@Override
|
||||
public PsiDirectory getOrChooseDirectory() {
|
||||
return DirectoryChooserUtil.getOrChooseDirectory(this);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public RelativeRectangle getAcceptArea() {
|
||||
return new RelativeRectangle(myTree);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public ContentResponse getContentResponse(@NotNull DockableContent content, RelativePoint point) {
|
||||
if (content.getKey() instanceof VirtualFile) {
|
||||
return ContentResponse.ACCEPT_COPY;
|
||||
}
|
||||
return ContentResponse.DENY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JComponent getContainerComponent() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void add(@NotNull DockableContent content, RelativePoint dropTarget) {
|
||||
if (!(content.getKey() instanceof VirtualFile)) {
|
||||
return;
|
||||
}
|
||||
|
||||
VirtualFile vFile = (VirtualFile)content.getKey();
|
||||
PsiFileSystemItem psiFile = PsiUtilCore.findFileSystemItem(myProject, vFile);
|
||||
Point p = dropTarget.getScreenPoint();
|
||||
SwingUtilities.convertPointFromScreen(p, myTree);
|
||||
FavoritesListNode node = findFavoritesListNode(p);
|
||||
if (node != null && psiFile != null) {
|
||||
dropPsiElements(FavoritesManager.getInstance(myProject), node, new PsiElement[]{psiFile});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEmpty() {
|
||||
return myTree.isEmpty();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Image processDropOver(@NotNull DockableContent content, RelativePoint point) {
|
||||
Point p = point.getScreenPoint();
|
||||
SwingUtilities.convertPointFromScreen(p, myTree);
|
||||
TreePath treePath = myTree.getClosestPathForLocation(p.x, p.y);
|
||||
FavoritesListNode node = getListNodeFromPath(treePath);
|
||||
treePath = node != null ? myTree.getPath(node) : null;
|
||||
if (treePath != null) {
|
||||
myTree.setSelectionPath(treePath);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisposeWhenEmpty() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -1,105 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.StandardTargetWeights;
|
||||
import com.intellij.ide.impl.SelectInTargetPsiWrapper;
|
||||
import com.intellij.notebook.editor.BackedVirtualFile;
|
||||
import com.intellij.openapi.extensions.ExtensionNotApplicableException;
|
||||
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.PsiElement;
|
||||
import com.intellij.psi.PsiFileSystemItem;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
final class FavoritesViewSelectInTarget extends SelectInTargetPsiWrapper {
|
||||
FavoritesViewSelectInTarget(final Project project) {
|
||||
super(project);
|
||||
|
||||
if (PlatformUtils.isPyCharmEducational()) {
|
||||
throw ExtensionNotApplicableException.create();
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return IdeBundle.message("select.in.favorites");
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToolWindowId() {
|
||||
return ToolWindowId.FAVORITES_VIEW;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void select(Object selector, VirtualFile virtualFile, boolean requestFocus) {
|
||||
select(myProject, selector, virtualFile, requestFocus);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void select(PsiElement element, boolean requestFocus) {
|
||||
PsiElement toSelect = findElementToSelect(element, null);
|
||||
if (toSelect != null) {
|
||||
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(toSelect);
|
||||
virtualFile = virtualFile == null ? null : BackedVirtualFile.getOriginFileIfBacked(virtualFile);
|
||||
select(toSelect, virtualFile, requestFocus);
|
||||
}
|
||||
}
|
||||
|
||||
private static ActionCallback select(@NotNull Project project, Object toSelect, VirtualFile virtualFile, boolean requestFocus) {
|
||||
final ActionCallback result = new ActionCallback();
|
||||
|
||||
ToolWindowManager windowManager = ToolWindowManager.getInstance(project);
|
||||
final ToolWindow favoritesToolWindow = windowManager.getToolWindow(ToolWindowId.FAVORITES_VIEW);
|
||||
|
||||
if (favoritesToolWindow != null) {
|
||||
final Runnable runnable = () -> {
|
||||
final FavoritesTreeViewPanel panel = UIUtil.findComponentOfType(favoritesToolWindow.getComponent(), FavoritesTreeViewPanel.class);
|
||||
if (panel != null) {
|
||||
panel.selectElement(toSelect, virtualFile, requestFocus);
|
||||
result.setDone();
|
||||
}
|
||||
};
|
||||
|
||||
if (requestFocus) {
|
||||
favoritesToolWindow.activate(runnable, false);
|
||||
}
|
||||
else {
|
||||
favoritesToolWindow.show(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canSelect(final PsiFileSystemItem file) {
|
||||
return findSuitableFavoritesList(file.getVirtualFile(), myProject, null) != null;
|
||||
}
|
||||
|
||||
public static String findSuitableFavoritesList(VirtualFile file, Project project, final String currentSubId) {
|
||||
FavoritesManager manager = FavoritesManager.getInstance(project);
|
||||
return manager != null ? manager.getFavoriteListName(currentSubId, file) : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getMinorViewId() {
|
||||
return FavoritesViewTreeBuilder.ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getWeight() {
|
||||
return StandardTargetWeights.FAVORITES_WEIGHT;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,222 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ProjectTopics;
|
||||
import com.intellij.ide.CopyPasteUtil;
|
||||
import com.intellij.ide.projectView.BaseProjectTreeBuilder;
|
||||
import com.intellij.ide.projectView.ProjectViewPsiTreeChangeListener;
|
||||
import com.intellij.ide.projectView.impl.ProjectAbstractTreeStructureBase;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeStructure;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeUpdater;
|
||||
import com.intellij.ide.util.treeView.NodeDescriptor;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.AdditionalLibraryRootsListener;
|
||||
import com.intellij.openapi.roots.ModuleRootEvent;
|
||||
import com.intellij.openapi.roots.ModuleRootListener;
|
||||
import com.intellij.openapi.util.ActionCallback;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.vcs.FileStatusListener;
|
||||
import com.intellij.openapi.vcs.FileStatusManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.wm.ToolWindowId;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.psi.util.PsiUtilCore;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.tree.TreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.concurrency.Promise;
|
||||
import org.jetbrains.concurrency.Promises;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.tree.DefaultMutableTreeNode;
|
||||
import javax.swing.tree.DefaultTreeModel;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public final class FavoritesViewTreeBuilder extends BaseProjectTreeBuilder {
|
||||
public static final String ID = ToolWindowId.FAVORITES_VIEW;
|
||||
|
||||
public FavoritesViewTreeBuilder(@NotNull Project project,
|
||||
JTree tree,
|
||||
DefaultTreeModel treeModel,
|
||||
ProjectAbstractTreeStructureBase treeStructure) {
|
||||
super(project,
|
||||
tree,
|
||||
treeModel,
|
||||
treeStructure,
|
||||
new FavoriteComparator());
|
||||
final MessageBusConnection bus = myProject.getMessageBus().connect(this);
|
||||
ProjectViewPsiTreeChangeListener psiTreeChangeListener = new ProjectViewPsiTreeChangeListener(myProject) {
|
||||
@Override
|
||||
protected DefaultMutableTreeNode getRootNode() {
|
||||
return FavoritesViewTreeBuilder.this.getRootNode();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected AbstractTreeUpdater getUpdater() {
|
||||
return FavoritesViewTreeBuilder.this.getUpdater();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isFlattenPackages() {
|
||||
return getStructure().isFlattenPackages();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void childrenChanged(PsiElement parent, final boolean stopProcessingForThisModificationCount) {
|
||||
PsiElement containingFile = parent instanceof PsiDirectory ? parent : parent.getContainingFile();
|
||||
if (containingFile != null && findNodeByElement(containingFile) == null) {
|
||||
queueUpdate(true);
|
||||
}
|
||||
else {
|
||||
super.childrenChanged(parent, true);
|
||||
}
|
||||
}
|
||||
};
|
||||
bus.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
|
||||
@Override
|
||||
public void rootsChanged(@NotNull ModuleRootEvent event) {
|
||||
queueUpdate(true);
|
||||
}
|
||||
});
|
||||
bus.subscribe(AdditionalLibraryRootsListener.TOPIC, (presentableLibraryName, oldRoots, newRoots, libraryNameForDebug) -> queueUpdate(true));
|
||||
PsiManager.getInstance(myProject).addPsiTreeChangeListener(psiTreeChangeListener, this);
|
||||
FileStatusListener fileStatusListener = new MyFileStatusListener();
|
||||
FileStatusManager.getInstance(myProject).addFileStatusListener(fileStatusListener, this);
|
||||
CopyPasteUtil.addDefaultListener(this, this::addSubtreeToUpdateByElement);
|
||||
|
||||
FavoritesListener favoritesListener = new FavoritesListener() {
|
||||
@Override
|
||||
public void rootsChanged() {
|
||||
updateFromRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listAdded(@NotNull String listName) {
|
||||
updateFromRoot();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void listRemoved(@NotNull String listName) {
|
||||
updateFromRoot();
|
||||
}
|
||||
};
|
||||
initRootNode();
|
||||
FavoritesManager.getInstance(myProject).addFavoritesListener(favoritesListener, this);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public FavoritesTreeStructure getStructure() {
|
||||
final AbstractTreeStructure structure = getTreeStructure();
|
||||
assert structure instanceof FavoritesTreeStructure;
|
||||
return (FavoritesTreeStructure)structure;
|
||||
}
|
||||
|
||||
public AbstractTreeNode getRoot() {
|
||||
final Object rootElement = getRootElement();
|
||||
assert rootElement instanceof AbstractTreeNode;
|
||||
return (AbstractTreeNode)rootElement;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateFromRoot() {
|
||||
updateFromRootCB();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public ActionCallback updateFromRootCB() {
|
||||
getStructure().rootsChanged();
|
||||
if (isDisposed()) return ActionCallback.DONE;
|
||||
getUpdater().cancelAllRequests();
|
||||
return queueUpdate();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Promise<Object> selectAsync(Object element, VirtualFile file, boolean requestFocus) {
|
||||
final DefaultMutableTreeNode node = findSmartFirstLevelNodeByElement(element);
|
||||
if (node != null) {
|
||||
return Promises.toPromise(TreeUtil.selectInTree(node, requestFocus, getTree()));
|
||||
}
|
||||
return super.selectAsync(element, file, requestFocus);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static DefaultMutableTreeNode findFirstLevelNodeWithObject(final DefaultMutableTreeNode aRoot, final Object aObject) {
|
||||
for (int i = 0; i < aRoot.getChildCount(); i++) {
|
||||
final DefaultMutableTreeNode child = (DefaultMutableTreeNode)aRoot.getChildAt(i);
|
||||
Object userObject = child.getUserObject();
|
||||
if (userObject instanceof FavoriteTreeNodeDescriptor) {
|
||||
if (Comparing.equal(((FavoriteTreeNodeDescriptor)userObject).getElement(), aObject)) {
|
||||
return child;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Object findNodeByElement(@NotNull Object element) {
|
||||
final Object node = findSmartFirstLevelNodeByElement(element);
|
||||
if (node != null) return node;
|
||||
return super.findNodeByElement(element);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
DefaultMutableTreeNode findSmartFirstLevelNodeByElement(final Object element) {
|
||||
for (Object child : getRoot().getChildren()) {
|
||||
AbstractTreeNode favorite = (AbstractTreeNode)child;
|
||||
Object currentValue = favorite.getValue();
|
||||
if (currentValue instanceof SmartPsiElementPointer) {
|
||||
currentValue = ((SmartPsiElementPointer<?>)favorite.getValue()).getElement();
|
||||
}
|
||||
/*else if (currentValue instanceof PsiJavaFile) {
|
||||
final PsiClass[] classes = ((PsiJavaFile)currentValue).getClasses();
|
||||
if (classes.length > 0) {
|
||||
currentValue = classes[0];
|
||||
}
|
||||
}*/
|
||||
if (Comparing.equal(element, currentValue)) {
|
||||
final DefaultMutableTreeNode nodeWithObject =
|
||||
findFirstLevelNodeWithObject((DefaultMutableTreeNode)getTree().getModel().getRoot(), favorite);
|
||||
if (nodeWithObject != null) {
|
||||
return nodeWithObject;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAlwaysShowPlus(NodeDescriptor nodeDescriptor) {
|
||||
Object[] childElements = getStructure().getChildElements(nodeDescriptor);
|
||||
return childElements.length > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isAutoExpandNode(NodeDescriptor nodeDescriptor) {
|
||||
return nodeDescriptor.getParentDescriptor() == null;
|
||||
}
|
||||
|
||||
private final class MyFileStatusListener implements FileStatusListener {
|
||||
@Override
|
||||
public void fileStatusesChanged() {
|
||||
queueUpdateFrom(getRootNode(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fileStatusChanged(@NotNull VirtualFile vFile) {
|
||||
PsiElement element = PsiUtilCore.findFileSystemItem(myProject, vFile);
|
||||
if (element != null && !addSubtreeToUpdateByElement(element) &&
|
||||
element instanceof PsiFile &&
|
||||
((PsiFile)element).getFileType() == StdFileTypes.JAVA) {
|
||||
addSubtreeToUpdateByElement(((PsiFile)element).getContainingDirectory());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2019 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
import com.intellij.ui.JBColor;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
public enum Flag {
|
||||
orange(JBColor.orange),
|
||||
blue(JBColor.blue),
|
||||
green(JBColor.green),
|
||||
red(JBColor.red),
|
||||
brown(new JBColor(new Color(0x804000), new Color(0x9C5700))),
|
||||
magenta(JBColor.magenta),
|
||||
violet(new JBColor(new Color(0x8000FF), new Color(0x9C57FF))),
|
||||
yellow(JBColor.yellow),
|
||||
grey(JBColor.lightGray);
|
||||
|
||||
private final Color myColor;
|
||||
|
||||
Flag(Color color) {
|
||||
myColor = color;
|
||||
}
|
||||
|
||||
public Color getColor() {
|
||||
return myColor;
|
||||
}
|
||||
}
|
||||
@@ -21,27 +21,12 @@ import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class InvalidUsageNoteNode {
|
||||
private final PercentDone myPercentDone = PercentDone._0;
|
||||
private Set<Flag> myFlags;
|
||||
private Set<Concept> myConcepts;
|
||||
|
||||
final List<TextChunk> myText;
|
||||
|
||||
public InvalidUsageNoteNode(List<TextChunk> text) {
|
||||
myText = text;
|
||||
}
|
||||
|
||||
public PercentDone getPercentDone() {
|
||||
return myPercentDone;
|
||||
}
|
||||
|
||||
public Set<Flag> getFlags() {
|
||||
return myFlags;
|
||||
}
|
||||
|
||||
public Set<Concept> getConcepts() {
|
||||
return myConcepts;
|
||||
}
|
||||
|
||||
public List<TextChunk> getText() {
|
||||
return myText;
|
||||
|
||||
@@ -20,9 +20,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.util.Set;
|
||||
|
||||
public class NoteNode {
|
||||
private PercentDone myPercentDone = PercentDone._0;
|
||||
private Set<Flag> myFlags;
|
||||
private Set<Concept> myConcepts;
|
||||
|
||||
@NotNull
|
||||
private String myText;
|
||||
@@ -33,30 +30,6 @@ public class NoteNode {
|
||||
myReadonly = readonly;
|
||||
}
|
||||
|
||||
public PercentDone getPercentDone() {
|
||||
return myPercentDone;
|
||||
}
|
||||
|
||||
public void setPercentDone(PercentDone percentDone) {
|
||||
myPercentDone = percentDone;
|
||||
}
|
||||
|
||||
public Set<Flag> getFlags() {
|
||||
return myFlags;
|
||||
}
|
||||
|
||||
public void setFlags(Set<Flag> flags) {
|
||||
myFlags = flags;
|
||||
}
|
||||
|
||||
public Set<Concept> getConcepts() {
|
||||
return myConcepts;
|
||||
}
|
||||
|
||||
public void setConcepts(Set<Concept> concepts) {
|
||||
myConcepts = concepts;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getText() {
|
||||
return myText;
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView;
|
||||
|
||||
public enum PercentDone {
|
||||
_0(0), _05(5), _20(20), _50(50), _70(70), _100(100);
|
||||
|
||||
private final int myPercent;
|
||||
|
||||
PercentDone(int percent) {
|
||||
myPercent = percent;
|
||||
}
|
||||
|
||||
public int getPercent() {
|
||||
return myPercent;
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.fileEditor.FileEditorManager;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class AddAllOpenFilesToFavorites extends AnAction implements DumbAware {
|
||||
private final String myFavoritesName;
|
||||
|
||||
public AddAllOpenFilesToFavorites(String chosenList) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
getTemplatePresentation().setText(chosenList, false);
|
||||
myFavoritesName = chosenList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
|
||||
final ArrayList<PsiFile> filesToAdd = getFilesToAdd(project);
|
||||
for (PsiFile file : filesToAdd) {
|
||||
favoritesManager.addRoots(myFavoritesName, null, file);
|
||||
}
|
||||
}
|
||||
|
||||
static ArrayList<PsiFile> getFilesToAdd(Project project) {
|
||||
ArrayList<PsiFile> result = new ArrayList<>();
|
||||
final FileEditorManager editorManager = FileEditorManager.getInstance(project);
|
||||
final PsiManager psiManager = PsiManager.getInstance(project);
|
||||
for (VirtualFile openFile : editorManager.getOpenFiles()) {
|
||||
if (!openFile.isValid()) continue;
|
||||
final PsiFile psiFile = psiManager.findFile(openFile);
|
||||
if (psiFile != null) {
|
||||
result.add(psiFile);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
final Project project = e.getProject();
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setEnabled(!getFilesToAdd(project).isEmpty());
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
class AddAllOpenFilesToNewFavoritesListAction extends AnAction implements DumbAware {
|
||||
AddAllOpenFilesToNewFavoritesListAction() {
|
||||
super(IdeBundle.messagePointer("action.add.all.open.tabs.to.new.favorites.list"),
|
||||
IdeBundle.messagePointer("action.add.to.new.favorites.list"), AllIcons.General.Add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final String newName = AddNewFavoritesListAction.doAddNewFavoritesList(e.getProject());
|
||||
if (newName != null) {
|
||||
new AddAllOpenFilesToFavorites(newName).actionPerformed(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
}
|
||||
else {
|
||||
e.getPresentation().setEnabled(!AddAllOpenFilesToFavorites.getFilesToAdd(project).isEmpty());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Separator;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddAllToFavoritesActionGroup extends ActionGroup implements DumbAware {
|
||||
@Override
|
||||
public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
|
||||
if (e == null) return AnAction.EMPTY_ARRAY;
|
||||
final Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return AnAction.EMPTY_ARRAY;
|
||||
}
|
||||
final List<String> listNames = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
final List<String> availableFavoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
availableFavoritesLists.remove(e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY));
|
||||
if (availableFavoritesLists.isEmpty()) {
|
||||
return new AnAction[]{new AddAllOpenFilesToNewFavoritesListAction()};
|
||||
}
|
||||
|
||||
AnAction[] actions = new AnAction[listNames.size() + 2];
|
||||
int idx = 0;
|
||||
for (String favoritesList : listNames) {
|
||||
actions[idx++] = new AddAllOpenFilesToFavorites(favoritesList);
|
||||
}
|
||||
actions[idx++] = Separator.getInstance();
|
||||
actions[idx] = new AddAllOpenFilesToNewFavoritesListAction();
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
super.update(e);
|
||||
e.getPresentation().setEnabled(AddToFavoritesAction.canCreateNodes(e));
|
||||
}
|
||||
}
|
||||
@@ -1,69 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.InputValidator;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddNewFavoritesListAction extends AnAction implements DumbAware {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabledAndVisible(Registry.is("ide.favorites.tool.window.applicable", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final Project project = e.getProject();
|
||||
if (project != null) {
|
||||
doAddNewFavoritesList(project);
|
||||
}
|
||||
}
|
||||
|
||||
public static String doAddNewFavoritesList(final Project project) {
|
||||
final FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
final String name = Messages.showInputDialog(project,
|
||||
IdeBundle.message("prompt.input.new.favorites.list.name"),
|
||||
IdeBundle.message("title.add.new.favorites.list"),
|
||||
Messages.getInformationIcon(),
|
||||
getUniqueName(project), new InputValidator() {
|
||||
@Override
|
||||
public boolean checkInput(String inputString) {
|
||||
return inputString != null && inputString.trim().length() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canClose(String inputString) {
|
||||
inputString = inputString.trim();
|
||||
if (favoritesManager.getAvailableFavoritesListNames().contains(inputString)) {
|
||||
Messages.showErrorDialog(project,
|
||||
IdeBundle.message("error.favorites.list.already.exists", inputString.trim()),
|
||||
IdeBundle.message("title.unable.to.add.favorites.list"));
|
||||
return false;
|
||||
}
|
||||
return inputString.length() > 0;
|
||||
}
|
||||
});
|
||||
if (name == null || name.length() == 0) return null;
|
||||
favoritesManager.createNewList(name);
|
||||
return name;
|
||||
}
|
||||
|
||||
private static String getUniqueName(Project project) {
|
||||
List<String> names = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
for (int i = 0; ; i++) {
|
||||
String newName = IdeBundle.message("favorites.list.unnamed", i > 0 ? i : "");
|
||||
if (names.contains(newName)) continue;
|
||||
return newName;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,8 +3,6 @@
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoriteNodeProvider;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.ide.projectView.ProjectView;
|
||||
import com.intellij.ide.projectView.ProjectViewNode;
|
||||
import com.intellij.ide.projectView.ProjectViewSettings;
|
||||
@@ -16,9 +14,7 @@ import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiDirectory;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -26,37 +22,23 @@ import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiManager;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
|
||||
public class AddToFavoritesAction extends AnAction implements DumbAware {
|
||||
@Deprecated(forRemoval = true)
|
||||
/**
|
||||
* @deprecated Stub left for plugin API compatibility
|
||||
*/
|
||||
public class AddToFavoritesAction extends AnAction {
|
||||
private static final Logger LOG = Logger.getInstance(AddToFavoritesAction.class);
|
||||
|
||||
private final String myFavoritesListName;
|
||||
|
||||
public AddToFavoritesAction(String choosenList) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
getTemplatePresentation().setText(choosenList, false);
|
||||
myFavoritesListName = choosenList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public @NotNull ActionUpdateThread getActionUpdateThread() {
|
||||
return ActionUpdateThread.BGT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
|
||||
Collection<AbstractTreeNode<?>> nodesToAdd = getNodesToAdd(dataContext, true);
|
||||
if (!nodesToAdd.isEmpty()) {
|
||||
Project project = e.getProject();
|
||||
FavoritesManager.getInstance(project).addRoots(myFavoritesListName, nodesToAdd);
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -85,38 +67,6 @@ public class AddToFavoritesAction extends AnAction implements DumbAware {
|
||||
return nodesToAdd == null ? Collections.emptyList() : nodesToAdd;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setEnabled(canCreateNodes(e, myFavoritesListName));
|
||||
}
|
||||
|
||||
public static boolean canCreateNodes(@NotNull AnActionEvent e) {
|
||||
return canCreateNodes(e, null);
|
||||
}
|
||||
|
||||
public static boolean canCreateNodes(@NotNull AnActionEvent e, @Nullable String listName) {
|
||||
DataContext dataContext = e.getDataContext();
|
||||
if (e.getProject() == null) {
|
||||
return false;
|
||||
}
|
||||
if (e.getPlace().equals(ActionPlaces.FAVORITES_VIEW_POPUP)
|
||||
&& FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext) == null) {
|
||||
return false;
|
||||
}
|
||||
final boolean inProjectView = e.getPlace().equals(ActionPlaces.J2EE_VIEW_POPUP) ||
|
||||
e.getPlace().equals(ActionPlaces.STRUCTURE_VIEW_POPUP) ||
|
||||
e.getPlace().equals(ActionPlaces.PROJECT_VIEW_POPUP);
|
||||
//com.intellij.openapi.actionSystem.ActionPlaces.USAGE_VIEW_TOOLBAR
|
||||
Collection<AbstractTreeNode<?>> nodes = getNodesToAdd(dataContext, inProjectView);
|
||||
if (listName != null && !nodes.isEmpty()) {
|
||||
return FavoritesManager.getInstance(e.getProject()).canAddRoots(listName, nodes);
|
||||
}
|
||||
return !nodes.isEmpty();
|
||||
}
|
||||
|
||||
static Object retrieveData(Object object, Object data) {
|
||||
return object == null ? data : object;
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.openapi.actionSystem.ActionGroup;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Separator;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.IndexNotReadyException;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddToFavoritesActionGroup extends ActionGroup implements DumbAware {
|
||||
|
||||
@Override
|
||||
public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
|
||||
if (e == null) return AnAction.EMPTY_ARRAY;
|
||||
final Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return AnAction.EMPTY_ARRAY;
|
||||
}
|
||||
final List<String> availableFavoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
availableFavoritesLists.remove(e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY));
|
||||
if (availableFavoritesLists.isEmpty()) {
|
||||
return new AnAction[]{new AddToNewFavoritesListAction()};
|
||||
}
|
||||
|
||||
AnAction[] actions = new AnAction[availableFavoritesLists.size() + 2];
|
||||
int idx = 0;
|
||||
for (String favoritesList : availableFavoritesLists) {
|
||||
actions[idx++] = new AddToFavoritesAction(favoritesList);
|
||||
}
|
||||
actions[idx++] = Separator.getInstance();
|
||||
actions[idx] = new AddToNewFavoritesListAction();
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
super.update(e);
|
||||
try {
|
||||
e.getPresentation().setVisible(AddToFavoritesAction.canCreateNodes(e));
|
||||
}
|
||||
catch (IndexNotReadyException e1) {
|
||||
e.getPresentation().setVisible(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.actions.QuickSwitchSchemeAction;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class AddToFavoritesPopupAction extends QuickSwitchSchemeAction implements DumbAware {
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setEnabledAndVisible(Registry.is("ide.favorites.tool.window.applicable", false));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void fillActions(Project project, @NotNull DefaultActionGroup group, @NotNull DataContext dataContext) {
|
||||
group.removeAll();
|
||||
|
||||
final List<String> availableFavoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
availableFavoritesLists.remove(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext));
|
||||
|
||||
for (String favoritesList : availableFavoritesLists) {
|
||||
group.add(new AddToFavoritesAction(favoritesList));
|
||||
}
|
||||
group.add(new AddToNewFavoritesListAction());
|
||||
}
|
||||
}
|
||||
@@ -1,44 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
class AddToNewFavoritesListAction extends AnAction implements DumbAware {
|
||||
AddToNewFavoritesListAction() {
|
||||
super(IdeBundle.messagePointer("action.add.to.new.favorites.list"),
|
||||
IdeBundle.messagePointer("action.add.to.new.favorites.list.description"), AllIcons.General.Add);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
Collection<AbstractTreeNode<?>> nodesToAdd = AddToFavoritesAction.getNodesToAdd(e.getDataContext(), true);
|
||||
if (!nodesToAdd.isEmpty()) {
|
||||
final String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
|
||||
if (newName != null) {
|
||||
FavoritesManager.getInstance(project).addRoots(newName, nodesToAdd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setEnabled(AddToFavoritesAction.canCreateNodes(e));
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
// Copyright 2000-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.dnd.aware.DnDAwareTree;
|
||||
import com.intellij.ide.favoritesTreeView.*;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.AnActionButton;
|
||||
import com.intellij.ui.CommonActionsPanel;
|
||||
import com.intellij.util.IconUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author anna
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class DeleteFromFavoritesAction extends AnActionButton implements DumbAware {
|
||||
private static final Logger LOG = Logger.getInstance(DeleteFromFavoritesAction.class);
|
||||
|
||||
public DeleteFromFavoritesAction() {
|
||||
super(IdeBundle.messagePointer("action.remove.from.current.favorites"), IconUtil.getRemoveIcon());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = e.getProject();
|
||||
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
|
||||
if (project == null || builder == null) {
|
||||
return;
|
||||
}
|
||||
Set<Object> selection = builder.getSelectedElements();
|
||||
if (selection.isEmpty()) {
|
||||
return;
|
||||
}
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
|
||||
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
|
||||
if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection)) {
|
||||
provider.handle(CommonActionsPanel.Buttons.REMOVE, project, selection, builder.getTree());
|
||||
return;
|
||||
}
|
||||
FavoriteTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
|
||||
final DnDAwareTree tree = FavoritesTreeViewPanel.FAVORITES_TREE_KEY.getData(dataContext);
|
||||
|
||||
assert roots != null && tree != null;
|
||||
Map<String, List<AbstractTreeNode<?>>> toRemove = new HashMap<>();
|
||||
for (FavoriteTreeNodeDescriptor root : roots) {
|
||||
final AbstractTreeNode node = root.getElement();
|
||||
if (node instanceof FavoritesListNode) {
|
||||
favoritesManager.removeFavoritesList((String)node.getValue());
|
||||
}
|
||||
else {
|
||||
final FavoritesListNode listNode = FavoritesTreeUtil.extractParentList(root);
|
||||
LOG.assertTrue(listNode != null);
|
||||
final String name = listNode.getName();
|
||||
if (!toRemove.containsKey(name)) {
|
||||
toRemove.put(name, new ArrayList<>());
|
||||
}
|
||||
toRemove.get(name).add(node);
|
||||
}
|
||||
}
|
||||
|
||||
for (String name : toRemove.keySet()) {
|
||||
favoritesManager.removeRoot(name, toRemove.get(name));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateButton(@NotNull AnActionEvent e) {
|
||||
e.getPresentation().setText(getTemplatePresentation().getText());
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = e.getProject();
|
||||
FavoritesViewTreeBuilder builder = FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY.getData(dataContext);
|
||||
if (project == null || builder == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
Set<Object> selection = builder.getSelectedElements();
|
||||
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
|
||||
if (listName == null) {//Selection is empty or contains several items under favorites/bookmarks/breakpoints at the same time
|
||||
e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
|
||||
if (provider != null) {
|
||||
boolean willHandle = provider.willHandle(CommonActionsPanel.Buttons.REMOVE, project, selection);
|
||||
e.getPresentation().setEnabled(willHandle);
|
||||
if (willHandle) {
|
||||
e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.REMOVE));
|
||||
} else {
|
||||
e.getPresentation().setText(CommonActionsPanel.Buttons.REMOVE.getText());
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
FavoriteTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
|
||||
|
||||
if (roots == null || roots.length == 0 || selection.isEmpty()) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
for (Object o : selection) {
|
||||
if (o instanceof AbstractTreeNode) {
|
||||
AbstractTreeNode node = (AbstractTreeNode)o;
|
||||
int deep = getDeep(node);
|
||||
if (deep != 2 && deep != 3) {//favorite list or it's nested "root"
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static int getDeep(AbstractTreeNode node) {
|
||||
int result = 0;
|
||||
while (node != null) {
|
||||
node = node.getParent();
|
||||
result++;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
@@ -1,61 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesListProvider;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.ui.CommonActionsPanel;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
public class EditFavoritesAction extends AnAction implements DumbAware {
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
FavoritesViewTreeBuilder treeBuilder = e.getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY);
|
||||
String listName = e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY);
|
||||
if (project == null || treeBuilder == null || listName == null) {
|
||||
return;
|
||||
}
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
|
||||
Set<Object> selection = treeBuilder.getSelectedElements();
|
||||
if (provider != null && provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection)) {
|
||||
provider.handle(CommonActionsPanel.Buttons.EDIT, project, selection, treeBuilder.getTree());
|
||||
return;
|
||||
}
|
||||
favoritesManager.renameList(project, listName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setText(getTemplatePresentation().getText());
|
||||
e.getPresentation().setIcon(CommonActionsPanel.Buttons.EDIT.getIcon());
|
||||
e.getPresentation().setEnabled(true);
|
||||
Project project = e.getProject();
|
||||
FavoritesViewTreeBuilder treeBuilder = e.getData(FavoritesTreeViewPanel.FAVORITES_TREE_BUILDER_KEY);
|
||||
String listName = e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY);
|
||||
if (project == null || treeBuilder == null || listName == null) {
|
||||
e.getPresentation().setEnabled(false);
|
||||
return;
|
||||
}
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
FavoritesListProvider provider = favoritesManager.getListProvider(listName);
|
||||
Set<Object> selection = treeBuilder.getSelectedElements();
|
||||
if (provider != null) {
|
||||
e.getPresentation().setEnabled(provider.willHandle(CommonActionsPanel.Buttons.EDIT, project, selection));
|
||||
e.getPresentation().setText(provider.getCustomName(CommonActionsPanel.Buttons.EDIT));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public class FavoritesAbbreviatePackageNamesAction extends FavoritesToolbarButtonAction {
|
||||
public FavoritesAbbreviatePackageNamesAction(Project project, FavoritesViewTreeBuilder builder) {
|
||||
super(project, builder, IdeBundle.message("action.abbreviate.qualified.package.names"), AllIcons.ObjectBrowser.AbbreviatePackageNames);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionEnabled() {
|
||||
return getViewSettings().isAbbreviatePackageNames();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(boolean enabled) {
|
||||
getViewSettings().setAbbreviateQualifiedPackages(enabled);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateButton(@NotNull AnActionEvent e) {
|
||||
super.updateButton(e);
|
||||
boolean visible = getViewSettings().isFlattenPackages();
|
||||
e.getPresentation().setVisible(visible);
|
||||
setVisible(visible);
|
||||
}
|
||||
}
|
||||
@@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.ui.AutoScrollToSourceHandler;
|
||||
import com.intellij.ui.UIBundle;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesAutoScrollToSourceAction extends FavoritesToolbarButtonAction {
|
||||
private final AutoScrollToSourceHandler myAutoScrollToSourceHandler;
|
||||
|
||||
public FavoritesAutoScrollToSourceAction(Project project,
|
||||
AutoScrollToSourceHandler autoScrollToSourceHandler,
|
||||
FavoritesViewTreeBuilder builder) {
|
||||
super(project, builder, UIBundle.message("autoscroll.to.source.action.name"), AllIcons.General.AutoscrollToSource);
|
||||
myAutoScrollToSourceHandler = autoScrollToSourceHandler;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionEnabled() {
|
||||
return getViewSettings().isAutoScrollToSource();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(boolean enabled) {
|
||||
getViewSettings().setAutoScrollToSource(enabled);
|
||||
if (enabled) {
|
||||
myAutoScrollToSourceHandler.onMouseClicked(getBuilder().getTree());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,47 +0,0 @@
|
||||
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Presentation;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesCompactEmptyMiddlePackagesAction extends FavoritesToolbarButtonAction {
|
||||
public FavoritesCompactEmptyMiddlePackagesAction(Project project, FavoritesViewTreeBuilder builder) {
|
||||
super(project, builder,
|
||||
IdeBundle.message("action.compact.empty.middle.packages"),
|
||||
AllIcons.ObjectBrowser.CompactEmptyPackages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateButton(@NotNull AnActionEvent e) {
|
||||
super.updateButton(e);
|
||||
Presentation presentation = e.getPresentation();
|
||||
// see com.intellij.ide.projectView.impl.ProjectViewImpl.HideEmptyMiddlePackagesAction.update
|
||||
if (getViewSettings().isFlattenPackages()) {
|
||||
presentation.setText(IdeBundle.messagePointer("action.hide.empty.middle.packages"));
|
||||
presentation.setDescription(IdeBundle.messagePointer("action.show.hide.empty.middle.packages"));
|
||||
}
|
||||
else {
|
||||
presentation.setText(IdeBundle.messagePointer("action.compact.empty.middle.packages"));
|
||||
presentation.setDescription(IdeBundle.messagePointer("action.show.compact.empty.middle.packages"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionEnabled() {
|
||||
return getViewSettings().isHideEmptyMiddlePackages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(boolean hide) {
|
||||
getViewSettings().setHideEmptyMiddlePackages(hide);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesFlattenPackagesAction extends FavoritesToolbarButtonAction {
|
||||
public FavoritesFlattenPackagesAction(Project project, FavoritesViewTreeBuilder builder) {
|
||||
super(project, builder, IdeBundle.message("action.flatten.packages"), AllIcons.ObjectBrowser.FlattenPackages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionEnabled() {
|
||||
return getViewSettings().isFlattenPackages();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(boolean enabled) {
|
||||
getViewSettings().setFlattenPackages(enabled);
|
||||
}
|
||||
}
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2011 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.icons.AllIcons;
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.project.Project;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public class FavoritesShowMembersAction extends FavoritesToolbarButtonAction {
|
||||
public FavoritesShowMembersAction(Project project, FavoritesViewTreeBuilder builder) {
|
||||
super(project, builder, IdeBundle.message("action.show.members"), AllIcons.ObjectBrowser.ShowMembers);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOptionEnabled() {
|
||||
return getViewSettings().isShowMembers();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setOption(boolean enabled) {
|
||||
getViewSettings().setShowMembers(enabled);
|
||||
}
|
||||
}
|
||||
@@ -1,67 +0,0 @@
|
||||
// Copyright 2000-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewSettings;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesViewTreeBuilder;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.Toggleable;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
import com.intellij.ui.AnActionButton;
|
||||
import org.jetbrains.annotations.Nls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import javax.swing.*;
|
||||
|
||||
import static com.intellij.openapi.actionSystem.ActionPlaces.isPopupPlace;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
public abstract class FavoritesToolbarButtonAction extends AnActionButton implements Toggleable, DumbAware {
|
||||
private FavoritesViewTreeBuilder myBuilder;
|
||||
private FavoritesViewSettings mySettings;
|
||||
|
||||
public FavoritesToolbarButtonAction(Project project, FavoritesViewTreeBuilder builder,
|
||||
@Nls(capitalization = Nls.Capitalization.Title) String name, Icon icon) {
|
||||
super(name, icon);
|
||||
myBuilder = builder;
|
||||
mySettings = FavoritesManager.getInstance(project).getViewSettings();
|
||||
setContextComponent(myBuilder.getTree());
|
||||
Disposer.register(project, new Disposable() {
|
||||
@Override
|
||||
public void dispose() {
|
||||
myBuilder = null;
|
||||
mySettings = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public abstract boolean isOptionEnabled();
|
||||
|
||||
public abstract void setOption(boolean enabled);
|
||||
|
||||
public FavoritesViewSettings getViewSettings() {
|
||||
return mySettings;
|
||||
}
|
||||
|
||||
public FavoritesViewTreeBuilder getBuilder() {
|
||||
return myBuilder;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
setOption(!isOptionEnabled());
|
||||
myBuilder.updateFromRootCB();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateButton(@NotNull AnActionEvent e) {
|
||||
super.updateButton(e);
|
||||
Toggleable.setSelected(e.getPresentation(), isOptionEnabled());
|
||||
if (isPopupPlace(e.getPlace())) e.getPresentation().setIcon(null);
|
||||
}
|
||||
}
|
||||
@@ -1,85 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoriteTreeNodeDescriptor;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesListNode;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.ide.util.treeView.AbstractTreeNode;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DataContext;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
public final class SendToFavoritesAction extends AnAction implements DumbAware {
|
||||
private final String toName;
|
||||
|
||||
public SendToFavoritesAction(String name) {
|
||||
//noinspection HardCodedStringLiteral
|
||||
super(name);
|
||||
toName = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = e.getProject();
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
|
||||
FavoriteTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
|
||||
if (roots == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
for (FavoriteTreeNodeDescriptor root : roots) {
|
||||
FavoriteTreeNodeDescriptor listNode = root.getFavoritesRoot();
|
||||
if (listNode != null && listNode !=root && listNode.getElement() instanceof FavoritesListNode) {
|
||||
doSend(favoritesManager, new FavoriteTreeNodeDescriptor[]{root}, listNode.getElement().getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void doSend(FavoritesManager favoritesManager, FavoriteTreeNodeDescriptor[] roots, final String listName) {
|
||||
for (FavoriteTreeNodeDescriptor root : roots) {
|
||||
AbstractTreeNode<?> rootElement = root.getElement();
|
||||
String name = listName;
|
||||
if (name == null) {
|
||||
name = root.getFavoritesRoot().getName();
|
||||
}
|
||||
favoritesManager.removeRoot(name, Collections.singletonList(rootElement));
|
||||
favoritesManager.addRoots(toName, Collections.singletonList(rootElement));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
e.getPresentation().setEnabled(isEnabled(e));
|
||||
}
|
||||
|
||||
static boolean isEnabled(@NotNull AnActionEvent e) {
|
||||
Project project = e.getProject();
|
||||
if (project == null) {
|
||||
return false;
|
||||
}
|
||||
FavoriteTreeNodeDescriptor[] roots = e.getData(FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY);
|
||||
if (roots == null || roots.length == 0) {
|
||||
return false;
|
||||
}
|
||||
for (FavoriteTreeNodeDescriptor root : roots) {
|
||||
FavoriteTreeNodeDescriptor listNode = root.getFavoritesRoot();
|
||||
if (listNode == null || listNode ==root || !(listNode.getElement() instanceof FavoritesListNode))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,71 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
|
||||
package com.intellij.ide.favoritesTreeView.actions;
|
||||
|
||||
import com.intellij.ide.IdeBundle;
|
||||
import com.intellij.ide.favoritesTreeView.FavoriteTreeNodeDescriptor;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesManager;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class SendToFavoritesGroup extends ActionGroup implements DumbAware {
|
||||
@Override
|
||||
public AnAction @NotNull [] getChildren(@Nullable AnActionEvent e) {
|
||||
if (e == null) {
|
||||
return EMPTY_ARRAY;
|
||||
}
|
||||
final Project project = e.getProject();
|
||||
final List<String> availableFavoritesLists = FavoritesManager.getInstance(project).getAvailableFavoritesListNames();
|
||||
availableFavoritesLists.remove(e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY));
|
||||
if (availableFavoritesLists.isEmpty()) {
|
||||
return new AnAction[]{new SendToNewFavoritesListAction()};
|
||||
}
|
||||
|
||||
List<AnAction> actions = new ArrayList<>();
|
||||
|
||||
for (String list : availableFavoritesLists) {
|
||||
actions.add(new SendToFavoritesAction(list));
|
||||
}
|
||||
actions.add(Separator.getInstance());
|
||||
actions.add(new SendToNewFavoritesListAction());
|
||||
return actions.toArray(AnAction.EMPTY_ARRAY);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update(@NotNull AnActionEvent e) {
|
||||
if (!Registry.is("ide.favorites.tool.window.applicable", false)) {
|
||||
e.getPresentation().setEnabledAndVisible(false);
|
||||
return;
|
||||
}
|
||||
super.update(e);
|
||||
e.getPresentation().setVisible(SendToFavoritesAction.isEnabled(e)
|
||||
&& e.getData(FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY) != null);
|
||||
}
|
||||
|
||||
private static class SendToNewFavoritesListAction extends AnAction {
|
||||
SendToNewFavoritesListAction() {
|
||||
super(IdeBundle.messagePointer("action.send.to.new.favorites.list"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void actionPerformed(@NotNull AnActionEvent e) {
|
||||
final DataContext dataContext = e.getDataContext();
|
||||
Project project = e.getProject();
|
||||
FavoriteTreeNodeDescriptor[] roots = FavoritesTreeViewPanel.CONTEXT_FAVORITES_ROOTS_DATA_KEY.getData(dataContext);
|
||||
String listName = FavoritesTreeViewPanel.FAVORITES_LIST_NAME_DATA_KEY.getData(dataContext);
|
||||
|
||||
String newName = AddNewFavoritesListAction.doAddNewFavoritesList(project);
|
||||
if (newName != null) {
|
||||
new SendToFavoritesAction(newName).doSend(FavoritesManager.getInstance(project), roots, listName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
// Copyright 2000-2021 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
|
||||
package com.intellij.ide.projectView.impl;
|
||||
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesPanel;
|
||||
import com.intellij.ide.favoritesTreeView.FavoritesTreeViewPanel;
|
||||
import com.intellij.openapi.project.DumbAware;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.registry.Registry;
|
||||
import com.intellij.openapi.wm.ToolWindow;
|
||||
import com.intellij.openapi.wm.ToolWindowFactory;
|
||||
import com.intellij.openapi.wm.ex.ToolWindowEx;
|
||||
import com.intellij.ui.content.Content;
|
||||
import com.intellij.ui.content.ContentManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author Konstantin Bulenkov
|
||||
*/
|
||||
final class FavoritesViewToolWindowFactory implements ToolWindowFactory, DumbAware {
|
||||
@Override
|
||||
public boolean isApplicable(@NotNull Project project) {
|
||||
return Registry.is("ide.favorites.tool.window.applicable", false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
|
||||
FavoritesTreeViewPanel panel = new FavoritesPanel(project).getPanel();
|
||||
panel.setupToolWindow((ToolWindowEx)toolWindow);
|
||||
ContentManager contentManager = toolWindow.getContentManager();
|
||||
Content content = contentManager.getFactory().createContent(panel, null, false);
|
||||
contentManager.addContent(content);
|
||||
}
|
||||
}
|
||||
@@ -31,48 +31,6 @@ import java.util.List;
|
||||
public final class DefaultSearchScopeProviders {
|
||||
private DefaultSearchScopeProviders() {}
|
||||
|
||||
public static class Favorites implements SearchScopeProvider {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return LangBundle.message("default.search.scope.favourites.display.name");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<SearchScope> getSearchScopes(@NotNull Project project, @NotNull DataContext dataContext) {
|
||||
FavoritesManager favoritesManager = FavoritesManager.getInstance(project);
|
||||
if (favoritesManager == null) return Collections.emptyList();
|
||||
List<SearchScope> result = new ArrayList<>();
|
||||
for (String favorite : favoritesManager.getAvailableFavoritesListNames()) {
|
||||
Collection<TreeItem<Pair<AbstractUrl, String>>> rootUrls = favoritesManager.getFavoritesListRootUrls(favorite);
|
||||
if (rootUrls.isEmpty()) continue; // ignore unused root
|
||||
result.add(new GlobalSearchScope(project) {
|
||||
@NotNull
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
return LangBundle.message("default.search.scope.favourite.display.name", favorite);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return ReadAction.compute(() -> favoritesManager.contains(favorite, file));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchInModuleContent(@NotNull Module aModule) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSearchInLibraries() {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CustomNamed implements SearchScopeProvider {
|
||||
@Override
|
||||
public String getDisplayName() {
|
||||
|
||||
@@ -10,7 +10,6 @@ experimental.toolbar.xamarin.title=Toolbar (Xamarin)
|
||||
editor.popup.menu.title=Editor Popup Menu
|
||||
|
||||
editor.tab.popup.menu.title=Editor Tab Popup Menu
|
||||
favorites.popup.title=Favorites View Popup Menu
|
||||
project.view.popup.menu.title=Project View Popup Menu
|
||||
commender.view.popup.menu.title=Commander View Popup Menu
|
||||
j2ee.view.popup.menu.title=Java EE View Popup Menu
|
||||
|
||||
@@ -82,7 +82,6 @@ public final class CustomActionsSchema implements PersistentStateComponent<Eleme
|
||||
idToName.put(IdeActions.GROUP_EDITOR_TAB_POPUP, ActionsTreeUtil.getEditorTabPopup());
|
||||
idToName.put(IdeActions.GROUP_PROJECT_VIEW_POPUP, ActionsTreeUtil.getProjectViewPopup());
|
||||
idToName.put(IdeActions.GROUP_SCOPE_VIEW_POPUP, ActionsTreeUtil.getScopeViewPopupMenu());
|
||||
idToName.put(IdeActions.GROUP_FAVORITES_VIEW_POPUP, ActionsTreeUtil.getFavoritesPopup());
|
||||
idToName.put(IdeActions.GROUP_COMMANDER_POPUP, ActionsTreeUtil.getCommanderPopup());
|
||||
idToName.put(IdeActions.GROUP_J2EE_VIEW_POPUP, ActionsTreeUtil.getJ2EEPopup());
|
||||
idToName.put(IdeActions.GROUP_NAVBAR_POPUP, ActionsTreeUtil.getNavigationBarPopupMenu());
|
||||
|
||||
@@ -773,10 +773,6 @@ public final class ActionsTreeUtil {
|
||||
return KeyMapBundle.message("editor.tab.popup.menu.title");
|
||||
}
|
||||
|
||||
@Nls
|
||||
public static String getFavoritesPopup() {
|
||||
return KeyMapBundle.message("favorites.popup.title");
|
||||
}
|
||||
|
||||
@Nls
|
||||
public static String getProjectViewPopup() {
|
||||
|
||||
@@ -37,14 +37,6 @@ group.LeftToolbarSideGroup.text=Left Side
|
||||
group.LeftToolbarSideGroupXamarin.text=Left Side (Xamarin)
|
||||
group.RightToolbarSideGroupXamarin.text=Right Side (Xamarin)
|
||||
action.SegmentedVcsControlAction.text=VCS Widget
|
||||
action.AddToFavoritesPopup.text=Add to Favorites
|
||||
action.AddToFavoritesPopup.description=Add selected node to favorites
|
||||
group.AddToFavorites.text=Add to F_avorites
|
||||
group.AddAllToFavorites.text=Add A_ll To Favorites
|
||||
action.AddNewFavoritesList.text=Add New Favorites List
|
||||
action.AddNewFavoritesList.description=Add New Favorites List
|
||||
action.EditFavorites.text=Rename Favorites List
|
||||
group.SendToFavoritesGroup.text=_Send to Favorites
|
||||
action.ActivateNavBar.text=Activate Navigation _Bar
|
||||
action.ActivateNavBar.description=Activate navigation bar
|
||||
action.CreateRunConfiguration.text=Create Run Configuration
|
||||
|
||||
@@ -575,7 +575,6 @@
|
||||
<customScopesProvider implementation="com.intellij.packageDependencies.DefaultScopesProvider" id="default" order="first"/>
|
||||
<customScopesProvider implementation="com.intellij.openapi.fileEditor.impl.OpenFilesScope$Provider" order="last"/>
|
||||
|
||||
<searchScopesProvider implementation="com.intellij.psi.search.DefaultSearchScopeProviders$Favorites"/>
|
||||
<searchScopesProvider implementation="com.intellij.psi.search.DefaultSearchScopeProviders$CustomNamed" order="last"/>
|
||||
|
||||
<refactoring.elementListenerProvider implementation="com.intellij.packageDependencies.ui.RefactoringScopeElementListenerProvider"/>
|
||||
@@ -948,8 +947,6 @@
|
||||
|
||||
<toolWindow id="Structure" anchor="left" icon="AllIcons.Toolwindows.ToolWindowStructure" secondary="true"
|
||||
factoryClass="com.intellij.ide.structureView.impl.StructureViewToolWindowFactory"/>
|
||||
<toolWindow id="Favorites" anchor="left" icon="AllIcons.Toolwindows.ToolWindowFavorites" secondary="true"
|
||||
factoryClass="com.intellij.ide.projectView.impl.FavoritesViewToolWindowFactory" order="after Structure"/>
|
||||
<toolWindow id="Bookmarks" anchor="left" icon="AllIcons.Toolwindows.ToolWindowBookmarks" secondary="true"
|
||||
factoryClass="com.intellij.ide.bookmark.ui.BookmarksViewFactory" order="after Structure"/>
|
||||
<toolWindowExtractorMode id="Bookmarks" mode="mirror"/>
|
||||
|
||||
@@ -1,11 +1,6 @@
|
||||
<idea-plugin>
|
||||
<actions>
|
||||
<action id="IncrementalSearch" class="com.intellij.codeInsight.navigation.actions.IncrementalSearchAction"/>
|
||||
<action id="AddToFavoritesPopup" class="com.intellij.ide.favoritesTreeView.actions.AddToFavoritesPopupAction"/>
|
||||
<group id="AddToFavorites" class="com.intellij.ide.favoritesTreeView.actions.AddToFavoritesActionGroup" popup="true"/>
|
||||
<group id="AddAllToFavorites" class="com.intellij.ide.favoritesTreeView.actions.AddAllToFavoritesActionGroup" popup="true"/>
|
||||
<action id="AddNewFavoritesList" class="com.intellij.ide.favoritesTreeView.actions.AddNewFavoritesListAction"/>
|
||||
<group id="SendToFavoritesGroup" class="com.intellij.ide.favoritesTreeView.actions.SendToFavoritesGroup" popup="true"/>
|
||||
|
||||
<action id="RunConfiguration" class="com.intellij.execution.actions.RunConfigurationsComboBoxAction"/>
|
||||
<action id="ChooseRunConfiguration" class="com.intellij.execution.actions.ChooseRunConfigurationPopupAction" icon="AllIcons.Actions.Execute"/>
|
||||
@@ -89,10 +84,6 @@
|
||||
<group id="NewProjectOrModuleGroup">
|
||||
</group>
|
||||
|
||||
<reference ref="AddToFavorites">
|
||||
<add-to-group group-id="FileMenu" anchor="after" relative-to-action="PrintExportGroup"/>
|
||||
</reference>
|
||||
|
||||
<action id="SaveFileAsTemplate" class="com.intellij.ide.actions.SaveFileAsTemplateAction">
|
||||
<add-to-group group-id="FileMenu" anchor="after" relative-to-action="FileOtherSettingsGroup"/>
|
||||
</action>
|
||||
@@ -845,8 +836,6 @@
|
||||
<separator/>
|
||||
<reference ref="ProjectViewPopupMenuRefactoringGroup"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="ProjectViewPopupMenuModifyGroup"/>
|
||||
<separator/>
|
||||
<reference ref="ProjectViewPopupMenuRunGroup"/>
|
||||
@@ -872,9 +861,6 @@
|
||||
<separator/>
|
||||
<reference ref="ProjectViewPopupMenuRefactoringGroup"/>
|
||||
<separator/>
|
||||
<action id="EditFavorites" class="com.intellij.ide.favoritesTreeView.actions.EditFavoritesAction"/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<reference ref="SendToFavoritesGroup"/>
|
||||
<separator/>
|
||||
<reference ref="ProjectViewPopupMenuModifyGroup"/>
|
||||
<separator/>
|
||||
@@ -960,8 +946,6 @@
|
||||
<reference ref="FindUsages"/>
|
||||
<reference ref="RefactoringMenu"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="CutCopyPasteGroup"/>
|
||||
<separator/>
|
||||
<reference ref="RunContextPopupGroup"/>
|
||||
@@ -1009,8 +993,6 @@
|
||||
<reference ref="Scratch.ChangeLanguage"/>
|
||||
<reference ref="AssociateWithFileType"/>
|
||||
<reference ref="MarkFileAs"/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<reference ref="AddAllToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="RunContextPopupGroup"/>
|
||||
<separator/>
|
||||
@@ -1036,8 +1018,6 @@
|
||||
<separator/>
|
||||
<action id="UsageView.ShowRecentFindUsages" class="com.intellij.find.impl.ShowRecentFindUsagesAction" use-shortcut-of="ShowSearchHistory"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="RunContextGroup"/>
|
||||
<separator/>
|
||||
<reference ref="ExportToTextFile"/>
|
||||
@@ -1084,8 +1064,6 @@
|
||||
<reference ref="FindUsages"/>
|
||||
<reference ref="RefactoringMenu"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="RunContextPopupGroup"/>
|
||||
<separator/>
|
||||
<reference ref="ReformatCode"/>
|
||||
@@ -1555,7 +1533,7 @@
|
||||
</reference>
|
||||
|
||||
<action id="RenameFile" class="com.intellij.refactoring.actions.RenameFileAction">
|
||||
<add-to-group group-id="EditorTabPopupMenuEx" anchor="after" relative-to-action="AddAllToFavorites"/>
|
||||
<add-to-group group-id="EditorTabPopupMenuEx" anchor="last"/>
|
||||
</action>
|
||||
<action id="UpdateRunningApplication" class="com.intellij.execution.update.UpdateRunningApplicationAction">
|
||||
<keyboard-shortcut first-keystroke="control F10" keymap="$default"/>
|
||||
|
||||
@@ -1059,9 +1059,6 @@
|
||||
<action id="Vcs.ShowMessageHistory">
|
||||
<keyboard-shortcut first-keystroke="control M"/>
|
||||
</action>
|
||||
<action id="AddToFavoritesPopup">
|
||||
<keyboard-shortcut first-keystroke="alt shift F"/>
|
||||
</action>
|
||||
<action id="CodeInspection.OnEditor">
|
||||
<keyboard-shortcut first-keystroke="alt shift I"/>
|
||||
</action>
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
<keyboard-shortcut first-keystroke="alt 6"/>
|
||||
<keyboard-shortcut first-keystroke="control 6"/>
|
||||
</action>
|
||||
<action id="AddToFavoritesPopup"/>
|
||||
<action id="Back">
|
||||
<keyboard-shortcut first-keystroke="alt LEFT"/>
|
||||
<mouse-shortcut keystroke="button4"/>
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
<action id="ActivateVersionControlToolWindow">
|
||||
<keyboard-shortcut first-keystroke="shift ctrl g" />
|
||||
</action>
|
||||
<action id="AddToFavoritesPopup" />
|
||||
<action id="Arrangement.Alias.Rule.Edit" />
|
||||
<action id="Arrangement.Alias.Rule.Match.Condition.Move.Up" />
|
||||
<action id="Arrangement.Alias.Rule.Remove">
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
<action id="ActivateVersionControlToolWindow">
|
||||
<keyboard-shortcut first-keystroke="shift ctrl g" />
|
||||
</action>
|
||||
<action id="AddToFavoritesPopup" />
|
||||
<action id="Arrangement.Alias.Rule.Edit" />
|
||||
<action id="Arrangement.Alias.Rule.Match.Condition.Move.Up" />
|
||||
<action id="Arrangement.Rule.Edit" />
|
||||
|
||||
@@ -62,6 +62,5 @@
|
||||
<action id="NextTab" />
|
||||
<action id="PreviousTab" />
|
||||
<action id="WD.UploadCurrentRemoteFileAction" />
|
||||
<action id="AddToFavoritesPopup" />
|
||||
<action id="EditorAddCaretPerSelectedLine"/>
|
||||
</keymap>
|
||||
|
||||
@@ -192,8 +192,6 @@
|
||||
<separator/>
|
||||
<reference ref="VersionControlsGroup"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
</group>
|
||||
|
||||
<group id="GuiDesigner.ComponentTreePopupMenu">
|
||||
|
||||
@@ -229,8 +229,6 @@
|
||||
<reference ref="ShowPackageDepsGroup"/>
|
||||
<reference ref="RefactoringMenu"/>
|
||||
<separator/>
|
||||
<reference ref="AddToFavorites"/>
|
||||
<separator/>
|
||||
<reference ref="TypeHierarchy"/>
|
||||
<reference ref="ReformatCode"/>
|
||||
<reference ref="OptimizeImports"/>
|
||||
|
||||
Reference in New Issue
Block a user