Skip to content

Commit 4dc4a3c

Browse files
authored
Merge branch '2.1.0-develop' into issue-131
2 parents 670fc35 + a61d897 commit 4dc4a3c

35 files changed

+340
-191
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td><font face="verdana" size="-1">Magento layout can be used for customizing a specific page or group of pages
12+
in frontend or admin area of Magento 2. The common customization tasks include changing page layout, adding
13+
new magento blocks, removing magento blocks etc. For more information refer
14+
<a href="https://devdocs.magento.com/guides/v2.4/frontend-dev-guide/layouts/layout-overview.html">
15+
layout overview docs
16+
</a>
17+
</font><br>
18+
</td>
19+
</tr>
20+
</table>
21+
</body>
22+
</html>

resources/magento2/common.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ common.license.proprietary=Proprietary
4242
common.description=Description
4343
common.parentDirectory=Parent Directory
4444
common.cliCommandName=Command Name
45-
common.cli.create.new.cli.command.title=Create a new Magento 2 CLI Command
4645
common.cli.generate.error=New CLI Command Generation Error
4746
common.cli.class.title=CLI Command Class
4847
common.validationErrorTitle=Validation Error

src/com/magento/idea/magento2plugin/actions/generation/CreateAPluginAction.java

Lines changed: 43 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation;
67

78
import com.intellij.openapi.actionSystem.AnActionEvent;
@@ -17,37 +18,44 @@
1718
import com.jetbrains.php.lang.psi.elements.PhpClass;
1819
import com.magento.idea.magento2plugin.MagentoIcons;
1920
import com.magento.idea.magento2plugin.actions.generation.dialog.CreateAPluginDialog;
21+
import com.magento.idea.magento2plugin.project.Settings;
2022
import com.magento.idea.magento2plugin.util.GetFirstClassOfFile;
2123
import com.magento.idea.magento2plugin.util.magento.plugin.IsPluginAllowedForMethod;
2224
import org.jetbrains.annotations.NotNull;
23-
import com.magento.idea.magento2plugin.project.Settings;
2425

