Skip to content

Commit e987000

Browse files
tobias-melcherBeckerWdf
authored andcommitted
Show Diff in "replace with local history" Dialog On Selection Change
- disallow multi selection in "replace with local history" dialog - fix layouting issue on MacOS when loading the compare viewers on selection change
1 parent 3776c2f commit e987000

File tree

5 files changed

+128
-8
lines changed

5 files changed

+128
-8
lines changed

team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.team.ui; singleton:=true
5-
Bundle-Version: 3.10.500.qualifier
5+
Bundle-Version: 3.11.0.qualifier
66
Bundle-Activator: org.eclipse.team.internal.ui.TeamUIPlugin
77
Bundle-Vendor: %providerName
88
Bundle-Localization: plugin

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,7 @@ private IWorkbenchPartSite getWorkbenchSite(IHistoryPageSite parentSite) {
336336
return null;
337337
}
338338

339-
@Override
340-
public void createControl(Composite parent) {
341-
339+
public final void createControl(Composite parent, boolean allowMultiSelection) {
342340
localComposite = new Composite(parent, SWT.NONE);
343341
GridLayout layout = new GridLayout();
344342
layout.marginHeight = 0;
@@ -348,7 +346,7 @@ public void createControl(Composite parent) {
348346
data.grabExcessVerticalSpace = true;
349347
localComposite.setLayoutData(data);
350348

351-
treeViewer = createTree(localComposite);
349+
treeViewer = createTree(localComposite, allowMultiSelection);
352350

353351
contributeActions();
354352

@@ -362,6 +360,11 @@ public void createControl(Composite parent) {
362360
PlatformUI.getWorkbench().getHelpSystem().setHelp(localComposite, IHelpContextIds.LOCAL_HISTORY_PAGE);
363361
}
364362

363+
@Override
364+
public void createControl(Composite parent) {
365+
createControl(parent, true);
366+
}
367+
365368
private void contributeActions() {
366369
final IPreferenceStore store = TeamUIPlugin.getPlugin().getPreferenceStore();
367370
//Group by Date
@@ -599,8 +602,12 @@ private boolean showGetContentsAction(ITreeSelection sel) {
599602
* @return the group control
600603
*/
601604
protected TreeViewer createTree(Composite parent) {
605+
return createTree(parent, true);
606+
}
607+
608+
protected final TreeViewer createTree(Composite parent, boolean allowMultiSelection) {
602609
historyTableProvider = new LocalFileHistoryTableProvider();
603-
TreeViewer viewer = historyTableProvider.createTree(parent);
610+
TreeViewer viewer = historyTableProvider.createTree(parent, allowMultiSelection);
604611
viewer.setContentProvider(new LocalHistoryContentProvider());
605612
return viewer;
606613
}

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryTableProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,15 @@ public void widgetSelected(SelectionEvent e) {
291291
* @return TableViewer
292292
*/
293293
public TreeViewer createTree(Composite parent) {
294-
Tree tree = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION);
294+
return createTree(parent, true);
295+
}
296+
297+
public TreeViewer createTree(Composite parent, boolean allowMultiSelection) {
298+
int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION;
299+
if (allowMultiSelection) {
300+
style = style | SWT.MULTI;
301+
}
302+
Tree tree = new Tree(parent, style);
295303
tree.setHeaderVisible(true);
296304
tree.setLinesVisible(false);
297305

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/ReplaceLocalHistory.java

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,29 @@
1515

1616
import org.eclipse.compare.CompareConfiguration;
1717
import org.eclipse.compare.CompareUI;
18+
import org.eclipse.compare.CompareViewerPane;
1819
import org.eclipse.compare.structuremergeviewer.ICompareInput;
1920
import org.eclipse.core.resources.IFile;
2021
import org.eclipse.core.resources.IFileState;
2122
import org.eclipse.core.runtime.CoreException;
2223
import org.eclipse.jface.action.IAction;
24+
import org.eclipse.jface.action.IToolBarManager;
25+
import org.eclipse.swt.SWT;
26+
import org.eclipse.swt.events.MouseEvent;
27+
import org.eclipse.swt.events.MouseListener;
28+
import org.eclipse.swt.events.SelectionAdapter;
29+
import org.eclipse.swt.events.SelectionEvent;
30+
import org.eclipse.swt.widgets.Composite;
31+
import org.eclipse.swt.widgets.Control;
32+
import org.eclipse.swt.widgets.Event;
2333
import org.eclipse.swt.widgets.Shell;
34+
import org.eclipse.swt.widgets.Tree;
2435
import org.eclipse.team.internal.ui.TeamUIMessages;
2536
import org.eclipse.team.internal.ui.TeamUIPlugin;
2637
import org.eclipse.team.internal.ui.Utils;
2738
import org.eclipse.team.ui.history.HistoryPageCompareEditorInput;
2839
import org.eclipse.team.ui.history.IHistoryPageSource;
40+
import org.eclipse.ui.part.IPage;
2941

3042
public class ReplaceLocalHistory extends ShowLocalHistory {
3143

@@ -54,6 +66,40 @@ public boolean isEditionSelectionDialog() {
5466
public String getOKButtonLabel() {
5567
return TeamUIMessages.ReplaceLocalHistory_0;
5668
}
69+
70+
@Override
71+
protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) {
72+
var page = super.createPage(parent, toolBarManager, false);
73+
Tree tree = getTree(page);
74+
runDefaultSelectionEventOnSelectionChange(tree);
75+
return page;
76+
}
77+
78+
private void runDefaultSelectionEventOnSelectionChange(Tree tree) {
79+
if (tree == null) {
80+
return;
81+
}
82+
var handler = new NotifyDefaultSelectionOnWidgetSelectedHandler(tree);
83+
tree.addSelectionListener(handler);
84+
tree.addMouseListener(handler);
85+
}
86+
87+
private Tree getTree(IPage page) {
88+
Control control = page.getControl();
89+
if (!(control instanceof Composite composite)) {
90+
return null;
91+
}
92+
Control[] children = composite.getChildren();
93+
if (children == null) {
94+
return null;
95+
}
96+
for (Control child : children) {
97+
if (child instanceof Tree t) {
98+
return t;
99+
}
100+
}
101+
return null;
102+
}
57103
@Override
58104
public boolean okPressed() {
59105
try {
@@ -76,4 +122,50 @@ public boolean okPressed() {
76122
protected String getPromptTitle() {
77123
return TeamUIMessages.ReplaceLocalHistory_1;
78124
}
125+
126+
private static final class NotifyDefaultSelectionOnWidgetSelectedHandler extends SelectionAdapter
127+
implements MouseListener {
128+
private boolean mouseDownPressed = false;
129+
private Runnable runOnMouseUp;
130+
private final Tree tree;
131+
132+
public NotifyDefaultSelectionOnWidgetSelectedHandler(Tree tree) {
133+
this.tree = tree;
134+
}
135+
@Override
136+
public void widgetSelected(SelectionEvent e) {
137+
if (tree.getSelectionCount() != 1) {
138+
return;
139+
}
140+
Runnable r = () -> {
141+
Event event = new Event();
142+
event.item = e.item;
143+
tree.notifyListeners(SWT.DefaultSelection, event);
144+
};
145+
if (mouseDownPressed) {
146+
// run DefaultSelection event after mouseUp
147+
runOnMouseUp = r;
148+
return;
149+
}
150+
r.run();
151+
}
152+
153+
@Override
154+
public void mouseDoubleClick(MouseEvent e) {
155+
}
156+
157+
@Override
158+
public void mouseDown(MouseEvent e) {
159+
mouseDownPressed = true;
160+
}
161+
162+
@Override
163+
public void mouseUp(MouseEvent e) {
164+
mouseDownPressed = false;
165+
if (runOnMouseUp != null) {
166+
runOnMouseUp.run();
167+
runOnMouseUp = null;
168+
}
169+
}
170+
}
79171
}

team/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/HistoryPageCompareEditorInput.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.eclipse.team.internal.ui.TeamUIMessages;
3232
import org.eclipse.team.internal.ui.Utils;
3333
import org.eclipse.team.internal.ui.history.DialogHistoryPageSite;
34+
import org.eclipse.team.internal.ui.history.LocalHistoryPage;
3435
import org.eclipse.team.ui.PageCompareEditorInput;
3536
import org.eclipse.ui.part.IPage;
3637
import org.eclipse.ui.part.Page;
@@ -79,11 +80,23 @@ protected void handleDispose() {
7980

8081
@Override
8182
protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) {
83+
return createPage(parent, toolBarManager, true);
84+
}
85+
86+
/**
87+
* @since 3.11
88+
*/
89+
protected final IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager,
90+
boolean allowMultiSelection) {
8291
site = new DialogHistoryPageSite(parent.getShell());
8392
historyPage = (IHistoryPage)pageSource.createPage(object);
8493
historyPage.setSite(site);
8594
site.setToolBarManager(toolBarManager);
86-
((Page) historyPage).createControl(parent);
95+
if (historyPage instanceof LocalHistoryPage localHistoryPage) {
96+
localHistoryPage.createControl(parent, allowMultiSelection);
97+
} else {
98+
((Page) historyPage).createControl(parent);
99+
}
87100
historyPage.setInput(object);
88101
String description = historyPage.getDescription();
89102
if (description == null)

0 commit comments

Comments
 (0)