Skip to content

Commit

Permalink
Handle updating "Difference/s" label on compare editor for empty toolbar
Browse files Browse the repository at this point in the history
Co-authored-by: Federico Jeanne <2205684+fedejeanne@users.noreply.github.com>
  • Loading branch information
lathapatil and fedejeanne committed Apr 17, 2024
1 parent bcb197c commit 8d37020
Showing 1 changed file with 16 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5408,27 +5408,30 @@ private boolean isIgnoreAncestor() {

private void updateToolbarLabel() {
final String DIFF_COUNT_ID = "DiffCount"; //$NON-NLS-1$
ToolBarManager tbm =
(ToolBarManager) getToolBarManager(fComposite.getParent());
boolean isUpdateNeeded = false;
ToolBarManager tbm = (ToolBarManager) getToolBarManager(fComposite.getParent());
int differenceCount = fMerger.changesCount();
if (tbm != null) {
if (tbm != null && tbm.getItems().length > 0) {

String label = MessageFormat.format(CompareMessages.TextMergeViewer_differences, differenceCount);
LabelContributionItem labelContributionItem = new LabelContributionItem(DIFF_COUNT_ID,
label);
LabelContributionItem labelContributionItem = new LabelContributionItem(DIFF_COUNT_ID, label);

if (tbm.find(DIFF_COUNT_ID) != null) {
tbm.replaceItem(DIFF_COUNT_ID, labelContributionItem);
} else {
isUpdateNeeded = true;
} else if (tbm.find("diffLabel") != null) { //$NON-NLS-1$
tbm.appendToGroup("diffLabel", labelContributionItem); //$NON-NLS-1$
isUpdateNeeded = true;
}
if (isUpdateNeeded) {
fComposite.getDisplay().asyncExec(() -> {
// relayout in next tick
ToolBar control = tbm.getControl();
if (control != null && !control.isDisposed()) {
tbm.update(true);
}
});
}
fComposite.getDisplay().asyncExec(() -> {
// relayout in next tick
ToolBar control = tbm.getControl();
if (control != null && !control.isDisposed()) {
tbm.update(true);
}
});
}
}

Expand Down

0 comments on commit 8d37020

Please sign in to comment.