mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
diff: remove unused code
This commit is contained in:
@@ -226,12 +226,12 @@
|
||||
|
||||
<action id="ChangesView.Browse" class="com.intellij.openapi.vcs.changes.actions.BrowseChangesAction"/>
|
||||
|
||||
<action id="Diff.PrevChange" class="com.intellij.openapi.vcs.changes.actions.ShowPrevChangeAction"
|
||||
icon="AllIcons.Actions.Prevfile" use-shortcut-of="PreviousTab"/>
|
||||
<action id="Diff.NextChange" class="com.intellij.openapi.vcs.changes.actions.ShowNextChangeAction"
|
||||
icon="AllIcons.Actions.Nextfile" use-shortcut-of="NextTab"/>
|
||||
<action id="Diff.SelectedChange" class="com.intellij.openapi.vcs.changes.actions.ShowSelectedChangeAction"
|
||||
icon="AllIcons.Actions.ShowAsTree" use-shortcut-of="GotoChangedFile"/>
|
||||
<action id="Diff.PrevChange" class="com.intellij.openapi.actionSystem.EmptyAction"
|
||||
icon="AllIcons.Actions.Prevfile" use-shortcut-of="PreviousTab"/>
|
||||
<action id="Diff.NextChange" class="com.intellij.openapi.actionSystem.EmptyAction"
|
||||
icon="AllIcons.Actions.Nextfile" use-shortcut-of="NextTab"/>
|
||||
<action id="Diff.SelectedChange" class="com.intellij.openapi.actionSystem.EmptyAction"
|
||||
icon="AllIcons.Actions.ShowAsTree" use-shortcut-of="GotoChangedFile"/>
|
||||
|
||||
<group id="EditorGutterVcsPopupMenu">
|
||||
<separator/>
|
||||
|
||||
@@ -20,7 +20,6 @@ import com.intellij.openapi.actionSystem.DataKey;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeList;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import com.intellij.openapi.vcs.changes.ChangesSelection;
|
||||
import com.intellij.openapi.vcs.history.VcsFileRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsHistoryProvider;
|
||||
@@ -63,7 +62,6 @@ public interface VcsDataKeys {
|
||||
DataKey<Change[]> SELECTED_CHANGES = DataKey.create("ChangeListView.SelectedChange");
|
||||
DataKey<Boolean> HAVE_SELECTED_CHANGES = DataKey.create("ChangeListView.HaveSelectedChanges");
|
||||
DataKey<Change[]> CHANGE_LEAD_SELECTION = DataKey.create("ChangeListView.ChangeLeadSelection");
|
||||
DataKey<ChangeRequestChain> DIFF_REQUEST_CHAIN = DataKey.create("diffRequestChain");
|
||||
DataKey<String> UPDATE_VIEW_SELECTED_PATH = DataKey.create("AbstractCommonUpdateAction.UpdateViewSelectedPath");
|
||||
DataKey<Iterable<Pair<VirtualFilePointer, FileStatus>>> UPDATE_VIEW_FILES_ITERABLE = DataKey.create("AbstractCommonUpdateAction.UpdatedFilesIterable");
|
||||
DataKey<Object> LABEL_BEFORE = DataKey.create("LABEL_BEFORE");
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes;
|
||||
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ChangeRequestChain {
|
||||
boolean canMoveForward();
|
||||
|
||||
boolean canMoveBack();
|
||||
|
||||
@Nullable
|
||||
DiffRequest moveForward();
|
||||
|
||||
@Nullable
|
||||
DiffRequest moveBack();
|
||||
|
||||
@NotNull
|
||||
List<DiffRequestPresentable> getAllRequests();
|
||||
|
||||
@Nullable
|
||||
DiffRequest moveTo(DiffRequestPresentable request);
|
||||
|
||||
/**
|
||||
* Returns the diff request which is currently shown in the diff dialog.
|
||||
*/
|
||||
@Nullable
|
||||
DiffRequestPresentable getCurrentRequest();
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class DiffChainContext {
|
||||
private final List<String> mySkippedBinaryExtentions;
|
||||
|
||||
public DiffChainContext() {
|
||||
mySkippedBinaryExtentions = new LinkedList<>();
|
||||
}
|
||||
|
||||
public void add(final String extention) {
|
||||
mySkippedBinaryExtentions.add(extention);
|
||||
}
|
||||
|
||||
public boolean contains(final String extention) {
|
||||
return mySkippedBinaryExtentions.contains(extention);
|
||||
}
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@Deprecated
|
||||
public interface DiffExtendUIFactory {
|
||||
DiffExtendUIFactory NONE = new DiffExtendUIFactory() {
|
||||
public List<? extends AnAction> createActions(Change change) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public JComponent createBottomComponent() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
List<? extends AnAction> createActions(Change change);
|
||||
|
||||
@Nullable
|
||||
JComponent createBottomComponent();
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
public enum DiffPresentationReturnValue {
|
||||
removeFromList,
|
||||
useRequest,
|
||||
quit
|
||||
}
|
||||
-78
@@ -1,78 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public interface DiffRequestPresentable {
|
||||
MyResult step(DiffChainContext context);
|
||||
|
||||
void haveStuff() throws VcsException;
|
||||
List<? extends AnAction> createActions(final DiffExtendUIFactory uiFactory);
|
||||
String getPathPresentation();
|
||||
|
||||
class MyResult {
|
||||
private final List<String> myErrors;
|
||||
private final DiffRequest myRequest;
|
||||
private final DiffPresentationReturnValue myReturnValue;
|
||||
|
||||
public MyResult(DiffRequest request, DiffPresentationReturnValue returnValue) {
|
||||
myRequest = request;
|
||||
myReturnValue = returnValue;
|
||||
myErrors = new ArrayList<>();
|
||||
}
|
||||
|
||||
public MyResult(DiffRequest request, DiffPresentationReturnValue returnValue, final String error) {
|
||||
myRequest = request;
|
||||
myReturnValue = returnValue;
|
||||
myErrors = new ArrayList<>();
|
||||
if (! StringUtil.isEmptyOrSpaces(error)) {
|
||||
myErrors.add(error);
|
||||
}
|
||||
}
|
||||
|
||||
public void addError(final String e) {
|
||||
myErrors.add(e);
|
||||
}
|
||||
|
||||
public List<String> getErrors() {
|
||||
return myErrors;
|
||||
}
|
||||
|
||||
public DiffRequest getRequest() {
|
||||
return myRequest;
|
||||
}
|
||||
|
||||
public DiffPresentationReturnValue getReturnValue() {
|
||||
return myReturnValue;
|
||||
}
|
||||
|
||||
public boolean hasErrors() {
|
||||
return ! myErrors.isEmpty();
|
||||
}
|
||||
|
||||
public String getAsOneError() {
|
||||
if (myErrors.isEmpty()) return null;
|
||||
return StringUtil.join(myErrors, "\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
-277
@@ -1,277 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.ActionManager;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.DiffTool;
|
||||
import com.intellij.openapi.diff.DiffToolbar;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.NullableFactory;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ChangeDiffRequest implements ChangeRequestChain {
|
||||
@NotNull private final List<DiffRequestPresentable> mySteps;
|
||||
private final boolean myShowFrame;
|
||||
private int myIndex;
|
||||
|
||||
private final DiffExtendUIFactory myActionsFactory;
|
||||
|
||||
private final AnAction myPrevChangeAction;
|
||||
private final AnAction myNextChangeAction;
|
||||
private final Project myProject;
|
||||
private final DiffChainContext myContext;
|
||||
private final AnAction mySelectChangeAction;
|
||||
|
||||
public ChangeDiffRequest(final Project project, @NotNull List<DiffRequestPresentable> steps, final DiffExtendUIFactory actionsFactory,
|
||||
final boolean showFrame) {
|
||||
myProject = project;
|
||||
mySteps = steps;
|
||||
myShowFrame = showFrame;
|
||||
myContext = new DiffChainContext();
|
||||
|
||||
myIndex = 0;
|
||||
myActionsFactory = actionsFactory;
|
||||
|
||||
myPrevChangeAction = ActionManager.getInstance().getAction("Diff.PrevChange");
|
||||
myNextChangeAction = ActionManager.getInstance().getAction("Diff.NextChange");
|
||||
mySelectChangeAction = ActionManager.getInstance().getAction("Diff.SelectedChange");
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<DiffRequestPresentable> getAllRequests() {
|
||||
return mySteps;
|
||||
}
|
||||
|
||||
private void onEveryMove(final DiffRequest simpleRequest, final boolean showFrame) {
|
||||
simpleRequest.passForDataContext(VcsDataKeys.DIFF_REQUEST_CHAIN, this);
|
||||
if (showFrame) {
|
||||
simpleRequest.addHint(DiffTool.HINT_SHOW_FRAME);
|
||||
}
|
||||
else {
|
||||
simpleRequest.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG);
|
||||
}
|
||||
if (mySteps.size() > 1) {
|
||||
simpleRequest.addHint(DiffTool.HINT_ALLOW_NO_DIFFERENCES);
|
||||
}
|
||||
}
|
||||
|
||||
public void quickCheckHaveStuff() throws VcsException {
|
||||
if (mySteps.isEmpty()) {
|
||||
throw new VcsException("Nothing selected to show diff");
|
||||
}
|
||||
if (mySteps.size() == 1) {
|
||||
mySteps.get(0).haveStuff();
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DiffRequest init(final int idx) {
|
||||
if (idx < 0 || idx > (mySteps.size() - 1)) return null;
|
||||
myIndex = idx - 1;
|
||||
final DiffRequest result = moveForward();
|
||||
if (result == null && idx > 0) {
|
||||
myIndex = -1;
|
||||
return moveForward();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean canMoveForward() {
|
||||
return myIndex < (mySteps.size() - 1);
|
||||
}
|
||||
|
||||
public boolean canMoveBack() {
|
||||
return myIndex > 0;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DiffRequest moveForward() {
|
||||
return moveWithErrorReport(new MoveDirection() {
|
||||
public boolean canMove() {
|
||||
return canMoveForward();
|
||||
}
|
||||
|
||||
public int direction() {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DiffRequest moveTo(DiffRequestPresentable presentable) {
|
||||
int index = findRequest(presentable);
|
||||
if (index == -1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final List<String> errors = new ArrayList<>();
|
||||
DiffRequestPresentable.MyResult result = moveImpl(presentable, errors);
|
||||
showErrors(errors);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
if (DiffPresentationReturnValue.removeFromList.equals(result.getReturnValue())) {
|
||||
return null;
|
||||
}
|
||||
myIndex = index;
|
||||
return result.getRequest();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public DiffRequestPresentable getCurrentRequest() {
|
||||
if (myIndex < 0 || myIndex >= mySteps.size()) {
|
||||
return null;
|
||||
}
|
||||
return mySteps.get(myIndex);
|
||||
}
|
||||
|
||||
private int findRequest(DiffRequestPresentable presentable) {
|
||||
for (int i = 0; i < mySteps.size(); i++) {
|
||||
DiffRequestPresentable step = mySteps.get(i);
|
||||
if (step.equals(presentable)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DiffRequest moveWithErrorReport(final MoveDirection moveDirection) {
|
||||
final List<String> errors = new ArrayList<>();
|
||||
final DiffRequest diffRequest = moveInc(moveDirection, errors);
|
||||
showErrors(errors);
|
||||
return diffRequest;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DiffRequestPresentable.MyResult moveImpl(DiffRequestPresentable requestPresentable, final List<String> errors) {
|
||||
final DiffRequestPresentable.MyResult result = requestPresentable.step(myContext);
|
||||
final DiffPresentationReturnValue returnValue = result.getReturnValue();
|
||||
if (DiffPresentationReturnValue.quit.equals(returnValue)) {
|
||||
errors.addAll(result.getErrors());
|
||||
return null;
|
||||
}
|
||||
|
||||
if (DiffPresentationReturnValue.removeFromList.equals(returnValue)) {
|
||||
mySteps.remove(requestPresentable);
|
||||
errors.addAll(result.getErrors());
|
||||
return result;
|
||||
}
|
||||
|
||||
final DiffRequest request = result.getRequest();
|
||||
takeStuffFromFactory(request, requestPresentable.createActions(myActionsFactory));
|
||||
onEveryMove(request, myShowFrame);
|
||||
return result;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DiffRequest moveInc(final MoveDirection moveDirection, final List<String> errors) {
|
||||
while (moveDirection.canMove()) {
|
||||
final int nextIdx = myIndex + moveDirection.direction();
|
||||
final DiffRequestPresentable diffRequestPresentable = mySteps.get(nextIdx);
|
||||
|
||||
DiffRequestPresentable.MyResult result = moveImpl(diffRequestPresentable, errors);
|
||||
if (result == null) {
|
||||
return null;
|
||||
}
|
||||
if (DiffPresentationReturnValue.removeFromList.equals(result.getReturnValue())) {
|
||||
if (moveDirection.direction() < 0) {
|
||||
// our position moves to head
|
||||
myIndex += moveDirection.direction();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
myIndex = nextIdx;
|
||||
return result.getRequest();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void showErrors(final List<String> errors) {
|
||||
if (errors.isEmpty()) return;
|
||||
final StringBuilder sb = new StringBuilder("Following problems have occurred:\n\n");
|
||||
for (String error : errors) {
|
||||
sb.append(error).append('\n');
|
||||
}
|
||||
Messages.showErrorDialog(myProject, sb.toString(), "Show Diff");
|
||||
}
|
||||
|
||||
private interface MoveDirection {
|
||||
boolean canMove();
|
||||
int direction();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public DiffRequest moveBack() {
|
||||
return moveWithErrorReport(new MoveDirection() {
|
||||
public boolean canMove() {
|
||||
return canMoveBack();
|
||||
}
|
||||
|
||||
public int direction() {
|
||||
return -1;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void takeStuffFromFactory(final DiffRequest request, final List<? extends AnAction> actions) {
|
||||
if (mySteps.size() > 1 || (myActionsFactory != null)) {
|
||||
request.setToolbarAddons(new DiffRequest.ToolbarAddons() {
|
||||
public void customize(final DiffToolbar toolbar) {
|
||||
if (mySteps.size() > 1) {
|
||||
toolbar.addSeparator();
|
||||
}
|
||||
toolbar.addAction(myPrevChangeAction);
|
||||
toolbar.addAction(myNextChangeAction);
|
||||
toolbar.addAction(mySelectChangeAction);
|
||||
|
||||
if (myActionsFactory != null) {
|
||||
toolbar.addSeparator();
|
||||
for (AnAction action : actions) {
|
||||
toolbar.addAction(action);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (myActionsFactory != null) {
|
||||
request.setBottomComponentFactory(new NullableFactory<JComponent>() {
|
||||
public JComponent create() {
|
||||
return myActionsFactory.createBottomComponent();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
-292
@@ -1,292 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2013 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.CommonBundle;
|
||||
import com.intellij.diff.FileAwareSimpleContent;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.diff.DiffContent;
|
||||
import com.intellij.openapi.diff.FileContent;
|
||||
import com.intellij.openapi.diff.SimpleContent;
|
||||
import com.intellij.openapi.diff.SimpleDiffRequest;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.fileTypes.ex.FileTypeChooser;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.io.FileUtilRt;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class ChangeDiffRequestPresentable implements DiffRequestPresentable {
|
||||
private final Project myProject;
|
||||
private final Change myChange;
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable");
|
||||
// I don't like that much
|
||||
private boolean myIgnoreDirectoryFlag;
|
||||
|
||||
public ChangeDiffRequestPresentable(final Project project, final Change change) {
|
||||
myChange = change;
|
||||
myProject = project;
|
||||
}
|
||||
|
||||
public Change getChange() {
|
||||
return myChange;
|
||||
}
|
||||
|
||||
public void setIgnoreDirectoryFlag(boolean ignoreDirectoryFlag) {
|
||||
myIgnoreDirectoryFlag = ignoreDirectoryFlag;
|
||||
}
|
||||
|
||||
public MyResult step(DiffChainContext context) {
|
||||
final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null);
|
||||
final List<String> errSb = new ArrayList<>();
|
||||
if (! canShowChange(context, errSb)) {
|
||||
return new MyResult(request, DiffPresentationReturnValue.removeFromList, StringUtil.join(errSb, "\n"));
|
||||
}
|
||||
if (! loadCurrentContents(request, myChange)) return new MyResult(request, DiffPresentationReturnValue.quit);
|
||||
return new MyResult(request, DiffPresentationReturnValue.useRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathPresentation() {
|
||||
return ChangesUtil.getFilePath(myChange).getPath();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void haveStuff() throws VcsException {
|
||||
final List<String> errSb = new ArrayList<>();
|
||||
final boolean canShow = checkContentsAvailable(myChange.getBeforeRevision(), myChange.getAfterRevision(), errSb);
|
||||
if (! canShow) {
|
||||
throw new VcsException(StringUtil.join(errSb, "\n"));
|
||||
}
|
||||
}
|
||||
|
||||
public List<? extends AnAction> createActions(DiffExtendUIFactory uiFactory) {
|
||||
return uiFactory.createActions(myChange);
|
||||
}
|
||||
|
||||
private boolean loadCurrentContents(final SimpleDiffRequest request, final Change change) {
|
||||
final ContentRevision bRev = change.getBeforeRevision();
|
||||
final ContentRevision aRev = change.getAfterRevision();
|
||||
|
||||
String beforePath = bRev != null ? bRev.getFile().getPath() : null;
|
||||
String afterPath = aRev != null ? aRev.getFile().getPath() : null;
|
||||
String title;
|
||||
if (beforePath != null && afterPath != null && !beforePath.equals(afterPath)) {
|
||||
beforePath = FileUtil.toSystemDependentName(beforePath);
|
||||
afterPath = FileUtil.toSystemDependentName(afterPath);
|
||||
title = beforePath + " -> " + afterPath;
|
||||
}
|
||||
else if (beforePath != null) {
|
||||
beforePath = FileUtil.toSystemDependentName(beforePath);
|
||||
title = beforePath;
|
||||
}
|
||||
else if (afterPath != null) {
|
||||
afterPath = FileUtil.toSystemDependentName(afterPath);
|
||||
title = afterPath;
|
||||
}
|
||||
else {
|
||||
title = VcsBundle.message("diff.unknown.path.title");
|
||||
}
|
||||
request.setWindowTitle(title);
|
||||
|
||||
boolean result = ProgressManager.getInstance().runProcessWithProgressSynchronously(new Runnable() {
|
||||
public void run() {
|
||||
final ProgressIndicator pi = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (pi != null) {
|
||||
pi.setIndeterminate(true);
|
||||
}
|
||||
request.setContents(createContent(bRev), createContent(aRev));
|
||||
}
|
||||
}, VcsBundle.message("progress.loading.diff.revisions"), true, myProject);
|
||||
if (! result) return false;
|
||||
|
||||
String beforeRevisionTitle = (bRev != null) ? bRev.getRevisionNumber().asString() : "";
|
||||
String afterRevisionTitle = (aRev != null) ? aRev.getRevisionNumber().asString() : "";
|
||||
if ((beforeRevisionTitle == null) || (beforeRevisionTitle.length() == 0)) {
|
||||
beforeRevisionTitle = "Base version";
|
||||
}
|
||||
if ((afterRevisionTitle == null) || (afterRevisionTitle.length() == 0)) {
|
||||
afterRevisionTitle = "Your version";
|
||||
}
|
||||
request.setContentTitles(beforeRevisionTitle, afterRevisionTitle);
|
||||
return true;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private DiffContent createContent(final ContentRevision revision) {
|
||||
ProgressManager.checkCanceled();
|
||||
if (revision == null) return SimpleContent.createEmpty();
|
||||
if (revision instanceof CurrentContentRevision) {
|
||||
final CurrentContentRevision current = (CurrentContentRevision)revision;
|
||||
final VirtualFile vFile = current.getVirtualFile();
|
||||
return vFile != null ? new FileContent(myProject, vFile) : new SimpleContent("");
|
||||
}
|
||||
FilePath filePath = revision.getFile();
|
||||
if (revision instanceof BinaryContentRevision) {
|
||||
final String name = filePath.getName();
|
||||
try {
|
||||
return FileContent.createFromTempFile(myProject, name, name, ((BinaryContentRevision)revision).getBinaryContent());
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.info(e);
|
||||
try {
|
||||
return FileContent.createFromTempFile(myProject, name, name, ArrayUtil.EMPTY_BYTE_ARRAY);
|
||||
}
|
||||
catch (IOException e1) {
|
||||
LOG.info(e1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
try {
|
||||
return FileContent.createFromTempFile(myProject, name, name, ArrayUtil.EMPTY_BYTE_ARRAY);
|
||||
}
|
||||
catch (IOException e1) {
|
||||
LOG.info(e1);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String revisionContent;
|
||||
try {
|
||||
revisionContent = revision.getContent();
|
||||
}
|
||||
catch(VcsException ex) {
|
||||
LOG.info(ex);
|
||||
// TODO: correct exception handling
|
||||
revisionContent = null;
|
||||
}
|
||||
SimpleContent content = revisionContent == null
|
||||
? new SimpleContent("")
|
||||
: new FileAwareSimpleContent(myProject, filePath, revisionContent, filePath.getFileType());
|
||||
VirtualFile vFile = filePath.getVirtualFile();
|
||||
if (vFile != null) {
|
||||
content.setCharset(vFile.getCharset());
|
||||
content.setBOM(vFile.getBOM());
|
||||
}
|
||||
content.setReadOnly(true);
|
||||
return content;
|
||||
}
|
||||
|
||||
private boolean canShowChange(DiffChainContext context, List<String> errSb) {
|
||||
final ContentRevision bRev = myChange.getBeforeRevision();
|
||||
final ContentRevision aRev = myChange.getAfterRevision();
|
||||
|
||||
if (myIgnoreDirectoryFlag) {
|
||||
if (! checkContentsAvailable(bRev, aRev, errSb)) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
boolean isOk = checkContentRevision(bRev, context, errSb);
|
||||
isOk &= checkContentRevision(aRev, context, errSb);
|
||||
|
||||
return isOk;
|
||||
}
|
||||
|
||||
private boolean checkContentRevision(ContentRevision rev, final DiffChainContext context, final List<String> errSb) {
|
||||
if (rev == null) return true;
|
||||
if (rev.getFile().isDirectory()) return false;
|
||||
if (! hasContents(rev, errSb)) {
|
||||
return false;
|
||||
}
|
||||
final FileType type = rev.getFile().getFileType();
|
||||
if (! type.isBinary()) return true;
|
||||
if (FileTypes.UNKNOWN.equals(type)) {
|
||||
final boolean associatedToText = checkAssociate(myProject, rev.getFile().getName(), context);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean hasContents(@Nullable final ContentRevision rev, final List<String> errSb) {
|
||||
if (rev == null) return false;
|
||||
try {
|
||||
if (rev instanceof BinaryContentRevision) {
|
||||
return ((BinaryContentRevision) rev).getBinaryContent() != null;
|
||||
} else {
|
||||
return rev.getContent() != null;
|
||||
}
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
errSb.add(e.getMessage());
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean checkContentsAvailable(@Nullable final ContentRevision bRev, @Nullable final ContentRevision aRev, final List<String> errSb) {
|
||||
if (hasContents(bRev, errSb)) return true;
|
||||
if (hasContents(aRev, errSb)) return true;
|
||||
errSb.add("Can't load revisions content:");
|
||||
if (bRev != null) errSb.add("Can't load content of " + bRev.getFile().getPresentableUrl() + " at " + bRev.getRevisionNumber().asString());
|
||||
if (aRev != null) errSb.add("Can't load content of " + aRev.getFile().getPresentableUrl() + " at " + aRev.getRevisionNumber().asString());
|
||||
if (aRev == null && bRev == null) errSb.add("Both revisions are empty");
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean checkAssociate(final Project project, String fileName, DiffChainContext context) {
|
||||
final String pattern = FileUtilRt.getExtension(fileName).toLowerCase();
|
||||
if (context.contains(pattern)) return false;
|
||||
int rc = Messages.showOkCancelDialog(project,
|
||||
VcsBundle.message("diff.unknown.file.type.prompt", fileName),
|
||||
VcsBundle.message("diff.unknown.file.type.title"),
|
||||
VcsBundle.message("diff.unknown.file.type.associate"),
|
||||
CommonBundle.getCancelButtonText(),
|
||||
Messages.getQuestionIcon());
|
||||
if (rc == Messages.OK) {
|
||||
FileType fileType = FileTypeChooser.associateFileType(fileName);
|
||||
return fileType != null && !fileType.isBinary();
|
||||
} else {
|
||||
context.add(pattern);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
ChangeDiffRequestPresentable that = (ChangeDiffRequestPresentable)o;
|
||||
|
||||
if (myChange != null ? !myChange.equals(that.myChange) : that.myChange != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myChange != null ? myChange.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
-88
@@ -1,88 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangesUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: Irina.Chernushina
|
||||
* Date: 2/14/12
|
||||
* Time: 3:07 PM
|
||||
*/
|
||||
public class ChangeForDiffConvertor implements Convertor<Change, DiffRequestPresentable> {
|
||||
private final Project myProject;
|
||||
private final boolean myRecursive;
|
||||
|
||||
public ChangeForDiffConvertor(Project project, final boolean recursive) {
|
||||
myProject = project;
|
||||
myRecursive = recursive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public DiffRequestPresentable convert(Change o) {
|
||||
return convert(o, false);
|
||||
}
|
||||
|
||||
public DiffRequestPresentable convert(final Change ch, final boolean forceText) {
|
||||
if (ch.hasOtherLayers() && myRecursive) {
|
||||
return new MultipleDiffRequestPresentable(myProject, ch);
|
||||
}
|
||||
if (ChangesUtil.isTextConflictingChange(ch)) {
|
||||
final AbstractVcs vcs = ChangesUtil.getVcsForChange(ch, myProject);
|
||||
if (vcs == null || vcs.getMergeProvider() == null) return null;
|
||||
final FilePath path = ChangesUtil.getFilePath(ch);
|
||||
VirtualFile vf = path.getVirtualFile();
|
||||
if (vf == null) {
|
||||
vf = LocalFileSystem.getInstance().refreshAndFindFileByPath(path.getPath());
|
||||
}
|
||||
if (vf == null) return null;
|
||||
|
||||
return new ConflictedDiffRequestPresentable(myProject, vf, ch);
|
||||
} else {
|
||||
if (forceText) {
|
||||
if (ch.getBeforeRevision() != null && ch.getAfterRevision() != null) {
|
||||
try {
|
||||
if (StringUtil.isEmptyOrSpaces(ch.getBeforeRevision().getContent()) &&
|
||||
StringUtil.isEmptyOrSpaces(ch.getAfterRevision().getContent())) {
|
||||
return null;
|
||||
}
|
||||
if (StringUtil.equals(ch.getBeforeRevision().getContent(), ch.getAfterRevision().getContent())) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
catch (VcsException e) {
|
||||
//
|
||||
}
|
||||
}
|
||||
}
|
||||
final ChangeDiffRequestPresentable presentable = new ChangeDiffRequestPresentable(myProject, ch);
|
||||
if (forceText) {
|
||||
presentable.setIgnoreDirectoryFlag(true);
|
||||
}
|
||||
return presentable;
|
||||
}
|
||||
}
|
||||
}
|
||||
-110
@@ -1,110 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.diff.DiffRequestFactory;
|
||||
import com.intellij.openapi.diff.MergeRequest;
|
||||
import com.intellij.openapi.diff.SimpleDiffRequest;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.AbstractVcs;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangesUtil;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.openapi.vcs.merge.MergeData;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: Irina.Chernushina
|
||||
* Date: 2/14/12
|
||||
* Time: 4:09 PM
|
||||
*/
|
||||
public class ConflictedDiffRequestPresentable implements DiffRequestPresentable {
|
||||
private final static Logger LOG = Logger.getInstance("#com.intellij.openapi.vcs.changes.actions.ConflictedDiffRequestPresentable");
|
||||
private final Project myProject;
|
||||
private final VirtualFile myFile;
|
||||
private final Change myChange;
|
||||
|
||||
public ConflictedDiffRequestPresentable(final Project project, VirtualFile file, final Change change) {
|
||||
myProject = project;
|
||||
myFile = file;
|
||||
myChange = change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyResult step(DiffChainContext context) {
|
||||
if (myChange.getAfterRevision() == null) return createErrorResult();
|
||||
FileType type = myChange.getVirtualFile() != null ? myChange.getVirtualFile().getFileType() : null;
|
||||
if (myFile.getFileType().isBinary()) {
|
||||
final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context);
|
||||
if (! nowItIsText) {
|
||||
return createErrorResult();
|
||||
}
|
||||
}
|
||||
final AbstractVcs vcs = ChangesUtil.getVcsForChange(myChange, myProject);
|
||||
if (vcs == null || vcs.getMergeProvider() == null) {
|
||||
return createErrorResult();
|
||||
}
|
||||
try {
|
||||
final MergeData mergeData = vcs.getMergeProvider().loadRevisions(myFile);
|
||||
final Charset charset = myFile.getCharset();
|
||||
final MergeRequest request = DiffRequestFactory.getInstance()
|
||||
.create3WayDiffRequest(CharsetToolkit.bytesToString(mergeData.CURRENT, charset),
|
||||
CharsetToolkit.bytesToString(mergeData.LAST, charset),
|
||||
CharsetToolkit.bytesToString(mergeData.ORIGINAL, charset),
|
||||
type, myProject, null, null);
|
||||
request.setWindowTitle(FileUtil.toSystemDependentName(myFile.getPresentableUrl()));
|
||||
// todo titles?
|
||||
VcsRevisionNumber lastRevisionNumber = mergeData.LAST_REVISION_NUMBER;
|
||||
request.setVersionTitles(new String[]{myChange.getAfterRevision().getRevisionNumber().asString(),
|
||||
"Base Version", lastRevisionNumber != null ? lastRevisionNumber.asString() : ""});
|
||||
return new MyResult(request, DiffPresentationReturnValue.useRequest);
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
return createErrorResult();
|
||||
}
|
||||
}
|
||||
|
||||
private MyResult createErrorResult() {
|
||||
final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null);
|
||||
return new MyResult(request, DiffPresentationReturnValue.removeFromList);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void haveStuff() throws VcsException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends AnAction> createActions(DiffExtendUIFactory uiFactory) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathPresentation() {
|
||||
return myFile.getPath();
|
||||
}
|
||||
}
|
||||
-70
@@ -1,70 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class DiffRequestPresentableProxy implements DiffRequestPresentable {
|
||||
private DiffRequestPresentable myDelegate;
|
||||
private List<? extends AnAction> myCachedActions;
|
||||
private MyResult myStepResult;
|
||||
|
||||
@NotNull
|
||||
public abstract DiffRequestPresentable init() throws VcsException;
|
||||
|
||||
@NotNull
|
||||
private DiffRequestPresentable initRequest() throws VcsException {
|
||||
if (myDelegate == null) {
|
||||
myDelegate = init();
|
||||
}
|
||||
return myDelegate;
|
||||
}
|
||||
|
||||
public List<? extends AnAction> createActions(DiffExtendUIFactory uiFactory) {
|
||||
if (myCachedActions == null) {
|
||||
try {
|
||||
myCachedActions = initRequest().createActions(uiFactory);
|
||||
}
|
||||
catch (VcsException e) {
|
||||
//should not occur
|
||||
return Collections.emptyList();
|
||||
}
|
||||
}
|
||||
return myCachedActions;
|
||||
}
|
||||
|
||||
public MyResult step(DiffChainContext context) {
|
||||
final DiffRequestPresentable request;
|
||||
try {
|
||||
request = initRequest();
|
||||
myStepResult = request.step(context);
|
||||
}
|
||||
catch (VcsException e) {
|
||||
myStepResult = new MyResult(null, DiffPresentationReturnValue.quit, e.getMessage());
|
||||
}
|
||||
return myStepResult;
|
||||
}
|
||||
|
||||
public void haveStuff() throws VcsException {
|
||||
final DiffRequestPresentable request = initRequest();
|
||||
request.haveStuff();
|
||||
}
|
||||
}
|
||||
-117
@@ -1,117 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2014 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.SimpleDiffRequest;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangesUtil;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created with IntelliJ IDEA.
|
||||
* User: Irina.Chernushina
|
||||
* Date: 2/14/12
|
||||
* Time: 3:48 PM
|
||||
*/
|
||||
public class MultipleDiffRequestPresentable implements DiffRequestPresentable {
|
||||
private final Project myProject;
|
||||
private final Change myChange;
|
||||
|
||||
public MultipleDiffRequestPresentable(Project project, Change change) {
|
||||
myProject = project;
|
||||
myChange = change;
|
||||
}
|
||||
|
||||
@Override
|
||||
public MyResult step(DiffChainContext context) {
|
||||
final ChangeForDiffConvertor convertor = new ChangeForDiffConvertor(myProject, false);
|
||||
final List<Pair<String,DiffRequestPresentable>> list = new ArrayList<>();
|
||||
final DiffRequestPresentable requestPresentable = convertor.convert(myChange, false);
|
||||
if (requestPresentable != null) {
|
||||
list.add(Pair.create("", requestPresentable));
|
||||
}
|
||||
final Map<String,Change> layers = myChange.getOtherLayers();
|
||||
for (Map.Entry<String, Change> entry : layers.entrySet()) {
|
||||
final String key = entry.getKey();
|
||||
final Change value = entry.getValue();
|
||||
final DiffRequestPresentable additional = convertor.convert(value, true);
|
||||
if (additional != null) {
|
||||
list.add(Pair.create(key, additional));
|
||||
}
|
||||
}
|
||||
|
||||
if (list.isEmpty()) return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.removeFromList);
|
||||
|
||||
DiffRequest request = null;
|
||||
final StringBuilder err = new StringBuilder();
|
||||
for (Pair<String, DiffRequestPresentable> pair : list) {
|
||||
final MyResult step = pair.getSecond().step(context);
|
||||
if (step == null) continue;
|
||||
final DiffPresentationReturnValue returnValue = step.getReturnValue();
|
||||
if (DiffPresentationReturnValue.quit.equals(returnValue)) {
|
||||
final String error = step.getAsOneError();
|
||||
if (StringUtil.isEmptyOrSpaces(error)) {
|
||||
return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.quit);
|
||||
} else {
|
||||
return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.quit, error);
|
||||
}
|
||||
} else if (! DiffPresentationReturnValue.removeFromList.equals(returnValue) && ! step.hasErrors()) {
|
||||
// use contents
|
||||
if (request == null) {
|
||||
request = step.getRequest();
|
||||
if (! StringUtil.isEmptyOrSpaces(pair.getFirst())) {
|
||||
request.setWindowTitle(pair.getFirst() + " " + request.getWindowTitle());
|
||||
}
|
||||
} else {
|
||||
request.addOtherLayer(pair.getFirst(), step.getRequest());
|
||||
}
|
||||
} else {
|
||||
final String error = step.getAsOneError();
|
||||
if (! StringUtil.isEmptyOrSpaces(error)) {
|
||||
err.append(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (request == null || err.length() > 0) {
|
||||
return new MyResult(new SimpleDiffRequest(myProject, ""), DiffPresentationReturnValue.removeFromList, err.toString());
|
||||
}
|
||||
return new MyResult(request, DiffPresentationReturnValue.useRequest, err.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void haveStuff() throws VcsException {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends AnAction> createActions(DiffExtendUIFactory uiFactory) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathPresentation() {
|
||||
return ChangesUtil.getFilePath(myChange).getPath();
|
||||
}
|
||||
}
|
||||
-84
@@ -1,84 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.CommonDataKeys;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.diff.DiffManager;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.DiffViewer;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.awt.*;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
abstract class ShowChangeAbstractAction extends DumbAwareAction {
|
||||
|
||||
ShowChangeAbstractAction() {
|
||||
setEnabledInModalContext(true);
|
||||
}
|
||||
|
||||
public void update(AnActionEvent e) {
|
||||
final ChangeRequestChain chain = e.getData(VcsDataKeys.DIFF_REQUEST_CHAIN);
|
||||
e.getPresentation().setEnabled(chain != null && isEnabled(chain));
|
||||
}
|
||||
|
||||
protected abstract boolean isEnabled(@NotNull ChangeRequestChain chain);
|
||||
|
||||
public void actionPerformed(AnActionEvent e) {
|
||||
final Project project = e.getData(CommonDataKeys.PROJECT);
|
||||
final ChangeRequestChain chain = e.getData(VcsDataKeys.DIFF_REQUEST_CHAIN);
|
||||
if (project == null || chain == null || !isEnabled(chain)) {
|
||||
return;
|
||||
}
|
||||
|
||||
DiffViewer diffViewer = e.getData(PlatformDataKeys.COMPOSITE_DIFF_VIEWER);
|
||||
if (diffViewer == null) {
|
||||
diffViewer = e.getData(PlatformDataKeys.DIFF_VIEWER);
|
||||
}
|
||||
if (diffViewer == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
actionPerformed(e, project, chain, diffViewer);
|
||||
}
|
||||
|
||||
protected void openRequest(@NotNull DiffViewer diffViewer, @Nullable DiffRequest request) {
|
||||
if (request != null) {
|
||||
if (diffViewer.acceptsType(request.getType())) {
|
||||
diffViewer.setDiffRequest(request);
|
||||
}
|
||||
else {
|
||||
final Window window = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
|
||||
if (window != null) {
|
||||
window.setVisible(false);
|
||||
}
|
||||
DiffManager.getInstance().getDiffTool().show(request);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected abstract void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain,
|
||||
@NotNull DiffViewer diffViewer);
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.DiffViewer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ShowNextChangeAction extends ShowChangeAbstractAction {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled(@NotNull ChangeRequestChain chain) {
|
||||
return chain.canMoveForward();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain,
|
||||
@NotNull DiffViewer diffViewer) {
|
||||
DiffRequest request = chain.moveForward();
|
||||
openRequest(diffViewer, request);
|
||||
}
|
||||
|
||||
}
|
||||
-42
@@ -1,42 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2009 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.DiffViewer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
*/
|
||||
public class ShowPrevChangeAction extends ShowChangeAbstractAction {
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled(@NotNull ChangeRequestChain chain) {
|
||||
return chain.canMoveBack();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain,
|
||||
@NotNull DiffViewer diffViewer) {
|
||||
DiffRequest request = chain.moveBack();
|
||||
openRequest(diffViewer, request);
|
||||
}
|
||||
|
||||
}
|
||||
-161
@@ -1,161 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2012 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.actions;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnActionEvent;
|
||||
import com.intellij.openapi.actionSystem.DefaultActionGroup;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.diff.DiffRequest;
|
||||
import com.intellij.openapi.diff.DiffViewer;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.popup.JBPopup;
|
||||
import com.intellij.openapi.ui.popup.JBPopupFactory;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import com.intellij.openapi.vcs.changes.ui.ChangesBrowser;
|
||||
import com.intellij.ui.awt.RelativePoint;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import javax.swing.tree.TreeSelectionModel;
|
||||
import java.awt.event.InputEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author Kirill Likhodedov
|
||||
*/
|
||||
public class ShowSelectedChangeAction extends ShowChangeAbstractAction {
|
||||
|
||||
private static final Logger LOG = Logger.getInstance(ShowSelectedChangeAction.class);
|
||||
|
||||
private JBPopup myPopup;
|
||||
|
||||
@Override
|
||||
protected boolean isEnabled(@NotNull ChangeRequestChain chain) {
|
||||
return getChangesFromRequests(chain.getAllRequests()).size() > 1;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(@NotNull AnActionEvent e, @NotNull Project project, @NotNull ChangeRequestChain chain,
|
||||
@NotNull DiffViewer diffViewer) {
|
||||
List<DiffRequestPresentable> requests = chain.getAllRequests();
|
||||
List<Change> changes = getChangesFromRequests(requests);
|
||||
|
||||
ChangesBrowser cb = new MyChangesBrowser(project, changes, requests, chain, diffViewer);
|
||||
|
||||
myPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(cb, cb.getPreferredFocusedComponent())
|
||||
.setResizable(true)
|
||||
.setModalContext(false)
|
||||
.setFocusable(true)
|
||||
.setRequestFocus(true)
|
||||
.setCancelOnWindowDeactivation(true)
|
||||
.setCancelOnOtherWindowOpen(true)
|
||||
.setMovable(true)
|
||||
.setCancelKeyEnabled(true)
|
||||
.setCancelOnClickOutside(true)
|
||||
.createPopup();
|
||||
|
||||
InputEvent event = e.getInputEvent();
|
||||
if (event instanceof MouseEvent) {
|
||||
myPopup.show(new RelativePoint((MouseEvent)event));
|
||||
}
|
||||
else {
|
||||
myPopup.showInBestPositionFor(e.getDataContext());
|
||||
}
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<Change> getChangesFromRequests(@NotNull List<DiffRequestPresentable> requests) {
|
||||
List<Change> changes = new ArrayList<>();
|
||||
for (DiffRequestPresentable step : requests) {
|
||||
Change change = getChange(step);
|
||||
if (change != null) {
|
||||
changes.add(change);
|
||||
}
|
||||
}
|
||||
return changes;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Change getChange(@NotNull DiffRequestPresentable presentable) {
|
||||
if (presentable instanceof DiffRequestPresentableProxy) {
|
||||
try {
|
||||
presentable = ((DiffRequestPresentableProxy)presentable).init();
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (presentable instanceof ChangeDiffRequestPresentable) {
|
||||
return ((ChangeDiffRequestPresentable)presentable).getChange();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private class MyChangesBrowser extends ChangesBrowser implements Runnable {
|
||||
private final List<DiffRequestPresentable> myRequests;
|
||||
private final ChangeRequestChain myChain;
|
||||
private final DiffViewer myDiffViewer;
|
||||
|
||||
public MyChangesBrowser(@NotNull Project project, @NotNull List<Change> changes, @NotNull List<DiffRequestPresentable> requests,
|
||||
@NotNull ChangeRequestChain chain, @NotNull DiffViewer diffViewer) {
|
||||
super(project, null, changes, null, false, false, null, MyUseCase.LOCAL_CHANGES, null);
|
||||
myRequests = requests;
|
||||
myChain = chain;
|
||||
myDiffViewer = diffViewer;
|
||||
|
||||
setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
|
||||
setChangesToDisplay(changes);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void buildToolBar(DefaultActionGroup toolBarGroup) {
|
||||
// remove diff action
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
protected Runnable getDoubleClickHandler() {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Change change = getSelectedChanges().get(0);
|
||||
DiffRequestPresentable selectedStep = findSelectedStep(change);
|
||||
if (selectedStep != null) {
|
||||
DiffRequest newRequest = myChain.moveTo(selectedStep);
|
||||
openRequest(myDiffViewer, newRequest);
|
||||
}
|
||||
myPopup.cancel();
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private DiffRequestPresentable findSelectedStep(@Nullable Change change) {
|
||||
for (DiffRequestPresentable step : myRequests) {
|
||||
Change c = getChange(step);
|
||||
if (c != null && c.equals(change)) {
|
||||
return step;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+2
-151
@@ -1,6 +1,5 @@
|
||||
package com.intellij.openapi.vcs.changes.actions.migrate;
|
||||
|
||||
import com.intellij.diff.actions.impl.GoToChangePopupBuilder;
|
||||
import com.intellij.diff.chains.DiffRequestChain;
|
||||
import com.intellij.diff.chains.DiffRequestProducer;
|
||||
import com.intellij.diff.chains.DiffRequestProducerException;
|
||||
@@ -14,7 +13,6 @@ import com.intellij.diff.requests.ErrorDiffRequest;
|
||||
import com.intellij.diff.requests.SimpleDiffRequest;
|
||||
import com.intellij.diff.util.DiffUserDataKeysEx;
|
||||
import com.intellij.diff.util.LineCol;
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.diff.DiffNavigationContext;
|
||||
import com.intellij.openapi.diff.DiffTool;
|
||||
@@ -22,23 +20,9 @@ import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.UserDataHolder;
|
||||
import com.intellij.openapi.util.UserDataHolderBase;
|
||||
import com.intellij.openapi.vcs.VcsDataKeys;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ChangeRequestChain;
|
||||
import com.intellij.openapi.vcs.changes.actions.ChangeDiffRequestPresentable;
|
||||
import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentable;
|
||||
import com.intellij.openapi.vcs.changes.actions.DiffRequestPresentableProxy;
|
||||
import com.intellij.openapi.vcs.changes.actions.diff.ChangeGoToChangePopupAction;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.Navigatable;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
@@ -56,14 +40,8 @@ public class MigrateToNewDiffUtil {
|
||||
|
||||
@NotNull
|
||||
public static DiffRequestChain convertRequestChain(@NotNull com.intellij.openapi.diff.DiffRequest oldRequest) {
|
||||
ChangeRequestChain oldChain = (ChangeRequestChain)oldRequest.getGenericData().get(VcsDataKeys.DIFF_REQUEST_CHAIN.getName());
|
||||
if (oldChain == null || oldChain.getAllRequests().size() < 2) {
|
||||
DiffRequest request = convertRequest(oldRequest);
|
||||
return new SimpleDiffRequestChain(request);
|
||||
}
|
||||
else {
|
||||
return new ChangeRequestChainWrapper(oldChain);
|
||||
}
|
||||
DiffRequest request = convertRequest(oldRequest);
|
||||
return new SimpleDiffRequestChain(request);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@@ -128,133 +106,6 @@ public class MigrateToNewDiffUtil {
|
||||
}
|
||||
}
|
||||
|
||||
private static class ChangeRequestChainWrapper extends UserDataHolderBase implements DiffRequestChain, GoToChangePopupBuilder.Chain {
|
||||
@NotNull private final ChangeRequestChain myChain;
|
||||
@NotNull private final List<MyProducerWrapper> myRequests;
|
||||
|
||||
private int myIndex;
|
||||
|
||||
public ChangeRequestChainWrapper(@NotNull ChangeRequestChain chain) {
|
||||
myChain = chain;
|
||||
myRequests = ContainerUtil.map(myChain.getAllRequests(),
|
||||
new Function<DiffRequestPresentable, MyProducerWrapper>() {
|
||||
@Override
|
||||
public MyProducerWrapper fun(DiffRequestPresentable presentable) {
|
||||
return new MyProducerWrapper(myChain, presentable);
|
||||
}
|
||||
});
|
||||
|
||||
myIndex = chain.getAllRequests().indexOf(chain.getCurrentRequest());
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public List<? extends MyProducerWrapper> getRequests() {
|
||||
return myRequests;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getIndex() {
|
||||
return myIndex;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setIndex(int index) {
|
||||
assert index >= 0 && index < myRequests.size();
|
||||
myIndex = index;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private static Change getChange(@NotNull DiffRequestPresentable presentable) {
|
||||
if (presentable instanceof DiffRequestPresentableProxy) {
|
||||
try {
|
||||
presentable = ((DiffRequestPresentableProxy)presentable).init();
|
||||
}
|
||||
catch (VcsException e) {
|
||||
LOG.info(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
if (presentable instanceof ChangeDiffRequestPresentable) {
|
||||
return ((ChangeDiffRequestPresentable)presentable).getChange();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public AnAction createGoToChangeAction(@NotNull Consumer<Integer> onSelected) {
|
||||
return new ChangeGoToChangePopupAction<ChangeRequestChainWrapper>(this, onSelected) {
|
||||
@NotNull
|
||||
@Override
|
||||
protected List<Change> getChanges() {
|
||||
return ContainerUtil.mapNotNull(myChain.getRequests(), new Function<MyProducerWrapper, Change>() {
|
||||
@Override
|
||||
@Nullable
|
||||
public Change fun(MyProducerWrapper wrapper) {
|
||||
return getChange(wrapper.getPresentable());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
protected Change getCurrentSelection() {
|
||||
return getChange(myChain.getRequests().get(myIndex).getPresentable());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int findSelectedStep(@Nullable Change change) {
|
||||
if (change == null) return -1;
|
||||
for (int i = 0; i < myRequests.size(); i++) {
|
||||
Change c = getChange(myRequests.get(i).getPresentable());
|
||||
if (c != null && change.equals(c)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyProducerWrapper implements DiffRequestProducer {
|
||||
@NotNull private final DiffRequestPresentable myPresentable;
|
||||
@NotNull private final ChangeRequestChain myChain;
|
||||
|
||||
public MyProducerWrapper(@NotNull ChangeRequestChain chain,
|
||||
@NotNull DiffRequestPresentable presentable) {
|
||||
myPresentable = presentable;
|
||||
myChain = chain;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getName() {
|
||||
return myPresentable.getPathPresentation();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public DiffRequestPresentable getPresentable() {
|
||||
return myPresentable;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public DiffRequest process(@NotNull UserDataHolder context, @NotNull ProgressIndicator indicator)
|
||||
throws DiffRequestProducerException, ProcessCanceledException {
|
||||
com.intellij.openapi.diff.DiffRequest oldRequest =
|
||||
UIUtil.invokeAndWaitIfNeeded(new Computable<com.intellij.openapi.diff.DiffRequest>() {
|
||||
@Override
|
||||
public com.intellij.openapi.diff.DiffRequest compute() {
|
||||
return myChain.moveTo(myPresentable);
|
||||
}
|
||||
});
|
||||
if (oldRequest == null) return new ErrorDiffRequest(this, "Can't build old-style request");
|
||||
return convertRequest(oldRequest);
|
||||
}
|
||||
}
|
||||
|
||||
private static class MyDiffRequestProducer implements DiffRequestProducer {
|
||||
@NotNull private final com.intellij.openapi.diff.DiffRequest myRequest;
|
||||
|
||||
|
||||
-147
@@ -1,147 +0,0 @@
|
||||
/*
|
||||
* Copyright 2000-2010 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.openapi.vcs.changes.patch;
|
||||
|
||||
import com.intellij.openapi.actionSystem.AnAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.diff.*;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.impl.DocumentImpl;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.ui.Messages;
|
||||
import com.intellij.openapi.util.Getter;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vcs.VcsBundle;
|
||||
import com.intellij.openapi.vcs.changes.actions.*;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class MergedDiffRequestPresentable implements DiffRequestPresentable {
|
||||
private final Project myProject;
|
||||
private final VirtualFile myFile;
|
||||
private final String myAfterTitle;
|
||||
private final Getter<ApplyPatchForBaseRevisionTexts> myTexts;
|
||||
|
||||
public MergedDiffRequestPresentable(final Project project,
|
||||
final Getter<ApplyPatchForBaseRevisionTexts> texts,
|
||||
final VirtualFile file,
|
||||
final String afterTitle) {
|
||||
myTexts = texts;
|
||||
myProject = project;
|
||||
myFile = file;
|
||||
myAfterTitle = afterTitle;
|
||||
}
|
||||
|
||||
public MyResult step(DiffChainContext context) {
|
||||
if (myFile.getFileType().isBinary()) {
|
||||
final boolean nowItIsText = ChangeDiffRequestPresentable.checkAssociate(myProject, myFile.getName(), context);
|
||||
if (!nowItIsText) {
|
||||
final SimpleDiffRequest request = new SimpleDiffRequest(myProject, null);
|
||||
return new MyResult(request, DiffPresentationReturnValue.removeFromList);
|
||||
}
|
||||
}
|
||||
final ApplyPatchForBaseRevisionTexts revisionTexts = myTexts.get();
|
||||
if (revisionTexts.getBase() == null) {
|
||||
final SimpleDiffRequest badDiffRequest = createBadDiffRequest(myProject, myFile, revisionTexts, true);
|
||||
return new MyResult(badDiffRequest, DiffPresentationReturnValue.useRequest);
|
||||
}
|
||||
final MergeRequest request = DiffRequestFactory.getInstance()
|
||||
.create3WayDiffRequest(revisionTexts.getLocal().toString(),
|
||||
revisionTexts.getPatched(),
|
||||
revisionTexts.getBase().toString(),
|
||||
myFile.getFileType(), myProject, null, null);
|
||||
request.setWindowTitle(VcsBundle.message("patch.apply.conflict.title", FileUtil.toSystemDependentName(myFile.getPresentableUrl())));
|
||||
request.setVersionTitles(new String[]{"Current Version", "Base Version", FileUtil.toSystemDependentName(myAfterTitle)});
|
||||
return new MyResult(request, DiffPresentationReturnValue.useRequest);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPathPresentation() {
|
||||
return myFile.getPath();
|
||||
}
|
||||
|
||||
public void haveStuff() {
|
||||
}
|
||||
|
||||
public List<? extends AnAction> createActions(DiffExtendUIFactory uiFactory) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SimpleDiffRequest createBadDiffRequest(@Nullable final Project project,
|
||||
@NotNull final VirtualFile file,
|
||||
@NotNull ApplyPatchForBaseRevisionTexts texts,
|
||||
boolean readonly) {
|
||||
final String fullPath = file.getParent() == null ? file.getPath() : file.getParent().getPath();
|
||||
final String title = "Result Of Patch Apply To " + file.getName() + " (" + fullPath + ")";
|
||||
|
||||
final SimpleDiffRequest simpleRequest = new SimpleDiffRequest(project, title);
|
||||
final DocumentImpl patched = new DocumentImpl(texts.getPatched());
|
||||
patched.setReadOnly(false);
|
||||
|
||||
final DocumentContent mergedContent =
|
||||
new DocumentContent(project, patched, file.getFileType());
|
||||
mergedContent.getDocument().setReadOnly(readonly);
|
||||
final SimpleContent originalContent = new SimpleContent(texts.getLocal().toString(), file.getFileType());
|
||||
|
||||
simpleRequest.setContents(originalContent, mergedContent);
|
||||
simpleRequest.setContentTitles(VcsBundle.message("diff.title.local"), "Patched (with problems)");
|
||||
simpleRequest.addHint(DiffTool.HINT_SHOW_MODAL_DIALOG);
|
||||
simpleRequest.addHint(DiffTool.HINT_DIFF_IS_APPROXIMATE);
|
||||
|
||||
if (!readonly) {
|
||||
simpleRequest.setOnOkRunnable(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String resultText = mergedContent.getDocument().getText();
|
||||
final Document document = FileDocumentManager.getInstance().getDocument(file);
|
||||
if (document == null) {
|
||||
try {
|
||||
VfsUtil.saveText(file, resultText);
|
||||
}
|
||||
catch (IOException e) {
|
||||
// todo bad: we had already returned success by now
|
||||
showIOException(project, file.getName(), e);
|
||||
}
|
||||
}
|
||||
else {
|
||||
document.setText(resultText);
|
||||
FileDocumentManager.getInstance().saveDocument(document);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
return simpleRequest;
|
||||
}
|
||||
|
||||
private static void showIOException(@Nullable Project project, @NotNull String name, @NotNull IOException e) {
|
||||
Messages.showErrorDialog(project,
|
||||
VcsBundle.message("patch.apply.error", name, e.getMessage()),
|
||||
VcsBundle.message("patch.apply.dialog.title"));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user