From e816eb7e8436cbd28dac162e444600c0ac7f76fc Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 14 Mar 2012 16:00:11 +0100 Subject: [PATCH] Drop no longer needed path APIs --- .../newProjectWizard/SourcePathsStep.java | 4 +- .../configuration/JavaContentEntryEditor.java | 39 +++--- .../actions/GotoModuleDirectory.java | 31 +++-- .../ui/configuration/ContentEntryEditor.java | 131 +++--------------- .../ContentEntryTreeCellRenderer.java | 40 ++---- .../configuration/ContentEntryTreeEditor.java | 13 +- .../actions/ContentEntryEditingAction.java | 26 +--- .../actions/ToggleExcludedStateAction.java | 18 +-- .../actions/ToggleSourcesStateAction.java | 20 +-- .../fileChooser/FileChooserDescriptor.java | 24 ++-- .../openapi/fileChooser/FileSystemTree.java | 3 - .../src/com/intellij/openapi/vfs/VfsUtil.java | 5 + .../fileChooser/actions/GotoHomeAction.java | 25 ++-- .../actions/GotoProjectDirectory.java | 6 +- .../fileChooser/ex/FileChooserDialogImpl.java | 6 +- .../fileChooser/ex/FileSystemTreeImpl.java | 46 ++---- .../fileChooser/impl/FileTreeStructure.java | 7 +- .../platform/FilesystemToolwindow.java | 4 +- .../cvsSupport2/ui/MigrateRootDialog.java | 7 +- .../ui/experts/SelectLocationStep.java | 7 +- .../wholeTree/VcsStructureChooser.java | 7 +- .../compiler/GroovyCompilerConfigurable.java | 18 ++- 22 files changed, 178 insertions(+), 309 deletions(-) diff --git a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SourcePathsStep.java b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SourcePathsStep.java index 27dc7c177cbd..c24cee3db639 100644 --- a/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SourcePathsStep.java +++ b/java/idea-ui/src/com/intellij/ide/util/newProjectWizard/SourcePathsStep.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -380,7 +380,7 @@ public class SourcePathsStep extends AbstractStepWithProgress 0) { append(" (" + prefix + ")", new SimpleTextAttributes(Font.PLAIN, Color.GRAY)); } - setIcon(updateIcon(contentEntry, path, getIcon(), expanded)); + setIcon(updateIcon(contentEntry, file, getIcon(), expanded)); } } } @@ -65,38 +63,36 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer { } } - private static String getPrefix(final ContentEntry entry, final String path) { + private static String getPrefix(final ContentEntry entry, final VirtualFile file) { for (final SourceFolder sourceFolder : entry.getSourceFolders()) { - final String sourcePath = VfsUtil.urlToPath(sourceFolder.getUrl()); - if (FileUtil.pathsEqual(sourcePath, path, true)) { + if (file.equals(sourceFolder.getFile())) { return sourceFolder.getPackagePrefix(); } } return ""; } - protected Icon updateIcon(final ContentEntry entry, final String path, final Icon originalIcon, final boolean expanded) { + protected Icon updateIcon(final ContentEntry entry, final VirtualFile file, Icon originalIcon, final boolean expanded) { for (ExcludeFolder excludeFolder : entry.getExcludeFolders()) { - final String excludePath = VfsUtil.urlToPath(excludeFolder.getUrl()); - if (FileUtil.isAncestor(excludePath, path, false)) { + final VirtualFile excludePath = excludeFolder.getFile(); + if (excludePath != null && VfsUtilCore.isAncestor(excludePath, file, false)) { return IconSet.getExcludeIcon(expanded); } } final SourceFolder[] sourceFolders = entry.getSourceFolders(); for (SourceFolder sourceFolder : sourceFolders) { - final String sourcePath = VfsUtil.urlToPath(sourceFolder.getUrl()); - if (FileUtil.pathsEqual(sourcePath, path, true)) { + if (file.equals(sourceFolder.getFile())) { return IconSet.getSourceRootIcon(sourceFolder.isTestSource(), expanded); } } Icon icon = originalIcon; - String currentRoot = null; + VirtualFile currentRoot = null; for (SourceFolder sourceFolder : sourceFolders) { - final String sourcePath = VfsUtil.urlToPath(sourceFolder.getUrl()); - if (FileUtil.isAncestor(sourcePath, path, true)) { - if (currentRoot != null && FileUtil.isAncestor(sourcePath, currentRoot, false)) { + final VirtualFile sourcePath = sourceFolder.getFile(); + if (sourcePath != null && VfsUtilCore.isAncestor(sourcePath, file, true)) { + if (currentRoot != null && VfsUtilCore.isAncestor(sourcePath, currentRoot, false)) { continue; } icon = IconSet.getSourceFolderIcon(sourceFolder.isTestSource(), expanded); @@ -105,10 +101,4 @@ public class ContentEntryTreeCellRenderer extends NodeRenderer { } return icon; } - - /** @deprecated use {@linkplain #updateIcon(com.intellij.openapi.roots.ContentEntry, String, javax.swing.Icon, boolean)} (to remove in IDEA 12) */ - @SuppressWarnings("UnusedDeclaration") - protected Icon updateIcon(final ContentEntry entry, final VirtualFile file, Icon originalIcon, final boolean expanded) { - return updateIcon(entry, file.getPath(), originalIcon, expanded); - } } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java index 961746901049..7e062e845320 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/ContentEntryTreeEditor.java @@ -33,16 +33,14 @@ import com.intellij.openapi.fileChooser.ex.FileSystemTreeImpl; import com.intellij.openapi.fileChooser.impl.FileTreeBuilder; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; +import com.intellij.openapi.roots.ContentEntry; import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.roots.ui.configuration.actions.IconWithTextAction; import com.intellij.openapi.roots.ui.configuration.actions.ToggleExcludedStateAction; import com.intellij.openapi.roots.ui.configuration.actions.ToggleSourcesStateAction; import com.intellij.openapi.util.Disposer; import com.intellij.openapi.util.IconLoader; -import com.intellij.openapi.util.io.FileUtil; -import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.VirtualFileManager; import com.intellij.ui.ScrollPaneFactory; import com.intellij.ui.TreeSpeedSearch; import com.intellij.ui.roots.ToolbarPanel; @@ -143,14 +141,17 @@ public class ContentEntryTreeEditor { myContentEntryEditor = contentEntryEditor; myContentEntryEditor.addContentEntryEditorListener(myContentEntryEditorListener); - final String path = FileUtil.toSystemDependentName(VfsUtil.urlToPath(contentEntryEditor.getContentEntryUrl())); - myDescriptor.setRoots(path); + final ContentEntry entry = contentEntryEditor.getContentEntry(); + assert entry != null : contentEntryEditor; + final VirtualFile file = entry.getFile(); + assert file != null : entry; + myDescriptor.setRoots(file); final Runnable init = new Runnable() { public void run() { //noinspection ConstantConditions myFileSystemTree.updateTree(); - myFileSystemTree.select(null, path); + myFileSystemTree.select(file, null); } }; diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ContentEntryEditingAction.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ContentEntryEditingAction.java index 745d3e46d49b..1de6fc97a411 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ContentEntryEditingAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ContentEntryEditingAction.java @@ -25,14 +25,11 @@ import com.intellij.openapi.fileChooser.ex.FileNodeDescriptor; import com.intellij.openapi.project.DumbAware; import com.intellij.openapi.vfs.VirtualFile; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import javax.swing.*; import javax.swing.tree.DefaultMutableTreeNode; import javax.swing.tree.TreePath; import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; import java.util.List; /** @@ -51,8 +48,8 @@ public abstract class ContentEntryEditingAction extends ToggleAction implements super.update(e); final Presentation presentation = e.getPresentation(); presentation.setEnabled(true); - final VirtualFile[] files = doGetSelectedFiles(); - if (files == null || files.length == 0) { + final VirtualFile[] files = getSelectedFiles(); + if (files.length == 0) { presentation.setEnabled(false); return; } @@ -64,25 +61,18 @@ public abstract class ContentEntryEditingAction extends ToggleAction implements } } - /** @deprecated use {@linkplain #getSelectedPaths()} (to remove in IDEA 12) */ - @SuppressWarnings("UnusedDeclaration") - @Nullable + @NotNull protected final VirtualFile[] getSelectedFiles() { - return doGetSelectedFiles(); - } - - @Nullable - private VirtualFile[] doGetSelectedFiles() { final TreePath[] selectionPaths = myTree.getSelectionPaths(); if (selectionPaths == null) { - return null; + return VirtualFile.EMPTY_ARRAY; } final List selected = new ArrayList(); for (TreePath treePath : selectionPaths) { final DefaultMutableTreeNode node = (DefaultMutableTreeNode)treePath.getLastPathComponent(); final Object nodeDescriptor = node.getUserObject(); if (!(nodeDescriptor instanceof FileNodeDescriptor)) { - return null; + return VirtualFile.EMPTY_ARRAY; } final FileElement fileElement = ((FileNodeDescriptor)nodeDescriptor).getElement(); final VirtualFile file = fileElement.getFile(); @@ -94,12 +84,6 @@ public abstract class ContentEntryEditingAction extends ToggleAction implements return selected.toArray(new VirtualFile[selected.size()]); } - @NotNull - protected List getSelectedPaths() { - final VirtualFile[] files = doGetSelectedFiles(); - return files != null ? Arrays.asList(FileChooserUtil.filesToPaths(files)) : Collections.emptyList(); - } - public JComponent createCustomComponent(Presentation presentation) { return new ActionButtonWithText(this, presentation, ActionPlaces.UNKNOWN, ActionToolbar.DEFAULT_MINIMUM_BUTTON_SIZE); } diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleExcludedStateAction.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleExcludedStateAction.java index 47580a3c7636..ac351f615a70 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleExcludedStateAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleExcludedStateAction.java @@ -23,9 +23,9 @@ import com.intellij.openapi.roots.ExcludeFolder; import com.intellij.openapi.roots.ui.configuration.ContentEntryEditor; import com.intellij.openapi.roots.ui.configuration.ContentEntryTreeEditor; import com.intellij.openapi.roots.ui.configuration.IconSet; +import com.intellij.openapi.vfs.VirtualFile; import javax.swing.*; -import java.util.List; /** * @author Eugene Zhuravlev @@ -45,23 +45,23 @@ public class ToggleExcludedStateAction extends ContentEntryEditingAction { @Override public boolean isSelected(final AnActionEvent e) { - final List selectedPaths = getSelectedPaths(); - if (selectedPaths.size() == 0) return false; + final VirtualFile[] selectedFiles = getSelectedFiles(); + if (selectedFiles.length == 0) return false; final ContentEntryEditor editor = myEntryTreeEditor.getContentEntryEditor(); - return editor.isExcluded(selectedPaths.get(0)) || editor.isUnderExcludedDirectory(selectedPaths.get(0)); + return editor.isExcluded(selectedFiles[0]) || editor.isUnderExcludedDirectory(selectedFiles[0]); } @Override public void setSelected(final AnActionEvent e, final boolean isSelected) { - final List selectedPaths = getSelectedPaths(); - assert selectedPaths.size() != 0; + final VirtualFile[] selectedFiles = getSelectedFiles(); + assert selectedFiles.length != 0; - for (String selectedPath : selectedPaths) { - final ExcludeFolder excludeFolder = myEntryTreeEditor.getContentEntryEditor().getExcludeFolder(selectedPath); + for (VirtualFile selectedFile : selectedFiles) { + final ExcludeFolder excludeFolder = myEntryTreeEditor.getContentEntryEditor().getExcludeFolder(selectedFile); if (isSelected) { if (excludeFolder == null) { // not excluded yet - myEntryTreeEditor.getContentEntryEditor().addExcludeFolder(selectedPath); + myEntryTreeEditor.getContentEntryEditor().addExcludeFolder(selectedFile); } } else { diff --git a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleSourcesStateAction.java b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleSourcesStateAction.java index 383d794680d9..1bf6fc986296 100644 --- a/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleSourcesStateAction.java +++ b/platform/lang-impl/src/com/intellij/openapi/roots/ui/configuration/actions/ToggleSourcesStateAction.java @@ -23,9 +23,9 @@ import com.intellij.openapi.roots.SourceFolder; import com.intellij.openapi.roots.ui.configuration.ContentEntryEditor; import com.intellij.openapi.roots.ui.configuration.ContentEntryTreeEditor; import com.intellij.openapi.roots.ui.configuration.IconSet; +import com.intellij.openapi.vfs.VirtualFile; import javax.swing.*; -import java.util.List; /** * @author Eugene Zhuravlev @@ -54,29 +54,29 @@ public class ToggleSourcesStateAction extends ContentEntryEditingAction { @Override public boolean isSelected(final AnActionEvent e) { - final List selectedPaths = getSelectedPaths(); - if (selectedPaths.size() == 0) return false; + final VirtualFile[] selectedFiles = getSelectedFiles(); + if (selectedFiles.length == 0) return false; final ContentEntryEditor editor = myEntryTreeEditor.getContentEntryEditor(); - return myEditTestSources ? editor.isTestSource(selectedPaths.get(0)) : editor.isSource(selectedPaths.get(0)); + return myEditTestSources ? editor.isTestSource(selectedFiles[0]) : editor.isSource(selectedFiles[0]); } @Override public void setSelected(final AnActionEvent e, final boolean isSelected) { - final List selectedPaths = getSelectedPaths(); - assert selectedPaths.size() != 0; + final VirtualFile[] selectedFiles = getSelectedFiles(); + assert selectedFiles.length != 0; final ContentEntryEditor contentEntryEditor = myEntryTreeEditor.getContentEntryEditor(); - for (String selectedPath : selectedPaths) { - final SourceFolder sourceFolder = contentEntryEditor.getSourceFolder(selectedPath); + for (VirtualFile selectedFile : selectedFiles) { + final SourceFolder sourceFolder = contentEntryEditor.getSourceFolder(selectedFile); if (isSelected) { if (sourceFolder == null) { // not marked yet - contentEntryEditor.addSourceFolder(selectedPath, myEditTestSources); + contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources); } else { if (myEditTestSources != sourceFolder.isTestSource()) { contentEntryEditor.removeSourceFolder(sourceFolder); - contentEntryEditor.addSourceFolder(selectedPath, myEditTestSources); + contentEntryEditor.addSourceFolder(selectedFile, myEditTestSources); } } } diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java index bf12cf6ff321..d4b150d8dd76 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java +++ b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileChooserDescriptor.java @@ -46,7 +46,7 @@ public class FileChooserDescriptor implements Cloneable { private String myDescription; private boolean myHideIgnored = true; - private final List myRoots = new ArrayList(); + private final List myRoots = new ArrayList(); private boolean myShowFileSystemRoots = true; private boolean myIsTreeRootVisible = false; @@ -240,34 +240,30 @@ public class FileChooserDescriptor implements Cloneable { myHideIgnored = hideIgnored; } - @NotNull - public final List getRootPaths() { + public final List getRoots() { return Collections.unmodifiableList(myRoots); } - public final void setRoots(final String... roots) { + public final void setRoots(final VirtualFile... roots) { setRoots(Arrays.asList(roots)); } - public final void setRoots(@NotNull final Collection roots) { + public final void setRoots(@NotNull final List roots) { myRoots.clear(); myRoots.addAll(roots); } - /** @deprecated use {@linkplain #getRootPaths()} (to remove in IDEA 13) */ - public final List getRoots() { - return FileChooserUtil.pathsToFiles(myRoots, false); - } - - /** @deprecated use {@linkplain #setRoots(java.util.Collection)} (to remove in IDEA 13) */ + /** @deprecated use {@linkplain #setRoots(com.intellij.openapi.vfs.VirtualFile...)} (to remove in IDEA 13) */ + @SuppressWarnings("UnusedDeclaration") public final void setRoot(VirtualFile root) { myRoots.clear(); - myRoots.add(root.getPresentableUrl()); + myRoots.add(root); } - /** @deprecated use {@linkplain #setRoots(java.util.Collection)} (to remove in IDEA 13) */ + /** @deprecated use {@linkplain #setRoots(com.intellij.openapi.vfs.VirtualFile...)} (to remove in IDEA 13) */ + @SuppressWarnings("UnusedDeclaration") public final void addRoot(VirtualFile root) { - myRoots.add(root.getPresentableUrl()); + myRoots.add(root); } public boolean isTreeRootVisible() { diff --git a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileSystemTree.java b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileSystemTree.java index d96931259608..810dbbc55014 100644 --- a/platform/platform-api/src/com/intellij/openapi/fileChooser/FileSystemTree.java +++ b/platform/platform-api/src/com/intellij/openapi/fileChooser/FileSystemTree.java @@ -40,16 +40,13 @@ public interface FileSystemTree extends Disposable { @Nullable VirtualFile getNewFileParent(); - void select(@Nullable Runnable onDone, String... paths); void select(VirtualFile file, @Nullable Runnable onDone); void select(VirtualFile[] files, @Nullable Runnable onDone); - void expand(@NotNull String path, @Nullable final Runnable onDone); void expand(VirtualFile file, @Nullable Runnable onDone); void addListener(Listener listener, Disposable parent); - boolean isUnderRoots(@NotNull String path); boolean isUnderRoots(@NotNull VirtualFile file); boolean selectionExists(); diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index b874b47b5a77..437ac447146c 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -680,4 +680,9 @@ public class VfsUtil extends VfsUtilCore { //noinspection SSBasedInspection return files.toArray(new VirtualFile[size]); } + + @NotNull + public static String getReadableUrl(@NotNull final VirtualFile file) { + return file.isInLocalFileSystem() ? file.getPresentableUrl() : file.getUrl(); + } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoHomeAction.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoHomeAction.java index 2ef4de6fb911..f4c056f87ace 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoHomeAction.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoHomeAction.java @@ -18,21 +18,24 @@ package com.intellij.openapi.fileChooser.actions; import com.intellij.openapi.actionSystem.AnActionEvent; import com.intellij.openapi.actionSystem.Presentation; import com.intellij.openapi.fileChooser.FileSystemTree; -import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.util.io.FileUtil; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.SystemProperties; +import org.jetbrains.annotations.Nullable; /** * @author Vladimir Kondratyev */ public final class GotoHomeAction extends FileChooserAction { protected void actionPerformed(final FileSystemTree fileSystemTree, final AnActionEvent e) { - final String userHome = SystemProperties.getUserHome(); - if (!StringUtil.isEmptyOrSpaces(userHome)) { - fileSystemTree.select(new Runnable() { + final VirtualFile userHomeDir = getUserHomeDir(); + if (userHomeDir != null) { + fileSystemTree.select(userHomeDir, new Runnable() { public void run() { - fileSystemTree.expand(userHome, null); + fileSystemTree.expand(userHomeDir, null); } - }, userHome); + }); } } @@ -40,7 +43,13 @@ public final class GotoHomeAction extends FileChooserAction { final Presentation presentation = e.getPresentation(); if (!presentation.isEnabled()) return; - final String userHome = SystemProperties.getUserHome(); - presentation.setEnabled(!StringUtil.isEmptyOrSpaces(userHome) && fileSystemTree.isUnderRoots(userHome)); + final VirtualFile userHomeDir = getUserHomeDir(); + presentation.setEnabled(userHomeDir != null && fileSystemTree.isUnderRoots(userHomeDir)); + } + + @Nullable + private static VirtualFile getUserHomeDir() { + final String path = SystemProperties.getUserHome(); + return LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(path)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoProjectDirectory.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoProjectDirectory.java index 2ab644c8d4d7..329c0b59c2cf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoProjectDirectory.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/actions/GotoProjectDirectory.java @@ -30,7 +30,7 @@ public final class GotoProjectDirectory extends FileChooserAction { private static final Icon ourIcon = IconLoader.getIcon(ApplicationInfoEx.getInstanceEx().getSmallIconUrl()); protected void actionPerformed(final FileSystemTree fileSystemTree, final AnActionEvent e) { - final VirtualFile projectPath = getProjectPath(e); + final VirtualFile projectPath = getProjectDir(e); if (projectPath != null) { fileSystemTree.select(projectPath, new Runnable() { public void run() { @@ -43,12 +43,12 @@ public final class GotoProjectDirectory extends FileChooserAction { protected void update(final FileSystemTree fileSystemTree, final AnActionEvent e) { final Presentation presentation = e.getPresentation(); presentation.setIcon(ourIcon); - final VirtualFile projectPath = getProjectPath(e); + final VirtualFile projectPath = getProjectDir(e); presentation.setEnabled(projectPath != null && fileSystemTree.isUnderRoots(projectPath)); } @Nullable - private static VirtualFile getProjectPath(final AnActionEvent e) { + private static VirtualFile getProjectDir(final AnActionEvent e) { final VirtualFile projectFileDir = e.getData(PlatformDataKeys.PROJECT_FILE_DIRECTORY); return projectFileDir != null && projectFileDir.isValid() ? projectFileDir : null; } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java index f9db8480e404..b71165706695 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileChooserDialogImpl.java @@ -495,9 +495,9 @@ public class FileChooserDialogImpl extends DialogWrapper implements FileChooserD text = getFilePath(selection.get(0)); } else { - final List rootPaths = myChooserDescriptor.getRootPaths(); - if (!myFileSystemTree.getTree().isRootVisible() && rootPaths.size() == 1) { - text = rootPaths.get(0); + final List roots = myChooserDescriptor.getRoots(); + if (!myFileSystemTree.getTree().isRootVisible() && roots.size() == 1) { + text = VfsUtil.getReadableUrl(roots.get(0)); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java index 3f21a0b745c4..6621314ab483 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/ex/FileSystemTreeImpl.java @@ -36,10 +36,10 @@ import com.intellij.openapi.fileChooser.impl.FileTreeStructure; import com.intellij.openapi.fileTypes.FileType; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; -import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.JarFileSystem; import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VfsUtilCore; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.newvfs.NewVirtualFile; import com.intellij.openapi.vfs.newvfs.RefreshQueue; @@ -50,7 +50,6 @@ import com.intellij.ui.UIBundle; import com.intellij.ui.treeStructure.Tree; import com.intellij.util.Function; import com.intellij.util.NullableFunction; -import com.intellij.util.containers.ContainerUtil; import com.intellij.util.containers.Convertor; import com.intellij.util.ui.tree.TreeUtil; import org.jetbrains.annotations.NotNull; @@ -63,7 +62,6 @@ import javax.swing.event.TreeSelectionEvent; import javax.swing.event.TreeSelectionListener; import javax.swing.tree.*; import java.awt.event.*; -import java.io.File; import java.io.IOException; import java.util.*; @@ -245,20 +243,6 @@ public class FileSystemTreeImpl implements FileSystemTree { select(new VirtualFile[]{file}, onDone); } - @Override - public void select(@Nullable final Runnable onDone, final String... paths) { - final List elements = ContainerUtil.mapNotNull(paths, new NullableFunction() { - @Override - public Object fun(final String path) { - final VirtualFile file = FileChooserUtil.pathToFile(path, false); - return file != null ? getFileElementFor(file) : null; - } - }); - if (elements.size() > 0) { - myTreeBuilder.select(elements.toArray(), onDone); - } - } - public void select(VirtualFile[] file, @Nullable final Runnable onDone) { Object[] elements = new Object[file.length]; for (int i = 0; i < file.length; i++) { @@ -269,14 +253,6 @@ public class FileSystemTreeImpl implements FileSystemTree { myTreeBuilder.select(elements, onDone); } - @Override - public void expand(@NotNull final String path, @Nullable final Runnable onDone) { - final VirtualFile file = FileChooserUtil.pathToFile(path, false); - if (file != null) { - myTreeBuilder.expand(getFileElementFor(file), onDone); - } - } - public void expand(final VirtualFile file, @Nullable final Runnable onDone) { myTreeBuilder.expand(getFileElementFor(file), onDone); } @@ -373,8 +349,8 @@ public class FileSystemTreeImpl implements FileSystemTree { final VirtualFile selected = getSelectedFile(); if (selected != null) return selected; - final List rootPaths = myDescriptor.getRootPaths(); - return rootPaths.size() == 1 ? FileChooserUtil.pathToFile(rootPaths.get(0), false) : null; + final List roots = myDescriptor.getRoots(); + return roots.size() == 1 ? roots.get(0) : null; } @NotNull @@ -432,13 +408,12 @@ public class FileSystemTreeImpl implements FileSystemTree { } @Override - public boolean isUnderRoots(@NotNull final String path) { - final List rootPaths = myDescriptor.getRootPaths(); - if (rootPaths.size() == 0) return true; + public boolean isUnderRoots(@NotNull VirtualFile file) { + final List roots = myDescriptor.getRoots(); + if (roots.size() == 0) return true; - final File candidate = new File(FileUtil.toSystemDependentName(path)); - for (String rootPath : rootPaths) { - if (FileUtil.isAncestor(new File(FileUtil.toSystemDependentName(rootPath)), candidate, false)) { + for (VirtualFile root : roots) { + if (root != null && VfsUtilCore.isAncestor(root, file, false)) { return true; } } @@ -446,11 +421,6 @@ public class FileSystemTreeImpl implements FileSystemTree { return false; } - @Override - public boolean isUnderRoots(@NotNull VirtualFile file) { - return isUnderRoots(file.getPath()); - } - public void addListener(final Listener listener, final Disposable parent) { myListeners.add(listener); Disposer.register(parent, new Disposable() { diff --git a/platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileTreeStructure.java b/platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileTreeStructure.java index 54f177f89c10..5c636c86383e 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileTreeStructure.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileChooser/impl/FileTreeStructure.java @@ -21,7 +21,6 @@ import com.intellij.ide.util.treeView.AbstractTreeStructure; import com.intellij.ide.util.treeView.NodeDescriptor; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileChooser.FileChooserDescriptor; -import com.intellij.openapi.fileChooser.FileChooserUtil; import com.intellij.openapi.fileChooser.FileElement; import com.intellij.openapi.fileChooser.ex.FileNodeDescriptor; import com.intellij.openapi.fileChooser.ex.RootFileElement; @@ -36,7 +35,6 @@ import org.jetbrains.annotations.Nullable; import javax.swing.*; import java.util.HashSet; -import java.util.List; /** * @author Yura Cangea @@ -51,9 +49,8 @@ public class FileTreeStructure extends AbstractTreeStructure { public FileTreeStructure(Project project, FileChooserDescriptor chooserDescriptor) { myProject = project; - final List rootPaths = chooserDescriptor.getRootPaths(); - final String name = rootPaths.size() == 1 ? rootPaths.get(0) : chooserDescriptor.getTitle(); - final VirtualFile[] rootFiles = VfsUtil.toVirtualFileArray(FileChooserUtil.pathsToFiles(rootPaths, false)); + final VirtualFile[] rootFiles = VfsUtil.toVirtualFileArray(chooserDescriptor.getRoots()); + final String name = rootFiles.length == 1 && rootFiles[0] != null ? rootFiles[0].getPresentableUrl() : chooserDescriptor.getTitle(); myRootElement = new RootFileElement(rootFiles, name, chooserDescriptor.isShowFileSystemRoots()); myChooserDescriptor = chooserDescriptor; myShowHidden = PropertiesComponent.getInstance().getBoolean("FileChooser.showHiddens", false); diff --git a/platform/platform-impl/src/com/intellij/platform/FilesystemToolwindow.java b/platform/platform-impl/src/com/intellij/platform/FilesystemToolwindow.java index c7100dc9f83c..1b9e984030a5 100644 --- a/platform/platform-impl/src/com/intellij/platform/FilesystemToolwindow.java +++ b/platform/platform-impl/src/com/intellij/platform/FilesystemToolwindow.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -57,7 +57,7 @@ public class FilesystemToolwindow { myContent = new MyContent(); final FileChooserDescriptor descriptor = new FileChooserDescriptor(true, true, true, false, true, true); - descriptor.addRoot(myRoot); + descriptor.setRoots(myRoot); myFsTree = new FileSystemTreeImpl(project, descriptor); myContent.add(ScrollPaneFactory.createScrollPane(myFsTree.getTree()), BorderLayout.CENTER); diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/MigrateRootDialog.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/MigrateRootDialog.java index 5836be3db99f..e5bf1f6f8742 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/MigrateRootDialog.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/MigrateRootDialog.java @@ -1,5 +1,5 @@ /* - * Copyright 2011 JetBrains s.r.o. + * 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. @@ -70,10 +70,7 @@ public class MigrateRootDialog extends DialogWrapper { } } }; - final VirtualFile[] roots = ProjectRootManager.getInstance(project).getContentRootsFromAllModules(); - for (VirtualFile vFile : roots) { - descriptor.addRoot(vFile); - } + descriptor.setRoots(ProjectRootManager.getInstance(project).getContentRootsFromAllModules()); myDirectoryField.addBrowseFolderListener("Select directory to migrate to a new CVS root", "", project, descriptor); FileChooserFactory.getInstance().installFileCompletion(myDirectoryField.getChildComponent(), descriptor, true, getDisposable()); myDirectoryField.getTextField().getDocument().addDocumentListener(new DocumentListener() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectLocationStep.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectLocationStep.java index df31adfd5c5b..6ae1eb86259d 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectLocationStep.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/ui/experts/SelectLocationStep.java @@ -31,6 +31,7 @@ import com.intellij.openapi.fileChooser.ex.LocalFsFinder; import com.intellij.openapi.fileChooser.impl.FileChooserFactoryImpl; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Disposer; +import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.PopupHandler; import com.intellij.ui.ScrollPaneFactory; @@ -260,9 +261,9 @@ public abstract class SelectLocationStep extends WizardStep { } } else { - final List rootPaths = myChooserDescriptor.getRootPaths(); - if (!myFileSystemTree.getTree().isRootVisible() && rootPaths.size() == 1) { - text = rootPaths.get(0); + final List roots = myChooserDescriptor.getRoots(); + if (!myFileSystemTree.getTree().isRootVisible() && roots.size() == 1) { + text = VfsUtil.getReadableUrl(roots.get(0)); } } diff --git a/plugins/git4idea/src/git4idea/history/wholeTree/VcsStructureChooser.java b/plugins/git4idea/src/git4idea/history/wholeTree/VcsStructureChooser.java index 681b20622b51..49244b08f964 100644 --- a/plugins/git4idea/src/git4idea/history/wholeTree/VcsStructureChooser.java +++ b/plugins/git4idea/src/git4idea/history/wholeTree/VcsStructureChooser.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2011 JetBrains s.r.o. + * 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. @@ -33,7 +33,6 @@ import com.intellij.openapi.ui.Splitter; import com.intellij.openapi.util.Computable; import com.intellij.openapi.vcs.AbstractVcs; import com.intellij.openapi.vcs.FilePath; -import com.intellij.openapi.vcs.ProjectLevelVcsManager; import com.intellij.openapi.vcs.changes.ui.VirtualFileListCellRenderer; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.ui.*; @@ -163,9 +162,7 @@ public class VcsStructureChooser extends DialogWrapper { return path1.compareToIgnoreCase(path2); } }; - for (VirtualFile root : list) { - descriptor.addRoot(root); - } + descriptor.setRoots(list); myTree = new Tree(); myTree.setMinimumSize(new Dimension(200, 200)); myTree.setBorder(BORDER); diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java index efdaeefa51aa..9c82159f2b91 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerConfigurable.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2009 JetBrains s.r.o. + * 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. @@ -30,11 +30,15 @@ import com.intellij.openapi.roots.ProjectFileIndex; import com.intellij.openapi.roots.ProjectRootManager; import com.intellij.openapi.util.Comparing; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Function; +import com.intellij.util.containers.ContainerUtil; import org.jetbrains.annotations.Nls; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyIcons; import javax.swing.*; +import java.util.Arrays; +import java.util.List; /** * @author peter @@ -63,11 +67,13 @@ public class GroovyCompilerConfigurable implements SearchableConfigurable, Confi return super.isFileVisible(file, showHiddenFiles) && !index.isIgnored(file); } }; - for (final Module module: ModuleManager.getInstance(project).getModules()) { - for (VirtualFile file : ModuleRootManager.getInstance(module).getSourceRoots()) { - descriptor.addRoot(file); - } - } + descriptor.setRoots(ContainerUtil.concat( + ContainerUtil.map(ModuleManager.getInstance(project).getModules(), new Function>() { + @Override + public List fun(final Module module) { + return Arrays.asList(ModuleRootManager.getInstance(module).getSourceRoots()); + } + }))); return new ExcludedEntriesConfigurable(project, descriptor, configuration); }