diff --git a/java/idea-ui/src/com/intellij/openapi/wm/IdeaFrameTitleBuilder.java b/java/idea-ui/src/com/intellij/openapi/wm/IdeaFrameTitleBuilder.java index b82da4da9fd1..9796f9e8db3b 100644 --- a/java/idea-ui/src/com/intellij/openapi/wm/IdeaFrameTitleBuilder.java +++ b/java/idea-ui/src/com/intellij/openapi/wm/IdeaFrameTitleBuilder.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. @@ -20,12 +20,14 @@ import com.intellij.openapi.project.ProjectUtil; import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.wm.impl.PlatformFrameTitleBuilder; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class IdeaFrameTitleBuilder extends PlatformFrameTitleBuilder { - public String getFileTitle(final Project project, final VirtualFile file) { + @Override + public String getFileTitle(@NotNull final Project project, @NotNull final VirtualFile file) { return ProjectUtil.calcRelativeToProjectPath(file, project, !SystemInfo.isMac); } } diff --git a/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java b/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java index f17e68759dcb..8683342f873e 100644 --- a/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java +++ b/platform/lang-api/src/com/intellij/openapi/project/ProjectUtil.java @@ -49,12 +49,16 @@ public class ProjectUtil { return FileUtil.getLocationRelativeToUserHome(project.getBasePath()); } - public static String calcRelativeToProjectPath(final VirtualFile file, final Project project, final boolean includeFilePath) { + @NotNull + public static String calcRelativeToProjectPath(@NotNull final VirtualFile file, + @Nullable final Project project, + final boolean includeFilePath) { return calcRelativeToProjectPath(file, project, includeFilePath, false); } - public static String calcRelativeToProjectPath(final VirtualFile file, - final Project project, + @NotNull + public static String calcRelativeToProjectPath(@NotNull final VirtualFile file, + @Nullable final Project project, final boolean includeFilePath, final boolean keepModuleAlwaysOnTheLeft) { if (file instanceof VirtualFilePathWrapper) { diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FrameTitleBuilder.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FrameTitleBuilder.java index ce0250378b27..3432f48dbe73 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/FrameTitleBuilder.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/FrameTitleBuilder.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. @@ -18,6 +18,7 @@ package com.intellij.openapi.wm.impl; import com.intellij.openapi.components.ServiceManager; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.project.Project; +import org.jetbrains.annotations.NotNull; /** * @author yole @@ -27,7 +28,7 @@ public abstract class FrameTitleBuilder { return ServiceManager.getService(FrameTitleBuilder.class); } - public abstract String getFileTitle(final Project project, final VirtualFile file); + public abstract String getProjectTitle(@NotNull final Project project); - public abstract String getProjectTitle(final Project project); + public abstract String getFileTitle(@NotNull final Project project, @NotNull final VirtualFile file); } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java index 76422cc6e8e1..ddb0d4f6ad93 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/IdeFrameImpl.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. @@ -256,7 +256,7 @@ public class IdeFrameImpl extends JFrame implements IdeFrame, DataProvider { myUpdatingTitle = false; } } - + private static final class Builder { public StringBuilder sb = new StringBuilder(); diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java index 468e749a9597..7f91b64d9cdf 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/PlatformFrameTitleBuilder.java @@ -21,39 +21,45 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFilePathWrapper; import com.intellij.platform.ProjectBaseDirectory; +import org.jetbrains.annotations.NotNull; /** * @author yole */ public class PlatformFrameTitleBuilder extends FrameTitleBuilder { - public String getProjectTitle(final Project project) { - final VirtualFile baseDir = project.getBaseDir(); - if (baseDir != null) { - if (SystemInfo.isMac && baseDir.getName().equals(project.getName())) { - return "[" + FileUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()) + "]"; - } - - return project.getName() + " - [" + FileUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()) + "]"; - } + @Override + public String getProjectTitle(@NotNull final Project project) { + final String basePath = project.getBasePath(); + if (basePath == null) return project.getName(); - return project.getName(); + if (basePath.equals(project.getName())) { + return "[" + FileUtil.getLocationRelativeToUserHome(basePath) + "]"; + } + else { + return project.getName() + " - [" + FileUtil.getLocationRelativeToUserHome(basePath) + "]"; + } } - public String getFileTitle(final Project project, final VirtualFile file) { + @Override + public String getFileTitle(@NotNull final Project project, @NotNull final VirtualFile file) { if (SystemInfo.isMac) return file.getName(); if (file instanceof VirtualFilePathWrapper) { return ((VirtualFilePathWrapper)file).getPresentablePath(); } + String url = FileUtil.getLocationRelativeToUserHome(file.getPresentableUrl()); + if (url == null) url = file.getPresentableUrl(); + VirtualFile baseDir = ProjectBaseDirectory.getInstance(project).getBaseDir(); if (baseDir == null) baseDir = project.getBaseDir(); + if (baseDir != null) { - //noinspection ConstantConditions final String projectHomeUrl = FileUtil.getLocationRelativeToUserHome(baseDir.getPresentableUrl()); - if (url.startsWith(projectHomeUrl)) { + if (projectHomeUrl != null && url.startsWith(projectHomeUrl)) { url = "..." + url.substring(projectHomeUrl.length()); } } + return url; } } diff --git a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java index 96aef7f4b09a..e02187132e29 100644 --- a/platform/util/src/com/intellij/openapi/util/io/FileUtil.java +++ b/platform/util/src/com/intellij/openapi/util/io/FileUtil.java @@ -1287,7 +1287,7 @@ public class FileUtil { } @Nullable - public static String getLocationRelativeToUserHome(final String path) { + public static String getLocationRelativeToUserHome(@Nullable final String path) { if (path == null) return null; if (SystemInfo.isUnix) {