Show logical project path in a frame title

This commit is contained in:
Roman Shevchenko
2012-02-21 13:55:07 +01:00
parent a59749c742
commit d7b980dfc3
6 changed files with 37 additions and 24 deletions
@@ -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);
}
}
@@ -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) {
@@ -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);
}
@@ -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();
@@ -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;
}
}
@@ -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) {