Skip to content

Commit 9da27a5

Browse files
committed
Support for code completion for AppController fields #50
1 parent bb0fdd1 commit 9da27a5

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

src/org/cakephp/netbeans/editor/CakePhpEditorExtender.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,15 @@ public List<PhpBaseElement> getElementsForCodeCompletion(FileObject fo) {
106106
List<PhpBaseElement> elements;
107107
elements = new LinkedList<PhpBaseElement>();
108108

109+
// get AppController
110+
CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule);
111+
FileObject appController = cakeModule.getFile(DIR_TYPE.APP, CakePhpModule.FILE_TYPE.CONTROLLER, "App", null);
112+
if (appController != null) {
113+
for (PhpClass phpClass : parseFields(appController)) {
114+
elements.add(new PhpVariable("$this", phpClass, fo, 0)); // NOI18N
115+
}
116+
}
117+
109118
for (PhpClass phpClass : parseFields(fo)) {
110119
if (isView || isHelper) {
111120
addDefaultHelpers(phpClass, fo);
@@ -220,6 +229,15 @@ private PhpClass getPhpClass(FileObject fo) {
220229
if (CakePhpUtils.isComponent(fo)) {
221230
return getComponentPhpClass();
222231
} else if (CakePhpUtils.isController(fo)) {
232+
// get AppController fields info.
233+
String name = fo.getName();
234+
name = CakePhpUtils.toUnderscoreCase(name);
235+
if ("app_controller".equals(name)) { // NOI18N
236+
FileObject currentFileObject = CakePhpUtils.getCurrentFileObject();
237+
if (currentFileObject != null && CakePhpUtils.isView(currentFileObject)) {
238+
return getViewPhpClass();
239+
}
240+
}
223241
return getControllerPhpClass();
224242
} else if (CakePhpUtils.isCtpFile(fo)) {
225243
return getViewPhpClass();

src/org/cakephp/netbeans/editor/visitors/CakePhpControllerVisitor.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,17 @@ public void visit(ExpressionStatement node) {
202202
@Override
203203
public Set<String> getFieldNames() {
204204
Set<String> fieldNames = new HashSet<String>();
205+
206+
// get AppController fields info.
207+
String name = CakePhpUtils.toUnderscoreCase(targetFile.getName());
208+
if ("app_controller".equals(name)) { // NOI18N
209+
FileObject currentFileObject = CakePhpUtils.getCurrentFileObject();
210+
if (currentFileObject != null && CakePhpUtils.isView(currentFileObject)) {
211+
fieldNames.add(HELPERS);
212+
return fieldNames;
213+
}
214+
}
215+
205216
if (isController) {
206217
fieldNames.add(USES);
207218
fieldNames.add(COMPONENTS);

src/org/cakephp/netbeans/util/CakePhpUtils.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,13 @@
4646
import java.util.Comparator;
4747
import java.util.List;
4848
import java.util.regex.Pattern;
49+
import javax.swing.text.Document;
50+
import javax.swing.text.JTextComponent;
4951
import org.cakephp.netbeans.CakePhp;
5052
import org.cakephp.netbeans.CakePhpFrameworkProvider;
5153
import org.cakephp.netbeans.module.CakePhpModule;
54+
import org.netbeans.api.editor.EditorRegistry;
55+
import org.netbeans.modules.editor.NbEditorUtilities;
5256
import org.netbeans.modules.php.api.editor.EditorSupport;
5357
import org.netbeans.modules.php.api.editor.PhpBaseElement;
5458
import org.netbeans.modules.php.api.editor.PhpClass;
@@ -383,4 +387,15 @@ public static String[] pluginSplit(String name) {
383387
}
384388
return new String[]{name};
385389
}
390+
391+
public static FileObject getCurrentFileObject() {
392+
JTextComponent editor = EditorRegistry.lastFocusedComponent();
393+
if (editor != null) {
394+
Document document = editor.getDocument();
395+
if (document != null) {
396+
return NbEditorUtilities.getFileObject(document);
397+
}
398+
}
399+
return null;
400+
}
386401
}

0 commit comments

Comments
 (0)