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
  • Loading branch information
tobias-melcher committed Nov 20, 2024
1 parent 6dd6732 commit 874a1d2
Showing 1 changed file with 52 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 874a1d2

Please sign in to comment.