8000 Merge branch 'master' into patch-1 · SylApps/idea-php-symfony2-plugin@31b9437 · GitHub
[go: up one dir, main page]

Skip to content

Commit 31b9437

Browse files
authored
Merge branch 'master' into patch-1
2 parents e3fe56a + 89d211c commit 31b9437

File tree

7 files changed

+118
-100
lines changed

7 files changed

+118
-100
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,14 @@ Autocomplete (or something else) is not working! Help! :open_mouth:
4242
Building, debugging and other
4343
--------------------
4444

45-
* Open the project in IntelliJ, and follow the steps here : http://confluence.jetbrains.com/display/PhpStorm/Setting-up+environment+for+PhpStorm+plugin+development
46-
* Want to donate? nice go [here](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5ZTGW6H4Y7MT8)
45+
* Install IntelliJ IDEA (Community Edition works fine)
46+
* Open this project
47+
* Choose `View > Tool Windows > Gradle`
48+
* Double click `idea-php-symfony2-plugin > Tasks > intellij > runIdle`
49+
50+
If you are having difficulties, consult the documentation: http://confluence.jetbrains.com/display/PhpStorm/Setting-up+environment+for+PhpStorm+plugin+development
51+
52+
* Want to sponsor my development? Nice! You can sponsor me via [PayPal](https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=5ZTGW6H4Y7MT8) or via [Github](https://github.com/sponsors/Haehnchen). Github matches your donation so the total donation will be doubled.
4753

4854
What? Something still does not work? Damn! :cry:
4955
------------------------------------------------

src/main/java/fr/adrienbrault/idea/symfony2plugin/SettingsForm.java

Lines changed: 8 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import com.intellij.openapi.options.Configurable;
88
import com.intellij.openapi.options.ConfigurationException;
99
import com.intellij.openapi.project.Project;
10+
import com.intellij.openapi.ui.TextBrowseFolderListener;
1011
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
1112
import com.intellij.openapi.vfs.VfsUtil;
1213
import com.intellij.openapi.vfs.VirtualFile;
@@ -18,6 +19,7 @@
1819
import org.jetbrains.annotations.Nullable;
1920

2021
import javax.swing.*;
22+
import java.awt.event.ActionEvent;
2123
import java.awt.event.MouseAdapter;
2224
import java.awt.event.MouseEvent;
2325
import java.awt.event.MouseListener;
@@ -78,13 +80,13 @@ public String getHelpTopic() {
7880
}
7981

8082
public JComponent createComponent() {
81-
pathToTranslationRootTextField.getButton().addMouseListener(createPathButtonMouseListener(pathToTranslationRootTextField.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
83+
pathToTranslationRootTextField.addBrowseFolderListener(createBrowseFolderListener(pathToTranslationRootTextField.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
8284
pathToTranslationRootTextFieldReset.addMouseListener(createResetPathButtonMouseListener(pathToTranslationRootTextField.getTextField(), Settings.DEFAULT_TRANSLATION_PATH));
8385

84-
directoryToApp.getButton().addMouseListener(createPathButtonMouseListener(directoryToApp.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
86+
directoryToApp.addBrowseFolderListener(createBrowseFolderListener(directoryToApp.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
8587
directoryToAppReset.addMouseListener(createResetPathButtonMouseListener(directoryToApp.getTextField(), Settings.DEFAULT_APP_DIRECTORY));
8688

87-
directoryToWeb.getButton().addMouseListener(createPathButtonMouseListener(directoryToWeb.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
89+
directoryToWeb.addBrowseFolderListener(createBrowseFolderListener(directoryToWeb.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
8890
directoryToWebReset.addMouseListener(createResetPathButtonMouseListener(directoryToWeb.getTextField(), Settings.DEFAULT_WEB_DIRECTORY));
8991

9092
enableSchedulerCheckBox.setEnabled(WebDeploymentUtil.isEnabled(project));
@@ -169,14 +171,10 @@ private void updateUIFromSettings() {
169171
directoryToWeb.setText(getSettings().directoryToWeb);
170172
}
171173

172-
private MouseListener createPathButtonMouseListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
173-
return new MouseListener() {
174-
@Override
175-
public void mouseClicked(MouseEvent mouseEvent) {
176-
}
177-
174+
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
175+
return new TextBrowseFolderListener(fileChooserDescriptor) {
178176
@Override
179-
public void mousePressed(MouseEvent mouseEvent) {
177+
public void actionPerformed(ActionEvent e) {
180178
VirtualFile projectDirectory = project.getBaseDir();
181179
VirtualFile selectedFile = FileChooser.chooseFile(
182180
fileChooserDescriptor,
@@ -195,18 +193,6 @@ public void mousePressed(MouseEvent mouseEvent) {
195193

196194
textField.setText(path);
197195
}
198-
199-
@Override
200-
public void mouseReleased(MouseEvent mouseEvent) {
201-
}
202-
203-
@Override
204-
public void mouseEntered(MouseEvent mouseEvent) {
205-
}
206-
207-
@Override
208-
public void mouseExited(MouseEvent mouseEvent) {
209-
}
210196
};
211197
}
212198

src/main/java/fr/adrienbrault/idea/symfony2plugin/profiler/ui/ProfilerSettingsDialog.java

Lines changed: 34 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package fr.adrienbrault.idea.symfony2plugin.profiler.ui;
22

33
import com.intellij.openapi.fileChooser.FileChooser;
4+
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
45
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
56
import com.intellij.openapi.options.Configurable;
67
import com.intellij.openapi.options.ConfigurationException;
78
import com.intellij.openapi.project.Project;
9+
import com.intellij.openapi.ui.TextBrowseFolderListener;
810
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
911
import com.intellij.openapi.vfs.VfsUtil;
1012
import com.intellij.openapi.vfs.VirtualFile;
@@ -14,6 +16,7 @@
1416
import org.jetbrains.annotations.Nullable;
1517

1618
import javax.swing.*;
19+
import java.awt.event.ActionEvent;
1720
import java.awt.event.MouseEvent;
1821
import java.awt.event.MouseListener;
1922

@@ -50,7 +53,8 @@ public String getHelpTopic() {
5053
@Nullable
5154
@Override
5255
public JComponent createComponent() {
53-
textLocalProfilerCsvPath.getButton().addMouseListener(new MyMouseListener());
56+
textLocalProfilerCsvPath.addBrowseFolderListener(createBrowseFolderListener(textLocalProfilerCsvPath.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
57+
5458
return mainPanel;
5559
}
5660

@@ -106,49 +110,35 @@ public void disposeUIResources() {
106110

107111
}
108112

109-
private class MyMouseListener implements MouseListener {
110-
@Override
111-
public void mouseClicked(MouseEvent mouseEvent) {
112-
}
113-
114-
@Override
115-
public void mousePressed(MouseEvent mouseEvent) {
116-
VirtualFile projectDirectory = project.getBaseDir();
117-
118-
String text = textLocalProfilerCsvPath.getText();
119-
VirtualFile toSelect = VfsUtil.findRelativeFile(text, projectDirectory);
120-
if(toSelect == null) {
121-
toSelect = projectDirectory;
122-
}
123-
124-
VirtualFile selectedFile = FileChooser.chooseFile(
125-
FileChooserDescriptorFactory.createSingleFileDescriptor("csv"),
126-
project,
127-
toSelect
128-
);
129-
130-
if (null == selectedFile) {
131-
return;
132-
}
133-
134-
String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/');
135-
if (null == path) {
136-
path = selectedFile.getPath();
113+
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
114+
return new TextBrowseFolderListener(fileChooserDescriptor) {
115+
@Override
116+
public void actionPerformed(ActionEvent e) {
117+
VirtualFile projectDirectory = project.getBaseDir();
118+
119+
String text = textField.getText();
120+
VirtualFile toSelect = VfsUtil.findRelativeFile(text, projectDirectory);
121+
if(toSelect == null) {
122+
toSelect = projectDirectory;
123+
}
124+
125+
VirtualFile selectedFile = FileChooser.chooseFile(
126+
FileChooserDescriptorFactory.createSingleFileDescriptor("csv"),
127+
project,
128+
toSelect
129+
);
130+
131+
if (null == selectedFile) {
132+
return;
133+
}
134+
135+
String path = VfsUtil.getRelativePath(selectedFile, projectDirectory, '/');
136+
if (null == path) {
137+
path = selectedFile.getPath();
138+
}
139+
140+
textField.setText(path);
137141
}
138-
139-
textLocalProfilerCsvPath.setText(path);
140-
}
141-
142-
@Override
143-
pu F438 blic void mouseReleased(MouseEvent mouseEvent) {
144-
}
145-
146-
@Override
147-
public void mouseEntered(MouseEvent mouseEvent) {
148-
}
149-
150-
@Override
151-
public void mouseExited(MouseEvent mouseEvent) {
152-
}
142+
};
153143
}
154144
}

src/main/java/fr/adrienbrault/idea/symfony2plugin/templating/util/TwigUtil.java

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@
7474
import java.util.regex.Pattern;
7575
import java.util.stream.Collectors;
7676

77+
import static fr.adrienbrault.idea.symfony2plugin.util.StringUtils.underscore;
78+
7779
/**
7880
* @author Adrien Brault <adrien.brault@gmail.com>
7981
* @author Daniel Espendiller <daniel@espendiller.net>
@@ -150,21 +152,39 @@ public static String[] getControllerMethodShortcut(@NotNull Method method) {
150152
templateFolderName = templateFolderName.replace("\\", "/");
151153

152154
String shortcutName;
155+
String shortcutNameForOldNotation;
153156

154157
// Foobar without (.html.twig)
155158
String templateName = className.substring(0, className.lastIndexOf("Controller"));
156159

157160
if(methodName.equals("__invoke")) {
158-
// AppBundle::Foobar.html.twig
161+
// AppBundle::foo_bar.html.twig
159162
shortcutName = String.format(
163+
"%s::%s%s",
164+
symfonyBundle.getName(),
165+
underscore(templateFolderName),
166+
underscore(templateName)
167+
);
168+
169+
// AppBundle::FooBar.html.twig
170+
shortcutNameForOldNotation = String.format(
160171
"%s::%s%s",
161172
symfonyBundle.getName(),
162173
templateFolderName,
163174
templateName
164175
);
165176
} else {
166-
// FooBundle:Foobar:foobar.html.twig
177+
// FooBundle:foo_bar:foo_bar.html.twig
167178
shortcutName = String.format(
179+
"%s:%s%s:%s",
180+
symfonyBundle.getName(),
181+
underscore(templateFolderName),
182+
underscore(templateName),
183+
underscore(StringUtils.removeEnd(methodName, "Action"))
184+
);
185+
186+
// FooBundle:FooBar:fooBar.html.twig
187+
shortcutNameForOldNotation = String.format(
168188
"%s:%s%s:%s",
169189
symfonyBundle.getName(),
170190
templateFolderName,
@@ -179,6 +199,9 @@ public static String[] getControllerMethodShortcut(@NotNull Method method) {
179199
shortcutName + ".html.twig",
180200
shortcutName + ".json.twig",
181201
shortcutName + ".xml.twig",
202+
shortcutNameForOldNotation + ".html.twig",
203+
shortcutNameForOldNotation + ".json.twig",
204+
shortcutNameForOldNotation + ".xml.twig",
182205
};
183206
}
184207

src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigNamespaceDialog.java

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
55
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
66
import com.intellij.openapi.project.Project;
7+
import com.intellij.openapi.ui.TextBrowseFolderListener;
78
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
89
import com.intellij.openapi.vfs.VfsUtil;
910
import com.intellij.openapi.vfs.VirtualFile;
@@ -58,7 +59,7 @@ public TwigNamespaceDialog(Project project, TableView<TwigPath> tableView) {
5859

5960
buttonCancel.addActionListener(e -> onCancel());
6061

61-
namespacePath.getButton().addMouseListener(createPathButtonMouseListener(namespacePath.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
62+
namespacePath.addBrowseFolderListener(createBrowseFolderListener(namespacePath.getTextField(), FileChooserDescriptorFactory.createSingleFolderDescriptor()));
6263

6364
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
6465
addWindowListener(new WindowAdapter() {
@@ -112,19 +113,15 @@ private void onCancel() {
112113
dispose();
113114
}
114115

115-
private MouseListener createPathButtonMouseListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
116-
return new MouseListener() {
116+
private TextBrowseFolderListener createBrowseFolderListener(final JTextField textField, final FileChooserDescriptor fileChooserDescriptor) {
117+
return new TextBrowseFolderListener(fileChooserDescriptor) {
117118
@Override
118-
public void mouseClicked(MouseEvent mouseEvent) {
119-
}
120-
121-
@Override
122-
public void mousePressed(MouseEvent mouseEvent) {
119+
public void actionPerformed(ActionEvent e) {
123120
VirtualFile projectDirectory = project.getBaseDir();
124121
VirtualFile selectedFile = FileChooser.chooseFile(
125-
fileChooserDescriptor,
126-
project,
127-
VfsUtil.findRelativeFile(textField.getText(), projectDirectory)
122+
fileChooserDescriptor,
123+
project,
124+
VfsUtil.findRelativeFile(textField.getText(), projectDirectory)
128125
);
129126

130127
if (null == selectedFile) {
@@ -138,22 +135,9 @@ public void mousePressed(MouseEvent mouseEvent) {
138135

139136
textField.setText(path);
140137
}
141-
142-
@Override
143-
public void mouseReleased(MouseEvent mouseEvent) {
144-
}
145-
146-
@Override
147-
public void mouseEntered(MouseEvent mouseEvent) {
148-
}
149-
150-
@Override
151-
public void mouseExited(MouseEvent mouseEvent) {
152-
}
153138
};
154139
}
155140

156-
157141
private class ChangeDocumentListener implements DocumentListener {
158142
@Override
159143
public void insertUpdate(DocumentEvent e) {

src/main/java/fr/adrienbrault/idea/symfony2plugin/ui/TwigSettingsForm.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
import com.intellij.openapi.options.Configurable;
44
import com.intellij.openapi.options.ConfigurationException;
5+
import com.intellij.openapi.project.DumbService;
56
import com.intellij.openapi.project.Project;
7+
import com.intellij.openapi.ui.DialogWrapper;
68
import com.intellij.ui.ToolbarDecorator;
79
import com.intellij.ui.table.TableView;
810
import com.intellij.util.ui.ColumnInfo;
@@ -50,6 +52,12 @@ private void attachItems() {
5052
return;
5153
}
5254

55+
if (DumbService.getInstance(project).isDumb()) {
56+
this.tableView.getEmptyText().setText("Not available while indexing. Please re-open this screen when ready.");
57+
58+
return;
59+
}
60+
5361
List<TwigPath> sortableLookupItems = new ArrayList<>(TwigUtil.getTwigNamespaces(this.project, true));
5462
Collections.sort(sortableLookupItems);
5563

src/test/java/fr/adrienbrault/idea/symfony2plugin/tests/templating/util/TwigUtilTest.java

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -422,9 +422,9 @@ public void testGetControllerMethodShortcut() {
422422

423423
List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));
424424

425-
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".html.twig");
426-
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".json.twig");
427-
assertContainsElements(strings, "FooBundle:Foobar:" + string[1] + ".xml.twig");
425+
assertContainsElements(strings, "FooBundle:foobar:" + string[1] + ".html.twig");
426+
assertContainsElements(strings, "FooBundle:foobar:" + string[1] + ".json.twig");
427+
assertContainsElements(strings, "FooBundle:foobar:" + string[1] + ".xml.twig");
428428
}
429429
}
430430

@@ -444,9 +444,30 @@ public void testGetControllerMethodShortcutForInvoke() {
444444

445445
List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));
446446

447-
assertContainsElements(strings, "FooBundle::Foobar.html.twig");
448-
assertContainsElements(strings, "FooBundle::Foobar.json.twig");
449-
assertContainsElements(strings, "FooBundle::Foobar.xml.twig");
447+
assertContainsElements(strings, "FooBundle::foobar.html.twig");
448+
assertContainsElements(strings, "FooBundle::foobar.json.twig");
449+
assertContainsElements(strings, "FooBundle::foobar.xml.twig");
450+
}
451+
452+
public void testGetControllerMethodShortcutForInvokeWithSnakeCase() {
453+
myFixture.copyFileToProject("controller_method.php");
454+
455+
myFixture.configureByText(PhpFileType.INSTANCE, "<?php\n" +
456+
"namespace FooBundle\\Controller;\n" +
457+
"class FooBarController\n" +
458+
"{\n" +
459+
" public function __in<caret>voke() {}\n" +
460+
"" +
461+
"}\n"
462+
);
463+
464+
PsiElement psiElement = myFixture.getFile().findElementAt(myFixture.getCaretOffset());
465+
466+
List<String> strings = Arrays.asList(TwigUtil.getControllerMethodShortcut((Method) psiElement.getParent()));
467+
468+
assertContainsElements(strings, "FooBundle::foo_bar.html.twig");
469+
assertContainsElements(strings, "FooBundle::foo_bar.json.twig");
470+
assertContainsElements(strings, "FooBundle::foo_bar.xml.twig");
450471
}
451472

452473
public void testFindTwigFileController() {

0 commit comments

Comments
 (0)
0