Add basic querysync support for BlazeProjectAction.
Allow subclasses to indicate if they support querysync. Current default is that none of them do.
*/
package com.google.idea.blaze.base.actions;
+import static com.google.idea.blaze.base.actions.BlazeProjectAction.QuerySyncStatus.HIDDEN;
+import static com.google.idea.blaze.base.actions.BlazeProjectAction.QuerySyncStatus.SUPPORTED;
+
import com.google.idea.blaze.base.qsync.QuerySync;
import com.google.idea.blaze.base.settings.Blaze;
import com.google.idea.blaze.base.settings.BuildSystemName;
@@ -26,6 +29,22 @@ import javax.swing.Icon;
/** Base class action that hides for non-blaze projects. */
public abstract class BlazeProjectAction extends AnAction {
+ /** Indicates if an action supports querysync. */
+ enum QuerySyncStatus {
+ /**
+ * The action does not support querysync, and is not ever expected to. It's not visible in the
+ * UI.
+ */
+ HIDDEN,
+ /**
+ * The action may support querysync in future, but does not yet. It is visible in the UI, but
+ * disabled.
+ */
+ DISABLED,
+ /** The action supports querysync and is available in the UI. */
+ SUPPORTED,
+ }
+
protected BlazeProjectAction() {}
protected BlazeProjectAction(Icon icon) {
@@ -48,6 +67,10 @@ public abstract class BlazeProjectAction extends AnAction {
e.getPresentation().setEnabledAndVisible(false);
return;
}
+ if (QuerySync.isEnabled() && querySyncSupport() == HIDDEN) {
+ e.getPresentation().setEnabledAndVisible(false);
+ return;
+ }
e.getPresentation().setEnabledAndVisible(true);
@@ -55,7 +78,7 @@ public abstract class BlazeProjectAction extends AnAction {
e.getPresentation().setEnabled(false);
return;
}
- if (QuerySync.isEnabled()) {
+ if (QuerySync.isEnabled() && querySyncSupport() != SUPPORTED) {
// TODO(b/260643753) disabling all blaze actions for querysync is way too broad, instead we
// should investigate which can be supported and update them accordingly.
e.getPresentation().setEnabled(false);
@@ -74,6 +97,11 @@ public abstract class BlazeProjectAction extends AnAction {
actionPerformedInBlazeProject(project, anActionEvent);
}
+ protected QuerySyncStatus querySyncSupport() {
+ // Default to disabled, meaning that the action has not yet been updated for querysync.
+ return QuerySyncStatus.DISABLED;
+ }
+
protected void updateForBlazeProject(Project project, AnActionEvent e) {}
protected abstract void actionPerformedInBlazeProject(Project project, AnActionEvent e);
