-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
966 add context action to create layout xml file
- Loading branch information
silinmykola
committed
Mar 7, 2022
1 parent
e4be0b9
commit c4f5568
Showing
15 changed files
with
708 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
src/com/magento/idea/magento2plugin/actions/context/xml/NewLayoutXmlAction.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.actions.context.xml; | ||
|
||
import com.intellij.ide.fileTemplates.actions.AttributesDefaults; | ||
import com.intellij.openapi.actionSystem.AnAction; | ||
import com.intellij.openapi.actionSystem.AnActionEvent; | ||
import com.intellij.openapi.actionSystem.DataContext; | ||
import com.intellij.openapi.actionSystem.LangDataKeys; | ||
import com.intellij.openapi.project.Project; | ||
import com.intellij.psi.PsiDirectory; | ||
import com.intellij.psi.PsiElement; | ||
import com.intellij.psi.PsiFile; | ||
import com.magento.idea.magento2plugin.MagentoIcons; | ||
import com.magento.idea.magento2plugin.actions.generation.dialog.NewLayoutTemplateDialog; | ||
import com.magento.idea.magento2plugin.magento.packages.Areas; | ||
import com.magento.idea.magento2plugin.magento.packages.ComponentType; | ||
import com.magento.idea.magento2plugin.magento.packages.Package; | ||
import com.magento.idea.magento2plugin.project.Settings; | ||
import com.magento.idea.magento2plugin.util.magento.GetMagentoModuleUtil; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class NewLayoutXmlAction extends AnAction { | ||
|
||
public static final String ACTION_NAME = "Magento 2 Layout File"; | ||
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 layout.xml file"; | ||
private PsiDirectory targetDirectory; | ||
|
||
/** | ||
* New layout.xml file generation action constructor. | ||
*/ | ||
public NewLayoutXmlAction() { | ||
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE); | ||
} | ||
|
||
@Override | ||
public void update(final @NotNull AnActionEvent event) { | ||
setIsAvailableForEvent(event, false); | ||
final Project project = event.getProject(); | ||
|
||
if (project == null || !Settings.isEnabled(project)) { | ||
return; | ||
} | ||
final DataContext context = event.getDataContext(); | ||
final PsiElement targetElement = LangDataKeys.PSI_ELEMENT.getData(context); | ||
|
||
if (!(targetElement instanceof PsiDirectory)) { | ||
return; | ||
} | ||
final PsiDirectory targetDirectoryCandidate = (PsiDirectory) targetElement; | ||
final GetMagentoModuleUtil.MagentoModuleData moduleData = GetMagentoModuleUtil | ||
.getByContext(targetDirectoryCandidate, project); | ||
|
||
if (moduleData == null) { | ||
return; | ||
} | ||
final PsiDirectory viewDir = moduleData.getViewDir(); | ||
|
||
if (viewDir == null) { | ||
return; | ||
} | ||
final List<String> allowedDirectories = Arrays.asList( | ||
Package.moduleViewDir, | ||
Areas.adminhtml.toString(), | ||
Areas.frontend.toString() | ||
); | ||
if (!allowedDirectories.contains(targetDirectoryCandidate.getName()) | ||
|| !moduleData.getType().equals(ComponentType.module)) { | ||
return; | ||
} | ||
final PsiDirectory parentDir = targetDirectoryCandidate.getParentDirectory(); | ||
|
||
if (parentDir == null | ||
|| !targetDirectoryCandidate.equals(viewDir) && !parentDir.equals(viewDir)) { | ||
return; | ||
} | ||
targetDirectory = targetDirectoryCandidate; | ||
setIsAvailableForEvent(event, true); | ||
} | ||
|
||
@Override | ||
public void actionPerformed(final @NotNull AnActionEvent event) { | ||
if (event.getProject() == null || targetDirectory == null) { | ||
return; | ||
} | ||
|
||
NewLayoutTemplateDialog.open(event.getProject(), targetDirectory); | ||
} | ||
|
||
/** | ||
* Set is action available for event. | ||
* | ||
* @param event AnActionEvent | ||
* @param isAvailable boolean | ||
*/ | ||
private void setIsAvailableForEvent( | ||
final @NotNull AnActionEvent event, | ||
final boolean isAvailable | ||
) { | ||
event.getPresentation().setVisible(isAvailable); | ||
event.getPresentation().setEnabled(isAvailable); | ||
} | ||
|
||
protected AttributesDefaults getProperties( | ||
final @NotNull AttributesDefaults defaults, | ||
final @NotNull GetMagentoModuleUtil.MagentoModuleData moduleData, | ||
final PsiDirectory targetDirectory, | ||
final PsiFile targetFile | ||
) { | ||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
src/com/magento/idea/magento2plugin/actions/generation/dialog/NewLayoutTemplateDialog.form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.NewLayoutTemplateDialog"> | ||
<grid id="7afc" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="10" left="10" bottom="10" right="10"/> | ||
<constraints> | ||
<xy x="136" y="92" width="545" height="340"/> | ||
</constraints> | ||
<properties> | ||
<preferredSize width="360" height="170"/> | ||
</properties> | ||
<border type="none"/> | ||
<children> | ||
<grid id="72800" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<hspacer id="9d205"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="1" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</hspacer> | ||
<grid id="f08e3" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<component id="4f53d" class="javax.swing.JButton" binding="buttonOK"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="OK"/> | ||
</properties> | ||
</component> | ||
<component id="80459" class="javax.swing.JButton" binding="buttonCancel"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Cancel"/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
<grid id="c5548" layout-manager="GridLayoutManager" row-count="4" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1"> | ||
<margin top="0" left="0" bottom="0" right="0"/> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
<border type="none"/> | ||
<children> | ||
<vspacer id="668b9"> | ||
<constraints> | ||
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
</vspacer> | ||
<component id="89b74" class="javax.swing.JComboBox" binding="area" custom-create="true"> | ||
<constraints> | ||
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="2" anchor="8" fill="1" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties/> | ||
</component> | ||
<component id="765fc" class="javax.swing.JLabel" binding="areaLabel"> | ||
<constraints> | ||
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value="Layout Area"/> | ||
</properties> | ||
</component> | ||
<component id="ccfdf" class="javax.swing.JTextField" binding="layoutName"> | ||
<constraints> | ||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"> | ||
<preferred-size width="150" height="-1"/> | ||
</grid> | ||
</constraints> | ||
<properties/> | ||
<clientProperties> | ||
<promptText class="java.lang.String" value="routeId_controller_action"/> | ||
</clientProperties> | ||
</component> | ||
<component id="4cd93" class="javax.swing.JLabel" binding="layoutNameLabel"> | ||
<constraints> | ||
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<labelFor value="ccfdf"/> | ||
<text value="Layout Name"/> | ||
</properties> | ||
</component> | ||
<component id="6cf67" class="javax.swing.JLabel" binding="layoutNameErrorMessage"> | ||
<constraints> | ||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/> | ||
</constraints> | ||
<properties> | ||
<text value=""/> | ||
</properties> | ||
</component> | ||
</children> | ||
</grid> | ||
</children> | ||
</grid> | ||
</form> |
Oops, something went wrong.