diff --git a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/IModelSyncService.kt b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/IModelSyncService.kt index 7971c62dc7..5f81707d81 100644 --- a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/IModelSyncService.kt +++ b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/IModelSyncService.kt @@ -36,6 +36,7 @@ interface IModelSyncService { fun getServerConnections(): List fun getUsedServerConnections(): List fun getBindings(): List + fun isReadonly(binding: IBinding): Boolean fun switchBranch(oldBranchRef: BranchReference, newBranchRef: BranchReference, dropLocalChanges: Boolean = false) } diff --git a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ModelSyncService.kt b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ModelSyncService.kt index 3ecfd63a0d..83032b4058 100644 --- a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ModelSyncService.kt +++ b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ModelSyncService.kt @@ -85,6 +85,12 @@ class ModelSyncService(val project: Project) : return loadedState.bindings.keys.map { Binding(it) } } + @Synchronized + override fun isReadonly(binding: IBinding): Boolean { + binding as Binding + return loadedState.bindings[binding.id]?.readonly == true + } + @Synchronized override fun switchBranch(oldBranchRef: BranchReference, newBranchRef: BranchReference, dropLocalChanges: Boolean) { updateState { diff --git a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ui/ModelSyncStatusWidget.kt b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ui/ModelSyncStatusWidget.kt index fe5cc73a8b..de1c11a12a 100644 --- a/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ui/ModelSyncStatusWidget.kt +++ b/mps-sync-plugin3/src/main/kotlin/org/modelix/mps/sync3/ui/ModelSyncStatusWidget.kt @@ -246,27 +246,27 @@ class ModelSyncStatusWidget(val project: Project) : CustomStatusBarWidget, Statu private fun getText(): @NlsContexts.Label String { val service = IModelSyncService.getInstance(project) var result: String? = null - for (connection in service.getServerConnections()) { - for (binding in connection.getBindings()) { - if (binding.isEnabled()) { - when (connection.getStatus()) { - IServerConnection.Status.CONNECTED -> {} - IServerConnection.Status.DISCONNECTED -> return "Disconnected" - IServerConnection.Status.AUTHORIZATION_REQUIRED -> { - return "Click to log in" - } - } - result = when (val status = binding.getStatus()) { - IBinding.Status.Disabled -> "Disabled" - IBinding.Status.Initializing -> "Initializing" - is IBinding.Status.Synced -> "Synchronized: ${status.versionHash.take(5)}" - is IBinding.Status.Syncing -> "Synchronizing: ${status.progress()}" - is IBinding.Status.Error -> "Synchronization failed: ${status.message}" - is IBinding.Status.NoPermission -> "${status.user} has no permission on ${binding.getBranchRef().repositoryId}" + service.getUsedServerConnections() + .flatMap { it.getBindings() } + // readonly comes first so that the result version hash is reliably the one from the modifiable binding + .sortedByDescending { service.isReadonly(it) } + .forEach { binding -> + when (binding.getConnection().getStatus()) { + IServerConnection.Status.CONNECTED -> {} + IServerConnection.Status.DISCONNECTED -> return "Disconnected" + IServerConnection.Status.AUTHORIZATION_REQUIRED -> { + return "Click to log in" } } + result = when (val status = binding.getStatus()) { + IBinding.Status.Disabled -> "Disabled" + IBinding.Status.Initializing -> "Initializing" + is IBinding.Status.Synced -> "Synchronized: ${status.versionHash.take(5)}" + is IBinding.Status.Syncing -> "Synchronizing: ${status.progress()}" + is IBinding.Status.Error -> "Synchronization failed: ${status.message}" + is IBinding.Status.NoPermission -> "${status.user} has no permission on ${binding.getBranchRef().repositoryId}" + } } - } return result ?: "Not Synchronized" } }