mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
RecentProjectsManager: use system-independent paths, #IDEA-173342 fixed
This commit is contained in:
@@ -23,6 +23,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.platform.PlatformProjectOpenProcessor;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -41,8 +43,9 @@ public class RecentProjectsManagerImpl extends RecentProjectsManagerBase {
|
||||
}
|
||||
|
||||
@Override
|
||||
@SystemIndependent
|
||||
protected String getProjectPath(@NotNull Project project) {
|
||||
return project.getPresentableUrl();
|
||||
return PathUtil.toSystemIndependentName(project.getPresentableUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+2
-1
@@ -45,6 +45,7 @@ import com.intellij.platform.templates.TemplateProjectDirectoryGenerator;
|
||||
import com.intellij.projectImport.ProjectOpenedCallback;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.NullableConsumer;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -210,7 +211,7 @@ public class AbstractNewProjectStep extends DefaultActionGroup implements DumbAw
|
||||
}
|
||||
}
|
||||
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(location.getParent());
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(PathUtil.toSystemIndependentName(location.getParent()));
|
||||
|
||||
ProjectOpenedCallback callback = null;
|
||||
if(generator instanceof TemplateProjectDirectoryGenerator){
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
package com.intellij.ide;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import com.intellij.util.containers.HashSet;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -56,7 +58,8 @@ public class ProjectGroup {
|
||||
myProjectPaths = projectPaths;
|
||||
}
|
||||
|
||||
public void addProject(String path) {
|
||||
public void addProject(@SystemIndependent String path) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
final List<String> projects = getProjects();
|
||||
projects.add(path);
|
||||
save(projects);
|
||||
@@ -70,7 +73,8 @@ public class ProjectGroup {
|
||||
return new ArrayList<>(new HashSet<>(StringUtil.split(myProjectPaths, File.pathSeparator)));
|
||||
}
|
||||
|
||||
public void removeProject(String path) {
|
||||
public void removeProject(@SystemIndependent String path) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
final List<String> projects = getProjects();
|
||||
projects.remove(path);
|
||||
save(projects);
|
||||
|
||||
@@ -17,6 +17,7 @@ package com.intellij.ide;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.Collections;
|
||||
@@ -28,9 +29,10 @@ public abstract class RecentProjectsManager {
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public abstract String getLastProjectCreationLocation();
|
||||
|
||||
public abstract void setLastProjectCreationLocation(@Nullable String lastProjectLocation);
|
||||
public abstract void setLastProjectCreationLocation(@Nullable @SystemIndependent String lastProjectLocation);
|
||||
|
||||
/** @deprecated do not use this method directly */
|
||||
@Deprecated
|
||||
@@ -38,9 +40,10 @@ public abstract class RecentProjectsManager {
|
||||
|
||||
public abstract void updateLastProjectPath();
|
||||
|
||||
@SystemIndependent
|
||||
public abstract String getLastProjectPath();
|
||||
|
||||
public abstract void removePath(@Nullable String path);
|
||||
public abstract void removePath(@Nullable @SystemIndependent String path);
|
||||
|
||||
/**
|
||||
* @param addClearListItem whether the "Clear List" action should be added to the end of the list.
|
||||
@@ -55,7 +58,7 @@ public abstract class RecentProjectsManager {
|
||||
public void addGroup(ProjectGroup group) {}
|
||||
public void removeGroup(ProjectGroup group) {}
|
||||
|
||||
public boolean hasPath(String path) {
|
||||
public boolean hasPath(@SystemIndependent String path) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,11 +19,11 @@ import com.intellij.openapi.components.RoamingType;
|
||||
import com.intellij.openapi.components.State;
|
||||
import com.intellij.openapi.components.Storage;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.platform.PlatformProjectOpenProcessor;
|
||||
import com.intellij.platform.ProjectBaseDirectory;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -44,15 +44,16 @@ public class RecentDirectoryProjectsManager extends RecentProjectsManagerBase {
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
protected String getProjectPath(@NotNull Project project) {
|
||||
final ProjectBaseDirectory baseDir = ProjectBaseDirectory.getInstance(project);
|
||||
final VirtualFile baseDirVFile = baseDir.getBaseDir() != null ? baseDir.getBaseDir() : project.getBaseDir();
|
||||
return baseDirVFile != null ? FileUtil.toSystemDependentName(baseDirVFile.getPath()) : null;
|
||||
return baseDirVFile != null ? baseDirVFile.getPath() : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void doOpenProject(@NotNull String projectPath, Project projectToClose, boolean forceOpenInNewFrame) {
|
||||
VirtualFile projectDir = LocalFileSystem.getInstance().findFileByPath(FileUtil.toSystemIndependentName(projectPath));
|
||||
protected void doOpenProject(@NotNull @SystemIndependent String projectPath, Project projectToClose, boolean forceOpenInNewFrame) {
|
||||
VirtualFile projectDir = LocalFileSystem.getInstance().findFileByPath(projectPath);
|
||||
if (projectDir != null) {
|
||||
EnumSet<PlatformProjectOpenProcessor.Option> options = EnumSet.of(PlatformProjectOpenProcessor.Option.REOPEN);
|
||||
if (forceOpenInNewFrame) options.add(PlatformProjectOpenProcessor.Option.FORCE_NEW_FRAME);
|
||||
|
||||
@@ -35,10 +35,7 @@ import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.wm.impl.SystemDock;
|
||||
import com.intellij.project.ProjectKt;
|
||||
import com.intellij.ui.IconDeferrer;
|
||||
import com.intellij.util.Alarm;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.ImageLoader;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.*;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.messages.MessageBus;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
@@ -97,6 +94,19 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
names.remove(recentPaths.get(index));
|
||||
recentPaths.remove(index);
|
||||
}
|
||||
|
||||
// TODO Should be removed later (required to convert the already saved system-dependent paths).
|
||||
List<String> paths = new ArrayList<>(recentPaths);
|
||||
recentPaths.clear();
|
||||
for (String path : paths) {
|
||||
recentPaths.add(PathUtil.toSystemIndependentName(path));
|
||||
}
|
||||
Map<String, RecentProjectMetaInfo> info = new HashMap<>(additionalInfo);
|
||||
additionalInfo.clear();
|
||||
for (Map.Entry<String, RecentProjectMetaInfo> entry : info.entrySet()) {
|
||||
entry.getValue().binFolder = PathUtil.toSystemIndependentName(entry.getValue().binFolder);
|
||||
additionalInfo.put(PathUtil.toSystemIndependentName(entry.getKey()), entry.getValue());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +153,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
|
||||
protected void removeDuplicates(State state) {
|
||||
for (String path : new ArrayList<>(state.recentPaths)) {
|
||||
if (path.endsWith(File.separator)) {
|
||||
if (path.endsWith("/")) {
|
||||
state.recentPaths.remove(path);
|
||||
state.additionalInfo.remove(path);
|
||||
state.openPaths.remove(path);
|
||||
@@ -161,11 +171,13 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removePath(@Nullable String path) {
|
||||
public void removePath(@Nullable @SystemIndependent String path) {
|
||||
if (path == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
|
||||
synchronized (myStateLock) {
|
||||
removePathFrom(myState.recentPaths, path);
|
||||
myState.names.remove(path);
|
||||
@@ -176,7 +188,8 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasPath(String path) {
|
||||
public boolean hasPath(@SystemIndependent String path) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
final State state = getState();
|
||||
return state != null && state.recentPaths.contains(path);
|
||||
}
|
||||
@@ -186,16 +199,20 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
*/
|
||||
@Override
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
public String getLastProjectCreationLocation() {
|
||||
return myState.lastProjectLocation;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setLastProjectCreationLocation(@Nullable String lastProjectLocation) {
|
||||
myState.lastProjectLocation = StringUtil.nullize(lastProjectLocation, true);
|
||||
public void setLastProjectCreationLocation(@Nullable @SystemIndependent String lastProjectLocation) {
|
||||
PathUtil.assertSystemIndependentName(lastProjectLocation);
|
||||
String location = StringUtil.nullize(lastProjectLocation, true);
|
||||
myState.lastProjectLocation = PathUtil.toSystemIndependentName(location);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SystemIndependent
|
||||
public String getLastProjectPath() {
|
||||
return myState.lastPath;
|
||||
}
|
||||
@@ -228,6 +245,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
|
||||
@Nullable
|
||||
public static Icon getProjectIcon(String path, boolean isDark) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
final MyIcon icon = ourProjectIcons.get(path);
|
||||
if (icon != null) {
|
||||
return icon.getIcon();
|
||||
@@ -239,6 +257,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
|
||||
@Nullable
|
||||
protected static Icon calculateIcon(String path, boolean isDark) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
File file = new File(path + (isDark ? "/.idea/icon_dark.png" : "/.idea/icon.png"));
|
||||
if (file.exists()) {
|
||||
final long timestamp = file.lastModified();
|
||||
@@ -457,6 +476,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
}
|
||||
|
||||
private AnAction createOpenAction(String path, Set<String> duplicates) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
String projectName = getProjectName(path);
|
||||
String displayName;
|
||||
synchronized (myStateLock) {
|
||||
@@ -475,7 +495,8 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
//return null;
|
||||
}
|
||||
|
||||
private void markPathRecent(String path) {
|
||||
private void markPathRecent(@SystemIndependent String path) {
|
||||
PathUtil.assertSystemIndependentName(path);
|
||||
synchronized (myStateLock) {
|
||||
if (path.endsWith(File.separator)) {
|
||||
path = path.substring(0, path.length() - File.separator.length());
|
||||
@@ -506,6 +527,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@SystemIndependent
|
||||
protected abstract String getProjectPath(@NotNull Project project);
|
||||
|
||||
protected abstract void doOpenProject(@NotNull String projectPath, @Nullable Project projectToClose, boolean forceOpenInNewFrame);
|
||||
@@ -705,7 +727,7 @@ public abstract class RecentProjectsManagerBase extends RecentProjectsManager im
|
||||
info.build = ApplicationInfoEx.getInstanceEx().getBuild().asString();
|
||||
info.productionCode = ApplicationInfoEx.getInstanceEx().getBuild().getProductCode();
|
||||
info.eap = ApplicationInfoEx.getInstanceEx().isEAP();
|
||||
info.binFolder = PathManager.getBinPath();
|
||||
info.binFolder = PathUtil.toSystemIndependentName(PathManager.getBinPath());
|
||||
info.projectOpenTimestamp = System.currentTimeMillis();
|
||||
info.buildTimestamp = ApplicationInfoEx.getInstanceEx().getBuildDate().getTimeInMillis();
|
||||
return info;
|
||||
|
||||
@@ -24,6 +24,8 @@ import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.util.BitUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemIndependent;
|
||||
|
||||
import java.awt.event.InputEvent;
|
||||
import java.io.File;
|
||||
@@ -36,14 +38,16 @@ public class ReopenProjectAction extends AnAction implements DumbAware {
|
||||
private final String myProjectName;
|
||||
private boolean myIsRemoved = false;
|
||||
|
||||
public ReopenProjectAction(final String projectPath, final String projectName, final String displayName) {
|
||||
public ReopenProjectAction(final @SystemIndependent String projectPath, final String projectName, final String displayName) {
|
||||
PathUtil.assertSystemIndependentName(projectPath);
|
||||
|
||||
myProjectPath = projectPath;
|
||||
myProjectName = projectName;
|
||||
|
||||
final Presentation presentation = getTemplatePresentation();
|
||||
String text = projectPath.equals(displayName) ? FileUtil.getLocationRelativeToUserHome(projectPath) : displayName;
|
||||
presentation.setText(text, false);
|
||||
presentation.setDescription(projectPath);
|
||||
presentation.setDescription(PathUtil.toSystemDependentName(projectPath));
|
||||
}
|
||||
|
||||
|
||||
@@ -59,7 +63,7 @@ public class ReopenProjectAction extends AnAction implements DumbAware {
|
||||
|
||||
Project project = e.getProject();
|
||||
if (!new File(myProjectPath).exists()) {
|
||||
if (Messages.showDialog(project, "The path " + FileUtil.toSystemDependentName(myProjectPath) + " does not exist.\n" +
|
||||
if (Messages.showDialog(project, "The path " + PathUtil.toSystemDependentName(myProjectPath) + " does not exist.\n" +
|
||||
"If it is on a removable or network drive, please make sure that the drive is connected.",
|
||||
"Reopen Project", new String[]{"OK", "&Remove From List"}, 0, Messages.getErrorIcon()) == 1) {
|
||||
myIsRemoved = true;
|
||||
@@ -75,6 +79,7 @@ public class ReopenProjectAction extends AnAction implements DumbAware {
|
||||
e.getPresentation().setText(getProjectName(), false);
|
||||
}
|
||||
|
||||
@SystemIndependent
|
||||
public String getProjectPath() {
|
||||
return myProjectPath;
|
||||
}
|
||||
|
||||
@@ -40,6 +40,7 @@ import com.intellij.openapi.wm.*;
|
||||
import com.intellij.project.ProjectKt;
|
||||
import com.intellij.projectImport.ProjectOpenProcessor;
|
||||
import com.intellij.ui.AppIcon;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.PlatformUtils;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -80,7 +81,7 @@ public class ProjectUtil {
|
||||
LOG.info(e);
|
||||
return;
|
||||
}
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(path.replace(File.separatorChar, '/'));
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(PathUtil.toSystemIndependentName(path));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +179,7 @@ public class ProjectUtil {
|
||||
}
|
||||
}
|
||||
|
||||
if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(path)) {
|
||||
if (isRemotePath(path) && !RecentProjectsManager.getInstance().hasPath(PathUtil.toSystemIndependentName(path))) {
|
||||
if (!confirmLoadingFromRemotePath(path, "warning.load.project.from.share", "title.load.project.from.share")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-1
@@ -29,6 +29,7 @@ import com.intellij.ui.components.panels.NonOpaquePanel;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.ui.speedSearch.NameFilteringListModel;
|
||||
import com.intellij.util.IconUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.ui.EmptyIcon;
|
||||
import com.intellij.util.ui.JBDimension;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
@@ -253,7 +254,7 @@ public class NewRecentProjectPanel extends RecentProjectPanel {
|
||||
} else if (value instanceof ReopenProjectAction) {
|
||||
final NonOpaquePanel p = new NonOpaquePanel(new BorderLayout());
|
||||
name.setText(((ReopenProjectAction)value).getProjectName());
|
||||
final String realPath = ((ReopenProjectAction)value).getProjectPath();
|
||||
final String realPath = PathUtil.toSystemDependentName(((ReopenProjectAction)value).getProjectPath());
|
||||
path.setText(getTitle2Text((ReopenProjectAction)value, path, JBUI.scale(isInsideGroup ? 80 : 60)));
|
||||
if (!realPath.equals(path.getText())) {
|
||||
projectsWithLongPathes.add((ReopenProjectAction)value);
|
||||
|
||||
+2
-1
@@ -43,6 +43,7 @@ import com.intellij.ui.ListUtil;
|
||||
import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.components.JBScrollPane;
|
||||
import com.intellij.ui.speedSearch.ListWithFilter;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.ui.JBUI;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
@@ -361,7 +362,7 @@ public class RecentProjectPanel extends JPanel {
|
||||
if (i != -1) {
|
||||
final Object elem = getModel().getElementAt(i);
|
||||
if (elem instanceof ReopenProjectAction && RecentProjectPanel.this.projectsWithLongPathes.contains(elem)) {
|
||||
return ((ReopenProjectAction)elem).getProjectPath();
|
||||
return PathUtil.toSystemDependentName(((ReopenProjectAction)elem).getProjectPath());
|
||||
}
|
||||
}
|
||||
return super.getToolTipText(event);
|
||||
|
||||
+2
-1
@@ -49,6 +49,7 @@ import com.intellij.ui.components.JBList;
|
||||
import com.intellij.ui.popup.PopupFactoryImpl;
|
||||
import com.intellij.ui.popup.list.ListPopupModel;
|
||||
import com.intellij.util.JdkBundle;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.Producer;
|
||||
import com.intellij.util.messages.MessageBusConnection;
|
||||
import com.intellij.util.ui.EdtInvocationManager;
|
||||
@@ -194,7 +195,7 @@ GuiTestUtil {
|
||||
}
|
||||
|
||||
public static void setUpDefaultProjectCreationLocationPath() {
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(getProjectCreationDirPath().getPath());
|
||||
RecentProjectsManager.getInstance().setLastProjectCreationLocation(PathUtil.toSystemIndependentName(getProjectCreationDirPath().getPath()));
|
||||
}
|
||||
|
||||
// Called by IdeTestApplication via reflection.
|
||||
|
||||
Reference in New Issue
Block a user