From 607ae35c13eb6b6d5024107e4fcfe81daf0e77b3 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 | 51 +++++++++++++++++++ 1 file changed, 51 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..b32b8337b52 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,47 @@ 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 c) { + Control[] children = c.getChildren(); + if (children == null) { + return null; + } + for (Control child : children) { + if (child instanceof Tree t) { + return t; + } + } + } + return null; + } @Override public boolean okPressed() { try {