This commit is contained in:
Roman Shevchenko
2012-02-21 13:52:35 +01:00
parent 8dd0125546
commit 3fbcc7c19f
4 changed files with 32 additions and 84 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.
@@ -13,10 +13,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/*
* @author max
*/
package com.intellij.openapi.project;
import com.intellij.ide.DataManager;
@@ -40,16 +36,17 @@ import org.jetbrains.annotations.Nullable;
import javax.swing.*;
/**
* @author max
*/
public class ProjectUtil {
@NonNls public static final String DIRECTORY_BASED_PROJECT_DIR = ".idea";
private ProjectUtil() {
}
private ProjectUtil() { }
@Nullable
public static String getProjectLocationString(@NotNull final Project project) {
String projectPath = project.getLocation();
return FileUtil.getLocationRelativeToUserHome(projectPath);
return FileUtil.getLocationRelativeToUserHome(project.getBasePath());
}
public static String calcRelativeToProjectPath(final VirtualFile file, final Project project, final boolean includeFilePath) {
@@ -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.
@@ -39,7 +39,6 @@ import com.intellij.openapi.Disposable;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.application.ex.ApplicationInfoEx;
import com.intellij.openapi.command.CommandProcessor;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.ServiceManager;
@@ -61,7 +60,6 @@ import com.intellij.openapi.ui.SimpleToolWindowPanel;
import com.intellij.openapi.ui.SplitterProportionsData;
import com.intellij.openapi.ui.popup.PopupChooserBuilder;
import com.intellij.openapi.util.*;
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.LocalFileSystem;
@@ -75,6 +73,7 @@ import com.intellij.openapi.wm.impl.content.ToolWindowContentUi;
import com.intellij.psi.*;
import com.intellij.psi.impl.file.PsiDirectoryFactory;
import com.intellij.psi.util.PsiUtilBase;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.ui.AutoScrollFromSourceHandler;
import com.intellij.ui.AutoScrollToSourceHandler;
import com.intellij.ui.GuiUtils;
@@ -157,7 +156,6 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
@Deprecated static final String PROJECT_VIEW_DATA_CONSTANT = DATA_KEY.getName();
private DefaultActionGroup myActionGroup;
private final Runnable myTreeChangeListener;
private String mySavedPaneId = ProjectViewPane.ID;
private String mySavedPaneSubId;
//private static final Icon COMPACT_EMPTY_MIDDLE_PACKAGES_ICON = IconLoader.getIcon("/objectBrowser/compactEmptyPackages.png");
@@ -200,11 +198,6 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
Disposer.register(myProject, this);
myFileEditorManager = fileEditorManager;
myTreeChangeListener = new Runnable() {
public void run() {
updateToolWindowTitle();
}
};
myConnection = project.getMessageBus().connect();
myConnection.subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
@@ -474,15 +467,13 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
createToolbarActions();
updateTitleActions();
newPane.setTreeChangeListener(myTreeChangeListener);
myAutoScrollToSourceHandler.install(newPane.myTree);
IdeFocusManager.getInstance(myProject).requestFocus(newPane.getComponentToFocus(), false);
updateToolWindowTitle();
newPane.restoreExpandedPaths();
if (selectedPsiElement != null) {
final VirtualFile virtualFile = PsiUtilBase.getVirtualFile(selectedPsiElement);
final VirtualFile virtualFile = PsiUtilCore.getVirtualFile(selectedPsiElement);
if (virtualFile != null && ((ProjectViewSelectInTarget)newPane.createSelectInTarget()).isSubIdSelectable(newSubId, new SelectInContext() {
@NotNull
public Project getProject() {
@@ -754,49 +745,6 @@ public class ProjectViewImpl extends ProjectView implements PersistentStateCompo
return myCurrentViewId;
}
private void updateToolWindowTitle() {
if (true) return;
ToolWindowManager toolWindowManager = ToolWindowManager.getInstance(myProject);
ToolWindow toolWindow = toolWindowManager == null ? null : toolWindowManager.getToolWindow(ToolWindowId.PROJECT_VIEW);
if (toolWindow == null) return;
String title = null;
final AbstractProjectViewPane pane = getCurrentProjectViewPane();
if (pane != null) {
final DefaultMutableTreeNode selectedNode = pane.getSelectedNode();
if (selectedNode != null) {
final Object o = selectedNode.getUserObject();
if (o instanceof ProjectViewNode) {
title = ((ProjectViewNode)o).getTitle();
}
}
}
if (title == null) {
if (true) return;
final PsiElement element = (PsiElement)myDataProvider.getData(LangDataKeys.PSI_ELEMENT.getName());
if (element != null) {
PsiFile file = element.getContainingFile();
if (file != null) {
title = FileUtil.getLocationRelativeToUserHome(file.getVirtualFile().getPresentableUrl());
}
else if (element instanceof PsiDirectory) {
title = PsiDirectoryFactory.getInstance(myProject).getQualifiedName((PsiDirectory) element, true);
}
else {
title = element.toString();
}
}
else {
title = "";
if (myProject != null) {
title = FileUtil.getLocationRelativeToUserHome(myProject.getPresentableUrl());
}
}
}
toolWindow.setTitle(title);
}
public PsiElement getParentOfCurrentSelection() {
final AbstractProjectViewPane viewPane = getCurrentProjectViewPane();
if (viewPane == null) {
@@ -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,14 +18,12 @@ package com.intellij.ide.impl;
import com.intellij.CommonBundle;
import com.intellij.ide.GeneralSettings;
import com.intellij.ide.IdeBundle;
import com.intellij.ide.highlighter.InternalFileType;
import com.intellij.ide.highlighter.ProjectFileType;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ModalityState;
import com.intellij.openapi.components.StorageScheme;
import com.intellij.openapi.components.impl.stores.IProjectStore;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.fileTypes.FileType;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.project.ProjectManager;
import com.intellij.openapi.project.ex.ProjectEx;
@@ -53,13 +51,12 @@ import java.io.IOException;
public class ProjectUtil {
private static final Logger LOG = Logger.getInstance("#com.intellij.ide.impl.ProjectUtil");
private ProjectUtil() {
}
private ProjectUtil() { }
public static void updateLastProjectLocation(final String projectFilePath) {
File lastProjectLocation = new File(projectFilePath);
if (lastProjectLocation.isFile()) {
lastProjectLocation = lastProjectLocation.getParentFile(); //for directory based project storages
lastProjectLocation = lastProjectLocation.getParentFile(); // for directory-based project storage
}
if (lastProjectLocation == null) { // the immediate parent of the ipr file
return;
@@ -205,19 +202,23 @@ public class ProjectUtil {
if (confirmOpenNewProject == GeneralSettings.OPEN_PROJECT_ASK) {
if (isNewProject) {
int exitCode = Messages.showYesNoDialog(IdeBundle.message("prompt.open.project.in.new.frame"),
IdeBundle.message("title.new.project"),
IdeBundle.message("button.existingframe"),
IdeBundle.message("button.newframe"),
Messages.getQuestionIcon(), new ProjectNewWindowDoNotAskOption());
IdeBundle.message("title.new.project"),
IdeBundle.message("button.existingframe"),
IdeBundle.message("button.newframe"),
Messages.getQuestionIcon(),
new ProjectNewWindowDoNotAskOption());
return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW : GeneralSettings.OPEN_PROJECT_NEW_WINDOW;
}
else {
int exitCode = Messages.showYesNoCancelDialog(IdeBundle.message("prompt.open.project.in.new.frame"),
IdeBundle.message("title.open.project"),
IdeBundle.message("button.existingframe"), IdeBundle.message("button.newframe"),
CommonBundle.getCancelButtonText(), Messages.getQuestionIcon(),
new ProjectNewWindowDoNotAskOption());
return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW : exitCode == 1 ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : Messages.CANCEL;
IdeBundle.message("title.open.project"),
IdeBundle.message("button.existingframe"),
IdeBundle.message("button.newframe"),
CommonBundle.getCancelButtonText(),
Messages.getQuestionIcon(),
new ProjectNewWindowDoNotAskOption());
return exitCode == 0 ? GeneralSettings.OPEN_PROJECT_SAME_WINDOW :
exitCode == 1 ? GeneralSettings.OPEN_PROJECT_NEW_WINDOW : Messages.CANCEL;
}
}
return confirmOpenNewProject;
@@ -265,6 +266,10 @@ public class ProjectUtil {
}
}
/**
* @deprecated use {@linkplain com.intellij.openapi.project.ProjectUtil#isProjectOrWorkspaceFile(com.intellij.openapi.vfs.VirtualFile)} (to remove in IDEA 13)
*/
@SuppressWarnings("UnusedDeclaration")
public static boolean isProjectOrWorkspaceFile(final VirtualFile file) {
return com.intellij.openapi.project.ProjectUtil.isProjectOrWorkspaceFile(file);
}
@@ -1290,17 +1290,15 @@ public class FileUtil {
public static String getLocationRelativeToUserHome(final String path) {
if (path == null) return null;
String _path = path;
if (SystemInfo.isLinux || SystemInfo.isMac) {
if (SystemInfo.isUnix) {
final File projectDir = new File(path);
final File userHomeDir = new File(SystemProperties.getUserHome());
if (isAncestor(userHomeDir, projectDir, true)) {
_path = "~/" + getRelativePath(userHomeDir, projectDir);
return "~/" + getRelativePath(userHomeDir, projectDir);
}
}
return _path;
return path;
}
public static boolean isHashBangLine(CharSequence firstCharsIfText, String marker) {