4545import java .util .ArrayList ;
4646import java .util .Collection ;
4747import java .util .Collections ;
48+ import java .util .Enumeration ;
4849import java .util .List ;
4950import java .util .concurrent .ExecutionException ;
5051import java .util .concurrent .Future ;
52+ import java .util .logging .Level ;
53+ import java .util .logging .Logger ;
5154import org .netbeans .modules .php .api .executable .InvalidPhpExecutableException ;
5255import org .netbeans .modules .php .api .phpmodule .PhpModule ;
5356import org .netbeans .modules .php .api .util .StringUtils ;
5457import org .netbeans .modules .php .phpcsfixer .commands .PhpCsFixer ;
58+ import org .openide .*;
5559import org .openide .awt .ActionID ;
5660import org .openide .awt .ActionRegistration ;
5761import org .openide .filesystems .FileObject ;
5862import org .openide .filesystems .FileUtil ;
63+ import org .openide .loaders .DataObject ;
64+ import org .openide .loaders .DataObjectNotFoundException ;
5965import org .openide .util .Exceptions ;
6066import org .openide .util .Lookup ;
6167import org .openide .util .NbBundle ;
7682public class FixAction extends PhpCsFixerBaseAction {
7783
7884 private static final long serialVersionUID = -3347012049948024185L ;
85+ private static final Logger LOGGER = Logger .getLogger (FixAction .class .getName ());
7986
8087 @ NbBundle .Messages ("FixAction.name=Fix" )
8188 @ Override
@@ -85,11 +92,46 @@ protected String getName() {
8592
8693 @ Override
8794 protected void runCommand (PhpModule phpModule , List <String > options ) throws InvalidPhpExecutableException {
88- for (FileObject target : getTargetFiles ()) {
95+ Collection <? extends FileObject > targetFiles = getTargetFiles ();
96+ for (FileObject target : targetFiles ) {
97+ if (target .isFolder ()) {
98+ Enumeration <? extends FileObject > children = target .getChildren (true );
99+ while (children .hasMoreElements ()) {
100+ if (isModifiedFile (children .nextElement ())) {
101+ return ;
102+ }
103+ }
104+ } else {
105+ if (isModifiedFile (target )) {
106+ return ;
107+ }
108+ }
89109 runCommand (phpModule , options , target );
90110 }
91111 }
92112
113+ @ NbBundle .Messages ({
114+ "# {0} - file name" ,
115+ "FixAction.message.modified.file=There is a modified file({0})."
116+ })
117+ private boolean isModifiedFile (FileObject target ) {
118+ try {
119+ DataObject dataObject = DataObject .find (target );
120+ if (!target .isFolder () && dataObject .isModified ()) {
121+ // show message
122+ NotifyDescriptor descriptor = new NotifyDescriptor .Message (
123+ Bundle .FixAction_message_modified_file (target .getNameExt ()),
124+ NotifyDescriptor .ERROR_MESSAGE
125+ );
126+ DialogDisplayer .getDefault ().notifyLater (descriptor );
127+ return true ;
128+ }
129+ }catch (DataObjectNotFoundException ex ) {
130+ LOGGER .log (Level .WARNING , null , ex );
131+ }
132+ return false ;
133+ }
134+
93135 @ Override
94136 public void runCommand (PhpModule phpModule , List <String > options , FileObject targetFile ) throws InvalidPhpExecutableException {
95137 List <String > params = getAllParams (targetFile , options );
0 commit comments