Skip to content
Closed
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions resources/META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
<action id="MagentoCreateMenuItem" class="com.magento.idea.magento2plugin.actions.generation.NewMenuItemAction" />
<add-to-group group-id="NewGroup" anchor="last"/>
</group>

Expand Down Expand Up @@ -95,6 +96,7 @@
<psi.referenceContributor language="PHP" implementation="com.magento.idea.magento2plugin.reference.php.PhpReferenceContributor"/>
<psi.referenceContributor language="JavaScript" implementation="com.magento.idea.magento2plugin.reference.js.JsReferenceContributor"/>

<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.AdminMenuIndexer" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.EventObserverIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.EventNameIndex" />
<fileBasedIndex implementation="com.magento.idea.magento2plugin.stubs.indexes.VirtualTypeIndex" />
Expand Down
6 changes: 5 additions & 1 deletion resources/magento2/common.properties
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,8 @@ common.cronGroup.description.scheduleLifetime=Window of time (in minutes) that c
common.cronGroup.description.historyCleanupEvery=Time (in minutes) that cron history is kept in the database.
common.cronGroup.description.historySuccessLifetime=Time (in minutes) that the record of successfully completed cron jobs are kept in the database.
common.cronGroup.description.historyFailureLifetime=Time (in minutes) that the record of failed cron jobs are kept in the database.
common.cronGroup.description.useSeparateProcess=Run this crongroup’s jobs in a separate php process.
common.cronGroup.description.useSeparateProcess=Run this crongroup’s jobs in a separate php process.
common.create.new.menu.item.title=Create a new Magento 2 menu item
common.title=Title
common.action=Action
common.resource=Resource
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation;

import com.intellij.ide.IdeView;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.CommonDataKeys;
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.magento.idea.magento2plugin.MagentoIcons;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewMenuItemDialog;

