mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
move getPresentableName to ProjectUtil
This commit is contained in:
@@ -22,7 +22,7 @@ import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.project.ProjectUtilCore;
|
||||
import com.intellij.openapi.project.ProjectUtil;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
@@ -92,7 +92,7 @@ public class CompilerPaths {
|
||||
|
||||
public static String getCompilerSystemDirectoryName(Project project) {
|
||||
// todo: use ProjectKt.getSystemCacheFileName()
|
||||
return ProjectUtilCore.getPresentableName(project) + "." + project.getLocationHash();
|
||||
return ProjectUtil.getPresentableName(project) + "." + project.getLocationHash();
|
||||
}
|
||||
|
||||
public static File getCompilerSystemDirectory() {
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package com.intellij.openapi.project
|
||||
|
||||
import com.intellij.ide.DataManager
|
||||
import com.intellij.ide.highlighter.ProjectFileType
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys
|
||||
import com.intellij.openapi.application.runWriteAction
|
||||
import com.intellij.openapi.fileEditor.UniqueVFilePathBuilder
|
||||
@@ -33,6 +34,7 @@ import com.intellij.openapi.vfs.VirtualFilePathWrapper
|
||||
import com.intellij.util.io.exists
|
||||
import java.nio.file.InvalidPathException
|
||||
import java.nio.file.Paths
|
||||
import java.util.*
|
||||
import javax.swing.JComponent
|
||||
|
||||
val Module.rootManager: ModuleRootManager
|
||||
@@ -57,7 +59,7 @@ fun calcRelativeToProjectPath(file: VirtualFile, project: Project?, includeFileP
|
||||
if (project == null) {
|
||||
return url
|
||||
}
|
||||
return ProjectUtilCore.displayUrlRelativeToProject(file, url, project, includeFilePath, keepModuleAlwaysOnTheLeft)
|
||||
return displayUrlRelativeToProject(file, url, project, includeFilePath, keepModuleAlwaysOnTheLeft)
|
||||
}
|
||||
|
||||
fun guessProjectForFile(file: VirtualFile): Project? = ProjectLocator.getInstance().guessProjectForFile(file)
|
||||
@@ -133,4 +135,25 @@ fun Project.guessProjectDir() : VirtualFile {
|
||||
}
|
||||
}
|
||||
return this.baseDir!!
|
||||
}
|
||||
|
||||
fun getPresentableName(project: Project): String? {
|
||||
if (project.isDefault) {
|
||||
return project.name
|
||||
}
|
||||
|
||||
val location = project.presentableUrl ?: return null
|
||||
|
||||
var projectName = FileUtil.toSystemIndependentName(location).trimEnd('/')
|
||||
val lastSlash = projectName.lastIndexOf('/')
|
||||
if (lastSlash >= 0 && lastSlash + 1 < projectName.length) {
|
||||
projectName = projectName.substring(lastSlash + 1)
|
||||
}
|
||||
|
||||
if (projectName.endsWith(ProjectFileType.DOT_DEFAULT_EXTENSION, ignoreCase = true)) {
|
||||
projectName = projectName.substring(0, projectName.length - ProjectFileType.DOT_DEFAULT_EXTENSION.length)
|
||||
}
|
||||
|
||||
// replace ':' from windows drive names
|
||||
return projectName.toLowerCase(Locale.US).replace(':', '_')
|
||||
}
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2000-2015 JetBrains s.r.o.
|
||||
* Copyright 2000-2017 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.
|
||||
@@ -16,29 +16,20 @@
|
||||
@file:JvmName("ProjectUtilCore")
|
||||
package com.intellij.openapi.project
|
||||
|
||||
import com.intellij.ide.highlighter.ProjectFileType
|
||||
import com.intellij.openapi.module.ModuleUtilCore
|
||||
import com.intellij.openapi.roots.JdkOrderEntry
|
||||
import com.intellij.openapi.roots.libraries.LibraryUtil
|
||||
import com.intellij.openapi.util.SystemInfo
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import com.intellij.openapi.util.text.StringUtil
|
||||
import com.intellij.openapi.vfs.LocalFileProvider
|
||||
import com.intellij.openapi.vfs.VirtualFile
|
||||
import java.util.*
|
||||
|
||||
fun displayUrlRelativeToProject(file: VirtualFile,
|
||||
url: String,
|
||||
project: Project,
|
||||
includeFilePath: Boolean,
|
||||
keepModuleAlwaysOnTheLeft: Boolean): String {
|
||||
var url = url
|
||||
fun displayUrlRelativeToProject(file: VirtualFile, url: String, project: Project, includeFilePath: Boolean, keepModuleAlwaysOnTheLeft: Boolean): String {
|
||||
var result = url
|
||||
val baseDir = project.baseDir
|
||||
if (baseDir != null && includeFilePath) {
|
||||
|
||||
val projectHomeUrl = baseDir.presentableUrl
|
||||
if (url.startsWith(projectHomeUrl)) {
|
||||
url = "..." + url.substring(projectHomeUrl.length)
|
||||
if (result.startsWith(projectHomeUrl)) {
|
||||
result = "...${result.substring(projectHomeUrl.length)}"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,44 +39,23 @@ fun displayUrlRelativeToProject(file: VirtualFile,
|
||||
val libraryEntry = LibraryUtil.findLibraryEntry(file, project)
|
||||
if (libraryEntry != null) {
|
||||
if (libraryEntry is JdkOrderEntry) {
|
||||
url = url + " - [" + libraryEntry.jdkName + "]"
|
||||
result = "$result - [${libraryEntry.jdkName}]"
|
||||
}
|
||||
else {
|
||||
url = url + " - [" + libraryEntry.presentableName + "]"
|
||||
result = "$result - [${libraryEntry.presentableName}]"
|
||||
}
|
||||
}
|
||||
else {
|
||||
url = url + " - [" + fileForJar.name + "]"
|
||||
result = "$result - [${fileForJar.name}]"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return url
|
||||
return if (!keepModuleAlwaysOnTheLeft && SystemInfo.isMac)
|
||||
url + " - [" + module.name + "]"
|
||||
else
|
||||
"[" + module.name + "] - " + url
|
||||
}
|
||||
|
||||
fun getPresentableName(project: Project): String? {
|
||||
if (project.isDefault) {
|
||||
return project.name
|
||||
val module = ModuleUtilCore.findModuleForFile(file, project) ?: return result
|
||||
return if (!keepModuleAlwaysOnTheLeft && SystemInfo.isMac) {
|
||||
"$result - [${module.name}]"
|
||||
}
|
||||
|
||||
val location = project.presentableUrl ?: return null
|
||||
|
||||
var projectName = FileUtil.toSystemIndependentName(location)
|
||||
projectName = StringUtil.trimEnd(projectName, "/")
|
||||
|
||||
val lastSlash = projectName.lastIndexOf('/')
|
||||
if (lastSlash >= 0 && lastSlash + 1 < projectName.length) {
|
||||
projectName = projectName.substring(lastSlash + 1)
|
||||
else {
|
||||
"[${module.name}] - $result"
|
||||
}
|
||||
|
||||
if (StringUtil.endsWithIgnoreCase(projectName, ProjectFileType.DOT_DEFAULT_EXTENSION)) {
|
||||
projectName = projectName.substring(0, projectName.length - ProjectFileType.DOT_DEFAULT_EXTENSION.length)
|
||||
}
|
||||
|
||||
projectName = projectName.toLowerCase(Locale.US).replace(':', '_') // replace ':' from windows drive names
|
||||
return projectName
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user