|
| 1 | +/* |
| 2 | + * Copyright © Magento, Inc. All rights reserved. |
| 3 | + * See COPYING.txt for license details. |
| 4 | + */ |
| 5 | + |
| 6 | +package com.magento.idea.magento2plugin.actions.generation; |
| 7 | + |
| 8 | +import com.intellij.ide.IdeView; |
| 9 | +import com.intellij.openapi.actionSystem.AnAction; |
| 10 | +import com.intellij.openapi.actionSystem.AnActionEvent; |
| 11 | +import com.intellij.openapi.actionSystem.CommonDataKeys; |
| 12 | +import com.intellij.openapi.actionSystem.DataContext; |
| 13 | +import com.intellij.openapi.actionSystem.LangDataKeys; |
| 14 | +import com.intellij.openapi.project.Project; |
| 15 | +import com.intellij.psi.PsiDirectory; |
| 16 | +import com.magento.idea.magento2plugin.MagentoIcons; |
| 17 | +import com.magento.idea.magento2plugin.actions.generation.dialog.NewEmailTemplateDialog; |
| 18 | + |
| 19 | +@SuppressWarnings({"PMD.OnlyOneReturn", "PMD.FieldNamingConventions"}) |
| 20 | +public class NewEmailTemplateAction extends AnAction { |
| 21 | + public static final String ACTION_NAME = "Magento 2 Email Template"; |
| 22 | + public static final String ACTION_DESCRIPTION = "Create a new Magento 2 email template"; |
| 23 | + |
| 24 | + /** |
| 25 | + * New email template action constructor. |
| 26 | + */ |
| 27 | + public NewEmailTemplateAction() { |
| 28 | + super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); |
| 29 | + } |
| 30 | + |
| 31 | + @Override |
| 32 | + public void actionPerformed(final AnActionEvent event) { |
| 33 | + final DataContext dataContext = event.getDataContext(); |
| 34 | + final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext); |
| 35 | + |
| 36 | + if (view == null) { |
| 37 | + return; |
| 38 | + } |
| 39 | + |
| 40 | + final Project project = CommonDataKeys.PROJECT.getData(dataContext); |
| 41 | + if (project == null) { |
| 42 | + return; |
| 43 | + } |
| 44 | + |
| 45 | + final PsiDirectory directory = view.getOrChooseDirectory(); |
| 46 | + if (directory == null) { |
| 47 | + return; |
| 48 | + } |
| 49 | + |
| 50 | + NewEmailTemplateDialog.open(project, directory); |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public boolean isDumbAware() { |
| 55 | + return false; |
| 56 | + } |
| 57 | +} |
0 commit comments