forked from magento/magento2-phpstorm-plugin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProjectDetector.java
64 lines (61 loc) · 3 KB
/
ProjectDetector.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
package com.magento.idea.magento2plugin.project;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.startup.StartupManager;
import com.intellij.openapi.util.Ref;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.platform.DirectoryProjectConfigurator;
import com.magento.idea.magento2plugin.indexes.IndexManager;
import com.magento.idea.magento2plugin.magento.packages.MagentoComponentManager;
import com.magento.idea.magento2plugin.util.magento.MagentoBasePathUtil;
import com.magento.idea.magento2plugin.util.magento.MagentoVersionUtil;
import javax.swing.event.HyperlinkEvent;
import org.jetbrains.annotations.NotNull;
public class ProjectDetector implements DirectoryProjectConfigurator {
@Override
public void configureProject(
final @NotNull Project project,
final @NotNull VirtualFile baseDir,
final @NotNull Ref<Module> moduleRef,
final boolean newProject
) {
StartupManager.getInstance(project).runWhenProjectIsInitialized(() -> {
DumbService.getInstance(project).smartInvokeLater(() -> {
if (!MagentoBasePathUtil.isMagentoFolderValid(baseDir.getPath())) {
return;
}
final Notification notification = new Notification("Magento", "Magento",
"<a href='enable'>Enable</a> Magento support for this project?",
NotificationType.INFORMATION, new NotificationListener.Adapter() {
@Override
public void hyperlinkActivated(
final @NotNull Notification notification,
final @NotNull HyperlinkEvent event
) {
Settings settings = Settings.getInstance(project);
settings.pluginEnabled = true;
settings.mftfSupportEnabled = true;
settings.magentoPath = project.getBasePath();
settings.magentoVersion = MagentoVersionUtil.get(
project,
project.getBasePath()
);
IndexManager.manualReindex();
MagentoComponentManager.getInstance(project).flushModules();
notification.expire();
}
});
Notifications.Bus.notify(notification, project);
});
});
}
}