Skip to content

Commit 922a243

Browse files
author
Vitaliy
authored
Merge branch '2.0.0-develop' into 212-issues
2 parents 7bb2777 + 657169c commit 922a243

File tree

14 files changed

+749
-18
lines changed

14 files changed

+749
-18
lines changed

build.gradle

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ intellij {
3939
'CSS',
4040
'JavaScriptLanguage',
4141
'com.intellij.lang.jsgraphql:2.3.0',
42-
'platform-images'
42+
'platform-images',
43+
'copyright'
4344
]
4445
updateSinceUntilBuild false
4546
sameSinceUntilBuild false

resources/META-INF/plugin.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
<depends>JavaScript</depends>
3636
<depends>com.intellij.modules.platform</depends>
3737
<depends>com.intellij.platform.images</depends>
38+
<depends>com.intellij.copyright</depends>
3839
<depends optional="true" config-file="withJsGraphQl.xml">com.intellij.lang.jsgraphql</depends>
3940

4041
<actions>
@@ -85,6 +86,9 @@
8586
<action id="InjectAViewModelAction.Menu" class="com.magento.idea.magento2plugin.actions.generation.InjectAViewModelAction">
8687
<add-to-group group-id="EditorPopupMenu"/>
8788
</action>
89+
<action id="OverrideInTheme.Menu" class="com.magento.idea.magento2plugin.actions.generation.OverrideInThemeAction">
90+
<add-to-group group-id="ProjectViewPopupMenu"/>
91+
</action>
8892

8993
</actions>
9094

