diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java index 703530758a67..20d2ffb69cf9 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/PushController.java @@ -36,6 +36,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import javax.swing.tree.DefaultMutableTreeNode; +import java.io.File; import java.util.*; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -148,7 +149,7 @@ public class PushController implements Disposable { @NotNull final R repository, @NotNull CheckedTreeNode rootNode) { T target = support.getDefaultTarget(repository); - String repoName = DvcsUtil.getShortRepositoryName(repository); + String repoName = getDisplayedRepoName(repository); S source = support.getSource(repository); final MyRepoModel model = new MyRepoModel(repository, support, mySingleRepoProject, source, target, @@ -187,6 +188,34 @@ public class PushController implements Disposable { rootNode.add(repoNode); } + // TODO This logic shall be moved to some common place and used instead of DvcsUtil.getShortRepositoryName + @NotNull + private String getDisplayedRepoName(@NotNull Repository repository) { + String name = DvcsUtil.getShortRepositoryName(repository); + int slash = name.lastIndexOf(File.separatorChar); + if (slash < 0) { + return name; + } + String candidate = name.substring(slash + 1); + if (!getOtherReposLastNames(repository).contains(candidate)) { + return candidate; + } + return name; + } + + @NotNull + private Set getOtherReposLastNames(@NotNull Repository except) { + Set repos = ContainerUtil.newHashSet(); + for (PushSupport support : myPushSupports) { + for (Repository repo : support.getRepositoryManager().getRepositories()) { + if (!repo.equals(except)) { + repos.add(repo.getRoot().getName()); + } + } + } + return repos; + } + public boolean isPushAllowed() { return ContainerUtil.exists(myPushSupports, new Condition>() { @Override @@ -224,7 +253,7 @@ public class PushController implements Disposable { @NotNull private Collection getNodesForSupport(final PushSupport support) { - return ContainerUtil.mapNotNull(myView2Model.entrySet(), new Function, RepositoryNode>() { + return ContainerUtil.mapNotNull(myView2Model.entrySet(), new Function, RepositoryNode>() { @Override public RepositoryNode fun(Map.Entry entry) { return entry.getValue().getSupport().equals(support) ? entry.getKey() : null; diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java index 6fb6d71ffc20..3f1582afeb04 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/push/ui/RepositoryNode.java @@ -20,6 +20,8 @@ import com.intellij.dvcs.push.PushTargetPanel; import com.intellij.ui.CheckedTreeNode; import com.intellij.ui.ColoredTreeCellRenderer; import com.intellij.ui.SimpleTextAttributes; +import com.intellij.util.ui.GraphicsUtil; +import com.intellij.util.ui.UIUtil; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -61,7 +63,7 @@ public class RepositoryNode extends CheckedTreeNode implements EditableTreeNode, renderer.setIconTextGap(CHECKBOX_WIDTH - myLoadingIcon.getIconWidth()); repoFixedWidth += CHECKBOX_WIDTH; } - renderer.append(myRepositoryPanel.getRepositoryName(), SimpleTextAttributes.GRAY_ATTRIBUTES); + renderer.append(getRepoName(renderer, repoFixedWidth), SimpleTextAttributes.GRAY_ATTRIBUTES); renderer.appendFixedTextFragmentWidth(repoFixedWidth); renderer.append(myRepositoryPanel.getSourceName(), SimpleTextAttributes.REGULAR_ATTRIBUTES); renderer.append(myRepositoryPanel.getArrow(), SimpleTextAttributes.REGULAR_ATTRIBUTES); @@ -71,6 +73,12 @@ public class RepositoryNode extends CheckedTreeNode implements EditableTreeNode, renderer.setBorder(new EmptyBorder(insets)); } + @NotNull + private String getRepoName(@NotNull ColoredTreeCellRenderer renderer, int maxWidth) { + String name = myRepositoryPanel.getRepositoryName(); + return GraphicsUtil.stringWidth(name, renderer.getFont()) > maxWidth - UIUtil.DEFAULT_VGAP ? name + " " : name; + } + @Override public Object getUserObject() { return myRepositoryPanel;