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 committed Nov 27, 2024
1 parent 6dd6732 commit 245c371
Show file tree
Hide file tree
Showing 5 changed files with 100 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.10.600.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 @@ -13,19 +13,33 @@
*******************************************************************************/
package org.eclipse.team.internal.ui.history;

import java.lang.reflect.InvocationTargetException;

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.core.runtime.NullProgressMonitor;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.IToolBarManager;
import org.eclipse.jface.operation.IRunnableWithProgress;
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 All @@ -46,6 +60,14 @@ private void showCompareInDialog(Shell shell, Object object){
cc.setLeftEditable(false);
cc.setRightEditable(false);
HistoryPageCompareEditorInput input = new HistoryPageCompareEditorInput(cc, pageSource, object) {
@Override
public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable)
throws InvocationTargetException, InterruptedException {
// Avoid using super.run() on macOS as it causes layout issues.
// The compare viewer controls appear small and do not fill the entire dialog.
runnable.run(new NullProgressMonitor());
}

@Override
public boolean isEditionSelectionDialog() {
return true;
Expand All @@ -54,6 +76,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, false);
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
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.10
*/
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 245c371

Please sign in to comment.