From 14f72e5e05fb0f5c615a54caf7f2ef3f66e2ea5d Mon Sep 17 00:00:00 2001 From: Vladimir Krivosheev Date: Tue, 18 Apr 2017 18:15:22 +0200 Subject: [PATCH] =?UTF-8?q?RunManager=20=E2=80=94=20do=20not=20set=20selec?= =?UTF-8?q?tedConfiguration=20in=20the=20iterator=20loop=20(can=20cause=20?= =?UTF-8?q?event=20dispatch)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../intellij/execution/impl/RunManagerImpl.kt | 48 +++++++++---------- 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt index b988f4258d22..ce49a80c33b1 100644 --- a/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt +++ b/platform/lang-impl/src/com/intellij/execution/impl/RunManagerImpl.kt @@ -102,15 +102,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi // When readExternal not all configuration may be loaded, so we need to remember the selected configuration // so that when it is eventually loaded, we can mark is as a selected. - private var loadedSelectedConfigurationUniqueName: String? = null - private var selectedConfigurationId: String? = null - set(value) { - field = value - if (value != null) { - loadedSelectedConfigurationUniqueName = null - } - } private val iconCache = TimedIconCache() private val _config by lazy { RunManagerConfig(PropertiesComponent.getInstance(project)) } @@ -369,13 +361,12 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } override var selectedConfiguration: RunnerAndConfigurationSettings? - get() { - if (selectedConfigurationId == null && loadedSelectedConfigurationUniqueName != null) { - selectedConfigurationId = loadedSelectedConfigurationUniqueName - } - return selectedConfigurationId?.let { lock.read { idToSettings.get(it) } } - } + get() = selectedConfigurationId?.let { lock.read { idToSettings.get(it) } } set(value) { + if (value?.uniqueID == selectedConfigurationId) { + return + } + selectedConfigurationId = value?.uniqueID fireRunConfigurationSelected() } @@ -643,25 +634,25 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } immutableSortedSettingsList = null - loadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) - selectedConfigurationId = loadedSelectedConfigurationUniqueName + selectedConfigurationId = parentNode.getAttributeValue(SELECTED_ATTR) } fireBeforeRunTasksUpdated() + // todo is it required fireRunConfigurationSelected() } fun readContext(parentNode: Element) { - loadedSelectedConfigurationUniqueName = parentNode.getAttributeValue(SELECTED_ATTR) + var selectedConfigurationId = parentNode.getAttributeValue(SELECTED_ATTR) for (element in parentNode.children) { val config = loadConfiguration(element, false) - if (loadedSelectedConfigurationUniqueName == null && element.getAttributeValue(SELECTED_ATTR).toBoolean()) { - loadedSelectedConfigurationUniqueName = config.uniqueID + if (selectedConfigurationId == null && element.getAttributeValue(SELECTED_ATTR).toBoolean()) { + selectedConfigurationId = config.uniqueID } } - selectedConfigurationId = loadedSelectedConfigurationUniqueName + this.selectedConfigurationId = selectedConfigurationId fireRunConfigurationSelected() } @@ -699,8 +690,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi else { val configurations = SmartList() val iterator = idToSettings.values.iterator() - while (iterator.hasNext()) { - val configuration = iterator.next() + for (configuration in iterator) { if (configuration.isTemporary || !configuration.isShared) { iterator.remove() @@ -708,15 +698,16 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } } - if (selectedConfigurationId != null && idToSettings.containsKey(selectedConfigurationId!!)) { - selectedConfigurationId = null + selectedConfigurationId?.let { + if (idToSettings.containsKey(it)) { + selectedConfigurationId = null + } } configurations } templateIdToConfiguration.clear() - loadedSelectedConfigurationUniqueName = null recentlyUsedTemporaries.clear() configurations } @@ -1103,6 +1094,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi val changedSettings = SmartList() val removed = SmartList() + var selectedConfigurationWasRemoved = false lock.write { immutableSortedSettingsList = null @@ -1110,7 +1102,7 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi for (settings in iterator) { if (toRemove.contains(settings)) { if (selectedConfigurationId == settings.uniqueID) { - selectedConfiguration = null + selectedConfigurationWasRemoved = true } iterator.remove() @@ -1137,6 +1129,10 @@ open class RunManagerImpl(internal val project: Project) : RunManagerEx(), Persi } } + if (selectedConfigurationWasRemoved) { + selectedConfiguration = null + } + removed.forEach { myDispatcher.multicaster.runConfigurationRemoved(it) } changedSettings.forEach { myDispatcher.multicaster.runConfigurationChanged(it, null) } }