-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add compare with parent action (closes #1283)
- Loading branch information
1 parent
b656bb1
commit 5112285
Showing
7 changed files
with
111 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
...main/java/com/virtuslab/gitmachete/frontend/actions/base/BaseCompareWithParentAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
package com.virtuslab.gitmachete.frontend.actions.base; | ||
|
||
import static com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.fmt; | ||
import static com.virtuslab.gitmachete.frontend.resourcebundles.GitMacheteBundle.getNonHtmlString; | ||
|
||
import java.util.Collections; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.fileEditor.FileDocumentManager; | ||
import git4idea.branch.GitBrancher; | ||
import lombok.val; | ||
import org.checkerframework.checker.guieffect.qual.UIEffect; | ||
|
||
public abstract class BaseCompareWithParentAction extends BaseGitMacheteRepositoryReadyAction implements IBranchNameProvider { | ||
|
||
@Override | ||
@UIEffect | ||
protected void onUpdate(AnActionEvent anActionEvent) { | ||
super.onUpdate(anActionEvent); | ||
|
||
val presentation = anActionEvent.getPresentation(); | ||
if (!presentation.isEnabled()) { | ||
return; | ||
} | ||
|
||
val branchName = getNameOfBranchUnderAction(anActionEvent); | ||
val gitRepository = getSelectedGitRepository(anActionEvent); | ||
val managedBranch = getManagedBranchByName(anActionEvent, branchName); | ||
|
||
if (gitRepository == null || managedBranch == null) { | ||
return; | ||
} | ||
|
||
if (managedBranch.isRoot()) { | ||
presentation.setEnabled(false); | ||
presentation.setDescription( | ||
fmt(getNonHtmlString("action.GitMachete.BaseCompareWithParentAction.description.disabled.branch-is-root"), | ||
managedBranch.getName())); | ||
return; | ||
} | ||
|
||
val parent = managedBranch.asNonRoot().getParent(); | ||
|
||
String description = fmt(getNonHtmlString("action.GitMachete.BaseCompareWithParentAction.description.precise"), | ||
parent.getName(), | ||
managedBranch.getName()); | ||
presentation.setDescription(description); | ||
} | ||
|
||
@Override | ||
@UIEffect | ||
public void actionPerformed(AnActionEvent anActionEvent) { | ||
FileDocumentManager.getInstance().saveAllDocuments(); | ||
|
||
val project = getProject(anActionEvent); | ||
val branchName = getNameOfBranchUnderAction(anActionEvent); | ||
val gitRepository = getSelectedGitRepository(anActionEvent); | ||
val managedBranch = getManagedBranchByName(anActionEvent, branchName); | ||
|
||
if (gitRepository == null || managedBranch == null || managedBranch.isRoot()) { | ||
return; | ||
} | ||
|
||
val parent = managedBranch.asNonRoot().getParent(); | ||
GitBrancher.getInstance(project).compare(parent.getName(), Collections.singletonList(gitRepository)); | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...om/virtuslab/gitmachete/frontend/actions/contextmenu/CompareSelectedWithParentAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.virtuslab.gitmachete.frontend.actions.contextmenu; | ||
|
||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import kr.pe.kwonnam.slf4jlambda.LambdaLogger; | ||
import lombok.CustomLog; | ||
import org.checkerframework.checker.nullness.qual.Nullable; | ||
|
||
import com.virtuslab.gitmachete.frontend.actions.base.BaseCompareWithParentAction; | ||
import com.virtuslab.gitmachete.frontend.actions.expectedkeys.IExpectsKeySelectedBranchName; | ||
|
||
@CustomLog | ||
public class CompareSelectedWithParentAction extends BaseCompareWithParentAction implements IExpectsKeySelectedBranchName { | ||
@Override | ||
public LambdaLogger log() { | ||
return LOG; | ||
} | ||
|
||
@Override | ||
public @Nullable String getNameOfBranchUnderAction(AnActionEvent anActionEvent) { | ||
return getSelectedBranchName(anActionEvent); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters