Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1204: Fixed bug View Model can be created in the vendor #1229

Open
wants to merge 4 commits into
base: 5.1.0-develop
Choose a base branch
from
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)
);
}
}