XPathView.XPathViewPlugin — store in own xpath.xml

use OptionsBundle to get name if plugin vendor is JetBrains and no resource bundle
This commit is contained in:
develar
2016-01-28 12:11:27 +01:00
parent 1d73d439d8
commit 11a49080d5
3 changed files with 57 additions and 46 deletions
@@ -165,7 +165,7 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
}
}
@Suppress("DEPRECATED_SYMBOL_WITH_MESSAGE")
@Suppress("DEPRECATION")
ApplicationManager.getApplication().getComponents(ExportableApplicationComponent::class.java).forEach(processor)
ServiceBean.loadServicesFromBeans(ExportableComponent.EXTENSION_POINT, ExportableComponent::class.java).forEach(processor)
@@ -189,43 +189,41 @@ fun getExportableComponentsMap(onlyExisting: Boolean,
result.keys.removeAll(::isSkipFile)
}
ServiceManagerImpl.processAllImplementationClasses(ApplicationManager.getApplication() as ApplicationImpl, object : PairProcessor<Class<*>, PluginDescriptor> {
override fun process(aClass: Class<*>, pluginDescriptor: PluginDescriptor?): Boolean {
val stateAnnotation = StoreUtil.getStateSpec(aClass)
if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty() || ExportableComponent::class.java.isAssignableFrom(aClass)) {
return true
}
val storage = sortStoragesByDeprecated(stateAnnotation.storages).firstOrNull() ?: return true
if (!(storage.roamingType != RoamingType.DISABLED && storage.storageClass == StateStorage::class && storage.scheme == StorageScheme.DEFAULT && !storage.file.isNullOrEmpty())) {
return true
}
var additionalExportFile: File? = null
var additionalExportPath = stateAnnotation.additionalExportFile
if (additionalExportPath.isNotEmpty()) {
// backward compatibility - path can contain macro
if (additionalExportPath[0] != '$') {
additionalExportPath = "$ROOT_CONFIG/$additionalExportPath"
}
additionalExportFile = File(storageManager.expandMacros(additionalExportPath))
if (isSkipFile(additionalExportFile)) {
additionalExportFile = null
}
}
val file = File(storageManager.expandMacros(storage.file))
val isFileIncluded = !isSkipFile(file)
if (isFileIncluded || additionalExportFile != null) {
val files = if (additionalExportFile == null) listOf(file) else if (isFileIncluded) listOf(file, additionalExportFile) else listOf(additionalExportFile)
val item = ExportableItem(files, if (computePresentableNames) getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor) else "", storage.roamingType)
result.putValue(file, item)
if (additionalExportFile != null) {
result.putValue(additionalExportFile, item)
}
}
return true
ServiceManagerImpl.processAllImplementationClasses(ApplicationManager.getApplication() as ApplicationImpl, PairProcessor<Class<*>, PluginDescriptor> { aClass, pluginDescriptor ->
val stateAnnotation = StoreUtil.getStateSpec(aClass)
if (stateAnnotation == null || stateAnnotation.name.isNullOrEmpty() || ExportableComponent::class.java.isAssignableFrom(aClass)) {
return@PairProcessor true
}
val storage = sortStoragesByDeprecated(stateAnnotation.storages).firstOrNull() ?: return@PairProcessor true
if (!(storage.roamingType != RoamingType.DISABLED && storage.storageClass == StateStorage::class && storage.scheme == StorageScheme.DEFAULT && !storage.file.isNullOrEmpty())) {
return@PairProcessor true
}
var additionalExportFile: File? = null
var additionalExportPath = stateAnnotation.additionalExportFile
if (additionalExportPath.isNotEmpty()) {
// backward compatibility - path can contain macro
if (additionalExportPath[0] != '$') {
additionalExportPath = "$ROOT_CONFIG/$additionalExportPath"
}
additionalExportFile = File(storageManager.expandMacros(additionalExportPath))
if (isSkipFile(additionalExportFile)) {
additionalExportFile = null
}
}
val file = File(storageManager.expandMacros(storage.file))
val isFileIncluded = !isSkipFile(file)
if (isFileIncluded || additionalExportFile != null) {
val files = if (additionalExportFile == null) listOf(file) else if (isFileIncluded) listOf(file, additionalExportFile) else listOf(additionalExportFile)
val item = ExportableItem(files, if (computePresentableNames) getComponentPresentableName(stateAnnotation, aClass, pluginDescriptor) else "", storage.roamingType)
result.putValue(file, item)
if (additionalExportFile != null) {
result.putValue(additionalExportFile, item)
}
}
true
})
return result
}
@@ -242,12 +240,21 @@ private fun getComponentPresentableName(state: State, aClass: Class<*>, pluginDe
}
val defaultName = state.name
val resourceBundleName = (if (pluginDescriptor is IdeaPluginDescriptor && "com.intellij" != pluginDescriptor.pluginId.idString) {
pluginDescriptor.resourceBundleBaseName
var resourceBundleName: String?
if (pluginDescriptor is IdeaPluginDescriptor && "com.intellij" != pluginDescriptor.pluginId.idString) {
resourceBundleName = pluginDescriptor.resourceBundleBaseName
if (resourceBundleName == null) {
if (pluginDescriptor.vendor == "JetBrains") {
resourceBundleName = OptionsBundle.PATH_TO_BUNDLE
}
else {
return defaultName
}
}
}
else {
OptionsBundle.PATH_TO_BUNDLE
}) ?: return defaultName
resourceBundleName = OptionsBundle.PATH_TO_BUNDLE
}
var classLoader = pluginDescriptor?.pluginClassLoader ?: aClass.classLoader
if (classLoader != null) {
@@ -340,4 +340,5 @@ exportable.ExportableFileTemplateSettings.presentable.name=File templates
exportable.ProjectManager.presentable.name=Default project
exportable.com.intellij.ide.ui.customization.CustomActionsSchema.presentable.name=Menus and toolbars customization
exportable.ActionMacroManager.presentable.name=Macros
exportable.ImportFilteringUsageViewSetting.presentable.name=Usage View: Imports
exportable.ImportFilteringUsageViewSetting.presentable.name=Usage View: Imports
exportable.XPathView.XPathViewPlugin.presentable.name=XPath Viewer
@@ -21,7 +21,10 @@ import com.intellij.codeInsight.hint.HintUtil;
import com.intellij.codeInsight.template.impl.DefaultLiveTemplatesProvider;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.components.*;
import com.intellij.openapi.components.ApplicationComponent;
import com.intellij.openapi.components.PersistentStateComponent;
import com.intellij.openapi.components.State;
import com.intellij.openapi.components.Storage;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.ScrollType;
import com.intellij.openapi.editor.markup.RangeHighlighter;
@@ -49,9 +52,9 @@ import java.util.List;
@State(
name = "XPathView.XPathViewPlugin",
storages = {
@Storage(
file = StoragePathMacros.APP_CONFIG + "/other.xml"
)}
@Storage(file = "xpath.xml"),
@Storage(file = "other.xml", deprecated = true)
}
)
public class XPathAppComponent implements ApplicationComponent, PersistentStateComponent<Config>, DefaultLiveTemplatesProvider {
private static final String ACTION_FIND_NEXT = "FindNext";