Open PawelLipski opened 1 year ago
The naive solution is just to do sth like:
--- a/frontend/actions/src/main/java/com/virtuslab/gitmachete/frontend/actions/expectedkeys/IExpectsKeyGitMacheteRepository.java
+++ b/frontend/actions/src/main/java/com/virtuslab/gitmachete/frontend/actions/expectedkeys/IExpectsKeyGitMacheteRepository.java
@@ -8,13 +8,16 @@ import com.virtuslab.branchlayout.api.BranchLayout;
import com.virtuslab.gitmachete.backend.api.IGitMacheteRepositorySnapshot;
import com.virtuslab.gitmachete.backend.api.IManagedBranchSnapshot;
import com.virtuslab.gitmachete.frontend.actions.base.IWithLogger;
-import com.virtuslab.gitmachete.frontend.datakeys.DataKeys;
+import com.virtuslab.gitmachete.frontend.ui.services.GraphTableService;
public interface IExpectsKeyGitMacheteRepository extends IWithLogger {
default @Nullable IGitMacheteRepositorySnapshot getGitMacheteRepositorySnapshot(AnActionEvent anActionEvent) {
- IGitMacheteRepositorySnapshot gitMacheteRepositorySnapshot = anActionEvent != null
- ? anActionEvent.getData(DataKeys.GIT_MACHETE_REPOSITORY_SNAPSHOT)
- : null;
+ val project = anActionEvent.getProject();
+ if (project == null) {
+ return null;
+ }
+ val graphTable = project.getService(GraphTableService.class).getGraphTable();
+ val gitMacheteRepositorySnapshot = graphTable.getGitMacheteRepositorySnapshot();
if (isLoggingAcceptable() && gitMacheteRepositorySnapshot == null) {
log().warn("Git Machete repository snapshot is undefined");
}
But there are other things to be considered:
getGitMacheteRepositorySnapshot()
always up to date when git machete tab is closed? if not (since IIRC the updates stop once the tab is no longer visible), then should the updates to repository snapshot happen even when the tab is closed? or maybe, the repository snapshot should be recomputed when it's needed while the tab is closed?com.virtuslab.gitmachete.frontend.datakeys.DataKeys
) be factored away this way as well)?
Otherwise, the
DataContext
passed inActionEvent
points toIdeFrameImpl
, not to our owncom.virtuslab.gitmachete.frontend.ui.impl.table.EnhancedGraphTable
, and hence the things likeGitMacheteRepositorySnapshot
aren't available to the action, which then gets disabled viacom.virtuslab.gitmachete.frontend.actions.base.BaseGitMacheteRepositoryReadyAction#onUpdate
.Naive (maybe correct?) solution: instead of relying on constructs like
anActionEvent.getData(DataKeys.GIT_MACHETE_REPOSITORY_SNAPSHOT)
, instead usecom.virtuslab.gitmachete.frontend.ui.services.GraphTableService
? and then usegetGitMacheteRepositorySnapshot()
on the graph table instance?