Search in sources :

Example 1 with HgCloneDialog

use of org.zmlx.hg4idea.ui.HgCloneDialog in project intellij-community by JetBrains.

the class HgCheckoutProvider method doCheckout.

public void doCheckout(@NotNull final Project project, @Nullable final Listener listener) {
    FileDocumentManager.getInstance().saveAllDocuments();
    final HgCloneDialog dialog = new HgCloneDialog(project);
    if (!dialog.showAndGet()) {
        return;
    }
    dialog.rememberSettings();
    VirtualFile destinationParent = LocalFileSystem.getInstance().findFileByIoFile(new File(dialog.getParentDirectory()));
    if (destinationParent == null) {
        return;
    }
    final String targetDir = destinationParent.getPath() + File.separator + dialog.getDirectoryName();
    final String sourceRepositoryURL = dialog.getSourceRepositoryURL();
    final AtomicReference<HgCommandResult> cloneResult = new AtomicReference<>();
    new Task.Backgroundable(project, HgVcsMessages.message("hg4idea.clone.progress", sourceRepositoryURL), true) {

        @Override
        public void run(@NotNull ProgressIndicator indicator) {
            HgCloneCommand clone = new HgCloneCommand(project);
            clone.setRepositoryURL(sourceRepositoryURL);
            clone.setDirectory(targetDir);
            cloneResult.set(clone.executeInCurrentThread());
        }

        @Override
        public void onSuccess() {
            if (cloneResult.get() == null || HgErrorUtil.hasErrorsInCommandExecution(cloneResult.get())) {
                new HgCommandResultNotifier(project).notifyError(cloneResult.get(), "Clone failed", "Clone from " + sourceRepositoryURL + " failed.");
            } else {
                DvcsUtil.addMappingIfSubRoot(project, targetDir, HgVcs.VCS_NAME);
                if (listener != null) {
                    listener.directoryCheckedOut(new File(dialog.getParentDirectory(), dialog.getDirectoryName()), HgVcs.getKey());
                    listener.checkoutCompleted();
                }
            }
        }
    }.queue();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Task(com.intellij.openapi.progress.Task) AtomicReference(java.util.concurrent.atomic.AtomicReference) HgCloneCommand(org.zmlx.hg4idea.command.HgCloneCommand) HgCommandResultNotifier(org.zmlx.hg4idea.action.HgCommandResultNotifier) HgCloneDialog(org.zmlx.hg4idea.ui.HgCloneDialog) HgCommandResult(org.zmlx.hg4idea.execution.HgCommandResult) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 File (java.io.File)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 HgCommandResultNotifier (org.zmlx.hg4idea.action.HgCommandResultNotifier)1 HgCloneCommand (org.zmlx.hg4idea.command.HgCloneCommand)1 HgCommandResult (org.zmlx.hg4idea.execution.HgCommandResult)1 HgCloneDialog (org.zmlx.hg4idea.ui.HgCloneDialog)1