Search in sources :

Example 1 with VcsContext

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);
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) AccessToken(com.intellij.openapi.application.AccessToken) ArrayList(java.util.ArrayList) MigrateRootDialog(com.intellij.cvsSupport2.ui.MigrateRootDialog) IOException(java.io.IOException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) CvsRootConfiguration(com.intellij.cvsSupport2.config.CvsRootConfiguration)

Example 2 with VcsContext

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);
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 3 with VcsContext

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);
    }
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) ReadonlyStatusHandler(com.intellij.openapi.vfs.ReadonlyStatusHandler)

Example 4 with VcsContext

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();
        }
    };
}
Also used : VcsContext(com.intellij.openapi.vcs.actions.VcsContext) CvsTabbedWindow(com.intellij.cvsSupport2.ui.CvsTabbedWindow) VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) CvsHandler(com.intellij.cvsSupport2.cvshandlers.CvsHandler) CommandCvsHandler(com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler) CvsContext(com.intellij.cvsSupport2.actions.cvsContext.CvsContext) ProjectLevelVcsManager(com.intellij.openapi.vcs.ProjectLevelVcsManager)

Aggregations

VcsContext (com.intellij.openapi.vcs.actions.VcsContext)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 Project (com.intellij.openapi.project.Project)3 File (java.io.File)2 CvsContext (com.intellij.cvsSupport2.actions.cvsContext.CvsContext)1 CvsRootConfiguration (com.intellij.cvsSupport2.config.CvsRootConfiguration)1 CommandCvsHandler (com.intellij.cvsSupport2.cvshandlers.CommandCvsHandler)1 CvsHandler (com.intellij.cvsSupport2.cvshandlers.CvsHandler)1 CvsTabbedWindow (com.intellij.cvsSupport2.ui.CvsTabbedWindow)1 MigrateRootDialog (com.intellij.cvsSupport2.ui.MigrateRootDialog)1 AccessToken (com.intellij.openapi.application.AccessToken)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 ProjectLevelVcsManager (com.intellij.openapi.vcs.ProjectLevelVcsManager)1 ReadonlyStatusHandler (com.intellij.openapi.vfs.ReadonlyStatusHandler)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1