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 b95364f
Showing 1 changed file with 24 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2059,14 +2059,7 @@ protected void createControls(Composite composite) {
// 1st row
if (fMarginWidth > 0) {
fAncestorCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
fAncestorCanvas.addPaintListener(new PaintListener() {

@Override
public void paintControl(PaintEvent e) {
paintSides(e.gc, fAncestor, fAncestorCanvas, false);

}
});
fAncestorCanvas.addPaintListener(e -> paintSides(e.gc, fAncestor, fAncestorCanvas, false));
fAncestorCanvas.addMouseListener(
new MouseAdapter() {
@Override
Expand Down Expand Up @@ -2095,14 +2088,7 @@ public void getName(AccessibleEvent e) {
// 2nd row
if (fMarginWidth > 0) {
fLeftCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
fLeftCanvas.addPaintListener(new PaintListener() {

@Override
public void paintControl(PaintEvent e) {
paintSides(e.gc, fLeft, fLeftCanvas, false);

}
});
fLeftCanvas.addPaintListener(e -> paintSides(e.gc, fLeft, fLeftCanvas, false));
fLeftCanvas.addMouseListener(
new MouseAdapter() {
@Override
Expand Down Expand Up @@ -2158,14 +2144,7 @@ public void getName(AccessibleEvent e) {

if (fMarginWidth > 0) {
fRightCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
fRightCanvas.addPaintListener(new PaintListener() {

@Override
public void paintControl(PaintEvent e) {
paintSides(e.gc, fRight, fRightCanvas, fSynchronizedScrolling);

}
});
fRightCanvas.addPaintListener(e -> paintSides(e.gc, fRight, fRightCanvas, fSynchronizedScrolling));
fRightCanvas.addMouseListener(
new MouseAdapter() {
@Override
Expand All @@ -2191,14 +2170,10 @@ public void mouseDown(MouseEvent e) {
);

fBirdsEyeCanvas = new Canvas(composite, SWT.DOUBLE_BUFFERED);
fBirdsEyeCanvas.addPaintListener(new PaintListener() {

@Override
public void paintControl(PaintEvent e) {
updateVScrollBar(); // Update scroll bar here as initially viewport height is wrong
paintBirdsEyeView((Canvas) e.widget, e.gc);
fBirdsEyeCanvas.addPaintListener(e -> {
updateVScrollBar(); // Update scroll bar here as initially viewport height is wrong
paintBirdsEyeView((Canvas) e.widget, e.gc);

}
});

fBirdsEyeCanvas.addMouseListener(
Expand Down Expand Up @@ -2480,14 +2455,7 @@ protected final Control createCenterControl(Composite parent) {

final Canvas canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED);

canvas.addPaintListener(new PaintListener() {

@Override
public void paintControl(PaintEvent e) {
paintCenter((Canvas) e.widget, e.gc);

}
});
canvas.addPaintListener(e -> paintCenter((Canvas) e.widget, e.gc));
new HoverResizer(canvas, HORIZONTAL);

Cursor normalCursor= canvas.getDisplay().getSystemCursor(SWT.CURSOR_ARROW);
Expand Down Expand Up @@ -4002,11 +3970,7 @@ private void configureCompareFilterActions(Object input, Object ancestor,
}

private void disposeCompareFilterActions(boolean updateActionBars) {
Iterator<ChangeCompareFilterPropertyAction> compareFilterActionsIterator = fCompareFilterActions
.iterator();
while (compareFilterActionsIterator.hasNext()) {
ChangeCompareFilterPropertyAction compareFilterAction = compareFilterActionsIterator
.next();
for (ChangeCompareFilterPropertyAction compareFilterAction : fCompareFilterActions) {
fLeft.removeTextAction(compareFilterAction);
fRight.removeTextAction(compareFilterAction);
fAncestor.removeTextAction(compareFilterAction);
Expand Down Expand Up @@ -5408,27 +5372,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 b95364f

Please sign in to comment.