resources/magento2/common.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ common.optionDescription=Option Description
1919
common.cancel=Cancel
2020
common.error=Error
2121
common.module.target=Target Module
22+
common.theme.target=Target Theme
2223
common.area.target=Target Area
2324
common.name=Name
2425
common.className=Class Name
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
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.openapi.actionSystem.AnActionEvent;
9+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
10+
import com.intellij.openapi.project.DumbAwareAction;
11+
import com.intellij.openapi.project.Project;
12+
import com.intellij.openapi.vfs.VirtualFile;
13+
import com.intellij.psi.PsiFile;
14+
import com.magento.idea.magento2plugin.MagentoIcons;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.OverrideInThemeDialog;
16+
import com.magento.idea.magento2plugin.magento.packages.ComponentType;
17+
import com.magento.idea.magento2plugin.magento.packages.Package;
18+
import com.magento.idea.magento2plugin.project.Settings;
19+
import com.magento.idea.magento2plugin.util.magento.GetComponentNameByDirectoryUtil;
20+
import com.magento.idea.magento2plugin.util.magento.GetComponentTypeByNameUtil;
21+
import org.jetbrains.annotations.NotNull;
22+
23+
public class OverrideInThemeAction extends DumbAwareAction {
24+
public static String actionName = "Override in theme...";
25+
public static String actionDescription = "Override template in project theme.";
26+
private PsiFile psiFile;
27+
28+
public OverrideInThemeAction() {
29+
super(actionName, actionDescription, MagentoIcons.MODULE);
30+
}
31+
32+
/**
33+
* Action entry point.
34+
*
35+
* @param event AnActionEvent
36+
*/
37+
public void update(final @NotNull AnActionEvent event) {
38+
boolean status = false;
39+
final Project project = event.getData(PlatformDataKeys.PROJECT);
40+
psiFile = event.getData(PlatformDataKeys.PSI_FILE);
41+
42+
if (Settings.isEnabled(project)) {
43+
try {
44+
status = isOverrideAllowed(
45+
psiFile.getVirtualFile(),
46+
project
47+
);
48+
} catch (NullPointerException e) { //NOPMD
49+
// Ignore
50+
}
51+
}
52+
53+
this.setStatus(event, status);
54+
}
55+
56+
private boolean isOverrideAllowed(final VirtualFile file, final Project project) {
57+
if (file.isDirectory()) {
58+
return false;
59+
}
60+
61+
boolean isAllowed = false;
62+
63+
final String componentType = GetComponentTypeByNameUtil.execute(
64+
GetComponentNameByDirectoryUtil.execute(psiFile.getContainingDirectory(), project)
65+
);
66+
67+
if (componentType.equals(ComponentType.module.toString())) {
68+
isAllowed = file.getPath().contains(Package.moduleViewDir);
69+
} else if (componentType.equals(ComponentType.theme.toString())) {
70+
isAllowed = true;
71+
}
72+
73+
return isAllowed;
74+
}
75+
76+
private void setStatus(final AnActionEvent event, final boolean status) {
77+
event.getPresentation().setVisible(status);
78+
event.getPresentation().setEnabled(status);
79+
}
80+
81+
@Override
82+
public void actionPerformed(final @NotNull AnActionEvent event) {
83+
OverrideInThemeDialog.open(event.getProject(), this.psiFile);
84+
}
85+
86+
@Override
87+
public boolean isDumbAware() {
88+
return false;
89+
}
90+
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.actions.generation.dialog.OverrideInThemeDialog">
3+
<grid id="cbd77" binding="contentPane" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
4+
<margin top="10" left="10" bottom="10" right="10"/>
5+
<constraints>
6+
<xy x="48" y="392" width="584" height="162"/>
7+
</constraints>
8+
<properties>
9+
<minimumSize width="350" height="150"/>
10+
<preferredSize width="350" height="150"/>
11+
<requestFocusEnabled value="true"/>
12+
</properties>
13+
<border type="none"/>
14+
<children>
15+
<grid id="94766" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
16+
<margin top="0" left="0" bottom="0" right="0"/>
17+
<constraints>
18+
<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"/>
19+
</constraints>
20+
<properties/>
21+
<border type="none"/>
22+
<children>
23+
<hspacer id="98af6">
24+
<constraints>
25+
<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"/>
26+
</constraints>
27+
</hspacer>
28+
<grid id="9538f" layout-manager="GridLayoutManager" row-count="1" column-count="2" same-size-horizontally="true" same-size-vertically="false" hgap="-1" vgap="-1">
29+
<margin top="0" left="0" bottom="0" right="0"/>
30+
<constraints>
31+
<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"/>
32+
</constraints>
33+
<properties/>
34+
<border type="none"/>
35+
<children>
36+
<component id="e7465" class="javax.swing.JButton" binding="buttonOK">
37+
<constraints>
38+
<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"/>
39+
</constraints>
40+
<properties>
41+
<text resource-bundle="magento2/common" key="common.ok"/>
42+
</properties>
43+
</component>
44+
<component id="5723f" class="javax.swing.JButton" binding="buttonCancel">
45+
<constraints>
46+
<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"/>
47+
</constraints>
48+
<properties>
49+
<text resource-bundle="magento2/common" key="common.cancel"/>
50+
</properties>
51+
</component>
52+
</children>
53+
</grid>
54+
</children>
55+
</grid>
56+
<grid id="e3588" layout-manager="GridLayoutManager" row-count="2" column-count="1" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
57+
<margin top="0" left="0" bottom="0" right="0"/>
58+
<constraints>
59+
<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"/>
60+
</constraints>
61+
<properties/>
62+
<border type="none"/>
63+
<children>
64+
<component id="5196a" class="javax.swing.JLabel" binding="selectTheme">
65+
<constraints>
66+
<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">
67+
<preferred-size width="319" height="16"/>
68+
</grid>
69+
</constraints>
70+
<properties>
71+
<labelFor value=""/>
72+
<text resource-bundle="magento2/common" key="common.theme.target"/>
73+
</properties>
74+
</component>
75+
<component id="bd654" class="com.magento.idea.magento2plugin.ui.FilteredComboBox" binding="theme" custom-create="true">
76+
<constraints>
77+
<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">
78+
<preferred-size width="319" height="30"/>
79+
</grid>
80+
</constraints>
81+
<properties/>
82+
</component>
83+
</children>
84+
</grid>
85+
</children>
86+
</grid>
87+
</form>
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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.dialog;
7+
8+
import com.intellij.openapi.project.Project;
9+
import com.intellij.openapi.ui.popup.JBPopupFactory;
10+
import com.intellij.psi.PsiFile;
11+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.OverrideInThemeDialogValidator;
12+
import com.magento.idea.magento2plugin.actions.generation.generator.OverrideInThemeGenerator;
13+
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
14+
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
15+
import java.awt.event.ActionEvent;
16+
import java.awt.event.ActionListener;
17+
import java.awt.event.KeyEvent;
18+
import java.awt.event.WindowAdapter;
19+
import java.awt.event.WindowEvent;
20+
import java.util.List;
21+
import javax.swing.JButton;
22+
import javax.swing.JComponent;
23+
import javax.swing.JLabel;
24+
import javax.swing.JPanel;
25+
import javax.swing.KeyStroke;
26+
import org.jetbrains.annotations.NotNull;
27+
28+
public class OverrideInThemeDialog extends AbstractDialog {
29+
@NotNull
30+
private final Project project;
31+
private final PsiFile psiFile;
32+
@NotNull
33+
private final OverrideInThemeDialogValidator validator;
34+
private JPanel contentPane;
35+
private JButton buttonOK;
36+
private JButton buttonCancel;
37+
private JLabel selectTheme; //NOPMD
38+
private FilteredComboBox theme;
39+
40+
/**
41+
* Constructor.
42+
*
43+
* @param project Project
44+
* @param psiFile PsiFile
45+
*/
46+
public OverrideInThemeDialog(final @NotNull Project project, final PsiFile psiFile) {
47+
super();
48+
49+
this.project = project;
50+
this.psiFile = psiFile;
51+
this.validator = new OverrideInThemeDialogValidator(this);
52+
53+
setContentPane(contentPane);
54+
setModal(true);
55+
getRootPane().setDefaultButton(buttonOK);
56+
57+
buttonOK.addActionListener(new ActionListener() {
58+
public void actionPerformed(final ActionEvent event) {
59+
onOK(); //NOPMD
60+
}
61+
});
62+
63+
buttonCancel.addActionListener(new ActionListener() {
64+
public void actionPerformed(final ActionEvent event) {
65+
onCancel();
66+
}
67+
});
68+
69+
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
70+
addWindowListener(new WindowAdapter() {
71+
public void windowClosing(final WindowEvent event) {
72+
onCancel();
73+
}
74+
});
75+
76+
contentPane.registerKeyboardAction(new ActionListener() {
77+
public void actionPerformed(final ActionEvent event) {
78+
onCancel();
79+
}
80+
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
81+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
82+
}
83+
84+
private void onOK() {
85+
if (!validator.validate(project)) {
86+
JBPopupFactory.getInstance().createMessage("Invalid theme selection.")
87+
.showCenteredInCurrentWindow(project);
88+
return;
89+
}
90+
91+
final OverrideInThemeGenerator overrideInThemeGenerator =
92+
new OverrideInThemeGenerator(project);
93+
overrideInThemeGenerator.execute(psiFile, this.getTheme());
94+
95+
this.setVisible(false);
96+
}
97+
98+
public String getTheme() {
99+
return this.theme.getSelectedItem().toString();
100+
}
101+
102+
/**
103+
* Open popup.
104+
*
105+
* @param project Project
106+
* @param psiFile PsiFile
107+
*/
108+
public static void open(final @NotNull Project project, final PsiFile psiFile) {
109+
final OverrideInThemeDialog dialog = new OverrideInThemeDialog(project, psiFile);
110+
dialog.pack();
111+
dialog.centerDialog(dialog);
112+
dialog.setVisible(true);
113+
}
114+
115+
private void createUIComponents() { //NOPMD
116+
final List<String> allThemesList = ModuleIndex.getInstance(project).getEditableThemeNames();
117+
118+
this.theme = new FilteredComboBox(allThemesList);
119+
}
120+
}

0 commit comments

Comments
 (0)