4141 */
4242package org .netbeans .modules .php .wordpress .ui .actions ;
4343
44+ import org .netbeans .api .options .OptionsDisplayer ;
4445import org .netbeans .modules .php .api .phpmodule .PhpModule ;
46+ import org .netbeans .modules .php .api .util .StringUtils ;
4547import org .netbeans .modules .php .spi .framework .actions .RunCommandAction ;
4648import 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 ;
4751import org .netbeans .modules .php .wordpress .util .WPUtils ;
52+ import org .openide .DialogDisplayer ;
53+ import org .openide .NotifyDescriptor ;
4854import org .openide .util .NbBundle ;
4955
5056/**
5460public class WordPressRunCommandAction extends RunCommandAction {
5561
5662 private static final WordPressRunCommandAction INSTANCE = new WordPressRunCommandAction ();
63+ private static final long serialVersionUID = 158739462398606689L ;
5764
5865 private WordPressRunCommandAction () {
5966 }
@@ -67,6 +74,16 @@ public void actionPerformed(PhpModule phpModule) {
6774 if (!WPUtils .isWP (phpModule )) {
6875 return ;
6976 }
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+ }
7087 WordPressPhpProvider .getInstance ().getFrameworkCommandSupport (phpModule ).openPanel ();
7188 }
7289
@@ -79,4 +96,17 @@ protected String getFullName() {
7996 return Bundle .WordPressRunCommandAction_name (getPureName ());
8097 }
8198
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+
82112}
0 commit comments