VCS: import to shelf added to apply patch dialog; allow to unshelve with another base paths (apply patch dialog opened)

This commit is contained in:
irengrig
2011-02-25 19:43:29 +03:00
parent 43bc01d973
commit 92618a5aba
13 changed files with 493 additions and 49 deletions
@@ -33,9 +33,13 @@ import java.util.List;
public class PatchCreator {
public static void create(Project p, List<Change> changes, String filePath, boolean isReverse)
throws IOException, VcsException {
List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(p, changes, p.getBaseDir().getPath(), isReverse);
writeFilePatches(p, filePath, patches);
}
public static void writeFilePatches(Project p, String filePath, List<FilePatch> patches) throws IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(filePath));
try {
List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(p, changes, p.getBaseDir().getPath(), isReverse);
String lineSeparator = CodeStyleSettingsManager.getInstance(p).getCurrentSettings().getLineSeparator();
UnifiedDiffWriter.write(patches, writer, lineSeparator);
}
@@ -123,6 +123,8 @@
<group id="ShelvedChangesPopupMenu">
<action id="ShelvedChanges.Unshelve" class="com.intellij.openapi.vcs.changes.shelf.UnshelveChangesAction"/>
<action id="ShelveChanges.UnshelveWithDialog" class="com.intellij.openapi.vcs.changes.shelf.UnshelveWithDialogAction"
text="Unshelve..." description="Correct paths where to apply patches and unshelve"/>
<action id="ShelvedChanges.Restore" class="com.intellij.openapi.vcs.changes.shelf.RestoreShelvedChange"/>
<action id="ShelvedChanges.Diff" class="com.intellij.openapi.vcs.changes.shelf.DiffShelvedChangesAction"
icon="/actions/diff.png"/>
@@ -0,0 +1,52 @@
/*
* Copyright 2000-2011 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.vcsUtil;
import com.intellij.openapi.util.Getter;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.util.SmartList;
import java.util.List;
/**
* @author irengrig
* Date: 2/25/11
* Time: 7:05 PM
*/
public abstract class VcsCatchingRunnable implements Runnable, Getter<List<VcsException>> {
private final List<VcsException> myExceptions;
public VcsCatchingRunnable() {
myExceptions = new SmartList<VcsException>();
}
@Override
public List<VcsException> get() {
return myExceptions;
}
protected abstract void runImpl() throws VcsException;
@Override
public void run() {
try {
runImpl();
}
catch (VcsException e) {
myExceptions.add(e);
}
}
}
@@ -46,6 +46,7 @@ import com.intellij.openapi.ui.DialogWrapper;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.util.Computable;
import com.intellij.openapi.vcs.*;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
import com.intellij.util.containers.Convertor;
@@ -55,6 +56,7 @@ import org.jetbrains.annotations.Nullable;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.LinkedList;
import java.util.List;
@@ -68,32 +70,6 @@ public class ApplyPatchAction extends DumbAwareAction {
}
public static void showApplyPatch(final Project project, final VirtualFile file) {
final Consumer<ApplyPatchDifferentiatedDialog> callback = new Consumer<ApplyPatchDifferentiatedDialog>() {
public void consume(ApplyPatchDifferentiatedDialog newDia) {
if (newDia.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
return;
}
final Collection<FilePatchInProgress> included = newDia.getIncluded();
final MultiMap<VirtualFile, FilePatchInProgress> patchGroups = new MultiMap<VirtualFile, FilePatchInProgress>();
for (FilePatchInProgress patchInProgress : included) {
patchGroups.putValue(patchInProgress.getBase(), patchInProgress);
}
final Collection<PatchApplier> appliers = new LinkedList<PatchApplier>();
for (VirtualFile base : patchGroups.keySet()) {
final PatchApplier patchApplier =
new PatchApplier<BinaryFilePatch>(project, base, ObjectsConvertor.convert(patchGroups.get(base),
new Convertor<FilePatchInProgress, FilePatch>() {
public FilePatch convert(FilePatchInProgress o) {
return o.getPatch();
}
}), newDia.getSelectedChangeList(), null);
appliers.add(patchApplier);
}
PatchApplier.executePatchGroup(appliers);
}
};
FileDocumentManager.getInstance().saveAllDocuments();
final VirtualFile toUse;
if (file != null) {
@@ -107,7 +83,8 @@ public class ApplyPatchAction extends DumbAwareAction {
}
toUse = files[0];
}
final ApplyPatchDifferentiatedDialog dialog = new ApplyPatchDifferentiatedDialog(project, callback, toUse);
final ApplyPatchDifferentiatedDialog dialog = new ApplyPatchDifferentiatedDialog(project, new ApplyPatchDefaultExecutor(project),
Collections.<ApplyPatchExecutor>singletonList(new ImportToShelfExecutor(project)), ApplyPatchMode.APPLY, toUse);
dialog.show();
}
@@ -0,0 +1,64 @@
/*
* Copyright 2000-2011 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.diff.impl.patch.BinaryFilePatch;
import com.intellij.openapi.diff.impl.patch.FilePatch;
import com.intellij.openapi.diff.impl.patch.formove.PatchApplier;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vcs.ObjectsConvertor;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.MultiMap;
import java.util.Collection;
import java.util.LinkedList;
/**
* @author irengrig
* Date: 2/25/11
* Time: 5:58 PM
*/
public class ApplyPatchDefaultExecutor implements ApplyPatchExecutor {
private final Project myProject;
public ApplyPatchDefaultExecutor(Project project) {
myProject = project;
}
@Override
public String getName() {
// not used
return null;
}
@Override
public void apply(MultiMap<VirtualFile, FilePatchInProgress> patchGroups, LocalChangeList localList, String fileName) {
final Collection<PatchApplier> appliers = new LinkedList<PatchApplier>();
for (VirtualFile base : patchGroups.keySet()) {
final PatchApplier patchApplier =
new PatchApplier<BinaryFilePatch>(myProject, base, ObjectsConvertor.convert(patchGroups.get(base),
new Convertor<FilePatchInProgress, FilePatch>() {
public FilePatch convert(FilePatchInProgress o) {
return o.getPatch();
}
}), localList, null);
appliers.add(patchApplier);
}
PatchApplier.executePatchGroup(appliers);
}
}
@@ -48,6 +48,7 @@ import com.intellij.ui.SimpleColoredComponent;
import com.intellij.ui.SimpleTextAttributes;
import com.intellij.util.Consumer;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.MultiMap;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -56,6 +57,7 @@ import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.tree.DefaultTreeModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.*;
@@ -79,16 +81,19 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
private final ChangeListChooserPanel myChangeListChooser;
private final ChangesLegendCalculator myInfoCalculator;
private final CommitLegendPanel myCommitLegendPanel;
private final Consumer<ApplyPatchDifferentiatedDialog> myCallback;
private final ApplyPatchExecutor myCallback;
private final List<ApplyPatchExecutor> myExecutors;
private boolean myContainBasedChanges;
private JLabel myPatchFileLabel;
public ApplyPatchDifferentiatedDialog(final Project project, final Consumer<ApplyPatchDifferentiatedDialog> callback,
@NotNull final VirtualFile patchFile) {
public ApplyPatchDifferentiatedDialog(final Project project, final ApplyPatchExecutor callback, final List<ApplyPatchExecutor> executors,
@NotNull final ApplyPatchMode applyPatchMode, @NotNull final VirtualFile patchFile) {
super(project, true);
myCallback = callback;
myExecutors = executors;
setModal(false);
setTitle(VcsBundle.message("patch.apply.dialog.title"));
setTitle(applyPatchMode.getTitle());
final FileChooserDescriptor descriptor = createSelectPatchDescriptor();
descriptor.setTitle(VcsBundle.message("patch.apply.select.title"));
@@ -148,6 +153,8 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
if (patchFile.isValid()) {
init(patchFile);
}
myPatchFileLabel.setVisible(applyPatchMode.isCanChangePatchFile());
myPatchFile.setVisible(applyPatchMode.isCanChangePatchFile());
}
public static FileChooserDescriptor createSelectPatchDescriptor() {
@@ -159,6 +166,39 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
};
}
@Override
protected Action[] createActions() {
if (myExecutors.isEmpty()) {
return super.createActions();
}
final List<Action> actions = new ArrayList<Action>(4);
actions.add(getOKAction());
for (int i = 0; i < myExecutors.size(); i++) {
final ApplyPatchExecutor executor = myExecutors.get(i);
final int finalI = i;
actions.add(new AbstractAction(executor.getName()) {
@Override
public void actionPerformed(ActionEvent e) {
runExecutor(executor);
close(NEXT_USER_EXIT_CODE + finalI);
}
});
}
actions.add(getCancelAction());
actions.add(getHelpAction());
return actions.toArray(new Action[actions.size()]);
}
private void runExecutor(ApplyPatchExecutor executor) {
final Collection<FilePatchInProgress> included = getIncluded();
if (included.isEmpty()) return;
final MultiMap<VirtualFile, FilePatchInProgress> patchGroups = new MultiMap<VirtualFile, FilePatchInProgress>();
for (FilePatchInProgress patchInProgress : included) {
patchGroups.putValue(patchInProgress.getBase(), patchInProgress);
}
executor.apply(patchGroups, getSelectedChangeList(), myRecentPathFileChange.get().getVf().getName());
}
@Override
@NonNls
protected String getDimensionServiceKey() {
@@ -287,9 +327,9 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
final GridBagConstraints gb =
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(1, 1, 1, 1), 0, 0);
final JLabel label = new JLabel(VcsBundle.message("create.patch.file.name.field"));
label.setLabelFor(myPatchFile);
myCenterPanel.add(label, gb);
myPatchFileLabel = new JLabel(VcsBundle.message("create.patch.file.name.field"));
myPatchFileLabel.setLabelFor(myPatchFile);
myCenterPanel.add(myPatchFileLabel, gb);
++ gb.gridx;
gb.fill = GridBagConstraints.HORIZONTAL;
@@ -724,7 +764,7 @@ public class ApplyPatchDifferentiatedDialog extends DialogWrapper {
@Override
protected void doOKAction() {
super.doOKAction();
myCallback.consume(this);
runExecutor(myCallback);
}
private class ZeroStrip extends AnAction {
@@ -0,0 +1,30 @@
/*
* Copyright 2000-2011 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.vcs.changes.LocalChangeList;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.MultiMap;
/**
* @author irengrig
* Date: 2/25/11
* Time: 5:18 PM
*/
public interface ApplyPatchExecutor {
String getName();
void apply(final MultiMap<VirtualFile, FilePatchInProgress> patchGroups, final LocalChangeList localList, String fileName);
}
@@ -0,0 +1,44 @@
/*
* Copyright 2000-2011 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.vcs.VcsBundle;
/**
* @author irengrig
* Date: 2/25/11
* Time: 5:23 PM
*/
public enum ApplyPatchMode {
APPLY(VcsBundle.message("patch.apply.dialog.title"), true),
UNSHELVE(VcsBundle.message("unshelve.changes.dialog.title"), false);
private final String myTitle;
private final boolean myCanChangePatchFile;
ApplyPatchMode(String title, boolean canChangePatchFile) {
myTitle = title;
myCanChangePatchFile = canChangePatchFile;
}
public String getTitle() {
return myTitle;
}
public boolean isCanChangePatchFile() {
return myCanChangePatchFile;
}
}
@@ -41,10 +41,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.io.*;
import java.util.Collection;
import java.util.List;
@@ -158,15 +155,8 @@ public class CreatePatchCommitExecutor implements CommitExecutorWithHelp, Projec
PATCH_PATH = file.getParent();
REVERSE_PATCH = myPanel.isReversePatch();
Writer writer = new OutputStreamWriter(new FileOutputStream(fileName));
try {
List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(myProject, changes, myProject.getBaseDir().getPresentableUrl(), REVERSE_PATCH);
final String lineSeparator = CodeStyleFacade.getInstance(myProject).getLineSeparator();
UnifiedDiffWriter.write(patches, writer, lineSeparator);
}
finally {
writer.close();
}
List<FilePatch> patches = IdeaTextPatchBuilder.buildPatch(myProject, changes, myProject.getBaseDir().getPresentableUrl(), REVERSE_PATCH);
PatchWriter.writePatches(myProject, fileName, patches);
if (binaryCount == 0) {
ApplicationManager.getApplication().invokeLater(new Runnable() {
public void run() {
@@ -0,0 +1,99 @@
/*
* Copyright 2000-2011 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.diff.impl.patch.FilePatch;
import com.intellij.openapi.diff.impl.patch.PatchHunk;
import com.intellij.openapi.diff.impl.patch.TextFilePatch;
import com.intellij.openapi.progress.ProgressManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.vcs.AbstractVcsHelper;
import com.intellij.openapi.vcs.ObjectsConvertor;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.shelf.ShelveChangesManager;
import com.intellij.openapi.vcs.changes.shelf.ShelvedChangeList;
import com.intellij.openapi.vcs.changes.shelf.ShelvedChangesViewManager;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.containers.Convertor;
import com.intellij.util.containers.MultiMap;
import com.intellij.vcsUtil.VcsCatchingRunnable;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
/**
* @author irengrig
* Date: 2/25/11
* Time: 6:21 PM
*/
public class ImportToShelfExecutor implements ApplyPatchExecutor {
public static final String IMPORT_TO_SHELF = "Import to shelf";
private final Project myProject;
public ImportToShelfExecutor(Project project) {
myProject = project;
}
@Override
public String getName() {
return IMPORT_TO_SHELF;
}
@Override
public void apply(final MultiMap<VirtualFile, FilePatchInProgress> patchGroups, LocalChangeList localList, final String fileName) {
final VcsCatchingRunnable vcsCatchingRunnable = new VcsCatchingRunnable() {
@Override
public void runImpl() throws VcsException {
final VirtualFile baseDir = myProject.getBaseDir();
final File ioBase = new File(baseDir.getPath());
final List<FilePatch> allPatches = new ArrayList<FilePatch>();
for (VirtualFile virtualFile : patchGroups.keySet()) {
final File ioCurrentBase = new File(virtualFile.getPath());
allPatches.addAll(ObjectsConvertor.convert(patchGroups.get(virtualFile),
new Convertor<FilePatchInProgress, TextFilePatch>() {
public TextFilePatch convert(FilePatchInProgress o) {
final TextFilePatch was = o.getPatch();
was.setBeforeName(FileUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase,
new File(ioCurrentBase, was.getBeforeName()))));
was.setAfterName(FileUtil.toSystemIndependentName(FileUtil.getRelativePath(ioBase,
new File(ioCurrentBase, was.getAfterName()))));
return was;
}
}));
}
if (!allPatches.isEmpty()) {
try {
final ShelvedChangeList shelvedChangeList = ShelveChangesManager.getInstance(myProject).importFilePatches(fileName, allPatches);
ShelvedChangesViewManager.getInstance(myProject).activateView(shelvedChangeList);
}
catch (IOException e) {
throw new VcsException(e);
}
}
}
};
ProgressManager.getInstance().runProcessWithProgressSynchronously(vcsCatchingRunnable, "Import patch to shelf", true, myProject);
if (! vcsCatchingRunnable.get().isEmpty()) {
AbstractVcsHelper.getInstance(myProject).showErrors(vcsCatchingRunnable.get(), IMPORT_TO_SHELF);
}
}
}
@@ -0,0 +1,48 @@
/*
* Copyright 2000-2011 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.codeStyle.CodeStyleFacade;
import com.intellij.openapi.diff.impl.patch.FilePatch;
import com.intellij.openapi.diff.impl.patch.UnifiedDiffWriter;
import com.intellij.openapi.project.Project;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.List;
/**
* @author irengrig
* Date: 2/25/11
* Time: 6:41 PM
*/
public class PatchWriter {
private PatchWriter() {
}
public static void writePatches(final Project project, String fileName, List<FilePatch> patches) throws IOException {
Writer writer = new OutputStreamWriter(new FileOutputStream(fileName));
try {
final String lineSeparator = CodeStyleFacade.getInstance(project).getLineSeparator();
UnifiedDiffWriter.write(patches, writer, lineSeparator);
}
finally {
writer.close();
}
}
}
@@ -44,6 +44,7 @@ import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsException;
import com.intellij.openapi.vcs.changes.*;
import com.intellij.openapi.vcs.changes.patch.PatchNameChecker;
import com.intellij.openapi.vcs.changes.patch.PatchWriter;
import com.intellij.openapi.vcs.changes.ui.RollbackWorker;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.util.Consumer;
@@ -199,6 +200,25 @@ public class ShelveChangesManager implements ProjectComponent, JDOMExternalizabl
return changeList;
}
public ShelvedChangeList importFilePatches(final String fileName, final List<FilePatch> patches) throws IOException {
try {
final File patchPath = getPatchPath(fileName);
myFileProcessor.savePathFile(
new CompoundShelfFileProcessor.ContentProvider(){
public void writeContentTo(final Writer writer) throws IOException {
UnifiedDiffWriter.write(patches, writer, "\n");
}
},
patchPath);
final ShelvedChangeList changeList = new ShelvedChangeList(patchPath.toString(), fileName.replace('\n', ' '), new SmartList<ShelvedBinaryFile>());
myShelvedChangeLists.add(changeList);
return changeList;
} finally {
notifyStateChanged();
}
}
public List<ShelvedChangeList> importChangeLists(final Collection<VirtualFile> files, final Consumer<VcsException> exceptionConsumer) {
final List<ShelvedChangeList> result = new ArrayList<ShelvedChangeList>(files.size());
try {
@@ -0,0 +1,74 @@
/*
* Copyright 2000-2011 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.shelf;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.fileEditor.FileDocumentManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.MessageType;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.changes.ChangeListManager;
import com.intellij.openapi.vcs.changes.LocalChangeList;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchDefaultExecutor;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchDifferentiatedDialog;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchExecutor;
import com.intellij.openapi.vcs.changes.patch.ApplyPatchMode;
import com.intellij.openapi.vcs.changes.ui.ChangeListChooser;
import com.intellij.openapi.vcs.ui.VcsBalloonProblemNotifier;
import com.intellij.openapi.vfs.LocalFileSystem;
import com.intellij.openapi.vfs.VirtualFile;
import java.io.File;
import java.util.Collections;
import java.util.List;
/**
* @author irengrig
* Date: 2/25/11
* Time: 5:50 PM
*/
public class UnshelveWithDialogAction extends AnAction {
@Override
public void actionPerformed(AnActionEvent e) {
final Project project = e.getData(PlatformDataKeys.PROJECT);
final ShelvedChangeList[] changeLists = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY);
if (project == null || changeLists == null || changeLists.length != 1) return;
FileDocumentManager.getInstance().saveAllDocuments();
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(changeLists[0].PATH));
if (virtualFile == null) {
VcsBalloonProblemNotifier.showOverChangesView(project, "Can not find path file", MessageType.ERROR);
return;
}
if (! changeLists[0].getBinaryFiles().isEmpty()) {
VcsBalloonProblemNotifier.showOverChangesView(project, "Binary file(s) would be skipped.", MessageType.WARNING);
}
final ApplyPatchDifferentiatedDialog dialog =
new ApplyPatchDifferentiatedDialog(project, new ApplyPatchDefaultExecutor(project), Collections.<ApplyPatchExecutor>emptyList(),
ApplyPatchMode.UNSHELVE, virtualFile);
dialog.show();
}
@Override
public void update(AnActionEvent e) {
final Project project = e.getData(PlatformDataKeys.PROJECT);
final ShelvedChangeList[] changes = e.getData(ShelvedChangesViewManager.SHELVED_CHANGELIST_KEY);
e.getPresentation().setEnabled(project != null && changes != null && changes.length == 1);
}
}