From 874a1d2cabc434e3dc7d646d6648c3a040a9c4b5 Mon Sep 17 00:00:00 2001 From: Tobias Melcher Date: Wed, 20 Nov 2024 12:57:25 +0100 Subject: [PATCH] show diff in "replace with local history" dialog on selection change --- .../ui/history/ReplaceLocalHistory.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/ReplaceLocalHistory.java b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/ReplaceLocalHistory.java index 9aa593b859e..a584951ee34 100644 --- a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/ReplaceLocalHistory.java +++ b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/ReplaceLocalHistory.java @@ -15,17 +15,27 @@ import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareUI; +import org.eclipse.compare.CompareViewerPane; import org.eclipse.compare.structuremergeviewer.ICompareInput; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IFileState; import org.eclipse.core.runtime.CoreException; import org.eclipse.jface.action.IAction; +import org.eclipse.jface.action.IToolBarManager; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +import org.eclipse.swt.widgets.Composite; +import org.eclipse.swt.widgets.Control; +import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; +import org.eclipse.swt.widgets.Tree; import org.eclipse.team.internal.ui.TeamUIMessages; import org.eclipse.team.internal.ui.TeamUIPlugin; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.ui.history.HistoryPageCompareEditorInput; import org.eclipse.team.ui.history.IHistoryPageSource; +import org.eclipse.ui.part.IPage; public class ReplaceLocalHistory extends ShowLocalHistory { @@ -54,6 +64,48 @@ public boolean isEditionSelectionDialog() { public String getOKButtonLabel() { return TeamUIMessages.ReplaceLocalHistory_0; } + + @Override + protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) { + var page = super.createPage(parent, toolBarManager); + Tree tree = getTree(page); + runDefaultSelectionEventOnSelectionChange(tree); + return page; + } + + private void runDefaultSelectionEventOnSelectionChange(Tree tree) { + if (tree == null) { + return; + } + tree.addSelectionListener(new SelectionAdapter() { + + @Override + public void widgetSelected(SelectionEvent e) { + if (tree.getSelectionCount() != 1) { + return; + } + Event event = new Event(); + event.item = e.item; + tree.notifyListeners(SWT.DefaultSelection, event); + } + }); + } + private Tree getTree(IPage page) { + Control control = page.getControl(); + if (!(control instanceof Composite composite)) { + return null; + } + Control[] children = composite.getChildren(); + if (children == null) { + return null; + } + for (Control child : children) { + if (child instanceof Tree t) { + return t; + } + } + return null; + } @Override public boolean okPressed() { try {