Skip to content

Commit

Permalink
Version 1.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Enrique Piatti committed Dec 30, 2012
1 parent 51da51b commit d9b4943
Show file tree
Hide file tree
Showing 22 changed files with 716 additions and 85 deletions.
35 changes: 30 additions & 5 deletions META-INF/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,33 @@
<description>Plugin for magento development</description>
<idea-version since-build="111.296"/>

<version>1.2.0</version>
<version>1.3.0</version>
<change-notes>
<![CDATA[
<p>
<span>1.3.0</span>
<ul>
<li>Bugfixes:
<ul>
<li>NullPointerExceptions</li>
</ul>
</li>
<li>Enhancend goto (Ctrl+B, Middle click, Ctrl+Click) for Layout XML
<ul>
<li>Now it works with "alias" inside templates which are assigned directly from the Block class (like $this->getChildHtml('topLinks') inside header.phtml)</li>
<li>Goto handle definition from &gt;update handle="[HERE]"&lt;</li>
</ul>
</li>
<li>Enhanced Rewrite Class action
<ul>
<li>Added support for Rewriting controllers (Alt+M &gt; Rewrite Controller when editing some controller, put the cursor inside the class).</li>
<li>Suggested class name now includes the original module name too to follow convention and avoid collitions</li>
<li>Rewrite works for default classes from magento even when they are not declared in config.xml</li>
</ul>
</li>
<li>Autocompletion for xml files inside app/etc/modules/*.xml</li>
</ul>
</p>
<p>
<span>1.2.0</span>
<ul>
Expand All @@ -16,17 +40,17 @@
<li>NullPointerExceptions</li>
</ul>
</li>
<li>Added magento dictionary from https://github.com/tim-bezhashvyly/phpstorm-magento-dictionary</>
<li>Added magento dictionary from https://github.com/tim-bezhashvyly/phpstorm-magento-dictionary</li>
<li>Autocomplete observer method names in config.xml in camelCase to follow coding standard</li>
<li>Autocomplete for common "extends" (use Ctrl+Space after extends keyword)</li>
<li>New actions for translating text.
<ul>
<li>Select any html text or any string in php and use Alt+M > Translate Text for wrapping that text with $this->__() *
<li>Select any html text or any string in php and use Alt+M &gt; Translate Text for wrapping that text with $this->__() *
<br>(Tip: use Ctrl+W for selecting the text to translate quickly)
<br>* You could do the same using the native Surround With Live Templates functionality (check http://blogs.jetbrains.com/idea/tag/surround-with/)
</li>
<li>
Use Alt+M > Add Translation when the cursor is over $this->__('[HERE]') to define a new translation (it will be appended to the selected csv file, or create a new csv if not exist).
Use Alt+M &gt; Add Translation when the cursor is over $this->__('[HERE]') to define a new translation (it will be appended to the selected csv file, or create a new csv if not exist).
</li>
</ul>
</li>
Expand Down Expand Up @@ -65,7 +89,7 @@
<li>Goto xml block definition in layout Action (use Alt+M when editing any Block class to go to the block node definition in layout xml)</li>
<li>Goto xml layout definitions for block names inside templates (use Ctrl+B or middle click over any name in getChild, getChildHtml, getBlock, getBlockHtml([HERE]) call)</li>
<li>Autocomplete for getChild, getChildHtml, getBlock and getBlockHtml on templates (use Ctrl+Space)</li>
<li>Config options for enabling/disabling layout features and choosing packages and themes (File > Settings > Magicento)</li>
<li>Config options for enabling/disabling layout features and choosing packages and themes (File &gt; Settings &gt; Magicento)</li>
</ul>
</li>
</ul>
Expand Down Expand Up @@ -210,6 +234,7 @@
description="wrap selected text with $this->__()"/>
<action id="AddTranslation" class="com.magicento.actions.AddTranslationAction" text="Add Translation"
description="add translation for this text to the selected csv file"/>
<action id="RewriteController" class="com.magicento.actions.RewriteControllerAction" text="Rewrite Controller"/>
</actions>

<extensions defaultExtensionNs="com.intellij">
Expand Down
Binary file modified magicento.jar
Binary file not shown.
11 changes: 11 additions & 0 deletions resources/fileTemplates/j2ee/magicento_controller.php.ft
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
#parse("PHP File Header")
#if(${REQUIRE} != "")

require_once '${REQUIRE}';

#end

class ${CLASSNAME} #if(${EXTENDS} != "")extends ${EXTENDS}#end {

}
1 change: 1 addition & 0 deletions src/com/magicento/MagicentoAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ protected List<AnAction> _getMagentoContextActions()
"GetStoreConfig",
"CompareWithOriginal",
"RewriteClass",
"RewriteController",
"EvaluateInMagento",
"GotoClassesOfFactory",
"CreateModule",
Expand Down
117 changes: 71 additions & 46 deletions src/com/magicento/actions/RewriteClassAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@ public class RewriteClassAction extends MagicentoActionAbstract {
public void executeAction()
{
final Project project = getProject();

PsiElement psiElement = getPsiElementAtCursor();
String className = PsiPhpHelper.getClassName(psiElement);
if(className.endsWith("_Abstract")){
IdeHelper.showDialog(project, "Cannot rewrite Abstract Classes", "Magicento Rewrite Class");
return;
}

ChooseModuleDialog dialog = new ChooseModuleDialog(project);
dialog.show();
if( dialog.isOK())
Expand All @@ -42,88 +50,105 @@ public void executeAction()
if(selectedModulePath != null)
{
VirtualFile currentFile = getVirtualFile();
PsiElement psiElement = getPsiElementAtCursor();
String className = PsiPhpHelper.getClassName(psiElement);
String classNameParts[] = className.split("_");
if(classNameParts.length > 3)
{
String originalModuleName = classNameParts[0]+"_"+classNameParts[1];
String originalNamespace = classNameParts[0];
String originalModuleName = classNameParts[1];
String originalFullModuleName = originalNamespace+"_"+originalModuleName;
String classType = classNameParts[2];
String originalClassPrefix = originalModuleName+"_"+classType;
String originalClassPrefix = originalFullModuleName+"_"+classType;
String originalFilePath = currentFile.getPath().replace("\\", "/");
String regex = "^(.+?/"+classNameParts[0]+"/"+classNameParts[1]+"/).+";
String originalModulePath = JavaHelper.extractFirstCaptureRegex(regex,originalFilePath);
String originalXmlPath = originalModulePath+"etc/config.xml";
File originalConfigXml = new File(originalXmlPath);
if(originalConfigXml.exists())
{

String firstPart = null;
String secondPartClassName = null;
String secondPart = null;
String groupType = null;

// search inside config.xml for the class prefix (so we can detect if this is a resource model)
// and also we need to know the group name on the xml to add the <rewrite> node there
String xpath = "//class[contains(.,'"+originalClassPrefix+"')]";
List<Element> originalClassNodes = XmlHelper.findXpath(originalConfigXml, xpath);
// TODO: search for default helper nodes too (not declared inside config.xml) @see MagicentoProjectComponent::defaultGroupsFromMagento
// TODO: add check for abstract classes (abstract classes cannot be rewritted)
if(originalClassNodes != null && originalClassNodes.size() > 0){
if(originalClassNodes != null && originalClassNodes.size() > 0)
{
Element correctNode = null;
for(Element originalClassNode : originalClassNodes){
String classPrefix = originalClassNode.getValue();
if(className.contains(classPrefix) && (correctNode == null || correctNode.getValue().length() < classPrefix.length())){
correctNode = originalClassNode;
}
}
if(correctNode != null){
String firstPart = correctNode.getParentElement().getName();
String secondPartClassName = className.substring(correctNode.getValue().length()+1);
String secondPart = WordUtils.uncapitalize(secondPartClassName.replace("_", " ")).replace(" ", "_"); // MagentoParser.getSecondPartUriFromClassName(className, correctNode.getValue());

// String originalUri = firstPart+"/"+secondPart;
File targetConfigXml = new File(selectedModulePath+"/etc/config.xml");

String targetModuleName = MagentoParser.getModuleNameFromModulePath(selectedModulePath);
String suggestedClassName = targetModuleName+"_"+correctNode.getValue().substring(originalModuleName.length()+1)+"_"+secondPartClassName;
final String newClassName = Messages.showInputDialog(project, "New class name", "Write the name of the new class", Messages.getQuestionIcon(), suggestedClassName, null);
if(newClassName == null || newClassName.isEmpty() || ! newClassName.startsWith(targetModuleName+"_"+classType)){
IdeHelper.showDialog(project, "Wrong class name", "Magicento Rewrite Class");
return;
}

if(correctNode != null){
firstPart = correctNode.getParentElement().getName();
secondPartClassName = className.substring(correctNode.getValue().length()+1);
secondPart = WordUtils.uncapitalize(secondPartClassName.replace("_", " ")).replace(" ", "_"); // MagentoParser.getSecondPartUriFromClassName(className, correctNode.getValue());
groupType = correctNode.getValue().substring(originalFullModuleName.length() + 1);
}
else {
IdeHelper.showDialog(project, "Couldn't find class node", "Magicento Rewrite Class");
return;
}

VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(targetConfigXml);
final XmlFile psiXmlFile = (XmlFile)PsiManager.getInstance(project).findFile(vFile);
}
// try the default nodes from Magento (not declared explicitely on the config.xml)
else if(originalNamespace.equals("Mage")){
firstPart = originalModuleName.toLowerCase();
secondPartClassName = className.substring(originalClassPrefix.length()+1);
secondPart = WordUtils.uncapitalize(secondPartClassName.replace("_", " ")).replace(" ", "_");
groupType = classType;
}
else {
IdeHelper.showDialog(project, "Couldn't find class node containing "+ originalClassPrefix + " value", "Magicento Rewrite Class");
return;
}

if(psiXmlFile != null)
{
String type = classType.toLowerCase()+"s";
String path = "config/global/"+type+"/"+firstPart+"/rewrite";
XmlTag newTag = XmlHelper.createTagInFile(psiXmlFile, secondPart, newClassName, path);
if(newTag == null){
IdeHelper.showDialog(project, "Error trying to create rewrite node in "+psiXmlFile.getVirtualFile().getPath(), "Magicento Rewrite Class");
return;
}

String relativePath = newClassName.substring(targetModuleName.length(),newClassName.lastIndexOf("_")).replace("_", "/");
String directoryPath = selectedModulePath + relativePath;
PsiFile newClassFile = createClass(directoryPath, newClassName, className);
// String originalUri = firstPart+"/"+secondPart;
File targetConfigXml = new File(selectedModulePath+"/etc/config.xml");

openFile(newClassFile);
String targetModuleName = MagentoParser.getModuleNameFromModulePath(selectedModulePath);
String suggestedClassName = targetModuleName+"_"+groupType+"_"+originalModuleName+"_"+secondPartClassName;
final String newClassName = Messages.showInputDialog(project, "New class name", "Write the name of the new class", Messages.getQuestionIcon(), suggestedClassName, null);
if(newClassName == null || newClassName.isEmpty() || ! newClassName.startsWith(targetModuleName+"_"+classType)){
IdeHelper.showDialog(project, "Wrong class name", "Magicento Rewrite Class");
return;
}

}

VirtualFile vFile = LocalFileSystem.getInstance().findFileByIoFile(targetConfigXml);
final XmlFile psiXmlFile = (XmlFile)PsiManager.getInstance(project).findFile(vFile);

if(psiXmlFile != null)
{
String type = classType.toLowerCase()+"s";
String path = "config/global/"+type+"/"+firstPart+"/rewrite";
XmlTag newTag = XmlHelper.createTagInFile(psiXmlFile, secondPart, newClassName, path);
if(newTag == null){
IdeHelper.showDialog(project, "Error trying to create rewrite node in "+psiXmlFile.getVirtualFile().getPath(), "Magicento Rewrite Class");
return;
}
else {
IdeHelper.showDialog(project, "Couldn't find class node", "Magicento Rewrite Class");
}
}
else {
IdeHelper.showDialog(project, "Couldn't find class node containing "+ originalClassPrefix + " value", "Magicento Rewrite Class");

String relativePath = newClassName.substring(targetModuleName.length(),newClassName.lastIndexOf("_")).replace("_", "/");
String directoryPath = selectedModulePath + relativePath;
PsiFile newClassFile = createClass(directoryPath, newClassName, className);

openFile(newClassFile);

}


}
else {
IdeHelper.showDialog(project, "Couldn't find: "+originalXmlPath, "Magicento Rewrite Class");
}

// TODO add support for default magento helpers (not declared explicitely in config.xml)

}

}
Expand Down
Loading

0 comments on commit d9b4943

Please sign in to comment.