IDEA-173548 Welcome screen should show branch name

GitOrigin-RevId: 26a9f25e5146eb3bdfb5a74a51cb735e7ec5ff54
This commit is contained in:
Anna.Gromova
2024-03-22 13:10:47 +00:00
committed by intellij-monorepo-bot
parent 277eeda1b1
commit 466091e05e
6 changed files with 55 additions and 4 deletions
@@ -1916,6 +1916,7 @@ label.version.any=<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
@@ -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<String>, projectGroup: ProjectGroup?): RecentProjectItem {
@@ -128,6 +134,7 @@ open class RecentProjectListActionProvider {
projectPath = reopenProjectAction.projectPath,
projectName = reopenProjectAction.projectName,
displayName = reopenProjectAction.projectNameToDisplay ?: "",
branchName = reopenProjectAction.branchName,
projectGroup = projectGroup
)
}
@@ -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;
}
@@ -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<PopupFactoryImpl.ActionIt
foreground = UIUtil.getLabelInfoForeground()
}.component
}
action.branchName?.let {
row {
label(it)
.customize(UnscaledGaps(bottom = 4, top = 4))
.applyToComponent {
icon = AllIcons.Vcs.Branch
font = JBFont.smallOrNewUiMedium()
foreground = UIUtil.getLabelInfoForeground()
}.component
}
}
}
}
}
@@ -383,6 +383,10 @@ internal class RecentProjectFilteringTree(
private val projectPathLabel = ComponentPanelBuilder.createNonWrappingCommentComponent("").apply {
foreground = NamedColorUtil.getInactiveTextColor()
}
private val projectBranchNameLabel = ComponentPanelBuilder.createNonWrappingCommentComponent("").apply {
foreground = NamedColorUtil.getInactiveTextColor()
icon = AllIcons.Vcs.Branch
}
private val projectIconLabel = JLabel()
private val projectActions = ActionsButton().apply {
setState(AllIcons.Ide.Notification.Gear, false)
@@ -392,6 +396,7 @@ internal class RecentProjectFilteringTree(
add(projectNameLabel)
add(projectPathLabel)
add(projectBranchNameLabel)
}
private val updateScaleHelper = UpdateScaleHelper()
@@ -420,6 +425,12 @@ internal class RecentProjectFilteringTree(
disabledIcon = recentProjectsManager.getProjectIcon(item.projectPath, isProjectValid = false)
isEnabled = isPathValid
}
projectBranchNameLabel.apply {
isVisible = item.branchName != null
if(isVisible) {
text = item.branchName
}
}
if (isPathValid) {
buttonViewModel.prepareActionsButton(projectActions, rowHovered, AllIcons.Ide.Notification.Gear,
AllIcons.Ide.Notification.GearHover)
@@ -51,6 +51,7 @@ internal data class RecentProjectItem(
val projectPath: @SystemIndependent String,
@NlsSafe val projectName: String,
@NlsSafe val displayName: String,
@NlsSafe val branchName: String? = null,
val projectGroup: ProjectGroup?
) : RecentProjectTreeItem {
override fun displayName(): String = displayName