use of com.intellij.openapi.vcs.actions.VcsContext in project intellij-community by JetBrains.
the class MigrateCvsRootAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
final VcsContext context = CvsContextWrapper.createInstance(event);
final VirtualFile selectedFile = context.getSelectedFile();
final Project project = context.getProject();
final MigrateRootDialog dialog = new MigrateRootDialog(project, selectedFile);
if (!dialog.showAndGet()) {
return;
}
final File directory = dialog.getSelectedDirectory();
final boolean shouldReplaceAllRoots = dialog.shouldReplaceAllRoots();
final List<File> rootFiles = new ArrayList<>();
try {
if (shouldReplaceAllRoots) {
collectRootFiles(directory, null, rootFiles);
} else {
collectRootFiles(directory, dialog.getCvsRoot(), rootFiles);
}
} catch (IOException e) {
LOG.error(e);
return;
}
final CvsRootConfiguration cvsConfiguration = dialog.getSelectedCvsConfiguration();
final String cvsRoot = cvsConfiguration.getCvsRootAsString();
for (final File file : rootFiles) {
try {
FileUtils.writeLine(file, cvsRoot);
} catch (IOException e) {
LOG.error(e);
break;
}
}
final AccessToken token = ApplicationManager.getApplication().acquireReadActionLock();
try {
for (File file : rootFiles) {
CvsVfsUtil.findFileByIoFile(file).refresh(true, false);
}
} finally {
token.finish();
}
StatusBar.Info.set("Finished migrating CVS root to " + cvsRoot, project);
}
use of com.intellij.openapi.vcs.actions.VcsContext in project intellij-community by JetBrains.
the class UnmarkAddedAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
VcsContext context = CvsContextWrapper.createCachedInstance(e);
final VirtualFile[] selectedFiles = context.getSelectedFiles();
ProgressManager.getInstance().runProcessWithProgressSynchronously(() -> {
ProgressIndicator progressIndicator = ProgressManager.getInstance().getProgressIndicator();
for (int i = 0; i < selectedFiles.length; i++) {
File file = CvsVfsUtil.getFileFor(selectedFiles[i]);
if (progressIndicator != null) {
progressIndicator.setFraction((double) i / (double) selectedFiles.length);
progressIndicator.setText(file.getAbsolutePath());
}
CvsUtil.removeEntryFor(file);
}
}, CvsBundle.message("operation.name.undo.add"), true, context.getProject());
VirtualFileManager.getInstance().asyncRefresh(null);
}
use of com.intellij.openapi.vcs.actions.VcsContext in project intellij-community by JetBrains.
the class MergeAction method actionPerformed.
public void actionPerformed(AnActionEvent e) {
try {
final VcsContext context = CvsContextWrapper.createCachedInstance(e);
final VirtualFile[] files = context.getSelectedFiles();
if (files.length == 0)
return;
final Project project = context.getProject();
final ReadonlyStatusHandler.OperationStatus operationStatus = ReadonlyStatusHandler.getInstance(project).ensureFilesWritable(files);
if (operationStatus.hasReadonlyFiles()) {
return;
}
AbstractVcsHelper.getInstance(project).showMergeDialog(Arrays.asList(files), new CvsMergeProvider());
} catch (Exception e1) {
LOG.error(e1);
}
}
use of com.intellij.openapi.vcs.actions.VcsContext in project intellij-community by JetBrains.
the class ImportAction method createCheckoutAction.
private AbstractAction createCheckoutAction(final boolean makeNewFilesReadOnly) {
return new AbstractAction(false) {
protected String getTitle(VcsContext context) {
return CvsBundle.message("operation.name.check.out.project");
}
protected CvsHandler getCvsHandler(CvsContext context) {
final Project project = context.getProject();
return CommandCvsHandler.createCheckoutHandler(myImportDetails.getCvsRoot(), new String[] { myImportDetails.getModuleName() }, myImportDetails.getBaseImportDirectory(), true, makeNewFilesReadOnly, project == null ? null : VcsConfiguration.getInstance(project).getCheckoutOption());
}
protected void onActionPerformed(CvsContext context, CvsTabbedWindow tabbedWindow, boolean successfully, CvsHandler handler) {
super.onActionPerformed(context, tabbedWindow, successfully, handler);
final Project project = context.getProject();
if (successfully) {
if (project != null) {
final VirtualFile importedRoot = CvsVfsUtil.findFileByIoFile(myImportDetails.getBaseImportDirectory());
updateDirectoryMappings(project, importedRoot);
}
}
}
/**
* Basically copied from GitInit/HgInit
*/
private void updateDirectoryMappings(Project project, VirtualFile mapRoot) {
if (project == null || project.isDefault()) {
return;
}
final VirtualFile projectBaseDir = project.getBaseDir();
if (projectBaseDir == null || !VfsUtil.isAncestor(projectBaseDir, mapRoot, false)) {
return;
}
mapRoot.refresh(false, false);
final String path = mapRoot.equals(projectBaseDir) ? "" : mapRoot.getPath();
ProjectLevelVcsManager manager = ProjectLevelVcsManager.getInstance(project);
manager.setDirectoryMappings(VcsUtil.addMapping(manager.getDirectoryMappings(), path, CvsVcs2.getInstance(project).getName()));
manager.updateActiveVcss();
}
};
}
Aggregations