Skip to content

Commit

Permalink
Issue apache#101 fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
baratynskiy authored and SerVB committed Jul 23, 2019
1 parent 9594672 commit 705db18
Showing 1 changed file with 31 additions and 14 deletions.
45 changes: 31 additions & 14 deletions src/main/java/org/jetbrains/kotlin/installer/KotlinInstaller.kt
Original file line number Diff line number Diff line change
Expand Up @@ -42,23 +42,40 @@ class KotlinInstaller : Yenta() {
ProjectUtils.checkKtHome()
WindowManager.getDefault().registry.addPropertyChangeListener listener@{
if (it.propertyName.equals("opened")) {
if (KotlinUpdater.updated) return@listener

val newHashSet = it.newValue as HashSet<TopComponent>
val oldHashSet = it.oldValue as HashSet<TopComponent>
newHashSet.filter {!oldHashSet.contains(it)}
.forEach {
val dataObject = it.lookup.lookup(DataObject::class.java) ?: return@forEach
val currentFile = dataObject.primaryFile
if (currentFile != null && currentFile.mimeType.equals("text/x-kt")) {
KotlinUpdater.checkUpdates()
val project = ProjectUtils.getKotlinProjectForFileObject(currentFile)
if (KotlinProjectHelper.INSTANCE.checkProject(project)) MavenHelper.configure(project)
}
}
checkProjectConfiguration(it)
checkUpdates(it)
}
}
}
}

private fun checkProjectConfiguration(changeEvent: PropertyChangeEvent) {
val newHashSet = changeEvent.newValue as HashSet<TopComponent>
val oldHashSet = changeEvent.oldValue as HashSet<TopComponent>
newHashSet.filter {!oldHashSet.contains(it)}
.forEach {
val dataObject = it.lookup.lookup(DataObject::class.java) ?: return@forEach
val currentFile = dataObject.primaryFile
if (currentFile != null && currentFile.mimeType.equals("text/x-kt")) {
val project = ProjectUtils.getKotlinProjectForFileObject(currentFile)
if (KotlinProjectHelper.INSTANCE.checkProject(project)) MavenHelper.configure(project)
}
}
}

private fun checkUpdates(changeEvent: PropertyChangeEvent) {
if (KotlinUpdater.updated) return

val newHashSet = changeEvent.newValue as HashSet<TopComponent>
val oldHashSet = changeEvent.oldValue as HashSet<TopComponent>
newHashSet.filter {!oldHashSet.contains(it)}
.forEach {
val dataObject = it.lookup.lookup(DataObject::class.java) ?: return@forEach
val currentFile = dataObject.primaryFile
if (currentFile != null && currentFile.mimeType.equals("text/x-kt")) {
KotlinUpdater.checkUpdates()
}
}
}

}

0 comments on commit 705db18

Please sign in to comment.