in rider/src/main/kotlin/com/jetbrains/rider/plugins/godot/projectView/GodotUidTracker.kt [75:130]
fun onEvent(events: MutableList<out VFileEvent>) {
val validProjects = synchronized(lock) { mutableListOf<Project>().also { it.addAll(projects) } }.filter {
!isUndoRedoInProgress(it) && !it.isDisposed
}.toList()
for (event in events) {
if (!isValidEvent(event)) continue
for (project in validProjects) {
if (isApplicableForProject(event, project)) {
val actions = getOrCreate(project)
if (isUidFile(event)) // Collect modified uid files at first (LocalHistory or git or something else)
actions.addInitialSetOfChangedUidFiles(Paths.get(event.path))
else {
try {
when (event) {
is VFileDeleteEvent -> {
val uidFile = getUidFile(event.path) ?: continue
actions.add(uidFile, project) {
val fileToDelete = VfsUtil.findFile(uidFile, true)
if (fileToDelete != null) {
fileToDelete.readBytes() // Preload file content into VFS to allow local history to restore it on undo operation
fileToDelete.delete(this)
}
}
}
is VFileMoveEvent -> {
val uidFile = getUidFile(event.oldPath) ?: continue
actions.add(uidFile, project) { VfsUtil.findFile(uidFile, true)?.move(this, event.newParent)
}
}
is VFilePropertyChangeEvent -> {
if (!event.isRename) continue
val uidFile = getUidFile(event.oldPath) ?: continue
actions.add(uidFile, project) {
val target = getUidFileName(event.newValue as String)
val origin = VfsUtil.findFile(uidFile, true)
val conflictingUid = origin?.parent?.findChild(target)
if (conflictingUid != null) {
logger.warn("Removing conflicting uid $conflictingUid")
conflictingUid.delete(this)
}
origin?.rename(this, target)
}
}
}
}
catch (t: Throwable) {
logger.error(t)
continue
}
}
}
}
}
}