active read-only repo should not disable export/import actions

This commit is contained in:
Vladimir Krivosheev
2018-07-02 15:06:40 +02:00
parent 3cc4642dfb
commit a080ac37a0
8 changed files with 27 additions and 51 deletions
@@ -42,7 +42,7 @@ import java.util.zip.ZipOutputStream
internal fun isImportExportActionApplicable(): Boolean {
val app = ApplicationManager.getApplication()
val storageManager = app.stateStore.storageManager as? StateStorageManagerImpl ?: return true
return !storageManager.isStreamProviderEnabled
return !storageManager.isStreamProviderPreventExportAction
}
// for Rider purpose
@@ -45,8 +45,8 @@ open class StateStorageManagerImpl(private val rootTagName: String,
val compoundStreamProvider: CompoundStreamProvider = CompoundStreamProvider()
val isStreamProviderEnabled: Boolean
get() = compoundStreamProvider.enabled
val isStreamProviderPreventExportAction: Boolean
get() = compoundStreamProvider.providers.any { it.isDisableExportAction }
override fun addStreamProvider(provider: StreamProvider, first: Boolean) {
if (first) {
@@ -1,6 +1,4 @@
/*
* Copyright 2000-2017 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.configurationStore
import com.intellij.openapi.components.RoamingType
@@ -12,6 +10,9 @@ interface StreamProvider {
val enabled: Boolean
get() = true
val isDisableExportAction: Boolean
get() = enabled
/**
* Called only on `write`
*/
+13 -10
View File
@@ -67,10 +67,10 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
private @Volatile var autoCommitEnabled = true
@Volatile var repositoryActive: Boolean = false
@Volatile var isRepositoryActive: Boolean = false
val active: Boolean
get() = repositoryActive || readOnlySourcesManager.repositories.isNotEmpty()
val isActive: Boolean
get() = isRepositoryActive || readOnlySourcesManager.repositories.isNotEmpty()
internal val autoSyncManager = AutoSyncManager(this)
internal val syncManager = SyncManager(this, autoSyncManager)
@@ -83,7 +83,7 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
inner class ApplicationLevelProvider : IcsStreamProvider(null) {
override fun delete(fileSpec: String, roamingType: RoamingType): Boolean {
if (!repositoryActive) {
if (!isRepositoryActive) {
return false
}
@@ -127,7 +127,7 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
}
finally {
autoCommitEnabled = true
repositoryActive = repositoryManager.isRepositoryExists()
isRepositoryActive = repositoryManager.isRepositoryExists()
}
}
@@ -139,7 +139,7 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
}
fun beforeApplicationLoaded(application: Application) {
repositoryActive = repositoryManager.isRepositoryExists()
isRepositoryActive = repositoryManager.isRepositoryExists()
application.stateStore.storageManager.addStreamProvider(ApplicationLevelProvider())
@@ -166,9 +166,12 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
open inner class IcsStreamProvider(private val projectId: String?) : StreamProvider {
override val enabled: Boolean
get() = this@IcsManager.active
get() = this@IcsManager.isActive
override fun isApplicable(fileSpec: String, roamingType: RoamingType): Boolean = repositoryActive
override val isDisableExportAction: Boolean
get() = this@IcsManager.isRepositoryActive
override fun isApplicable(fileSpec: String, roamingType: RoamingType): Boolean = isRepositoryActive
override fun processChildren(path: String, roamingType: RoamingType, filter: (name: String) -> Boolean, processor: (name: String, input: InputStream, readOnly: Boolean) -> Boolean): Boolean {
val fullPath = toRepositoryPath(path, roamingType, null)
@@ -178,7 +181,7 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
repository.processChildren(fullPath, filter) { name, input -> processor(name, input, true) }
}
if (!repositoryActive) {
if (!isRepositoryActive) {
return false
}
@@ -201,7 +204,7 @@ class IcsManager @JvmOverloads constructor(dir: Path, val schemeManagerFactory:
protected open fun isAutoCommit(fileSpec: String, roamingType: RoamingType): Boolean = true
override fun read(fileSpec: String, roamingType: RoamingType, consumer: (InputStream?) -> Unit): Boolean {
if (!repositoryActive) {
if (!isRepositoryActive) {
return false
}
@@ -62,7 +62,7 @@ internal class ConfigureIcsAction : DumbAwareAction() {
return
}
if (icsManager.active) {
if (icsManager.isActive) {
e.presentation.isEnabledAndVisible = true
}
else {
+3 -17
View File
@@ -1,18 +1,4 @@
/*
* 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.settingsRepository
import com.intellij.configurationStore.ComponentStoreImpl
@@ -59,7 +45,7 @@ internal class AutoSyncManager(private val icsManager: IcsManager) {
fun registerListeners(project: Project) {
project.messageBus.connect().subscribe(Notifications.TOPIC, object : NotificationsAdapter() {
override fun notify(notification: Notification) {
if (!icsManager.active) {
if (!icsManager.isActive) {
return
}
@@ -82,7 +68,7 @@ internal class AutoSyncManager(private val icsManager: IcsManager) {
}
fun autoSync(onAppExit: Boolean = false, force: Boolean = false) {
if (!enabled || !icsManager.active || (!force && !icsManager.settings.autoSync)) {
if (!enabled || !icsManager.isActive || (!force && !icsManager.settings.autoSync)) {
return
}
@@ -108,7 +108,7 @@ private fun deleteRepository(icsManager: IcsManager) {
indicator.isIndeterminate = true
repositoryManager.deleteRepository()
icsManager.repositoryActive = false
icsManager.isRepositoryActive = false
}
val store = ApplicationManager.getApplication().stateStore as ComponentStoreImpl
@@ -1,18 +1,4 @@
/*
* Copyright 2000-2015 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.
*/
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package org.jetbrains.settingsRepository.test
import com.intellij.configurationStore.SchemeManagerFactoryBase
@@ -64,7 +50,7 @@ abstract class IcsTestCase {
val icsManager by lazy(LazyThreadSafetyMode.NONE) {
val icsManager = IcsManager(tempDirManager.newPath(), lazy { SchemeManagerFactoryBase.TestSchemeManagerFactory(tempDirManager.newPath()) })
icsManager.repositoryManager.createRepositoryIfNeed()
icsManager.repositoryActive = true
icsManager.isRepositoryActive = true
icsManager
}