VirtusLab / git-machete-intellij-plugin

Probably the sharpest git repository organizer & rebase/merge workflow automation tool you've ever seen
MIT License
134 stars 16 forks source link

Keyboard shortcuts for actions only work when Git Machete tool window is open #1445

Open PawelLipski opened 1 year ago

PawelLipski commented 1 year ago

Otherwise, the DataContext passed in ActionEvent points to IdeFrameImpl, not to our own com.virtuslab.gitmachete.frontend.ui.impl.table.EnhancedGraphTable, and hence the things like GitMacheteRepositorySnapshot aren't available to the action, which then gets disabled via com.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 use com.virtuslab.gitmachete.frontend.ui.services.GraphTableService? and then use getGitMacheteRepositorySnapshot() on the graph table instance?

PawelLipski commented 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");
     }
PawelLipski commented 1 year ago

But there are other things to be considered: