4545import javax .swing .AbstractAction ;
4646import javax .swing .JMenu ;
4747import javax .swing .JMenuItem ;
48+ import org .netbeans .api .project .FileOwnerQuery ;
49+ import org .netbeans .api .project .Project ;
4850import org .netbeans .modules .php .api .phpmodule .PhpModule ;
4951import org .netbeans .modules .php .api .util .StringUtils ;
5052import org .netbeans .modules .php .phpcsfixer .options .PhpCsFixerOptions ;
53+ import org .netbeans .spi .project .ui .support .ProjectConvertors ;
5154import org .openide .awt .ActionID ;
5255import org .openide .awt .ActionReference ;
5356import org .openide .awt .ActionReferences ;
6871@ ActionRegistration (
6972 displayName = "#PhpCsFixerActionsFactory.name" , lazy = false )
7073@ ActionReferences ({
71- @ ActionReference (path = "Loaders/folder/any/Actions" , position = 1600 ),
72- @ ActionReference (path = "Loaders/text/x-php5/Actions" , position = 1600 ),
73- @ ActionReference (path = "Editors/text/x-php5/Popup" , position = 600 ),
74- @ ActionReference (path = "Projects/org-netbeans-modules-php-project/Actions" , position = 1100 )
74+ @ ActionReference (path = "Loaders/folder/any/Actions" , position = 1690 ),
75+ @ ActionReference (path = "Loaders/text/x-php5/Actions" , position = 1690 ),
76+ @ ActionReference (path = "Editors/text/x-php5/Popup" , position = 590 ),
77+ @ ActionReference (path = "Projects/org-netbeans-modules-php-project/Actions" , position = 1090 )
7578})
7679@ NbBundle .Messages ("PhpCsFixerActionsFactory.name=PHP CS Fixer" )
7780public class PhpCsFixerActionsFactory extends AbstractAction implements Presenter .Popup {
@@ -87,7 +90,7 @@ public void actionPerformed(ActionEvent e) {
8790 @ Override
8891 public JMenuItem getPopupPresenter () {
8992 if (!isInPhpModule ()) {
90- return null ;
93+ return new JMenuItem () ;
9194 }
9295 String phpCsFixerPath = PhpCsFixerOptions .getInstance ().getPhpCsFixerPath ();
9396 if (StringUtils .isEmpty (phpCsFixerPath )) {
@@ -107,7 +110,21 @@ private boolean isInPhpModule() {
107110 if (target == null ) {
108111 return false ;
109112 }
110- PhpModule phpModule = PhpModule .Factory .forFileObject (target );
113+ if (!target .isFolder ()) {
114+ return true ;
115+ }
116+ Project nonConvertorOwner = ProjectConvertors .getNonConvertorOwner (target );
117+ if (nonConvertorOwner == null ) {
118+ nonConvertorOwner = FileOwnerQuery .getOwner (target );
119+ if (nonConvertorOwner == null ) {
120+ return false ;
121+ }
122+ }
123+ PhpModule phpModule = PhpModule .Factory .lookupPhpModule (nonConvertorOwner );
124+ if (phpModule != null ) {
125+ return true ;
126+ }
127+ phpModule = PhpModule .Factory .forFileObject (target );
111128 return phpModule != null ;
112129 }
113130
0 commit comments