Skip to content

Commit 008592a

Browse files
author
Vitaliy Boyko
committed
Revert "270: fixed endless loop of notifications"
This reverts commit 4d2f938
1 parent b39b243 commit 008592a

File tree

7 files changed

+66
-133
lines changed

7 files changed

+66
-133
lines changed

resources/META-INF/plugin.xml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,6 @@
194194
<internalFileTemplate name="Magento Module Controller Backend Class"/>
195195
<internalFileTemplate name="Magento Module Controller Frontend Class"/>
196196
<internalFileTemplate name="Magento Module Cron Groups Xml"/>
197-
198-
<postStartupActivity implementation="com.magento.idea.magento2plugin.project.startup.CheckIfMagentoPathIsValidActivity"/>
199197
</extensions>
200198

201199
<extensions defaultExtensionNs="com.jetbrains.php">

src/com/magento/idea/magento2plugin/generation/php/NewModuleForm.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public MagentoProjectGeneratorSettings getSettings() {
116116
final Settings.State state = new Settings.State();
117117
state.setPluginEnabled(true);
118118
state.setMftfSupportEnabled(true);
119-
state.setDefaultLicenseName(Settings.defaultLicense);
119+
state.setDefaultLicenseName(Settings.DEFAULT_LICENSE);
120120
state.setMagentoPathAndUpdateLastUsed(this.magentoPath.getTextField().getText().trim());
121121

122122
return new MagentoProjectGeneratorSettings(

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

Lines changed: 61 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1,111 +1,99 @@
1-
/*
1+
/**
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5-
65
package com.magento.idea.magento2plugin.project;
76

87
import com.intellij.ide.util.PropertiesComponent;
9-
import com.intellij.openapi.components.PersistentStateComponent;
10-
import com.intellij.openapi.components.ServiceManager;
11-
import com.intellij.openapi.components.State;
12-
import com.intellij.openapi.components.Storage;
8+
import com.intellij.openapi.components.*;
139
import com.intellij.openapi.project.Project;
1410
import com.intellij.openapi.util.text.StringUtil;
1511
import com.intellij.util.EventDispatcher;
1612
import com.intellij.util.xmlb.annotations.Attribute;
1713
import com.intellij.util.xmlb.annotations.Tag;
18-
import java.util.EventListener;
14+
import com.magento.idea.magento2plugin.init.ConfigurationManager;
15+
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
1916
import org.jetbrains.annotations.NotNull;
2017
import org.jetbrains.annotations.Nullable;
18+
import java.util.EventListener;
2119

2220
@State(
23-
name = "Magento2PluginSettings",
24-
storages = {
25-
@Storage("magento2plugin.xml")
26-
}
21+
name = "Magento2PluginSettings",
22+
storages = {
23+
@Storage("magento2plugin.xml")
24+
}
2725
)
2826
public class Settings implements PersistentStateComponent<Settings.State> {
29-
private final EventDispatcher<MagentoModuleDataListener> myEventDispatcher
30-
= EventDispatcher.create(MagentoModuleDataListener.class);
31-
public boolean pluginEnabled;
32-
public static String defaultLicense = "Proprietary";
27+
private final EventDispatcher<MagentoModuleDataListener> myEventDispatcher = EventDispatcher.create(MagentoModuleDataListener.class);
28+
public boolean pluginEnabled = false;
29+
public static String DEFAULT_LICENSE = "Proprietary";
3330
public String magentoPath;
34-
public boolean mftfSupportEnabled;
35-
public boolean myDoNotAskContentConfigAgain;
36-
public String magentoVersion;
31+
public boolean mftfSupportEnabled = false;
32+
public boolean myDoNotAskContentConfigAgain = false;
33+
public String magentoVersion = null;
3734

38-
@Override
3935
@Nullable
4036
public Settings.State getState() {
4137
return new Settings.State(
4238
this.pluginEnabled,
4339
this.magentoPath,
44-
defaultLicense,
40+
DEFAULT_LICENSE,
4541
this.mftfSupportEnabled,
4642
this.myDoNotAskContentConfigAgain,
4743
this.magentoVersion
4844
);
4945
}
5046

51-
/**
52-
* State setter.
53-
*
54-
* @param state State
55-
*/
56-
public void setState(final State state) {
57-
final State oldState = this.getState();
47+
public void setState(State state) {
48+
State oldState = this.getState();
5849
this.loadState(state);
5950
this.notifyListeners(state, oldState);
6051
}
6152

62-
@Override
63-
public void loadState(final @NotNull Settings.State state) {
53+
public void loadState(@NotNull Settings.State state) {
6454
this.pluginEnabled = state.isPluginEnabled();
6555
this.magentoPath = state.getMagentoPath();
66-
this.defaultLicense = state.getDefaultLicenseName();
56+
this.DEFAULT_LICENSE = state.getDefaultLicenseName();
6757
this.mftfSupportEnabled = state.isMftfSupportEnabled();
6858
this.myDoNotAskContentConfigAgain = state.isDoNotAskContentConfigAgain();
6959
this.magentoVersion = state.getMagentoVersion();
7060
}
7161

72-
public void addListener(final MagentoModuleDataListener listener) {
62+
public void addListener(MagentoModuleDataListener listener) {
7363
this.myEventDispatcher.addListener(listener);
7464
}
7565

76-
private void notifyListeners(final State state, final State oldState) {
66+
private void notifyListeners(State state, State oldState) {
7767
if (!state.equals(oldState)) {
7868
this.myEventDispatcher.getMulticaster().stateChanged(state, oldState);
7969
}
8070
}
8171

82-
public void setDoNotAskContentConfigurationAgain(
83-
final boolean doNotAskContentConfigurationAgain
84-
) {
72+
public void setDoNotAskContentConfigurationAgain(boolean doNotAskContentConfigurationAgain) {
8573
this.myDoNotAskContentConfigAgain = doNotAskContentConfigurationAgain;
8674
}
8775

88-
public void setMagentoPath(final String magentoPath) {
76+
public void setMagentoPath(String magentoPath) {
8977
this.magentoPath = magentoPath;
9078
}
9179

9280
public interface MagentoModuleDataListener extends EventListener {
9381
void stateChanged(State state, State oldState);
9482
}
9583

96-
public static Settings getInstance(final Project project) {
84+
public static Settings getInstance(Project project) {
9785
return ServiceManager.getService(project, Settings.class);
9886
}
9987

100-
public static boolean isEnabled(final @NotNull Project project) {
88+
public static boolean isEnabled(@NotNull Project project) {
10189
return getInstance(project).pluginEnabled;
10290
}
10391

104-
public static String getDefaultLicenseName(final @NotNull Project project) {
105-
return getInstance(project).defaultLicense;
92+
public static String getDefaultLicenseName(@NotNull Project project) {
93+
return getInstance(project).DEFAULT_LICENSE;
10694
}
10795

108-
public static boolean isMftfSupportEnabled(final @NotNull Project project) {
96+
public static boolean isMftfSupportEnabled(@NotNull Project project) {
10997
return getInstance(project).mftfSupportEnabled;
11098
}
11199

@@ -115,11 +103,21 @@ public static String getLastMagentoPath() {
115103
}
116104

117105
@Nullable
118-
public static String getMagentoPath(final @NotNull Project project) {
119-
return getInstance(project).magentoPath;
106+
public static String getMagentoPath(@NotNull Project project) {
107+
Settings settings = getInstance(project);
108+
String path = settings.magentoPath;
109+
if (path == null || path.isEmpty()) {
110+
if (MagentoBasePathUtil.isMagentoFolderValid(project.getBasePath())) {
111+
settings.setMagentoPath(project.getBasePath());
112+
} else {
113+
settings.pluginEnabled = false;
114+
ConfigurationManager.suggestToConfigureMagentoPath(project);
115+
return null;
116+
}
117+
}
118+
return settings.magentoPath;
120119
}
121120

122-
@SuppressWarnings({"PMD.DataClass"})
123121
@Tag
124122
public static class State {
125123
public boolean pluginEnabled;
@@ -129,26 +127,16 @@ public static class State {
129127
public boolean myDoNotAskContentConfigAgain;
130128
public String magentoVersion;
131129

132-
public State() {//NOPMD
130+
public State() {
133131
}
134132

135-
/**
136-
* Settings State.
137-
*
138-
* @param pluginEnabled boolean
139-
* @param magentoPath String
140-
* @param defaultLicenseName String
141-
* @param mftfSupportEnabled boolean
142-
* @param myDoNotAskContentConfigAgain boolean
143-
* @param magentoVersion String
144-
*/
145133
public State(
146-
final boolean pluginEnabled,
147-
final String magentoPath,
148-
final String defaultLicenseName,
149-
final boolean mftfSupportEnabled,
150-
final boolean myDoNotAskContentConfigAgain,
151-
final String magentoVersion
134+
boolean pluginEnabled,
135+
String magentoPath,
136+
String defaultLicenseName,
137+
boolean mftfSupportEnabled,
138+
boolean myDoNotAskContentConfigAgain,
139+
String magentoVersion
152140
) {
153141
this.pluginEnabled = pluginEnabled;
154142
this.magentoPath = magentoPath;
@@ -163,7 +151,7 @@ public boolean isPluginEnabled() {
163151
return this.pluginEnabled;
164152
}
165153

166-
public void setPluginEnabled(final boolean enabled) {
154+
public void setPluginEnabled(boolean enabled) {
167155
this.pluginEnabled = enabled;
168156
}
169157

@@ -172,7 +160,7 @@ public String getMagentoPath() {
172160
}
173161

174162
@Tag("magentoPath")
175-
public void setMagentoPath(final String magentoPath) {
163+
public void setMagentoPath(String magentoPath) {
176164
this.magentoPath = magentoPath;
177165
}
178166

@@ -181,28 +169,22 @@ public String getMagentoVersion() {
181169
}
182170

183171
@Tag("magentoVersion")
184-
public void setMagentoVersion(final String magentoVersion) {
172+
public void setMagentoVersion(String magentoVersion) {
185173
this.magentoVersion = magentoVersion;
186174
}
187175

188-
/**
189-
* Last Used Magento Path setter.
190-
*
191-
* @param magentoPath String
192-
*/
193-
public void setMagentoPathAndUpdateLastUsed(final String magentoPath) {
176+
public void setMagentoPathAndUpdateLastUsed(String magentoPath) {
194177
this.setMagentoPath(magentoPath);
195178
if (!StringUtil.isEmptyOrSpaces(magentoPath)) {
196-
PropertiesComponent.getInstance()
197-
.setValue("magento.support.magentoPath", magentoPath);
179+
PropertiesComponent.getInstance().setValue("magento.support.magentoPath", magentoPath);
198180
}
199181
}
200182

201183
public String getDefaultLicenseName() {
202184
return this.defaultLicenseName;
203185
}
204186

205-
public void setDefaultLicenseName(final String defaultLicenseName) {
187+
public void setDefaultLicenseName(String defaultLicenseName) {
206188
this.defaultLicenseName = defaultLicenseName;
207189
}
208190

@@ -214,50 +196,40 @@ public boolean isDoNotAskContentConfigAgain() {
214196
return this.myDoNotAskContentConfigAgain;
215197
}
216198

217-
public void setMftfSupportEnabled(final boolean mftfSupportEnabled) {
199+
public void setMftfSupportEnabled(boolean mftfSupportEnabled) {
218200
this.mftfSupportEnabled = mftfSupportEnabled;
219201
}
220202

221-
@SuppressWarnings({"PMD.ConfusingTernary"})
222-
@Override
223-
public boolean equals(final Object objectToCompare) {
203+
public boolean equals(Object objectToCompare) {
224204
if (this == objectToCompare) {
225205
return true;
226206
} else if (objectToCompare != null && this.getClass() == objectToCompare.getClass()) {
227-
final State state = (State) objectToCompare;
207+
State state = (State) objectToCompare;
228208
if (this.isPluginEnabled() != state.isPluginEnabled()) {
229209
return false;
230210
} else if (this.isMftfSupportEnabled() != state.isMftfSupportEnabled()) {
231211
return false;
232-
} else if (
233-
this.isDoNotAskContentConfigAgain() != state.isDoNotAskContentConfigAgain()
234-
) {
212+
} else if (this.isDoNotAskContentConfigAgain() != state.isDoNotAskContentConfigAgain()) {
235213
return false;
236214
} else {
237215
if (this.magentoPath != null) {
238216
return this.magentoPath.equals(state.magentoPath);
239217
}
240218
if (this.defaultLicenseName != null) {
241219
return this.defaultLicenseName.equals(state.defaultLicenseName);
242-
} else {
243-
return state.defaultLicenseName == null;
244-
}
220+
} else return state.defaultLicenseName == null;
245221
}
246222
} else {
247223
return false;
248224
}
249225
}
250226

251-
@SuppressWarnings({"PMD.ConfusingTernary"})
252-
@Override
253227
public int hashCode() {
254228
int result = this.isPluginEnabled() ? 1 : 0;
255229
result = 31 * result + (this.magentoPath != null ? this.magentoPath.hashCode() : 0);
256230
result = 31 * result + (this.isMftfSupportEnabled() ? 1 : 0);
257231
result = 31 * result + (this.isDoNotAskContentConfigAgain() ? 1 : 0);
258-
result = 31 * result + (
259-
this.defaultLicenseName != null ? this.defaultLicenseName.hashCode() : 0
260-
);
232+
result = 31 * result + (this.defaultLicenseName != null ? this.defaultLicenseName.hashCode() : 0);
261233
return result;
262234
}
263235
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public void mouseClicked(final MouseEvent event) {
8484
new RegenerateUrnMapListener(project)
8585
);
8686

87-
moduleDefaultLicenseName.setText(getSettings().defaultLicense);
87+
moduleDefaultLicenseName.setText(getSettings().DEFAULT_LICENSE);
8888
mftfSupportEnabled.setSelected(getSettings().mftfSupportEnabled);
8989
magentoPath.getTextField().setText(getSettings().magentoPath);
9090
resolveMagentoVersion();
@@ -103,7 +103,7 @@ protected void reindex() {
103103
@Override
104104
public boolean isModified() {
105105
final boolean licenseChanged = !moduleDefaultLicenseName.getText().equals(
106-
Settings.defaultLicense
106+
Settings.DEFAULT_LICENSE
107107
);
108108
final boolean statusChanged = !pluginEnabled.isSelected() == getSettings().pluginEnabled;
109109
final boolean mftfSupportChanged = mftfSupportEnabled.isSelected()
@@ -139,7 +139,7 @@ public void apply() throws ConfigurationException {
139139

140140
private void saveSettings() {
141141
getSettings().pluginEnabled = pluginEnabled.isSelected();
142-
getSettings().defaultLicense = moduleDefaultLicenseName.getText();
142+
getSettings().DEFAULT_LICENSE = moduleDefaultLicenseName.getText();
143143
getSettings().mftfSupportEnabled = mftfSupportEnabled.isSelected();
144144
getSettings().magentoPath = getMagentoPath();
145145
getSettings().magentoVersion = getMagentoVersion();

src/com/magento/idea/magento2plugin/project/startup/CheckIfMagentoPathIsValidActivity.java

Lines changed: 0 additions & 30 deletions
This file was deleted.

src/com/magento/idea/magento2plugin/stubs/indexes/js/MagentoLibJsIndex.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,7 @@ public ID<String, Void> getName() {
4141
public DataIndexer<String, Void, FileContent> getIndexer() {
4242
return inputData -> {
4343
final Map<String, Void> map = new HashMap<>();//NOPMD
44-
final String magentoPath = Settings.getMagentoPath(inputData.getProject());
45-
if (magentoPath == null) {
46-
return map;
47-
}
48-
final String libPath = magentoPath
44+
final String libPath = Settings.getMagentoPath(inputData.getProject())
4945
+ File.separator + Package.libWebRoot + File.separator;
5046
final VirtualFile file = inputData.getFile();
5147

0 commit comments

Comments
 (0)