|
20 | 20 | import org.eclipse.compare.CompareUI; |
21 | 21 | import org.eclipse.compare.CompareViewerPane; |
22 | 22 | import org.eclipse.compare.INavigatable; |
| 23 | +import org.eclipse.compare.ITypedElement; |
23 | 24 | import org.eclipse.compare.internal.Utilities; |
24 | 25 | import org.eclipse.compare.internal.patch.DiffViewerComparator; |
25 | 26 | import org.eclipse.jface.action.Action; |
|
29 | 30 | import org.eclipse.jface.action.ToolBarManager; |
30 | 31 | import org.eclipse.jface.util.IPropertyChangeListener; |
31 | 32 | import org.eclipse.jface.util.PropertyChangeEvent; |
| 33 | +import org.eclipse.jface.viewers.DoubleClickEvent; |
32 | 34 | import org.eclipse.jface.viewers.ISelection; |
33 | 35 | import org.eclipse.jface.viewers.IStructuredSelection; |
34 | 36 | import org.eclipse.jface.viewers.ITreeContentProvider; |
@@ -245,6 +247,7 @@ public boolean hasChange(int changeFlag) { |
245 | 247 | setLabelProvider(diffViewerLabelProvider); |
246 | 248 |
|
247 | 249 | addSelectionChangedListener(event -> updateActions()); |
| 250 | + addDoubleClickListener(this::expandCollapseAction); |
248 | 251 |
|
249 | 252 | setComparator(new DiffViewerComparator()); |
250 | 253 |
|
@@ -670,6 +673,30 @@ private void internalSetSelection(TreeItem ti, boolean fireOpen) { |
670 | 673 | } |
671 | 674 | } |
672 | 675 |
|
| 676 | + private void expandCollapseAction(DoubleClickEvent event) { |
| 677 | + ISelection s = event.getSelection(); |
| 678 | + |
| 679 | + if (s.isEmpty()) |
| 680 | + return; |
| 681 | + |
| 682 | + if (getElement(s) instanceof DiffNode d) { |
| 683 | + if (d.getType() == ITypedElement.FOLDER_TYPE) { |
| 684 | + if (getExpandedState(d)) |
| 685 | + collapseToLevel(d, 1); |
| 686 | + else |
| 687 | + expandToLevel(d, 1); |
| 688 | + } |
| 689 | + } |
| 690 | + } |
| 691 | + |
| 692 | + private static Object getElement(ISelection selection) { |
| 693 | + if (selection instanceof IStructuredSelection ss) { |
| 694 | + if (ss.size() == 1) |
| 695 | + return ss.getFirstElement(); |
| 696 | + } |
| 697 | + return null; |
| 698 | + } |
| 699 | + |
673 | 700 | private void updateActions() { |
674 | 701 | if (fExpandAllAction != null) { |
675 | 702 | fExpandAllAction.setEnabled(getSelection().isEmpty()); |
|
0 commit comments