45
45
import java .util .Collections ;
46
46
import java .util .List ;
47
47
import org .cakephp .netbeans .module .CakePhpModule ;
48
+ import org .cakephp .netbeans .module .CakePhpModule .FILE_TYPE ;
48
49
import org .cakephp .netbeans .util .CakePhpUtils ;
49
50
import org .cakephp .netbeans .util .CakeVersion ;
50
51
import org .netbeans .modules .php .api .phpmodule .PhpModule ;
@@ -105,16 +106,9 @@ public List<String> getElements(int argCount, String inputValue) {
105
106
// for CakePHP 2.1+
106
107
if (isPlugin && cakeVersion >= 2 ) {
107
108
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 ;
118
112
}
119
113
return elements ;
120
114
}
@@ -126,16 +120,9 @@ public List<String> getElements(int argCount, String inputValue) {
126
120
currentPluginName = null ;
127
121
}
128
122
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 );
139
126
140
127
if (!subDirectoryPath .isEmpty ()) {
141
128
return elements ;
@@ -150,7 +137,7 @@ public List<String> getElements(int argCount, String inputValue) {
150
137
for (FileObject child : pluginDirectory .getChildren ()) {
151
138
if (child .isFolder ()) {
152
139
String name = child .getNameExt ();
153
- viewDirectory = cakeModule .getViewDirectory (dirType , name );
140
+ FileObject viewDirectory = cakeModule .getViewDirectory (dirType , name );
154
141
if (viewDirectory != null && viewDirectory .getFileObject (ELEMENTS ) != null ) {
155
142
if (name .startsWith (filter )) {
156
143
name = name + DOT ;
@@ -167,22 +154,35 @@ public List<String> getElements(int argCount, String inputValue) {
167
154
}
168
155
169
156
/**
170
- * Add element starting with filter value to list.
157
+ * Add elements starting with filter value to list.
171
158
*
172
- * @param fo FileObject for adding
159
+ * @param elementsDirectory FileObject for adding
173
160
* @param filter filtering with this value
174
161
* @param elements List for adding (add to this)
175
- * @return true if add, otherwise false
162
+ * @param pluginName plugin name
176
163
*/
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
+ }
180
169
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
+ }
185
175
}
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 );
187
187
}
188
188
}
0 commit comments