use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.
the class RevertCommittedStuffAbstractAction method actionPerformed.
public void actionPerformed(final AnActionEvent e) {
final Project project = e.getRequiredData(CommonDataKeys.PROJECT);
final VirtualFile baseDir = project.getBaseDir();
assert baseDir != null;
final Change[] changes = myForPerformConvertor.convert(e);
if (changes == null || changes.length == 0)
return;
final List<Change> changesList = new ArrayList<>();
Collections.addAll(changesList, changes);
FileDocumentManager.getInstance().saveAllDocuments();
String defaultName = null;
final ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
if (changeLists != null && changeLists.length > 0) {
defaultName = VcsBundle.message("revert.changes.default.name", changeLists[0].getName());
}
final ChangeListChooser chooser = new ChangeListChooser(project, ChangeListManager.getInstance(project).getChangeListsCopy(), null, "Select Target Changelist", defaultName);
if (!chooser.showAndGet()) {
return;
}
final List<FilePatch> patches = new ArrayList<>();
ProgressManager.getInstance().run(new Task.Backgroundable(project, VcsBundle.message("revert.changes.title"), true) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {
final List<Change> preprocessed = ChangesPreprocess.preprocessChangesRemoveDeletedForDuplicateMoved(changesList);
patches.addAll(IdeaTextPatchBuilder.buildPatch(project, preprocessed, baseDir.getPresentableUrl(), true));
} catch (final VcsException ex) {
WaitForProgressToShow.runOrInvokeLaterAboveProgress(new Runnable() {
@Override
public void run() {
Messages.showErrorDialog(project, "Failed to revert changes: " + ex.getMessage(), VcsBundle.message("revert.changes.title"));
}
}, null, myProject);
indicator.cancel();
}
}
@Override
public void onSuccess() {
new PatchApplier<BinaryFilePatch>(project, baseDir, patches, chooser.getSelectedList(), null, null).execute();
}
});
}
use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.
the class GetCommittedChangelistAction method actionPerformed.
@Override
protected void actionPerformed(@NotNull final VcsContext context) {
Collection<FilePath> filePaths = getFilePaths(context);
final List<ChangeList> selectedChangeLists = new ArrayList<>();
final ChangeList[] selectionFromContext = context.getSelectedChangeLists();
if (selectionFromContext != null) {
Collections.addAll(selectedChangeLists, selectionFromContext);
}
final List<CommittedChangeList> incomingChanges = CommittedChangesCache.getInstance(context.getProject()).getCachedIncomingChanges();
final List<CommittedChangeList> intersectingChanges = new ArrayList<>();
if (incomingChanges != null) {
for (CommittedChangeList changeList : incomingChanges) {
if (!selectedChangeLists.contains(changeList)) {
for (Change change : changeList.getChanges()) {
if (filePaths.contains(ChangesUtil.getFilePath(change))) {
intersectingChanges.add(changeList);
break;
}
}
}
}
}
if (intersectingChanges.size() > 0) {
int rc = Messages.showOkCancelDialog(context.getProject(), VcsBundle.message("get.committed.changes.intersecting.prompt", intersectingChanges.size(), selectedChangeLists.size()), VcsBundle.message("get.committed.changes.title"), Messages.getQuestionIcon());
if (rc != Messages.OK)
return;
}
super.actionPerformed(context);
}
use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.
the class GetCommittedChangelistAction method getFilePaths.
private static Collection<FilePath> getFilePaths(final VcsContext context) {
final Set<FilePath> files = new HashSet<>();
final ChangeList[] selectedChangeLists = context.getSelectedChangeLists();
if (selectedChangeLists != null) {
for (ChangeList changelist : selectedChangeLists) {
for (Change change : changelist.getChanges()) {
files.add(ChangesUtil.getFilePath(change));
}
}
}
return files;
}
use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.
the class BaseAnalysisActionDialog method getScope.
@NotNull
public AnalysisScope getScope(@NotNull AnalysisUIOptions uiOptions, @NotNull AnalysisScope defaultScope, @NotNull Project project, Module module) {
AnalysisScope scope;
if (isProjectScopeSelected()) {
scope = new AnalysisScope(project);
uiOptions.SCOPE_TYPE = AnalysisScope.PROJECT;
} else {
final SearchScope customScope = getCustomScope();
if (customScope != null) {
scope = new AnalysisScope(customScope, project);
uiOptions.SCOPE_TYPE = AnalysisScope.CUSTOM;
uiOptions.CUSTOM_SCOPE_NAME = customScope.getDisplayName();
} else if (isModuleScopeSelected()) {
scope = new AnalysisScope(module);
uiOptions.SCOPE_TYPE = AnalysisScope.MODULE;
} else if (isUncommitedFilesSelected()) {
final ChangeListManager changeListManager = ChangeListManager.getInstance(project);
List<VirtualFile> files;
if (myChangeLists.getSelectedItem() == ALL) {
files = changeListManager.getAffectedFiles();
} else {
files = new ArrayList<>();
for (ChangeList list : changeListManager.getChangeListsCopy()) {
if (!Comparing.strEqual(list.getName(), (String) myChangeLists.getSelectedItem()))
continue;
final Collection<Change> changes = list.getChanges();
for (Change change : changes) {
final ContentRevision afterRevision = change.getAfterRevision();
if (afterRevision != null) {
final VirtualFile vFile = afterRevision.getFile().getVirtualFile();
if (vFile != null) {
files.add(vFile);
}
}
}
}
}
scope = new AnalysisScope(project, new HashSet<>(files));
uiOptions.SCOPE_TYPE = AnalysisScope.UNCOMMITTED_FILES;
} else {
scope = defaultScope;
//just not project scope
uiOptions.SCOPE_TYPE = defaultScope.getScopeType();
}
}
uiOptions.ANALYZE_TEST_SOURCES = isInspectTestSources();
scope.setIncludeTestSource(isInspectTestSources());
FindSettings.getInstance().setDefaultScopeName(scope.getDisplayName());
return scope;
}
use of com.intellij.openapi.vcs.changes.ChangeList in project intellij-community by JetBrains.
the class ChangelistConflictAccessProvider method requestWriting.
@NotNull
@Override
public Collection<VirtualFile> requestWriting(VirtualFile... files) {
ChangelistConflictTracker.Options options = myManager.getConflictTracker().getOptions();
if (!options.TRACKING_ENABLED || !options.SHOW_DIALOG) {
return Collections.emptyList();
}
ArrayList<VirtualFile> denied = new ArrayList<>();
for (VirtualFile file : files) {
if (file != null && !myManager.getConflictTracker().isWritingAllowed(file)) {
denied.add(file);
}
}
if (!denied.isEmpty()) {
HashSet<ChangeList> changeLists = new HashSet<>();
ArrayList<Change> changes = new ArrayList<>();
for (VirtualFile file : denied) {
changeLists.add(myManager.getChangeList(file));
changes.add(myManager.getChange(file));
}
ChangelistConflictDialog dialog;
final int savedEventCount = IdeEventQueue.getInstance().getEventCount();
do {
dialog = new ChangelistConflictDialog(myProject, new ArrayList<>(changeLists), denied);
dialog.show();
} while (dialog.isOK() && !dialog.getResolution().resolveConflict(myProject, changes, null));
IdeEventQueue.getInstance().setEventCount(savedEventCount);
if (dialog.isOK()) {
options.LAST_RESOLUTION = dialog.getResolution();
return Collections.emptyList();
}
}
return denied;
}
Aggregations