Search in sources :

Example 1 with HgRepositoryManager

use of org.zmlx.hg4idea.repo.HgRepositoryManager in project intellij-community by JetBrains.

the class HgUtil method sortByHgRoots.

@NotNull
public static Map<VirtualFile, Collection<VirtualFile>> sortByHgRoots(@NotNull Project project, @NotNull Collection<VirtualFile> files) {
    Map<VirtualFile, Collection<VirtualFile>> sorted = new HashMap<>();
    HgRepositoryManager repositoryManager = getRepositoryManager(project);
    for (VirtualFile file : files) {
        HgRepository repo = repositoryManager.getRepositoryForFile(file);
        if (repo == null) {
            continue;
        }
        Collection<VirtualFile> filesForRoot = sorted.get(repo.getRoot());
        if (filesForRoot == null) {
            filesForRoot = new HashSet<>();
            sorted.put(repo.getRoot(), filesForRoot);
        }
        filesForRoot.add(file);
    }
    return sorted;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgRepository(org.zmlx.hg4idea.repo.HgRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with HgRepositoryManager

use of org.zmlx.hg4idea.repo.HgRepositoryManager in project intellij-community by JetBrains.

the class HgUtil method getRepositoryForFile.

@Nullable
public static HgRepository getRepositoryForFile(@NotNull Project project, @Nullable VirtualFile file) {
    if (file == null || project.isDisposed())
        return null;
    HgRepositoryManager repositoryManager = getRepositoryManager(project);
    VirtualFile root = getHgRootOrNull(project, file);
    return repositoryManager.getRepositoryForRoot(root);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) VcsVirtualFile(com.intellij.openapi.vcs.vfs.VcsVirtualFile) AbstractVcsVirtualFile(com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) Nullable(org.jetbrains.annotations.Nullable)

Example 3 with HgRepositoryManager

use of org.zmlx.hg4idea.repo.HgRepositoryManager in project intellij-community by JetBrains.

the class HgAbstractGlobalAction method actionPerformed.

public void actionPerformed(@NotNull AnActionEvent event) {
    final DataContext dataContext = event.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return;
    }
    VirtualFile[] files = event.getData(CommonDataKeys.VIRTUAL_FILE_ARRAY);
    final HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
    List<HgRepository> repositories = repositoryManager.getRepositories();
    if (!repositories.isEmpty()) {
        List<HgRepository> selectedRepositories = files != null ? HgActionUtil.collectRepositoriesFromFiles(repositoryManager, Arrays.asList(files)) : ContainerUtil.<HgRepository>emptyList();
        execute(project, repositories, selectedRepositories.isEmpty() ? Collections.singletonList(HgUtil.getCurrentRepository(project)) : selectedRepositories);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgRepository(org.zmlx.hg4idea.repo.HgRepository)

Example 4 with HgRepositoryManager

use of org.zmlx.hg4idea.repo.HgRepositoryManager in project intellij-community by JetBrains.

the class HgActionUtil method getSelectedRepositoryFromEvent.

@Nullable
@CalledInAwt
public static HgRepository getSelectedRepositoryFromEvent(AnActionEvent e) {
    final DataContext dataContext = e.getDataContext();
    final Project project = CommonDataKeys.PROJECT.getData(dataContext);
    if (project == null) {
        return null;
    }
    VirtualFile file = e.getData(CommonDataKeys.VIRTUAL_FILE);
    HgRepositoryManager repositoryManager = HgUtil.getRepositoryManager(project);
    return file != null ? repositoryManager.getRepositoryForFileQuick(file) : HgUtil.getCurrentRepository(project);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) CalledInAwt(org.jetbrains.annotations.CalledInAwt) Nullable(org.jetbrains.annotations.Nullable)

Example 5 with HgRepositoryManager

use of org.zmlx.hg4idea.repo.HgRepositoryManager in project intellij-community by JetBrains.

the class HgBranchPopup method getInstance.

/**
   * @param currentRepository Current repository, which means the repository of the currently open or selected file.
   */
public static HgBranchPopup getInstance(@NotNull Project project, @NotNull HgRepository currentRepository) {
    HgRepositoryManager manager = HgUtil.getRepositoryManager(project);
    HgProjectSettings hgProjectSettings = ServiceManager.getService(project, HgProjectSettings.class);
    HgMultiRootBranchConfig hgMultiRootBranchConfig = new HgMultiRootBranchConfig(manager.getRepositories());
    Condition<AnAction> preselectActionCondition = new Condition<AnAction>() {

        @Override
        public boolean value(AnAction action) {
            return false;
        }
    };
    return new HgBranchPopup(currentRepository, manager, hgMultiRootBranchConfig, hgProjectSettings, preselectActionCondition);
}
Also used : Condition(com.intellij.openapi.util.Condition) HgRepositoryManager(org.zmlx.hg4idea.repo.HgRepositoryManager) HgProjectSettings(org.zmlx.hg4idea.HgProjectSettings) AnAction(com.intellij.openapi.actionSystem.AnAction)

Aggregations

HgRepositoryManager (org.zmlx.hg4idea.repo.HgRepositoryManager)7 VirtualFile (com.intellij.openapi.vfs.VirtualFile)5 AbstractVcsVirtualFile (com.intellij.openapi.vcs.vfs.AbstractVcsVirtualFile)3 VcsVirtualFile (com.intellij.openapi.vcs.vfs.VcsVirtualFile)3 HgRepository (org.zmlx.hg4idea.repo.HgRepository)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 Project (com.intellij.openapi.project.Project)2 NotNull (org.jetbrains.annotations.NotNull)2 Nullable (org.jetbrains.annotations.Nullable)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 Condition (com.intellij.openapi.util.Condition)1 FilePath (com.intellij.openapi.vcs.FilePath)1 ArrayList (java.util.ArrayList)1 CalledInAwt (org.jetbrains.annotations.CalledInAwt)1 HgProjectSettings (org.zmlx.hg4idea.HgProjectSettings)1 HgCommandException (org.zmlx.hg4idea.execution.HgCommandException)1 HgCommandExecutor (org.zmlx.hg4idea.execution.HgCommandExecutor)1