Skip to content

Commit bb0fdd1

Browse files
committed
Fix #52 Autocompleting elements doesn't work
1 parent 2f90f0e commit bb0fdd1

File tree

1 file changed

+32
-32
lines changed

1 file changed

+32
-32
lines changed

src/org/cakephp/netbeans/editor/codecompletion/methods/ElementMethod.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
import java.util.Collections;
4646
import java.util.List;
4747
import org.cakephp.netbeans.module.CakePhpModule;
48+
import org.cakephp.netbeans.module.CakePhpModule.FILE_TYPE;
4849
import org.cakephp.netbeans.util.CakePhpUtils;
4950
import org.cakephp.netbeans.util.CakeVersion;
5051
import org.netbeans.modules.php.api.phpmodule.PhpModule;
@@ -105,16 +106,9 @@ public List<String> getElements(int argCount, String inputValue) {
105106
// for CakePHP 2.1+
106107
if (isPlugin && cakeVersion >= 2) {
107108
for (CakePhpModule.DIR_TYPE dirType : PLUGINS) {
108-
FileObject viewDirectory = cakeModule.getViewDirectory(dirType, pluginName);
109-
if (viewDirectory != null) {
110-
FileObject elementsDirectory = viewDirectory.getFileObject(getRelativePath());
111-
if (elementsDirectory != null) {
112-
for (FileObject element : elementsDirectory.getChildren()) {
113-
addElement(element, filter, elements, pluginName);
114-
}
115-
}
116-
break;
117-
}
109+
FileObject elementsDirectory = cakeModule.getDirectory(dirType, FILE_TYPE.ELEMENT, pluginName);
110+
addElements(elementsDirectory, filter, elements, pluginName);
111+
break;
118112
}
119113
return elements;
120114
}
@@ -126,16 +120,9 @@ public List<String> getElements(int argCount, String inputValue) {
126120
currentPluginName = null;
127121
}
128122

129-
// get view directory
130-
FileObject viewDirectory = cakeModule.getViewDirectory(currentDirType, currentPluginName);
131-
if (viewDirectory != null) {
132-
FileObject elementDirectory = viewDirectory.getFileObject(getRelativePath());
133-
if (elementDirectory != null) {
134-
for (FileObject child : elementDirectory.getChildren()) {
135-
addElement(child, filter, elements);
136-
}
137-
}
138-
}
123+
// get element directory
124+
FileObject elementsDirectory = cakeModule.getDirectory(currentDirType, FILE_TYPE.ELEMENT, currentPluginName);
125+
addElements(elementsDirectory, filter, elements);
139126

140127
if (!subDirectoryPath.isEmpty()) {
141128
return elements;
@@ -150,7 +137,7 @@ public List<String> getElements(int argCount, String inputValue) {
150137
for (FileObject child : pluginDirectory.getChildren()) {
151138
if (child.isFolder()) {
152139
String name = child.getNameExt();
153-
viewDirectory = cakeModule.getViewDirectory(dirType, name);
140+
FileObject viewDirectory = cakeModule.getViewDirectory(dirType, name);
154141
if (viewDirectory != null && viewDirectory.getFileObject(ELEMENTS) != null) {
155142
if (name.startsWith(filter)) {
156143
name = name + DOT;
@@ -167,22 +154,35 @@ public List<String> getElements(int argCount, String inputValue) {
167154
}
168155

169156
/**
170-
* Add element starting with filter value to list.
157+
* Add elements starting with filter value to list.
171158
*
172-
* @param fo FileObject for adding
159+
* @param elementsDirectory FileObject for adding
173160
* @param filter filtering with this value
174161
* @param elements List for adding (add to this)
175-
* @return true if add, otherwise false
162+
* @param pluginName plugin name
176163
*/
177-
private boolean addElement(FileObject fo, String filter, List<String> elements) {
178-
return addElement(fo, filter, elements, null);
179-
}
164+
private void addElements(FileObject elementsDirectory, String filter, List<String> elements, String pluginName) {
165+
if (elementsDirectory != null) {
166+
if (!subDirectoryPath.isEmpty()) {
167+
elementsDirectory = elementsDirectory.getFileObject(subDirectoryPath);
168+
}
180169

181-
private String getRelativePath() {
182-
String subPath = ELEMENTS;
183-
if (!subDirectoryPath.isEmpty()) {
184-
subPath = subPath + SLASH + subDirectoryPath;
170+
if (elementsDirectory != null) {
171+
for (FileObject child : elementsDirectory.getChildren()) {
172+
addElement(child, filter, elements, pluginName);
173+
}
174+
}
185175
}
186-
return subPath;
176+
}
177+
178+
/**
179+
* Add elements starting with filter value to list.
180+
*
181+
* @param elementsDirectory FileObject for adding
182+
* @param filter filtering with this value
183+
* @param elements List for adding (add to this)
184+
*/
185+
private void addElements(FileObject elementsDirectory, String filter, List<String> elements) {
186+
addElements(elementsDirectory, filter, elements, null);
187187
}
188188
}

0 commit comments

Comments
 (0)