IDEA-171878 Add EP ProjectNameProvider

This commit is contained in:
Vladimir Krivosheev
2017-04-24 15:31:54 +02:00
parent b88cf52083
commit 5a6520013b
4 changed files with 47 additions and 17 deletions
@@ -33,6 +33,7 @@ import com.intellij.openapi.module.Module
import com.intellij.openapi.module.ModuleManager
import com.intellij.openapi.project.Project
import com.intellij.openapi.project.ProjectCoreUtil
import com.intellij.openapi.project.ex.ProjectEx.NAME_PROVIDER_EP
import com.intellij.openapi.project.impl.ProjectImpl
import com.intellij.openapi.project.impl.ProjectManagerImpl.UnableToSaveProjectNotification
import com.intellij.openapi.project.impl.ProjectStoreClassProvider
@@ -48,6 +49,7 @@ import com.intellij.openapi.vfs.VirtualFile
import com.intellij.util.PathUtilRt
import com.intellij.util.SmartList
import com.intellij.util.attribute
import com.intellij.util.containers.computeOrNull
import com.intellij.util.containers.forEachGuaranteed
import com.intellij.util.containers.isNullOrEmpty
import com.intellij.util.io.*
@@ -303,25 +305,24 @@ private open class ProjectStoreImpl(project: ProjectImpl, private val pathMacroM
}
override fun getProjectName(): String {
if (isDirectoryBased) {
val baseDir = projectBasePath
val nameFile = nameFile
if (nameFile.exists()) {
try {
nameFile.inputStream().reader().useLines { it.firstOrNull { !it.isEmpty() }?.trim() }?.let {
lastSavedProjectName = it
return it
}
}
catch (ignored: IOException) {
}
}
return PathUtilRt.getFileName(baseDir).replace(":", "")
}
else {
if (!isDirectoryBased) {
return PathUtilRt.getFileName(projectFilePath).removeSuffix(ProjectFileType.DOT_DEFAULT_EXTENSION)
}
val baseDir = projectBasePath
val nameFile = nameFile
if (nameFile.exists()) {
LOG.catchAndLog {
nameFile.inputStream().reader().useLines { it.firstOrNull { !it.isEmpty() }?.trim() }?.let {
lastSavedProjectName = it
return it
}
}
}
return NAME_PROVIDER_EP.extensions.computeOrNull {
LOG.catchAndLog { it.getName(project) }
} ?: PathUtilRt.getFileName(baseDir).replace(":", "")
}
private fun saveProjectName() {
@@ -15,6 +15,7 @@
*/
package com.intellij.openapi.project.ex;
import com.intellij.openapi.extensions.ExtensionPointName;
import com.intellij.openapi.project.Project;
import com.intellij.util.messages.Topic;
import org.jetbrains.annotations.NotNull;
@@ -26,6 +27,8 @@ public interface ProjectEx extends Project {
void saved(@NotNull final Project project);
}
ExtensionPointName<ProjectNameProvider> NAME_PROVIDER_EP = ExtensionPointName.create("com.intellij.projectNameProvider");
void init();
void setProjectName(@NotNull String name);
@@ -0,0 +1,25 @@
/*
* 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.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.project.ex;
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
public interface ProjectNameProvider {
@Nullable
String getName(@NotNull Project project);
}
@@ -282,5 +282,6 @@
<extensionPoint name="achromatopsiaSupport" interface="com.intellij.ide.ui.ColorBlindnessSupport"/>
<extensionPoint name="bundledInspectionProfile" beanClass="com.intellij.configurationStore.BundledSchemeEP"/>
<extensionPoint name="projectNameProvider" beanClass="com.intellij.openapi.project.ex.ProjectNameProvider"/>
</extensionPoints>
</idea-plugin>