Skip to content

Commit

Permalink
Show Diff in "replace with local history" Dialog On Selection Change
Browse files Browse the repository at this point in the history
- disallow multi selection in "replace with local history" dialog
- fix layouting issue on MacOS when loading the compare viewers on
selection change
  • Loading branch information
tobias-melcher authored and BeckerWdf committed Dec 3, 2024
1 parent 3776c2f commit e987000
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 8 deletions.
2 changes: 1 addition & 1 deletion team/bundles/org.eclipse.team.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -348,7 +346,7 @@ public void createControl(Composite parent) {
data.grabExcessVerticalSpace = true;
localComposite.setLayoutData(data);

treeViewer = createTree(localComposite);
treeViewer = createTree(localComposite, allowMultiSelection);

contributeActions();

Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {
Expand All @@ -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;
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit e987000

Please sign in to comment.