Search in sources :

Example 1 with GitVcsSettings

use of git4idea.config.GitVcsSettings in project intellij-community by JetBrains.

the class GitLogBranchOperationsActionGroup method getChildren.

@NotNull
@Override
public AnAction[] getChildren(AnActionEvent e) {
    if (e == null)
        return AnAction.EMPTY_ARRAY;
    Project project = e.getProject();
    VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
    VcsLogUi logUI = e.getData(VcsLogDataKeys.VCS_LOG_UI);
    List<VcsRef> branches = e.getData(VcsLogDataKeys.VCS_LOG_BRANCHES);
    if (project == null || log == null || logUI == null || branches == null) {
        return AnAction.EMPTY_ARRAY;
    }
    List<CommitId> commits = log.getSelectedCommits();
    if (commits.size() != 1)
        return AnAction.EMPTY_ARRAY;
    CommitId commit = commits.get(0);
    GitRepositoryManager repositoryManager = GitRepositoryManager.getInstance(project);
    final GitRepository root = repositoryManager.getRepositoryForRoot(commit.getRoot());
    if (root == null)
        return AnAction.EMPTY_ARRAY;
    List<VcsRef> vcsRefs = ContainerUtil.filter(branches, new Condition<VcsRef>() {

        @Override
        public boolean value(VcsRef ref) {
            if (ref.getType() == GitRefManager.LOCAL_BRANCH) {
                return !ref.getName().equals(root.getCurrentBranchName());
            }
            if (ref.getType() == GitRefManager.REMOTE_BRANCH)
                return true;
            return false;
        }
    });
    VcsLogProvider provider = logUI.getDataPack().getLogProviders().get(root.getRoot());
    if (provider != null) {
        VcsLogRefManager refManager = provider.getReferenceManager();
        Comparator<VcsRef> comparator = refManager.getLabelsOrderComparator();
        ContainerUtil.sort(vcsRefs, comparator);
    }
    if (vcsRefs.isEmpty())
        return AnAction.EMPTY_ARRAY;
    GitVcsSettings settings = GitVcsSettings.getInstance(project);
    boolean showBranchesPopup = vcsRefs.size() > MAX_BRANCH_GROUPS;
    List<AnAction> branchActionGroups = new ArrayList<>();
    for (VcsRef ref : vcsRefs) {
        branchActionGroups.add(createBranchGroup(project, ref, root, repositoryManager, settings, showBranchesPopup));
    }
    DefaultActionGroup branchesGroup = new DefaultActionGroup("Branches", branchActionGroups);
    branchesGroup.setPopup(showBranchesPopup);
    return new AnAction[] { branchesGroup };
}
Also used : GitVcsSettings(git4idea.config.GitVcsSettings) ArrayList(java.util.ArrayList) GitRepositoryManager(git4idea.repo.GitRepositoryManager) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GitVcsSettings

use of git4idea.config.GitVcsSettings in project intellij-community by JetBrains.

the class GitBranchPopup method getInstance.

/**
   * @param currentRepository Current repository, which means the repository of the currently open or selected file.
   *                          In the case of synchronized branch operations current repository matter much less, but sometimes is used,
   *                          for example, it is preselected in the repositories combobox in the compare branches dialog.
   */
