[push] Fix long repository names

* Shorten repository names more: use only the folder name (unless
  there would be a conflict of two identical names).
* Make sure there is some padding between repo name and branch.
This commit is contained in:
Kirill Likhodedov
2014-09-23 16:15:03 +04:00
parent c1aa9a85fb
commit f4195292e9
2 changed files with 40 additions and 3 deletions
@@ -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<R, S, T> model = new MyRepoModel<R, S, T>(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<String> getOtherReposLastNames(@NotNull Repository except) {
Set<String> 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<PushSupport<?, ?, ?>>() {
@Override
@@ -224,7 +253,7 @@ public class PushController implements Disposable {
@NotNull
private Collection<RepositoryNode> getNodesForSupport(final PushSupport<?, ?, ?> support) {
return ContainerUtil.mapNotNull(myView2Model.entrySet(), new Function<Map.Entry<RepositoryNode,MyRepoModel>, RepositoryNode>() {
return ContainerUtil.mapNotNull(myView2Model.entrySet(), new Function<Map.Entry<RepositoryNode, MyRepoModel>, RepositoryNode>() {
@Override
public RepositoryNode fun(Map.Entry<RepositoryNode, MyRepoModel> entry) {
return entry.getValue().getSupport().equals(support) ? entry.getKey() : null;
@@ -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;