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"));
}
}
}
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);
}
Aggregations