Skip to content

Commit 4274c9c

Browse files
committed
Add support for Symfony 2.8 and 3 using the new directory structure #635, also add auto configuration to set all custom paths and enabled plugin directly out of notification box
1 parent 5806fd5 commit 4274c9c

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

src/fr/adrienbrault/idea/symfony2plugin/Settings.java

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,12 @@
2121
)
2222
public class Settings implements PersistentStateComponent<Settings> {
2323

24-
public static String DEFAULT_CONTAINER_PATH = "app/cache/dev/appDevDebugProjectContainer.xml";
24+
// Symfony 2 and 3 paths
25+
public static String[] DEFAULT_CONTAINER_PATHS = new String[] {
26+
"app/cache/dev/appDevDebugProjectContainer.xml",
27+
"var/cache/dev/appDevDebugProjectContainer.xml",
28+
};
29+
2530
public static String DEFAULT_URL_GENERATOR_PATH = "app/cache/dev/appDevUrlGenerator.php";
2631
public static String DEFAULT_TRANSLATION_PATH = "app/cache/dev/translations";
2732

src/fr/adrienbrault/idea/symfony2plugin/Symfony2ProjectComponent.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,16 @@
55
import com.intellij.notification.Notifications;
66
import com.intellij.openapi.components.ProjectComponent;
77
import com.intellij.openapi.diagnostic.Logger;
8-
import com.intellij.openapi.editor.EditorFactory;
9-
import com.intellij.openapi.editor.event.CaretListener;
108
import com.intellij.openapi.extensions.ExtensionPointName;
119
import com.intellij.openapi.project.Project;
1210
import com.intellij.openapi.util.io.FileUtil;
1311
import com.intellij.openapi.vfs.VfsUtil;
1412
import com.intellij.openapi.wm.StatusBar;
1513
import com.intellij.openapi.wm.WindowManager;
1614
import com.intellij.psi.PsiElement;
17-
import fr.adrienbrault.idea.symfony2plugin.codeInsight.caret.overlay.CaretTextOverlayListener;
1815
import fr.adrienbrault.idea.symfony2plugin.dic.ContainerFile;
1916
import fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoader;
2017
import fr.adrienbrault.idea.symfony2plugin.extension.ServiceContainerLoaderParameter;
21-
import fr.adrienbrault.idea.symfony2plugin.routing.Route;
2218
import fr.adrienbrault.idea.symfony2plugin.routing.RouteHelper;
2319
import fr.adrienbrault.idea.symfony2plugin.util.IdeHelper;
2420
import fr.adrienbrault.idea.symfony2plugin.util.service.ServiceXmlParserFactory;
@@ -120,7 +116,9 @@ public List<File> getContainerFiles(boolean attachSetting) {
120116
}
121117

122118
if(containerFiles.size() == 0) {
123-
containerFiles.add(new ContainerFile(Settings.DEFAULT_CONTAINER_PATH));
119+
for (String s : Settings.DEFAULT_CONTAINER_PATHS) {
120+
containerFiles.add(new ContainerFile(s));
121+
}
124122
}
125123

126124
List<File> validFiles = new ArrayList<File>();
@@ -145,7 +143,8 @@ private void checkProject() {
145143

146144
if(!this.isEnabled() && !Settings.getInstance(project).dismissEnableNotification) {
147145
if(VfsUtil.findRelativeFile(this.project.getBaseDir(), "vendor") != null
148-
&& VfsUtil.findRelativeFile(this.project.getBaseDir(), "app", "cache") != null
146+
&& VfsUtil.findRelativeFile(this.project.getBaseDir(), "app", "config") != null
147+
&& VfsUtil.findRelativeFile(this.project.getBaseDir(), "app", "Resources") != null
149148
&& VfsUtil.findRelativeFile(this.project.getBaseDir(), "vendor", "symfony", "symfony") != null
150149
) {
151150
IdeHelper.notifyEnableMessage(project);

src/fr/adrienbrault/idea/symfony2plugin/installer/SymfonyInstallerProjectGenerator.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import fr.adrienbrault.idea.symfony2plugin.Settings;
1313
import fr.adrienbrault.idea.symfony2plugin.Symfony2Icons;
1414
import fr.adrienbrault.idea.symfony2plugin.Symfony2ProjectComponent;
15+
import fr.adrienbrault.idea.symfony2plugin.util.IdeHelper;
1516
import org.jetbrains.annotations.Nls;
1617
import org.jetbrains.annotations.NotNull;
1718
import org.jetbrains.annotations.Nullable;
@@ -65,7 +66,8 @@ public void generateProject(@NotNull final Project project, final @NotNull Virtu
6566
SymfonyInstallerCommandExecutor executor = new SymfonyInstallerCommandExecutor(project, baseDir, commands) {
6667
@Override
6768
protected void onFinish(@Nullable String message) {
68-
Settings.getInstance(project).pluginEnabled = true;
69+
IdeHelper.enablePluginAndConfigure(project);
70+
6971
if(message != null) {
7072
// replace empty lines, provide html output, and remove our temporary path
7173
showInfoNotification(project, message

src/fr/adrienbrault/idea/symfony2plugin/ui/ContainerSettingsForm.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ public void mouseClicked(MouseEvent e) {
6969
resetContainerList();
7070

7171
// add default path
72-
ContainerSettingsForm.this.modelList.addRow(new ContainerFile(Settings.DEFAULT_CONTAINER_PATH));
72+
for (String defaultContainerPath : Settings.DEFAULT_CONTAINER_PATHS) {
73+
ContainerSettingsForm.this.modelList.addRow(new ContainerFile(defaultContainerPath));
74+
}
7375

7476
}
7577
});

src/fr/adrienbrault/idea/symfony2plugin/util/IdeHelper.java

+14-2
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public static boolean supportsStatusBar() {
136136

137137
public static void notifyEnableMessage(final Project project) {
138138

139-
Notification notification = new Notification("Symfony Plugin", "Symfony Plugin", "Enable the Symfony Plugin in <a href=\"config\">Project Settings</a> or <a href=\"dismiss\">dismiss</a> further messages", NotificationType.INFORMATION, new NotificationListener() {
139+
Notification notification = new Notification("Symfony Plugin", "Symfony Plugin", "Enable the Symfony Plugin <a href=\"enable\">with auto configuration now</a>, open <a href=\"config\">Project Settings</a> or <a href=\"dismiss\">dismiss</a> further messages", NotificationType.INFORMATION, new NotificationListener() {
140140
@Override
141141
public void hyperlinkUpdate(@NotNull Notification notification, @NotNull HyperlinkEvent event) {
142142

@@ -145,7 +145,9 @@ public void hyperlinkUpdate(@NotNull Notification notification, @NotNull Hyperli
145145

146146
// open settings dialog and show panel
147147
SettingsForm.show(project);
148-
148+
} else if("enable".equals(event.getDescription())) {
149+
enablePluginAndConfigure(project);
150+
Notifications.Bus.notify(new Notification("Symfony Plugin", "Symfony Plugin", "Plugin enabled", NotificationType.INFORMATION), project);
149151
} else if("dismiss".equals(event.getDescription())) {
150152

151153
// use dont want to show notification again
@@ -160,6 +162,16 @@ public void hyperlinkUpdate(@NotNull Notification notification, @NotNull Hyperli
160162
Notifications.Bus.notify(notification, project);
161163
}
162164

165+
public static void enablePluginAndConfigure(@NotNull Project project) {
166+
Settings.getInstance(project).pluginEnabled = true;
167+
168+
// Symfony 3.0 structure
169+
if(VfsUtil.findRelativeFile(project.getBaseDir(), "var", "cache") == null) {
170+
Settings.getInstance(project).pathToUrlGenerator = "var/cache/dev/appDevUrlGenerator.php";
171+
Settings.getInstance(project).pathToTranslation = "var/cache/dev/translations";
172+
}
173+
}
174+
163175
public static void navigateToPsiElement(@NotNull PsiElement psiElement) {
164176
final Navigatable descriptor = PsiNavigationSupport.getInstance().getDescriptor(psiElement);
165177
if (descriptor != null) {

0 commit comments

Comments
 (0)