IDEA-78156 Make git branch max text a bit smaller, add ellipsis to the middle

Move shortenTextWithEllipsis to StringUtil
This commit is contained in:
Kirill Likhodedov
2012-02-21 21:13:47 +04:00
parent 9f2da31c07
commit 35bd269410
2 changed files with 24 additions and 2 deletions
@@ -2247,4 +2247,23 @@ public class StringUtil {
public static boolean isOctalDigit(char c) {
return '0' <= c && c <= '7';
}
@NotNull
public static String shortenTextWithEllipsis(final String text, final int max_length, final int suffix_length) {
final int prefix_length = max_length - suffix_length - 3;
assert prefix_length > 0;
final StringBuilder buffer = new StringBuilder();
final int textLength = text.length();
if (textLength > max_length) {
StringBuilder shorterText = new StringBuilder();
shorterText.append(text.substring(0, prefix_length));
shorterText.append("...");
shorterText.append(text.substring(textLength - suffix_length));
buffer.append(shorterText.toString());
}
else {
buffer.append(text);
}
return buffer.toString();
}
}
@@ -43,11 +43,13 @@ public class GitBranchWidget extends EditorBasedWidget implements StatusBarWidge
private final GitVcsSettings mySettings;
private volatile String myText = "";
private volatile String myTooltip = "";
private final String myMaxString;
public GitBranchWidget(Project project) {
super(project);
GitRepositoryManager.getInstance(project).addListenerToAllRepositories(this);
mySettings = GitVcsSettings.getInstance(project);
myMaxString = "Git: Rebasing master";
}
@Override
@@ -108,7 +110,7 @@ public class GitBranchWidget extends EditorBasedWidget implements StatusBarWidge
@NotNull
@Override
public String getMaxValue() {
return "Git: Rebasing abcdefghij";
return myMaxString;
}
@Override
@@ -142,7 +144,8 @@ public class GitBranchWidget extends EditorBasedWidget implements StatusBarWidge
return;
}
myText = GitBranchUiUtil.getDisplayableBranchText(repo);
int maxLength = myMaxString.length() - 1; // -1, because there are arrows indicating that it is a popup
myText = StringUtil.shortenTextWithEllipsis(GitBranchUiUtil.getDisplayableBranchText(repo), maxLength, 5);
myTooltip = getDisplayableBranchTooltip(repo);
myStatusBar.updateWidget(ID());
mySettings.setRecentRoot(repo.getRoot().getPath());