Skip to content

Commit f4e9593

Browse files
author
Vasilii Burlacu
committed
Show the current project magento version in settings window
1 parent c6e8886 commit f4e9593

File tree

3 files changed

+87
-10
lines changed

3 files changed

+87
-10
lines changed
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
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.util;
7+
8+
import com.intellij.ide.DataManager;
9+
import com.intellij.json.psi.JsonFile;
10+
import com.intellij.json.psi.JsonObject;
11+
import com.intellij.openapi.actionSystem.DataConstants;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.project.Project;
14+
import com.intellij.openapi.vfs.LocalFileSystem;
15+
import com.intellij.openapi.vfs.VirtualFile;
16+
import com.intellij.psi.PsiFile;
17+
import com.intellij.psi.PsiManager;
18+
import com.intellij.psi.util.PsiTreeUtil;
19+
import com.magento.idea.magento2plugin.php.module.ComposerPackageModel;
20+
import com.magento.idea.magento2plugin.php.module.ComposerPackageModelImpl;
21+
22+
public class MagentoVersion {
23+
private static MagentoVersion INSTANCE = null;
24+
private String version = "unknown";
25+
private Project project;
26+
27+
public static MagentoVersion getInstance() {
28+
if (null == INSTANCE) {
29+
INSTANCE = new MagentoVersion();
30+
}
31+
return INSTANCE;
32+
}
33+
34+
public String get() {
35+
DataContext dataContext = DataManager.getInstance().getDataContext();
36+
this.project = (Project) dataContext.getData(DataConstants.PROJECT);
37+
38+
VirtualFile file = LocalFileSystem.getInstance().findFileByPath(this.getFilePath());
39+
40+
if (file == null) {
41+
return version;
42+
}
43+
44+
PsiManager psiManager = PsiManager.getInstance(this.project);
45+
PsiFile composerFile = psiManager.findFile(file);
46+
47+
if (composerFile instanceof JsonFile) {
48+
JsonFile composerJsonFile = (JsonFile) composerFile;
49+
JsonObject jsonObject = PsiTreeUtil.getChildOfType(composerJsonFile, JsonObject.class);
50+
51+
if (jsonObject == null) {
52+
return version;
53+
}
54+
55+
ComposerPackageModel composerObject = new ComposerPackageModelImpl(jsonObject);
56+
57+
if (composerObject.getType() != null) {
58+
version = composerObject.getVersion();
59+
}
60+
}
61+
62+
return version;
63+
}
64+
65+
private String getFilePath() {
66+
String fileName = "composer.json";
67+
return this.project.getBasePath() + "/" + fileName;
68+
}
69+
}

src/com/magento/idea/magento2plugin/project/SettingsForm.form

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,4 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<!--
3-
/**
4-
* Copyright © Magento, Inc. All rights reserved.
5-
* See COPYING.txt for license details.
6-
*/
7-
-->
82
<form xmlns="http://www.intellij.com/uidesigner/form/" version="1" bind-to-class="com.magento.idea.magento2plugin.project.SettingsForm">
93
<grid id="27dc6" binding="panel1" default-binding="true" layout-manager="GridLayoutManager" row-count="2" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
104
<margin top="0" left="0" bottom="0" right="0"/>
@@ -15,6 +9,8 @@
159
<border type="none"/>
1610
<children>
1711
<grid id="61372" layout-manager="FormLayout">
12+
<rowspec value="center:max(d;4px):noGrow"/>
13+
<rowspec value="top:3dlu:noGrow"/>
1814
<rowspec value="center:max(d;4px):noGrow"/>
1915
<rowspec value="top:3dlu:noGrow"/>
2016
<rowspec value="center:max(d;4px):noGrow"/>
@@ -46,6 +42,15 @@
4642
<text value="Regenerate urn map"/>
4743
</properties>
4844
</component>
45+
<component id="c2894" class="javax.swing.JLabel" binding="magentoVersion">
46+
<constraints>
47+
<grid row="4" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
48+
<forms/>
49+
</constraints>
50+
<properties>
51+
<text value=""/>
52+
</properties>
53+
</component>
4954
</children>
5055
</grid>
5156
<component id="2ef99" class="javax.swing.JCheckBox" binding="pluginEnabled">

src/com/magento/idea/magento2plugin/project/SettingsForm.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
import com.intellij.psi.PsiFile;
1616
import com.intellij.psi.PsiManager;
1717
import com.intellij.psi.search.FilenameIndex;
18+
import com.magento.idea.magento2plugin.actions.generation.util.MagentoVersion;
1819
import com.magento.idea.magento2plugin.indexes.IndexManager;
19-
import com.magento.idea.magento2plugin.php.module.ComposerPackageModel;
20-
import com.magento.idea.magento2plugin.php.module.MagentoComponent;
21-
import com.magento.idea.magento2plugin.php.module.MagentoComponentManager;
22-
import com.magento.idea.magento2plugin.php.module.MagentoModule;
20+
import com.magento.idea.magento2plugin.php.module.*;
2321
import org.jetbrains.annotations.Nls;
2422
import org.jetbrains.annotations.NotNull;
2523
import org.jetbrains.annotations.Nullable;
@@ -42,6 +40,8 @@ public class SettingsForm implements Configurable {
4240
private JButton buttonReindex;
4341
private JPanel panel1;
4442
private JButton regenerateUrnMapButton;
43+
private JLabel magentoVersion;
44+
private MagentoVersion magentoVersionModel = MagentoVersion.getInstance();
4545

4646
public SettingsForm(@NotNull final Project project) {
4747
this.project = project;
@@ -78,6 +78,9 @@ public void mouseClicked(MouseEvent e) {
7878
regenerateUrnMapButton.addMouseListener(
7979
new RegenerateUrnMapListener(project)
8080
);
81+
82+
magentoVersion.setText("Magento version: ".concat(magentoVersionModel.get()));
83+
8184
return (JComponent) panel1;
8285
}
8386

0 commit comments

Comments
 (0)