From f093e2adadb3b362dd6ca55780de3ae51602572f 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 - disallow multi selection in "replace with local history" dialog - fix layouting issue on MacOS when loading the compare viewers on selection change --- .../org.eclipse.team.ui/META-INF/MANIFEST.MF | 2 +- .../internal/ui/history/LocalHistoryPage.java | 17 +++- .../ui/history/LocalHistoryTableProvider.java | 10 +- .../ui/history/ReplaceLocalHistory.java | 92 +++++++++++++++++++ .../HistoryPageCompareEditorInput.java | 15 ++- 5 files changed, 128 insertions(+), 8 deletions(-) diff --git a/team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF b/team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF index 62161645980..351a59e5d81 100644 --- a/team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF +++ b/team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Bundle-ManifestVersion: 2 Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.team.ui; singleton:=true -Bundle-Version: 3.10.500.qualifier +Bundle-Version: 3.11.0.qualifier Bundle-Activator: org.eclipse.team.internal.ui.TeamUIPlugin Bundle-Vendor: %providerName Bundle-Localization: plugin diff --git a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java index e67388075a7..6e6e3e617db 100644 --- a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java +++ b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryPage.java @@ -336,9 +336,7 @@ private IWorkbenchPartSite getWorkbenchSite(IHistoryPageSite parentSite) { return null; } - @Override - public void createControl(Composite parent) { - + public final void createControl(Composite parent, boolean allowMultiSelection) { localComposite = new Composite(parent, SWT.NONE); GridLayout layout = new GridLayout(); layout.marginHeight = 0; @@ -348,7 +346,7 @@ public void createControl(Composite parent) { data.grabExcessVerticalSpace = true; localComposite.setLayoutData(data); - treeViewer = createTree(localComposite); + treeViewer = createTree(localComposite, allowMultiSelection); contributeActions(); @@ -362,6 +360,11 @@ public void createControl(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(localComposite, IHelpContextIds.LOCAL_HISTORY_PAGE); } + @Override + public void createControl(Composite parent) { + createControl(parent, true); + } + private void contributeActions() { final IPreferenceStore store = TeamUIPlugin.getPlugin().getPreferenceStore(); //Group by Date @@ -599,8 +602,12 @@ private boolean showGetContentsAction(ITreeSelection sel) { * @return the group control */ protected TreeViewer createTree(Composite parent) { + return createTree(parent, true); + } + + protected final TreeViewer createTree(Composite parent, boolean allowMultiSelection) { historyTableProvider = new LocalFileHistoryTableProvider(); - TreeViewer viewer = historyTableProvider.createTree(parent); + TreeViewer viewer = historyTableProvider.createTree(parent, allowMultiSelection); viewer.setContentProvider(new LocalHistoryContentProvider()); return viewer; } diff --git a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryTableProvider.java b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryTableProvider.java index f685895eaae..72c1c634bfe 100644 --- a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryTableProvider.java +++ b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/history/LocalHistoryTableProvider.java @@ -291,7 +291,15 @@ public void widgetSelected(SelectionEvent e) { * @return TableViewer */ public TreeViewer createTree(Composite parent) { - Tree tree = new Tree(parent, SWT.H_SCROLL | SWT.V_SCROLL | SWT.MULTI | SWT.FULL_SELECTION); + return createTree(parent, true); + } + + public TreeViewer createTree(Composite parent, boolean allowMultiSelection) { + int style = SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION; + if (allowMultiSelection) { + style = style | SWT.MULTI; + } + Tree tree = new Tree(parent, style); tree.setHeaderVisible(true); tree.setLinesVisible(false); 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..3f7dc45f815 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,29 @@ 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.MouseEvent; +import org.eclipse.swt.events.MouseListener; +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 +66,40 @@ public boolean isEditionSelectionDialog() { public String getOKButtonLabel() { return TeamUIMessages.ReplaceLocalHistory_0; } + + @Override + protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) { + var page = super.createPage(parent, toolBarManager, false); + Tree tree = getTree(page); + runDefaultSelectionEventOnSelectionChange(tree); + return page; + } + + private void runDefaultSelectionEventOnSelectionChange(Tree tree) { + if (tree == null) { + return; + } + var handler = new NotifyDefaultSelectionOnWidgetSelectedHandler(tree); + tree.addSelectionListener(handler); + tree.addMouseListener(handler); + } + + 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 { @@ -76,4 +122,50 @@ public boolean okPressed() { protected String getPromptTitle() { return TeamUIMessages.ReplaceLocalHistory_1; } + + private static final class NotifyDefaultSelectionOnWidgetSelectedHandler extends SelectionAdapter + implements MouseListener { + private boolean mouseDownPressed = false; + private Runnable runOnMouseUp; + private final Tree tree; + + public NotifyDefaultSelectionOnWidgetSelectedHandler(Tree tree) { + this.tree = tree; + } + @Override + public void widgetSelected(SelectionEvent e) { + if (tree.getSelectionCount() != 1) { + return; + } + Runnable r = () -> { + Event event = new Event(); + event.item = e.item; + tree.notifyListeners(SWT.DefaultSelection, event); + }; + if (mouseDownPressed) { + // run DefaultSelection event after mouseUp + runOnMouseUp = r; + return; + } + r.run(); + } + + @Override + public void mouseDoubleClick(MouseEvent e) { + } + + @Override + public void mouseDown(MouseEvent e) { + mouseDownPressed = true; + } + + @Override + public void mouseUp(MouseEvent e) { + mouseDownPressed = false; + if (runOnMouseUp != null) { + runOnMouseUp.run(); + runOnMouseUp = null; + } + } + } } diff --git a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/HistoryPageCompareEditorInput.java b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/HistoryPageCompareEditorInput.java index 79b87f5e714..3162df544cc 100644 --- a/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/HistoryPageCompareEditorInput.java +++ b/team/bundles/org.eclipse.team.ui/src/org/eclipse/team/ui/history/HistoryPageCompareEditorInput.java @@ -31,6 +31,7 @@ import org.eclipse.team.internal.ui.TeamUIMessages; import org.eclipse.team.internal.ui.Utils; import org.eclipse.team.internal.ui.history.DialogHistoryPageSite; +import org.eclipse.team.internal.ui.history.LocalHistoryPage; import org.eclipse.team.ui.PageCompareEditorInput; import org.eclipse.ui.part.IPage; import org.eclipse.ui.part.Page; @@ -79,11 +80,23 @@ protected void handleDispose() { @Override protected IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager) { + return createPage(parent, toolBarManager, true); + } + + /** + * @since 3.11 + */ + protected final IPage createPage(CompareViewerPane parent, IToolBarManager toolBarManager, + boolean allowMultiSelection) { site = new DialogHistoryPageSite(parent.getShell()); historyPage = (IHistoryPage)pageSource.createPage(object); historyPage.setSite(site); site.setToolBarManager(toolBarManager); - ((Page) historyPage).createControl(parent); + if (historyPage instanceof LocalHistoryPage localHistoryPage) { + localHistoryPage.createControl(parent, allowMultiSelection); + } else { + ((Page) historyPage).createControl(parent); + } historyPage.setInput(object); String description = historyPage.getDescription(); if (description == null)