Skip to content

Commit 1e4e0bd

Browse files
committed
Merge branch 'netbeans73dev' into netbeans73
2 parents 80bc976 + e38167f commit 1e4e0bd

18 files changed

+704
-155
lines changed

README.md

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ This plugin provides support for CakePHP.
1717

1818
## About CakePHP 3.x
1919

20-
This plugin recognizes CakePHP3. But many features might not work yet.
20+
Currently, This plugin doesn't recognize CakePHP3.
2121

2222
## WHAT WORKS
2323

@@ -82,16 +82,10 @@ CakePHP 2.x
8282
NewProject (Ctrl + Shift + N) > PHP > PHP Application with Existing Source
8383
Please select your cakephp dir(e.g. /home/NetBeansProjects/myproject)
8484

85-
### App Directory Name
85+
### App Directory Path
8686

87-
Multiple app directory names support.
88-
89-
#### Change app directory name
90-
91-
Please set the following if you would like to different app directory name.
92-
93-
1. Project properties > Framework > CakePHP
94-
2. `app Folder name` : please set your new app folder name
87+
You can set app directory path from source directory.
88+
Project properties > Framework > CakePHP > Custom directory path > app
9589

9690
#### Use multiple app directories
9791

@@ -146,8 +140,8 @@ myproject(e.g. myapp)
146140
```
147141

148142
1. Project properties > Framework > CakePHP
149-
2. Check `Use the relative path to the CakePHP directory from the project directory.`
150-
3. `CakePHP Directory` : "../"
143+
2. `app` : "" (empty or ".")
144+
3. `CakePHP Root` : "../"
151145

152146
Please notice that Code Completion is not available. You have to add the cakephp core path to include path.
153147

manifest.mf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ Manifest-Version: 1.0
22
OpenIDE-Module: org.cakephp.netbeans
33
OpenIDE-Module-Layer: org/cakephp/netbeans/resources/layer.xml
44
OpenIDE-Module-Localizing-Bundle: org/cakephp/netbeans/resources/Bundle.properties
5-
OpenIDE-Module-Specification-Version: 0.9.5
5+
OpenIDE-Module-Specification-Version: 0.9.6

src/org/cakephp/netbeans/CakePhpFrameworkProvider.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@
5151
import org.cakephp.netbeans.editor.codecompletion.CakePhpEditorExtenderFactory;
5252
import org.cakephp.netbeans.module.CakePhpModule;
5353
import org.cakephp.netbeans.module.CakePhpModule.DIR_TYPE;
54+
import org.cakephp.netbeans.preferences.CakePreferences;
5455
import org.netbeans.modules.php.api.framework.BadgeIcon;
5556
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5657
import org.netbeans.modules.php.api.phpmodule.PhpModuleProperties;
@@ -102,11 +103,14 @@ public BadgeIcon getBadgeIcon() {
102103

103104
@Override
104105
public boolean isInPhpModule(PhpModule phpModule) {
105-
CakePhpModule module = CakePhpModule.forPhpModule(phpModule);
106-
if (module == null) {
107-
return false;
106+
Boolean enabled = CakePreferences.isEnabled(phpModule);
107+
if (enabled != null) {
108+
// manually
109+
return enabled;
108110
}
109-
return module.isInCakePhp();
111+
// automatically
112+
CakePhpModule cakeModule = CakePhpModule.forPhpModule(phpModule);
113+
return cakeModule == null ? false : cakeModule.isInCakePhp();
110114
}
111115

112116
@Override
@@ -115,7 +119,7 @@ public File[] getConfigurationFiles(PhpModule phpModule) {
115119
List<File> configFiles = new LinkedList<File>();
116120
FileObject config = CakePhpModule.forPhpModule(phpModule).getConfigDirectory(DIR_TYPE.APP);
117121
assert config != null : "app/config or app/Config not found for CakePHP project " + phpModule.getDisplayName();
118-
if (config != null && config.isFolder()) {
122+
if (config.isFolder()) {
119123
Enumeration<? extends FileObject> children = config.getChildren(true);
120124
while (children.hasMoreElements()) {
121125
FileObject child = children.nextElement();

src/org/cakephp/netbeans/CakePhpModuleCustomizerExtender.java

Lines changed: 62 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,14 @@
4444
import java.util.EnumSet;
4545
import javax.swing.JComponent;
4646
import javax.swing.event.ChangeListener;
47+
import org.cakephp.netbeans.module.CakePhpModule;
4748
import org.cakephp.netbeans.preferences.CakePreferences;
4849
import org.cakephp.netbeans.ui.customizer.CakePhpCustomizerPanel;
50+
import org.cakephp.netbeans.validator.CakePhpCustomizerValidator;
4951
import org.netbeans.modules.php.api.phpmodule.PhpModule;
52+
import org.netbeans.modules.php.api.validation.ValidationResult;
5053
import org.netbeans.modules.php.spi.framework.PhpModuleCustomizerExtender;
54+
import org.openide.filesystems.FileObject;
5155
import org.openide.util.ChangeSupport;
5256
import org.openide.util.HelpCtx;
5357
import org.openide.util.NbBundle;
@@ -61,19 +65,24 @@ public class CakePhpModuleCustomizerExtender extends PhpModuleCustomizerExtender
6165
private CakePhpCustomizerPanel component;
6266
private final String appDirectoryPath;
6367
private final String cakePhpDirPath;
64-
private final boolean isProjectDir;
6568
private final boolean isShowPopupForOneItem;
6669
private final boolean originalAutoCreateState;
6770
private final boolean originalIgnoreTmpDirectory;
71+
private final boolean isEnabled;
6872
private ChangeSupport changeSupport = new ChangeSupport(this);
73+
private String errorMessage;
74+
private boolean isValid;
75+
private final PhpModule phpModule;
6976

7077
CakePhpModuleCustomizerExtender(PhpModule phpModule) {
78+
this.phpModule = phpModule;
7179
originalAutoCreateState = CakePreferences.getAutoCreateView(phpModule);
7280
cakePhpDirPath = CakePreferences.getCakePhpDirPath(phpModule);
73-
isProjectDir = CakePreferences.useProjectDirectory(phpModule);
7481
originalIgnoreTmpDirectory = CakePreferences.ignoreTmpDirectory(phpModule);
7582
isShowPopupForOneItem = CakePreferences.isShowPopupForOneItem(phpModule);
7683
appDirectoryPath = CakePreferences.getAppDirectoryPath(phpModule);
84+
Boolean enabled = CakePreferences.isEnabled(phpModule);
85+
isEnabled = enabled == null ? false : enabled;
7786
}
7887

7988
@Override
@@ -83,12 +92,18 @@ public String getDisplayName() {
8392

8493
@Override
8594
public void addChangeListener(ChangeListener listener) {
86-
changeSupport.addChangeListener(listener);
95+
if (listener instanceof CakePhpModule) {
96+
changeSupport.addChangeListener(listener);
97+
}
98+
getPanel().addChangeListener(listener);
8799
}
88100

89101
@Override
90102
public void removeChangeListener(ChangeListener listener) {
91-
changeSupport.removeChangeListener(listener);
103+
if (listener instanceof CakePhpModule) {
104+
changeSupport.removeChangeListener(listener);
105+
}
106+
getPanel().removeChangeListener(listener);
92107
}
93108

94109
@Override
@@ -103,31 +118,33 @@ public HelpCtx getHelp() {
103118

104119
@Override
105120
public boolean isValid() {
106-
return true;
121+
validate();
122+
return isValid;
107123
}
108124

109125
@Override
110126
public String getErrorMessage() {
111-
return null;
127+
validate();
128+
return errorMessage;
112129
}
113130

114-
public void fireChange() {
131+
void fireChange() {
115132
changeSupport.fireChange();
116133
}
117134

118135
@Override
119136
public EnumSet<Change> save(PhpModule phpModule) {
120137
EnumSet<Change> enumset = EnumSet.of(Change.FRAMEWORK_CHANGE);
121138
boolean newAutoCreateState = getPanel().isAutoCreateView();
122-
String newCakePhpDirPath = getPanel().getCakePhpDirTextField();
139+
String newCakePhpDirPath = getPanel().getCakePhpDirPath();
123140
boolean newIgnoreTmpDirectory = getPanel().ignoreTmpDirectory();
124141
String newAppDirectoryPath = getPanel().getAppDirectoryPath();
125142

126143
if (newAutoCreateState != originalAutoCreateState) {
127144
CakePreferences.setAutoCreateView(phpModule, newAutoCreateState);
128145
}
129-
if (isProjectDir != getPanel().isUseProjectDirectory()) {
130-
CakePreferences.setUseProjectDirectory(phpModule, !isProjectDir);
146+
if (isEnabled != getPanel().isEnabledCakePhp()) {
147+
CakePreferences.setEnabled(phpModule, !isEnabled);
131148
}
132149
if (isShowPopupForOneItem != getPanel().isShowPopupForOneItem()) {
133150
CakePreferences.setShowPopupForOneItem(phpModule, !isShowPopupForOneItem);
@@ -150,12 +167,45 @@ private CakePhpCustomizerPanel getPanel() {
150167
if (component == null) {
151168
component = new CakePhpCustomizerPanel();
152169
component.setAutoCreateView(originalAutoCreateState);
153-
component.setCakePhpDirTextField(cakePhpDirPath);
154-
component.setUseProjectDirectory(isProjectDir);
170+
component.setCakePhpDirPath(cakePhpDirPath);
155171
component.setIgnoreTmpDirectory(originalIgnoreTmpDirectory);
156172
component.setShowPopupForOneItem(isShowPopupForOneItem);
157173
component.setAppDirectoryPath(appDirectoryPath);
174+
component.setEnabledCakePhp(isEnabled);
158175
}
159176
return component;
160177
}
178+
179+
@NbBundle.Messages("CakePhpModuleCustomizerExtender.error.source.invalid=Can't find source directory. Project might be broken.")
180+
void validate() {
181+
CakePhpCustomizerPanel panel = getPanel();
182+
if (!panel.isEnabledCakePhp()) {
183+
isValid = true;
184+
errorMessage = null;
185+
return;
186+
}
187+
188+
// get source directory
189+
FileObject sourceDirectory = phpModule.getSourceDirectory();
190+
if (sourceDirectory == null) {
191+
// broken project
192+
isValid = false;
193+
errorMessage = Bundle.CakePhpModuleCustomizerExtender_error_source_invalid();
194+
return;
195+
}
196+
197+
// validate
198+
CakePhpCustomizerValidator validator = new CakePhpCustomizerValidator()
199+
.validateCakePhpPath(sourceDirectory, panel.getCakePhpDirPath())
200+
.validateAppPath(sourceDirectory, panel.getAppDirectoryPath());
201+
ValidationResult result = validator.getResult();
202+
if (result.hasWarnings()) {
203+
isValid = false;
204+
errorMessage = result.getWarnings().get(0).getMessage();
205+
return;
206+
}
207+
// no problem
208+
isValid = true;
209+
errorMessage = null;
210+
}
161211
}

0 commit comments

Comments
 (0)