From d8b06497f6bc8a70e2fbd0696460376ed78bc5f3 Mon Sep 17 00:00:00 2001 From: Julia Beliaeva Date: Sat, 11 May 2024 00:46:50 +0200 Subject: [PATCH] [lvcs] use better presentation for single-change activity items GitOrigin-RevId: 304ea72dc53f231ffd53746cbc416695f66b5b1f --- .../messages/LocalHistoryBundle.properties | 11 ++++++-- .../lvcs/impl/ChangeSetActivityItem.kt | 22 ++++++++++++++- .../impl/LocalHistoryActivityProviderTest.kt | 28 +++++++++---------- 3 files changed, 43 insertions(+), 18 deletions(-) diff --git a/platform/lvcs-impl/resources/messages/LocalHistoryBundle.properties b/platform/lvcs-impl/resources/messages/LocalHistoryBundle.properties index b6b5a89cc393..89a21c25cb82 100644 --- a/platform/lvcs-impl/resources/messages/LocalHistoryBundle.properties +++ b/platform/lvcs-impl/resources/messages/LocalHistoryBundle.properties @@ -69,9 +69,14 @@ activity.list.empty.text.recent=No recent activity detected activity.list.empty.text.recent.matching=No matching recent activity detected activity.list.empty.text.in.scope=No activity in {0} detected activity.list.empty.text.in.scope.matching=No matching activity in {0} detected -activity.item.presentation=Changes -activity.item.presentation.from.path=Changes in {0} -activity.item.presentation.from.paths=Changes in {0} + {1} more +activity.item.presentation=Change +activity.item.presentation.from.path=Change {0} +activity.item.presentation.from.paths=Change {0} + {1} more +activity.item.presentation.create.path=Create {0} +activity.item.presentation.delete.path=Delete {0} +activity.item.presentation.rename.path=Rename {0} to {1} +activity.item.presentation.move.path=Move {0} to {1} +activity.item.presentation.modify.path=Modify {0} activity.filter.empty.text.content=Search by content activity.filter.empty.text.fileName=Search by file name activity.browser.empty.text=No changes detected diff --git a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/ChangeSetActivityItem.kt b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/ChangeSetActivityItem.kt index e2967efed009..b2faf4dfa5c8 100644 --- a/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/ChangeSetActivityItem.kt +++ b/platform/lvcs-impl/src/com/intellij/platform/lvcs/impl/ChangeSetActivityItem.kt @@ -3,7 +3,8 @@ package com.intellij.platform.lvcs.impl import com.intellij.history.ActivityId import com.intellij.history.core.Paths -import com.intellij.history.core.changes.ChangeSet +import com.intellij.history.core.changes.* +import com.intellij.history.integration.CommonActivity import com.intellij.history.integration.LocalHistoryBundle import com.intellij.openapi.util.NlsContexts import com.intellij.openapi.util.NlsSafe @@ -27,10 +28,29 @@ internal class ChangeActivityItem(changeSet: ChangeSet, scope: ActivityScope) : override val name = getName(changeSet, scope) private fun getName(changeSet: ChangeSet, scope: ActivityScope): @NlsContexts.Label String? { + if (changeSet.activityId == CommonActivity.ExternalChange || changeSet.name == null) { + val nameFromSingleChange = getNameFromSingleChange(changeSet, scope) + if (nameFromSingleChange != null) return nameFromSingleChange + } if (changeSet.name != null) return changeSet.name if (!scope.hasMultipleFiles) return LocalHistoryBundle.message("activity.item.presentation") return changeSet.presentableNameFromPaths() } + + private fun getNameFromSingleChange(changeSet: ChangeSet, scope: ActivityScope): @NlsContexts.Label String? { + val singleChange = changeSet.changes.singleOrNull() ?: return null + return when (singleChange) { + is CreateEntryChange -> LocalHistoryBundle.message("activity.item.presentation.create.path", Paths.getNameOf(singleChange.path)) + is DeleteChange -> LocalHistoryBundle.message("activity.item.presentation.delete.path", Paths.getNameOf(singleChange.path)) + is RenameChange -> LocalHistoryBundle.message("activity.item.presentation.rename.path", singleChange.oldName, Paths.getNameOf(singleChange.path)) + is MoveChange -> LocalHistoryBundle.message("activity.item.presentation.move.path", Paths.getNameOf(singleChange.path), + Paths.getNameOf(Paths.getParentOf(singleChange.path))) + is ContentChange -> + if (scope.hasMultipleFiles) LocalHistoryBundle.message("activity.item.presentation.modify.path", Paths.getNameOf(singleChange.path)) + else null + else -> null + } + } } private fun ChangeSet.presentableNameFromPaths(): @NlsContexts.Label String? { diff --git a/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt b/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt index e9e91ae19a09..e1245f3a94c3 100644 --- a/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt +++ b/platform/lvcs-impl/testSrc/com/intellij/platform/lvcs/impl/LocalHistoryActivityProviderTest.kt @@ -79,9 +79,9 @@ class LocalHistoryActivityProviderTest : IntegrationTestCase() { val directoryActivity = provider.loadActivityList(scope, null) TestCase.assertEquals(4, directoryActivity.items.size) TestCase.assertEquals(listOf("label", - "Changes in file.txt", - "Changes in file.txt", - "Changes in directory"), directoryActivity.getNamesList()) + "Modify ${file.name}", + "Create ${file.name}", + "Create ${directory.name}"), directoryActivity.getNamesList()) } fun `test recent activity`() { @@ -143,12 +143,12 @@ class LocalHistoryActivityProviderTest : IntegrationTestCase() { val activityList = provider.loadActivityList(scope, null) TestCase.assertEquals(listOf(visibleLabel, - "Changes in ${otherFile.name}", - "Changes in ${file.name}", - "Changes in ${otherFile.name}", - "Changes in ${file.name}", - "External change", - "External change"), activityList.getNamesList()) + "Modify ${otherFile.name}", + "Modify ${file.name}", + "Modify ${otherFile.name}", + "Modify ${file.name}", + "Create ${otherFile.name}", + "Create ${file.name}"), activityList.getNamesList()) } fun `test parent directory and child file history`() { @@ -171,12 +171,12 @@ class LocalHistoryActivityProviderTest : IntegrationTestCase() { val activityList = provider.loadActivityList(scope, null) - TestCase.assertEquals(listOf("Changes in ${file.name}", + TestCase.assertEquals(listOf("Modify ${file.name}", moveActionName, - "Changes in ${file.name}", - "Changes in ${file.name}", - "Changes in directory" /* directory created */, - "External change" /* file created */), activityList.getNamesList()) + "Modify ${file.name}", + "Modify ${file.name}", + "Create ${directory.name}", + "Create ${file.name}"), activityList.getNamesList()) } fun `test diff data`() {