diff --git a/src/com/magento/idea/magento2plugin/actions/generation/InjectAViewModelAction.java b/src/com/magento/idea/magento2plugin/actions/generation/InjectAViewModelAction.java index 682f50b04..a3635f2e8 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/InjectAViewModelAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/InjectAViewModelAction.java @@ -16,9 +16,12 @@ import com.intellij.psi.xml.XmlTag; import com.magento.idea.magento2plugin.MagentoIcons; import com.magento.idea.magento2plugin.actions.generation.dialog.InjectAViewModelDialog; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; import com.magento.idea.magento2plugin.magento.files.CommonXml; import com.magento.idea.magento2plugin.magento.files.LayoutXml; import com.magento.idea.magento2plugin.project.Settings; +import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import java.util.List; import org.jetbrains.annotations.NotNull; public class InjectAViewModelAction extends DumbAwareAction { @@ -42,6 +45,15 @@ public void update(final @NotNull AnActionEvent event) { if (project == null) { return; } + final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE); + + if (psiFile == null) { + return; + } + + if (!isEditableModule(project, psiFile)) { + return; + } if (Settings.isEnabled(project)) { final XmlTag element = getElement(event); @@ -128,4 +140,12 @@ private void setStatus(final AnActionEvent event, final boolean status) { event.getPresentation().setVisible(status); event.getPresentation().setEnabled(status); } + + private boolean isEditableModule(final Project project, final PsiFile psiFile) { + final List allModulesList = new ModuleIndex(project).getEditableModuleNames(); + + return allModulesList.contains( + GetModuleNameByDirectoryUtil.execute(psiFile.getContainingDirectory(), project) + ); + } }