blob: 229900bbfb6e901b102911cf8dd4d34e6d441185 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
/*******************************************************************************
* Copyright (c) 2006, 2017 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.team.internal.ui.history;
import org.eclipse.compare.CompareConfiguration;
import org.eclipse.compare.CompareUI;
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.swt.widgets.Shell;
import org.eclipse.team.internal.ui.*;
import org.eclipse.team.ui.history.HistoryPageCompareEditorInput;
import org.eclipse.team.ui.history.IHistoryPageSource;
public class ReplaceLocalHistory extends ShowLocalHistory {
@Override
public void run(IAction action) {
final IFile file = (IFile) getSelection().getFirstElement();
IFileState states[]= getLocalHistory();
if (states == null || states.length == 0)
return;
Runnable r = () -> showCompareInDialog(getShell(), file);
TeamUIPlugin.getStandardDisplay().asyncExec(r);
}
private void showCompareInDialog(Shell shell, Object object){
IHistoryPageSource pageSource = LocalHistoryPageSource.getInstance();
if (pageSource != null && pageSource.canShowHistoryFor(object)) {
CompareConfiguration cc = new CompareConfiguration();
cc.setLeftEditable(false);
cc.setRightEditable(false);
HistoryPageCompareEditorInput input = new HistoryPageCompareEditorInput(cc, pageSource, object) {
@Override
public boolean isEditionSelectionDialog() {
return true;
}
@Override
public String getOKButtonLabel() {
return TeamUIMessages.ReplaceLocalHistory_0;
}
@Override
public boolean okPressed() {
try {
Object o = getSelectedEdition();
FileRevisionTypedElement right = (FileRevisionTypedElement) ((ICompareInput)o).getRight();
IFile file = (IFile)getCompareResult();
file.setContents(right.getContents(), false, true, null);
} catch (CoreException e) {
Utils.handle(e);
return false;
}
return true;
}
};
CompareUI.openCompareDialog(input);
}
}
@Override
protected String getPromptTitle() {
return TeamUIMessages.ReplaceLocalHistory_1;
}
}
|