From a080ac37a0ea9e81987f15aa09fe9a2aeef6894f Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Mon, 2 Jul 2018 15:02:46 +0200 Subject: [PATCH] active read-only repo should not disable export/import actions --- .../src/ExportSettingsAction.kt | 2 +- .../src/StateStorageManagerImpl.kt | 4 ++-- .../configurationStore/StreamProvider.kt | 7 +++--- plugins/settings-repository/src/IcsManager.kt | 23 +++++++++++-------- .../src/actions/SyncAction.kt | 2 +- plugins/settings-repository/src/autoSync.kt | 20 +++------------- .../src/repositoryListEditor.kt | 2 +- .../testSrc/IcsTestCase.kt | 18 ++------------- 8 files changed, 27 insertions(+), 51 deletions(-) diff --git a/platform/configuration-store-impl/src/ExportSettingsAction.kt b/platform/configuration-store-impl/src/ExportSettingsAction.kt index 5f97df448be3..d551266ee485 100644 --- a/platform/configuration-store-impl/src/ExportSettingsAction.kt +++ b/platform/configuration-store-impl/src/ExportSettingsAction.kt @@ -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 diff --git a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt index 4d208ba73da4..9ccbb226d6a5 100644 --- a/platform/configuration-store-impl/src/StateStorageManagerImpl.kt +++ b/platform/configuration-store-impl/src/StateStorageManagerImpl.kt @@ -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) { diff --git a/platform/projectModel-api/src/com/intellij/configurationStore/StreamProvider.kt b/platform/projectModel-api/src/com/intellij/configurationStore/StreamProvider.kt index 631377bd947b..f1fb93ac7da6 100644 --- a/platform/projectModel-api/src/com/intellij/configurationStore/StreamProvider.kt +++ b/platform/projectModel-api/src/com/intellij/configurationStore/StreamProvider.kt @@ -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` */ diff --git a/plugins/settings-repository/src/IcsManager.kt b/plugins/settings-repository/src/IcsManager.kt index ea642e72714f..d8e0e4113928 100644 --- a/plugins/settings-repository/src/IcsManager.kt +++ b/plugins/settings-repository/src/IcsManager.kt @@ -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 } diff --git a/plugins/settings-repository/src/actions/SyncAction.kt b/plugins/settings-repository/src/actions/SyncAction.kt index 45d30699f5d2..ecf97413bc8d 100644 --- a/plugins/settings-repository/src/actions/SyncAction.kt +++ b/plugins/settings-repository/src/actions/SyncAction.kt @@ -62,7 +62,7 @@ internal class ConfigureIcsAction : DumbAwareAction() { return } - if (icsManager.active) { + if (icsManager.isActive) { e.presentation.isEnabledAndVisible = true } else { diff --git a/plugins/settings-repository/src/autoSync.kt b/plugins/settings-repository/src/autoSync.kt index 0d4475a3e2af..5f8381115159 100644 --- a/plugins/settings-repository/src/autoSync.kt +++ b/plugins/settings-repository/src/autoSync.kt @@ -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 } diff --git a/plugins/settings-repository/src/repositoryListEditor.kt b/plugins/settings-repository/src/repositoryListEditor.kt index e99404672108..0eab67b3f6c1 100644 --- a/plugins/settings-repository/src/repositoryListEditor.kt +++ b/plugins/settings-repository/src/repositoryListEditor.kt @@ -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 diff --git a/plugins/settings-repository/testSrc/IcsTestCase.kt b/plugins/settings-repository/testSrc/IcsTestCase.kt index e131420c9d2c..55bd2a89750d 100644 --- a/plugins/settings-repository/testSrc/IcsTestCase.kt +++ b/plugins/settings-repository/testSrc/IcsTestCase.kt @@ -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 }