mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-78156 Make git branch max text a bit smaller, add ellipsis to the middle
Move shortenTextWithEllipsis to StringUtil
This commit is contained in:
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user