Search in sources :

Example 1 with IManagedBranchSnapshot

use of com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class BaseRebaseBranchOntoParentAction method onUpdate.

@Override
@UIEffect
protected void onUpdate(AnActionEvent anActionEvent) {
    super.onUpdate(anActionEvent);
    val presentation = anActionEvent.getPresentation();
    if (!presentation.isEnabledAndVisible()) {
        return;
    }
    val state = getSelectedGitRepository(anActionEvent).map(r -> r.getState());
    val isCalledFromContextMenu = anActionEvent.getPlace().equals(ActionPlaces.ACTION_PLACE_CONTEXT_MENU);
    if (state.isEmpty()) {
        presentation.setEnabled(false);
        presentation.setDescription(getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.disabled.repository.unknown-state"));
    } else if (state.get() != Repository.State.NORMAL && !(isCalledFromContextMenu && state.get() == Repository.State.DETACHED)) {
        val stateName = Match(state.get()).of(Case($(Repository.State.GRAFTING), getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.repository.state.ongoing.cherry-pick")), Case($(Repository.State.DETACHED), getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.repository.state.detached-head")), Case($(Repository.State.MERGING), getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.repository.state.ongoing.merge")), Case($(Repository.State.REBASING), getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.repository.state.ongoing.rebase")), Case($(Repository.State.REVERTING), getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.repository.state.ongoing.revert")), Case($(), ": " + state.get().name().toLowerCase()));
        presentation.setEnabled(false);
        presentation.setDescription(format(getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.disabled.repository.status"), stateName));
    } else {
        val branchName = getNameOfBranchUnderAction(anActionEvent).getOrNull();
        val branch = branchName != null ? getManagedBranchByName(anActionEvent, branchName).getOrNull() : null;
        if (branch == null) {
            presentation.setEnabled(false);
            presentation.setDescription(format(getString("action.GitMachete.description.disabled.undefined.machete-branch"), "Rebase", getQuotedStringOrCurrent(branchName)));
        } else if (branch.isRoot()) {
            if (anActionEvent.getPlace().equals(ActionPlaces.ACTION_PLACE_TOOLBAR)) {
                presentation.setEnabled(false);
                presentation.setDescription(format(getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description.disabled.root-branch"), branch.getName()));
            } else {
                // contextmenu
                // in case of root branch we do not want to show this option at all
                presentation.setEnabledAndVisible(false);
            }
        } else if (branch.isNonRoot()) {
            val nonRootBranch = branch.asNonRoot();
            IManagedBranchSnapshot upstream = nonRootBranch.getParent();
            presentation.setDescription(format(getString("action.GitMachete.BaseRebaseBranchOntoParentAction.description"), branch.getName(), upstream.getName()));
        }
        val isRebasingCurrent = branch != null && getCurrentBranchNameIfManaged(anActionEvent).map(bn -> bn.equals(branch.getName())).getOrElse(false);
        if (isCalledFromContextMenu && isRebasingCurrent) {
            presentation.setText(getString("action.GitMachete.BaseRebaseBranchOntoParentAction.text"));
        }
    }
}
Also used : lombok.val(lombok.val) ActionUtils.getQuotedStringOrCurrent(com.virtuslab.gitmachete.frontend.actions.common.ActionUtils.getQuotedStringOrCurrent) Match(io.vavr.API.Match) IntelliJNotificationCompat(com.virtuslab.gitmachete.frontend.compat.IntelliJNotificationCompat) IGitMacheteRepositorySnapshot(com.virtuslab.gitmachete.backend.api.IGitMacheteRepositorySnapshot) IManagedBranchSnapshot(com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot) AtomicReference(java.util.concurrent.atomic.AtomicReference) IExpectsKeyGitMacheteRepository(com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeyGitMacheteRepository) Task(com.intellij.openapi.progress.Task) Option(io.vavr.control.Option) UIThreadUnsafe(com.virtuslab.qual.guieffect.UIThreadUnsafe) IGitRebaseParameters(com.virtuslab.gitmachete.backend.api.IGitRebaseParameters) GitVersion(git4idea.config.GitVersion) GitRebaseUtils(git4idea.rebase.GitRebaseUtils) Project(com.intellij.openapi.project.Project) Repository(com.intellij.dvcs.repo.Repository) GitRepository(git4idea.repo.GitRepository) GitRebaseParams(git4idea.branch.GitRebaseParams) API.$(io.vavr.API.$) GitRebaseEditorHandler(git4idea.rebase.GitRebaseEditorHandler) GitFreezingProcess(git4idea.util.GitFreezingProcess) INonRootManagedBranchSnapshot(com.virtuslab.gitmachete.backend.api.INonRootManagedBranchSnapshot) lombok.val(lombok.val) Case(io.vavr.API.Case) CustomLog(lombok.CustomLog) GitMacheteBundle.getString(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) Try(io.vavr.control.Try) UIEffect(org.checkerframework.checker.guieffect.qual.UIEffect) GitMacheteBundle.format(com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.format) ActionPlaces(com.virtuslab.gitmachete.frontend.defs.ActionPlaces) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) IEnhancedLambdaLogger(com.virtuslab.logger.IEnhancedLambdaLogger) IExecutionResult(com.virtuslab.gitmachete.backend.api.hooks.IExecutionResult) CheckoutSelectedBranchAction(com.virtuslab.gitmachete.frontend.actions.contextmenu.CheckoutSelectedBranchAction) Collections(java.util.Collections) IManagedBranchSnapshot(com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot) UIEffect(org.checkerframework.checker.guieffect.qual.UIEffect)

Example 2 with IManagedBranchSnapshot

use of com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot in project git-machete-intellij-plugin by VirtusLab.

the class RepositoryGraphBuilder method createBranchItemFor.

/**
 * @return {@link BranchItem} for given properties and provide additional attributes if the branch is the current one
 */
private BranchItem createBranchItemFor(IManagedBranchSnapshot branch, @GTENegativeOne int prevSiblingItemIndex, GraphItemColor graphItemColor, @NonNegative int indentLevel) {
    RelationToRemote relationToRemote = branch.getRelationToRemote();
    Option<IManagedBranchSnapshot> currentBranch = repositorySnapshot.getCurrentBranchIfManaged();
    boolean isCurrentBranch = currentBranch.isDefined() && currentBranch.get().equals(branch);
    boolean hasChildItem = !branch.getChildren().isEmpty();
    return new BranchItem(branch, graphItemColor, relationToRemote, prevSiblingItemIndex, indentLevel, isCurrentBranch, hasChildItem);
}
Also used : BranchItem(com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem) IManagedBranchSnapshot(com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot) RelationToRemote(com.virtuslab.gitmachete.backend.api.RelationToRemote)

Aggregations

IManagedBranchSnapshot (com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot)2 Repository (com.intellij.dvcs.repo.Repository)1 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)1 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)1 Task (com.intellij.openapi.progress.Task)1 Project (com.intellij.openapi.project.Project)1 IGitMacheteRepositorySnapshot (com.virtuslab.gitmachete.backend.api.IGitMacheteRepositorySnapshot)1 IGitRebaseParameters (com.virtuslab.gitmachete.backend.api.IGitRebaseParameters)1 INonRootManagedBranchSnapshot (com.virtuslab.gitmachete.backend.api.INonRootManagedBranchSnapshot)1 RelationToRemote (com.virtuslab.gitmachete.backend.api.RelationToRemote)1 IExecutionResult (com.virtuslab.gitmachete.backend.api.hooks.IExecutionResult)1 ActionUtils.getQuotedStringOrCurrent (com.virtuslab.gitmachete.frontend.actions.common.ActionUtils.getQuotedStringOrCurrent)1 CheckoutSelectedBranchAction (com.virtuslab.gitmachete.frontend.actions.contextmenu.CheckoutSelectedBranchAction)1 IExpectsKeyGitMacheteRepository (com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeyGitMacheteRepository)1 IntelliJNotificationCompat (com.virtuslab.gitmachete.frontend.compat.IntelliJNotificationCompat)1 ActionPlaces (com.virtuslab.gitmachete.frontend.defs.ActionPlaces)1 BranchItem (com.virtuslab.gitmachete.frontend.graph.impl.items.BranchItem)1 GitMacheteBundle.format (com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.format)1 GitMacheteBundle.getString (com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getString)1 IEnhancedLambdaLogger (com.virtuslab.logger.IEnhancedLambdaLogger)1