2526
public class CreateAPluginAction extends DumbAwareAction {
26-
public static String ACTION_NAME = "Create a Plugin...";
27-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 plugin for the class";
28-
private final IsPluginAllowedForMethod isPluginAllowed;
27+
public static final String ACTION_NAME = "Create a new Plugin for this method";
28+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Plugin";
29+
private final IsPluginAllowedForMethod isPluginAllowed;// NOPMD
2930
private final GetFirstClassOfFile getFirstClassOfFile;
3031
private Method targetMethod;
3132
private PhpClass targetClass;
3233

34+
/**
35+
* Constructor.
36+
*/
3337
public CreateAPluginAction() {
3438
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
3539
this.isPluginAllowed = IsPluginAllowedForMethod.getInstance();
3640
this.getFirstClassOfFile = GetFirstClassOfFile.getInstance();
3741
}
3842

39-
public void update(AnActionEvent event) {
40-
targetClass = null;
41-
targetMethod = null;
42-
Project project = event.getData(PlatformDataKeys.PROJECT);
43+
/**
44+
* Updates the state of action.
45+
*/
46+
@Override
47+
public void update(final AnActionEvent event) {
48+
targetClass = null;// NOPMD
49+
targetMethod = null;// NOPMD
50+
final Project project = event.getData(PlatformDataKeys.PROJECT);
4351
if (Settings.isEnabled(project)) {
44-
Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
45-
PsiFile psiFile = pair.getFirst();
46-
PhpClass phpClass = pair.getSecond();
47-
if ((phpClass == null || psiFile == null)
48-
|| !(psiFile instanceof PhpFile)
49-
|| phpClass.isFinal()
50-
|| this.targetMethod == null
52+
final Pair<PsiFile, PhpClass> pair = this.findPhpClass(event);
53+
final PsiFile psiFile = pair.getFirst();
54+
final PhpClass phpClass = pair.getSecond();
55+
if (phpClass == null
56+
|| !(psiFile instanceof PhpFile)
57+
|| phpClass.isFinal()
58+
|| this.targetMethod == null
5159
) {
5260
this.setStatus(event, false);
5361
return;
@@ -60,23 +68,23 @@ public void update(AnActionEvent event) {
6068
this.setStatus(event, false);
6169
}
6270

63-
private void setStatus(AnActionEvent event, boolean status) {
71+
private void setStatus(final AnActionEvent event, final boolean status) {
6472
event.getPresentation().setVisible(status);
6573
event.getPresentation().setEnabled(status);
6674
}
6775

6876
@Override
69-
public void actionPerformed(@NotNull AnActionEvent e) {
70-
CreateAPluginDialog.open(e.getProject(), this.targetMethod, this.targetClass);
77+
public void actionPerformed(@NotNull final AnActionEvent event) {
78+
CreateAPluginDialog.open(event.getProject(), this.targetMethod, this.targetClass);
7179
}
7280

7381
@Override
7482
public boolean isDumbAware() {
7583
return false;
7684
}
7785

78-
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull AnActionEvent event) {
79-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
86+
private Pair<PsiFile, PhpClass> findPhpClass(@NotNull final AnActionEvent event) {
87+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
8088

8189
PhpClass phpClass = null;
8290
if (psiFile instanceof PhpFile) {
@@ -87,23 +95,29 @@ private Pair<PsiFile, PhpClass> findPhpClass(@NotNull AnActionEvent event) {
8795
return Pair.create(psiFile, phpClass);
8896
}
8997

90-
private void fetchTargetMethod(@NotNull AnActionEvent event, PsiFile psiFile, PhpClass phpClass) {
91-
Caret caret = event.getData(PlatformDataKeys.CARET);
98+
private void fetchTargetMethod(
99+
@NotNull final AnActionEvent event,
100+
final PsiFile psiFile,
101+
final PhpClass phpClass
102+
) {
103+
final Caret caret = event.getData(PlatformDataKeys.CARET);
92104
if (caret == null) {
93105
return;
94106
}
95-
int offset = caret.getOffset();
96-
PsiElement element = psiFile.findElementAt(offset);
107+
final int offset = caret.getOffset();
108+
final PsiElement element = psiFile.findElementAt(offset);
97109
if (element == null) {
98110
return;
99111
}
100-
if (element instanceof Method && element.getParent() == phpClass && isPluginAllowed.check((Method)element)) {
101-
this.targetMethod = (Method)element;
112+
if (element instanceof Method && element.getParent()
113+
== phpClass && isPluginAllowed.check((Method) element)) {
114+
this.targetMethod = (Method) element;
102115
return;
103116
}
104-
PsiElement parent = element.getParent();
105-
if (parent instanceof Method && parent.getParent() == phpClass && isPluginAllowed.check((Method)parent)) {
106-
this.targetMethod = (Method)parent;
117+
final PsiElement parent = element.getParent();
118+
if (parent instanceof Method && parent.getParent()
119+
== phpClass && isPluginAllowed.check((Method) parent)) {
120+
this.targetMethod = (Method) parent;
107121
}
108122
}
109123
}

src/com/magento/idea/magento2plugin/actions/generation/CreateAnObserverAction.java

Lines changed: 40 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation;
67

78
import com.intellij.lang.ASTNode;
@@ -27,27 +28,31 @@
2728
import org.jetbrains.annotations.NotNull;
2829

2930
public class CreateAnObserverAction extends DumbAwareAction {
30-
public static final String ACTION_NAME = "Create a Magento Observer...";
31-
static final String ACTION_DESCRIPTION = "Create a new Magento 2 Observer for the event";
31+
public static final String ACTION_NAME = "Create a new Observer for this event";
32+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Observer";
3233
public String targetEvent;
3334

3435
public CreateAnObserverAction() {
3536
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
3637
}
3738

38-
public void update(AnActionEvent event) {
39-
Project project = event.getData(PlatformDataKeys.PROJECT);
39+
/**
40+
* Updates the state of action.
41+
*/
42+
@Override
43+
public void update(final AnActionEvent event) {
44+
final Project project = event.getData(PlatformDataKeys.PROJECT);
4045
if (!Settings.isEnabled(project)) {
4146
this.setStatus(event, false);
4247
return;
4348
}
44-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
49+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
4550
if (!(psiFile instanceof PhpFile)) {
4651
this.setStatus(event, false);
4752
return;
4853
}
4954

50-
PsiElement element = getElement(event);
55+
final PsiElement element = getElement(event);
5156
if (element == null) {
5257
this.setStatus(event, false);
5358
return;
@@ -62,87 +67,76 @@ public void update(AnActionEvent event) {
6267
this.setStatus(event, false);
6368
}
6469

65-
private PsiElement getElement(@NotNull AnActionEvent event) {
66-
Caret caret = event.getData(PlatformDataKeys.CARET);
67-
PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
70+
private PsiElement getElement(@NotNull final AnActionEvent event) {
71+
final Caret caret = event.getData(PlatformDataKeys.CARET);
6872
if (caret == null) {
6973
return null;
7074
}
71-
int offset = caret.getOffset();
72-
PsiElement element = psiFile.findElementAt(offset);
75+
final int offset = caret.getOffset();
76+
final PsiFile psiFile = event.getData(PlatformDataKeys.PSI_FILE);
77+
final PsiElement element = psiFile.findElementAt(offset);
7378
if (element == null) {
7479
return null;
7580
}
7681
return element;
7782
}
7883

79-
private boolean isObserverEventNameClicked(@NotNull PsiElement element) {
80-
if (checkIsElementStringLiteral(element)) {
81-
if (checkIsParametersList(element.getParent().getParent()) &&
82-
checkIsMethodReference(element.getParent().getParent().getParent()) &&
83-
checkIsEventDispatchMethod((MethodReference) element.getParent().getParent().getParent())) {
84-
return true;
85-
}
86-
}
87-
return false;
84+
private boolean isObserverEventNameClicked(@NotNull final PsiElement element) {
85+
return checkIsElementStringLiteral(element)
86+
&& checkIsParametersList(element.getParent().getParent())
87+
&& checkIsMethodReference(element.getParent().getParent().getParent())
88+
&& checkIsEventDispatchMethod(
89+
(MethodReference) element.getParent().getParent().getParent()
90+
);
8891
}
8992

90-
private boolean checkIsParametersList(@NotNull PsiElement element) {
91-
if (element instanceof ParameterList) {
92-
return true;
93-
}
94-
return false;
93+
private boolean checkIsParametersList(@NotNull final PsiElement element) {
94+
return element instanceof ParameterList;
9595
}
9696

97-
private boolean checkIsMethodReference(@NotNull PsiElement element) {
98-
if (element instanceof MethodReference) {
99-
return true;
100-
}
101-
return false;
97+
private boolean checkIsMethodReference(@NotNull final PsiElement element) {
98+
return element instanceof MethodReference;
10299
}
103100

104-
private boolean checkIsEventDispatchMethod(MethodReference element) {
105-
PsiReference elementReference = element.getReference();
101+
private boolean checkIsEventDispatchMethod(final MethodReference element) {
102+
final PsiReference elementReference = element.getReference();
106103
if (elementReference == null) {
107104
return false;
108105
}
109-
PsiElement method = elementReference.resolve();
106+
final PsiElement method = elementReference.resolve();
110107
if (!(method instanceof Method)) {
111108
return false;
112109
}
113110
if (!((Method) method).getName().equals(Observer.DISPATCH_METHOD)) {
114111
return false;
115112
}
116-
PsiElement phpClass = method.getParent();
113+
final PsiElement phpClass = method.getParent();
117114
if (!(phpClass instanceof PhpClass)) {
118115
return false;
119116
}
120-
String fqn = ((PhpClass) phpClass).getPresentableFQN();
117+
final String fqn = ((PhpClass) phpClass).getPresentableFQN();
121118
return fqn.equals(Observer.INTERFACE);
122119
}
123120

124-
private boolean checkIsElementStringLiteral(@NotNull PsiElement element) {
125-
ASTNode astNode = element.getNode();
121+
private boolean checkIsElementStringLiteral(@NotNull final PsiElement element) {
122+
final ASTNode astNode = element.getNode();
126123
if (astNode == null) {
127124
return false;
128125
}
129-
IElementType elementType = astNode.getElementType();
130-
131-
if (elementType != PhpTokenTypes.STRING_LITERAL && elementType != PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE) {
132-
return false;
133-
}
126+
final IElementType elementType = astNode.getElementType();
134127

135-
return true;
128+
return elementType == PhpTokenTypes.STRING_LITERAL
129+
|| elementType == PhpTokenTypes.STRING_LITERAL_SINGLE_QUOTE;
136130
}
137131

138-
private void setStatus(AnActionEvent event, boolean status) {
132+
private void setStatus(final AnActionEvent event, final boolean status) {
139133
event.getPresentation().setVisible(status);
140134
event.getPresentation().setEnabled(status);
141135
}
142136

143137
@Override
144-
public void actionPerformed(@NotNull AnActionEvent e) {
145-
CreateAnObserverDialog.open(e.getProject(), this.targetEvent);
138+
public void actionPerformed(@NotNull final AnActionEvent event) {
139+
CreateAnObserverDialog.open(event.getProject(), this.targetEvent);
146140
}
147141

148142
@Override

src/com/magento/idea/magento2plugin/actions/generation/InjectAViewModelAction.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
import org.jetbrains.annotations.NotNull;
2323

2424
public class InjectAViewModelAction extends DumbAwareAction {
25-
public static String actionName = "Inject a View Model...";
26-
public static String actionDescription = "Inject a View Model as an argument of block";
25+
public static String actionName = "Inject a new View Model for this block";
26+
public static String actionDescription = "Inject a new Magento 2 View Model";
2727
private XmlTag targetXmlTag;
2828

2929
public InjectAViewModelAction() {

src/com/magento/idea/magento2plugin/actions/generation/NewBlockAction.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,43 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation;
67

78
import com.intellij.ide.IdeView;
8-
import com.intellij.openapi.actionSystem.*;
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;
914
import com.intellij.openapi.project.Project;
1015
import com.intellij.psi.PsiDirectory;
1116
import com.magento.idea.magento2plugin.MagentoIcons;
1217
import com.magento.idea.magento2plugin.actions.generation.dialog.NewBlockDialog;
1318
import org.jetbrains.annotations.NotNull;
1419

1520
public class NewBlockAction extends AnAction {
16-
public static String ACTION_NAME = "Magento 2 Block";
17-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 block";
21+
public static final String ACTION_NAME = "Magento 2 Block";
22+
public static final String ACTION_DESCRIPTION = "Create a new Magento 2 Block";
1823

19-
NewBlockAction() {
24+
public NewBlockAction() {
2025
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
2126
}
2227

2328
@Override
24-
public void actionPerformed(@NotNull AnActionEvent e) {
25-
DataContext dataContext = e.getDataContext();
26-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
29+
public void actionPerformed(@NotNull final AnActionEvent event) {
30+
final DataContext dataContext = event.getDataContext();
31+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
2732
if (view == null) {
2833
return;
2934
}
3035

31-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
36+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
3237
if (project == null) {
3338
return;
3439
}
3540

36-
PsiDirectory directory = view.getOrChooseDirectory();
41+
final PsiDirectory directory = view.getOrChooseDirectory();
3742
if (directory == null) {
3843
return;
3944
}

0 commit comments

Comments
 (0)