Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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);
Expand Down Expand Up @@ -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<String> allModulesList = new ModuleIndex(project).getEditableModuleNames();

return allModulesList.contains(
GetModuleNameByDirectoryUtil.execute(psiFile.getContainingDirectory(), project)
);
}
}