From 466091e05ef9befca6d5750bccd943a58961620e Mon Sep 17 00:00:00 2001 From: "Anna.Gromova" Date: Thu, 21 Mar 2024 18:36:18 +0100 Subject: [PATCH] IDEA-173548 Welcome screen should show branch name GitOrigin-RevId: 26a9f25e5146eb3bdfb5a74a51cb735e7ec5ff54 --- .../resources/messages/IdeBundle.properties | 1 + .../ide/RecentProjectListActionProvider.kt | 11 +++++++-- .../com/intellij/ide/ReopenProjectAction.java | 23 +++++++++++++++++-- .../ProjectToolbarWidgetAction.kt | 12 ++++++++++ .../RecentProjectFilteringTree.kt | 11 +++++++++ .../recentProjects/RecentProjectTreeItem.kt | 1 + 6 files changed, 55 insertions(+), 4 deletions(-) diff --git a/platform/platform-api/resources/messages/IdeBundle.properties b/platform/platform-api/resources/messages/IdeBundle.properties index 0f25b403c9f4..89a96917a4e3 100644 --- a/platform/platform-api/resources/messages/IdeBundle.properties +++ b/platform/platform-api/resources/messages/IdeBundle.properties @@ -1916,6 +1916,7 @@ label.version.any= link.more=More\u2026 +action.reopen.project.display.name.with.branch={0} [{1}] message.the.path.0.does.not.exist.maybe.on.remote=The path {0} does not exist.\n\ If it is on a removable or network drive, please make sure that the drive is connected. dialog.title.invalidate.caches=Invalidate Caches diff --git a/platform/platform-impl/src/com/intellij/ide/RecentProjectListActionProvider.kt b/platform/platform-impl/src/com/intellij/ide/RecentProjectListActionProvider.kt index 0d71f42f5e4a..2b2c1acd5789 100644 --- a/platform/platform-impl/src/com/intellij/ide/RecentProjectListActionProvider.kt +++ b/platform/platform-impl/src/com/intellij/ide/RecentProjectListActionProvider.kt @@ -11,6 +11,7 @@ import com.intellij.openapi.util.text.NaturalComparator import com.intellij.openapi.wm.impl.welcomeScreen.recentProjects.ProjectsGroupItem import com.intellij.openapi.wm.impl.welcomeScreen.recentProjects.RecentProjectItem import com.intellij.openapi.wm.impl.welcomeScreen.recentProjects.RecentProjectTreeItem +import java.nio.file.Path open class RecentProjectListActionProvider { companion object { @@ -112,14 +113,19 @@ open class RecentProjectListActionProvider { var displayName = recentProjectManager.getDisplayName(path) val projectName = recentProjectManager.getProjectName(path) + var branch: String? = null + if (displayName.isNullOrBlank()) { - displayName = if (duplicates.contains(projectName)) FileUtil.toSystemDependentName(path) else projectName + displayName = if(duplicates.contains(projectName)) { + branch = RecentProjectsManagerBase.getInstanceEx().getProjectMetaInfo(Path.of(path))?.currentBranch + FileUtil.toSystemDependentName(path) + } else projectName } // It's better don't to remove non-existent projects. Sometimes projects stored // on USB-sticks or flash-cards, and it will be nice to have them in the list // when USB device or SD-card is mounted - return ReopenProjectAction(path, projectName, displayName) + return ReopenProjectAction(path, projectName, displayName, branch) } private fun createRecentProject(path: String, duplicates: Set, projectGroup: ProjectGroup?): RecentProjectItem { @@ -128,6 +134,7 @@ open class RecentProjectListActionProvider { projectPath = reopenProjectAction.projectPath, projectName = reopenProjectAction.projectName, displayName = reopenProjectAction.projectNameToDisplay ?: "", + branchName = reopenProjectAction.branchName, projectGroup = projectGroup ) } diff --git a/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java b/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java index 55fb2e7525d5..65d618f86c96 100644 --- a/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java +++ b/platform/platform-impl/src/com/intellij/ide/ReopenProjectAction.java @@ -29,17 +29,22 @@ public class ReopenProjectAction extends AnAction implements DumbAware, LightEdi private final @SystemIndependent String myProjectPath; private final @NlsSafe String myProjectName; private final @NlsSafe String myDisplayName; + + private final @NlsSafe @Nullable String myBranchName; + private boolean myIsRemoved = false; private @Nullable ProjectGroup myProjectGroup; public ReopenProjectAction(@NotNull @SystemIndependent String projectPath, @NlsSafe String projectName, - @NlsSafe String displayName) { + @NlsSafe String displayName, + @NlsSafe @Nullable String branchName) { getTemplatePresentation().setText(IdeBundle.message("action.ReopenProject.reopen.project.text")); getTemplatePresentation().setApplicationScope(true); myProjectPath = projectPath; myProjectName = projectName; myDisplayName = displayName; + myBranchName = branchName; if (Strings.isEmpty(getProjectDisplayName())) { Logger.getInstance(ReopenProjectAction.class).error( @@ -47,6 +52,12 @@ public class ReopenProjectAction extends AnAction implements DumbAware, LightEdi } } + public ReopenProjectAction(@NotNull @SystemIndependent String projectPath, + @NlsSafe String projectName, + @NlsSafe String displayName) { + this(projectPath, projectName, displayName, null); + } + @Override public @NotNull ActionUpdateThread getActionUpdateThread() { return ActionUpdateThread.BGT; @@ -61,7 +72,11 @@ public class ReopenProjectAction extends AnAction implements DumbAware, LightEdi } public @Nullable @NlsSafe String getProjectDisplayName() { - return myProjectPath.equals(myDisplayName) ? FileUtil.getLocationRelativeToUserHome(myProjectPath) : myDisplayName; + String s = myProjectPath.equals(myDisplayName) ? FileUtil.getLocationRelativeToUserHome(myProjectPath) : myDisplayName; + if(myBranchName != null) { + return IdeBundle.message("action.reopen.project.display.name.with.branch", s, myBranchName); + } + return s; } @Override @@ -98,6 +113,10 @@ public class ReopenProjectAction extends AnAction implements DumbAware, LightEdi return myProjectPath; } + public @NlsSafe @Nullable String getBranchName() { + return myBranchName; + } + public boolean isRemoved() { return myIsRemoved; } diff --git a/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/ProjectToolbarWidgetAction.kt b/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/ProjectToolbarWidgetAction.kt index 9f65562f08a7..f1c9230079b9 100644 --- a/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/ProjectToolbarWidgetAction.kt +++ b/platform/platform-impl/src/com/intellij/openapi/wm/impl/headertoolbar/ProjectToolbarWidgetAction.kt @@ -1,6 +1,7 @@ // Copyright 2000-2023 JetBrains s.r.o. and contributors. Use of this source code is governed by the Apache 2.0 license. package com.intellij.openapi.wm.impl.headertoolbar +import com.intellij.icons.AllIcons import com.intellij.ide.ProjectWindowCustomizerService import com.intellij.ide.RecentProjectListActionProvider import com.intellij.ide.RecentProjectsManagerBase @@ -189,6 +190,17 @@ private class ProjectWidgetRenderer : ListCellRenderer