Skip to content

Commit 47219ce

Browse files
committed
Show a message dialog when there is a modified file.
1 parent 0a596c6 commit 47219ce

File tree

2 files changed

+51
-1
lines changed

2 files changed

+51
-1
lines changed

nbproject/project.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,14 @@
112112
<specification-version>7.55.1</specification-version>
113113
</run-dependency>
114114
</dependency>
115+
<dependency>
116+
<code-name-base>org.openide.dialogs</code-name-base>
117+
<build-prerequisite/>
118+
<compile-dependency/>
119+
<run-dependency>
120+
<specification-version>7.42.1</specification-version>
121+
</run-dependency>
122+
</dependency>
115123
<dependency>
116124
<code-name-base>org.openide.filesystems</code-name-base>
117125
<build-prerequisite/>

src/org/netbeans/modules/php/phpcsfixer/ui/actions/FixAction.java

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,23 @@
4545
import java.util.ArrayList;
4646
import java.util.Collection;
4747
import java.util.Collections;
48+
import java.util.Enumeration;
4849
import java.util.List;
4950
import java.util.concurrent.ExecutionException;
5051
import java.util.concurrent.Future;
52+
import java.util.logging.Level;
53+
import java.util.logging.Logger;
5154
import org.netbeans.modules.php.api.executable.InvalidPhpExecutableException;
5255
import org.netbeans.modules.php.api.phpmodule.PhpModule;
5356
import org.netbeans.modules.php.api.util.StringUtils;
5457
import org.netbeans.modules.php.phpcsfixer.commands.PhpCsFixer;
58+
import org.openide.*;
5559
import org.openide.awt.ActionID;
5660
import org.openide.awt.ActionRegistration;
5761
import org.openide.filesystems.FileObject;
5862
import org.openide.filesystems.FileUtil;
63+
import org.openide.loaders.DataObject;
64+
import org.openide.loaders.DataObjectNotFoundException;
5965
import org.openide.util.Exceptions;
6066
import org.openide.util.Lookup;
6167
import org.openide.util.NbBundle;
@@ -76,6 +82,7 @@
7682
public 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

Comments
 (0)