Skip to content

Commit 09ae385

Browse files
committed
Add a new option for an output window #28
1 parent 231e850 commit 09ae385

File tree

7 files changed

+110
-27
lines changed

7 files changed

+110
-27
lines changed

nbproject/project.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@
119119
<specification-version>9.6.1</specification-version>
120120
</run-dependency>
121121
</dependency>
122+
<dependency>
123+
<code-name-base>org.openide.io</code-name-base>
124+
<build-prerequisite/>
125+
<compile-dependency/>
126+
<run-dependency>
127+
<specification-version>1.49.1</specification-version>
128+
</run-dependency>
129+
</dependency>
122130
<dependency>
123131
<code-name-base>org.openide.loaders</code-name-base>
124132
<build-prerequisite/>

src/org/netbeans/modules/php/phpcsfixer/commands/PhpCsFixer.java

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
import org.openide.filesystems.FileObject;
5757
import org.openide.filesystems.FileUtil;
5858
import org.openide.util.NbBundle;
59+
import org.openide.windows.InputOutput;
5960

6061
/**
6162
* @see https://github.com/FriendsOfPHP/PHP-CS-Fixer
@@ -68,6 +69,7 @@ public final class PhpCsFixer {
6869
public static final String NAME_LONG = NAME + ".phar"; // NOI18N
6970
public static final String DOWNLOAD_URL = "http://get.sensiolabs.org/php-cs-fixer.phar"; // NOI18N
7071
private final String phpcsfixerPath;
72+
private boolean isDryRun;
7173
// commands
7274
private static final String FIX_COMMAND = "fix"; // NOI18N
7375
private static final String SELF_UPDATE_COMMAND = "self-update"; // NOI18N
@@ -83,8 +85,20 @@ public final class PhpCsFixer {
8385
"--ansi", // NOI18N
8486
"--no-interaction"); // NOI18N
8587

88+
private static final ExecutionDescriptor DEFAULT_EXECUTION_DESCRIPTOR = new ExecutionDescriptor()
89+
.optionsPath(PhpCsFixerOptionsPanelController.getOptionsPath())
90+
.controllable(true)
91+
.frontWindow(true)
92+
.frontWindowOnError(true)
93+
.inputVisible(false)
94+
.showProgress(true);
95+
96+
private static final ExecutionDescriptor NO_OUTPUT_EXECUTION_DESCRIPTOR = new ExecutionDescriptor()
97+
.inputOutput(InputOutput.NULL);
98+
8699
public PhpCsFixer(String phpcsfixerPath) {
87100
this.phpcsfixerPath = phpcsfixerPath;
101+
isDryRun = false;
88102
}
89103

90104
public static PhpCsFixer getDefault() throws InvalidPhpExecutableException {
@@ -110,6 +124,7 @@ public Future<Integer> fix(PhpModule phpModule, String... params) {
110124
}
111125

112126
public Future<Integer> fixDryRun(PhpModule phpModule, String... params) {
127+
isDryRun = true;
113128
List<String> allParams = new ArrayList<>(params.length + 1);
114129
allParams.addAll(Arrays.asList(params));
115130
allParams.add(DRY_RUN_PARAM);
@@ -157,9 +172,13 @@ private PhpExecutable getPhpExecutable(PhpModule phpModule, String title) {
157172
}
158173

159174
private ExecutionDescriptor getDescriptor(PhpModule phpModule) {
160-
ExecutionDescriptor descriptor = PhpExecutable.DEFAULT_EXECUTION_DESCRIPTOR
161-
.optionsPath(PhpCsFixerOptionsPanelController.getOptionsPath())
162-
.inputVisible(false);
175+
ExecutionDescriptor descriptor;
176+
if (PhpCsFixerOptions.getInstance().showOutputWindow() || isDryRun) {
177+
descriptor = DEFAULT_EXECUTION_DESCRIPTOR;
178+
} else {
179+
descriptor = NO_OUTPUT_EXECUTION_DESCRIPTOR;
180+
}
181+
descriptor = descriptor.postExecution(() -> {});
163182
if (phpModule != null) {
164183
final FileObject sourceDirectory = phpModule.getSourceDirectory();
165184
if (sourceDirectory != null) {

src/org/netbeans/modules/php/phpcsfixer/options/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ PhpCsFixerOptionsPanel.dryRunLabel.text=--dry-run
1616
PhpCsFixerOptionsPanel.versionLabel.text=Version:
1717
PhpCsFixerOptionsPanel.rulesCheckBox.text=--rules=
1818
PhpCsFixerOptionsPanel.rulesTextField.text=
19+
PhpCsFixerPanel.showOutputWindowCheckBox.text=Show an output window

src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerOptions.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public final class PhpCsFixerOptions {
7676
private static final String CUSTOM = "custom"; // NOI18N
7777
private static final String VERBOSE = "verbose"; // NOI18N
7878
private static final String DIFF = "diff"; // NOI18N
79+
private static final String SHOW_OUTPUT_WINDOW = "show.output.window"; // NOI18N
7980
private volatile boolean phpcsfixerSearched = false;
8081

8182
public static final int LATEST_VERSION = 2;
@@ -233,6 +234,14 @@ public void setDiff(boolean isDiff) {
233234
getPreferences().putBoolean(DIFF, isDiff);
234235
}
235236

237+
public boolean showOutputWindow() {
238+
return getPreferences().getBoolean(SHOW_OUTPUT_WINDOW, true);
239+
}
240+
241+
public void setShowOutputWindow(boolean show) {
242+
getPreferences().putBoolean(SHOW_OUTPUT_WINDOW, show);
243+
}
244+
236245
public List<String> getAllOptions() {
237246
List<String> all = new ArrayList<>();
238247
if (getVersion() == 2) {

src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerPanel.form

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,21 +17,29 @@
1717
<DimensionLayout dim="0">
1818
<Group type="103" groupAlignment="0" attributes="0">
1919
<Component id="optionsPanel" alignment="0" max="32767" attributes="0"/>
20-
<Group type="102" alignment="0" attributes="0">
21-
<EmptySpace max="-2" attributes="0"/>
22-
<Component id="pathLabel" min="-2" max="-2" attributes="0"/>
20+
<Group type="102" attributes="0">
2321
<EmptySpace max="-2" attributes="0"/>
2422
<Group type="103" groupAlignment="0" attributes="0">
25-
<Group type="102" attributes="0">
26-
<Component id="phpCsFixerNameLabel" min="-2" max="-2" attributes="0"/>
27-
<EmptySpace min="0" pref="12" max="32767" attributes="0"/>
28-
</Group>
29-
<Group type="102" attributes="0">
30-
<Component id="pathTextField" max="32767" attributes="0"/>
23+
<Group type="102" alignment="0" attributes="0">
24+
<Component id="pathLabel" min="-2" max="-2" attributes="0"/>
3125
<EmptySpace max="-2" attributes="0"/>
32-
<Component id="browseButton" min="-2" pref="78" max="-2" attributes="0"/>
33-
<EmptySpace max="-2" attributes="0"/>
34-
<Component id="downloadButton" min="-2" max="-2" attributes="0"/>
26+
<Group type="103" groupAlignment="0" attributes="0">
27+
<Group type="102" attributes="0">
28+
<Component id="phpCsFixerNameLabel" min="-2" max="-2" attributes="0"/>
29+
<EmptySpace min="0" pref="12" max="32767" attributes="0"/>
30+
</Group>
31+
<Group type="102" attributes="0">
32+
<Component id="pathTextField" max="32767" attributes="0"/>
33+
<EmptySpace max="-2" attributes="0"/>
34+
<Component id="browseButton" min="-2" pref="78" max="-2" attributes="0"/>
35+
<EmptySpace max="-2" attributes="0"/>
36+
<Component id="downloadButton" min="-2" max="-2" attributes="0"/>
37+
</Group>
38+
</Group>
39+
</Group>
40+
<Group type="102" alignment="0" attributes="0">
41+
<Component id="showOutputWindowCheckBox" min="-2" max="-2" attributes="0"/>
42+
<EmptySpace min="0" pref="0" max="32767" attributes="0"/>
3543
</Group>
3644
</Group>
3745
<EmptySpace max="-2" attributes="0"/>
@@ -51,6 +59,8 @@
5159
<EmptySpace max="-2" attributes="0"/>
5260
<Component id="phpCsFixerNameLabel" min="-2" max="-2" attributes="0"/>
5361
<EmptySpace max="-2" attributes="0"/>
62+
<Component id="showOutputWindowCheckBox" min="-2" max="-2" attributes="0"/>
63+
<EmptySpace max="-2" attributes="0"/>
5464
<Component id="optionsPanel" min="-2" max="-2" attributes="0"/>
5565
<EmptySpace max="32767" attributes="0"/>
5666
</Group>
@@ -101,5 +111,12 @@
101111
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="downloadButtonActionPerformed"/>
102112
</Events>
103113
</Component>
114+
<Component class="javax.swing.JCheckBox" name="showOutputWindowCheckBox">
115+
<Properties>
116+
<Property name="text" type="java.lang.String" editor="org.netbeans.modules.i18n.form.FormI18nStringEditor">
117+
<ResourceString bundle="org/netbeans/modules/php/phpcsfixer/options/Bundle.properties" key="PhpCsFixerPanel.showOutputWindowCheckBox.text" replaceFormat="org.openide.util.NbBundle.getMessage({sourceFileName}.class, &quot;{key}&quot;)"/>
118+
</Property>
119+
</Properties>
120+
</Component>
104121
</SubComponents>
105122
</Form>

src/org/netbeans/modules/php/phpcsfixer/options/PhpCsFixerPanel.java

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ final class PhpCsFixerPanel extends javax.swing.JPanel {
7575
private String rules;
7676
// common
7777
private boolean useCustom;
78+
private boolean showOutputWindow;
7879
private boolean isRunOnSave;
7980
private boolean isVerbose;
8081
private boolean isDiff;
@@ -99,6 +100,7 @@ private void initComponents() {
99100
phpCsFixerNameLabel = new javax.swing.JLabel();
100101
optionsPanel = new org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptionsPanel();
101102
downloadButton = new javax.swing.JButton();
103+
showOutputWindowCheckBox = new javax.swing.JCheckBox();
102104

103105
org.openide.awt.Mnemonics.setLocalizedText(pathLabel, org.openide.util.NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.pathLabel.text")); // NOI18N
104106

@@ -120,25 +122,32 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
120122
}
121123
});
122124

125+
org.openide.awt.Mnemonics.setLocalizedText(showOutputWindowCheckBox, org.openide.util.NbBundle.getMessage(PhpCsFixerPanel.class, "PhpCsFixerPanel.showOutputWindowCheckBox.text")); // NOI18N
126+
123127
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
124128
this.setLayout(layout);
125129
layout.setHorizontalGroup(
126130
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127131
.addComponent(optionsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
128132
.addGroup(layout.createSequentialGroup()
129133
.addContainerGap()
130-
.addComponent(pathLabel)
131-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
132134
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
133135
.addGroup(layout.createSequentialGroup()
134-
.addComponent(phpCsFixerNameLabel)
135-
.addGap(0, 12, Short.MAX_VALUE))
136-
.addGroup(layout.createSequentialGroup()
137-
.addComponent(pathTextField)
138-
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
139-
.addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
136+
.addComponent(pathLabel)
140137
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
141-
.addComponent(downloadButton)))
138+
.addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
139+
.addGroup(layout.createSequentialGroup()
140+
.addComponent(phpCsFixerNameLabel)
141+
.addGap(0, 12, Short.MAX_VALUE))
142+
.addGroup(layout.createSequentialGroup()
143+
.addComponent(pathTextField)
144+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
145+
.addComponent(browseButton, javax.swing.GroupLayout.PREFERRED_SIZE, 78, javax.swing.GroupLayout.PREFERRED_SIZE)
146+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
147+
.addComponent(downloadButton))))
148+
.addGroup(layout.createSequentialGroup()
149+
.addComponent(showOutputWindowCheckBox)
150+
.addGap(0, 0, Short.MAX_VALUE)))
142151
.addContainerGap())
143152
);
144153
layout.setVerticalGroup(
@@ -153,6 +162,8 @@ public void actionPerformed(java.awt.event.ActionEvent evt) {
153162
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
154163
.addComponent(phpCsFixerNameLabel)
155164
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
165+
.addComponent(showOutputWindowCheckBox)
166+
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
156167
.addComponent(optionsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
157168
.addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
158169
);
@@ -226,8 +237,11 @@ private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GE
226237
void load() {
227238
PhpCsFixerOptions options = getOptions();
228239
setPath(options.getPhpCsFixerPath());
240+
setShowOutputWindow(options.showOutputWindow());
229241

242+
// original options
230243
version = options.getVersion();
244+
showOutputWindow = options.showOutputWindow();
231245

232246
// 1.x
233247
useLevel = options.useLevel();
@@ -278,6 +292,11 @@ void store() {
278292
} else {
279293
options.setPhpCsFixerPath(""); // NOI18N
280294
}
295+
296+
if (showOutputWindow != showOutputWindow()) {
297+
options.setShowOutputWindow(showOutputWindow());
298+
}
299+
281300
if (version != optionsPanel.getVersion()) {
282301
options.setVersion(optionsPanel.getVersion());
283302
}
@@ -337,6 +356,14 @@ public String getPath() {
337356
return pathTextField.getText();
338357
}
339358

359+
public void setShowOutputWindow(boolean show) {
360+
showOutputWindowCheckBox.setSelected(show);
361+
}
362+
363+
public boolean showOutputWindow() {
364+
return showOutputWindowCheckBox.isSelected();
365+
}
366+
340367
boolean valid() {
341368
// TODO check whether form is consistent and complete
342369
String path = pathTextField.getText();
@@ -350,6 +377,7 @@ boolean valid() {
350377
private javax.swing.JLabel pathLabel;
351378
private javax.swing.JTextField pathTextField;
352379
private javax.swing.JLabel phpCsFixerNameLabel;
380+
private javax.swing.JCheckBox showOutputWindowCheckBox;
353381
// End of variables declaration//GEN-END:variables
354382

355383
private static class FileFilterImpl extends FileFilter {

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@
4444
import java.awt.event.ActionEvent;
4545
import java.util.ArrayList;
4646
import java.util.List;
47+
import java.util.logging.Level;
48+
import java.util.logging.Logger;
4749
import javax.swing.AbstractAction;
4850
import static javax.swing.Action.NAME;
4951
import static javax.swing.Action.SHORT_DESCRIPTION;
@@ -52,7 +54,6 @@
5254
import org.netbeans.modules.php.api.util.StringUtils;
5355
import org.netbeans.modules.php.phpcsfixer.options.PhpCsFixerOptions;
5456
import org.netbeans.modules.php.phpcsfixer.preferences.PhpCsFixerPreferences;
55-
import org.openide.util.Exceptions;
5657

5758
/**
5859
*
@@ -61,6 +62,7 @@
6162
public abstract class PhpCsFixerBaseAction extends AbstractAction {
6263

6364
private static final long serialVersionUID = -8856272088582157210L;
65+
private static final Logger LOGGER = Logger.getLogger(PhpCsFixerBaseAction.class.getName());
6466

6567
public PhpCsFixerBaseAction() {
6668
putValue("noIconInMenu", true); // NOI18N
@@ -83,8 +85,7 @@ public void actionPerformed(ActionEvent e) {
8385
try {
8486
runCommand(phpModule, getOptions());
8587
} catch (InvalidPhpExecutableException ex) {
86-
// TODO implement
87-
Exceptions.printStackTrace(ex);
88+
LOGGER.log(Level.WARNING, null, ex);
8889
}
8990
}
9091

0 commit comments

Comments
 (0)