41
41
*/
42
42
package org .netbeans .modules .php .wordpress .ui .actions ;
43
43
44
+ import org .netbeans .api .options .OptionsDisplayer ;
44
45
import org .netbeans .modules .php .api .phpmodule .PhpModule ;
46
+ import org .netbeans .modules .php .api .util .StringUtils ;
45
47
import org .netbeans .modules .php .spi .framework .actions .RunCommandAction ;
46
48
import org .netbeans .modules .php .wordpress .WordPressPhpProvider ;
49
+ import org .netbeans .modules .php .wordpress .commands .WordPressCli ;
50
+ import org .netbeans .modules .php .wordpress .ui .options .WordPressOptions ;
47
51
import org .netbeans .modules .php .wordpress .util .WPUtils ;
52
+ import org .openide .DialogDisplayer ;
53
+ import org .openide .NotifyDescriptor ;
48
54
import org .openide .util .NbBundle ;
49
55
50
56
/**
54
60
public class WordPressRunCommandAction extends RunCommandAction {
55
61
56
62
private static final WordPressRunCommandAction INSTANCE = new WordPressRunCommandAction ();
63
+ private static final long serialVersionUID = 158739462398606689L ;
57
64
58
65
private WordPressRunCommandAction () {
59
66
}
@@ -67,6 +74,16 @@ public void actionPerformed(PhpModule phpModule) {
67
74
if (!WPUtils .isWP (phpModule )) {
68
75
return ;
69
76
}
77
+ String wpCliPath = WordPressOptions .getInstance ().getWpCliPath ();
78
+ if (StringUtils .isEmpty (wpCliPath )) {
79
+ openOptionsPanel (Bundle .WordPressRunCommandAction_message_no_wp_cli ());
80
+ return ;
81
+ }
82
+ String error = WordPressCli .validate (wpCliPath );
83
+ if (error != null ) {
84
+ openOptionsPanel (Bundle .WordPressRunCommandAction_message_invalid_wp_cli ());
85
+ return ;
86
+ }
70
87
WordPressPhpProvider .getInstance ().getFrameworkCommandSupport (phpModule ).openPanel ();
71
88
}
72
89
@@ -79,4 +96,17 @@ protected String getFullName() {
79
96
return Bundle .WordPressRunCommandAction_name (getPureName ());
80
97
}
81
98
99
+ @ NbBundle .Messages ({
100
+ "WordPressRunCommandAction.message.no.wp-cli=Please set wp-cli path." ,
101
+ "WordPressRunCommandAction.message.invalid.wp-cli=Please set valid wp-cli path."
102
+ })
103
+ private void openOptionsPanel (String errorMessage ) {
104
+ NotifyDescriptor .Message message = new NotifyDescriptor .Message (
105
+ errorMessage ,
106
+ NotifyDescriptor .ERROR_MESSAGE
107
+ );
108
+ DialogDisplayer .getDefault ().notify (message );
109
+ OptionsDisplayer .getDefault ().open (WordPressOptions .getOptionsPath ());
110
+ }
111
+
82
112
}
0 commit comments