static GitBranchPopup getInstance(@NotNull final Project project, @NotNull GitRepository currentRepository) {
    final GitVcsSettings vcsSettings = GitVcsSettings.getInstance(project);
    Condition<AnAction> preselectActionCondition = action -> {
        if (action instanceof GitBranchPopupActions.LocalBranchActions) {
            GitBranchPopupActions.LocalBranchActions branchAction = (GitBranchPopupActions.LocalBranchActions) action;
            String branchName = branchAction.getBranchName();
            String recentBranch;
            List<GitRepository> repositories = branchAction.getRepositories();
            if (repositories.size() == 1) {
                recentBranch = vcsSettings.getRecentBranchesByRepository().get(repositories.iterator().next().getRoot().getPath());
            } else {
                recentBranch = vcsSettings.getRecentCommonBranch();
            }
            if (recentBranch != null && recentBranch.equals(branchName)) {
                return true;
            }
        }
        return false;
    };
    return new GitBranchPopup(currentRepository, GitUtil.getRepositoryManager(project), vcsSettings, preselectActionCondition);
}
Also used : GitRepositoryManager(git4idea.repo.GitRepositoryManager) BranchActionGroupPopup.wrapWithMoreActionIfNeeded(com.intellij.dvcs.ui.BranchActionGroupPopup.wrapWithMoreActionIfNeeded) GitVcsSettings(git4idea.config.GitVcsSettings) ContainerUtil(com.intellij.util.containers.ContainerUtil) RootAction(com.intellij.dvcs.ui.RootAction) GitBranchUtil(git4idea.branch.GitBranchUtil) AbstractRepositoryManager(com.intellij.dvcs.repo.AbstractRepositoryManager) GitUtil(git4idea.GitUtil) DvcsUtil(com.intellij.dvcs.DvcsUtil) Project(com.intellij.openapi.project.Project) GitRepository(git4idea.repo.GitRepository) BranchActionGroup(com.intellij.dvcs.ui.BranchActionGroup) DvcsBranchPopup(com.intellij.dvcs.branch.DvcsBranchPopup) DEFAULT_NUM(com.intellij.dvcs.branch.DvcsBranchPopup.MyMoreIndex.DEFAULT_NUM) AnAction(com.intellij.openapi.actionSystem.AnAction) BranchActionUtil.getNumOfTopShownBranches(com.intellij.dvcs.ui.BranchActionUtil.getNumOfTopShownBranches) ActionGroup(com.intellij.openapi.actionSystem.ActionGroup) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Objects(java.util.Objects) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) MAX_NUM(com.intellij.dvcs.branch.DvcsBranchPopup.MyMoreIndex.MAX_NUM) ContainerUtil.map(com.intellij.util.containers.ContainerUtil.map) NotNull(org.jetbrains.annotations.NotNull) FAVORITE_BRANCH_COMPARATOR(com.intellij.dvcs.ui.BranchActionUtil.FAVORITE_BRANCH_COMPARATOR) Condition(com.intellij.openapi.util.Condition) javax.swing(javax.swing) GitVcsSettings(git4idea.config.GitVcsSettings) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 3 with GitVcsSettings

use of git4idea.config.GitVcsSettings in project intellij-community by JetBrains.

the class GitResetAction method actionPerformed.

@Override
protected void actionPerformed(@NotNull final Project project, @NotNull final Map<GitRepository, VcsFullCommitDetails> commits) {
    GitVcsSettings settings = GitVcsSettings.getInstance(project);
    GitResetMode defaultMode = ObjectUtils.notNull(settings.getResetMode(), GitResetMode.getDefault());
    GitNewResetDialog dialog = new GitNewResetDialog(project, commits, defaultMode);
    if (dialog.showAndGet()) {
        final GitResetMode selectedMode = dialog.getResetMode();
        settings.setResetMode(selectedMode);
        new Task.Backgroundable(project, "Git reset", true) {

            @Override
            public void run(@NotNull ProgressIndicator indicator) {
                Map<GitRepository, Hash> hashes = commits.keySet().stream().collect(Collectors.toMap(Function.identity(), repo -> commits.get(repo).getId()));
                new GitResetOperation(project, hashes, selectedMode, indicator).execute();
            }
        }.queue();
    }
}
Also used : GitVcsSettings(git4idea.config.GitVcsSettings) Task(com.intellij.openapi.progress.Task) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Map(java.util.Map)

Aggregations

GitVcsSettings (git4idea.config.GitVcsSettings)3 Project (com.intellij.openapi.project.Project)2 GitRepository (git4idea.repo.GitRepository)2 GitRepositoryManager (git4idea.repo.GitRepositoryManager)2 NotNull (org.jetbrains.annotations.NotNull)2 DvcsUtil (com.intellij.dvcs.DvcsUtil)1 DvcsBranchPopup (com.intellij.dvcs.branch.DvcsBranchPopup)1 DEFAULT_NUM (com.intellij.dvcs.branch.DvcsBranchPopup.MyMoreIndex.DEFAULT_NUM)1 MAX_NUM (com.intellij.dvcs.branch.DvcsBranchPopup.MyMoreIndex.MAX_NUM)1 AbstractRepositoryManager (com.intellij.dvcs.repo.AbstractRepositoryManager)1 BranchActionGroup (com.intellij.dvcs.ui.BranchActionGroup)1 BranchActionGroupPopup.wrapWithMoreActionIfNeeded (com.intellij.dvcs.ui.BranchActionGroupPopup.wrapWithMoreActionIfNeeded)1 FAVORITE_BRANCH_COMPARATOR (com.intellij.dvcs.ui.BranchActionUtil.FAVORITE_BRANCH_COMPARATOR)1 BranchActionUtil.getNumOfTopShownBranches (com.intellij.dvcs.ui.BranchActionUtil.getNumOfTopShownBranches)1 RootAction (com.intellij.dvcs.ui.RootAction)1 ActionGroup (com.intellij.openapi.actionSystem.ActionGroup)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1