@SuppressWarnings({"PMD.FieldNamingConventions"})
public class NewMenuItemAction extends AnAction {
public static String ACTION_NAME = "Magento 2 Menu Item";
public static String ACTION_DESCRIPTION = "Create a new Magento 2 Menu Item";

public NewMenuItemAction() {
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
}

@Override
public void actionPerformed(
@org.jetbrains.annotations.NotNull
final AnActionEvent event
) {
final DataContext context = event.getDataContext();
final IdeView view = LangDataKeys.IDE_VIEW.getData(context);
if (view == null) {
return;
}

final Project project = CommonDataKeys.PROJECT.getData(context);
if (project == null) {
return;
}

final PsiDirectory directory = view.getOrChooseDirectory();
if (directory == null) {
return;
}

NewMenuItemDialog.open(project, directory);
}

@Override
public boolean isDumbAware() {
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
<?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.NewMenuItemDialog">
<grid id="27dc6" binding="controlPanel" 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="20" y="20" width="549" height="442"/>
</constraints>
<properties>
<inheritsPopupMenu value="true"/>
<minimumSize width="549" height="442"/>
</properties>
<border type="none"/>
<children>
<grid id="266ab" 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>
<component id="5f7dc" class="javax.swing.JTextField" binding="titleFieldName">
<constraints>
<grid row="0" 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>
<text value=""/>
</properties>
</component>
<component id="801d7" class="javax.swing.JLabel">
<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 resource-bundle="magento2/common" key="common.title"/>
</properties>
</component>
<component id="fc01c" class="javax.swing.JTextField" binding="actionFieldName">
<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/>
</component>
<component id="3c432" class="javax.swing.JLabel">
<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>
<text resource-bundle="magento2/common" key="common.action"/>
</properties>
</component>
<component id="2b5b5" class="javax.swing.JTextField" binding="resourceFieldName">
<constraints>
<grid row="2" 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/>
</component>
<component id="d193a" class="javax.swing.JLabel">
<constraints>
<grid row="2" 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 resource-bundle="magento2/common" key="common.resource"/>
</properties>
</component>
<scrollpane id="3fb45">
<constraints>
<grid row="3" column="1" row-span="1" col-span="1" vsize-policy="7" hsize-policy="7" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="4ef4f" class="javax.swing.JTree" binding="moduleMenuTree">
<constraints/>
<properties>
<maximumSize width="400" height="250"/>
<preferredSize width="400" height="250"/>
<requestFocusEnabled value="false"/>
<rootVisible value="true"/>
</properties>
</component>
</children>
</scrollpane>
</children>
</grid>
<grid id="752f7" layout-manager="GridLayoutManager" row-count="1" column-count="3" 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="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
<border type="none"/>
<children>
<component id="d2c5e" class="javax.swing.JButton" binding="buttonOK">
<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 resource-bundle="magento2/common" key="common.ok"/>
</properties>
</component>
<hspacer id="2fc93">
<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>
<component id="a2945" class="javax.swing.JButton" binding="buttonCancel">
<constraints>
<grid row="0" column="2" 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 resource-bundle="magento2/common" key="common.cancel"/>
</properties>
<clientProperties>
<hideActionText class="java.lang.Boolean" value="false"/>
</clientProperties>
</component>
</children>
</grid>
</children>
</grid>
</form>
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.dialog;

import com.intellij.openapi.project.Project;
import com.intellij.psi.PsiDirectory;
import com.intellij.ui.treeStructure.Tree;
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.NewMenuItemValidator;
import com.magento.idea.magento2plugin.indexes.AdminMenuIndex;
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectory;
import java.awt.event.KeyEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.util.List;
import javax.swing.JComponent;
import javax.swing.JTree;
import javax.swing.KeyStroke;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.DefaultTreeModel;

public class NewMenuItemDialog extends AbstractDialog {
private javax.swing.JPanel controlPanel;
private javax.swing.JTextField titleFieldName;
private javax.swing.JTextField actionFieldName;
private javax.swing.JTextField resourceFieldName;
private javax.swing.JButton buttonOK;
private javax.swing.JButton buttonCancel;
private JTree moduleMenuTree;

private final Project project;
private final String moduleName;
private final NewMenuItemValidator validator;

/**
* Open new dialog for adding a new menu item.
*
* @param project Project
* @param directory PsiDirectory
*/
public NewMenuItemDialog(final Project project, final PsiDirectory directory) {
super();
this.project = project;
this.moduleName = GetModuleNameByDirectory.getInstance(project).execute(directory);
this.validator = new NewMenuItemValidator();

setContentPane(controlPanel);
setModal(true);
getRootPane().setDefaultButton(buttonOK);
setTitle(this.bundle.message("common.create.new.menu.item.title"));

buttonOK.addActionListener(e -> onOK());
buttonCancel.addActionListener(e -> onCancel());

setMenuTree();

setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
addWindowListener(new WindowAdapter() {
@Override
public void windowClosing(WindowEvent event) {
onCancel();
}
});

controlPanel.registerKeyboardAction(
event -> onCancel(),
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
);
}

private void setMenuTree() {
final List<String> menuItems = AdminMenuIndex.getInstance(project).getAdminMenuItems();
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Contacts"); // root node

DefaultMutableTreeNode contact1 = new DefaultMutableTreeNode("Contact # 1"); // level 1 node
DefaultMutableTreeNode nickName1 = new DefaultMutableTreeNode("drocktapiff"); // level 2 (leaf) node
contact1.add(nickName1);

DefaultMutableTreeNode contact2 = new DefaultMutableTreeNode("Contact # 2");
DefaultMutableTreeNode nickName2 = new DefaultMutableTreeNode("dic19");
contact2.add(nickName2);

root.add(contact1);
root.add(contact2);

DefaultTreeModel model = new DefaultTreeModel(root);
JTree tree = new Tree(model);

moduleMenuTree.setModel(tree.getModel());
}

/**
* Open a new CLI command dialog.
*
* @param project Project
* @param directory Directory
*/
public static void open(final Project project, final PsiDirectory directory) {
final NewMenuItemDialog dialog = new NewMenuItemDialog(project, directory);

dialog.pack();
dialog.centerDialog(dialog);
dialog.setVisible(true);
}

private void onOK() {
//if (!validator.validate(this.project,this)) {
// return;
// }
//this.generate();
this.setVisible(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

package com.magento.idea.magento2plugin.actions.generation.dialog.validator;


import com.magento.idea.magento2plugin.bundles.CommonBundle;
import com.magento.idea.magento2plugin.bundles.ValidatorBundle;
import com.intellij.openapi.project.Project;
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCLICommandDialog;

@SuppressWarnings({
"PMD.FieldNamingConventions",
"PMD.RedundantFieldInitializer",
"PMD.OnlyOneReturn",
"PMD.AvoidDuplicateLiterals",
})
public class NewMenuItemValidator {
private static NewMenuItemValidator INSTANCE = null;
private final ValidatorBundle validatorBundle;
private final CommonBundle commonBundle;

/**
* Returns a new instance of a class.
*
* @return NewMenuItemValidator
*/
public static NewMenuItemValidator getInstance() {
if (null != INSTANCE) {
return INSTANCE;
}
INSTANCE = new NewMenuItemValidator();

return INSTANCE;
}

public NewMenuItemValidator() {
this.validatorBundle = new ValidatorBundle();
this.commonBundle = new CommonBundle();
}

/**
* Validate new menu item command form data.
*
* @param project Project
* @param dialog Dialog
* @return boolen
*/
public boolean validate(final Project project, final NewCLICommandDialog dialog) {
return true;
}
}
Loading